1
2
3
4
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/imx-common/rdc-sema.h>
16#include <asm/arch/imx-rdc.h>
17#include <asm/arch/crm_regs.h>
18#include <dm.h>
19#include <imx_thermal.h>
20
21#if defined(CONFIG_IMX_THERMAL)
22static const struct imx_thermal_plat imx7_thermal_plat = {
23 .regs = (void *)ANATOP_BASE_ADDR,
24 .fuse_bank = 3,
25 .fuse_word = 3,
26};
27
28U_BOOT_DEVICE(imx7_thermal) = {
29 .name = "imx_thermal",
30 .platdata = &imx7_thermal_plat,
31};
32#endif
33
34#ifdef CONFIG_IMX_RDC
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58static rdc_peri_cfg_t const resources[] = {
59 (RDC_PER_SIM1 | RDC_DOMAIN(0)),
60 (RDC_PER_SIM2 | RDC_DOMAIN(0)),
61 (RDC_PER_UART1 | RDC_DOMAIN(0)),
62 (RDC_PER_UART2 | RDC_DOMAIN(0)),
63 (RDC_PER_UART3 | RDC_DOMAIN(0)),
64 (RDC_PER_UART4 | RDC_DOMAIN(0)),
65 (RDC_PER_UART5 | RDC_DOMAIN(0)),
66 (RDC_PER_UART6 | RDC_DOMAIN(0)),
67 (RDC_PER_UART7 | RDC_DOMAIN(0)),
68 (RDC_PER_SAI1 | RDC_DOMAIN(0)),
69 (RDC_PER_SAI2 | RDC_DOMAIN(0)),
70 (RDC_PER_SAI3 | RDC_DOMAIN(0)),
71 (RDC_PER_WDOG1 | RDC_DOMAIN(0)),
72 (RDC_PER_WDOG2 | RDC_DOMAIN(0)),
73 (RDC_PER_WDOG3 | RDC_DOMAIN(0)),
74 (RDC_PER_WDOG4 | RDC_DOMAIN(0)),
75 (RDC_PER_GPT1 | RDC_DOMAIN(0)),
76 (RDC_PER_GPT2 | RDC_DOMAIN(0)),
77 (RDC_PER_GPT3 | RDC_DOMAIN(0)),
78 (RDC_PER_GPT4 | RDC_DOMAIN(0)),
79 (RDC_PER_PWM1 | RDC_DOMAIN(0)),
80 (RDC_PER_PWM2 | RDC_DOMAIN(0)),
81 (RDC_PER_PWM3 | RDC_DOMAIN(0)),
82 (RDC_PER_PWM4 | RDC_DOMAIN(0)),
83 (RDC_PER_ENET1 | RDC_DOMAIN(0)),
84 (RDC_PER_ENET2 | RDC_DOMAIN(0)),
85};
86
87static void isolate_resource(void)
88{
89 imx_rdc_setup_peripherals(resources, ARRAY_SIZE(resources));
90}
91#endif
92
93#if defined(CONFIG_SECURE_BOOT)
94struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
95 .bank = 1,
96 .word = 3,
97};
98#endif
99
100
101
102
103
104#define OCOTP_TESTER3_SPEED_SHIFT 8
105#define OCOTP_TESTER3_SPEED_800MHZ 0
106#define OCOTP_TESTER3_SPEED_850MHZ 1
107#define OCOTP_TESTER3_SPEED_1GHZ 2
108
109u32 get_cpu_speed_grade_hz(void)
110{
111 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
112 struct fuse_bank *bank = &ocotp->bank[1];
113 struct fuse_bank1_regs *fuse =
114 (struct fuse_bank1_regs *)bank->fuse_regs;
115 uint32_t val;
116
117 val = readl(&fuse->tester3);
118 val >>= OCOTP_TESTER3_SPEED_SHIFT;
119 val &= 0x3;
120
121 switch(val) {
122 case OCOTP_TESTER3_SPEED_800MHZ:
123 return 792000000;
124 case OCOTP_TESTER3_SPEED_850MHZ:
125 return 852000000;
126 case OCOTP_TESTER3_SPEED_1GHZ:
127 return 996000000;
128 }
129 return 0;
130}
131
132
133
134
135
136#define OCOTP_TESTER3_TEMP_SHIFT 6
137
138u32 get_cpu_temp_grade(int *minc, int *maxc)
139{
140 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
141 struct fuse_bank *bank = &ocotp->bank[1];
142 struct fuse_bank1_regs *fuse =
143 (struct fuse_bank1_regs *)bank->fuse_regs;
144 uint32_t val;
145
146 val = readl(&fuse->tester3);
147 val >>= OCOTP_TESTER3_TEMP_SHIFT;
148 val &= 0x3;
149
150 if (minc && maxc) {
151 if (val == TEMP_AUTOMOTIVE) {
152 *minc = -40;
153 *maxc = 125;
154 } else if (val == TEMP_INDUSTRIAL) {
155 *minc = -40;
156 *maxc = 105;
157 } else if (val == TEMP_EXTCOMMERCIAL) {
158 *minc = -20;
159 *maxc = 105;
160 } else {
161 *minc = 0;
162 *maxc = 95;
163 }
164 }
165 return val;
166}
167
168static bool is_mx7d(void)
169{
170 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
171 struct fuse_bank *bank = &ocotp->bank[1];
172 struct fuse_bank1_regs *fuse =
173 (struct fuse_bank1_regs *)bank->fuse_regs;
174 int val;
175
176 val = readl(&fuse->tester4);
177 if (val & 1)
178 return false;
179 else
180 return true;
181}
182
183u32 get_cpu_rev(void)
184{
185 struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
186 ANATOP_BASE_ADDR;
187 u32 reg = readl(&ccm_anatop->digprog);
188 u32 type = (reg >> 16) & 0xff;
189
190 if (!is_mx7d())
191 type = MXC_CPU_MX7S;
192
193 reg &= 0xff;
194 return (type << 12) | reg;
195}
196
197#ifdef CONFIG_REVISION_TAG
198u32 __weak get_board_rev(void)
199{
200 return get_cpu_rev();
201}
202#endif
203
204
205static void init_csu(void)
206{
207 int i = 0;
208 for (i = 0; i < CSU_NUM_REGS; i++)
209 writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
210}
211
212static void imx_enet_mdio_fixup(void)
213{
214 struct iomuxc_gpr_base_regs *gpr_regs =
215 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
216
217
218
219
220
221
222
223
224 if (soc_rev() >= CHIP_REV_1_1) {
225 setbits_le32(&gpr_regs->gpr[0],
226 IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
227 }
228}
229
230int arch_cpu_init(void)
231{
232 init_aips();
233
234 init_csu();
235
236 imx_set_wdog_powerdown(false);
237
238 imx_enet_mdio_fixup();
239
240#ifdef CONFIG_APBH_DMA
241
242 mxs_dma_init();
243#endif
244
245 if (IS_ENABLED(CONFIG_IMX_RDC))
246 isolate_resource();
247
248 return 0;
249}
250
251#ifdef CONFIG_SERIAL_TAG
252void get_board_serial(struct tag_serialnr *serialnr)
253{
254 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
255 struct fuse_bank *bank = &ocotp->bank[0];
256 struct fuse_bank0_regs *fuse =
257 (struct fuse_bank0_regs *)bank->fuse_regs;
258
259 serialnr->low = fuse->tester0;
260 serialnr->high = fuse->tester1;
261}
262#endif
263
264#if defined(CONFIG_FEC_MXC)
265void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
266{
267 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
268 struct fuse_bank *bank = &ocotp->bank[9];
269 struct fuse_bank9_regs *fuse =
270 (struct fuse_bank9_regs *)bank->fuse_regs;
271
272 if (0 == dev_id) {
273 u32 value = readl(&fuse->mac_addr1);
274 mac[0] = (value >> 8);
275 mac[1] = value;
276
277 value = readl(&fuse->mac_addr0);
278 mac[2] = value >> 24;
279 mac[3] = value >> 16;
280 mac[4] = value >> 8;
281 mac[5] = value;
282 } else {
283 u32 value = readl(&fuse->mac_addr2);
284 mac[0] = value >> 24;
285 mac[1] = value >> 16;
286 mac[2] = value >> 8;
287 mac[3] = value;
288
289 value = readl(&fuse->mac_addr1);
290 mac[4] = value >> 24;
291 mac[5] = value >> 16;
292 }
293}
294#endif
295
296#ifdef CONFIG_IMX_BOOTAUX
297int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data)
298{
299 u32 stack, pc;
300 struct src *src_reg = (struct src *)SRC_BASE_ADDR;
301
302 if (!boot_private_data)
303 return 1;
304
305 stack = *(u32 *)boot_private_data;
306 pc = *(u32 *)(boot_private_data + 4);
307
308
309 writel(stack, M4_BOOTROM_BASE_ADDR);
310 writel(pc, M4_BOOTROM_BASE_ADDR + 4);
311
312
313 clrsetbits_le32(&src_reg->m4rcr, SRC_M4RCR_M4C_NON_SCLR_RST_MASK,
314 SRC_M4RCR_ENABLE_M4_MASK);
315
316 return 0;
317}
318
319int arch_auxiliary_core_check_up(u32 core_id)
320{
321 uint32_t val;
322 struct src *src_reg = (struct src *)SRC_BASE_ADDR;
323
324 val = readl(&src_reg->m4rcr);
325 if (val & 0x00000001)
326 return 0;
327
328 return 1;
329}
330#endif
331
332void set_wdog_reset(struct wdog_regs *wdog)
333{
334 u32 reg = readw(&wdog->wcr);
335
336
337
338
339
340 reg = readw(&wdog->wcr);
341 reg |= 1 << 3;
342
343
344
345
346 reg |= 1 << 0;
347 writew(reg, &wdog->wcr);
348}
349
350
351
352
353
354
355
356const struct boot_mode soc_boot_modes[] = {
357 {"ecspi1:0", MAKE_CFGVAL(0x00, 0x60, 0x00, 0x00)},
358 {"ecspi1:1", MAKE_CFGVAL(0x40, 0x62, 0x00, 0x00)},
359 {"ecspi1:2", MAKE_CFGVAL(0x80, 0x64, 0x00, 0x00)},
360 {"ecspi1:3", MAKE_CFGVAL(0xc0, 0x66, 0x00, 0x00)},
361
362 {"weim", MAKE_CFGVAL(0x00, 0x50, 0x00, 0x00)},
363 {"qspi1", MAKE_CFGVAL(0x10, 0x40, 0x00, 0x00)},
364
365 {"usdhc1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
366 {"usdhc2", MAKE_CFGVAL(0x10, 0x14, 0x00, 0x00)},
367 {"usdhc3", MAKE_CFGVAL(0x10, 0x18, 0x00, 0x00)},
368 {"mmc1", MAKE_CFGVAL(0x10, 0x20, 0x00, 0x00)},
369 {"mmc2", MAKE_CFGVAL(0x10, 0x24, 0x00, 0x00)},
370 {"mmc3", MAKE_CFGVAL(0x10, 0x28, 0x00, 0x00)},
371 {NULL, 0},
372};
373
374enum boot_device get_boot_device(void)
375{
376 struct bootrom_sw_info **p =
377 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
378
379 enum boot_device boot_dev = SD1_BOOT;
380 u8 boot_type = (*p)->boot_dev_type;
381 u8 boot_instance = (*p)->boot_dev_instance;
382
383 switch (boot_type) {
384 case BOOT_TYPE_SD:
385 boot_dev = boot_instance + SD1_BOOT;
386 break;
387 case BOOT_TYPE_MMC:
388 boot_dev = boot_instance + MMC1_BOOT;
389 break;
390 case BOOT_TYPE_NAND:
391 boot_dev = NAND_BOOT;
392 break;
393 case BOOT_TYPE_QSPI:
394 boot_dev = QSPI_BOOT;
395 break;
396 case BOOT_TYPE_WEIM:
397 boot_dev = WEIM_NOR_BOOT;
398 break;
399 case BOOT_TYPE_SPINOR:
400 boot_dev = SPI_NOR_BOOT;
401 break;
402 default:
403 break;
404 }
405
406 return boot_dev;
407}
408
409#ifdef CONFIG_ENV_IS_IN_MMC
410__weak int board_mmc_get_env_dev(int devno)
411{
412 return CONFIG_SYS_MMC_ENV_DEV;
413}
414
415int mmc_get_env_dev(void)
416{
417 struct bootrom_sw_info **p =
418 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
419 int devno = (*p)->boot_dev_instance;
420 u8 boot_type = (*p)->boot_dev_type;
421
422
423 if ((boot_type != BOOT_TYPE_SD) && (boot_type != BOOT_TYPE_MMC))
424 return CONFIG_SYS_MMC_ENV_DEV;
425
426 return board_mmc_get_env_dev(devno);
427}
428#endif
429
430void s_init(void)
431{
432#if !defined CONFIG_SPL_BUILD
433
434 asm volatile(
435 "mrc p15, 0, r0, c1, c0, 1\n"
436 "orr r0, r0, #1 << 6\n"
437 "mcr p15, 0, r0, c1, c0, 1\n");
438#endif
439
440 clock_init();
441
442 return;
443}
444
445void reset_misc(void)
446{
447#ifdef CONFIG_VIDEO_MXS
448 lcdif_power_down();
449#endif
450}
451
452