blob: 4f1e24033d758a97d23373e63650248866df7dae [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskibe44b182017-01-27 23:16:29 +01002/*
3 * Copyright (C) 2014 Wandboard
4 * Author: Tungyi Lin <tungyilin1127@gmail.com>
5 * Richard Hu <hakahu@gmail.com>
Lukasz Majewskibe44b182017-01-27 23:16:29 +01006 */
7
8#include <asm/arch/clock.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/iomux.h>
11#include <asm/arch/mx6-pins.h>
12#include <errno.h>
13#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020014#include <asm/mach-imx/iomux-v3.h>
15#include <asm/mach-imx/video.h>
Lukasz Majewskibe44b182017-01-27 23:16:29 +010016#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080017#include <fsl_esdhc_imx.h>
Lukasz Majewskibe44b182017-01-27 23:16:29 +010018#include <asm/arch/crm_regs.h>
19#include <asm/io.h>
20#include <asm/arch/sys_proto.h>
21#include <spl.h>
22
Lukasz Majewskibe44b182017-01-27 23:16:29 +010023#include <asm/arch/mx6-ddr.h>
24/*
25 * Driving strength:
26 * 0x30 == 40 Ohm
27 * 0x28 == 48 Ohm
28 */
29
30#define IMX6DQ_DRIVE_STRENGTH 0x30
31#define IMX6SDL_DRIVE_STRENGTH 0x28
32
33/* configure MX6Q/DUAL mmdc DDR io registers */
34static struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
35 .dram_sdclk_0 = IMX6DQ_DRIVE_STRENGTH,
36 .dram_sdclk_1 = IMX6DQ_DRIVE_STRENGTH,
37 .dram_cas = IMX6DQ_DRIVE_STRENGTH,
38 .dram_ras = IMX6DQ_DRIVE_STRENGTH,
39 .dram_reset = IMX6DQ_DRIVE_STRENGTH,
40 .dram_sdcke0 = IMX6DQ_DRIVE_STRENGTH,
41 .dram_sdcke1 = IMX6DQ_DRIVE_STRENGTH,
42 .dram_sdba2 = 0x00000000,
43 .dram_sdodt0 = IMX6DQ_DRIVE_STRENGTH,
44 .dram_sdodt1 = IMX6DQ_DRIVE_STRENGTH,
45 .dram_sdqs0 = IMX6DQ_DRIVE_STRENGTH,
46 .dram_sdqs1 = IMX6DQ_DRIVE_STRENGTH,
47 .dram_sdqs2 = IMX6DQ_DRIVE_STRENGTH,
48 .dram_sdqs3 = IMX6DQ_DRIVE_STRENGTH,
49 .dram_sdqs4 = IMX6DQ_DRIVE_STRENGTH,
50 .dram_sdqs5 = IMX6DQ_DRIVE_STRENGTH,
51 .dram_sdqs6 = IMX6DQ_DRIVE_STRENGTH,
52 .dram_sdqs7 = IMX6DQ_DRIVE_STRENGTH,
53 .dram_dqm0 = IMX6DQ_DRIVE_STRENGTH,
54 .dram_dqm1 = IMX6DQ_DRIVE_STRENGTH,
55 .dram_dqm2 = IMX6DQ_DRIVE_STRENGTH,
56 .dram_dqm3 = IMX6DQ_DRIVE_STRENGTH,
57 .dram_dqm4 = IMX6DQ_DRIVE_STRENGTH,
58 .dram_dqm5 = IMX6DQ_DRIVE_STRENGTH,
59 .dram_dqm6 = IMX6DQ_DRIVE_STRENGTH,
60 .dram_dqm7 = IMX6DQ_DRIVE_STRENGTH,
61};
62
63/* configure MX6Q/DUAL mmdc GRP io registers */
64static struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
65 .grp_ddr_type = 0x000c0000,
66 .grp_ddrmode_ctl = 0x00020000,
67 .grp_ddrpke = 0x00000000,
68 .grp_addds = IMX6DQ_DRIVE_STRENGTH,
69 .grp_ctlds = IMX6DQ_DRIVE_STRENGTH,
70 .grp_ddrmode = 0x00020000,
71 .grp_b0ds = IMX6DQ_DRIVE_STRENGTH,
72 .grp_b1ds = IMX6DQ_DRIVE_STRENGTH,
73 .grp_b2ds = IMX6DQ_DRIVE_STRENGTH,
74 .grp_b3ds = IMX6DQ_DRIVE_STRENGTH,
75 .grp_b4ds = IMX6DQ_DRIVE_STRENGTH,
76 .grp_b5ds = IMX6DQ_DRIVE_STRENGTH,
77 .grp_b6ds = IMX6DQ_DRIVE_STRENGTH,
78 .grp_b7ds = IMX6DQ_DRIVE_STRENGTH,
79};
80
81/* configure MX6SOLO/DUALLITE mmdc DDR io registers */
82struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
83 .dram_sdclk_0 = IMX6SDL_DRIVE_STRENGTH,
84 .dram_sdclk_1 = IMX6SDL_DRIVE_STRENGTH,
85 .dram_cas = IMX6SDL_DRIVE_STRENGTH,
86 .dram_ras = IMX6SDL_DRIVE_STRENGTH,
87 .dram_reset = IMX6SDL_DRIVE_STRENGTH,
88 .dram_sdcke0 = IMX6SDL_DRIVE_STRENGTH,
89 .dram_sdcke1 = IMX6SDL_DRIVE_STRENGTH,
90 .dram_sdba2 = 0x00000000,
91 .dram_sdodt0 = IMX6SDL_DRIVE_STRENGTH,
92 .dram_sdodt1 = IMX6SDL_DRIVE_STRENGTH,
93 .dram_sdqs0 = IMX6SDL_DRIVE_STRENGTH,
94 .dram_sdqs1 = IMX6SDL_DRIVE_STRENGTH,
95 .dram_sdqs2 = IMX6SDL_DRIVE_STRENGTH,
96 .dram_sdqs3 = IMX6SDL_DRIVE_STRENGTH,
97 .dram_sdqs4 = IMX6SDL_DRIVE_STRENGTH,
98 .dram_sdqs5 = IMX6SDL_DRIVE_STRENGTH,
99 .dram_sdqs6 = IMX6SDL_DRIVE_STRENGTH,
100 .dram_sdqs7 = IMX6SDL_DRIVE_STRENGTH,
101 .dram_dqm0 = IMX6SDL_DRIVE_STRENGTH,
102 .dram_dqm1 = IMX6SDL_DRIVE_STRENGTH,
103 .dram_dqm2 = IMX6SDL_DRIVE_STRENGTH,
104 .dram_dqm3 = IMX6SDL_DRIVE_STRENGTH,
105 .dram_dqm4 = IMX6SDL_DRIVE_STRENGTH,
106 .dram_dqm5 = IMX6SDL_DRIVE_STRENGTH,
107 .dram_dqm6 = IMX6SDL_DRIVE_STRENGTH,
108 .dram_dqm7 = IMX6SDL_DRIVE_STRENGTH,
109};
110
111/* configure MX6SOLO/DUALLITE mmdc GRP io registers */
112struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
113 .grp_ddr_type = 0x000c0000,
114 .grp_ddrmode_ctl = 0x00020000,
115 .grp_ddrpke = 0x00000000,
116 .grp_addds = IMX6SDL_DRIVE_STRENGTH,
117 .grp_ctlds = IMX6SDL_DRIVE_STRENGTH,
118 .grp_ddrmode = 0x00020000,
119 .grp_b0ds = IMX6SDL_DRIVE_STRENGTH,
120 .grp_b1ds = IMX6SDL_DRIVE_STRENGTH,
121 .grp_b2ds = IMX6SDL_DRIVE_STRENGTH,
122 .grp_b3ds = IMX6SDL_DRIVE_STRENGTH,
123 .grp_b4ds = IMX6SDL_DRIVE_STRENGTH,
124 .grp_b5ds = IMX6SDL_DRIVE_STRENGTH,
125 .grp_b6ds = IMX6SDL_DRIVE_STRENGTH,
126 .grp_b7ds = IMX6SDL_DRIVE_STRENGTH,
127};
128
129/* H5T04G63AFR-PB */
130static struct mx6_ddr3_cfg h5t04g63afr = {
131 .mem_speed = 1600,
132 .density = 4,
133 .width = 16,
134 .banks = 8,
135 .rowaddr = 15,
136 .coladdr = 10,
137 .pagesz = 2,
138 .trcd = 1375,
139 .trcmin = 4875,
140 .trasmin = 3500,
141};
142
143/* H5TQ2G63DFR-H9 */
144static struct mx6_ddr3_cfg h5tq2g63dfr = {
145 .mem_speed = 1333,
146 .density = 2,
147 .width = 16,
148 .banks = 8,
149 .rowaddr = 14,
150 .coladdr = 10,
151 .pagesz = 2,
152 .trcd = 1350,
153 .trcmin = 4950,
154 .trasmin = 3600,
155};
156
157static struct mx6_mmdc_calibration mx6q_2g_mmdc_calib = {
158 .p0_mpwldectrl0 = 0x001f001f,
159 .p0_mpwldectrl1 = 0x001f001f,
160 .p1_mpwldectrl0 = 0x001f001f,
161 .p1_mpwldectrl1 = 0x001f001f,
162 .p0_mpdgctrl0 = 0x4301030d,
163 .p0_mpdgctrl1 = 0x03020277,
164 .p1_mpdgctrl0 = 0x4300030a,
165 .p1_mpdgctrl1 = 0x02780248,
166 .p0_mprddlctl = 0x4536393b,
167 .p1_mprddlctl = 0x36353441,
168 .p0_mpwrdlctl = 0x41414743,
169 .p1_mpwrdlctl = 0x462f453f,
170};
171
172/* DDR 64bit 2GB */
173static struct mx6_ddr_sysinfo mem_q = {
174 .dsize = 2,
175 .cs1_mirror = 0,
176 /* config for full 4GB range so that get_mem_size() works */
177 .cs_density = 32,
178 .ncs = 1,
179 .bi_on = 1,
180 .rtt_nom = 1,
181 .rtt_wr = 0,
182 .ralat = 5,
183 .walat = 0,
184 .mif3_mode = 3,
185 .rst_to_cke = 0x23,
186 .sde_to_rst = 0x10,
187};
188
189static struct mx6_mmdc_calibration mx6dl_1g_mmdc_calib = {
190 .p0_mpwldectrl0 = 0x001f001f,
191 .p0_mpwldectrl1 = 0x001f001f,
192 .p1_mpwldectrl0 = 0x001f001f,
193 .p1_mpwldectrl1 = 0x001f001f,
194 .p0_mpdgctrl0 = 0x420e020e,
195 .p0_mpdgctrl1 = 0x02000200,
196 .p1_mpdgctrl0 = 0x42020202,
197 .p1_mpdgctrl1 = 0x01720172,
198 .p0_mprddlctl = 0x494c4f4c,
199 .p1_mprddlctl = 0x4a4c4c49,
200 .p0_mpwrdlctl = 0x3f3f3133,
201 .p1_mpwrdlctl = 0x39373f2e,
202};
203
204static struct mx6_mmdc_calibration mx6s_512m_mmdc_calib = {
205 .p0_mpwldectrl0 = 0x0040003c,
206 .p0_mpwldectrl1 = 0x0032003e,
207 .p0_mpdgctrl0 = 0x42350231,
208 .p0_mpdgctrl1 = 0x021a0218,
209 .p0_mprddlctl = 0x4b4b4e49,
210 .p0_mpwrdlctl = 0x3f3f3035,
211};
212
213/* DDR 64bit 1GB */
214static struct mx6_ddr_sysinfo mem_dl = {
215 .dsize = 2,
216 .cs1_mirror = 0,
217 /* config for full 4GB range so that get_mem_size() works */
218 .cs_density = 32,
219 .ncs = 1,
220 .bi_on = 1,
221 .rtt_nom = 1,
222 .rtt_wr = 0,
223 .ralat = 5,
224 .walat = 0,
225 .mif3_mode = 3,
226 .rst_to_cke = 0x23,
227 .sde_to_rst = 0x10,
228};
229
230/* DDR 32bit 512MB */
231static struct mx6_ddr_sysinfo mem_s = {
232 .dsize = 1,
233 .cs1_mirror = 0,
234 /* config for full 4GB range so that get_mem_size() works */
235 .cs_density = 32,
236 .ncs = 1,
237 .bi_on = 1,
238 .rtt_nom = 1,
239 .rtt_wr = 0,
240 .ralat = 5,
241 .walat = 0,
242 .mif3_mode = 3,
243 .rst_to_cke = 0x23,
244 .sde_to_rst = 0x10,
245};
246
247static void ccgr_init(void)
248{
249 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
250
251 writel(0x00C03F3F, &ccm->CCGR0);
252 writel(0x0030FC03, &ccm->CCGR1);
253 writel(0x0FFFC000, &ccm->CCGR2);
254 writel(0x3FF00000, &ccm->CCGR3);
255 writel(0x00FFF300, &ccm->CCGR4);
256 writel(0x0F0000C3, &ccm->CCGR5);
257 writel(0x000003FF, &ccm->CCGR6);
258}
259
Lukasz Majewskibe44b182017-01-27 23:16:29 +0100260static void spl_dram_init(void)
261{
262 if (is_cpu_type(MXC_CPU_MX6SOLO)) {
263 mx6sdl_dram_iocfg(32, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
264 mx6_dram_cfg(&mem_s, &mx6s_512m_mmdc_calib, &h5tq2g63dfr);
265 } else if (is_cpu_type(MXC_CPU_MX6DL)) {
266 mx6sdl_dram_iocfg(64, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
267 mx6_dram_cfg(&mem_dl, &mx6dl_1g_mmdc_calib, &h5tq2g63dfr);
268 } else if (is_cpu_type(MXC_CPU_MX6Q)) {
269 mx6dq_dram_iocfg(64, &mx6dq_ddr_ioregs, &mx6dq_grp_ioregs);
270 mx6_dram_cfg(&mem_q, &mx6q_2g_mmdc_calib, &h5t04g63afr);
271 }
272
273 udelay(100);
274}
275
Lukasz Majewskibcf82d12019-10-15 10:28:44 +0200276static void setup_spi(void)
277{
278 enable_spi_clk(true, 2);
279}
280
281#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
282 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
283 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
284
285static iomux_v3_cfg_t const uart1_pads[] = {
286 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
287 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
288};
289
290static void setup_iomux_uart(void)
291{
292 SETUP_IOMUX_PADS(uart1_pads);
293}
294
Lukasz Majewskibe44b182017-01-27 23:16:29 +0100295void board_init_f(ulong dummy)
296{
297 ccgr_init();
298
299 /* setup AIPS and disable watchdog */
300 arch_cpu_init();
301
302 gpr_init();
303
304 /* iomux */
Lukasz Majewskibcf82d12019-10-15 10:28:44 +0200305 setup_iomux_uart();
Lukasz Majewskibe44b182017-01-27 23:16:29 +0100306
307 /* setup GP timer */
308 timer_init();
309
310 /* UART clocks enabled and gd valid - init serial console */
311 preloader_console_init();
312
Lukasz Majewskibcf82d12019-10-15 10:28:44 +0200313 /* enable ECSPI clocks */
314 setup_spi();
315
Lukasz Majewskibe44b182017-01-27 23:16:29 +0100316 /* DDR initialization */
317 spl_dram_init();
Lukasz Majewskibe44b182017-01-27 23:16:29 +0100318}
Lukasz Majewskibcf82d12019-10-15 10:28:44 +0200319
320void board_boot_order(u32 *spl_boot_list)
321{
322 switch (spl_boot_device()) {
323 case BOOT_DEVICE_MMC2:
324 case BOOT_DEVICE_MMC1:
325 spl_boot_list[0] = BOOT_DEVICE_MMC2;
326 spl_boot_list[1] = BOOT_DEVICE_MMC1;
327 break;
328
329 case BOOT_DEVICE_NOR:
330 spl_boot_list[0] = BOOT_DEVICE_NOR;
331 break;
332 }
333}
334
335#ifdef CONFIG_SPL_OS_BOOT
336int spl_start_uboot(void)
337{
338 char s[16];
339 int ret;
340 /*
341 * We use BOOT_DEVICE_MMC1, but SD card is connected
342 * to MMC2
343 *
344 * Correct "mapping" is delivered in board defined
345 * board_boot_order() function.
346 *
347 * SD card boot is regarded as a "development" one,
348 * hence we _always_ go through the u-boot.
349 *
350 */
351 if (spl_boot_device() == BOOT_DEVICE_MMC1)
352 return 1;
353
354 /* break into full u-boot on 'c' */
355 if (serial_tstc() && serial_getc() == 'c')
356 return 1;
357
358 env_init();
359 ret = env_get_f("boot_os", s, sizeof(s));
360 if ((ret != -1) && (strcmp(s, "no") == 0))
361 return 1;
362
363 /*
364 * Check if SWUpdate recovery needs to be started
365 *
366 * recovery_status = NULL (not set - ret == -1) -> normal operation
367 *
368 * recovery_status = progress or
369 * recovery_status = failed or
370 * recovery_status = <any value> -> start SWUpdate
371 *
372 */
373 ret = env_get_f("recovery_status", s, sizeof(s));
374 if (ret != -1)
375 return 1;
376
377 return 0;
378}
379#endif /* CONFIG_SPL_OS_BOOT */
380
381#define WEIM_NOR_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
382 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
383 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
384
385#define NOR_WP IMX_GPIO_NR(1, 1)
386
387static iomux_v3_cfg_t const eimnor_pads[] = {
388 IOMUX_PADS(PAD_EIM_D16__EIM_DATA16 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
389 IOMUX_PADS(PAD_EIM_D17__EIM_DATA17 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
390 IOMUX_PADS(PAD_EIM_D18__EIM_DATA18 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
391 IOMUX_PADS(PAD_EIM_D19__EIM_DATA19 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
392 IOMUX_PADS(PAD_EIM_D20__EIM_DATA20 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
393 IOMUX_PADS(PAD_EIM_D21__EIM_DATA21 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
394 IOMUX_PADS(PAD_EIM_D22__EIM_DATA22 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
395 IOMUX_PADS(PAD_EIM_D23__EIM_DATA23 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
396 IOMUX_PADS(PAD_EIM_D24__EIM_DATA24 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
397 IOMUX_PADS(PAD_EIM_D25__EIM_DATA25 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
398 IOMUX_PADS(PAD_EIM_D26__EIM_DATA26 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
399 IOMUX_PADS(PAD_EIM_D27__EIM_DATA27 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
400 IOMUX_PADS(PAD_EIM_D28__EIM_DATA28 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
401 IOMUX_PADS(PAD_EIM_D29__EIM_DATA29 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
402 IOMUX_PADS(PAD_EIM_D30__EIM_DATA30 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
403 IOMUX_PADS(PAD_EIM_D31__EIM_DATA31 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
404 IOMUX_PADS(PAD_EIM_DA0__EIM_AD00 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
405 IOMUX_PADS(PAD_EIM_DA1__EIM_AD01 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
406 IOMUX_PADS(PAD_EIM_DA2__EIM_AD02 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
407 IOMUX_PADS(PAD_EIM_DA3__EIM_AD03 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
408 IOMUX_PADS(PAD_EIM_DA4__EIM_AD04 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
409 IOMUX_PADS(PAD_EIM_DA5__EIM_AD05 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
410 IOMUX_PADS(PAD_EIM_DA6__EIM_AD06 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
411 IOMUX_PADS(PAD_EIM_DA7__EIM_AD07 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
412 IOMUX_PADS(PAD_EIM_DA8__EIM_AD08 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
413 IOMUX_PADS(PAD_EIM_DA9__EIM_AD09 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
414 IOMUX_PADS(PAD_EIM_DA10__EIM_AD10 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
415 IOMUX_PADS(PAD_EIM_DA11__EIM_AD11 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
416 IOMUX_PADS(PAD_EIM_DA12__EIM_AD12 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
417 IOMUX_PADS(PAD_EIM_DA13__EIM_AD13 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
418 IOMUX_PADS(PAD_EIM_DA14__EIM_AD14 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
419 IOMUX_PADS(PAD_EIM_DA15__EIM_AD15 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
420 IOMUX_PADS(PAD_EIM_A16__EIM_ADDR16 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
421 IOMUX_PADS(PAD_EIM_A17__EIM_ADDR17 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
422 IOMUX_PADS(PAD_EIM_A18__EIM_ADDR18 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
423 IOMUX_PADS(PAD_EIM_A19__EIM_ADDR19 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
424 IOMUX_PADS(PAD_EIM_A20__EIM_ADDR20 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
425 IOMUX_PADS(PAD_EIM_A21__EIM_ADDR21 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
426 IOMUX_PADS(PAD_EIM_A22__EIM_ADDR22 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
427 IOMUX_PADS(PAD_EIM_A23__EIM_ADDR23 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
428 IOMUX_PADS(PAD_EIM_A24__EIM_ADDR24 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
429 IOMUX_PADS(PAD_EIM_A25__EIM_ADDR25 | MUX_PAD_CTRL(WEIM_NOR_PAD_CTRL)),
430 IOMUX_PADS(PAD_EIM_OE__EIM_OE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
431 IOMUX_PADS(PAD_EIM_RW__EIM_RW | MUX_PAD_CTRL(NO_PAD_CTRL)),
432 IOMUX_PADS(PAD_EIM_CS0__EIM_CS0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
433 IOMUX_PADS(PAD_GPIO_1__GPIO1_IO01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
434};
435
436static void eimnor_cs_setup(void)
437{
438 struct weim *weim_regs = (struct weim *)WEIM_BASE_ADDR;
439
440 /* NOR configuration */
441 writel(0x00620181, &weim_regs->cs0gcr1);
442 writel(0x00000001, &weim_regs->cs0gcr2);
443 writel(0x0b020000, &weim_regs->cs0rcr1);
444 writel(0x0000b000, &weim_regs->cs0rcr2);
445 writel(0x0804a240, &weim_regs->cs0wcr1);
446 writel(0x00000000, &weim_regs->cs0wcr2);
447
448 writel(0x00000120, &weim_regs->wcr);
449 writel(0x00000010, &weim_regs->wiar);
450 writel(0x00000000, &weim_regs->ear);
451
452 set_chipselect_size(CS0_128);
453}
454
455static void setup_eimnor(void)
456{
457 SETUP_IOMUX_PADS(eimnor_pads);
458 gpio_direction_output(NOR_WP, 1);
459
460 enable_eim_clk(1);
461 eimnor_cs_setup();
462}
463
464#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
465 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
466 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
467
468#define USDHC2_CD_GPIO IMX_GPIO_NR(1, 4)
469
470static iomux_v3_cfg_t const usdhc2_pads[] = {
471 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
472 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
473 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
474 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
475 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
476 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
477 /* Carrier MicroSD Card Detect */
478 IOMUX_PADS(PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
479};
480
481static iomux_v3_cfg_t const usdhc3_pads[] = {
482 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
483 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
484 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
485 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
486 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
487 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
488 IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
489 IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
490 IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
491 IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
492 IOMUX_PADS(PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
493};
494
495static struct fsl_esdhc_cfg usdhc_cfg[2] = {
496 {USDHC3_BASE_ADDR},
497 {USDHC2_BASE_ADDR},
498};
499
500int board_mmc_getcd(struct mmc *mmc)
501{
502 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
503 int ret = 0;
504
505 switch (cfg->esdhc_base) {
506 case USDHC2_BASE_ADDR:
507 ret = !gpio_get_value(USDHC2_CD_GPIO);
508 break;
509 case USDHC3_BASE_ADDR:
510 /*
511 * eMMC don't have card detect pin - since it is soldered to the
512 * PCB board
513 */
514 ret = 1;
515 break;
516 }
517 return ret;
518}
519
520int board_mmc_init(bd_t *bis)
521{
522 int ret;
523 u32 index = 0;
524
525 /*
526 * MMC MAP
527 * (U-Boot device node) (Physical Port)
528 * mmc0 Soldered on board eMMC device
529 * mmc1 MicroSD card
530 */
531 for (index = 0; index < CONFIG_SYS_FSL_USDHC_NUM; ++index) {
532 switch (index) {
533 case 0:
534 SETUP_IOMUX_PADS(usdhc3_pads);
535 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
536 usdhc_cfg[0].max_bus_width = 8;
537 break;
538 case 1:
539 SETUP_IOMUX_PADS(usdhc2_pads);
540 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
541 usdhc_cfg[1].max_bus_width = 4;
542 gpio_direction_input(USDHC2_CD_GPIO);
543 break;
544 default:
545 printf("Warning: More USDHC controllers (%d) than supported (%d)\n",
546 index + 1, CONFIG_SYS_FSL_USDHC_NUM);
547 return -EINVAL;
548 }
549
550 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
551 if (ret)
552 return ret;
553 }
554
555 return 0;
556}
557
558#ifdef CONFIG_SPL_BOARD_INIT
559#define DISPLAY_EN IMX_GPIO_NR(1, 2)
560void spl_board_init(void)
561{
562 setup_eimnor();
563
564 gpio_direction_output(DISPLAY_EN, 1);
565}
566#endif /* CONFIG_SPL_BOARD_INIT */