blob: 46484813d2c77ccda3b210dab4ea8d29dc854f0f [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 */
Simon Glassafb02152019-12-28 10:45:01 -07005#include <cpu_func.h>
Simon Glassa7b51302019-11-14 12:57:46 -07006#include <init.h>
Peng Fanb5a90292017-02-22 16:21:43 +08007#include <asm/io.h>
8#include <asm/arch/clock.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/sys_proto.h>
Peng Fanb1d6be92019-07-22 01:24:37 +000011#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020012#include <asm/mach-imx/hab.h>
Peng Fanb5a90292017-02-22 16:21:43 +080013
Fabio Estevamd1d70232019-11-05 09:47:51 -030014#define PMC0_BASE_ADDR 0x410a1000
15#define PMC0_CTRL 0x28
16#define PMC0_CTRL_LDOEN BIT(31)
17#define PMC0_CTRL_LDOOKDIS BIT(30)
18#define PMC0_CTRL_PMC1ON BIT(24)
19#define PMC1_BASE_ADDR 0x40400000
20#define PMC1_RUN 0x8
21#define PMC1_STOP 0x10
22#define PMC1_VLPS 0x14
Fabio Estevam04c71e72019-11-05 09:47:52 -030023#define PMC1_LDOVL_SHIFT 16
24#define PMC1_LDOVL_MASK (0x3f << PMC1_LDOVL_SHIFT)
25#define PMC1_LDOVL_900 0x1e
26#define PMC1_LDOVL_950 0x23
Fabio Estevamd1d70232019-11-05 09:47:51 -030027#define PMC1_STATUS 0x20
28#define PMC1_STATUS_LDOVLF BIT(8)
29
Peng Fanb5a90292017-02-22 16:21:43 +080030static char *get_reset_cause(char *);
31
Stefano Babicf8b509b2019-09-20 08:47:53 +020032#if defined(CONFIG_IMX_HAB)
Peng Fana26ba6d2017-02-22 16:21:53 +080033struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
34 .bank = 29,
35 .word = 6,
36};
37#endif
38
Peng Fan67753cf2019-07-22 01:25:05 +000039#define ROM_VERSION_ADDR 0x80
Peng Fanb5a90292017-02-22 16:21:43 +080040u32 get_cpu_rev(void)
41{
Peng Fan67753cf2019-07-22 01:25:05 +000042 /* Check the ROM version for cpu revision */
43 u32 rom_version = readl((void __iomem *)ROM_VERSION_ADDR);
44
45 return (MXC_CPU_MX7ULP << 12) | (rom_version & 0xFF);
Peng Fanb5a90292017-02-22 16:21:43 +080046}
47
48#ifdef CONFIG_REVISION_TAG
49u32 __weak get_board_rev(void)
50{
51 return get_cpu_rev();
52}
53#endif
54
55enum bt_mode get_boot_mode(void)
56{
57 u32 bt0_cfg = 0;
58
59 bt0_cfg = readl(CMC0_RBASE + 0x40);
60 bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
61
62 if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
63 /* No low power boot */
64 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
65 return DUAL_BOOT;
66 else
67 return SINGLE_BOOT;
68 }
69
70 return LOW_POWER_BOOT;
71}
72
73int arch_cpu_init(void)
74{
75 return 0;
76}
77
78#ifdef CONFIG_BOARD_POSTCLK_INIT
79int board_postclk_init(void)
80{
81 return 0;
82}
83#endif
84
85#define UNLOCK_WORD0 0xC520 /* 1st unlock word */
86#define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
87#define REFRESH_WORD0 0xA602 /* 1st refresh word */
88#define REFRESH_WORD1 0xB480 /* 2nd refresh word */
89
90static void disable_wdog(u32 wdog_base)
91{
92 writel(UNLOCK_WORD0, (wdog_base + 0x04));
93 writel(UNLOCK_WORD1, (wdog_base + 0x04));
94 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
95 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
96 writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
97
98 writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
99 writel(REFRESH_WORD1, (wdog_base + 0x04));
100}
101
102void init_wdog(void)
103{
104 /*
105 * ROM will configure WDOG1, disable it or enable it
106 * depending on FUSE. The update bit is set for reconfigurable.
107 * We have to use unlock sequence to reconfigure it.
108 * WDOG2 is not touched by ROM, so it will have default value
109 * which is enabled. We can directly configure it.
110 * To simplify the codes, we still use same reconfigure
111 * process as WDOG1. Because the update bit is not set for
112 * WDOG2, the unlock sequence won't take effect really.
113 * It actually directly configure the wdog.
114 * In this function, we will disable both WDOG1 and WDOG2,
115 * and set update bit for both. So that kernel can reconfigure them.
116 */
117 disable_wdog(WDG1_RBASE);
118 disable_wdog(WDG2_RBASE);
119}
120
Jorge Ramirez-Ortiz409cf642020-01-17 10:50:25 +0100121#if !defined(CONFIG_SPL) || (defined(CONFIG_SPL) && defined(CONFIG_SPL_BUILD))
Fabio Estevamd1d70232019-11-05 09:47:51 -0300122#if defined(CONFIG_LDO_ENABLED_MODE)
123static void init_ldo_mode(void)
124{
125 unsigned int reg;
126
127 /* Set LDOOKDIS */
128 setbits_le32(PMC0_BASE_ADDR + PMC0_CTRL, PMC0_CTRL_LDOOKDIS);
129
130 /* Set LDOVL to 0.95V in PMC1_RUN */
131 reg = readl(PMC1_BASE_ADDR + PMC1_RUN);
Fabio Estevam04c71e72019-11-05 09:47:52 -0300132 reg &= ~PMC1_LDOVL_MASK;
133 reg |= (PMC1_LDOVL_950 << PMC1_LDOVL_SHIFT);
Fabio Estevamd1d70232019-11-05 09:47:51 -0300134 writel(PMC1_BASE_ADDR + PMC1_RUN, reg);
135
136 /* Wait for LDOVLF to be cleared */
137 reg = readl(PMC1_BASE_ADDR + PMC1_STATUS);
138 while (reg & PMC1_STATUS_LDOVLF)
139 ;
140
141 /* Set LDOVL to 0.95V in PMC1_STOP */
142 reg = readl(PMC1_BASE_ADDR + PMC1_STOP);
Fabio Estevam04c71e72019-11-05 09:47:52 -0300143 reg &= ~PMC1_LDOVL_MASK;
144 reg |= (PMC1_LDOVL_950 << PMC1_LDOVL_SHIFT);
Fabio Estevamd1d70232019-11-05 09:47:51 -0300145 writel(PMC1_BASE_ADDR + PMC1_STOP, reg);
146
147 /* Set LDOVL to 0.90V in PMC1_VLPS */
148 reg = readl(PMC1_BASE_ADDR + PMC1_VLPS);
Fabio Estevam04c71e72019-11-05 09:47:52 -0300149 reg &= ~PMC1_LDOVL_MASK;
150 reg |= (PMC1_LDOVL_900 << PMC1_LDOVL_SHIFT);
Fabio Estevamd1d70232019-11-05 09:47:51 -0300151 writel(PMC1_BASE_ADDR + PMC1_VLPS, reg);
152
153 /* Set LDOEN bit */
154 setbits_le32(PMC0_BASE_ADDR + PMC0_CTRL, PMC0_CTRL_LDOEN);
155
156 /* Set the PMC1ON bit */
157 setbits_le32(PMC0_BASE_ADDR + PMC0_CTRL, PMC0_CTRL_PMC1ON);
158}
159#endif
Peng Fanb5a90292017-02-22 16:21:43 +0800160
161void s_init(void)
162{
163 /* Disable wdog */
164 init_wdog();
165
166 /* clock configuration. */
167 clock_init();
168
Bai Pingb1b61c62019-07-22 01:24:42 +0000169 if (soc_rev() < CHIP_REV_2_0) {
170 /* enable dumb pmic */
171 writel((readl(SNVS_LP_LPCR) | SNVS_LPCR_DPEN), SNVS_LP_LPCR);
172 }
Fabio Estevamd1d70232019-11-05 09:47:51 -0300173
174#if defined(CONFIG_LDO_ENABLED_MODE)
175 init_ldo_mode();
176#endif
Peng Fanb5a90292017-02-22 16:21:43 +0800177 return;
178}
Jorge Ramirez-Ortiz409cf642020-01-17 10:50:25 +0100179#endif
Peng Fanb5a90292017-02-22 16:21:43 +0800180
181#ifndef CONFIG_ULP_WATCHDOG
182void reset_cpu(ulong addr)
183{
184 setbits_le32(SIM0_RBASE, SIM_SOPT1_A7_SW_RESET);
185 while (1)
186 ;
187}
188#endif
189
190#if defined(CONFIG_DISPLAY_CPUINFO)
191const char *get_imx_type(u32 imxtype)
192{
193 return "7ULP";
194}
195
Fabio Estevama320c122019-11-05 09:47:50 -0300196#define PMC0_BASE_ADDR 0x410a1000
197#define PMC0_CTRL 0x28
198#define PMC0_CTRL_LDOEN BIT(31)
199
200static bool ldo_mode_is_enabled(void)
201{
202 unsigned int reg;
203
204 reg = readl(PMC0_BASE_ADDR + PMC0_CTRL);
205 if (reg & PMC0_CTRL_LDOEN)
206 return true;
207 else
208 return false;
209}
210
Peng Fanb5a90292017-02-22 16:21:43 +0800211int print_cpuinfo(void)
212{
213 u32 cpurev;
214 char cause[18];
215
216 cpurev = get_cpu_rev();
217
218 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
219 get_imx_type((cpurev & 0xFF000) >> 12),
220 (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
221 mxc_get_clock(MXC_ARM_CLK) / 1000000);
222
223 printf("Reset cause: %s\n", get_reset_cause(cause));
224
225 printf("Boot mode: ");
226 switch (get_boot_mode()) {
227 case LOW_POWER_BOOT:
228 printf("Low power boot\n");
229 break;
230 case DUAL_BOOT:
231 printf("Dual boot\n");
232 break;
233 case SINGLE_BOOT:
234 default:
235 printf("Single boot\n");
236 break;
237 }
238
Fabio Estevama320c122019-11-05 09:47:50 -0300239 if (ldo_mode_is_enabled())
240 printf("PMC1: LDO enabled mode\n");
241 else
242 printf("PMC1: LDO bypass mode\n");
243
Peng Fanb5a90292017-02-22 16:21:43 +0800244 return 0;
245}
246#endif
247
248#define CMC_SRS_TAMPER (1 << 31)
249#define CMC_SRS_SECURITY (1 << 30)
250#define CMC_SRS_TZWDG (1 << 29)
251#define CMC_SRS_JTAG_RST (1 << 28)
252#define CMC_SRS_CORE1 (1 << 16)
253#define CMC_SRS_LOCKUP (1 << 15)
254#define CMC_SRS_SW (1 << 14)
255#define CMC_SRS_WDG (1 << 13)
256#define CMC_SRS_PIN_RESET (1 << 8)
257#define CMC_SRS_WARM (1 << 4)
258#define CMC_SRS_HVD (1 << 3)
259#define CMC_SRS_LVD (1 << 2)
260#define CMC_SRS_POR (1 << 1)
261#define CMC_SRS_WUP (1 << 0)
262
263static u32 reset_cause = -1;
264
265static char *get_reset_cause(char *ret)
266{
267 u32 cause1, cause = 0, srs = 0;
268 u32 *reg_ssrs = (u32 *)(SRC_BASE_ADDR + 0x28);
269 u32 *reg_srs = (u32 *)(SRC_BASE_ADDR + 0x20);
270
271 if (!ret)
272 return "null";
273
274 srs = readl(reg_srs);
275 cause1 = readl(reg_ssrs);
276 writel(cause1, reg_ssrs);
277
278 reset_cause = cause1;
279
280 cause = cause1 & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
281
282 switch (cause) {
283 case CMC_SRS_POR:
284 sprintf(ret, "%s", "POR");
285 break;
286 case CMC_SRS_WUP:
287 sprintf(ret, "%s", "WUP");
288 break;
289 case CMC_SRS_WARM:
290 cause = cause1 & (CMC_SRS_WDG | CMC_SRS_SW |
291 CMC_SRS_JTAG_RST);
292 switch (cause) {
293 case CMC_SRS_WDG:
294 sprintf(ret, "%s", "WARM-WDG");
295 break;
296 case CMC_SRS_SW:
297 sprintf(ret, "%s", "WARM-SW");
298 break;
299 case CMC_SRS_JTAG_RST:
300 sprintf(ret, "%s", "WARM-JTAG");
301 break;
302 default:
303 sprintf(ret, "%s", "WARM-UNKN");
304 break;
305 }
306 break;
307 default:
308 sprintf(ret, "%s-%X", "UNKN", cause1);
309 break;
310 }
311
312 debug("[%X] SRS[%X] %X - ", cause1, srs, srs^cause1);
313 return ret;
314}
315
316#ifdef CONFIG_ENV_IS_IN_MMC
317__weak int board_mmc_get_env_dev(int devno)
318{
319 return CONFIG_SYS_MMC_ENV_DEV;
320}
321
322int mmc_get_env_dev(void)
323{
324 int devno = 0;
325 u32 bt1_cfg = 0;
326
327 /* If not boot from sd/mmc, use default value */
328 if (get_boot_mode() == LOW_POWER_BOOT)
329 return CONFIG_SYS_MMC_ENV_DEV;
330
331 bt1_cfg = readl(CMC1_RBASE + 0x40);
332 devno = (bt1_cfg >> 9) & 0x7;
333
334 return board_mmc_get_env_dev(devno);
335}
336#endif
Peng Fanb1d6be92019-07-22 01:24:37 +0000337
338enum boot_device get_boot_device(void)
339{
340 struct bootrom_sw_info **p =
341 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
342
343 enum boot_device boot_dev = SD1_BOOT;
344 u8 boot_type = (*p)->boot_dev_type;
345 u8 boot_instance = (*p)->boot_dev_instance;
346
347 switch (boot_type) {
348 case BOOT_TYPE_SD:
349 boot_dev = boot_instance + SD1_BOOT;
350 break;
351 case BOOT_TYPE_MMC:
352 boot_dev = boot_instance + MMC1_BOOT;
353 break;
354 case BOOT_TYPE_USB:
355 boot_dev = USB_BOOT;
356 break;
357 default:
358 break;
359 }
360
361 return boot_dev;
362}