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