]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/armv7/mx7/soc.c
imx: mx7: implement functions to boot auxiliary core
[u-boot] / arch / arm / cpu / armv7 / mx7 / soc.c
1 /*
2  * Copyright (C) 2015 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <asm/io.h>
9 #include <asm/arch/imx-regs.h>
10 #include <asm/arch/clock.h>
11 #include <asm/arch/sys_proto.h>
12 #include <asm/imx-common/boot_mode.h>
13 #include <asm/imx-common/dma.h>
14 #include <asm/imx-common/hab.h>
15 #include <asm/arch/crm_regs.h>
16 #include <dm.h>
17 #include <imx_thermal.h>
18
19 #if defined(CONFIG_IMX_THERMAL)
20 static const struct imx_thermal_plat imx7_thermal_plat = {
21         .regs = (void *)ANATOP_BASE_ADDR,
22         .fuse_bank = 3,
23         .fuse_word = 3,
24 };
25
26 U_BOOT_DEVICE(imx7_thermal) = {
27         .name = "imx_thermal",
28         .platdata = &imx7_thermal_plat,
29 };
30 #endif
31
32 #if defined(CONFIG_SECURE_BOOT)
33 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
34         .bank = 1,
35         .word = 3,
36 };
37 #endif
38
39 /*
40  * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
41  * defines a 2-bit SPEED_GRADING
42  */
43 #define OCOTP_TESTER3_SPEED_SHIFT       8
44 #define OCOTP_TESTER3_SPEED_800MHZ      0
45 #define OCOTP_TESTER3_SPEED_850MHZ      1
46 #define OCOTP_TESTER3_SPEED_1GHZ        2
47
48 u32 get_cpu_speed_grade_hz(void)
49 {
50         struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
51         struct fuse_bank *bank = &ocotp->bank[1];
52         struct fuse_bank1_regs *fuse =
53                 (struct fuse_bank1_regs *)bank->fuse_regs;
54         uint32_t val;
55
56         val = readl(&fuse->tester3);
57         val >>= OCOTP_TESTER3_SPEED_SHIFT;
58         val &= 0x3;
59
60         switch(val) {
61         case OCOTP_TESTER3_SPEED_800MHZ:
62                 return 792000000;
63         case OCOTP_TESTER3_SPEED_850MHZ:
64                 return 852000000;
65         case OCOTP_TESTER3_SPEED_1GHZ:
66                 return 996000000;
67         }
68         return 0;
69 }
70
71 /*
72  * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
73  * defines a 2-bit SPEED_GRADING
74  */
75 #define OCOTP_TESTER3_TEMP_SHIFT        6
76
77 u32 get_cpu_temp_grade(int *minc, int *maxc)
78 {
79         struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
80         struct fuse_bank *bank = &ocotp->bank[1];
81         struct fuse_bank1_regs *fuse =
82                 (struct fuse_bank1_regs *)bank->fuse_regs;
83         uint32_t val;
84
85         val = readl(&fuse->tester3);
86         val >>= OCOTP_TESTER3_TEMP_SHIFT;
87         val &= 0x3;
88
89         if (minc && maxc) {
90                 if (val == TEMP_AUTOMOTIVE) {
91                         *minc = -40;
92                         *maxc = 125;
93                 } else if (val == TEMP_INDUSTRIAL) {
94                         *minc = -40;
95                         *maxc = 105;
96                 } else if (val == TEMP_EXTCOMMERCIAL) {
97                         *minc = -20;
98                         *maxc = 105;
99                 } else {
100                         *minc = 0;
101                         *maxc = 95;
102                 }
103         }
104         return val;
105 }
106
107 u32 get_cpu_rev(void)
108 {
109         struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
110                                                  ANATOP_BASE_ADDR;
111         u32 reg = readl(&ccm_anatop->digprog);
112         u32 type = (reg >> 16) & 0xff;
113
114         reg &= 0xff;
115         return (type << 12) | reg;
116 }
117
118 #ifdef CONFIG_REVISION_TAG
119 u32 __weak get_board_rev(void)
120 {
121         return get_cpu_rev();
122 }
123 #endif
124
125 /* enable all periherial can be accessed in nosec mode */
126 static void init_csu(void)
127 {
128         int i = 0;
129         for (i = 0; i < CSU_NUM_REGS; i++)
130                 writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
131 }
132
133 static void imx_enet_mdio_fixup(void)
134 {
135         struct iomuxc_gpr_base_regs *gpr_regs =
136                 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
137
138         /*
139          * The management data input/output (MDIO) requires open-drain,
140          * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports
141          * this feature. So to TO1.1, need to enable open drain by setting
142          * bits GPR0[8:7].
143          */
144
145         if (soc_rev() >= CHIP_REV_1_1) {
146                 setbits_le32(&gpr_regs->gpr[0],
147                              IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
148         }
149 }
150
151 int arch_cpu_init(void)
152 {
153         init_aips();
154
155         init_csu();
156         /* Disable PDE bit of WMCR register */
157         imx_set_wdog_powerdown(false);
158
159         imx_enet_mdio_fixup();
160
161 #ifdef CONFIG_APBH_DMA
162         /* Start APBH DMA */
163         mxs_dma_init();
164 #endif
165
166         return 0;
167 }
168
169 #ifdef CONFIG_SERIAL_TAG
170 void get_board_serial(struct tag_serialnr *serialnr)
171 {
172         struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
173         struct fuse_bank *bank = &ocotp->bank[0];
174         struct fuse_bank0_regs *fuse =
175                 (struct fuse_bank0_regs *)bank->fuse_regs;
176
177         serialnr->low = fuse->tester0;
178         serialnr->high = fuse->tester1;
179 }
180 #endif
181
182 #if defined(CONFIG_FEC_MXC)
183 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
184 {
185         struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
186         struct fuse_bank *bank = &ocotp->bank[9];
187         struct fuse_bank9_regs *fuse =
188                 (struct fuse_bank9_regs *)bank->fuse_regs;
189
190         if (0 == dev_id) {
191                 u32 value = readl(&fuse->mac_addr1);
192                 mac[0] = (value >> 8);
193                 mac[1] = value;
194
195                 value = readl(&fuse->mac_addr0);
196                 mac[2] = value >> 24;
197                 mac[3] = value >> 16;
198                 mac[4] = value >> 8;
199                 mac[5] = value;
200         } else {
201                 u32 value = readl(&fuse->mac_addr2);
202                 mac[0] = value >> 24;
203                 mac[1] = value >> 16;
204                 mac[2] = value >> 8;
205                 mac[3] = value;
206
207                 value = readl(&fuse->mac_addr1);
208                 mac[4] = value >> 24;
209                 mac[5] = value >> 16;
210         }
211 }
212 #endif
213
214 #ifdef CONFIG_IMX_BOOTAUX
215 int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data)
216 {
217         u32 stack, pc;
218         struct src *src_reg = (struct src *)SRC_BASE_ADDR;
219
220         if (!boot_private_data)
221                 return 1;
222
223         stack = *(u32 *)boot_private_data;
224         pc = *(u32 *)(boot_private_data + 4);
225
226         /* Set the stack and pc to M4 bootROM */
227         writel(stack, M4_BOOTROM_BASE_ADDR);
228         writel(pc, M4_BOOTROM_BASE_ADDR + 4);
229
230         /* Enable M4 */
231         clrsetbits_le32(&src_reg->m4rcr, SRC_M4RCR_M4C_NON_SCLR_RST_MASK,
232                         SRC_M4RCR_ENABLE_M4_MASK);
233
234         return 0;
235 }
236
237 int arch_auxiliary_core_check_up(u32 core_id)
238 {
239         uint32_t val;
240         struct src *src_reg = (struct src *)SRC_BASE_ADDR;
241
242         val = readl(&src_reg->m4rcr);
243         if (val & 0x00000001)
244                 return 0; /* assert in reset */
245
246         return 1;
247 }
248 #endif
249
250 void set_wdog_reset(struct wdog_regs *wdog)
251 {
252         u32 reg = readw(&wdog->wcr);
253         /*
254          * Output WDOG_B signal to reset external pmic or POR_B decided by
255          * the board desgin. Without external reset, the peripherals/DDR/
256          * PMIC are not reset, that may cause system working abnormal.
257          */
258         reg = readw(&wdog->wcr);
259         reg |= 1 << 3;
260         /*
261          * WDZST bit is write-once only bit. Align this bit in kernel,
262          * otherwise kernel code will have no chance to set this bit.
263          */
264         reg |= 1 << 0;
265         writew(reg, &wdog->wcr);
266 }
267
268 /*
269  * cfg_val will be used for
270  * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
271  * After reset, if GPR10[28] is 1, ROM will copy GPR9[25:0]
272  * to SBMR1, which will determine the boot device.
273  */
274 const struct boot_mode soc_boot_modes[] = {
275         {"ecspi1:0",    MAKE_CFGVAL(0x00, 0x60, 0x00, 0x00)},
276         {"ecspi1:1",    MAKE_CFGVAL(0x40, 0x62, 0x00, 0x00)},
277         {"ecspi1:2",    MAKE_CFGVAL(0x80, 0x64, 0x00, 0x00)},
278         {"ecspi1:3",    MAKE_CFGVAL(0xc0, 0x66, 0x00, 0x00)},
279
280         {"weim",        MAKE_CFGVAL(0x00, 0x50, 0x00, 0x00)},
281         {"qspi1",       MAKE_CFGVAL(0x10, 0x40, 0x00, 0x00)},
282         /* 4 bit bus width */
283         {"usdhc1",      MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
284         {"usdhc2",      MAKE_CFGVAL(0x10, 0x14, 0x00, 0x00)},
285         {"usdhc3",      MAKE_CFGVAL(0x10, 0x18, 0x00, 0x00)},
286         {"mmc1",        MAKE_CFGVAL(0x10, 0x20, 0x00, 0x00)},
287         {"mmc2",        MAKE_CFGVAL(0x10, 0x24, 0x00, 0x00)},
288         {"mmc3",        MAKE_CFGVAL(0x10, 0x28, 0x00, 0x00)},
289         {NULL,          0},
290 };
291
292 enum boot_device get_boot_device(void)
293 {
294         struct bootrom_sw_info **p =
295                 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
296
297         enum boot_device boot_dev = SD1_BOOT;
298         u8 boot_type = (*p)->boot_dev_type;
299         u8 boot_instance = (*p)->boot_dev_instance;
300
301         switch (boot_type) {
302         case BOOT_TYPE_SD:
303                 boot_dev = boot_instance + SD1_BOOT;
304                 break;
305         case BOOT_TYPE_MMC:
306                 boot_dev = boot_instance + MMC1_BOOT;
307                 break;
308         case BOOT_TYPE_NAND:
309                 boot_dev = NAND_BOOT;
310                 break;
311         case BOOT_TYPE_QSPI:
312                 boot_dev = QSPI_BOOT;
313                 break;
314         case BOOT_TYPE_WEIM:
315                 boot_dev = WEIM_NOR_BOOT;
316                 break;
317         case BOOT_TYPE_SPINOR:
318                 boot_dev = SPI_NOR_BOOT;
319                 break;
320         default:
321                 break;
322         }
323
324         return boot_dev;
325 }
326
327 #ifdef CONFIG_ENV_IS_IN_MMC
328 __weak int board_mmc_get_env_dev(int devno)
329 {
330         return CONFIG_SYS_MMC_ENV_DEV;
331 }
332
333 int mmc_get_env_dev(void)
334 {
335         struct bootrom_sw_info **p =
336                 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
337         int devno = (*p)->boot_dev_instance;
338         u8 boot_type = (*p)->boot_dev_type;
339
340         /* If not boot from sd/mmc, use default value */
341         if ((boot_type != BOOT_TYPE_SD) && (boot_type != BOOT_TYPE_MMC))
342                 return CONFIG_SYS_MMC_ENV_DEV;
343
344         return board_mmc_get_env_dev(devno);
345 }
346 #endif
347
348 void s_init(void)
349 {
350 #if !defined CONFIG_SPL_BUILD
351         /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
352         asm volatile(
353                         "mrc p15, 0, r0, c1, c0, 1\n"
354                         "orr r0, r0, #1 << 6\n"
355                         "mcr p15, 0, r0, c1, c0, 1\n");
356 #endif
357         /* clock configuration. */
358         clock_init();
359
360         return;
361 }