1 // SPDX-License-Identifier: GPL-2.0+
4 * Sascha Hauer, Pengutronix
6 * (C) Copyright 2009 Freescale Semiconductor, Inc.
11 #include <linux/errno.h>
13 #include <asm/arch/imx-regs.h>
14 #include <asm/arch/clock.h>
15 #include <asm/arch/sys_proto.h>
16 #include <asm/bootm.h>
17 #include <asm/mach-imx/boot_mode.h>
18 #include <asm/mach-imx/dma.h>
19 #include <asm/mach-imx/hab.h>
21 #include <asm/arch/mxc_hdmi.h>
22 #include <asm/arch/crm_regs.h>
24 #include <imx_thermal.h>
41 #if defined(CONFIG_IMX_THERMAL)
42 static const struct imx_thermal_plat imx6_thermal_plat = {
43 .regs = (void *)ANATOP_BASE_ADDR,
48 U_BOOT_DEVICE(imx6_thermal) = {
49 .name = "imx_thermal",
50 .platdata = &imx6_thermal_plat,
54 #if defined(CONFIG_IMX_HAB)
55 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
63 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
64 return readl(&scu->config) & 3;
69 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
70 u32 reg = readl(&anatop->digprog_sololite);
71 u32 type = ((reg >> 16) & 0xff);
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) {
81 type = MXC_CPU_MX6SOLO;
84 if (type == MXC_CPU_MX6Q) {
89 if (type == MXC_CPU_MX6ULL) {
90 if (readl(SRC_BASE_ADDR + 0x1c) & (1 << 6))
91 type = MXC_CPU_MX6ULZ;
94 major = ((reg >> 8) & 0xff);
96 ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
100 type = MXC_CPU_MX6DP;
102 reg &= 0xff; /* mx6 silicon revision */
104 /* For 6DQ, the value 0x00630005 is Silicon revision 1.3*/
105 if (((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D)) && (reg == 0x5))
108 return (type << 12) | (reg + (0x10 * (major + 1)));
112 * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
113 * defines a 2-bit SPEED_GRADING
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
124 #define OCOTP_CFG3_SPEED_528MHZ 1
125 #define OCOTP_CFG3_SPEED_696MHZ 2
130 #define OCOTP_CFG3_SPEED_792MHZ 2
131 #define OCOTP_CFG3_SPEED_900MHZ 3
133 u32 get_cpu_speed_grade_hz(void)
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;
141 val = readl(&fuse->cfg3);
142 val >>= OCOTP_CFG3_SPEED_SHIFT;
146 if (val == OCOTP_CFG3_SPEED_528MHZ)
148 else if (val == OCOTP_CFG3_SPEED_696MHZ)
155 if (val == OCOTP_CFG3_SPEED_528MHZ)
157 else if (val == OCOTP_CFG3_SPEED_792MHZ)
159 else if (val == OCOTP_CFG3_SPEED_900MHZ)
166 /* Valid for IMX6DQ */
167 case OCOTP_CFG3_SPEED_1P2GHZ:
168 if (is_mx6dq() || is_mx6dqp())
170 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
171 case OCOTP_CFG3_SPEED_1GHZ:
173 /* Valid for IMX6DQ */
174 case OCOTP_CFG3_SPEED_850MHZ:
175 if (is_mx6dq() || is_mx6dqp())
177 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
178 case OCOTP_CFG3_SPEED_800MHZ:
185 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
186 * defines a 2-bit Temperature Grade
188 * return temperature grade and min/max temperature in Celsius
190 #define OCOTP_MEM0_TEMP_SHIFT 6
192 u32 get_cpu_temp_grade(int *minc, int *maxc)
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;
200 val = readl(&fuse->mem0);
201 val >>= OCOTP_MEM0_TEMP_SHIFT;
205 if (val == TEMP_AUTOMOTIVE) {
208 } else if (val == TEMP_INDUSTRIAL) {
211 } else if (val == TEMP_EXTCOMMERCIAL) {
222 #ifdef CONFIG_REVISION_TAG
223 u32 __weak get_board_rev(void)
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);
230 if (type == MXC_CPU_MX6D)
231 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
237 static void clear_ldo_ramp(void)
239 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
242 /* ROM may modify LDO ramp up time according to fuse setting, so in
243 * order to be in the safe side we neeed to reset these settings to
244 * match the reset value: 0'b00
246 reg = readl(&anatop->ana_misc2);
247 reg &= ~(0x3f << 24);
248 writel(reg, &anatop->ana_misc2);
252 * Set the PMU_REG_CORE register
254 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
255 * Possible values are from 0.725V to 1.450V in steps of
258 static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
260 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
261 u32 val, step, old, reg = readl(&anatop->reg_core);
264 /* No LDO_SOC/PU/ARM */
269 val = 0x00; /* Power gated off */
271 val = 0x1F; /* Power FET switched full on. No regulation */
273 val = (mv - 700) / 25;
291 old = (reg & (0x1F << shift)) >> shift;
292 step = abs(val - old);
296 reg = (reg & ~(0x1F << shift)) | (val << shift);
297 writel(reg, &anatop->reg_core);
300 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
308 static void set_ahb_rate(u32 val)
310 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
313 div = get_periph_clk() / val - 1;
314 reg = readl(&mxc_ccm->cbcdr);
316 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
317 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
320 static void clear_mmdc_ch_mask(void)
322 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
324 reg = readl(&mxc_ccm->ccdr);
326 /* Clear MMDC channel mask */
327 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll())
328 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
330 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
331 writel(reg, &mxc_ccm->ccdr);
334 #define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
336 static void init_bandgap(void)
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;
346 * Ensure the bandgap has stabilized.
348 while (!(readl(&anatop->ana_misc0) & 0x80))
351 * For best noise performance of the analog blocks using the
352 * outputs of the bandgap, the reftop_selfbiasoff bit should
355 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
357 * On i.MX6ULL,we need to set VBGADJ bits according to the
358 * REFTOP_TRIM[3:0] in fuse table
359 * 000 - set REFTOP_VBGADJ[2:0] to 3b'110,
360 * 110 - set REFTOP_VBGADJ[2:0] to 3b'000,
361 * 001 - set REFTOP_VBGADJ[2:0] to 3b'001,
362 * 010 - set REFTOP_VBGADJ[2:0] to 3b'010,
363 * 011 - set REFTOP_VBGADJ[2:0] to 3b'011,
364 * 100 - set REFTOP_VBGADJ[2:0] to 3b'100,
365 * 101 - set REFTOP_VBGADJ[2:0] to 3b'101,
366 * 111 - set REFTOP_VBGADJ[2:0] to 3b'111,
369 val = readl(&fuse->mem0);
370 val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
373 writel(val << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
374 &anatop->ana_misc0_set);
378 #if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
379 static void noc_setup(void)
383 writel(0x80000201, 0xbb0608);
384 /* Bypass IPU1 QoS generator */
385 writel(0x00000002, 0x00bb048c);
386 /* Bypass IPU2 QoS generator */
387 writel(0x00000002, 0x00bb050c);
388 /* Bandwidth THR for of PRE0 */
389 writel(0x00000200, 0x00bb0690);
390 /* Bandwidth THR for of PRE1 */
391 writel(0x00000200, 0x00bb0710);
392 /* Bandwidth THR for of PRE2 */
393 writel(0x00000200, 0x00bb0790);
394 /* Bandwidth THR for of PRE3 */
395 writel(0x00000200, 0x00bb0810);
396 /* Saturation THR for of PRE0 */
397 writel(0x00000010, 0x00bb0694);
398 /* Saturation THR for of PRE1 */
399 writel(0x00000010, 0x00bb0714);
400 /* Saturation THR for of PRE2 */
401 writel(0x00000010, 0x00bb0794);
402 /* Saturation THR for of PRE */
403 writel(0x00000010, 0x00bb0814);
409 int arch_cpu_init(void)
411 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
415 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
416 clear_mmdc_ch_mask();
419 * Disable self-bias circuit in the analog bandap.
420 * The self-bias circuit is used by the bandgap during startup.
421 * This bit should be set after the bandgap has initialized.
425 if (!is_mx6ul() && !is_mx6ull()) {
427 * When low freq boot is enabled, ROM will not set AHB
428 * freq, so we need to ensure AHB freq is 132MHz in such
431 * To i.MX6UL, when power up, default ARM core and
432 * AHB rate is 396M and 132M.
434 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
435 set_ahb_rate(132000000);
439 if (is_soc_rev(CHIP_REV_1_0) == 0) {
441 * According to the design team's requirement on
442 * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
443 * as open drain 100K (0x0000b8a0).
444 * Only exists on TO1.0
446 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
449 * From TO1.1, SNVS adds internal pull up control
450 * for POR_B, the register filed is GPBIT[1:0],
451 * after system boot up, it can be set to 2b'01
452 * to disable internal pull up.It can save about
453 * 30uA power in SNVS mode.
455 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
457 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
463 * GPBIT[1:0] is suggested to set to 2'b11:
464 * 2'b00 : always PUP100K
465 * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
466 * 2'b10 : always disable PUP100K
467 * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
468 * register offset is different from i.MX6UL, since
469 * i.MX6UL is fixed by ECO.
471 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
472 0x3, MX6UL_SNVS_LP_BASE_ADDR);
475 /* Set perclk to source from OSC 24MHz */
477 setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
479 imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register */
482 setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
486 #if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
493 #ifdef CONFIG_ENV_IS_IN_MMC
494 __weak int board_mmc_get_env_dev(int devno)
496 return CONFIG_SYS_MMC_ENV_DEV;
499 static int mmc_get_boot_dev(void)
501 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
502 u32 soc_sbmr = readl(&src_regs->sbmr1);
508 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
509 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
510 * i.MX6SL/SX/UL has same layout.
512 bootsel = (soc_sbmr & 0x000000FF) >> 6;
514 /* No boot from sd/mmc */
518 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
519 devno = (soc_sbmr & 0x00001800) >> 11;
524 int mmc_get_env_dev(void)
526 int devno = mmc_get_boot_dev();
528 /* If not boot from sd/mmc, use default value */
530 return CONFIG_SYS_MMC_ENV_DEV;
532 return board_mmc_get_env_dev(devno);
535 #ifdef CONFIG_SYS_MMC_ENV_PART
536 __weak int board_mmc_get_env_part(int devno)
538 return CONFIG_SYS_MMC_ENV_PART;
541 uint mmc_get_env_part(struct mmc *mmc)
543 int devno = mmc_get_boot_dev();
545 /* If not boot from sd/mmc, use default value */
547 return CONFIG_SYS_MMC_ENV_PART;
549 return board_mmc_get_env_part(devno);
554 int board_postclk_init(void)
556 /* NO LDO SOC on i.MX6SLL */
560 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
565 #ifndef CONFIG_SPL_BUILD
567 * cfg_val will be used for
568 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
569 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
570 * instead of SBMR1 to determine the boot device.
572 const struct boot_mode soc_boot_modes[] = {
573 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
574 /* reserved value should start rom usb */
575 #if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
576 {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
578 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
580 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
581 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
582 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
583 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
584 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
585 /* 4 bit bus width */
586 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
587 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
588 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
589 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
594 void reset_misc(void)
596 #ifndef CONFIG_SPL_BUILD
597 #if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
605 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
606 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
609 u32 reg, periph1, periph2;
611 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll())
614 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
615 * to make sure PFD is working right, otherwise, PFDs may
616 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
617 * workaround in ROM code, as bus clock need it
620 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
621 ANATOP_PFD_CLKGATE_MASK(1) |
622 ANATOP_PFD_CLKGATE_MASK(2) |
623 ANATOP_PFD_CLKGATE_MASK(3);
624 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
625 ANATOP_PFD_CLKGATE_MASK(3);
627 reg = readl(&ccm->cbcmr);
628 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
629 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
630 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
631 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
633 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
634 if ((periph2 != 0x2) && (periph1 != 0x2))
635 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
637 if ((periph2 != 0x1) && (periph1 != 0x1) &&
638 (periph2 != 0x3) && (periph1 != 0x3))
639 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
641 writel(mask480, &anatop->pfd_480_set);
642 writel(mask528, &anatop->pfd_528_set);
643 writel(mask480, &anatop->pfd_480_clr);
644 writel(mask528, &anatop->pfd_528_clr);
647 #ifdef CONFIG_IMX_HDMI
648 void imx_enable_hdmi_phy(void)
650 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
652 reg = readb(&hdmi->phy_conf0);
653 reg |= HDMI_PHY_CONF0_PDZ_MASK;
654 writeb(reg, &hdmi->phy_conf0);
656 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
657 writeb(reg, &hdmi->phy_conf0);
659 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
660 writeb(reg, &hdmi->phy_conf0);
661 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
664 void imx_setup_hdmi(void)
666 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
667 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
671 /* Turn on HDMI PHY clock */
672 reg = readl(&mxc_ccm->CCGR2);
673 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
674 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
675 writel(reg, &mxc_ccm->CCGR2);
676 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
677 reg = readl(&mxc_ccm->chsccdr);
678 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
679 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
680 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
681 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
682 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
683 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
684 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
685 writel(reg, &mxc_ccm->chsccdr);
687 /* Clear the overflow condition */
688 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
689 /* TMDS software reset */
690 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
691 val = readb(&hdmi->fc_invidconf);
692 /* Need minimum 3 times to write to clear the register */
693 for (count = 0 ; count < 5 ; count++)
694 writeb(val, &hdmi->fc_invidconf);
701 * gpr_init() function is common for boards using MX6S, MX6DL, MX6D,
702 * MX6Q and MX6QP processors
706 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
709 * If this function is used in a common MX6 spl implementation
710 * we have to ensure that it is only called for suitable cpu types,
711 * otherwise it breaks hardware parts like enet1, can1, can2, etc.
713 if (!is_mx6dqp() && !is_mx6dq() && !is_mx6sdl())
716 /* enable AXI cache for VDOA/VPU/IPU */
717 writel(0xF00000CF, &iomux->gpr[4]);
719 /* set IPU AXI-id1 Qos=0x1 AXI-id0/2/3 Qos=0x7 */
720 writel(0x77177717, &iomux->gpr[6]);
721 writel(0x77177717, &iomux->gpr[7]);
723 /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
724 writel(0x007F007F, &iomux->gpr[6]);
725 writel(0x007F007F, &iomux->gpr[7]);