1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
11 #include <asm/arch/clock.h>
12 #include <asm/arch/imx-regs.h>
13 #include <asm/arch/sys_proto.h>
14 #include <asm/mach-imx/boot_mode.h>
15 #include <asm/mach-imx/hab.h>
17 #define PMC0_BASE_ADDR 0x410a1000
18 #define PMC0_CTRL 0x28
19 #define PMC0_CTRL_LDOEN BIT(31)
20 #define PMC0_CTRL_LDOOKDIS BIT(30)
21 #define PMC0_CTRL_PMC1ON BIT(24)
22 #define PMC1_BASE_ADDR 0x40400000
24 #define PMC1_STOP 0x10
25 #define PMC1_VLPS 0x14
26 #define PMC1_LDOVL_SHIFT 16
27 #define PMC1_LDOVL_MASK (0x3f << PMC1_LDOVL_SHIFT)
28 #define PMC1_LDOVL_900 0x1e
29 #define PMC1_LDOVL_950 0x23
30 #define PMC1_STATUS 0x20
31 #define PMC1_STATUS_LDOVLF BIT(8)
33 static char *get_reset_cause(char *);
35 #if defined(CONFIG_IMX_HAB)
36 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
42 #define ROM_VERSION_ADDR 0x80
45 /* Check the ROM version for cpu revision */
46 u32 rom_version = readl((void __iomem *)ROM_VERSION_ADDR);
48 return (MXC_CPU_MX7ULP << 12) | (rom_version & 0xFF);
51 #ifdef CONFIG_REVISION_TAG
52 u32 __weak get_board_rev(void)
58 enum bt_mode get_boot_mode(void)
62 bt0_cfg = readl(CMC0_RBASE + 0x40);
63 bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
65 if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
66 /* No low power boot */
67 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
73 return LOW_POWER_BOOT;
76 int arch_cpu_init(void)
81 #ifdef CONFIG_BOARD_POSTCLK_INIT
82 int board_postclk_init(void)
88 #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
89 #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
90 #define REFRESH_WORD0 0xA602 /* 1st refresh word */
91 #define REFRESH_WORD1 0xB480 /* 2nd refresh word */
93 static void disable_wdog(u32 wdog_base)
95 writel(UNLOCK_WORD0, (wdog_base + 0x04));
96 writel(UNLOCK_WORD1, (wdog_base + 0x04));
97 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
98 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
99 writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
101 writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
102 writel(REFRESH_WORD1, (wdog_base + 0x04));
108 * ROM will configure WDOG1, disable it or enable it
109 * depending on FUSE. The update bit is set for reconfigurable.
110 * We have to use unlock sequence to reconfigure it.
111 * WDOG2 is not touched by ROM, so it will have default value
112 * which is enabled. We can directly configure it.
113 * To simplify the codes, we still use same reconfigure
114 * process as WDOG1. Because the update bit is not set for
115 * WDOG2, the unlock sequence won't take effect really.
116 * It actually directly configure the wdog.
117 * In this function, we will disable both WDOG1 and WDOG2,
118 * and set update bit for both. So that kernel can reconfigure them.
120 disable_wdog(WDG1_RBASE);
121 disable_wdog(WDG2_RBASE);
124 static bool ldo_mode_is_enabled(void)
128 reg = readl(PMC0_BASE_ADDR + PMC0_CTRL);
129 if (reg & PMC0_CTRL_LDOEN)
135 #if !defined(CONFIG_SPL) || (defined(CONFIG_SPL) && defined(CONFIG_SPL_BUILD))
136 #if defined(CONFIG_LDO_ENABLED_MODE)
137 static void init_ldo_mode(void)
141 if (ldo_mode_is_enabled())
145 setbits_le32(PMC0_BASE_ADDR + PMC0_CTRL, PMC0_CTRL_LDOOKDIS);
147 /* Set LDOVL to 0.95V in PMC1_RUN */
148 reg = readl(PMC1_BASE_ADDR + PMC1_RUN);
149 reg &= ~PMC1_LDOVL_MASK;
150 reg |= (PMC1_LDOVL_950 << PMC1_LDOVL_SHIFT);
151 writel(PMC1_BASE_ADDR + PMC1_RUN, reg);
153 /* Wait for LDOVLF to be cleared */
154 reg = readl(PMC1_BASE_ADDR + PMC1_STATUS);
155 while (reg & PMC1_STATUS_LDOVLF)
158 /* Set LDOVL to 0.95V in PMC1_STOP */
159 reg = readl(PMC1_BASE_ADDR + PMC1_STOP);
160 reg &= ~PMC1_LDOVL_MASK;
161 reg |= (PMC1_LDOVL_950 << PMC1_LDOVL_SHIFT);
162 writel(PMC1_BASE_ADDR + PMC1_STOP, reg);
164 /* Set LDOVL to 0.90V in PMC1_VLPS */
165 reg = readl(PMC1_BASE_ADDR + PMC1_VLPS);
166 reg &= ~PMC1_LDOVL_MASK;
167 reg |= (PMC1_LDOVL_900 << PMC1_LDOVL_SHIFT);
168 writel(PMC1_BASE_ADDR + PMC1_VLPS, reg);
171 setbits_le32(PMC0_BASE_ADDR + PMC0_CTRL, PMC0_CTRL_LDOEN);
173 /* Set the PMC1ON bit */
174 setbits_le32(PMC0_BASE_ADDR + PMC0_CTRL, PMC0_CTRL_PMC1ON);
183 /* clock configuration. */
186 if (soc_rev() < CHIP_REV_2_0) {
187 /* enable dumb pmic */
188 writel((readl(SNVS_LP_LPCR) | SNVS_LPCR_DPEN), SNVS_LP_LPCR);
191 #if defined(CONFIG_LDO_ENABLED_MODE)
198 #ifndef CONFIG_ULP_WATCHDOG
199 void reset_cpu(ulong addr)
201 setbits_le32(SIM0_RBASE, SIM_SOPT1_A7_SW_RESET);
207 #if defined(CONFIG_DISPLAY_CPUINFO)
208 const char *get_imx_type(u32 imxtype)
213 int print_cpuinfo(void)
218 cpurev = get_cpu_rev();
220 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
221 get_imx_type((cpurev & 0xFF000) >> 12),
222 (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
223 mxc_get_clock(MXC_ARM_CLK) / 1000000);
225 printf("Reset cause: %s\n", get_reset_cause(cause));
227 printf("Boot mode: ");
228 switch (get_boot_mode()) {
230 printf("Low power boot\n");
233 printf("Dual boot\n");
237 printf("Single boot\n");
241 if (ldo_mode_is_enabled())
242 printf("PMC1: LDO enabled mode\n");
244 printf("PMC1: LDO bypass mode\n");
250 #define CMC_SRS_TAMPER (1 << 31)
251 #define CMC_SRS_SECURITY (1 << 30)
252 #define CMC_SRS_TZWDG (1 << 29)
253 #define CMC_SRS_JTAG_RST (1 << 28)
254 #define CMC_SRS_CORE1 (1 << 16)
255 #define CMC_SRS_LOCKUP (1 << 15)
256 #define CMC_SRS_SW (1 << 14)
257 #define CMC_SRS_WDG (1 << 13)
258 #define CMC_SRS_PIN_RESET (1 << 8)
259 #define CMC_SRS_WARM (1 << 4)
260 #define CMC_SRS_HVD (1 << 3)
261 #define CMC_SRS_LVD (1 << 2)
262 #define CMC_SRS_POR (1 << 1)
263 #define CMC_SRS_WUP (1 << 0)
265 static u32 reset_cause = -1;
267 static char *get_reset_cause(char *ret)
269 u32 cause1, cause = 0, srs = 0;
270 u32 *reg_ssrs = (u32 *)(SRC_BASE_ADDR + 0x28);
271 u32 *reg_srs = (u32 *)(SRC_BASE_ADDR + 0x20);
276 srs = readl(reg_srs);
277 cause1 = readl(reg_ssrs);
278 writel(cause1, reg_ssrs);
280 reset_cause = cause1;
282 cause = cause1 & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
286 sprintf(ret, "%s", "POR");
289 sprintf(ret, "%s", "WUP");
292 cause = cause1 & (CMC_SRS_WDG | CMC_SRS_SW |
296 sprintf(ret, "%s", "WARM-WDG");
299 sprintf(ret, "%s", "WARM-SW");
301 case CMC_SRS_JTAG_RST:
302 sprintf(ret, "%s", "WARM-JTAG");
305 sprintf(ret, "%s", "WARM-UNKN");
310 sprintf(ret, "%s-%X", "UNKN", cause1);
314 debug("[%X] SRS[%X] %X - ", cause1, srs, srs^cause1);
318 #ifdef CONFIG_ENV_IS_IN_MMC
319 __weak int board_mmc_get_env_dev(int devno)
321 return CONFIG_SYS_MMC_ENV_DEV;
324 int mmc_get_env_dev(void)
329 /* If not boot from sd/mmc, use default value */
330 if (get_boot_mode() == LOW_POWER_BOOT)
331 return CONFIG_SYS_MMC_ENV_DEV;
333 bt1_cfg = readl(CMC1_RBASE + 0x40);
334 devno = (bt1_cfg >> 9) & 0x7;
336 return board_mmc_get_env_dev(devno);
340 enum boot_device get_boot_device(void)
342 struct bootrom_sw_info **p =
343 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
345 enum boot_device boot_dev = SD1_BOOT;
346 u8 boot_type = (*p)->boot_dev_type;
347 u8 boot_instance = (*p)->boot_dev_instance;
351 boot_dev = boot_instance + SD1_BOOT;
354 boot_dev = boot_instance + MMC1_BOOT;