blob: 8bc80ee6baa84c26f23248f6cc28a11bb0a134d5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jagan Teki215cd412017-05-07 02:43:12 +05302/*
3 * Copyright (C) 2016 Amarula Solutions B.V.
4 * Copyright (C) 2016 Engicam S.r.l.
5 * Author: Jagan Teki <jagan@amarulasolutions.com>
Jagan Teki215cd412017-05-07 02:43:12 +05306 */
7
Simon Glass2dc9c342020-05-10 11:40:01 -06008#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass36736182019-11-14 12:57:24 -070010#include <serial.h>
Jagan Teki215cd412017-05-07 02:43:12 +053011#include <spl.h>
Simon Glassdbd79542020-05-10 11:40:11 -060012#include <linux/delay.h>
Jagan Teki215cd412017-05-07 02:43:12 +053013
14#include <asm/io.h>
15#include <asm/gpio.h>
16#include <linux/sizes.h>
17
18#include <asm/arch/clock.h>
19#include <asm/arch/crm_regs.h>
20#include <asm/arch/iomux.h>
21#include <asm/arch/mx6-ddr.h>
22#include <asm/arch/mx6-pins.h>
23#include <asm/arch/sys_proto.h>
24
Stefano Babic33731bc2017-06-29 10:16:06 +020025#include <asm/mach-imx/iomux-v3.h>
26#include <asm/mach-imx/video.h>
Jagan Teki215cd412017-05-07 02:43:12 +053027
Jagan Tekica5b8162017-11-21 00:02:11 +053028#ifdef CONFIG_SPL_LOAD_FIT
29int board_fit_config_name_match(const char *name)
30{
31 if (is_mx6dq() && !strcmp(name, "imx6q-icore"))
32 return 0;
33 else if (is_mx6dq() && !strcmp(name, "imx6q-icore-rqs"))
34 return 0;
Jagan Teki41c7bd92018-06-02 17:25:27 +053035 else if (is_mx6dq() && !strcmp(name, "imx6q-icore-mipi"))
36 return 0;
Jagan Tekica5b8162017-11-21 00:02:11 +053037 else if ((is_mx6dl() || is_mx6solo()) && !strcmp(name, "imx6dl-icore"))
38 return 0;
39 else if ((is_mx6dl() || is_mx6solo()) && !strcmp(name, "imx6dl-icore-rqs"))
40 return 0;
Jagan Teki41c7bd92018-06-02 17:25:27 +053041 else if ((is_mx6dl() || is_mx6solo()) && !strcmp(name, "imx6dl-icore-mipi"))
42 return 0;
Jagan Tekica5b8162017-11-21 00:02:11 +053043 else
44 return -1;
45}
46#endif
47
Jagan Teki515bd002017-11-21 00:02:16 +053048#ifdef CONFIG_ENV_IS_IN_MMC
49void board_boot_order(u32 *spl_boot_list)
50{
51 u32 bmode = imx6_src_get_boot_mode();
52 u8 boot_dev = BOOT_DEVICE_MMC1;
53
54 switch ((bmode & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
55 case IMX6_BMODE_SD:
56 case IMX6_BMODE_ESD:
57 /* SD/eSD - BOOT_DEVICE_MMC1 */
58 break;
59 case IMX6_BMODE_MMC:
60 case IMX6_BMODE_EMMC:
61 /* MMC/eMMC */
62 boot_dev = BOOT_DEVICE_MMC2;
63 break;
64 default:
65 /* Default - BOOT_DEVICE_MMC1 */
66 printf("Wrong board boot order\n");
67 break;
68 }
69
70 spl_boot_list[0] = boot_dev;
71}
72#endif
73
Jagan Teki88d8f882017-08-28 16:45:48 +053074#ifdef CONFIG_SPL_OS_BOOT
75int spl_start_uboot(void)
76{
77 /* break into full u-boot on 'c' */
78 if (serial_tstc() && serial_getc() == 'c')
79 return 1;
80
81 return 0;
82}
83#endif
84
Jagan Teki2c67e882017-05-07 02:43:13 +053085#ifdef CONFIG_MX6QDL
Jagan Teki215cd412017-05-07 02:43:12 +053086/*
87 * Driving strength:
88 * 0x30 == 40 Ohm
89 * 0x28 == 48 Ohm
90 */
91#define IMX6DQ_DRIVE_STRENGTH 0x30
92#define IMX6SDL_DRIVE_STRENGTH 0x28
93
94/* configure MX6Q/DUAL mmdc DDR io registers */
95static struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
96 .dram_sdqs0 = IMX6DQ_DRIVE_STRENGTH,
97 .dram_sdqs1 = IMX6DQ_DRIVE_STRENGTH,
98 .dram_sdqs2 = IMX6DQ_DRIVE_STRENGTH,
99 .dram_sdqs3 = IMX6DQ_DRIVE_STRENGTH,
100 .dram_sdqs4 = IMX6DQ_DRIVE_STRENGTH,
101 .dram_sdqs5 = IMX6DQ_DRIVE_STRENGTH,
102 .dram_sdqs6 = IMX6DQ_DRIVE_STRENGTH,
103 .dram_sdqs7 = IMX6DQ_DRIVE_STRENGTH,
104 .dram_dqm0 = IMX6DQ_DRIVE_STRENGTH,
105 .dram_dqm1 = IMX6DQ_DRIVE_STRENGTH,
106 .dram_dqm2 = IMX6DQ_DRIVE_STRENGTH,
107 .dram_dqm3 = IMX6DQ_DRIVE_STRENGTH,
108 .dram_dqm4 = IMX6DQ_DRIVE_STRENGTH,
109 .dram_dqm5 = IMX6DQ_DRIVE_STRENGTH,
110 .dram_dqm6 = IMX6DQ_DRIVE_STRENGTH,
111 .dram_dqm7 = IMX6DQ_DRIVE_STRENGTH,
112 .dram_cas = IMX6DQ_DRIVE_STRENGTH,
113 .dram_ras = IMX6DQ_DRIVE_STRENGTH,
114 .dram_sdclk_0 = IMX6DQ_DRIVE_STRENGTH,
115 .dram_sdclk_1 = IMX6DQ_DRIVE_STRENGTH,
116 .dram_reset = IMX6DQ_DRIVE_STRENGTH,
117 .dram_sdcke0 = IMX6DQ_DRIVE_STRENGTH,
118 .dram_sdcke1 = IMX6DQ_DRIVE_STRENGTH,
119 .dram_sdba2 = 0x00000000,
120 .dram_sdodt0 = IMX6DQ_DRIVE_STRENGTH,
121 .dram_sdodt1 = IMX6DQ_DRIVE_STRENGTH,
122};
123
124/* configure MX6Q/DUAL mmdc GRP io registers */
125static struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
126 .grp_b0ds = IMX6DQ_DRIVE_STRENGTH,
127 .grp_b1ds = IMX6DQ_DRIVE_STRENGTH,
128 .grp_b2ds = IMX6DQ_DRIVE_STRENGTH,
129 .grp_b3ds = IMX6DQ_DRIVE_STRENGTH,
130 .grp_b4ds = IMX6DQ_DRIVE_STRENGTH,
131 .grp_b5ds = IMX6DQ_DRIVE_STRENGTH,
132 .grp_b6ds = IMX6DQ_DRIVE_STRENGTH,
133 .grp_b7ds = IMX6DQ_DRIVE_STRENGTH,
134 .grp_addds = IMX6DQ_DRIVE_STRENGTH,
135 .grp_ddrmode_ctl = 0x00020000,
136 .grp_ddrpke = 0x00000000,
137 .grp_ddrmode = 0x00020000,
138 .grp_ctlds = IMX6DQ_DRIVE_STRENGTH,
139 .grp_ddr_type = 0x000c0000,
140};
141
142/* configure MX6SOLO/DUALLITE mmdc DDR io registers */
143struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
144 .dram_sdclk_0 = IMX6SDL_DRIVE_STRENGTH,
145 .dram_sdclk_1 = IMX6SDL_DRIVE_STRENGTH,
146 .dram_cas = IMX6SDL_DRIVE_STRENGTH,
147 .dram_ras = IMX6SDL_DRIVE_STRENGTH,
148 .dram_reset = IMX6SDL_DRIVE_STRENGTH,
149 .dram_sdcke0 = IMX6SDL_DRIVE_STRENGTH,
150 .dram_sdcke1 = IMX6SDL_DRIVE_STRENGTH,
151 .dram_sdba2 = 0x00000000,
152 .dram_sdodt0 = IMX6SDL_DRIVE_STRENGTH,
153 .dram_sdodt1 = IMX6SDL_DRIVE_STRENGTH,
154 .dram_sdqs0 = IMX6SDL_DRIVE_STRENGTH,
155 .dram_sdqs1 = IMX6SDL_DRIVE_STRENGTH,
156 .dram_sdqs2 = IMX6SDL_DRIVE_STRENGTH,
157 .dram_sdqs3 = IMX6SDL_DRIVE_STRENGTH,
158 .dram_sdqs4 = IMX6SDL_DRIVE_STRENGTH,
159 .dram_sdqs5 = IMX6SDL_DRIVE_STRENGTH,
160 .dram_sdqs6 = IMX6SDL_DRIVE_STRENGTH,
161 .dram_sdqs7 = IMX6SDL_DRIVE_STRENGTH,
162 .dram_dqm0 = IMX6SDL_DRIVE_STRENGTH,
163 .dram_dqm1 = IMX6SDL_DRIVE_STRENGTH,
164 .dram_dqm2 = IMX6SDL_DRIVE_STRENGTH,
165 .dram_dqm3 = IMX6SDL_DRIVE_STRENGTH,
166 .dram_dqm4 = IMX6SDL_DRIVE_STRENGTH,
167 .dram_dqm5 = IMX6SDL_DRIVE_STRENGTH,
168 .dram_dqm6 = IMX6SDL_DRIVE_STRENGTH,
169 .dram_dqm7 = IMX6SDL_DRIVE_STRENGTH,
170};
171
172/* configure MX6SOLO/DUALLITE mmdc GRP io registers */
173struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
174 .grp_ddr_type = 0x000c0000,
175 .grp_ddrmode_ctl = 0x00020000,
176 .grp_ddrpke = 0x00000000,
177 .grp_addds = IMX6SDL_DRIVE_STRENGTH,
178 .grp_ctlds = IMX6SDL_DRIVE_STRENGTH,
179 .grp_ddrmode = 0x00020000,
180 .grp_b0ds = IMX6SDL_DRIVE_STRENGTH,
181 .grp_b1ds = IMX6SDL_DRIVE_STRENGTH,
182 .grp_b2ds = IMX6SDL_DRIVE_STRENGTH,
183 .grp_b3ds = IMX6SDL_DRIVE_STRENGTH,
184 .grp_b4ds = IMX6SDL_DRIVE_STRENGTH,
185 .grp_b5ds = IMX6SDL_DRIVE_STRENGTH,
186 .grp_b6ds = IMX6SDL_DRIVE_STRENGTH,
187 .grp_b7ds = IMX6SDL_DRIVE_STRENGTH,
188};
189
190/* mt41j256 */
191static struct mx6_ddr3_cfg mt41j256 = {
192 .mem_speed = 1066,
193 .density = 2,
194 .width = 16,
195 .banks = 8,
196 .rowaddr = 13,
197 .coladdr = 10,
198 .pagesz = 2,
199 .trcd = 1375,
200 .trcmin = 4875,
201 .trasmin = 3500,
202 .SRT = 0,
203};
204
205static struct mx6_mmdc_calibration mx6dq_mmdc_calib = {
206 .p0_mpwldectrl0 = 0x000E0009,
207 .p0_mpwldectrl1 = 0x0018000E,
208 .p1_mpwldectrl0 = 0x00000007,
209 .p1_mpwldectrl1 = 0x00000000,
210 .p0_mpdgctrl0 = 0x43280334,
211 .p0_mpdgctrl1 = 0x031C0314,
212 .p1_mpdgctrl0 = 0x4318031C,
213 .p1_mpdgctrl1 = 0x030C0258,
214 .p0_mprddlctl = 0x3E343A40,
215 .p1_mprddlctl = 0x383C3844,
216 .p0_mpwrdlctl = 0x40404440,
217 .p1_mpwrdlctl = 0x4C3E4446,
218};
219
220/* DDR 64bit */
221static struct mx6_ddr_sysinfo mem_q = {
222 .ddr_type = DDR_TYPE_DDR3,
223 .dsize = 2,
224 .cs1_mirror = 0,
225 /* config for full 4GB range so that get_mem_size() works */
226 .cs_density = 32,
227 .ncs = 1,
228 .bi_on = 1,
229 .rtt_nom = 2,
230 .rtt_wr = 2,
231 .ralat = 5,
232 .walat = 0,
233 .mif3_mode = 3,
234 .rst_to_cke = 0x23,
235 .sde_to_rst = 0x10,
236};
237
238static struct mx6_mmdc_calibration mx6dl_mmdc_calib = {
239 .p0_mpwldectrl0 = 0x001F0024,
240 .p0_mpwldectrl1 = 0x00110018,
241 .p1_mpwldectrl0 = 0x001F0024,
242 .p1_mpwldectrl1 = 0x00110018,
243 .p0_mpdgctrl0 = 0x4230022C,
244 .p0_mpdgctrl1 = 0x02180220,
245 .p1_mpdgctrl0 = 0x42440248,
246 .p1_mpdgctrl1 = 0x02300238,
247 .p0_mprddlctl = 0x44444A48,
248 .p1_mprddlctl = 0x46484A42,
249 .p0_mpwrdlctl = 0x38383234,
250 .p1_mpwrdlctl = 0x3C34362E,
251};
252
253/* DDR 64bit 1GB */
254static struct mx6_ddr_sysinfo mem_dl = {
255 .dsize = 2,
256 .cs1_mirror = 0,
257 /* config for full 4GB range so that get_mem_size() works */
258 .cs_density = 32,
259 .ncs = 1,
260 .bi_on = 1,
261 .rtt_nom = 1,
262 .rtt_wr = 1,
263 .ralat = 5,
264 .walat = 0,
265 .mif3_mode = 3,
266 .rst_to_cke = 0x23,
267 .sde_to_rst = 0x10,
268};
269
270/* DDR 32bit 512MB */
271static struct mx6_ddr_sysinfo mem_s = {
272 .dsize = 1,
273 .cs1_mirror = 0,
274 /* config for full 4GB range so that get_mem_size() works */
275 .cs_density = 32,
276 .ncs = 1,
277 .bi_on = 1,
278 .rtt_nom = 1,
279 .rtt_wr = 1,
280 .ralat = 5,
281 .walat = 0,
282 .mif3_mode = 3,
283 .rst_to_cke = 0x23,
284 .sde_to_rst = 0x10,
285};
Jagan Teki2c67e882017-05-07 02:43:13 +0530286#endif /* CONFIG_MX6QDL */
287
288#ifdef CONFIG_MX6UL
289static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = {
290 .grp_addds = 0x00000030,
291 .grp_ddrmode_ctl = 0x00020000,
292 .grp_b0ds = 0x00000030,
293 .grp_ctlds = 0x00000030,
294 .grp_b1ds = 0x00000030,
295 .grp_ddrpke = 0x00000000,
296 .grp_ddrmode = 0x00020000,
297 .grp_ddr_type = 0x000c0000,
298};
299
300static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
301 .dram_dqm0 = 0x00000030,
302 .dram_dqm1 = 0x00000030,
303 .dram_ras = 0x00000030,
304 .dram_cas = 0x00000030,
305 .dram_odt0 = 0x00000030,
306 .dram_odt1 = 0x00000030,
307 .dram_sdba2 = 0x00000000,
308 .dram_sdclk_0 = 0x00000008,
309 .dram_sdqs0 = 0x00000038,
310 .dram_sdqs1 = 0x00000030,
311 .dram_reset = 0x00000030,
312};
313
314static struct mx6_mmdc_calibration mx6_mmcd_calib = {
315 .p0_mpwldectrl0 = 0x00070007,
316 .p0_mpdgctrl0 = 0x41490145,
317 .p0_mprddlctl = 0x40404546,
318 .p0_mpwrdlctl = 0x4040524D,
319};
320
321struct mx6_ddr_sysinfo ddr_sysinfo = {
322 .dsize = 0,
323 .cs_density = 20,
324 .ncs = 1,
325 .cs1_mirror = 0,
326 .rtt_wr = 2,
327 .rtt_nom = 1, /* RTT_Nom = RZQ/2 */
328 .walat = 1, /* Write additional latency */
329 .ralat = 5, /* Read additional latency */
330 .mif3_mode = 3, /* Command prediction working mode */
331 .bi_on = 1, /* Bank interleaving enabled */
332 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
333 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
334 .ddr_type = DDR_TYPE_DDR3,
335};
336
337static struct mx6_ddr3_cfg mem_ddr = {
338 .mem_speed = 800,
339 .density = 4,
340 .width = 16,
341 .banks = 8,
342#ifdef TARGET_MX6UL_ISIOT
343 .rowaddr = 15,
344#else
345 .rowaddr = 13,
346#endif
347 .coladdr = 10,
348 .pagesz = 2,
349 .trcd = 1375,
350 .trcmin = 4875,
351 .trasmin = 3500,
352};
353#endif /* CONFIG_MX6UL */
Jagan Teki215cd412017-05-07 02:43:12 +0530354
355static void ccgr_init(void)
356{
357 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
358
Jagan Teki2c67e882017-05-07 02:43:13 +0530359#ifdef CONFIG_MX6QDL
Jagan Teki215cd412017-05-07 02:43:12 +0530360 writel(0x00003F3F, &ccm->CCGR0);
361 writel(0x0030FC00, &ccm->CCGR1);
362 writel(0x000FC000, &ccm->CCGR2);
363 writel(0x3F300000, &ccm->CCGR3);
364 writel(0xFF00F300, &ccm->CCGR4);
365 writel(0x0F0000C3, &ccm->CCGR5);
366 writel(0x000003CC, &ccm->CCGR6);
Jagan Teki2c67e882017-05-07 02:43:13 +0530367#elif CONFIG_MX6UL
368 writel(0x00c03f3f, &ccm->CCGR0);
369 writel(0xfcffff00, &ccm->CCGR1);
370 writel(0x0cffffcc, &ccm->CCGR2);
371 writel(0x3f3c3030, &ccm->CCGR3);
372 writel(0xff00fffc, &ccm->CCGR4);
373 writel(0x033f30ff, &ccm->CCGR5);
374 writel(0x00c00fff, &ccm->CCGR6);
375#endif
Jagan Teki215cd412017-05-07 02:43:12 +0530376}
377
Jagan Teki215cd412017-05-07 02:43:12 +0530378static void spl_dram_init(void)
379{
Jagan Teki2c67e882017-05-07 02:43:13 +0530380#ifdef CONFIG_MX6QDL
Jagan Teki215cd412017-05-07 02:43:12 +0530381 if (is_mx6solo()) {
382 mx6sdl_dram_iocfg(32, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
383 mx6_dram_cfg(&mem_s, &mx6dl_mmdc_calib, &mt41j256);
384 } else if (is_mx6dl()) {
385 mx6sdl_dram_iocfg(64, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
386 mx6_dram_cfg(&mem_dl, &mx6dl_mmdc_calib, &mt41j256);
387 } else if (is_mx6dq()) {
388 mx6dq_dram_iocfg(64, &mx6dq_ddr_ioregs, &mx6dq_grp_ioregs);
389 mx6_dram_cfg(&mem_q, &mx6dq_mmdc_calib, &mt41j256);
390 }
Jagan Teki2c67e882017-05-07 02:43:13 +0530391#elif CONFIG_MX6UL
392 mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs);
393 mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr);
394#endif
Jagan Teki215cd412017-05-07 02:43:12 +0530395
396 udelay(100);
397}
398
399void board_init_f(ulong dummy)
400{
401 ccgr_init();
402
403 /* setup AIPS and disable watchdog */
404 arch_cpu_init();
405
Michael Trimarchia97401e2018-06-23 16:10:07 +0200406 if (!(is_mx6ul()))
407 gpr_init();
Jagan Teki215cd412017-05-07 02:43:12 +0530408
Jagan Teki215cd412017-05-07 02:43:12 +0530409 /* setup GP timer */
410 timer_init();
411
Michael Trimarchi719f9822022-12-09 15:05:49 +0530412 /* Enable device tree and early DM support*/
413 spl_early_init();
414
Jagan Teki215cd412017-05-07 02:43:12 +0530415 /* UART clocks enabled and gd valid - init serial console */
416 preloader_console_init();
417
418 /* DDR initialization */
419 spl_dram_init();
Jagan Teki215cd412017-05-07 02:43:12 +0530420}