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