blob: 127fcfeea1a35b32b0f1fa81a409a21686085301 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fanb5a90292017-02-22 16:21:43 +08002/*
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
Peng Fanb5a90292017-02-22 16:21:43 +08004 */
5#include <asm/io.h>
6#include <asm/arch/clock.h>
7#include <asm/arch/imx-regs.h>
8#include <asm/arch/sys_proto.h>
Peng Fanb1d6be92019-07-22 01:24:37 +00009#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020010#include <asm/mach-imx/hab.h>
Peng Fanb5a90292017-02-22 16:21:43 +080011
12static char *get_reset_cause(char *);
13
Stefano Babicf8b509b2019-09-20 08:47:53 +020014#if defined(CONFIG_IMX_HAB)
Peng Fana26ba6d2017-02-22 16:21:53 +080015struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
16 .bank = 29,
17 .word = 6,
18};
19#endif
20
Peng Fan67753cf2019-07-22 01:25:05 +000021#define ROM_VERSION_ADDR 0x80
Peng Fanb5a90292017-02-22 16:21:43 +080022u32 get_cpu_rev(void)
23{
Peng Fan67753cf2019-07-22 01:25:05 +000024 /* Check the ROM version for cpu revision */
25 u32 rom_version = readl((void __iomem *)ROM_VERSION_ADDR);
26
27 return (MXC_CPU_MX7ULP << 12) | (rom_version & 0xFF);
Peng Fanb5a90292017-02-22 16:21:43 +080028}
29
30#ifdef CONFIG_REVISION_TAG
31u32 __weak get_board_rev(void)
32{
33 return get_cpu_rev();
34}
35#endif
36
37enum bt_mode get_boot_mode(void)
38{
39 u32 bt0_cfg = 0;
40
41 bt0_cfg = readl(CMC0_RBASE + 0x40);
42 bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
43
44 if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
45 /* No low power boot */
46 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
47 return DUAL_BOOT;
48 else
49 return SINGLE_BOOT;
50 }
51
52 return LOW_POWER_BOOT;
53}
54
55int arch_cpu_init(void)
56{
57 return 0;
58}
59
60#ifdef CONFIG_BOARD_POSTCLK_INIT
61int board_postclk_init(void)
62{
63 return 0;
64}
65#endif
66
67#define UNLOCK_WORD0 0xC520 /* 1st unlock word */
68#define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
69#define REFRESH_WORD0 0xA602 /* 1st refresh word */
70#define REFRESH_WORD1 0xB480 /* 2nd refresh word */
71
72static void disable_wdog(u32 wdog_base)
73{
74 writel(UNLOCK_WORD0, (wdog_base + 0x04));
75 writel(UNLOCK_WORD1, (wdog_base + 0x04));
76 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
77 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
78 writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
79
80 writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
81 writel(REFRESH_WORD1, (wdog_base + 0x04));
82}
83
84void init_wdog(void)
85{
86 /*
87 * ROM will configure WDOG1, disable it or enable it
88 * depending on FUSE. The update bit is set for reconfigurable.
89 * We have to use unlock sequence to reconfigure it.
90 * WDOG2 is not touched by ROM, so it will have default value
91 * which is enabled. We can directly configure it.
92 * To simplify the codes, we still use same reconfigure
93 * process as WDOG1. Because the update bit is not set for
94 * WDOG2, the unlock sequence won't take effect really.
95 * It actually directly configure the wdog.
96 * In this function, we will disable both WDOG1 and WDOG2,
97 * and set update bit for both. So that kernel can reconfigure them.
98 */
99 disable_wdog(WDG1_RBASE);
100 disable_wdog(WDG2_RBASE);
101}
102
103
104void s_init(void)
105{
106 /* Disable wdog */
107 init_wdog();
108
109 /* clock configuration. */
110 clock_init();
111
Bai Pingb1b61c62019-07-22 01:24:42 +0000112 if (soc_rev() < CHIP_REV_2_0) {
113 /* enable dumb pmic */
114 writel((readl(SNVS_LP_LPCR) | SNVS_LPCR_DPEN), SNVS_LP_LPCR);
115 }
Peng Fanb5a90292017-02-22 16:21:43 +0800116 return;
117}
118
119#ifndef CONFIG_ULP_WATCHDOG
120void reset_cpu(ulong addr)
121{
122 setbits_le32(SIM0_RBASE, SIM_SOPT1_A7_SW_RESET);
123 while (1)
124 ;
125}
126#endif
127
128#if defined(CONFIG_DISPLAY_CPUINFO)
129const char *get_imx_type(u32 imxtype)
130{
131 return "7ULP";
132}
133
134int print_cpuinfo(void)
135{
136 u32 cpurev;
137 char cause[18];
138
139 cpurev = get_cpu_rev();
140
141 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
142 get_imx_type((cpurev & 0xFF000) >> 12),
143 (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
144 mxc_get_clock(MXC_ARM_CLK) / 1000000);
145
146 printf("Reset cause: %s\n", get_reset_cause(cause));
147
148 printf("Boot mode: ");
149 switch (get_boot_mode()) {
150 case LOW_POWER_BOOT:
151 printf("Low power boot\n");
152 break;
153 case DUAL_BOOT:
154 printf("Dual boot\n");
155 break;
156 case SINGLE_BOOT:
157 default:
158 printf("Single boot\n");
159 break;
160 }
161
162 return 0;
163}
164#endif
165
166#define CMC_SRS_TAMPER (1 << 31)
167#define CMC_SRS_SECURITY (1 << 30)
168#define CMC_SRS_TZWDG (1 << 29)
169#define CMC_SRS_JTAG_RST (1 << 28)
170#define CMC_SRS_CORE1 (1 << 16)
171#define CMC_SRS_LOCKUP (1 << 15)
172#define CMC_SRS_SW (1 << 14)
173#define CMC_SRS_WDG (1 << 13)
174#define CMC_SRS_PIN_RESET (1 << 8)
175#define CMC_SRS_WARM (1 << 4)
176#define CMC_SRS_HVD (1 << 3)
177#define CMC_SRS_LVD (1 << 2)
178#define CMC_SRS_POR (1 << 1)
179#define CMC_SRS_WUP (1 << 0)
180
181static u32 reset_cause = -1;
182
183static char *get_reset_cause(char *ret)
184{
185 u32 cause1, cause = 0, srs = 0;
186 u32 *reg_ssrs = (u32 *)(SRC_BASE_ADDR + 0x28);
187 u32 *reg_srs = (u32 *)(SRC_BASE_ADDR + 0x20);
188
189 if (!ret)
190 return "null";
191
192 srs = readl(reg_srs);
193 cause1 = readl(reg_ssrs);
194 writel(cause1, reg_ssrs);
195
196 reset_cause = cause1;
197
198 cause = cause1 & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
199
200 switch (cause) {
201 case CMC_SRS_POR:
202 sprintf(ret, "%s", "POR");
203 break;
204 case CMC_SRS_WUP:
205 sprintf(ret, "%s", "WUP");
206 break;
207 case CMC_SRS_WARM:
208 cause = cause1 & (CMC_SRS_WDG | CMC_SRS_SW |
209 CMC_SRS_JTAG_RST);
210 switch (cause) {
211 case CMC_SRS_WDG:
212 sprintf(ret, "%s", "WARM-WDG");
213 break;
214 case CMC_SRS_SW:
215 sprintf(ret, "%s", "WARM-SW");
216 break;
217 case CMC_SRS_JTAG_RST:
218 sprintf(ret, "%s", "WARM-JTAG");
219 break;
220 default:
221 sprintf(ret, "%s", "WARM-UNKN");
222 break;
223 }
224 break;
225 default:
226 sprintf(ret, "%s-%X", "UNKN", cause1);
227 break;
228 }
229
230 debug("[%X] SRS[%X] %X - ", cause1, srs, srs^cause1);
231 return ret;
232}
233
234#ifdef CONFIG_ENV_IS_IN_MMC
235__weak int board_mmc_get_env_dev(int devno)
236{
237 return CONFIG_SYS_MMC_ENV_DEV;
238}
239
240int mmc_get_env_dev(void)
241{
242 int devno = 0;
243 u32 bt1_cfg = 0;
244
245 /* If not boot from sd/mmc, use default value */
246 if (get_boot_mode() == LOW_POWER_BOOT)
247 return CONFIG_SYS_MMC_ENV_DEV;
248
249 bt1_cfg = readl(CMC1_RBASE + 0x40);
250 devno = (bt1_cfg >> 9) & 0x7;
251
252 return board_mmc_get_env_dev(devno);
253}
254#endif
Peng Fanb1d6be92019-07-22 01:24:37 +0000255
256enum boot_device get_boot_device(void)
257{
258 struct bootrom_sw_info **p =
259 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
260
261 enum boot_device boot_dev = SD1_BOOT;
262 u8 boot_type = (*p)->boot_dev_type;
263 u8 boot_instance = (*p)->boot_dev_instance;
264
265 switch (boot_type) {
266 case BOOT_TYPE_SD:
267 boot_dev = boot_instance + SD1_BOOT;
268 break;
269 case BOOT_TYPE_MMC:
270 boot_dev = boot_instance + MMC1_BOOT;
271 break;
272 case BOOT_TYPE_USB:
273 boot_dev = USB_BOOT;
274 break;
275 default:
276 break;
277 }
278
279 return boot_dev;
280}