2 * Copyright (C) 2016 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
7 #include <asm/arch/clock.h>
8 #include <asm/arch/imx-regs.h>
9 #include <asm/arch/sys_proto.h>
11 static char *get_reset_cause(char *);
15 /* Temporally hard code the CPU rev to 0x73, rev 1.0. Fix it later */
16 return (MXC_CPU_MX7ULP << 12) | (1 << 4);
19 #ifdef CONFIG_REVISION_TAG
20 u32 __weak get_board_rev(void)
26 enum bt_mode get_boot_mode(void)
30 bt0_cfg = readl(CMC0_RBASE + 0x40);
31 bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
33 if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
34 /* No low power boot */
35 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
41 return LOW_POWER_BOOT;
44 int arch_cpu_init(void)
49 #ifdef CONFIG_BOARD_POSTCLK_INIT
50 int board_postclk_init(void)
56 #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
57 #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
58 #define REFRESH_WORD0 0xA602 /* 1st refresh word */
59 #define REFRESH_WORD1 0xB480 /* 2nd refresh word */
61 static void disable_wdog(u32 wdog_base)
63 writel(UNLOCK_WORD0, (wdog_base + 0x04));
64 writel(UNLOCK_WORD1, (wdog_base + 0x04));
65 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
66 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
67 writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
69 writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
70 writel(REFRESH_WORD1, (wdog_base + 0x04));
76 * ROM will configure WDOG1, disable it or enable it
77 * depending on FUSE. The update bit is set for reconfigurable.
78 * We have to use unlock sequence to reconfigure it.
79 * WDOG2 is not touched by ROM, so it will have default value
80 * which is enabled. We can directly configure it.
81 * To simplify the codes, we still use same reconfigure
82 * process as WDOG1. Because the update bit is not set for
83 * WDOG2, the unlock sequence won't take effect really.
84 * It actually directly configure the wdog.
85 * In this function, we will disable both WDOG1 and WDOG2,
86 * and set update bit for both. So that kernel can reconfigure them.
88 disable_wdog(WDG1_RBASE);
89 disable_wdog(WDG2_RBASE);
98 /* clock configuration. */
104 #ifndef CONFIG_ULP_WATCHDOG
105 void reset_cpu(ulong addr)
107 setbits_le32(SIM0_RBASE, SIM_SOPT1_A7_SW_RESET);
113 #if defined(CONFIG_DISPLAY_CPUINFO)
114 const char *get_imx_type(u32 imxtype)
119 int print_cpuinfo(void)
124 cpurev = get_cpu_rev();
126 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
127 get_imx_type((cpurev & 0xFF000) >> 12),
128 (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
129 mxc_get_clock(MXC_ARM_CLK) / 1000000);
131 printf("Reset cause: %s\n", get_reset_cause(cause));
133 printf("Boot mode: ");
134 switch (get_boot_mode()) {
136 printf("Low power boot\n");
139 printf("Dual boot\n");
143 printf("Single boot\n");
151 #define CMC_SRS_TAMPER (1 << 31)
152 #define CMC_SRS_SECURITY (1 << 30)
153 #define CMC_SRS_TZWDG (1 << 29)
154 #define CMC_SRS_JTAG_RST (1 << 28)
155 #define CMC_SRS_CORE1 (1 << 16)
156 #define CMC_SRS_LOCKUP (1 << 15)
157 #define CMC_SRS_SW (1 << 14)
158 #define CMC_SRS_WDG (1 << 13)
159 #define CMC_SRS_PIN_RESET (1 << 8)
160 #define CMC_SRS_WARM (1 << 4)
161 #define CMC_SRS_HVD (1 << 3)
162 #define CMC_SRS_LVD (1 << 2)
163 #define CMC_SRS_POR (1 << 1)
164 #define CMC_SRS_WUP (1 << 0)
166 static u32 reset_cause = -1;
168 static char *get_reset_cause(char *ret)
170 u32 cause1, cause = 0, srs = 0;
171 u32 *reg_ssrs = (u32 *)(SRC_BASE_ADDR + 0x28);
172 u32 *reg_srs = (u32 *)(SRC_BASE_ADDR + 0x20);
177 srs = readl(reg_srs);
178 cause1 = readl(reg_ssrs);
179 writel(cause1, reg_ssrs);
181 reset_cause = cause1;
183 cause = cause1 & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
187 sprintf(ret, "%s", "POR");
190 sprintf(ret, "%s", "WUP");
193 cause = cause1 & (CMC_SRS_WDG | CMC_SRS_SW |
197 sprintf(ret, "%s", "WARM-WDG");
200 sprintf(ret, "%s", "WARM-SW");
202 case CMC_SRS_JTAG_RST:
203 sprintf(ret, "%s", "WARM-JTAG");
206 sprintf(ret, "%s", "WARM-UNKN");
211 sprintf(ret, "%s-%X", "UNKN", cause1);
215 debug("[%X] SRS[%X] %X - ", cause1, srs, srs^cause1);
219 #ifdef CONFIG_ENV_IS_IN_MMC
220 __weak int board_mmc_get_env_dev(int devno)
222 return CONFIG_SYS_MMC_ENV_DEV;
225 int mmc_get_env_dev(void)
230 /* If not boot from sd/mmc, use default value */
231 if (get_boot_mode() == LOW_POWER_BOOT)
232 return CONFIG_SYS_MMC_ENV_DEV;
234 bt1_cfg = readl(CMC1_RBASE + 0x40);
235 devno = (bt1_cfg >> 9) & 0x7;
237 return board_mmc_get_env_dev(devno);