]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - arch/arm/mach-imx/mx7ulp/soc.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
6 #include <asm/arch/clock.h>
7 #include <asm/arch/imx-regs.h>
8 #include <asm/arch/sys_proto.h>
9 #include <asm/mach-imx/hab.h>
11 static char *get_reset_cause(char *);
13 #if defined(CONFIG_SECURE_BOOT)
14 struct imx_sec_config_fuse_t
const imx_sec_config_fuse
= {
22 /* Temporally hard code the CPU rev to 0x73, rev 1.0. Fix it later */
23 return (MXC_CPU_MX7ULP
<< 12) | (1 << 4);
26 #ifdef CONFIG_REVISION_TAG
27 u32 __weak
get_board_rev(void)
33 enum bt_mode
get_boot_mode(void)
37 bt0_cfg
= readl(CMC0_RBASE
+ 0x40);
38 bt0_cfg
&= (BT0CFG_LPBOOT_MASK
| BT0CFG_DUALBOOT_MASK
);
40 if (!(bt0_cfg
& BT0CFG_LPBOOT_MASK
)) {
41 /* No low power boot */
42 if (bt0_cfg
& BT0CFG_DUALBOOT_MASK
)
48 return LOW_POWER_BOOT
;
51 int arch_cpu_init(void)
56 #ifdef CONFIG_BOARD_POSTCLK_INIT
57 int board_postclk_init(void)
63 #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
64 #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
65 #define REFRESH_WORD0 0xA602 /* 1st refresh word */
66 #define REFRESH_WORD1 0xB480 /* 2nd refresh word */
68 static void disable_wdog(u32 wdog_base
)
70 writel(UNLOCK_WORD0
, (wdog_base
+ 0x04));
71 writel(UNLOCK_WORD1
, (wdog_base
+ 0x04));
72 writel(0x0, (wdog_base
+ 0x0C)); /* Set WIN to 0 */
73 writel(0x400, (wdog_base
+ 0x08)); /* Set timeout to default 0x400 */
74 writel(0x120, (wdog_base
+ 0x00)); /* Disable it and set update */
76 writel(REFRESH_WORD0
, (wdog_base
+ 0x04)); /* Refresh the CNT */
77 writel(REFRESH_WORD1
, (wdog_base
+ 0x04));
83 * ROM will configure WDOG1, disable it or enable it
84 * depending on FUSE. The update bit is set for reconfigurable.
85 * We have to use unlock sequence to reconfigure it.
86 * WDOG2 is not touched by ROM, so it will have default value
87 * which is enabled. We can directly configure it.
88 * To simplify the codes, we still use same reconfigure
89 * process as WDOG1. Because the update bit is not set for
90 * WDOG2, the unlock sequence won't take effect really.
91 * It actually directly configure the wdog.
92 * In this function, we will disable both WDOG1 and WDOG2,
93 * and set update bit for both. So that kernel can reconfigure them.
95 disable_wdog(WDG1_RBASE
);
96 disable_wdog(WDG2_RBASE
);
105 /* clock configuration. */
111 #ifndef CONFIG_ULP_WATCHDOG
112 void reset_cpu(ulong addr
)
114 setbits_le32(SIM0_RBASE
, SIM_SOPT1_A7_SW_RESET
);
120 #if defined(CONFIG_DISPLAY_CPUINFO)
121 const char *get_imx_type(u32 imxtype
)
126 int print_cpuinfo(void)
131 cpurev
= get_cpu_rev();
133 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
134 get_imx_type((cpurev
& 0xFF000) >> 12),
135 (cpurev
& 0x000F0) >> 4, (cpurev
& 0x0000F) >> 0,
136 mxc_get_clock(MXC_ARM_CLK
) / 1000000);
138 printf("Reset cause: %s\n", get_reset_cause(cause
));
140 printf("Boot mode: ");
141 switch (get_boot_mode()) {
143 printf("Low power boot\n");
146 printf("Dual boot\n");
150 printf("Single boot\n");
158 #define CMC_SRS_TAMPER (1 << 31)
159 #define CMC_SRS_SECURITY (1 << 30)
160 #define CMC_SRS_TZWDG (1 << 29)
161 #define CMC_SRS_JTAG_RST (1 << 28)
162 #define CMC_SRS_CORE1 (1 << 16)
163 #define CMC_SRS_LOCKUP (1 << 15)
164 #define CMC_SRS_SW (1 << 14)
165 #define CMC_SRS_WDG (1 << 13)
166 #define CMC_SRS_PIN_RESET (1 << 8)
167 #define CMC_SRS_WARM (1 << 4)
168 #define CMC_SRS_HVD (1 << 3)
169 #define CMC_SRS_LVD (1 << 2)
170 #define CMC_SRS_POR (1 << 1)
171 #define CMC_SRS_WUP (1 << 0)
173 static u32 reset_cause
= -1;
175 static char *get_reset_cause(char *ret
)
177 u32 cause1
, cause
= 0, srs
= 0;
178 u32
*reg_ssrs
= (u32
*)(SRC_BASE_ADDR
+ 0x28);
179 u32
*reg_srs
= (u32
*)(SRC_BASE_ADDR
+ 0x20);
184 srs
= readl(reg_srs
);
185 cause1
= readl(reg_ssrs
);
186 writel(cause1
, reg_ssrs
);
188 reset_cause
= cause1
;
190 cause
= cause1
& (CMC_SRS_POR
| CMC_SRS_WUP
| CMC_SRS_WARM
);
194 sprintf(ret
, "%s", "POR");
197 sprintf(ret
, "%s", "WUP");
200 cause
= cause1
& (CMC_SRS_WDG
| CMC_SRS_SW
|
204 sprintf(ret
, "%s", "WARM-WDG");
207 sprintf(ret
, "%s", "WARM-SW");
209 case CMC_SRS_JTAG_RST
:
210 sprintf(ret
, "%s", "WARM-JTAG");
213 sprintf(ret
, "%s", "WARM-UNKN");
218 sprintf(ret
, "%s-%X", "UNKN", cause1
);
222 debug("[%X] SRS[%X] %X - ", cause1
, srs
, srs
^cause1
);
226 #ifdef CONFIG_ENV_IS_IN_MMC
227 __weak
int board_mmc_get_env_dev(int devno
)
229 return CONFIG_SYS_MMC_ENV_DEV
;
232 int mmc_get_env_dev(void)
237 /* If not boot from sd/mmc, use default value */
238 if (get_boot_mode() == LOW_POWER_BOOT
)
239 return CONFIG_SYS_MMC_ENV_DEV
;
241 bt1_cfg
= readl(CMC1_RBASE
+ 0x40);
242 devno
= (bt1_cfg
>> 9) & 0x7;
244 return board_mmc_get_env_dev(devno
);