1
2
3
4
5
6
7
8
9
10#include <common.h>
11#include <env.h>
12#include <init.h>
13#include <linux/delay.h>
14#include <linux/errno.h>
15#include <asm/io.h>
16#include <asm/arch/imx-regs.h>
17#include <asm/arch/clock.h>
18#include <asm/arch/sys_proto.h>
19#include <asm/bootm.h>
20#include <asm/mach-imx/boot_mode.h>
21#include <asm/mach-imx/dma.h>
22#include <asm/mach-imx/hab.h>
23#include <stdbool.h>
24#include <asm/arch/mxc_hdmi.h>
25#include <asm/arch/crm_regs.h>
26#include <dm.h>
27#include <imx_thermal.h>
28#include <mmc.h>
29
30#define has_err007805() \
31 (is_mx6sl() || is_mx6dl() || is_mx6solo() || is_mx6ull())
32
33struct scu_regs {
34 u32 ctrl;
35 u32 config;
36 u32 status;
37 u32 invalidate;
38 u32 fpga_rev;
39};
40
41#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_IMX_THERMAL)
42static const struct imx_thermal_plat imx6_thermal_plat = {
43 .regs = (void *)ANATOP_BASE_ADDR,
44 .fuse_bank = 1,
45 .fuse_word = 6,
46};
47
48U_BOOT_DRVINFO(imx6_thermal) = {
49 .name = "imx_thermal",
50 .plat = &imx6_thermal_plat,
51};
52#endif
53
54#if defined(CONFIG_IMX_HAB)
55struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
56 .bank = 0,
57 .word = 6,
58};
59#endif
60
61u32 get_nr_cpus(void)
62{
63 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
64 return readl(&scu->config) & 3;
65}
66
67u32 get_cpu_rev(void)
68{
69 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
70 u32 reg = readl(&anatop->digprog_sololite);
71 u32 type = ((reg >> 16) & 0xff);
72 u32 major, cfg = 0;
73
74 if (type != MXC_CPU_MX6SL) {
75 reg = readl(&anatop->digprog);
76 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
77 cfg = readl(&scu->config) & 3;
78 type = ((reg >> 16) & 0xff);
79 if (type == MXC_CPU_MX6DL) {
80 if (!cfg)
81 type = MXC_CPU_MX6SOLO;
82 }
83
84 if (type == MXC_CPU_MX6Q) {
85 if (cfg == 1)
86 type = MXC_CPU_MX6D;
87 }
88
89 if (type == MXC_CPU_MX6ULL) {
90 if (readl(SRC_BASE_ADDR + 0x1c) & (1 << 6))
91 type = MXC_CPU_MX6ULZ;
92 }
93 }
94 major = ((reg >> 8) & 0xff);
95 if ((major >= 1) &&
96 ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
97 major--;
98 type = MXC_CPU_MX6QP;
99 if (cfg == 1)
100 type = MXC_CPU_MX6DP;
101 }
102 reg &= 0xff;
103
104
105 if (((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D)) && (reg == 0x5))
106 reg = 0x3;
107
108 return (type << 12) | (reg + (0x10 * (major + 1)));
109}
110
111
112
113
114
115#define OCOTP_CFG3_SPEED_SHIFT 16
116#define OCOTP_CFG3_SPEED_800MHZ 0
117#define OCOTP_CFG3_SPEED_850MHZ 1
118#define OCOTP_CFG3_SPEED_1GHZ 2
119#define OCOTP_CFG3_SPEED_1P2GHZ 3
120
121
122
123
124#define OCOTP_CFG3_SPEED_528MHZ 1
125#define OCOTP_CFG3_SPEED_696MHZ 2
126
127
128
129
130#define OCOTP_CFG3_SPEED_792MHZ 2
131#define OCOTP_CFG3_SPEED_900MHZ 3
132
133u32 get_cpu_speed_grade_hz(void)
134{
135 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
136 struct fuse_bank *bank = &ocotp->bank[0];
137 struct fuse_bank0_regs *fuse =
138 (struct fuse_bank0_regs *)bank->fuse_regs;
139 uint32_t val;
140
141 val = readl(&fuse->cfg3);
142 val >>= OCOTP_CFG3_SPEED_SHIFT;
143 val &= 0x3;
144
145 if (is_mx6ul()) {
146 if (val == OCOTP_CFG3_SPEED_528MHZ)
147 return 528000000;
148 else if (val == OCOTP_CFG3_SPEED_696MHZ)
149 return 696000000;
150 else
151 return 0;
152 }
153
154 if (is_mx6ull()) {
155 if (val == OCOTP_CFG3_SPEED_528MHZ)
156 return 528000000;
157 else if (val == OCOTP_CFG3_SPEED_792MHZ)
158 return 792000000;
159 else if (val == OCOTP_CFG3_SPEED_900MHZ)
160 return 900000000;
161 else
162 return 0;
163 }
164
165 switch (val) {
166
167 case OCOTP_CFG3_SPEED_1P2GHZ:
168 if (is_mx6dq() || is_mx6dqp())
169 return 1200000000;
170
171 case OCOTP_CFG3_SPEED_1GHZ:
172 return 996000000;
173
174 case OCOTP_CFG3_SPEED_850MHZ:
175 if (is_mx6dq() || is_mx6dqp())
176 return 852000000;
177
178 case OCOTP_CFG3_SPEED_800MHZ:
179 return 792000000;
180 }
181 return 0;
182}
183
184
185
186
187
188
189
190#define OCOTP_MEM0_TEMP_SHIFT 6
191
192u32 get_cpu_temp_grade(int *minc, int *maxc)
193{
194 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
195 struct fuse_bank *bank = &ocotp->bank[1];
196 struct fuse_bank1_regs *fuse =
197 (struct fuse_bank1_regs *)bank->fuse_regs;
198 uint32_t val;
199
200 val = readl(&fuse->mem0);
201 val >>= OCOTP_MEM0_TEMP_SHIFT;
202 val &= 0x3;
203
204 if (minc && maxc) {
205 if (val == TEMP_AUTOMOTIVE) {
206 *minc = -40;
207 *maxc = 125;
208 } else if (val == TEMP_INDUSTRIAL) {
209 *minc = -40;
210 *maxc = 105;
211 } else if (val == TEMP_EXTCOMMERCIAL) {
212 *minc = -20;
213 *maxc = 105;
214 } else {
215 *minc = 0;
216 *maxc = 95;
217 }
218 }
219 return val;
220}
221
222#ifdef CONFIG_REVISION_TAG
223u32 __weak get_board_rev(void)
224{
225 u32 cpurev = get_cpu_rev();
226 u32 type = ((cpurev >> 12) & 0xff);
227 if (type == MXC_CPU_MX6SOLO)
228 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
229
230 if (type == MXC_CPU_MX6D)
231 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
232
233 return cpurev;
234}
235#endif
236
237static void clear_ldo_ramp(void)
238{
239 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
240 int reg;
241
242
243
244
245
246 reg = readl(&anatop->ana_misc2);
247 reg &= ~(0x3f << 24);
248 writel(reg, &anatop->ana_misc2);
249}
250
251
252
253
254
255
256
257
258int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
259{
260 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
261 u32 val, step, old, reg = readl(&anatop->reg_core);
262 u8 shift;
263
264
265 if (is_mx6sll())
266 return 0;
267
268 if (mv < 725)
269 val = 0x00;
270 else if (mv > 1450)
271 val = 0x1F;
272 else
273 val = (mv - 700) / 25;
274
275 clear_ldo_ramp();
276
277 switch (ldo) {
278 case LDO_SOC:
279 shift = 18;
280 break;
281 case LDO_PU:
282 shift = 9;
283 break;
284 case LDO_ARM:
285 shift = 0;
286 break;
287 default:
288 return -EINVAL;
289 }
290
291 old = (reg & (0x1F << shift)) >> shift;
292 step = abs(val - old);
293 if (step == 0)
294 return 0;
295
296 reg = (reg & ~(0x1F << shift)) | (val << shift);
297 writel(reg, &anatop->reg_core);
298
299
300
301
302
303 udelay(3 * step);
304
305 return 0;
306}
307
308static void set_ahb_rate(u32 val)
309{
310 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
311 u32 reg, div;
312
313 div = get_periph_clk() / val - 1;
314 reg = readl(&mxc_ccm->cbcdr);
315
316 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
317 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
318}
319
320static void clear_mmdc_ch_mask(void)
321{
322 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
323 u32 reg;
324 reg = readl(&mxc_ccm->ccdr);
325
326
327 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll())
328 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
329 else
330 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
331 writel(reg, &mxc_ccm->ccdr);
332}
333
334#define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
335
336static void init_bandgap(void)
337{
338 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
339 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
340 struct fuse_bank *bank = &ocotp->bank[1];
341 struct fuse_bank1_regs *fuse =
342 (struct fuse_bank1_regs *)bank->fuse_regs;
343 uint32_t val;
344
345
346
347
348 while (!(readl(&anatop->ana_misc0) & 0x80))
349 ;
350
351
352
353
354
355 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
356
357
358
359
360
361
362
363
364
365
366
367
368 if (is_mx6ull()) {
369 static const u32 map[] = {6, 1, 2, 3, 4, 5, 0, 7};
370
371 val = readl(&fuse->mem0);
372 val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
373 val &= 0x7;
374
375 writel(map[val] << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
376 &anatop->ana_misc0_set);
377 }
378}
379
380#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
381static void noc_setup(void)
382{
383 enable_ipu_clock();
384
385 writel(0x80000201, 0xbb0608);
386
387 writel(0x00000002, 0x00bb048c);
388
389 writel(0x00000002, 0x00bb050c);
390
391 writel(0x00000200, 0x00bb0690);
392
393 writel(0x00000200, 0x00bb0710);
394
395 writel(0x00000200, 0x00bb0790);
396
397 writel(0x00000200, 0x00bb0810);
398
399 writel(0x00000010, 0x00bb0694);
400
401 writel(0x00000010, 0x00bb0714);
402
403 writel(0x00000010, 0x00bb0794);
404
405 writel(0x00000010, 0x00bb0814);
406
407 disable_ipu_clock();
408}
409#endif
410
411int arch_cpu_init(void)
412{
413 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
414
415 init_aips();
416
417
418 clear_mmdc_ch_mask();
419
420
421
422
423
424
425 init_bandgap();
426
427 if (!is_mx6ul() && !is_mx6ull()) {
428
429
430
431
432
433
434
435
436 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
437 set_ahb_rate(132000000);
438 }
439
440 if (is_mx6ul()) {
441 if (is_soc_rev(CHIP_REV_1_0) == 0) {
442
443
444
445
446
447
448 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
449 } else {
450
451
452
453
454
455
456
457 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
458 (~0x1400)) | 0x400,
459 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
460 }
461 }
462
463 if (is_mx6ull()) {
464
465
466
467
468
469
470
471
472
473 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
474 0x3, MX6UL_SNVS_LP_BASE_ADDR);
475 }
476
477
478 if (has_err007805())
479 setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
480
481 imx_wdog_disable_powerdown();
482
483 if (is_mx6sx())
484 setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
485
486 init_src();
487
488#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
489 if (is_mx6dqp())
490 noc_setup();
491#endif
492
493 enable_ca7_smp();
494
495 return 0;
496}
497
498#ifdef CONFIG_ENV_IS_IN_MMC
499__weak int board_mmc_get_env_dev(int devno)
500{
501 return CONFIG_SYS_MMC_ENV_DEV;
502}
503
504static int mmc_get_boot_dev(void)
505{
506 u32 soc_sbmr = imx6_src_get_boot_mode();
507 u32 bootsel;
508 int devno;
509
510
511
512
513
514
515
516 bootsel = (soc_sbmr & 0x000000FF) >> 6;
517
518
519 if (bootsel != 1)
520 return -1;
521
522
523 devno = (soc_sbmr & 0x00001800) >> 11;
524
525 return devno;
526}
527
528int mmc_get_env_dev(void)
529{
530 int devno = mmc_get_boot_dev();
531
532
533 if (devno < 0)
534 return CONFIG_SYS_MMC_ENV_DEV;
535
536 return board_mmc_get_env_dev(devno);
537}
538
539#ifdef CONFIG_SYS_MMC_ENV_PART
540__weak int board_mmc_get_env_part(int devno)
541{
542 return CONFIG_SYS_MMC_ENV_PART;
543}
544
545uint mmc_get_env_part(struct mmc *mmc)
546{
547 int devno = mmc_get_boot_dev();
548
549
550 if (devno < 0)
551 return CONFIG_SYS_MMC_ENV_PART;
552
553 return board_mmc_get_env_part(devno);
554}
555#endif
556#endif
557
558int board_postclk_init(void)
559{
560
561 if (is_mx6sll())
562 return 0;
563
564 set_ldo_voltage(LDO_SOC, 1175);
565
566 return 0;
567}
568
569#ifndef CONFIG_SPL_BUILD
570
571
572
573
574
575
576const struct boot_mode soc_boot_modes[] = {
577 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
578
579#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
580 {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
581#else
582 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
583#endif
584 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
585 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
586 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
587 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
588 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
589
590 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
591 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
592 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
593 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
594 {NULL, 0},
595};
596#endif
597
598void reset_misc(void)
599{
600#ifndef CONFIG_SPL_BUILD
601#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_VIDEO)
602 lcdif_power_down();
603#endif
604#endif
605}
606
607void s_init(void)
608{
609 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
610 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
611 u32 mask480;
612 u32 mask528;
613 u32 reg, periph1, periph2;
614
615 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll())
616 return;
617
618
619
620
621
622
623
624 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
625 ANATOP_PFD_CLKGATE_MASK(1) |
626 ANATOP_PFD_CLKGATE_MASK(2) |
627 ANATOP_PFD_CLKGATE_MASK(3);
628 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
629 ANATOP_PFD_CLKGATE_MASK(3);
630
631 reg = readl(&ccm->cbcmr);
632 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
633 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
634 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
635 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
636
637
638 if ((periph2 != 0x2) && (periph1 != 0x2))
639 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
640
641 if ((periph2 != 0x1) && (periph1 != 0x1) &&
642 (periph2 != 0x3) && (periph1 != 0x3))
643 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
644
645 writel(mask480, &anatop->pfd_480_set);
646 writel(mask528, &anatop->pfd_528_set);
647 writel(mask480, &anatop->pfd_480_clr);
648 writel(mask528, &anatop->pfd_528_clr);
649}
650
651#ifdef CONFIG_IMX_HDMI
652void imx_enable_hdmi_phy(void)
653{
654 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
655 u8 reg;
656 reg = readb(&hdmi->phy_conf0);
657 reg |= HDMI_PHY_CONF0_PDZ_MASK;
658 writeb(reg, &hdmi->phy_conf0);
659 udelay(3000);
660 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
661 writeb(reg, &hdmi->phy_conf0);
662 udelay(3000);
663 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
664 writeb(reg, &hdmi->phy_conf0);
665 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
666}
667
668void imx_setup_hdmi(void)
669{
670 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
671 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
672 int reg, count;
673 u8 val;
674
675
676 reg = readl(&mxc_ccm->CCGR2);
677 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
678 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
679 writel(reg, &mxc_ccm->CCGR2);
680 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
681 reg = readl(&mxc_ccm->chsccdr);
682 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
683 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
684 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
685 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
686 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
687 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
688 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
689 writel(reg, &mxc_ccm->chsccdr);
690
691
692 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
693
694 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
695 val = readb(&hdmi->fc_invidconf);
696
697 for (count = 0 ; count < 5 ; count++)
698 writeb(val, &hdmi->fc_invidconf);
699 }
700}
701#endif
702
703#ifdef CONFIG_ARCH_MISC_INIT
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723static void setup_serial_number(void)
724{
725 char serial_string[17];
726 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
727 struct fuse_bank *bank = &ocotp->bank[0];
728 struct fuse_bank0_regs *fuse =
729 (struct fuse_bank0_regs *)bank->fuse_regs;
730
731 if (env_get("serial#"))
732 return;
733
734 snprintf(serial_string, sizeof(serial_string), "%08x%08x",
735 fuse->uid_low, fuse->uid_high);
736 env_set("serial#", serial_string);
737}
738
739int arch_misc_init(void)
740{
741 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
742 struct udevice *dev;
743 int ret;
744
745 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
746 if (ret)
747 printf("Failed to initialize caam_jr: %d\n", ret);
748 }
749 setup_serial_number();
750 return 0;
751}
752#endif
753
754
755
756
757
758void gpr_init(void)
759{
760 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
761
762
763
764
765
766
767 if (!is_mx6dqp() && !is_mx6dq() && !is_mx6sdl())
768 return;
769
770
771 writel(0xF00000CF, &iomux->gpr[4]);
772 if (is_mx6dqp()) {
773
774 writel(0x77177717, &iomux->gpr[6]);
775 writel(0x77177717, &iomux->gpr[7]);
776 } else {
777
778 writel(0x007F007F, &iomux->gpr[6]);
779 writel(0x007F007F, &iomux->gpr[7]);
780 }
781}
782