1 // SPDX-License-Identifier: GPL-2.0+
4 * Sascha Hauer, Pengutronix
6 * (C) Copyright 2009 Freescale Semiconductor, Inc.
10 #include <linux/errno.h>
12 #include <asm/arch/imx-regs.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/sys_proto.h>
15 #include <asm/bootm.h>
16 #include <asm/mach-imx/boot_mode.h>
17 #include <asm/mach-imx/dma.h>
18 #include <asm/mach-imx/hab.h>
20 #include <asm/arch/mxc_hdmi.h>
21 #include <asm/arch/crm_regs.h>
23 #include <imx_thermal.h>
40 #if defined(CONFIG_IMX_THERMAL)
41 static const struct imx_thermal_plat imx6_thermal_plat = {
42 .regs = (void *)ANATOP_BASE_ADDR,
47 U_BOOT_DEVICE(imx6_thermal) = {
48 .name = "imx_thermal",
49 .platdata = &imx6_thermal_plat,
53 #if defined(CONFIG_SECURE_BOOT)
54 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
62 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
63 return readl(&scu->config) & 3;
68 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
69 u32 reg = readl(&anatop->digprog_sololite);
70 u32 type = ((reg >> 16) & 0xff);
73 if (type != MXC_CPU_MX6SL) {
74 reg = readl(&anatop->digprog);
75 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
76 cfg = readl(&scu->config) & 3;
77 type = ((reg >> 16) & 0xff);
78 if (type == MXC_CPU_MX6DL) {
80 type = MXC_CPU_MX6SOLO;
83 if (type == MXC_CPU_MX6Q) {
89 major = ((reg >> 8) & 0xff);
91 ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
97 reg &= 0xff; /* mx6 silicon revision */
99 /* For 6DQ, the value 0x00630005 is Silicon revision 1.3*/
100 if (((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D)) && (reg == 0x5))
103 return (type << 12) | (reg + (0x10 * (major + 1)));
107 * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
108 * defines a 2-bit SPEED_GRADING
110 #define OCOTP_CFG3_SPEED_SHIFT 16
111 #define OCOTP_CFG3_SPEED_800MHZ 0
112 #define OCOTP_CFG3_SPEED_850MHZ 1
113 #define OCOTP_CFG3_SPEED_1GHZ 2
114 #define OCOTP_CFG3_SPEED_1P2GHZ 3
119 #define OCOTP_CFG3_SPEED_528MHZ 1
120 #define OCOTP_CFG3_SPEED_696MHZ 2
125 #define OCOTP_CFG3_SPEED_792MHZ 2
126 #define OCOTP_CFG3_SPEED_900MHZ 3
128 u32 get_cpu_speed_grade_hz(void)
130 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
131 struct fuse_bank *bank = &ocotp->bank[0];
132 struct fuse_bank0_regs *fuse =
133 (struct fuse_bank0_regs *)bank->fuse_regs;
136 val = readl(&fuse->cfg3);
137 val >>= OCOTP_CFG3_SPEED_SHIFT;
141 if (val == OCOTP_CFG3_SPEED_528MHZ)
143 else if (val == OCOTP_CFG3_SPEED_696MHZ)
150 if (val == OCOTP_CFG3_SPEED_528MHZ)
152 else if (val == OCOTP_CFG3_SPEED_792MHZ)
154 else if (val == OCOTP_CFG3_SPEED_900MHZ)
161 /* Valid for IMX6DQ */
162 case OCOTP_CFG3_SPEED_1P2GHZ:
163 if (is_mx6dq() || is_mx6dqp())
165 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
166 case OCOTP_CFG3_SPEED_1GHZ:
168 /* Valid for IMX6DQ */
169 case OCOTP_CFG3_SPEED_850MHZ:
170 if (is_mx6dq() || is_mx6dqp())
172 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
173 case OCOTP_CFG3_SPEED_800MHZ:
180 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
181 * defines a 2-bit Temperature Grade
183 * return temperature grade and min/max temperature in Celsius
185 #define OCOTP_MEM0_TEMP_SHIFT 6
187 u32 get_cpu_temp_grade(int *minc, int *maxc)
189 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
190 struct fuse_bank *bank = &ocotp->bank[1];
191 struct fuse_bank1_regs *fuse =
192 (struct fuse_bank1_regs *)bank->fuse_regs;
195 val = readl(&fuse->mem0);
196 val >>= OCOTP_MEM0_TEMP_SHIFT;
200 if (val == TEMP_AUTOMOTIVE) {
203 } else if (val == TEMP_INDUSTRIAL) {
206 } else if (val == TEMP_EXTCOMMERCIAL) {
217 #ifdef CONFIG_REVISION_TAG
218 u32 __weak get_board_rev(void)
220 u32 cpurev = get_cpu_rev();
221 u32 type = ((cpurev >> 12) & 0xff);
222 if (type == MXC_CPU_MX6SOLO)
223 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
225 if (type == MXC_CPU_MX6D)
226 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
232 static void clear_ldo_ramp(void)
234 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
237 /* ROM may modify LDO ramp up time according to fuse setting, so in
238 * order to be in the safe side we neeed to reset these settings to
239 * match the reset value: 0'b00
241 reg = readl(&anatop->ana_misc2);
242 reg &= ~(0x3f << 24);
243 writel(reg, &anatop->ana_misc2);
247 * Set the PMU_REG_CORE register
249 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
250 * Possible values are from 0.725V to 1.450V in steps of
253 static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
255 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
256 u32 val, step, old, reg = readl(&anatop->reg_core);
259 /* No LDO_SOC/PU/ARM */
264 val = 0x00; /* Power gated off */
266 val = 0x1F; /* Power FET switched full on. No regulation */
268 val = (mv - 700) / 25;
286 old = (reg & (0x1F << shift)) >> shift;
287 step = abs(val - old);
291 reg = (reg & ~(0x1F << shift)) | (val << shift);
292 writel(reg, &anatop->reg_core);
295 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
303 static void set_ahb_rate(u32 val)
305 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
308 div = get_periph_clk() / val - 1;
309 reg = readl(&mxc_ccm->cbcdr);
311 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
312 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
315 static void clear_mmdc_ch_mask(void)
317 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
319 reg = readl(&mxc_ccm->ccdr);
321 /* Clear MMDC channel mask */
322 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll())
323 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
325 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
326 writel(reg, &mxc_ccm->ccdr);
329 #define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
331 static void init_bandgap(void)
333 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
334 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
335 struct fuse_bank *bank = &ocotp->bank[1];
336 struct fuse_bank1_regs *fuse =
337 (struct fuse_bank1_regs *)bank->fuse_regs;
341 * Ensure the bandgap has stabilized.
343 while (!(readl(&anatop->ana_misc0) & 0x80))
346 * For best noise performance of the analog blocks using the
347 * outputs of the bandgap, the reftop_selfbiasoff bit should
350 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
352 * On i.MX6ULL,we need to set VBGADJ bits according to the
353 * REFTOP_TRIM[3:0] in fuse table
354 * 000 - set REFTOP_VBGADJ[2:0] to 3b'110,
355 * 110 - set REFTOP_VBGADJ[2:0] to 3b'000,
356 * 001 - set REFTOP_VBGADJ[2:0] to 3b'001,
357 * 010 - set REFTOP_VBGADJ[2:0] to 3b'010,
358 * 011 - set REFTOP_VBGADJ[2:0] to 3b'011,
359 * 100 - set REFTOP_VBGADJ[2:0] to 3b'100,
360 * 101 - set REFTOP_VBGADJ[2:0] to 3b'101,
361 * 111 - set REFTOP_VBGADJ[2:0] to 3b'111,
364 val = readl(&fuse->mem0);
365 val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
368 writel(val << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
369 &anatop->ana_misc0_set);
373 int arch_cpu_init(void)
375 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
379 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
380 clear_mmdc_ch_mask();
383 * Disable self-bias circuit in the analog bandap.
384 * The self-bias circuit is used by the bandgap during startup.
385 * This bit should be set after the bandgap has initialized.
389 if (!is_mx6ul() && !is_mx6ull()) {
391 * When low freq boot is enabled, ROM will not set AHB
392 * freq, so we need to ensure AHB freq is 132MHz in such
395 * To i.MX6UL, when power up, default ARM core and
396 * AHB rate is 396M and 132M.
398 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
399 set_ahb_rate(132000000);
403 if (is_soc_rev(CHIP_REV_1_0) == 0) {
405 * According to the design team's requirement on
406 * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
407 * as open drain 100K (0x0000b8a0).
408 * Only exists on TO1.0
410 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
413 * From TO1.1, SNVS adds internal pull up control
414 * for POR_B, the register filed is GPBIT[1:0],
415 * after system boot up, it can be set to 2b'01
416 * to disable internal pull up.It can save about
417 * 30uA power in SNVS mode.
419 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
421 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
427 * GPBIT[1:0] is suggested to set to 2'b11:
428 * 2'b00 : always PUP100K
429 * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
430 * 2'b10 : always disable PUP100K
431 * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
432 * register offset is different from i.MX6UL, since
433 * i.MX6UL is fixed by ECO.
435 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
436 0x3, MX6UL_SNVS_LP_BASE_ADDR);
439 /* Set perclk to source from OSC 24MHz */
441 setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
443 imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register */
446 setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
453 #ifdef CONFIG_ENV_IS_IN_MMC
454 __weak int board_mmc_get_env_dev(int devno)
456 return CONFIG_SYS_MMC_ENV_DEV;
459 static int mmc_get_boot_dev(void)
461 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
462 u32 soc_sbmr = readl(&src_regs->sbmr1);
468 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
469 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
470 * i.MX6SL/SX/UL has same layout.
472 bootsel = (soc_sbmr & 0x000000FF) >> 6;
474 /* No boot from sd/mmc */
478 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
479 devno = (soc_sbmr & 0x00001800) >> 11;
484 int mmc_get_env_dev(void)
486 int devno = mmc_get_boot_dev();
488 /* If not boot from sd/mmc, use default value */
490 return CONFIG_SYS_MMC_ENV_DEV;
492 return board_mmc_get_env_dev(devno);
495 #ifdef CONFIG_SYS_MMC_ENV_PART
496 __weak int board_mmc_get_env_part(int devno)
498 return CONFIG_SYS_MMC_ENV_PART;
501 uint mmc_get_env_part(struct mmc *mmc)
503 int devno = mmc_get_boot_dev();
505 /* If not boot from sd/mmc, use default value */
507 return CONFIG_SYS_MMC_ENV_PART;
509 return board_mmc_get_env_part(devno);
514 int board_postclk_init(void)
516 /* NO LDO SOC on i.MX6SLL */
520 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
525 #ifndef CONFIG_SPL_BUILD
527 * cfg_val will be used for
528 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
529 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
530 * instead of SBMR1 to determine the boot device.
532 const struct boot_mode soc_boot_modes[] = {
533 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
534 /* reserved value should start rom usb */
535 #if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
536 {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
538 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
540 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
541 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
542 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
543 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
544 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
545 /* 4 bit bus width */
546 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
547 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
548 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
549 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
554 void reset_misc(void)
556 #ifndef CONFIG_SPL_BUILD
557 #ifdef CONFIG_VIDEO_MXS
565 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
566 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
569 u32 reg, periph1, periph2;
571 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll())
574 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
575 * to make sure PFD is working right, otherwise, PFDs may
576 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
577 * workaround in ROM code, as bus clock need it
580 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
581 ANATOP_PFD_CLKGATE_MASK(1) |
582 ANATOP_PFD_CLKGATE_MASK(2) |
583 ANATOP_PFD_CLKGATE_MASK(3);
584 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
585 ANATOP_PFD_CLKGATE_MASK(3);
587 reg = readl(&ccm->cbcmr);
588 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
589 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
590 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
591 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
593 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
594 if ((periph2 != 0x2) && (periph1 != 0x2))
595 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
597 if ((periph2 != 0x1) && (periph1 != 0x1) &&
598 (periph2 != 0x3) && (periph1 != 0x3))
599 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
601 writel(mask480, &anatop->pfd_480_set);
602 writel(mask528, &anatop->pfd_528_set);
603 writel(mask480, &anatop->pfd_480_clr);
604 writel(mask528, &anatop->pfd_528_clr);
607 #ifdef CONFIG_IMX_HDMI
608 void imx_enable_hdmi_phy(void)
610 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
612 reg = readb(&hdmi->phy_conf0);
613 reg |= HDMI_PHY_CONF0_PDZ_MASK;
614 writeb(reg, &hdmi->phy_conf0);
616 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
617 writeb(reg, &hdmi->phy_conf0);
619 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
620 writeb(reg, &hdmi->phy_conf0);
621 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
624 void imx_setup_hdmi(void)
626 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
627 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
631 /* Turn on HDMI PHY clock */
632 reg = readl(&mxc_ccm->CCGR2);
633 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
634 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
635 writel(reg, &mxc_ccm->CCGR2);
636 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
637 reg = readl(&mxc_ccm->chsccdr);
638 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
639 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
640 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
641 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
642 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
643 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
644 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
645 writel(reg, &mxc_ccm->chsccdr);
647 /* Clear the overflow condition */
648 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
649 /* TMDS software reset */
650 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
651 val = readb(&hdmi->fc_invidconf);
652 /* Need minimum 3 times to write to clear the register */
653 for (count = 0 ; count < 5 ; count++)
654 writeb(val, &hdmi->fc_invidconf);
661 * gpr_init() function is common for boards using MX6S, MX6DL, MX6D,
662 * MX6Q and MX6QP processors
666 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
669 * If this function is used in a common MX6 spl implementation
670 * we have to ensure that it is only called for suitable cpu types,
671 * otherwise it breaks hardware parts like enet1, can1, can2, etc.
673 if (!is_mx6dqp() && !is_mx6dq() && !is_mx6sdl())
676 /* enable AXI cache for VDOA/VPU/IPU */
677 writel(0xF00000CF, &iomux->gpr[4]);
679 /* set IPU AXI-id1 Qos=0x1 AXI-id0/2/3 Qos=0x7 */
680 writel(0x77177717, &iomux->gpr[6]);
681 writel(0x77177717, &iomux->gpr[7]);
683 /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
684 writel(0x007F007F, &iomux->gpr[6]);
685 writel(0x007F007F, &iomux->gpr[7]);