Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Freescale Semiconductor, Inc. |
Gaurav Jain | e389ac9 | 2022-03-24 11:50:30 +0530 | [diff] [blame] | 4 | * Copyright 2021 NXP |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/imx-regs.h> |
| 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 13 | #include <asm/mach-imx/dma.h> |
| 14 | #include <asm/mach-imx/hab.h> |
| 15 | #include <asm/mach-imx/rdc-sema.h> |
Peng Fan | 4784249 | 2016-01-28 16:55:09 +0800 | [diff] [blame] | 16 | #include <asm/arch/imx-rdc.h> |
Marek Vasut | 28c0b63 | 2020-08-05 15:34:04 +0200 | [diff] [blame] | 17 | #include <asm/mach-imx/boot_mode.h> |
Sven Schwermer | 2645cfa | 2022-01-02 20:36:56 +0100 | [diff] [blame] | 18 | #include <asm/mach-imx/sys_proto.h> |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 19 | #include <asm/arch/crm_regs.h> |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 20 | #include <asm/bootm.h> |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 21 | #include <dm.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 22 | #include <env.h> |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 23 | #include <imx_thermal.h> |
Bryan O'Donoghue | 0cdded8 | 2018-03-26 15:27:32 +0100 | [diff] [blame] | 24 | #include <asm/setup.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 25 | #include <linux/delay.h> |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 26 | |
Anson Huang | 9d61854 | 2018-08-08 09:17:49 +0800 | [diff] [blame] | 27 | #define IOMUXC_GPR1 0x4 |
| 28 | #define BM_IOMUXC_GPR1_IRQ 0x1000 |
| 29 | |
| 30 | #define GPC_LPCR_A7_BSC 0x0 |
| 31 | #define GPC_LPCR_M4 0x8 |
| 32 | #define GPC_SLPCR 0x14 |
| 33 | #define GPC_PGC_ACK_SEL_A7 0x24 |
| 34 | #define GPC_IMR1_CORE0 0x30 |
| 35 | #define GPC_IMR1_CORE1 0x40 |
| 36 | #define GPC_IMR1_M4 0x50 |
| 37 | #define GPC_PGC_CPU_MAPPING 0xec |
| 38 | #define GPC_PGC_C0_PUPSCR 0x804 |
| 39 | #define GPC_PGC_SCU_TIMING 0x890 |
| 40 | #define GPC_PGC_C1_PUPSCR 0x844 |
| 41 | |
| 42 | #define BM_LPCR_A7_BSC_IRQ_SRC_A7_WAKEUP 0x70000000 |
| 43 | #define BM_LPCR_A7_BSC_CPU_CLK_ON_LPM 0x4000 |
| 44 | #define BM_LPCR_M4_MASK_DSM_TRIGGER 0x80000000 |
| 45 | #define BM_SLPCR_EN_DSM 0x80000000 |
| 46 | #define BM_SLPCR_RBC_EN 0x40000000 |
| 47 | #define BM_SLPCR_REG_BYPASS_COUNT 0x3f000000 |
| 48 | #define BM_SLPCR_VSTBY 0x4 |
| 49 | #define BM_SLPCR_SBYOS 0x2 |
| 50 | #define BM_SLPCR_BYPASS_PMIC_READY 0x1 |
| 51 | #define BM_SLPCR_EN_A7_FASTWUP_WAIT_MODE 0x10000 |
| 52 | |
| 53 | #define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PUP_ACK 0x80000000 |
| 54 | #define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK 0x8000 |
| 55 | |
| 56 | #define BM_GPC_PGC_CORE_PUPSCR 0x7fff80 |
| 57 | |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 58 | #if defined(CONFIG_IMX_THERMAL) |
| 59 | static const struct imx_thermal_plat imx7_thermal_plat = { |
| 60 | .regs = (void *)ANATOP_BASE_ADDR, |
| 61 | .fuse_bank = 3, |
| 62 | .fuse_word = 3, |
| 63 | }; |
| 64 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 65 | U_BOOT_DRVINFO(imx7_thermal) = { |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 66 | .name = "imx_thermal", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 67 | .plat = &imx7_thermal_plat, |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 68 | }; |
| 69 | #endif |
| 70 | |
Peng Fan | 77d3aeb | 2017-08-12 22:10:57 +0800 | [diff] [blame] | 71 | #if CONFIG_IS_ENABLED(IMX_RDC) |
Peng Fan | 4784249 | 2016-01-28 16:55:09 +0800 | [diff] [blame] | 72 | /* |
| 73 | * In current design, if any peripheral was assigned to both A7 and M4, |
| 74 | * it will receive ipg_stop or ipg_wait when any of the 2 platforms enter |
| 75 | * low power mode. So M4 sleep will cause some peripherals fail to work |
| 76 | * at A7 core side. At default, all resources are in domain 0 - 3. |
| 77 | * |
| 78 | * There are 26 peripherals impacted by this IC issue: |
| 79 | * SIM2(sim2/emvsim2) |
| 80 | * SIM1(sim1/emvsim1) |
| 81 | * UART1/UART2/UART3/UART4/UART5/UART6/UART7 |
| 82 | * SAI1/SAI2/SAI3 |
| 83 | * WDOG1/WDOG2/WDOG3/WDOG4 |
| 84 | * GPT1/GPT2/GPT3/GPT4 |
| 85 | * PWM1/PWM2/PWM3/PWM4 |
| 86 | * ENET1/ENET2 |
| 87 | * Software Workaround: |
| 88 | * Here we setup some resources to domain 0 where M4 codes will move |
| 89 | * the M4 out of this domain. Then M4 is not able to access them any longer. |
| 90 | * This is a workaround for ic issue. So the peripherals are not shared |
| 91 | * by them. This way requires the uboot implemented the RDC driver and |
| 92 | * set the 26 IPs above to domain 0 only. M4 code will assign resource |
| 93 | * to its own domain, if it want to use the resource. |
| 94 | */ |
| 95 | static rdc_peri_cfg_t const resources[] = { |
| 96 | (RDC_PER_SIM1 | RDC_DOMAIN(0)), |
| 97 | (RDC_PER_SIM2 | RDC_DOMAIN(0)), |
| 98 | (RDC_PER_UART1 | RDC_DOMAIN(0)), |
| 99 | (RDC_PER_UART2 | RDC_DOMAIN(0)), |
| 100 | (RDC_PER_UART3 | RDC_DOMAIN(0)), |
| 101 | (RDC_PER_UART4 | RDC_DOMAIN(0)), |
| 102 | (RDC_PER_UART5 | RDC_DOMAIN(0)), |
| 103 | (RDC_PER_UART6 | RDC_DOMAIN(0)), |
| 104 | (RDC_PER_UART7 | RDC_DOMAIN(0)), |
| 105 | (RDC_PER_SAI1 | RDC_DOMAIN(0)), |
| 106 | (RDC_PER_SAI2 | RDC_DOMAIN(0)), |
| 107 | (RDC_PER_SAI3 | RDC_DOMAIN(0)), |
| 108 | (RDC_PER_WDOG1 | RDC_DOMAIN(0)), |
| 109 | (RDC_PER_WDOG2 | RDC_DOMAIN(0)), |
| 110 | (RDC_PER_WDOG3 | RDC_DOMAIN(0)), |
| 111 | (RDC_PER_WDOG4 | RDC_DOMAIN(0)), |
| 112 | (RDC_PER_GPT1 | RDC_DOMAIN(0)), |
| 113 | (RDC_PER_GPT2 | RDC_DOMAIN(0)), |
| 114 | (RDC_PER_GPT3 | RDC_DOMAIN(0)), |
| 115 | (RDC_PER_GPT4 | RDC_DOMAIN(0)), |
| 116 | (RDC_PER_PWM1 | RDC_DOMAIN(0)), |
| 117 | (RDC_PER_PWM2 | RDC_DOMAIN(0)), |
| 118 | (RDC_PER_PWM3 | RDC_DOMAIN(0)), |
| 119 | (RDC_PER_PWM4 | RDC_DOMAIN(0)), |
| 120 | (RDC_PER_ENET1 | RDC_DOMAIN(0)), |
| 121 | (RDC_PER_ENET2 | RDC_DOMAIN(0)), |
| 122 | }; |
| 123 | |
| 124 | static void isolate_resource(void) |
| 125 | { |
| 126 | imx_rdc_setup_peripherals(resources, ARRAY_SIZE(resources)); |
| 127 | } |
| 128 | #endif |
| 129 | |
Stefano Babic | f8b509b | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 130 | #if defined(CONFIG_IMX_HAB) |
Adrian Alonso | fcc8cb3 | 2015-10-12 13:48:13 -0500 | [diff] [blame] | 131 | struct imx_sec_config_fuse_t const imx_sec_config_fuse = { |
| 132 | .bank = 1, |
| 133 | .word = 3, |
| 134 | }; |
| 135 | #endif |
| 136 | |
Fabio Estevam | f6ced1b | 2016-02-28 12:33:17 -0300 | [diff] [blame] | 137 | static bool is_mx7d(void) |
| 138 | { |
| 139 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 140 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 141 | struct fuse_bank1_regs *fuse = |
| 142 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 143 | int val; |
| 144 | |
| 145 | val = readl(&fuse->tester4); |
| 146 | if (val & 1) |
| 147 | return false; |
| 148 | else |
| 149 | return true; |
| 150 | } |
| 151 | |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 152 | u32 get_cpu_rev(void) |
| 153 | { |
| 154 | struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *) |
| 155 | ANATOP_BASE_ADDR; |
| 156 | u32 reg = readl(&ccm_anatop->digprog); |
| 157 | u32 type = (reg >> 16) & 0xff; |
| 158 | |
Fabio Estevam | f6ced1b | 2016-02-28 12:33:17 -0300 | [diff] [blame] | 159 | if (!is_mx7d()) |
| 160 | type = MXC_CPU_MX7S; |
| 161 | |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 162 | reg &= 0xff; |
| 163 | return (type << 12) | reg; |
| 164 | } |
| 165 | |
| 166 | #ifdef CONFIG_REVISION_TAG |
| 167 | u32 __weak get_board_rev(void) |
| 168 | { |
| 169 | return get_cpu_rev(); |
| 170 | } |
| 171 | #endif |
| 172 | |
Peng Fan | eb518d5 | 2016-01-04 13:16:41 +0800 | [diff] [blame] | 173 | static void imx_enet_mdio_fixup(void) |
| 174 | { |
| 175 | struct iomuxc_gpr_base_regs *gpr_regs = |
| 176 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 177 | |
| 178 | /* |
| 179 | * The management data input/output (MDIO) requires open-drain, |
| 180 | * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports |
| 181 | * this feature. So to TO1.1, need to enable open drain by setting |
| 182 | * bits GPR0[8:7]. |
| 183 | */ |
| 184 | |
| 185 | if (soc_rev() >= CHIP_REV_1_1) { |
| 186 | setbits_le32(&gpr_regs->gpr[0], |
| 187 | IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK); |
| 188 | } |
| 189 | } |
| 190 | |
Jun Nie | 9b1c85a | 2019-05-08 14:38:30 +0800 | [diff] [blame] | 191 | static void init_cpu_basic(void) |
| 192 | { |
| 193 | imx_enet_mdio_fixup(); |
| 194 | |
| 195 | #ifdef CONFIG_APBH_DMA |
| 196 | /* Start APBH DMA */ |
| 197 | mxs_dma_init(); |
| 198 | #endif |
| 199 | } |
| 200 | |
Igor Opaniuk | b65af98 | 2019-12-30 13:56:44 +0200 | [diff] [blame] | 201 | #ifdef CONFIG_IMX_BOOTAUX |
| 202 | /* |
| 203 | * Table of mappings of physical mem regions in both |
| 204 | * Cortex-A7 and Cortex-M4 address spaces. |
| 205 | * |
| 206 | * For additional details check sections 2.1.2 and 2.1.3 in |
| 207 | * i.MX7Dual Applications Processor Reference Manual |
| 208 | * |
| 209 | */ |
| 210 | const struct rproc_att hostmap[] = { |
| 211 | /* aux core , host core, size */ |
| 212 | { 0x00000000, 0x00180000, 0x8000 }, /* OCRAM_S */ |
| 213 | { 0x00180000, 0x00180000, 0x8000 }, /* OCRAM_S */ |
| 214 | { 0x20180000, 0x00180000, 0x8000 }, /* OCRAM_S */ |
| 215 | { 0x1fff8000, 0x007f8000, 0x8000 }, /* TCML */ |
| 216 | { 0x20000000, 0x00800000, 0x8000 }, /* TCMU */ |
| 217 | { 0x00900000, 0x00900000, 0x20000 }, /* OCRAM_128KB */ |
| 218 | { 0x20200000, 0x00900000, 0x20000 }, /* OCRAM_128KB */ |
| 219 | { 0x00920000, 0x00920000, 0x20000 }, /* OCRAM_EPDC */ |
| 220 | { 0x20220000, 0x00920000, 0x20000 }, /* OCRAM_EPDC */ |
| 221 | { 0x00940000, 0x00940000, 0x20000 }, /* OCRAM_PXP */ |
| 222 | { 0x20240000, 0x00940000, 0x20000 }, /* OCRAM_PXP */ |
| 223 | { 0x10000000, 0x80000000, 0x0fff0000 }, /* DDR Code alias */ |
Igor Opaniuk | 02239e2 | 2020-07-15 13:30:52 +0300 | [diff] [blame] | 224 | { 0x80000000, 0x80000000, 0x60000000 }, /* DDRC */ |
Igor Opaniuk | b65af98 | 2019-12-30 13:56:44 +0200 | [diff] [blame] | 225 | { /* sentinel */ } |
| 226 | }; |
| 227 | #endif |
| 228 | |
Tom Rini | e1e8544 | 2021-08-27 21:18:30 -0400 | [diff] [blame] | 229 | #if !CONFIG_IS_ENABLED(SKIP_LOWLEVEL_INIT) |
Jun Nie | 9b1c85a | 2019-05-08 14:38:30 +0800 | [diff] [blame] | 230 | /* enable all periherial can be accessed in nosec mode */ |
| 231 | static void init_csu(void) |
| 232 | { |
| 233 | int i = 0; |
| 234 | |
| 235 | for (i = 0; i < CSU_NUM_REGS; i++) |
| 236 | writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4); |
| 237 | } |
| 238 | |
Anson Huang | 9d61854 | 2018-08-08 09:17:49 +0800 | [diff] [blame] | 239 | static void imx_gpcv2_init(void) |
| 240 | { |
| 241 | u32 val, i; |
| 242 | |
| 243 | /* |
| 244 | * Force IOMUXC irq pending, so that the interrupt to GPC can be |
| 245 | * used to deassert dsm_request signal when the signal gets |
| 246 | * asserted unexpectedly. |
| 247 | */ |
| 248 | val = readl(IOMUXC_GPR_BASE_ADDR + IOMUXC_GPR1); |
| 249 | val |= BM_IOMUXC_GPR1_IRQ; |
| 250 | writel(val, IOMUXC_GPR_BASE_ADDR + IOMUXC_GPR1); |
| 251 | |
| 252 | /* Initially mask all interrupts */ |
| 253 | for (i = 0; i < 4; i++) { |
| 254 | writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_CORE0 + i * 4); |
| 255 | writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_CORE1 + i * 4); |
| 256 | writel(~0, GPC_IPS_BASE_ADDR + GPC_IMR1_M4 + i * 4); |
| 257 | } |
| 258 | |
| 259 | /* set SCU timing */ |
| 260 | writel((0x59 << 10) | 0x5B | (0x2 << 20), |
| 261 | GPC_IPS_BASE_ADDR + GPC_PGC_SCU_TIMING); |
| 262 | |
| 263 | /* only external IRQs to wake up LPM and core 0/1 */ |
| 264 | val = readl(GPC_IPS_BASE_ADDR + GPC_LPCR_A7_BSC); |
| 265 | val |= BM_LPCR_A7_BSC_IRQ_SRC_A7_WAKEUP; |
| 266 | writel(val, GPC_IPS_BASE_ADDR + GPC_LPCR_A7_BSC); |
| 267 | |
| 268 | /* set C0 power up timming per design requirement */ |
| 269 | val = readl(GPC_IPS_BASE_ADDR + GPC_PGC_C0_PUPSCR); |
| 270 | val &= ~BM_GPC_PGC_CORE_PUPSCR; |
| 271 | val |= (0x1A << 7); |
| 272 | writel(val, GPC_IPS_BASE_ADDR + GPC_PGC_C0_PUPSCR); |
| 273 | |
| 274 | /* set C1 power up timming per design requirement */ |
| 275 | val = readl(GPC_IPS_BASE_ADDR + GPC_PGC_C1_PUPSCR); |
| 276 | val &= ~BM_GPC_PGC_CORE_PUPSCR; |
| 277 | val |= (0x1A << 7); |
| 278 | writel(val, GPC_IPS_BASE_ADDR + GPC_PGC_C1_PUPSCR); |
| 279 | |
| 280 | /* dummy ack for time slot by default */ |
| 281 | writel(BM_GPC_PGC_ACK_SEL_A7_DUMMY_PUP_ACK | |
| 282 | BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK, |
| 283 | GPC_IPS_BASE_ADDR + GPC_PGC_ACK_SEL_A7); |
| 284 | |
| 285 | /* mask M4 DSM trigger */ |
| 286 | writel(readl(GPC_IPS_BASE_ADDR + GPC_LPCR_M4) | |
| 287 | BM_LPCR_M4_MASK_DSM_TRIGGER, |
| 288 | GPC_IPS_BASE_ADDR + GPC_LPCR_M4); |
| 289 | |
| 290 | /* set mega/fast mix in A7 domain */ |
| 291 | writel(0x1, GPC_IPS_BASE_ADDR + GPC_PGC_CPU_MAPPING); |
| 292 | |
| 293 | /* DSM related settings */ |
| 294 | val = readl(GPC_IPS_BASE_ADDR + GPC_SLPCR); |
| 295 | val &= ~(BM_SLPCR_EN_DSM | BM_SLPCR_VSTBY | BM_SLPCR_RBC_EN | |
| 296 | BM_SLPCR_SBYOS | BM_SLPCR_BYPASS_PMIC_READY | |
| 297 | BM_SLPCR_REG_BYPASS_COUNT); |
| 298 | val |= BM_SLPCR_EN_A7_FASTWUP_WAIT_MODE; |
| 299 | writel(val, GPC_IPS_BASE_ADDR + GPC_SLPCR); |
| 300 | |
| 301 | /* |
| 302 | * disabling RBC need to delay at least 2 cycles of CKIL(32K) |
| 303 | * due to hardware design requirement, which is |
| 304 | * ~61us, here we use 65us for safe |
| 305 | */ |
| 306 | udelay(65); |
| 307 | } |
| 308 | |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 309 | int arch_cpu_init(void) |
| 310 | { |
| 311 | init_aips(); |
| 312 | |
Peng Fan | fcd53ce | 2015-10-23 10:13:04 +0800 | [diff] [blame] | 313 | init_csu(); |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 314 | /* Disable PDE bit of WMCR register */ |
Fabio Estevam | 5f79d46 | 2017-11-23 10:55:33 -0200 | [diff] [blame] | 315 | imx_wdog_disable_powerdown(); |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 316 | |
Jun Nie | 9b1c85a | 2019-05-08 14:38:30 +0800 | [diff] [blame] | 317 | init_cpu_basic(); |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 318 | |
Peng Fan | 77d3aeb | 2017-08-12 22:10:57 +0800 | [diff] [blame] | 319 | #if CONFIG_IS_ENABLED(IMX_RDC) |
| 320 | isolate_resource(); |
| 321 | #endif |
Peng Fan | 4784249 | 2016-01-28 16:55:09 +0800 | [diff] [blame] | 322 | |
Bryan O'Donoghue | 0290ea0 | 2018-04-05 19:46:06 +0100 | [diff] [blame] | 323 | init_snvs(); |
| 324 | |
Anson Huang | 9d61854 | 2018-08-08 09:17:49 +0800 | [diff] [blame] | 325 | imx_gpcv2_init(); |
| 326 | |
Sven Schwermer | 2645cfa | 2022-01-02 20:36:56 +0100 | [diff] [blame] | 327 | enable_ca7_smp(); |
| 328 | |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 329 | return 0; |
| 330 | } |
Jun Nie | 9b1c85a | 2019-05-08 14:38:30 +0800 | [diff] [blame] | 331 | #else |
| 332 | int arch_cpu_init(void) |
| 333 | { |
| 334 | init_cpu_basic(); |
| 335 | |
| 336 | return 0; |
| 337 | } |
Rui Miguel Silva | d1bb7a0 | 2018-09-05 11:56:05 +0100 | [diff] [blame] | 338 | #endif |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 339 | |
Stefan Agner | 42dac20 | 2016-07-13 00:25:39 -0700 | [diff] [blame] | 340 | #ifdef CONFIG_ARCH_MISC_INIT |
| 341 | int arch_misc_init(void) |
| 342 | { |
| 343 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 344 | struct tag_serialnr serialnr; |
| 345 | char serial_string[0x20]; |
| 346 | |
Stefan Agner | 42dac20 | 2016-07-13 00:25:39 -0700 | [diff] [blame] | 347 | if (is_mx7d()) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 348 | env_set("soc", "imx7d"); |
Stefan Agner | 42dac20 | 2016-07-13 00:25:39 -0700 | [diff] [blame] | 349 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 350 | env_set("soc", "imx7s"); |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 351 | |
| 352 | /* Set serial# standard environment variable based on OTP settings */ |
| 353 | get_board_serial(&serialnr); |
| 354 | snprintf(serial_string, sizeof(serial_string), "0x%08x%08x", |
| 355 | serialnr.low, serialnr.high); |
| 356 | env_set("serial#", serial_string); |
Stefan Agner | 42dac20 | 2016-07-13 00:25:39 -0700 | [diff] [blame] | 357 | #endif |
| 358 | |
Gaurav Jain | e389ac9 | 2022-03-24 11:50:30 +0530 | [diff] [blame] | 359 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 360 | struct udevice *dev; |
| 361 | int ret; |
| 362 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 363 | if (ret) |
Ye Li | ec34689 | 2022-05-11 13:56:20 +0530 | [diff] [blame] | 364 | printf("Failed to initialize caam_jr: %d\n", ret); |
Gaurav Jain | e389ac9 | 2022-03-24 11:50:30 +0530 | [diff] [blame] | 365 | } |
Bryan O'Donoghue | 1ec9d9d | 2018-01-26 16:27:58 +0000 | [diff] [blame] | 366 | |
Stefan Agner | 42dac20 | 2016-07-13 00:25:39 -0700 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | #endif |
| 370 | |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 371 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Bryan O'Donoghue | 3031d43 | 2018-03-26 15:27:33 +0100 | [diff] [blame] | 372 | /* |
| 373 | * OCOTP_TESTER |
| 374 | * i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1, 08/2016 |
| 375 | * OCOTP_TESTER describes a unique ID based on silicon wafer |
| 376 | * and die X/Y position |
| 377 | * |
| 378 | * OCOTOP_TESTER offset 0x410 |
| 379 | * 31:0 fuse 0 |
| 380 | * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID |
| 381 | * |
| 382 | * OCOTP_TESTER1 offset 0x420 |
| 383 | * 31:24 fuse 1 |
| 384 | * The X-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID |
| 385 | * 23:16 fuse 1 |
| 386 | * The Y-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID |
| 387 | * 15:11 fuse 1 |
| 388 | * The wafer number of the wafer on which the device was fabricated/SJC |
| 389 | * CHALLENGE/ Unique ID |
| 390 | * 10:0 fuse 1 |
| 391 | * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID |
| 392 | */ |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 393 | void get_board_serial(struct tag_serialnr *serialnr) |
| 394 | { |
| 395 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 396 | struct fuse_bank *bank = &ocotp->bank[0]; |
| 397 | struct fuse_bank0_regs *fuse = |
| 398 | (struct fuse_bank0_regs *)bank->fuse_regs; |
| 399 | |
| 400 | serialnr->low = fuse->tester0; |
| 401 | serialnr->high = fuse->tester1; |
| 402 | } |
| 403 | #endif |
| 404 | |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 405 | void set_wdog_reset(struct wdog_regs *wdog) |
| 406 | { |
| 407 | u32 reg = readw(&wdog->wcr); |
| 408 | /* |
| 409 | * Output WDOG_B signal to reset external pmic or POR_B decided by |
| 410 | * the board desgin. Without external reset, the peripherals/DDR/ |
| 411 | * PMIC are not reset, that may cause system working abnormal. |
| 412 | */ |
| 413 | reg = readw(&wdog->wcr); |
| 414 | reg |= 1 << 3; |
| 415 | /* |
| 416 | * WDZST bit is write-once only bit. Align this bit in kernel, |
| 417 | * otherwise kernel code will have no chance to set this bit. |
| 418 | */ |
| 419 | reg |= 1 << 0; |
| 420 | writew(reg, &wdog->wcr); |
| 421 | } |
| 422 | |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 423 | void s_init(void) |
| 424 | { |
Adrian Alonso | 2b3d961 | 2015-09-02 13:54:19 -0500 | [diff] [blame] | 425 | /* clock configuration. */ |
| 426 | clock_init(); |
| 427 | |
| 428 | return; |
| 429 | } |
Peng Fan | 99c874b | 2016-05-19 13:02:16 +0800 | [diff] [blame] | 430 | |
Marek Vasut | 28c0b63 | 2020-08-05 15:34:04 +0200 | [diff] [blame] | 431 | #ifndef CONFIG_SPL_BUILD |
| 432 | const struct boot_mode soc_boot_modes[] = { |
| 433 | {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)}, |
Marek Vasut | 6b17c85 | 2020-08-05 15:34:05 +0200 | [diff] [blame] | 434 | {"primary", MAKE_CFGVAL_PRIMARY_BOOT}, |
| 435 | {"secondary", MAKE_CFGVAL_SECONDARY_BOOT}, |
Marek Vasut | 28c0b63 | 2020-08-05 15:34:04 +0200 | [diff] [blame] | 436 | {NULL, 0}, |
| 437 | }; |
Marek Vasut | 5602238 | 2020-08-05 15:34:07 +0200 | [diff] [blame] | 438 | |
| 439 | int boot_mode_getprisec(void) |
| 440 | { |
| 441 | struct src *psrc = (struct src *)SRC_BASE_ADDR; |
| 442 | |
| 443 | return !!(readl(&psrc->gpr10) & IMX7_SRC_GPR10_PERSIST_SECONDARY_BOOT); |
| 444 | } |
Marek Vasut | 28c0b63 | 2020-08-05 15:34:04 +0200 | [diff] [blame] | 445 | #endif |
| 446 | |
Peng Fan | 99c874b | 2016-05-19 13:02:16 +0800 | [diff] [blame] | 447 | void reset_misc(void) |
| 448 | { |
Fabio Estevam | ad5fbe0 | 2018-12-11 16:40:37 -0200 | [diff] [blame] | 449 | #ifndef CONFIG_SPL_BUILD |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame^] | 450 | #if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_VIDEO) |
Peng Fan | 99c874b | 2016-05-19 13:02:16 +0800 | [diff] [blame] | 451 | lcdif_power_down(); |
| 452 | #endif |
Fabio Estevam | ad5fbe0 | 2018-12-11 16:40:37 -0200 | [diff] [blame] | 453 | #endif |
Peng Fan | 99c874b | 2016-05-19 13:02:16 +0800 | [diff] [blame] | 454 | } |