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