]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/armv7/mx7ulp/soc.c
imx: mx7ulp: Add soc level initialization codes and functions
[u-boot] / arch / arm / cpu / armv7 / mx7ulp / soc.c
1 /*
2  * Copyright (C) 2016 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 #include <asm/io.h>
7 #include <asm/arch/clock.h>
8 #include <asm/arch/imx-regs.h>
9 #include <asm/arch/sys_proto.h>
10
11 static char *get_reset_cause(char *);
12
13 u32 get_cpu_rev(void)
14 {
15         /* Temporally hard code the CPU rev to 0x73, rev 1.0. Fix it later */
16         return (MXC_CPU_MX7ULP << 12) | (1 << 4);
17 }
18
19 #ifdef CONFIG_REVISION_TAG
20 u32 __weak get_board_rev(void)
21 {
22         return get_cpu_rev();
23 }
24 #endif
25
26 enum bt_mode get_boot_mode(void)
27 {
28         u32 bt0_cfg = 0;
29
30         bt0_cfg = readl(CMC0_RBASE + 0x40);
31         bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
32
33         if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
34                 /* No low power boot */
35                 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
36                         return DUAL_BOOT;
37                 else
38                         return SINGLE_BOOT;
39         }
40
41         return LOW_POWER_BOOT;
42 }
43
44 int arch_cpu_init(void)
45 {
46         return 0;
47 }
48
49 #ifdef CONFIG_BOARD_POSTCLK_INIT
50 int board_postclk_init(void)
51 {
52         return 0;
53 }
54 #endif
55
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 */
60
61 static void disable_wdog(u32 wdog_base)
62 {
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 */
68
69         writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
70         writel(REFRESH_WORD1, (wdog_base + 0x04));
71 }
72
73 void init_wdog(void)
74 {
75         /*
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.
87          */
88         disable_wdog(WDG1_RBASE);
89         disable_wdog(WDG2_RBASE);
90 }
91
92
93 void s_init(void)
94 {
95         /* Disable wdog */
96         init_wdog();
97
98         /* clock configuration. */
99         clock_init();
100
101         return;
102 }
103
104 #ifndef CONFIG_ULP_WATCHDOG
105 void reset_cpu(ulong addr)
106 {
107         setbits_le32(SIM0_RBASE, SIM_SOPT1_A7_SW_RESET);
108         while (1)
109                 ;
110 }
111 #endif
112
113 #if defined(CONFIG_DISPLAY_CPUINFO)
114 const char *get_imx_type(u32 imxtype)
115 {
116         return "7ULP";
117 }
118
119 int print_cpuinfo(void)
120 {
121         u32 cpurev;
122         char cause[18];
123
124         cpurev = get_cpu_rev();
125
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);
130
131         printf("Reset cause: %s\n", get_reset_cause(cause));
132
133         printf("Boot mode: ");
134         switch (get_boot_mode()) {
135         case LOW_POWER_BOOT:
136                 printf("Low power boot\n");
137                 break;
138         case DUAL_BOOT:
139                 printf("Dual boot\n");
140                 break;
141         case SINGLE_BOOT:
142         default:
143                 printf("Single boot\n");
144                 break;
145         }
146
147         return 0;
148 }
149 #endif
150
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)
165
166 static u32 reset_cause = -1;
167
168 static char *get_reset_cause(char *ret)
169 {
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);
173
174         if (!ret)
175                 return "null";
176
177         srs = readl(reg_srs);
178         cause1 = readl(reg_ssrs);
179         writel(cause1, reg_ssrs);
180
181         reset_cause = cause1;
182
183         cause = cause1 & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
184
185         switch (cause) {
186         case CMC_SRS_POR:
187                 sprintf(ret, "%s", "POR");
188                 break;
189         case CMC_SRS_WUP:
190                 sprintf(ret, "%s", "WUP");
191                 break;
192         case CMC_SRS_WARM:
193                 cause = cause1 & (CMC_SRS_WDG | CMC_SRS_SW |
194                         CMC_SRS_JTAG_RST);
195                 switch (cause) {
196                 case CMC_SRS_WDG:
197                         sprintf(ret, "%s", "WARM-WDG");
198                         break;
199                 case CMC_SRS_SW:
200                         sprintf(ret, "%s", "WARM-SW");
201                         break;
202                 case CMC_SRS_JTAG_RST:
203                         sprintf(ret, "%s", "WARM-JTAG");
204                         break;
205                 default:
206                         sprintf(ret, "%s", "WARM-UNKN");
207                         break;
208                 }
209                 break;
210         default:
211                 sprintf(ret, "%s-%X", "UNKN", cause1);
212                 break;
213         }
214
215         debug("[%X] SRS[%X] %X - ", cause1, srs, srs^cause1);
216         return ret;
217 }
218
219 #ifdef CONFIG_ENV_IS_IN_MMC
220 __weak int board_mmc_get_env_dev(int devno)
221 {
222         return CONFIG_SYS_MMC_ENV_DEV;
223 }
224
225 int mmc_get_env_dev(void)
226 {
227         int devno = 0;
228         u32 bt1_cfg = 0;
229
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;
233
234         bt1_cfg = readl(CMC1_RBASE + 0x40);
235         devno = (bt1_cfg >> 9) & 0x7;
236
237         return board_mmc_get_env_dev(devno);
238 }
239 #endif