blob: 16025855646f7c09c42c2ad18ed64a1db96c22c8 [file] [log] [blame]
Adrian Alonsoc5752f72015-09-02 13:54:19 -05001/*
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>
Stefano Babic552a8482017-06-29 10:16:06 +020012#include <asm/mach-imx/boot_mode.h>
13#include <asm/mach-imx/dma.h>
14#include <asm/mach-imx/hab.h>
15#include <asm/mach-imx/rdc-sema.h>
Peng Fan35c4ce52016-01-28 16:55:09 +080016#include <asm/arch/imx-rdc.h>
Adrian Alonsoc5752f72015-09-02 13:54:19 -050017#include <asm/arch/crm_regs.h>
18#include <dm.h>
19#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
Adrian Alonsoc5752f72015-09-02 13:54:19 -050023#if defined(CONFIG_IMX_THERMAL)
24static const struct imx_thermal_plat imx7_thermal_plat = {
25 .regs = (void *)ANATOP_BASE_ADDR,
26 .fuse_bank = 3,
27 .fuse_word = 3,
28};
29
30U_BOOT_DEVICE(imx7_thermal) = {
31 .name = "imx_thermal",
32 .platdata = &imx7_thermal_plat,
33};
34#endif
35
Peng Fane872f272017-08-12 22:10:57 +080036#if CONFIG_IS_ENABLED(IMX_RDC)
Peng Fan35c4ce52016-01-28 16:55:09 +080037/*
38 * In current design, if any peripheral was assigned to both A7 and M4,
39 * it will receive ipg_stop or ipg_wait when any of the 2 platforms enter
40 * low power mode. So M4 sleep will cause some peripherals fail to work
41 * at A7 core side. At default, all resources are in domain 0 - 3.
42 *
43 * There are 26 peripherals impacted by this IC issue:
44 * SIM2(sim2/emvsim2)
45 * SIM1(sim1/emvsim1)
46 * UART1/UART2/UART3/UART4/UART5/UART6/UART7
47 * SAI1/SAI2/SAI3
48 * WDOG1/WDOG2/WDOG3/WDOG4
49 * GPT1/GPT2/GPT3/GPT4
50 * PWM1/PWM2/PWM3/PWM4
51 * ENET1/ENET2
52 * Software Workaround:
53 * Here we setup some resources to domain 0 where M4 codes will move
54 * the M4 out of this domain. Then M4 is not able to access them any longer.
55 * This is a workaround for ic issue. So the peripherals are not shared
56 * by them. This way requires the uboot implemented the RDC driver and
57 * set the 26 IPs above to domain 0 only. M4 code will assign resource
58 * to its own domain, if it want to use the resource.
59 */
60static rdc_peri_cfg_t const resources[] = {
61 (RDC_PER_SIM1 | RDC_DOMAIN(0)),
62 (RDC_PER_SIM2 | RDC_DOMAIN(0)),
63 (RDC_PER_UART1 | RDC_DOMAIN(0)),
64 (RDC_PER_UART2 | RDC_DOMAIN(0)),
65 (RDC_PER_UART3 | RDC_DOMAIN(0)),
66 (RDC_PER_UART4 | RDC_DOMAIN(0)),
67 (RDC_PER_UART5 | RDC_DOMAIN(0)),
68 (RDC_PER_UART6 | RDC_DOMAIN(0)),
69 (RDC_PER_UART7 | RDC_DOMAIN(0)),
70 (RDC_PER_SAI1 | RDC_DOMAIN(0)),
71 (RDC_PER_SAI2 | RDC_DOMAIN(0)),
72 (RDC_PER_SAI3 | RDC_DOMAIN(0)),
73 (RDC_PER_WDOG1 | RDC_DOMAIN(0)),
74 (RDC_PER_WDOG2 | RDC_DOMAIN(0)),
75 (RDC_PER_WDOG3 | RDC_DOMAIN(0)),
76 (RDC_PER_WDOG4 | RDC_DOMAIN(0)),
77 (RDC_PER_GPT1 | RDC_DOMAIN(0)),
78 (RDC_PER_GPT2 | RDC_DOMAIN(0)),
79 (RDC_PER_GPT3 | RDC_DOMAIN(0)),
80 (RDC_PER_GPT4 | RDC_DOMAIN(0)),
81 (RDC_PER_PWM1 | RDC_DOMAIN(0)),
82 (RDC_PER_PWM2 | RDC_DOMAIN(0)),
83 (RDC_PER_PWM3 | RDC_DOMAIN(0)),
84 (RDC_PER_PWM4 | RDC_DOMAIN(0)),
85 (RDC_PER_ENET1 | RDC_DOMAIN(0)),
86 (RDC_PER_ENET2 | RDC_DOMAIN(0)),
87};
88
89static void isolate_resource(void)
90{
91 imx_rdc_setup_peripherals(resources, ARRAY_SIZE(resources));
92}
93#endif
94
Adrian Alonsobb955142015-10-12 13:48:13 -050095#if defined(CONFIG_SECURE_BOOT)
96struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
97 .bank = 1,
98 .word = 3,
99};
100#endif
101
Fabio Estevame25a0652016-02-28 12:33:17 -0300102static bool is_mx7d(void)
103{
104 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
105 struct fuse_bank *bank = &ocotp->bank[1];
106 struct fuse_bank1_regs *fuse =
107 (struct fuse_bank1_regs *)bank->fuse_regs;
108 int val;
109
110 val = readl(&fuse->tester4);
111 if (val & 1)
112 return false;
113 else
114 return true;
115}
116
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500117u32 get_cpu_rev(void)
118{
119 struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
120 ANATOP_BASE_ADDR;
121 u32 reg = readl(&ccm_anatop->digprog);
122 u32 type = (reg >> 16) & 0xff;
123
Fabio Estevame25a0652016-02-28 12:33:17 -0300124 if (!is_mx7d())
125 type = MXC_CPU_MX7S;
126
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500127 reg &= 0xff;
128 return (type << 12) | reg;
129}
130
131#ifdef CONFIG_REVISION_TAG
132u32 __weak get_board_rev(void)
133{
134 return get_cpu_rev();
135}
136#endif
137
Peng Fan7de47032015-10-23 10:13:04 +0800138/* enable all periherial can be accessed in nosec mode */
139static void init_csu(void)
140{
141 int i = 0;
142 for (i = 0; i < CSU_NUM_REGS; i++)
143 writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
144}
145
Peng Fand9699de2016-01-04 13:16:41 +0800146static void imx_enet_mdio_fixup(void)
147{
148 struct iomuxc_gpr_base_regs *gpr_regs =
149 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
150
151 /*
152 * The management data input/output (MDIO) requires open-drain,
153 * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports
154 * this feature. So to TO1.1, need to enable open drain by setting
155 * bits GPR0[8:7].
156 */
157
158 if (soc_rev() >= CHIP_REV_1_1) {
159 setbits_le32(&gpr_regs->gpr[0],
160 IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
161 }
162}
163
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500164int arch_cpu_init(void)
165{
166 init_aips();
167
Peng Fan7de47032015-10-23 10:13:04 +0800168 init_csu();
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500169 /* Disable PDE bit of WMCR register */
Fabio Estevame2162d72017-11-23 10:55:33 -0200170 imx_wdog_disable_powerdown();
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500171
Peng Fand9699de2016-01-04 13:16:41 +0800172 imx_enet_mdio_fixup();
173
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500174#ifdef CONFIG_APBH_DMA
175 /* Start APBH DMA */
176 mxs_dma_init();
177#endif
178
Peng Fane872f272017-08-12 22:10:57 +0800179#if CONFIG_IS_ENABLED(IMX_RDC)
180 isolate_resource();
181#endif
Peng Fan35c4ce52016-01-28 16:55:09 +0800182
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500183 return 0;
184}
185
Stefan Agnerec7fde32016-07-13 00:25:39 -0700186#ifdef CONFIG_ARCH_MISC_INIT
187int arch_misc_init(void)
188{
189#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
190 if (is_mx7d())
Simon Glass382bee52017-08-03 12:22:09 -0600191 env_set("soc", "imx7d");
Stefan Agnerec7fde32016-07-13 00:25:39 -0700192 else
Simon Glass382bee52017-08-03 12:22:09 -0600193 env_set("soc", "imx7s");
Stefan Agnerec7fde32016-07-13 00:25:39 -0700194#endif
195
Bryan O'Donoghued1ceb0c2018-01-26 16:27:58 +0000196#ifdef CONFIG_FSL_CAAM
197 sec_init();
198#endif
199
Stefan Agnerec7fde32016-07-13 00:25:39 -0700200 return 0;
201}
202#endif
203
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500204#ifdef CONFIG_SERIAL_TAG
205void get_board_serial(struct tag_serialnr *serialnr)
206{
207 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
208 struct fuse_bank *bank = &ocotp->bank[0];
209 struct fuse_bank0_regs *fuse =
210 (struct fuse_bank0_regs *)bank->fuse_regs;
211
212 serialnr->low = fuse->tester0;
213 serialnr->high = fuse->tester1;
214}
215#endif
216
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500217void set_wdog_reset(struct wdog_regs *wdog)
218{
219 u32 reg = readw(&wdog->wcr);
220 /*
221 * Output WDOG_B signal to reset external pmic or POR_B decided by
222 * the board desgin. Without external reset, the peripherals/DDR/
223 * PMIC are not reset, that may cause system working abnormal.
224 */
225 reg = readw(&wdog->wcr);
226 reg |= 1 << 3;
227 /*
228 * WDZST bit is write-once only bit. Align this bit in kernel,
229 * otherwise kernel code will have no chance to set this bit.
230 */
231 reg |= 1 << 0;
232 writew(reg, &wdog->wcr);
233}
234
235/*
236 * cfg_val will be used for
237 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
238 * After reset, if GPR10[28] is 1, ROM will copy GPR9[25:0]
239 * to SBMR1, which will determine the boot device.
240 */
241const struct boot_mode soc_boot_modes[] = {
242 {"ecspi1:0", MAKE_CFGVAL(0x00, 0x60, 0x00, 0x00)},
243 {"ecspi1:1", MAKE_CFGVAL(0x40, 0x62, 0x00, 0x00)},
244 {"ecspi1:2", MAKE_CFGVAL(0x80, 0x64, 0x00, 0x00)},
245 {"ecspi1:3", MAKE_CFGVAL(0xc0, 0x66, 0x00, 0x00)},
246
247 {"weim", MAKE_CFGVAL(0x00, 0x50, 0x00, 0x00)},
248 {"qspi1", MAKE_CFGVAL(0x10, 0x40, 0x00, 0x00)},
249 /* 4 bit bus width */
250 {"usdhc1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
251 {"usdhc2", MAKE_CFGVAL(0x10, 0x14, 0x00, 0x00)},
252 {"usdhc3", MAKE_CFGVAL(0x10, 0x18, 0x00, 0x00)},
253 {"mmc1", MAKE_CFGVAL(0x10, 0x20, 0x00, 0x00)},
254 {"mmc2", MAKE_CFGVAL(0x10, 0x24, 0x00, 0x00)},
255 {"mmc3", MAKE_CFGVAL(0x10, 0x28, 0x00, 0x00)},
256 {NULL, 0},
257};
258
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500259void s_init(void)
260{
261#if !defined CONFIG_SPL_BUILD
262 /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
263 asm volatile(
264 "mrc p15, 0, r0, c1, c0, 1\n"
265 "orr r0, r0, #1 << 6\n"
266 "mcr p15, 0, r0, c1, c0, 1\n");
267#endif
268 /* clock configuration. */
269 clock_init();
270
271 return;
272}
Peng Fan9f8fa182016-05-19 13:02:16 +0800273
274void reset_misc(void)
275{
276#ifdef CONFIG_VIDEO_MXS
277 lcdif_power_down();
278#endif
279}
280