blob: 60e688c5184234d3c33b365f08c383226d1590ff [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Adrian Alonsoc5752f72015-09-02 13:54:19 -05002/*
3 * Copyright (C) 2015 Freescale Semiconductor, Inc.
Adrian Alonsoc5752f72015-09-02 13:54:19 -05004 */
5
6#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -06007#include <init.h>
Adrian Alonsoc5752f72015-09-02 13:54:19 -05008#include <asm/io.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/clock.h>
11#include <asm/arch/sys_proto.h>
Stefano Babic552a8482017-06-29 10:16:06 +020012#include <asm/mach-imx/dma.h>
13#include <asm/mach-imx/hab.h>
14#include <asm/mach-imx/rdc-sema.h>
Peng Fan35c4ce52016-01-28 16:55:09 +080015#include <asm/arch/imx-rdc.h>
Adrian Alonsoc5752f72015-09-02 13:54:19 -050016#include <asm/arch/crm_regs.h>
17#include <dm.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060018#include <env.h>
Adrian Alonsoc5752f72015-09-02 13:54:19 -050019#include <imx_thermal.h>
Bryan O'Donoghued1ceb0c2018-01-26 16:27:58 +000020#include <fsl_sec.h>
Bryan O'Donoghueca831822018-03-26 15:27:32 +010021#include <asm/setup.h>
Adrian Alonsoc5752f72015-09-02 13:54:19 -050022
Anson Huangb0598372018-08-08 09:17:49 +080023#define IOMUXC_GPR1 0x4
24#define BM_IOMUXC_GPR1_IRQ 0x1000
25
26#define GPC_LPCR_A7_BSC 0x0
27#define GPC_LPCR_M4 0x8
28#define GPC_SLPCR 0x14
29#define GPC_PGC_ACK_SEL_A7 0x24
30#define GPC_IMR1_CORE0 0x30
31#define GPC_IMR1_CORE1 0x40
32#define GPC_IMR1_M4 0x50
33#define GPC_PGC_CPU_MAPPING 0xec
34#define GPC_PGC_C0_PUPSCR 0x804
35#define GPC_PGC_SCU_TIMING 0x890
36#define GPC_PGC_C1_PUPSCR 0x844
37
38#define BM_LPCR_A7_BSC_IRQ_SRC_A7_WAKEUP 0x70000000
39#define BM_LPCR_A7_BSC_CPU_CLK_ON_LPM 0x4000
40#define BM_LPCR_M4_MASK_DSM_TRIGGER 0x80000000
41#define BM_SLPCR_EN_DSM 0x80000000
42#define BM_SLPCR_RBC_EN 0x40000000
43#define BM_SLPCR_REG_BYPASS_COUNT 0x3f000000
44#define BM_SLPCR_VSTBY 0x4
45#define BM_SLPCR_SBYOS 0x2
46#define BM_SLPCR_BYPASS_PMIC_READY 0x1
47#define BM_SLPCR_EN_A7_FASTWUP_WAIT_MODE 0x10000
48
49#define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PUP_ACK 0x80000000
50#define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK 0x8000
51
52#define BM_GPC_PGC_CORE_PUPSCR 0x7fff80
53
Adrian Alonsoc5752f72015-09-02 13:54:19 -050054#if defined(CONFIG_IMX_THERMAL)
55static const struct imx_thermal_plat imx7_thermal_plat = {
56 .regs = (void *)ANATOP_BASE_ADDR,
57 .fuse_bank = 3,
58 .fuse_word = 3,
59};
60
61U_BOOT_DEVICE(imx7_thermal) = {
62 .name = "imx_thermal",
63 .platdata = &imx7_thermal_plat,
64};
65#endif
66
Peng Fane872f272017-08-12 22:10:57 +080067#if CONFIG_IS_ENABLED(IMX_RDC)
Peng Fan35c4ce52016-01-28 16:55:09 +080068/*
69 * In current design, if any peripheral was assigned to both A7 and M4,
70 * it will receive ipg_stop or ipg_wait when any of the 2 platforms enter
71 * low power mode. So M4 sleep will cause some peripherals fail to work
72 * at A7 core side. At default, all resources are in domain 0 - 3.
73 *
74 * There are 26 peripherals impacted by this IC issue:
75 * SIM2(sim2/emvsim2)
76 * SIM1(sim1/emvsim1)
77 * UART1/UART2/UART3/UART4/UART5/UART6/UART7
78 * SAI1/SAI2/SAI3
79 * WDOG1/WDOG2/WDOG3/WDOG4
80 * GPT1/GPT2/GPT3/GPT4
81 * PWM1/PWM2/PWM3/PWM4
82 * ENET1/ENET2
83 * Software Workaround:
84 * Here we setup some resources to domain 0 where M4 codes will move
85 * the M4 out of this domain. Then M4 is not able to access them any longer.
86 * This is a workaround for ic issue. So the peripherals are not shared
87 * by them. This way requires the uboot implemented the RDC driver and
88 * set the 26 IPs above to domain 0 only. M4 code will assign resource
89 * to its own domain, if it want to use the resource.
90 */
91static rdc_peri_cfg_t const resources[] = {
92 (RDC_PER_SIM1 | RDC_DOMAIN(0)),
93 (RDC_PER_SIM2 | RDC_DOMAIN(0)),
94 (RDC_PER_UART1 | RDC_DOMAIN(0)),
95 (RDC_PER_UART2 | RDC_DOMAIN(0)),
96 (RDC_PER_UART3 | RDC_DOMAIN(0)),
97 (RDC_PER_UART4 | RDC_DOMAIN(0)),
98 (RDC_PER_UART5 | RDC_DOMAIN(0)),
99 (RDC_PER_UART6 | RDC_DOMAIN(0)),
100 (RDC_PER_UART7 | RDC_DOMAIN(0)),
101 (RDC_PER_SAI1 | RDC_DOMAIN(0)),
102 (RDC_PER_SAI2 | RDC_DOMAIN(0)),
103 (RDC_PER_SAI3 | RDC_DOMAIN(0)),
104 (RDC_PER_WDOG1 | RDC_DOMAIN(0)),
105 (RDC_PER_WDOG2 | RDC_DOMAIN(0)),
106 (RDC_PER_WDOG3 | RDC_DOMAIN(0)),
107 (RDC_PER_WDOG4 | RDC_DOMAIN(0)),
108 (RDC_PER_GPT1 | RDC_DOMAIN(0)),
109 (RDC_PER_GPT2 | RDC_DOMAIN(0)),
110 (RDC_PER_GPT3 | RDC_DOMAIN(0)),
111 (RDC_PER_GPT4 | RDC_DOMAIN(0)),
112 (RDC_PER_PWM1 | RDC_DOMAIN(0)),
113 (RDC_PER_PWM2 | RDC_DOMAIN(0)),
114 (RDC_PER_PWM3 | RDC_DOMAIN(0)),
115 (RDC_PER_PWM4 | RDC_DOMAIN(0)),
116 (RDC_PER_ENET1 | RDC_DOMAIN(0)),
117 (RDC_PER_ENET2 | RDC_DOMAIN(0)),
118};
119
120static void isolate_resource(void)
121{
122 imx_rdc_setup_peripherals(resources, ARRAY_SIZE(resources));
123}
124#endif
125
Stefano Babicd714a752019-09-20 08:47:53 +0200126#if defined(CONFIG_IMX_HAB)
Adrian Alonsobb955142015-10-12 13:48:13 -0500127struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
128 .bank = 1,
129 .word = 3,
130};
131#endif
132
Fabio Estevame25a0652016-02-28 12:33:17 -0300133static bool is_mx7d(void)
134{
135 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
136 struct fuse_bank *bank = &ocotp->bank[1];
137 struct fuse_bank1_regs *fuse =
138 (struct fuse_bank1_regs *)bank->fuse_regs;
139 int val;
140
141 val = readl(&fuse->tester4);
142 if (val & 1)
143 return false;
144 else
145 return true;
146}
147
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500148u32 get_cpu_rev(void)
149{
150 struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
151 ANATOP_BASE_ADDR;
152 u32 reg = readl(&ccm_anatop->digprog);
153 u32 type = (reg >> 16) & 0xff;
154
Fabio Estevame25a0652016-02-28 12:33:17 -0300155 if (!is_mx7d())
156 type = MXC_CPU_MX7S;
157
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500158 reg &= 0xff;
159 return (type << 12) | reg;
160}
161
162#ifdef CONFIG_REVISION_TAG
163u32 __weak get_board_rev(void)
164{
165 return get_cpu_rev();
166}
167#endif
168
Peng Fand9699de2016-01-04 13:16:41 +0800169static void imx_enet_mdio_fixup(void)
170{
171 struct iomuxc_gpr_base_regs *gpr_regs =
172 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
173
174 /*
175 * The management data input/output (MDIO) requires open-drain,
176 * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports
177 * this feature. So to TO1.1, need to enable open drain by setting
178 * bits GPR0[8:7].
179 */
180
181 if (soc_rev() >= CHIP_REV_1_1) {
182 setbits_le32(&gpr_regs->gpr[0],
183 IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
184 }
185}
186
Jun Niebc7c9ed2019-05-08 14:38:30 +0800187static void init_cpu_basic(void)
188{
189 imx_enet_mdio_fixup();
190
191#ifdef CONFIG_APBH_DMA
192 /* Start APBH DMA */
193 mxs_dma_init();
194#endif
195}
196
Igor Opaniukc0f037f2019-12-30 13:56:44 +0200197#ifdef CONFIG_IMX_BOOTAUX
198/*
199 * Table of mappings of physical mem regions in both
200 * Cortex-A7 and Cortex-M4 address spaces.
201 *
202 * For additional details check sections 2.1.2 and 2.1.3 in
203 * i.MX7Dual Applications Processor Reference Manual
204 *
205 */
206const struct rproc_att hostmap[] = {
207 /* aux core , host core, size */
208 { 0x00000000, 0x00180000, 0x8000 }, /* OCRAM_S */
209 { 0x00180000, 0x00180000, 0x8000 }, /* OCRAM_S */
210 { 0x20180000, 0x00180000, 0x8000 }, /* OCRAM_S */
211 { 0x1fff8000, 0x007f8000, 0x8000 }, /* TCML */
212 { 0x20000000, 0x00800000, 0x8000 }, /* TCMU */
213 { 0x00900000, 0x00900000, 0x20000 }, /* OCRAM_128KB */
214 { 0x20200000, 0x00900000, 0x20000 }, /* OCRAM_128KB */
215 { 0x00920000, 0x00920000, 0x20000 }, /* OCRAM_EPDC */
216 { 0x20220000, 0x00920000, 0x20000 }, /* OCRAM_EPDC */
217 { 0x00940000, 0x00940000, 0x20000 }, /* OCRAM_PXP */
218 { 0x20240000, 0x00940000, 0x20000 }, /* OCRAM_PXP */
219 { 0x10000000, 0x80000000, 0x0fff0000 }, /* DDR Code alias */
220 { 0x80000000, 0x80000000, 0xe0000000 }, /* DDRC */
221 { /* sentinel */ }
222};
223#endif
224
Jun Niebc7c9ed2019-05-08 14:38:30 +0800225#ifndef CONFIG_SKIP_LOWLEVEL_INIT
226/* enable all periherial can be accessed in nosec mode */
227static void init_csu(void)
228{
229 int i = 0;
230
231 for (i = 0; i < CSU_NUM_REGS; i++)
232 writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
233}
234
Anson Huangb0598372018-08-08 09:17:49 +0800235static void imx_gpcv2_init(void)
236{
237 u32 val, i;
238
239 /*
240 * Force IOMUXC irq pending, so that the interrupt to GPC can be
241 * used to deassert dsm_request signal when the signal gets
242 * asserted unexpectedly.
243 */
244 val = readl(IOMUXC_GPR_BASE_ADDR + IOMUXC_GPR1);
245 val |= BM_IOMUXC_GPR1_IRQ;
246 writel(val, IOMUXC_GPR_BASE_ADDR + IOMUXC_GPR1);
247
248 /* Initially mask all interrupts */
249 for (i = 0; i < 4; i++) {
250 writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_CORE0 + i * 4);
251 writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_CORE1 + i * 4);
252 writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_M4 + i * 4);
253 }
254
255 /* set SCU timing */
256 writel((0x59 << 10) | 0x5B | (0x2 << 20),
257 GPC_IPS_BASE_ADDR + GPC_PGC_SCU_TIMING);
258
259 /* only external IRQs to wake up LPM and core 0/1 */
260 val = readl(GPC_IPS_BASE_ADDR + GPC_LPCR_A7_BSC);
261 val |= BM_LPCR_A7_BSC_IRQ_SRC_A7_WAKEUP;
262 writel(val, GPC_IPS_BASE_ADDR + GPC_LPCR_A7_BSC);
263
264 /* set C0 power up timming per design requirement */
265 val = readl(GPC_IPS_BASE_ADDR + GPC_PGC_C0_PUPSCR);
266 val &= ~BM_GPC_PGC_CORE_PUPSCR;
267 val |= (0x1A << 7);
268 writel(val, GPC_IPS_BASE_ADDR + GPC_PGC_C0_PUPSCR);
269
270 /* set C1 power up timming per design requirement */
271 val = readl(GPC_IPS_BASE_ADDR + GPC_PGC_C1_PUPSCR);
272 val &= ~BM_GPC_PGC_CORE_PUPSCR;
273 val |= (0x1A << 7);
274 writel(val, GPC_IPS_BASE_ADDR + GPC_PGC_C1_PUPSCR);
275
276 /* dummy ack for time slot by default */
277 writel(BM_GPC_PGC_ACK_SEL_A7_DUMMY_PUP_ACK |
278 BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK,
279 GPC_IPS_BASE_ADDR + GPC_PGC_ACK_SEL_A7);
280
281 /* mask M4 DSM trigger */
282 writel(readl(GPC_IPS_BASE_ADDR + GPC_LPCR_M4) |
283 BM_LPCR_M4_MASK_DSM_TRIGGER,
284 GPC_IPS_BASE_ADDR + GPC_LPCR_M4);
285
286 /* set mega/fast mix in A7 domain */
287 writel(0x1, GPC_IPS_BASE_ADDR + GPC_PGC_CPU_MAPPING);
288
289 /* DSM related settings */
290 val = readl(GPC_IPS_BASE_ADDR + GPC_SLPCR);
291 val &= ~(BM_SLPCR_EN_DSM | BM_SLPCR_VSTBY | BM_SLPCR_RBC_EN |
292 BM_SLPCR_SBYOS | BM_SLPCR_BYPASS_PMIC_READY |
293 BM_SLPCR_REG_BYPASS_COUNT);
294 val |= BM_SLPCR_EN_A7_FASTWUP_WAIT_MODE;
295 writel(val, GPC_IPS_BASE_ADDR + GPC_SLPCR);
296
297 /*
298 * disabling RBC need to delay at least 2 cycles of CKIL(32K)
299 * due to hardware design requirement, which is
300 * ~61us, here we use 65us for safe
301 */
302 udelay(65);
303}
304
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500305int arch_cpu_init(void)
306{
307 init_aips();
308
Peng Fan7de47032015-10-23 10:13:04 +0800309 init_csu();
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500310 /* Disable PDE bit of WMCR register */
Fabio Estevame2162d72017-11-23 10:55:33 -0200311 imx_wdog_disable_powerdown();
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500312
Jun Niebc7c9ed2019-05-08 14:38:30 +0800313 init_cpu_basic();
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500314
Peng Fane872f272017-08-12 22:10:57 +0800315#if CONFIG_IS_ENABLED(IMX_RDC)
316 isolate_resource();
317#endif
Peng Fan35c4ce52016-01-28 16:55:09 +0800318
Bryan O'Donoghue723f8352018-04-05 19:46:06 +0100319 init_snvs();
320
Anson Huangb0598372018-08-08 09:17:49 +0800321 imx_gpcv2_init();
322
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500323 return 0;
324}
Jun Niebc7c9ed2019-05-08 14:38:30 +0800325#else
326int arch_cpu_init(void)
327{
328 init_cpu_basic();
329
330 return 0;
331}
Rui Miguel Silvabe277c32018-09-05 11:56:05 +0100332#endif
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500333
Stefan Agnerec7fde32016-07-13 00:25:39 -0700334#ifdef CONFIG_ARCH_MISC_INIT
335int arch_misc_init(void)
336{
337#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
338 if (is_mx7d())
Simon Glass382bee52017-08-03 12:22:09 -0600339 env_set("soc", "imx7d");
Stefan Agnerec7fde32016-07-13 00:25:39 -0700340 else
Simon Glass382bee52017-08-03 12:22:09 -0600341 env_set("soc", "imx7s");
Stefan Agnerec7fde32016-07-13 00:25:39 -0700342#endif
343
Bryan O'Donoghued1ceb0c2018-01-26 16:27:58 +0000344#ifdef CONFIG_FSL_CAAM
345 sec_init();
346#endif
347
Stefan Agnerec7fde32016-07-13 00:25:39 -0700348 return 0;
349}
350#endif
351
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500352#ifdef CONFIG_SERIAL_TAG
Bryan O'Donoghue1ab1ffd2018-03-26 15:27:33 +0100353/*
354 * OCOTP_TESTER
355 * i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1, 08/2016
356 * OCOTP_TESTER describes a unique ID based on silicon wafer
357 * and die X/Y position
358 *
359 * OCOTOP_TESTER offset 0x410
360 * 31:0 fuse 0
361 * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
362 *
363 * OCOTP_TESTER1 offset 0x420
364 * 31:24 fuse 1
365 * The X-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
366 * 23:16 fuse 1
367 * The Y-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
368 * 15:11 fuse 1
369 * The wafer number of the wafer on which the device was fabricated/SJC
370 * CHALLENGE/ Unique ID
371 * 10:0 fuse 1
372 * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
373 */
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500374void get_board_serial(struct tag_serialnr *serialnr)
375{
376 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
377 struct fuse_bank *bank = &ocotp->bank[0];
378 struct fuse_bank0_regs *fuse =
379 (struct fuse_bank0_regs *)bank->fuse_regs;
380
381 serialnr->low = fuse->tester0;
382 serialnr->high = fuse->tester1;
383}
384#endif
385
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500386void set_wdog_reset(struct wdog_regs *wdog)
387{
388 u32 reg = readw(&wdog->wcr);
389 /*
390 * Output WDOG_B signal to reset external pmic or POR_B decided by
391 * the board desgin. Without external reset, the peripherals/DDR/
392 * PMIC are not reset, that may cause system working abnormal.
393 */
394 reg = readw(&wdog->wcr);
395 reg |= 1 << 3;
396 /*
397 * WDZST bit is write-once only bit. Align this bit in kernel,
398 * otherwise kernel code will have no chance to set this bit.
399 */
400 reg |= 1 << 0;
401 writew(reg, &wdog->wcr);
402}
403
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500404void s_init(void)
405{
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500406 /* clock configuration. */
407 clock_init();
408
409 return;
410}
Peng Fan9f8fa182016-05-19 13:02:16 +0800411
412void reset_misc(void)
413{
Fabio Estevambab289c2018-12-11 16:40:37 -0200414#ifndef CONFIG_SPL_BUILD
Igor Opaniuk8c1df092019-06-04 00:05:59 +0300415#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Fan9f8fa182016-05-19 13:02:16 +0800416 lcdif_power_down();
417#endif
Fabio Estevambab289c2018-12-11 16:40:37 -0200418#endif
Peng Fan9f8fa182016-05-19 13:02:16 +0800419}
420