1
2
3
4
5
6
7
8#include <common.h>
9#include <asm/io.h>
10#include <asm/arch/crm_regs.h>
11#include <asm/arch/mx6-ddr.h>
12#include <asm/arch/mx6-pins.h>
13#include <asm/arch/sys_proto.h>
14#include <asm/imx-common/boot_mode.h>
15#include <asm/imx-common/iomux-v3.h>
16#include <asm/imx-common/mxc_i2c.h>
17#include <environment.h>
18#include <spl.h>
19
20#include "gsc.h"
21#include "common.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#define RTT_NOM_120OHM
26#define GSC_EEPROM_DDR_SIZE 0x2B
27#define GSC_EEPROM_DDR_WIDTH 0x2D
28
29
30struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
31
32 .dram_sdclk_0 = 0x00020030,
33 .dram_sdclk_1 = 0x00020030,
34 .dram_cas = 0x00020030,
35 .dram_ras = 0x00020030,
36 .dram_reset = 0x00020030,
37
38 .dram_sdcke0 = 0x00003000,
39 .dram_sdcke1 = 0x00003000,
40
41 .dram_sdba2 = 0x00000000,
42
43 .dram_sdodt0 = 0x00003030,
44 .dram_sdodt1 = 0x00003030,
45
46 .dram_sdqs0 = 0x00000030,
47 .dram_sdqs1 = 0x00000030,
48 .dram_sdqs2 = 0x00000030,
49 .dram_sdqs3 = 0x00000030,
50 .dram_sdqs4 = 0x00000030,
51 .dram_sdqs5 = 0x00000030,
52 .dram_sdqs6 = 0x00000030,
53 .dram_sdqs7 = 0x00000030,
54
55
56 .dram_dqm0 = 0x00020030,
57 .dram_dqm1 = 0x00020030,
58 .dram_dqm2 = 0x00020030,
59 .dram_dqm3 = 0x00020030,
60 .dram_dqm4 = 0x00020030,
61 .dram_dqm5 = 0x00020030,
62 .dram_dqm6 = 0x00020030,
63 .dram_dqm7 = 0x00020030,
64};
65
66
67struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
68
69 .grp_ddr_type = 0x000c0000,
70 .grp_ddrmode_ctl = 0x00020000,
71
72 .grp_ddrpke = 0x00000000,
73
74 .grp_addds = 0x00000030,
75
76 .grp_ctlds = 0x00000030,
77
78 .grp_ddrmode = 0x00020000,
79 .grp_b0ds = 0x00000030,
80 .grp_b1ds = 0x00000030,
81 .grp_b2ds = 0x00000030,
82 .grp_b3ds = 0x00000030,
83 .grp_b4ds = 0x00000030,
84 .grp_b5ds = 0x00000030,
85 .grp_b6ds = 0x00000030,
86 .grp_b7ds = 0x00000030,
87};
88
89
90struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
91
92 .dram_sdclk_0 = 0x00020030,
93 .dram_sdclk_1 = 0x00020030,
94 .dram_cas = 0x00020030,
95 .dram_ras = 0x00020030,
96 .dram_reset = 0x00020030,
97
98 .dram_sdcke0 = 0x00003000,
99 .dram_sdcke1 = 0x00003000,
100
101 .dram_sdba2 = 0x00000000,
102
103 .dram_sdodt0 = 0x00003030,
104 .dram_sdodt1 = 0x00003030,
105
106 .dram_sdqs0 = 0x00000030,
107 .dram_sdqs1 = 0x00000030,
108 .dram_sdqs2 = 0x00000030,
109 .dram_sdqs3 = 0x00000030,
110 .dram_sdqs4 = 0x00000030,
111 .dram_sdqs5 = 0x00000030,
112 .dram_sdqs6 = 0x00000030,
113 .dram_sdqs7 = 0x00000030,
114
115
116 .dram_dqm0 = 0x00020030,
117 .dram_dqm1 = 0x00020030,
118 .dram_dqm2 = 0x00020030,
119 .dram_dqm3 = 0x00020030,
120 .dram_dqm4 = 0x00020030,
121 .dram_dqm5 = 0x00020030,
122 .dram_dqm6 = 0x00020030,
123 .dram_dqm7 = 0x00020030,
124};
125
126
127struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
128
129 .grp_ddr_type = 0x000c0000,
130
131 .grp_ddrmode_ctl = 0x00020000,
132
133 .grp_ddrpke = 0x00000000,
134
135 .grp_addds = 0x00000030,
136
137 .grp_ctlds = 0x00000030,
138
139 .grp_ddrmode = 0x00020000,
140 .grp_b0ds = 0x00000030,
141 .grp_b1ds = 0x00000030,
142 .grp_b2ds = 0x00000030,
143 .grp_b3ds = 0x00000030,
144 .grp_b4ds = 0x00000030,
145 .grp_b5ds = 0x00000030,
146 .grp_b6ds = 0x00000030,
147 .grp_b7ds = 0x00000030,
148};
149
150
151static struct mx6_ddr3_cfg mt41k64m16jt_125 = {
152 .mem_speed = 1600,
153 .density = 1,
154 .width = 16,
155 .banks = 8,
156 .rowaddr = 13,
157 .coladdr = 10,
158 .pagesz = 2,
159 .trcd = 1375,
160 .trcmin = 4875,
161 .trasmin = 3500,
162};
163
164
165static struct mx6_ddr3_cfg mt41k128m16jt_125 = {
166 .mem_speed = 1600,
167 .density = 2,
168 .width = 16,
169 .banks = 8,
170 .rowaddr = 14,
171 .coladdr = 10,
172 .pagesz = 2,
173 .trcd = 1375,
174 .trcmin = 4875,
175 .trasmin = 3500,
176};
177
178
179static struct mx6_ddr3_cfg mt41k256m16ha_125 = {
180 .mem_speed = 1600,
181 .density = 4,
182 .width = 16,
183 .banks = 8,
184 .rowaddr = 15,
185 .coladdr = 10,
186 .pagesz = 2,
187 .trcd = 1375,
188 .trcmin = 4875,
189 .trasmin = 3500,
190};
191
192
193
194
195static struct mx6_mmdc_calibration mx6sdl_64x16_mmdc_calib = {
196
197 .p0_mpwldectrl0 = 0x004C004E,
198 .p0_mpwldectrl1 = 0x00440044,
199
200 .p0_mpdgctrl0 = 0x42440247,
201 .p0_mpdgctrl1 = 0x02310232,
202
203 .p0_mprddlctl = 0x45424746,
204
205 .p0_mpwrdlctl = 0x33382C31,
206};
207
208static struct mx6_mmdc_calibration mx6dq_256x16_mmdc_calib = {
209
210 .p0_mpwldectrl0 = 0x001B0016,
211 .p0_mpwldectrl1 = 0x000C000E,
212
213 .p0_mpdgctrl0 = 0x4324033A,
214 .p0_mpdgctrl1 = 0x00000000,
215
216 .p0_mprddlctl = 0x40403438,
217
218 .p0_mpwrdlctl = 0x40403D36,
219};
220
221static struct mx6_mmdc_calibration mx6sdl_256x16_mmdc_calib = {
222
223 .p0_mpwldectrl0 = 0x00420043,
224 .p0_mpwldectrl1 = 0x0016001A,
225
226 .p0_mpdgctrl0 = 0x4238023B,
227 .p0_mpdgctrl1 = 0x00000000,
228
229 .p0_mprddlctl = 0x40404849,
230
231 .p0_mpwrdlctl = 0x40402E2F,
232};
233
234static struct mx6_mmdc_calibration mx6dq_128x32_mmdc_calib = {
235
236 .p0_mpwldectrl0 = 0x00190017,
237 .p0_mpwldectrl1 = 0x00140026,
238
239 .p0_mpdgctrl0 = 0x43380347,
240 .p0_mpdgctrl1 = 0x433C034D,
241
242 .p0_mprddlctl = 0x3C313539,
243
244 .p0_mpwrdlctl = 0x36393C39,
245};
246
247static struct mx6_mmdc_calibration mx6sdl_128x32_mmdc_calib = {
248
249 .p0_mpwldectrl0 = 0x003C003C,
250 .p0_mpwldectrl1 = 0x001F002A,
251
252 .p0_mpdgctrl0 = 0x42410244,
253 .p0_mpdgctrl1 = 0x4234023A,
254
255 .p0_mprddlctl = 0x484A4C4B,
256
257 .p0_mpwrdlctl = 0x33342B32,
258};
259
260static struct mx6_mmdc_calibration mx6dq_128x64_mmdc_calib = {
261
262 .p0_mpwldectrl0 = 0x00190017,
263 .p0_mpwldectrl1 = 0x00140026,
264 .p1_mpwldectrl0 = 0x0021001C,
265 .p1_mpwldectrl1 = 0x0011001D,
266
267 .p0_mpdgctrl0 = 0x43380347,
268 .p0_mpdgctrl1 = 0x433C034D,
269 .p1_mpdgctrl0 = 0x032C0324,
270 .p1_mpdgctrl1 = 0x03310232,
271
272 .p0_mprddlctl = 0x3C313539,
273 .p1_mprddlctl = 0x37343141,
274
275 .p0_mpwrdlctl = 0x36393C39,
276 .p1_mpwrdlctl = 0x42344438,
277};
278
279static struct mx6_mmdc_calibration mx6sdl_128x64_mmdc_calib = {
280
281 .p0_mpwldectrl0 = 0x003C003C,
282 .p0_mpwldectrl1 = 0x001F002A,
283 .p1_mpwldectrl0 = 0x00330038,
284 .p1_mpwldectrl1 = 0x0022003F,
285
286 .p0_mpdgctrl0 = 0x42410244,
287 .p0_mpdgctrl1 = 0x4234023A,
288 .p1_mpdgctrl0 = 0x022D022D,
289 .p1_mpdgctrl1 = 0x021C0228,
290
291 .p0_mprddlctl = 0x484A4C4B,
292 .p1_mprddlctl = 0x4B4D4E4B,
293
294 .p0_mpwrdlctl = 0x33342B32,
295 .p1_mpwrdlctl = 0x3933332B,
296};
297
298static struct mx6_mmdc_calibration mx6dq_256x32_mmdc_calib = {
299
300 .p0_mpwldectrl0 = 0x001E001A,
301 .p0_mpwldectrl1 = 0x0026001F,
302
303 .p0_mpdgctrl0 = 0x43370349,
304 .p0_mpdgctrl1 = 0x032D0327,
305
306 .p0_mprddlctl = 0x3D303639,
307
308 .p0_mpwrdlctl = 0x32363934,
309};
310
311static struct mx6_mmdc_calibration mx6sdl_256x32_mmdc_calib = {
312
313 .p0_mpwldectrl0 = 0X00480047,
314 .p0_mpwldectrl1 = 0X003D003F,
315
316 .p0_mpdgctrl0 = 0X423E0241,
317 .p0_mpdgctrl1 = 0X022B022C,
318
319 .p0_mprddlctl = 0X49454A4A,
320
321 .p0_mpwrdlctl = 0X2E372C32,
322};
323
324static struct mx6_mmdc_calibration mx6dq_256x64_mmdc_calib = {
325
326 .p0_mpwldectrl0 = 0X00220021,
327 .p0_mpwldectrl1 = 0X00200030,
328 .p1_mpwldectrl0 = 0X002D0027,
329 .p1_mpwldectrl1 = 0X00150026,
330
331 .p0_mpdgctrl0 = 0x43330342,
332 .p0_mpdgctrl1 = 0x0339034A,
333 .p1_mpdgctrl0 = 0x032F0325,
334 .p1_mpdgctrl1 = 0x032F022E,
335
336 .p0_mprddlctl = 0X3A2E3437,
337 .p1_mprddlctl = 0X35312F3F,
338
339 .p0_mpwrdlctl = 0X33363B37,
340 .p1_mpwrdlctl = 0X40304239,
341};
342
343static void spl_dram_init(int width, int size_mb, int board_model)
344{
345 struct mx6_ddr3_cfg *mem = NULL;
346 struct mx6_mmdc_calibration *calib = NULL;
347 struct mx6_ddr_sysinfo sysinfo = {
348
349 .dsize = width/32,
350
351 .cs_density = 32,
352
353 .ncs = 1,
354 .cs1_mirror = 0,
355 .rtt_wr = 1 ,
356#ifdef RTT_NOM_120OHM
357 .rtt_nom = 2 ,
358#else
359 .rtt_nom = 1 ,
360#endif
361 .walat = 1,
362 .ralat = 5,
363 .mif3_mode = 3,
364 .bi_on = 1,
365 .sde_to_rst = 0x10,
366 .rst_to_cke = 0x23,
367 .pd_fast_exit = 1,
368 .ddr_type = DDR_TYPE_DDR3,
369 };
370
371
372
373
374
375
376
377
378 if (width == 16 && size_mb == 128) {
379 mem = &mt41k64m16jt_125;
380 if (is_cpu_type(MXC_CPU_MX6Q))
381 ;
382 else
383 calib = &mx6sdl_64x16_mmdc_calib;
384 debug("1gB density\n");
385 } else if (width == 16 && size_mb == 256) {
386
387 mem = &mt41k128m16jt_125;
388 if (is_cpu_type(MXC_CPU_MX6Q))
389 calib = &mx6dq_128x32_mmdc_calib;
390 else
391 calib = &mx6sdl_128x32_mmdc_calib;
392 debug("2gB density\n");
393 } else if (width == 16 && size_mb == 512) {
394 mem = &mt41k256m16ha_125;
395 if (is_cpu_type(MXC_CPU_MX6Q))
396 calib = &mx6dq_256x16_mmdc_calib;
397 else
398 calib = &mx6sdl_256x16_mmdc_calib;
399 debug("4gB density\n");
400 } else if (width == 32 && size_mb == 256) {
401
402 mem = &mt41k64m16jt_125;
403 if (is_cpu_type(MXC_CPU_MX6Q))
404 ;
405 else
406 calib = &mx6sdl_64x16_mmdc_calib;
407 debug("1gB density\n");
408 } else if (width == 32 && size_mb == 512) {
409 mem = &mt41k128m16jt_125;
410 if (is_cpu_type(MXC_CPU_MX6Q))
411 calib = &mx6dq_128x32_mmdc_calib;
412 else
413 calib = &mx6sdl_128x32_mmdc_calib;
414 debug("2gB density\n");
415 } else if (width == 32 && size_mb == 1024) {
416 mem = &mt41k256m16ha_125;
417 if (is_cpu_type(MXC_CPU_MX6Q))
418 calib = &mx6dq_256x32_mmdc_calib;
419 else
420 calib = &mx6sdl_256x32_mmdc_calib;
421 debug("4gB density\n");
422 } else if (width == 64 && size_mb == 512) {
423 mem = &mt41k64m16jt_125;
424 debug("1gB density\n");
425 } else if (width == 64 && size_mb == 1024) {
426 mem = &mt41k128m16jt_125;
427 if (is_cpu_type(MXC_CPU_MX6Q))
428 calib = &mx6dq_128x64_mmdc_calib;
429 else
430 calib = &mx6sdl_128x64_mmdc_calib;
431 debug("2gB density\n");
432 } else if (width == 64 && size_mb == 2048) {
433 mem = &mt41k256m16ha_125;
434 if (is_cpu_type(MXC_CPU_MX6Q))
435 calib = &mx6dq_256x64_mmdc_calib;
436 debug("4gB density\n");
437 }
438
439 if (!(mem && calib)) {
440 puts("Error: Invalid Calibration/Board Configuration\n");
441 printf("MEM : %s\n", mem ? "OKAY" : "NULL");
442 printf("CALIB : %s\n", calib ? "OKAY" : "NULL");
443 printf("CPUTYPE: %s\n",
444 is_cpu_type(MXC_CPU_MX6Q) ? "IMX6Q" : "IMX6DL");
445 printf("SIZE_MB: %d\n", size_mb);
446 printf("WIDTH : %d\n", width);
447 hang();
448 }
449
450 if (is_cpu_type(MXC_CPU_MX6Q))
451 mx6dq_dram_iocfg(width, &mx6dq_ddr_ioregs,
452 &mx6dq_grp_ioregs);
453 else
454 mx6sdl_dram_iocfg(width, &mx6sdl_ddr_ioregs,
455 &mx6sdl_grp_ioregs);
456 mx6_dram_cfg(&sysinfo, calib, mem);
457}
458
459static void ccgr_init(void)
460{
461 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
462
463 writel(0x00C03F3F, &ccm->CCGR0);
464 writel(0x0030FC03, &ccm->CCGR1);
465 writel(0x0FFFC000, &ccm->CCGR2);
466 writel(0x3FF00000, &ccm->CCGR3);
467 writel(0xFFFFF300, &ccm->CCGR4);
468 writel(0x0F0000C3, &ccm->CCGR5);
469 writel(0x000003FF, &ccm->CCGR6);
470}
471
472static void gpr_init(void)
473{
474 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
475
476
477 writel(0xF00000CF, &iomux->gpr[4]);
478
479 writel(0x007F007F, &iomux->gpr[6]);
480 writel(0x007F007F, &iomux->gpr[7]);
481}
482
483
484
485
486
487
488void board_init_f(ulong dummy)
489{
490 struct ventana_board_info ventana_info;
491 int board_model;
492
493
494 ccgr_init();
495
496
497 arch_cpu_init();
498
499
500 gpr_init();
501
502
503 setup_iomux_uart();
504 setup_ventana_i2c();
505
506
507 timer_init();
508
509
510 preloader_console_init();
511
512
513 board_model = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
514
515
516 setup_iomux_gpio(board_model, &ventana_info);
517
518
519 if (GW_UNKNOWN == board_model)
520 hang();
521
522
523 spl_dram_init(8 << ventana_info.sdram_width,
524 16 << ventana_info.sdram_size,
525 board_model);
526
527
528 memset(__bss_start, 0, __bss_end - __bss_start);
529
530
531 gsc_boot_wd_disable();
532}
533
534
535
536void spl_board_init(void)
537{
538
539 u32 boot_device = spl_boot_device();
540
541 switch (boot_device) {
542 case BOOT_DEVICE_MMC1:
543 puts("Booting from MMC\n");
544 break;
545 case BOOT_DEVICE_NAND:
546 puts("Booting from NAND\n");
547 break;
548 case BOOT_DEVICE_SATA:
549 puts("Booting from SATA\n");
550 break;
551 default:
552 puts("Unknown boot device\n");
553 }
554
555
556 setup_pmic();
557}
558
559#ifdef CONFIG_SPL_OS_BOOT
560
561int spl_start_uboot(void)
562{
563 int ret = 1;
564
565 debug("%s\n", __func__);
566#ifdef CONFIG_SPL_ENV_SUPPORT
567 env_init();
568 env_relocate_spec();
569 debug("boot_os=%s\n", getenv("boot_os"));
570 if (getenv_yesno("boot_os") == 1)
571 ret = 0;
572#endif
573 debug("%s booting %s\n", __func__, ret ? "uboot" : "linux");
574 return ret;
575}
576#endif
577
578void reset_cpu(ulong addr)
579{
580}
581