1
2
3
4
5
6
7#include <common.h>
8#include <env.h>
9#include <gsc.h>
10#include <hang.h>
11#include <i2c.h>
12#include <init.h>
13#include <spl.h>
14#include <asm/arch/crm_regs.h>
15#include <asm/arch/mx6-ddr.h>
16#include <asm/arch/mx6-pins.h>
17#include <asm/arch/sys_proto.h>
18#include <asm/mach-imx/mxc_i2c.h>
19#include <linux/delay.h>
20#include <power/mp5416.h>
21#include <power/pmic.h>
22#include <power/pfuze100_pmic.h>
23#include <power/ltc3676_pmic.h>
24
25#include "common.h"
26
27#define RTT_NOM_120OHM
28#define GSC_EEPROM_DDR_SIZE 0x2B
29#define GSC_EEPROM_DDR_WIDTH 0x2D
30
31
32struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
33
34 .dram_sdclk_0 = 0x00020030,
35 .dram_sdclk_1 = 0x00020030,
36 .dram_cas = 0x00020030,
37 .dram_ras = 0x00020030,
38 .dram_reset = 0x00020030,
39
40 .dram_sdcke0 = 0x00003000,
41 .dram_sdcke1 = 0x00003000,
42
43 .dram_sdba2 = 0x00000000,
44
45 .dram_sdodt0 = 0x00003030,
46 .dram_sdodt1 = 0x00003030,
47
48 .dram_sdqs0 = 0x00000030,
49 .dram_sdqs1 = 0x00000030,
50 .dram_sdqs2 = 0x00000030,
51 .dram_sdqs3 = 0x00000030,
52 .dram_sdqs4 = 0x00000030,
53 .dram_sdqs5 = 0x00000030,
54 .dram_sdqs6 = 0x00000030,
55 .dram_sdqs7 = 0x00000030,
56
57
58 .dram_dqm0 = 0x00020030,
59 .dram_dqm1 = 0x00020030,
60 .dram_dqm2 = 0x00020030,
61 .dram_dqm3 = 0x00020030,
62 .dram_dqm4 = 0x00020030,
63 .dram_dqm5 = 0x00020030,
64 .dram_dqm6 = 0x00020030,
65 .dram_dqm7 = 0x00020030,
66};
67
68
69struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
70
71 .grp_ddr_type = 0x000c0000,
72 .grp_ddrmode_ctl = 0x00020000,
73
74 .grp_ddrpke = 0x00000000,
75
76 .grp_addds = 0x00000030,
77
78 .grp_ctlds = 0x00000030,
79
80 .grp_ddrmode = 0x00020000,
81 .grp_b0ds = 0x00000030,
82 .grp_b1ds = 0x00000030,
83 .grp_b2ds = 0x00000030,
84 .grp_b3ds = 0x00000030,
85 .grp_b4ds = 0x00000030,
86 .grp_b5ds = 0x00000030,
87 .grp_b6ds = 0x00000030,
88 .grp_b7ds = 0x00000030,
89};
90
91
92struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
93
94 .dram_sdclk_0 = 0x00020030,
95 .dram_sdclk_1 = 0x00020030,
96 .dram_cas = 0x00020030,
97 .dram_ras = 0x00020030,
98 .dram_reset = 0x00020030,
99
100 .dram_sdcke0 = 0x00003000,
101 .dram_sdcke1 = 0x00003000,
102
103 .dram_sdba2 = 0x00000000,
104
105 .dram_sdodt0 = 0x00003030,
106 .dram_sdodt1 = 0x00003030,
107
108 .dram_sdqs0 = 0x00000030,
109 .dram_sdqs1 = 0x00000030,
110 .dram_sdqs2 = 0x00000030,
111 .dram_sdqs3 = 0x00000030,
112 .dram_sdqs4 = 0x00000030,
113 .dram_sdqs5 = 0x00000030,
114 .dram_sdqs6 = 0x00000030,
115 .dram_sdqs7 = 0x00000030,
116
117
118 .dram_dqm0 = 0x00020030,
119 .dram_dqm1 = 0x00020030,
120 .dram_dqm2 = 0x00020030,
121 .dram_dqm3 = 0x00020030,
122 .dram_dqm4 = 0x00020030,
123 .dram_dqm5 = 0x00020030,
124 .dram_dqm6 = 0x00020030,
125 .dram_dqm7 = 0x00020030,
126};
127
128
129struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
130
131 .grp_ddr_type = 0x000c0000,
132
133 .grp_ddrmode_ctl = 0x00020000,
134
135 .grp_ddrpke = 0x00000000,
136
137 .grp_addds = 0x00000030,
138
139 .grp_ctlds = 0x00000030,
140
141 .grp_ddrmode = 0x00020000,
142 .grp_b0ds = 0x00000030,
143 .grp_b1ds = 0x00000030,
144 .grp_b2ds = 0x00000030,
145 .grp_b3ds = 0x00000030,
146 .grp_b4ds = 0x00000030,
147 .grp_b5ds = 0x00000030,
148 .grp_b6ds = 0x00000030,
149 .grp_b7ds = 0x00000030,
150};
151
152
153static struct mx6_ddr3_cfg mt41k64m16jt_125 = {
154 .mem_speed = 1600,
155 .density = 1,
156 .width = 16,
157 .banks = 8,
158 .rowaddr = 13,
159 .coladdr = 10,
160 .pagesz = 2,
161 .trcd = 1375,
162 .trcmin = 4875,
163 .trasmin = 3500,
164};
165
166
167static struct mx6_ddr3_cfg mt41k128m16jt_125 = {
168 .mem_speed = 1600,
169 .density = 2,
170 .width = 16,
171 .banks = 8,
172 .rowaddr = 14,
173 .coladdr = 10,
174 .pagesz = 2,
175 .trcd = 1375,
176 .trcmin = 4875,
177 .trasmin = 3500,
178};
179
180
181static struct mx6_ddr3_cfg mt41k256m16ha_125 = {
182 .mem_speed = 1600,
183 .density = 4,
184 .width = 16,
185 .banks = 8,
186 .rowaddr = 15,
187 .coladdr = 10,
188 .pagesz = 2,
189 .trcd = 1375,
190 .trcmin = 4875,
191 .trasmin = 3500,
192};
193
194
195static struct mx6_ddr3_cfg mt41k512m16ha_125 = {
196 .mem_speed = 1600,
197 .density = 8,
198 .width = 16,
199 .banks = 8,
200 .rowaddr = 16,
201 .coladdr = 10,
202 .pagesz = 2,
203 .trcd = 1375,
204 .trcmin = 4875,
205 .trasmin = 3500,
206};
207
208
209
210
211static struct mx6_mmdc_calibration mx6sdl_64x16_mmdc_calib = {
212
213 .p0_mpwldectrl0 = 0x004C004E,
214 .p0_mpwldectrl1 = 0x00440044,
215
216 .p0_mpdgctrl0 = 0x42440247,
217 .p0_mpdgctrl1 = 0x02310232,
218
219 .p0_mprddlctl = 0x45424746,
220
221 .p0_mpwrdlctl = 0x33382C31,
222};
223
224
225static struct mx6_mmdc_calibration mx6dq_64x64_mmdc_calib = {
226
227 .p0_mpwldectrl0 = 0x00190017,
228 .p0_mpwldectrl1 = 0x00140026,
229 .p1_mpwldectrl0 = 0x0021001C,
230 .p1_mpwldectrl1 = 0x0011001D,
231
232 .p0_mpdgctrl0 = 0x43380347,
233 .p0_mpdgctrl1 = 0x433C034D,
234 .p1_mpdgctrl0 = 0x032C0324,
235 .p1_mpdgctrl1 = 0x03310232,
236
237 .p0_mprddlctl = 0x3C313539,
238 .p1_mprddlctl = 0x37343141,
239
240 .p0_mpwrdlctl = 0x36393C39,
241 .p1_mpwrdlctl = 0x42344438,
242};
243
244
245static struct mx6_mmdc_calibration mx6sdl_64x64_mmdc_calib = {
246
247 .p0_mpwldectrl0 = 0x003C003C,
248 .p0_mpwldectrl1 = 0x001F002A,
249 .p1_mpwldectrl0 = 0x00330038,
250 .p1_mpwldectrl1 = 0x0022003F,
251
252 .p0_mpdgctrl0 = 0x42410244,
253 .p0_mpdgctrl1 = 0x4234023A,
254 .p1_mpdgctrl0 = 0x022D022D,
255 .p1_mpdgctrl1 = 0x021C0228,
256
257 .p0_mprddlctl = 0x484A4C4B,
258 .p1_mprddlctl = 0x4B4D4E4B,
259
260 .p0_mpwrdlctl = 0x33342B32,
261 .p1_mpwrdlctl = 0x3933332B,
262};
263
264static struct mx6_mmdc_calibration mx6dq_256x16_mmdc_calib = {
265
266 .p0_mpwldectrl0 = 0x001B0016,
267 .p0_mpwldectrl1 = 0x000C000E,
268
269 .p0_mpdgctrl0 = 0x4324033A,
270 .p0_mpdgctrl1 = 0x00000000,
271
272 .p0_mprddlctl = 0x40403438,
273
274 .p0_mpwrdlctl = 0x40403D36,
275};
276
277static struct mx6_mmdc_calibration mx6sdl_256x16_mmdc_calib = {
278
279 .p0_mpwldectrl0 = 0x00420043,
280 .p0_mpwldectrl1 = 0x0016001A,
281
282 .p0_mpdgctrl0 = 0x4238023B,
283 .p0_mpdgctrl1 = 0x00000000,
284
285 .p0_mprddlctl = 0x40404849,
286
287 .p0_mpwrdlctl = 0x40402E2F,
288};
289
290static struct mx6_mmdc_calibration mx6dq_128x32_mmdc_calib = {
291
292 .p0_mpwldectrl0 = 0x00190017,
293 .p0_mpwldectrl1 = 0x00140026,
294
295 .p0_mpdgctrl0 = 0x43380347,
296 .p0_mpdgctrl1 = 0x433C034D,
297
298 .p0_mprddlctl = 0x3C313539,
299
300 .p0_mpwrdlctl = 0x36393C39,
301};
302
303static struct mx6_mmdc_calibration mx6sdl_128x32_mmdc_calib = {
304
305 .p0_mpwldectrl0 = 0x003C003C,
306 .p0_mpwldectrl1 = 0x001F002A,
307
308 .p0_mpdgctrl0 = 0x42410244,
309 .p0_mpdgctrl1 = 0x4234023A,
310
311 .p0_mprddlctl = 0x484A4C4B,
312
313 .p0_mpwrdlctl = 0x33342B32,
314};
315
316static struct mx6_mmdc_calibration mx6dq_128x64_mmdc_calib = {
317
318 .p0_mpwldectrl0 = 0x00190017,
319 .p0_mpwldectrl1 = 0x00140026,
320 .p1_mpwldectrl0 = 0x0021001C,
321 .p1_mpwldectrl1 = 0x0011001D,
322
323 .p0_mpdgctrl0 = 0x43380347,
324 .p0_mpdgctrl1 = 0x433C034D,
325 .p1_mpdgctrl0 = 0x032C0324,
326 .p1_mpdgctrl1 = 0x03310232,
327
328 .p0_mprddlctl = 0x3C313539,
329 .p1_mprddlctl = 0x37343141,
330
331 .p0_mpwrdlctl = 0x36393C39,
332 .p1_mpwrdlctl = 0x42344438,
333};
334
335static struct mx6_mmdc_calibration mx6sdl_128x64_mmdc_calib = {
336
337 .p0_mpwldectrl0 = 0x003C003C,
338 .p0_mpwldectrl1 = 0x001F002A,
339 .p1_mpwldectrl0 = 0x00330038,
340 .p1_mpwldectrl1 = 0x0022003F,
341
342 .p0_mpdgctrl0 = 0x42410244,
343 .p0_mpdgctrl1 = 0x4234023A,
344 .p1_mpdgctrl0 = 0x022D022D,
345 .p1_mpdgctrl1 = 0x021C0228,
346
347 .p0_mprddlctl = 0x484A4C4B,
348 .p1_mprddlctl = 0x4B4D4E4B,
349
350 .p0_mpwrdlctl = 0x33342B32,
351 .p1_mpwrdlctl = 0x3933332B,
352};
353
354static struct mx6_mmdc_calibration mx6dq_256x32_mmdc_calib = {
355
356 .p0_mpwldectrl0 = 0x001E001A,
357 .p0_mpwldectrl1 = 0x0026001F,
358
359 .p0_mpdgctrl0 = 0x43370349,
360 .p0_mpdgctrl1 = 0x032D0327,
361
362 .p0_mprddlctl = 0x3D303639,
363
364 .p0_mpwrdlctl = 0x32363934,
365};
366
367static struct mx6_mmdc_calibration mx6sdl_256x32_mmdc_calib = {
368
369 .p0_mpwldectrl0 = 0X00480047,
370 .p0_mpwldectrl1 = 0X003D003F,
371
372 .p0_mpdgctrl0 = 0X423E0241,
373 .p0_mpdgctrl1 = 0X022B022C,
374
375 .p0_mprddlctl = 0X49454A4A,
376
377 .p0_mpwrdlctl = 0X2E372C32,
378};
379
380static struct mx6_mmdc_calibration mx6dq_256x64_mmdc_calib = {
381
382 .p0_mpwldectrl0 = 0X00220021,
383 .p0_mpwldectrl1 = 0X00200030,
384 .p1_mpwldectrl0 = 0X002D0027,
385 .p1_mpwldectrl1 = 0X00150026,
386
387 .p0_mpdgctrl0 = 0x43330342,
388 .p0_mpdgctrl1 = 0x0339034A,
389 .p1_mpdgctrl0 = 0x032F0325,
390 .p1_mpdgctrl1 = 0x032F022E,
391
392 .p0_mprddlctl = 0X3A2E3437,
393 .p1_mprddlctl = 0X35312F3F,
394
395 .p0_mpwrdlctl = 0X33363B37,
396 .p1_mpwrdlctl = 0X40304239,
397};
398
399static struct mx6_mmdc_calibration mx6sdl_256x64_mmdc_calib = {
400
401 .p0_mpwldectrl0 = 0x0048004A,
402 .p0_mpwldectrl1 = 0x003F004A,
403 .p1_mpwldectrl0 = 0x001E0028,
404 .p1_mpwldectrl1 = 0x002C0043,
405
406 .p0_mpdgctrl0 = 0x02250219,
407 .p0_mpdgctrl1 = 0x01790202,
408 .p1_mpdgctrl0 = 0x02080208,
409 .p1_mpdgctrl1 = 0x016C0175,
410
411 .p0_mprddlctl = 0x4A4C4D4C,
412 .p1_mprddlctl = 0x494C4A48,
413
414 .p0_mpwrdlctl = 0x403F3437,
415 .p1_mpwrdlctl = 0x383A3930,
416};
417
418static struct mx6_mmdc_calibration mx6sdl_256x64x2_mmdc_calib = {
419
420 .p0_mpwldectrl0 = 0x001F003F,
421 .p0_mpwldectrl1 = 0x001F001F,
422 .p1_mpwldectrl0 = 0x001F004E,
423 .p1_mpwldectrl1 = 0x0059001F,
424
425 .p0_mpdgctrl0 = 0x42220225,
426 .p0_mpdgctrl1 = 0x0213021F,
427 .p1_mpdgctrl0 = 0x022C0242,
428 .p1_mpdgctrl1 = 0x022C0244,
429
430 .p0_mprddlctl = 0x474A4C4A,
431 .p1_mprddlctl = 0x48494C45,
432
433 .p0_mpwrdlctl = 0x3F3F3F36,
434 .p1_mpwrdlctl = 0x3F36363F,
435};
436
437static struct mx6_mmdc_calibration mx6sdl_128x64x2_mmdc_calib = {
438
439 .p0_mpwldectrl0 = 0x001F003F,
440 .p0_mpwldectrl1 = 0x001F001F,
441 .p1_mpwldectrl0 = 0x001F004E,
442 .p1_mpwldectrl1 = 0x0059001F,
443
444 .p0_mpdgctrl0 = 0x42220225,
445 .p0_mpdgctrl1 = 0x0213021F,
446 .p1_mpdgctrl0 = 0x022C0242,
447 .p1_mpdgctrl1 = 0x022C0244,
448
449 .p0_mprddlctl = 0x474A4C4A,
450 .p1_mprddlctl = 0x48494C45,
451
452 .p0_mpwrdlctl = 0x3F3F3F36,
453 .p1_mpwrdlctl = 0x3F36363F,
454};
455
456static struct mx6_mmdc_calibration mx6dq_512x32_mmdc_calib = {
457
458 .p0_mpwldectrl0 = 0x002A0025,
459 .p0_mpwldectrl1 = 0x003A002A,
460
461 .p0_mpdgctrl0 = 0x43430356,
462 .p0_mpdgctrl1 = 0x033C0335,
463
464 .p0_mprddlctl = 0x4B373F42,
465
466 .p0_mpwrdlctl = 0x303E3C36,
467};
468
469static struct mx6_mmdc_calibration mx6dq_512x64_mmdc_calib = {
470
471 .p0_mpwldectrl0 = 0x00230020,
472 .p0_mpwldectrl1 = 0x002F002A,
473 .p1_mpwldectrl0 = 0x001D0027,
474 .p1_mpwldectrl1 = 0x00100023,
475
476 .p0_mpdgctrl0 = 0x03250339,
477 .p0_mpdgctrl1 = 0x031C0316,
478 .p1_mpdgctrl0 = 0x03210331,
479 .p1_mpdgctrl1 = 0x031C025A,
480
481 .p0_mprddlctl = 0x40373C40,
482 .p1_mprddlctl = 0x3A373646,
483
484 .p0_mpwrdlctl = 0x2E353933,
485 .p1_mpwrdlctl = 0x3C2F3F35,
486};
487
488static void spl_dram_init(int width, int size_mb, int board_model)
489{
490 struct mx6_ddr3_cfg *mem = NULL;
491 struct mx6_mmdc_calibration *calib = NULL;
492 struct mx6_ddr_sysinfo sysinfo = {
493
494 .dsize = width/32,
495
496 .cs_density = 32,
497
498 .ncs = 1,
499 .cs1_mirror = 0,
500 .rtt_wr = 1 ,
501#ifdef RTT_NOM_120OHM
502 .rtt_nom = 2 ,
503#else
504 .rtt_nom = 1 ,
505#endif
506 .walat = 1,
507 .ralat = 5,
508 .mif3_mode = 3,
509 .bi_on = 1,
510 .sde_to_rst = 0x10,
511 .rst_to_cke = 0x23,
512 .pd_fast_exit = 1,
513 .ddr_type = DDR_TYPE_DDR3,
514 .refsel = 1,
515 .refr = 7,
516 };
517
518
519
520
521
522
523
524
525 if (width == 16 && size_mb == 128) {
526 mem = &mt41k64m16jt_125;
527 if (is_cpu_type(MXC_CPU_MX6Q))
528 ;
529 else
530 calib = &mx6sdl_64x16_mmdc_calib;
531 debug("1gB density\n");
532 } else if (width == 16 && size_mb == 256) {
533
534 mem = &mt41k128m16jt_125;
535 if (is_cpu_type(MXC_CPU_MX6Q))
536 calib = &mx6dq_128x32_mmdc_calib;
537 else
538 calib = &mx6sdl_128x32_mmdc_calib;
539 debug("2gB density\n");
540 } else if (width == 16 && size_mb == 512) {
541 mem = &mt41k256m16ha_125;
542 if (is_cpu_type(MXC_CPU_MX6Q))
543 calib = &mx6dq_256x16_mmdc_calib;
544 else
545 calib = &mx6sdl_256x16_mmdc_calib;
546 debug("4gB density\n");
547 } else if (width == 16 && size_mb == 1024) {
548 mem = &mt41k512m16ha_125;
549 if (is_cpu_type(MXC_CPU_MX6Q))
550 calib = &mx6dq_512x32_mmdc_calib;
551 debug("8gB density\n");
552 } else if (width == 32 && size_mb == 256) {
553
554 mem = &mt41k64m16jt_125;
555 if (is_cpu_type(MXC_CPU_MX6Q))
556 ;
557 else
558 calib = &mx6sdl_64x16_mmdc_calib;
559 debug("1gB density\n");
560 } else if (width == 32 && size_mb == 512) {
561 mem = &mt41k128m16jt_125;
562 if (is_cpu_type(MXC_CPU_MX6Q))
563 calib = &mx6dq_128x32_mmdc_calib;
564 else
565 calib = &mx6sdl_128x32_mmdc_calib;
566 debug("2gB density\n");
567 } else if (width == 32 && size_mb == 1024) {
568 mem = &mt41k256m16ha_125;
569 if (is_cpu_type(MXC_CPU_MX6Q))
570 calib = &mx6dq_256x32_mmdc_calib;
571 else
572 calib = &mx6sdl_256x32_mmdc_calib;
573 debug("4gB density\n");
574 } else if (width == 32 && size_mb == 2048) {
575 mem = &mt41k512m16ha_125;
576 if (is_cpu_type(MXC_CPU_MX6Q))
577 calib = &mx6dq_512x32_mmdc_calib;
578 debug("8gB density\n");
579 } else if (width == 64 && size_mb == 512) {
580 mem = &mt41k64m16jt_125;
581 debug("1gB density\n");
582 if (is_cpu_type(MXC_CPU_MX6Q))
583 calib = &mx6dq_64x64_mmdc_calib;
584 else
585 calib = &mx6sdl_64x64_mmdc_calib;
586 } else if (width == 64 && size_mb == 1024) {
587 mem = &mt41k128m16jt_125;
588 if (is_cpu_type(MXC_CPU_MX6Q))
589 calib = &mx6dq_128x64_mmdc_calib;
590 else
591 calib = &mx6sdl_128x64_mmdc_calib;
592 debug("2gB density\n");
593 } else if (width == 64 && size_mb == 2048) {
594 switch(board_model) {
595 case GW5905:
596
597 mem = &mt41k128m16jt_125;
598 debug("2gB density - 2 chipsel\n");
599 if (!is_cpu_type(MXC_CPU_MX6Q)) {
600 calib = &mx6sdl_128x64x2_mmdc_calib;
601 sysinfo.ncs = 2;
602 sysinfo.cs_density = 10;
603 sysinfo.cs1_mirror = 1;
604 }
605 break;
606 default:
607 mem = &mt41k256m16ha_125;
608 if (is_cpu_type(MXC_CPU_MX6Q))
609 calib = &mx6dq_256x64_mmdc_calib;
610 else
611 calib = &mx6sdl_256x64_mmdc_calib;
612 debug("4gB density\n");
613 break;
614 }
615 } else if (width == 64 && size_mb == 4096) {
616 switch(board_model) {
617 case GW5903:
618
619 mem = &mt41k256m16ha_125;
620 debug("4gB density - 2 chipsel\n");
621 if (!is_cpu_type(MXC_CPU_MX6Q)) {
622 calib = &mx6sdl_256x64x2_mmdc_calib;
623 sysinfo.ncs = 2;
624 sysinfo.cs_density = 18;
625 sysinfo.cs1_mirror = 1;
626 }
627 break;
628 default:
629 mem = &mt41k512m16ha_125;
630 if (is_cpu_type(MXC_CPU_MX6Q))
631 calib = &mx6dq_512x64_mmdc_calib;
632 debug("8gB density\n");
633 break;
634 }
635 }
636
637 if (!(mem && calib)) {
638 puts("Error: Invalid Calibration/Board Configuration\n");
639 printf("MEM : %s\n", mem ? "OKAY" : "NULL");
640 printf("CALIB : %s\n", calib ? "OKAY" : "NULL");
641 printf("CPUTYPE: %s\n",
642 is_cpu_type(MXC_CPU_MX6Q) ? "IMX6Q" : "IMX6DL");
643 printf("SIZE_MB: %d\n", size_mb);
644 printf("WIDTH : %d\n", width);
645 hang();
646 }
647
648 if (is_cpu_type(MXC_CPU_MX6Q))
649 mx6dq_dram_iocfg(width, &mx6dq_ddr_ioregs,
650 &mx6dq_grp_ioregs);
651 else
652 mx6sdl_dram_iocfg(width, &mx6sdl_ddr_ioregs,
653 &mx6sdl_grp_ioregs);
654 mx6_dram_cfg(&sysinfo, calib, mem);
655}
656
657static void ccgr_init(void)
658{
659 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
660
661 writel(0x00C03F3F, &ccm->CCGR0);
662 writel(0x0030FC03, &ccm->CCGR1);
663 writel(0x0FFFC000, &ccm->CCGR2);
664 writel(0x3FF00000, &ccm->CCGR3);
665 writel(0xFFFFF300, &ccm->CCGR4);
666 writel(0x0F0000C3, &ccm->CCGR5);
667 writel(0x000003FF, &ccm->CCGR6);
668}
669
670
671static const iomux_v3_cfg_t uart2_pads[] = {
672 IOMUX_PADS(PAD_SD4_DAT7__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
673 IOMUX_PADS(PAD_SD4_DAT4__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
674};
675
676void setup_iomux_uart(void)
677{
678 SETUP_IOMUX_PADS(uart2_pads);
679}
680
681
682
683
684
685
686
687static struct i2c_pads_info mx6q_i2c_pad_info[] = {
688 {
689 .scl = {
690 .i2c_mode = MX6Q_PAD_EIM_D21__I2C1_SCL | PC,
691 .gpio_mode = MX6Q_PAD_EIM_D21__GPIO3_IO21 | PC,
692 .gp = IMX_GPIO_NR(3, 21)
693 },
694 .sda = {
695 .i2c_mode = MX6Q_PAD_EIM_D28__I2C1_SDA | PC,
696 .gpio_mode = MX6Q_PAD_EIM_D28__GPIO3_IO28 | PC,
697 .gp = IMX_GPIO_NR(3, 28)
698 }
699 }, {
700 .scl = {
701 .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL | PC,
702 .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12 | PC,
703 .gp = IMX_GPIO_NR(4, 12)
704 },
705 .sda = {
706 .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA | PC,
707 .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13 | PC,
708 .gp = IMX_GPIO_NR(4, 13)
709 }
710 }, {
711 .scl = {
712 .i2c_mode = MX6Q_PAD_GPIO_3__I2C3_SCL | PC,
713 .gpio_mode = MX6Q_PAD_GPIO_3__GPIO1_IO03 | PC,
714 .gp = IMX_GPIO_NR(1, 3)
715 },
716 .sda = {
717 .i2c_mode = MX6Q_PAD_GPIO_6__I2C3_SDA | PC,
718 .gpio_mode = MX6Q_PAD_GPIO_6__GPIO1_IO06 | PC,
719 .gp = IMX_GPIO_NR(1, 6)
720 }
721 }
722};
723
724static struct i2c_pads_info mx6dl_i2c_pad_info[] = {
725 {
726 .scl = {
727 .i2c_mode = MX6DL_PAD_EIM_D21__I2C1_SCL | PC,
728 .gpio_mode = MX6DL_PAD_EIM_D21__GPIO3_IO21 | PC,
729 .gp = IMX_GPIO_NR(3, 21)
730 },
731 .sda = {
732 .i2c_mode = MX6DL_PAD_EIM_D28__I2C1_SDA | PC,
733 .gpio_mode = MX6DL_PAD_EIM_D28__GPIO3_IO28 | PC,
734 .gp = IMX_GPIO_NR(3, 28)
735 }
736 }, {
737 .scl = {
738 .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL | PC,
739 .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12 | PC,
740 .gp = IMX_GPIO_NR(4, 12)
741 },
742 .sda = {
743 .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA | PC,
744 .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13 | PC,
745 .gp = IMX_GPIO_NR(4, 13)
746 }
747 }, {
748 .scl = {
749 .i2c_mode = MX6DL_PAD_GPIO_3__I2C3_SCL | PC,
750 .gpio_mode = MX6DL_PAD_GPIO_3__GPIO1_IO03 | PC,
751 .gp = IMX_GPIO_NR(1, 3)
752 },
753 .sda = {
754 .i2c_mode = MX6DL_PAD_GPIO_6__I2C3_SDA | PC,
755 .gpio_mode = MX6DL_PAD_GPIO_6__GPIO1_IO06 | PC,
756 .gp = IMX_GPIO_NR(1, 6)
757 }
758 }
759};
760
761static void setup_ventana_i2c(int i2c)
762{
763 struct i2c_pads_info *p;
764
765 if (is_cpu_type(MXC_CPU_MX6Q))
766 p = &mx6q_i2c_pad_info[i2c];
767 else
768 p = &mx6dl_i2c_pad_info[i2c];
769
770 setup_i2c(i2c, CONFIG_SYS_I2C_SPEED, 0x7f, p);
771}
772
773
774void setup_pmic(void)
775{
776 struct pmic *p;
777 const int i2c_pmic = 1;
778 u32 reg;
779 char rev;
780 int i;
781
782
783 rev = 'A';
784 for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
785 if (ventana_info.model[i] >= 'A') {
786 rev = ventana_info.model[i];
787 break;
788 }
789 }
790
791 i2c_set_bus_num(i2c_pmic);
792
793
794 if (!i2c_probe(CONFIG_POWER_PFUZE100_I2C_ADDR)) {
795 debug("probed PFUZE100@0x%x\n", CONFIG_POWER_PFUZE100_I2C_ADDR);
796 power_pfuze100_init(i2c_pmic);
797 p = pmic_get("PFUZE100");
798 if (p && !pmic_probe(p)) {
799 pmic_reg_read(p, PFUZE100_DEVICEID, ®);
800 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
801
802
803 pmic_reg_read(p, PFUZE100_VGEN1VOL, ®);
804 reg &= ~(LDO_VOL_MASK);
805 reg |= (LDOA_1_50V | LDO_EN);
806 pmic_reg_write(p, PFUZE100_VGEN1VOL, reg);
807
808
809 pmic_reg_read(p, PFUZE100_SWBSTCON1, ®);
810 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
811 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
812 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
813
814 if (board_type == GW54xx && (rev == 'G')) {
815
816 pmic_reg_write(p, PFUZE100_VGEN5VOL, 0);
817
818
819 pmic_reg_read(p, PFUZE100_VGEN6VOL, ®);
820 reg &= ~(LDO_VOL_MASK);
821 reg |= (LDOB_2_50V | LDO_EN);
822 pmic_reg_write(p, PFUZE100_VGEN6VOL, reg);
823 }
824 }
825
826
827 pmic_reg_read(p, PFUZE100_SW1ABMODE, ®);
828 reg &= ~(SW_MODE_MASK);
829 reg |= PWM_PWM;
830 pmic_reg_write(p, PFUZE100_SW1ABMODE, reg);
831
832 pmic_reg_read(p, PFUZE100_SW2MODE, ®);
833 reg &= ~(SW_MODE_MASK);
834 reg |= PWM_PWM;
835 pmic_reg_write(p, PFUZE100_SW2MODE, reg);
836
837 pmic_reg_read(p, PFUZE100_SW3AMODE, ®);
838 reg &= ~(SW_MODE_MASK);
839 reg |= PWM_PWM;
840 pmic_reg_write(p, PFUZE100_SW3AMODE, reg);
841
842 pmic_reg_read(p, PFUZE100_SW3BMODE, ®);
843 reg &= ~(SW_MODE_MASK);
844 reg |= PWM_PWM;
845 pmic_reg_write(p, PFUZE100_SW3BMODE, reg);
846
847 pmic_reg_read(p, PFUZE100_SW4MODE, ®);
848 reg &= ~(SW_MODE_MASK);
849 reg |= PWM_PWM;
850 pmic_reg_write(p, PFUZE100_SW4MODE, reg);
851 }
852
853
854 else if (!i2c_probe(CONFIG_POWER_LTC3676_I2C_ADDR)) {
855 debug("probed LTC3676@0x%x\n", CONFIG_POWER_LTC3676_I2C_ADDR);
856 power_ltc3676_init(i2c_pmic);
857 p = pmic_get("LTC3676_PMIC");
858 if (!p || pmic_probe(p))
859 return;
860 puts("PMIC: LTC3676\n");
861
862
863
864
865
866
867
868
869
870 switch (board_type) {
871 case GW560x:
872
873 pmic_reg_write(p, LTC3676_DVB3B,
874 0x1f | LTC3676_PGOOD_MASK);
875
876 pmic_reg_write(p, LTC3676_DVB3A, 0x1f);
877 break;
878 case GW5903:
879
880 pmic_reg_write(p, LTC3676_DVB3B,
881 0x1f | LTC3676_PGOOD_MASK);
882
883 pmic_reg_write(p, LTC3676_DVB3A, 0x1f);
884
885
886 pmic_reg_write(p, LTC3676_DVB4B,
887 0x1f | LTC3676_PGOOD_MASK);
888
889 pmic_reg_write(p, LTC3676_DVB4A, 0x1f);
890 break;
891 case GW5905:
892
893 pmic_reg_write(p, LTC3676_DVB1B,
894 0x1f | LTC3676_PGOOD_MASK);
895
896 pmic_reg_write(p, LTC3676_DVB1A, 0x1f);
897
898
899 pmic_reg_write(p, LTC3676_DVB3B,
900 0x1f | LTC3676_PGOOD_MASK);
901
902 pmic_reg_write(p, LTC3676_DVB3A, 0x1f);
903 break;
904 default:
905
906 pmic_reg_write(p, LTC3676_DVB1B,
907 0x1f | LTC3676_PGOOD_MASK);
908
909 pmic_reg_write(p, LTC3676_DVB1A, 0x1f);
910
911
912 pmic_reg_write(p, LTC3676_DVB3B,
913 0x1f | LTC3676_PGOOD_MASK);
914
915 pmic_reg_write(p, LTC3676_DVB3A, 0x1f);
916 }
917
918
919 pmic_reg_write(p, LTC3676_BUCK1, 0xc0);
920 pmic_reg_write(p, LTC3676_BUCK2, 0xc0);
921 pmic_reg_write(p, LTC3676_BUCK3, 0xc0);
922 pmic_reg_write(p, LTC3676_BUCK4, 0xc0);
923 }
924
925
926 else if (!i2c_probe(0x69)) {
927 puts("PMIC: MP5416\n");
928 switch (board_type) {
929 case GW5910:
930
931 reg = MP5416_VSET_EN | MP5416_VSET_SW1_SVAL(1475000);
932 i2c_write(0x69, MP5416_VSET_SW1, 1, (uint8_t *)®, 1);
933
934 reg = MP5416_VSET_EN | MP5416_VSET_SW4_SVAL(1475000);
935 i2c_write(0x69, MP5416_VSET_SW4, 1, (uint8_t *)®, 1);
936 break;
937 }
938 }
939}
940
941
942
943
944
945
946void board_init_f(ulong dummy)
947{
948 struct ventana_board_info ventana_info;
949 int board_model;
950
951
952 ccgr_init();
953
954
955 arch_cpu_init();
956
957
958 gpr_init();
959
960
961 setup_iomux_uart();
962 setup_ventana_i2c(0);
963 setup_ventana_i2c(1);
964
965
966 timer_init();
967
968
969 preloader_console_init();
970
971
972
973
974
975
976 while (1) {
977 if (!i2c_set_bus_num(BOARD_EEPROM_BUSNO) &&
978 !i2c_probe(BOARD_EEPROM_ADDR))
979 break;
980 mdelay(1);
981 }
982
983
984 board_model = read_eeprom(&ventana_info);
985
986
987 setup_iomux_gpio(board_model);
988
989
990 if (GW_UNKNOWN == board_model)
991 hang();
992
993
994 spl_dram_init(8 << ventana_info.sdram_width,
995 16 << ventana_info.sdram_size,
996 board_model);
997}
998
999void board_boot_order(u32 *spl_boot_list)
1000{
1001 spl_boot_list[0] = spl_boot_device();
1002 switch (spl_boot_list[0]) {
1003 case BOOT_DEVICE_NAND:
1004 spl_boot_list[1] = BOOT_DEVICE_MMC1;
1005 spl_boot_list[2] = BOOT_DEVICE_UART;
1006 break;
1007 case BOOT_DEVICE_MMC1:
1008 spl_boot_list[1] = BOOT_DEVICE_UART;
1009 break;
1010 }
1011}
1012
1013
1014
1015void spl_board_init(void)
1016{
1017 u32 boot_device;
1018
1019
1020 boot_device = spl_boot_device();
1021
1022
1023 board_type = read_eeprom(&ventana_info);
1024 if (board_type == GW_UNKNOWN)
1025 hang();
1026
1027 switch (boot_device) {
1028 case BOOT_DEVICE_MMC1:
1029 puts("Booting from MMC\n");
1030 break;
1031 case BOOT_DEVICE_NAND:
1032 puts("Booting from NAND\n");
1033 break;
1034 case BOOT_DEVICE_SATA:
1035 puts("Booting from SATA\n");
1036 break;
1037 default:
1038 puts("Unknown boot device\n");
1039 }
1040
1041
1042 setup_pmic();
1043}
1044
1045#ifdef CONFIG_SPL_OS_BOOT
1046
1047int spl_start_uboot(void)
1048{
1049 unsigned char ret = 1;
1050
1051 debug("%s\n", __func__);
1052#ifdef CONFIG_SPL_ENV_SUPPORT
1053 env_init();
1054 env_load();
1055 debug("boot_os=%s\n", env_get("boot_os"));
1056 if (env_get_yesno("boot_os") == 1)
1057 ret = 0;
1058#else
1059
1060 i2c_set_bus_num(0);
1061 gsc_i2c_read(0x50, 0x0, 1, &ret, 1);
1062#endif
1063 if (!ret)
1064 gsc_boot_wd_disable();
1065
1066 debug("%s booting %s\n", __func__, ret ? "uboot" : "linux");
1067 return ret;
1068}
1069#endif
1070