2 * Copyright (C) 2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
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>
17 #include <imx_thermal.h>
19 #if defined(CONFIG_IMX_THERMAL)
20 static const struct imx_thermal_plat imx7_thermal_plat = {
21 .regs = (void *)ANATOP_BASE_ADDR,
26 U_BOOT_DEVICE(imx7_thermal) = {
27 .name = "imx_thermal",
28 .platdata = &imx7_thermal_plat,
32 #if defined(CONFIG_SECURE_BOOT)
33 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
40 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
41 * defines a 2-bit SPEED_GRADING
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
48 u32 get_cpu_speed_grade_hz(void)
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;
56 val = readl(&fuse->tester3);
57 val >>= OCOTP_TESTER3_SPEED_SHIFT;
61 case OCOTP_TESTER3_SPEED_800MHZ:
63 case OCOTP_TESTER3_SPEED_850MHZ:
65 case OCOTP_TESTER3_SPEED_1GHZ:
72 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
73 * defines a 2-bit SPEED_GRADING
75 #define OCOTP_TESTER3_TEMP_SHIFT 6
77 u32 get_cpu_temp_grade(int *minc, int *maxc)
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;
85 val = readl(&fuse->tester3);
86 val >>= OCOTP_TESTER3_TEMP_SHIFT;
90 if (val == TEMP_AUTOMOTIVE) {
93 } else if (val == TEMP_INDUSTRIAL) {
96 } else if (val == TEMP_EXTCOMMERCIAL) {
107 u32 get_cpu_rev(void)
109 struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
111 u32 reg = readl(&ccm_anatop->digprog);
112 u32 type = (reg >> 16) & 0xff;
115 return (type << 12) | reg;
118 #ifdef CONFIG_REVISION_TAG
119 u32 __weak get_board_rev(void)
121 return get_cpu_rev();
125 /* enable all periherial can be accessed in nosec mode */
126 static void init_csu(void)
129 for (i = 0; i < CSU_NUM_REGS; i++)
130 writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
133 static void imx_enet_mdio_fixup(void)
135 struct iomuxc_gpr_base_regs *gpr_regs =
136 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
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
145 if (soc_rev() >= CHIP_REV_1_1) {
146 setbits_le32(&gpr_regs->gpr[0],
147 IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
151 int arch_cpu_init(void)
156 /* Disable PDE bit of WMCR register */
157 imx_set_wdog_powerdown(false);
159 imx_enet_mdio_fixup();
161 #ifdef CONFIG_APBH_DMA
169 #ifdef CONFIG_SERIAL_TAG
170 void get_board_serial(struct tag_serialnr *serialnr)
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;
177 serialnr->low = fuse->tester0;
178 serialnr->high = fuse->tester1;
182 #if defined(CONFIG_FEC_MXC)
183 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
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;
191 u32 value = readl(&fuse->mac_addr1);
192 mac[0] = (value >> 8);
195 value = readl(&fuse->mac_addr0);
196 mac[2] = value >> 24;
197 mac[3] = value >> 16;
201 u32 value = readl(&fuse->mac_addr2);
202 mac[0] = value >> 24;
203 mac[1] = value >> 16;
207 value = readl(&fuse->mac_addr1);
208 mac[4] = value >> 24;
209 mac[5] = value >> 16;
214 void set_wdog_reset(struct wdog_regs *wdog)
216 u32 reg = readw(&wdog->wcr);
218 * Output WDOG_B signal to reset external pmic or POR_B decided by
219 * the board desgin. Without external reset, the peripherals/DDR/
220 * PMIC are not reset, that may cause system working abnormal.
222 reg = readw(&wdog->wcr);
225 * WDZST bit is write-once only bit. Align this bit in kernel,
226 * otherwise kernel code will have no chance to set this bit.
229 writew(reg, &wdog->wcr);
233 * cfg_val will be used for
234 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
235 * After reset, if GPR10[28] is 1, ROM will copy GPR9[25:0]
236 * to SBMR1, which will determine the boot device.
238 const struct boot_mode soc_boot_modes[] = {
239 {"ecspi1:0", MAKE_CFGVAL(0x00, 0x60, 0x00, 0x00)},
240 {"ecspi1:1", MAKE_CFGVAL(0x40, 0x62, 0x00, 0x00)},
241 {"ecspi1:2", MAKE_CFGVAL(0x80, 0x64, 0x00, 0x00)},
242 {"ecspi1:3", MAKE_CFGVAL(0xc0, 0x66, 0x00, 0x00)},
244 {"weim", MAKE_CFGVAL(0x00, 0x50, 0x00, 0x00)},
245 {"qspi1", MAKE_CFGVAL(0x10, 0x40, 0x00, 0x00)},
246 /* 4 bit bus width */
247 {"usdhc1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
248 {"usdhc2", MAKE_CFGVAL(0x10, 0x14, 0x00, 0x00)},
249 {"usdhc3", MAKE_CFGVAL(0x10, 0x18, 0x00, 0x00)},
250 {"mmc1", MAKE_CFGVAL(0x10, 0x20, 0x00, 0x00)},
251 {"mmc2", MAKE_CFGVAL(0x10, 0x24, 0x00, 0x00)},
252 {"mmc3", MAKE_CFGVAL(0x10, 0x28, 0x00, 0x00)},
256 enum boot_device get_boot_device(void)
258 struct bootrom_sw_info **p =
259 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
261 enum boot_device boot_dev = SD1_BOOT;
262 u8 boot_type = (*p)->boot_dev_type;
263 u8 boot_instance = (*p)->boot_dev_instance;
267 boot_dev = boot_instance + SD1_BOOT;
270 boot_dev = boot_instance + MMC1_BOOT;
273 boot_dev = NAND_BOOT;
276 boot_dev = QSPI_BOOT;
279 boot_dev = WEIM_NOR_BOOT;
281 case BOOT_TYPE_SPINOR:
282 boot_dev = SPI_NOR_BOOT;
291 #ifdef CONFIG_ENV_IS_IN_MMC
292 __weak int board_mmc_get_env_dev(int devno)
294 return CONFIG_SYS_MMC_ENV_DEV;
297 int mmc_get_env_dev(void)
299 struct bootrom_sw_info **p =
300 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
301 int devno = (*p)->boot_dev_instance;
302 u8 boot_type = (*p)->boot_dev_type;
304 /* If not boot from sd/mmc, use default value */
305 if ((boot_type != BOOT_TYPE_SD) && (boot_type != BOOT_TYPE_MMC))
306 return CONFIG_SYS_MMC_ENV_DEV;
308 return board_mmc_get_env_dev(devno);
314 #if !defined CONFIG_SPL_BUILD
315 /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
317 "mrc p15, 0, r0, c1, c0, 1\n"
318 "orr r0, r0, #1 << 6\n"
319 "mcr p15, 0, r0, c1, c0, 1\n");
321 /* clock configuration. */