Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 2 | /* |
Ye Li | 70487ff | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 3 | * Copyright 2017-2019 NXP |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 4 | * |
| 5 | * Peng Fan <peng.fan@nxp.com> |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 9edefc2 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 12 | #include <asm/arch/imx-regs.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch/sys_proto.h> |
| 16 | #include <asm/mach-imx/hab.h> |
| 17 | #include <asm/mach-imx/boot_mode.h> |
| 18 | #include <asm/mach-imx/syscounter.h> |
| 19 | #include <asm/armv8/mmu.h> |
Peng Fan | e663c70 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 20 | #include <dm/uclass.h> |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 21 | #include <errno.h> |
| 22 | #include <fdt_support.h> |
| 23 | #include <fsl_wdog.h> |
| 24 | #include <imx_sip.h> |
Peng Fan | a2f143e | 2020-05-11 15:14:04 +0800 | [diff] [blame^] | 25 | #include <linux/arm-smccc.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 26 | #include <linux/bitops.h> |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Stefano Babic | d714a75 | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 30 | #if defined(CONFIG_IMX_HAB) |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 31 | struct imx_sec_config_fuse_t const imx_sec_config_fuse = { |
| 32 | .bank = 1, |
| 33 | .word = 3, |
| 34 | }; |
| 35 | #endif |
| 36 | |
| 37 | int timer_init(void) |
| 38 | { |
| 39 | #ifdef CONFIG_SPL_BUILD |
| 40 | struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR; |
| 41 | unsigned long freq = readl(&sctr->cntfid0); |
| 42 | |
| 43 | /* Update with accurate clock frequency */ |
| 44 | asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory"); |
| 45 | |
| 46 | clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1, |
| 47 | SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG); |
| 48 | #endif |
| 49 | |
| 50 | gd->arch.tbl = 0; |
| 51 | gd->arch.tbu = 0; |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | void enable_tzc380(void) |
| 57 | { |
| 58 | struct iomuxc_gpr_base_regs *gpr = |
| 59 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 60 | |
| 61 | /* Enable TZASC and lock setting */ |
| 62 | setbits_le32(&gpr->gpr[10], GPR_TZASC_EN); |
| 63 | setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK); |
Peng Fan | a07c718 | 2019-12-27 10:19:42 +0800 | [diff] [blame] | 64 | if (is_imx8mm() || is_imx8mn() || is_imx8mp()) |
Peng Fan | dbb2b7e | 2019-08-27 06:25:30 +0000 | [diff] [blame] | 65 | setbits_le32(&gpr->gpr[10], BIT(1)); |
Ye Li | b3cf0a8 | 2019-08-27 06:25:34 +0000 | [diff] [blame] | 66 | /* |
| 67 | * set Region 0 attribute to allow secure and non-secure |
| 68 | * read/write permission. Found some masters like usb dwc3 |
| 69 | * controllers can't work with secure memory. |
| 70 | */ |
| 71 | writel(0xf0000000, TZASC_BASE_ADDR + 0x108); |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void set_wdog_reset(struct wdog_regs *wdog) |
| 75 | { |
| 76 | /* |
| 77 | * Output WDOG_B signal to reset external pmic or POR_B decided by |
| 78 | * the board design. Without external reset, the peripherals/DDR/ |
| 79 | * PMIC are not reset, that may cause system working abnormal. |
| 80 | * WDZST bit is write-once only bit. Align this bit in kernel, |
| 81 | * otherwise kernel code will have no chance to set this bit. |
| 82 | */ |
| 83 | setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK); |
| 84 | } |
| 85 | |
| 86 | static struct mm_region imx8m_mem_map[] = { |
| 87 | { |
| 88 | /* ROM */ |
| 89 | .virt = 0x0UL, |
| 90 | .phys = 0x0UL, |
| 91 | .size = 0x100000UL, |
| 92 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 93 | PTE_BLOCK_OUTER_SHARE |
| 94 | }, { |
Gary Bisson | cb15885 | 2018-11-14 17:55:28 +0100 | [diff] [blame] | 95 | /* CAAM */ |
| 96 | .virt = 0x100000UL, |
| 97 | .phys = 0x100000UL, |
| 98 | .size = 0x8000UL, |
| 99 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 100 | PTE_BLOCK_NON_SHARE | |
| 101 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 102 | }, { |
| 103 | /* TCM */ |
| 104 | .virt = 0x7C0000UL, |
| 105 | .phys = 0x7C0000UL, |
| 106 | .size = 0x80000UL, |
| 107 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 108 | PTE_BLOCK_NON_SHARE | |
| 109 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 110 | }, { |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 111 | /* OCRAM */ |
| 112 | .virt = 0x900000UL, |
| 113 | .phys = 0x900000UL, |
| 114 | .size = 0x200000UL, |
| 115 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 116 | PTE_BLOCK_OUTER_SHARE |
| 117 | }, { |
| 118 | /* AIPS */ |
| 119 | .virt = 0xB00000UL, |
| 120 | .phys = 0xB00000UL, |
| 121 | .size = 0x3f500000UL, |
| 122 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 123 | PTE_BLOCK_NON_SHARE | |
| 124 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 125 | }, { |
| 126 | /* DRAM1 */ |
| 127 | .virt = 0x40000000UL, |
| 128 | .phys = 0x40000000UL, |
Peng Fan | 59efa6b | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 129 | .size = PHYS_SDRAM_SIZE, |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 130 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 131 | PTE_BLOCK_OUTER_SHARE |
Peng Fan | 59efa6b | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 132 | #ifdef PHYS_SDRAM_2_SIZE |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 133 | }, { |
| 134 | /* DRAM2 */ |
| 135 | .virt = 0x100000000UL, |
| 136 | .phys = 0x100000000UL, |
Peng Fan | 59efa6b | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 137 | .size = PHYS_SDRAM_2_SIZE, |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 138 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 139 | PTE_BLOCK_OUTER_SHARE |
Peng Fan | 59efa6b | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 140 | #endif |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 141 | }, { |
| 142 | /* List terminator */ |
| 143 | 0, |
| 144 | } |
| 145 | }; |
| 146 | |
| 147 | struct mm_region *mem_map = imx8m_mem_map; |
| 148 | |
Peng Fan | 59efa6b | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 149 | void enable_caches(void) |
| 150 | { |
| 151 | /* |
| 152 | * If OPTEE runs, remove OPTEE memory from MMU table to |
| 153 | * avoid speculative prefetch. OPTEE runs at the top of |
| 154 | * the first memory bank |
| 155 | */ |
| 156 | if (rom_pointer[1]) |
| 157 | imx8m_mem_map[5].size -= rom_pointer[1]; |
| 158 | |
| 159 | icache_enable(); |
| 160 | dcache_enable(); |
| 161 | } |
| 162 | |
Peng Fan | 78db9a5 | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 163 | static u32 get_cpu_variant_type(u32 type) |
| 164 | { |
| 165 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 166 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 167 | struct fuse_bank1_regs *fuse = |
| 168 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 169 | |
| 170 | u32 value = readl(&fuse->tester4); |
| 171 | |
Peng Fan | cb1a1de | 2020-02-05 17:34:54 +0800 | [diff] [blame] | 172 | if (type == MXC_CPU_IMX8MQ) { |
| 173 | if ((value & 0x3) == 0x2) |
| 174 | return MXC_CPU_IMX8MD; |
| 175 | else if (value & 0x200000) |
| 176 | return MXC_CPU_IMX8MQL; |
| 177 | |
| 178 | } else if (type == MXC_CPU_IMX8MM) { |
Peng Fan | 78db9a5 | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 179 | switch (value & 0x3) { |
| 180 | case 2: |
| 181 | if (value & 0x1c0000) |
| 182 | return MXC_CPU_IMX8MMDL; |
| 183 | else |
| 184 | return MXC_CPU_IMX8MMD; |
| 185 | case 3: |
| 186 | if (value & 0x1c0000) |
| 187 | return MXC_CPU_IMX8MMSL; |
| 188 | else |
| 189 | return MXC_CPU_IMX8MMS; |
| 190 | default: |
| 191 | if (value & 0x1c0000) |
| 192 | return MXC_CPU_IMX8MML; |
| 193 | break; |
| 194 | } |
Peng Fan | c915403 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 195 | } else if (type == MXC_CPU_IMX8MN) { |
| 196 | switch (value & 0x3) { |
| 197 | case 2: |
| 198 | if (value & 0x1000000) |
| 199 | return MXC_CPU_IMX8MNDL; |
| 200 | else |
| 201 | return MXC_CPU_IMX8MND; |
| 202 | case 3: |
| 203 | if (value & 0x1000000) |
| 204 | return MXC_CPU_IMX8MNSL; |
| 205 | else |
| 206 | return MXC_CPU_IMX8MNS; |
| 207 | default: |
| 208 | if (value & 0x1000000) |
| 209 | return MXC_CPU_IMX8MNL; |
| 210 | break; |
| 211 | } |
Peng Fan | 78db9a5 | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | return type; |
| 215 | } |
| 216 | |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 217 | u32 get_cpu_rev(void) |
| 218 | { |
| 219 | struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR; |
| 220 | u32 reg = readl(&ana_pll->digprog); |
| 221 | u32 type = (reg >> 16) & 0xff; |
Peng Fan | 78db9a5 | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 222 | u32 major_low = (reg >> 8) & 0xff; |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 223 | u32 rom_version; |
| 224 | |
| 225 | reg &= 0xff; |
| 226 | |
Peng Fan | 625b03d | 2019-12-27 10:14:02 +0800 | [diff] [blame] | 227 | /* iMX8MP */ |
| 228 | if (major_low == 0x43) { |
| 229 | return (MXC_CPU_IMX8MP << 12) | reg; |
| 230 | } else if (major_low == 0x42) { |
| 231 | /* iMX8MN */ |
Peng Fan | c915403 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 232 | type = get_cpu_variant_type(MXC_CPU_IMX8MN); |
Peng Fan | 2434131 | 2019-06-27 17:23:49 +0800 | [diff] [blame] | 233 | } else if (major_low == 0x41) { |
Peng Fan | 78db9a5 | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 234 | type = get_cpu_variant_type(MXC_CPU_IMX8MM); |
| 235 | } else { |
| 236 | if (reg == CHIP_REV_1_0) { |
| 237 | /* |
Peng Fan | 9e09445 | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 238 | * For B0 chip, the DIGPROG is not updated, |
| 239 | * it is still TO1.0. we have to check ROM |
| 240 | * version or OCOTP_READ_FUSE_DATA. |
| 241 | * 0xff0055aa is magic number for B1. |
Peng Fan | 78db9a5 | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 242 | */ |
Peng Fan | 9e09445 | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 243 | if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) { |
| 244 | reg = CHIP_REV_2_1; |
| 245 | } else { |
| 246 | rom_version = |
| 247 | readl((void __iomem *)ROM_VERSION_A0); |
| 248 | if (rom_version != CHIP_REV_1_0) { |
| 249 | rom_version = readl((void __iomem *)ROM_VERSION_B0); |
Patrick Wildt | 6a4b07e | 2019-11-19 09:42:06 +0100 | [diff] [blame] | 250 | rom_version &= 0xff; |
Peng Fan | 9e09445 | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 251 | if (rom_version == CHIP_REV_2_0) |
| 252 | reg = CHIP_REV_2_0; |
| 253 | } |
Peng Fan | 78db9a5 | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 254 | } |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 255 | } |
Peng Fan | cb1a1de | 2020-02-05 17:34:54 +0800 | [diff] [blame] | 256 | |
| 257 | type = get_cpu_variant_type(type); |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | return (type << 12) | reg; |
| 261 | } |
| 262 | |
| 263 | static void imx_set_wdog_powerdown(bool enable) |
| 264 | { |
| 265 | struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 266 | struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR; |
| 267 | struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR; |
| 268 | |
| 269 | /* Write to the PDE (Power Down Enable) bit */ |
| 270 | writew(enable, &wdog1->wmcr); |
| 271 | writew(enable, &wdog2->wmcr); |
| 272 | writew(enable, &wdog3->wmcr); |
| 273 | } |
| 274 | |
Peng Fan | e663c70 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 275 | int arch_cpu_init_dm(void) |
| 276 | { |
| 277 | struct udevice *dev; |
| 278 | int ret; |
| 279 | |
Peng Fan | cd7c806 | 2019-10-16 03:01:51 +0000 | [diff] [blame] | 280 | if (CONFIG_IS_ENABLED(CLK)) { |
| 281 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 282 | "clock-controller@30380000", |
| 283 | &dev); |
| 284 | if (ret < 0) { |
| 285 | printf("Failed to find clock node. Check device tree\n"); |
| 286 | return ret; |
| 287 | } |
Peng Fan | e663c70 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 293 | int arch_cpu_init(void) |
| 294 | { |
Peng Fan | 702339b | 2019-04-17 09:41:16 +0000 | [diff] [blame] | 295 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 296 | /* |
Peng Fan | 0528ba0 | 2019-08-27 06:25:37 +0000 | [diff] [blame] | 297 | * ROM might disable clock for SCTR, |
| 298 | * enable the clock before timer_init. |
| 299 | */ |
| 300 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 301 | clock_enable(CCGR_SCTR, 1); |
| 302 | /* |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 303 | * Init timer at very early state, because sscg pll setting |
| 304 | * will use it |
| 305 | */ |
| 306 | timer_init(); |
| 307 | |
| 308 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 309 | clock_init(); |
| 310 | imx_set_wdog_powerdown(false); |
| 311 | } |
| 312 | |
Peng Fan | 702339b | 2019-04-17 09:41:16 +0000 | [diff] [blame] | 313 | if (is_imx8mq()) { |
| 314 | clock_enable(CCGR_OCOTP, 1); |
| 315 | if (readl(&ocotp->ctrl) & 0x200) |
| 316 | writel(0x200, &ocotp->ctrl_clr); |
| 317 | } |
| 318 | |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 319 | return 0; |
| 320 | } |
| 321 | |
Peng Fan | b182137 | 2019-09-16 03:09:36 +0000 | [diff] [blame] | 322 | #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP) |
| 323 | struct rom_api *g_rom_api = (struct rom_api *)0x980; |
| 324 | |
| 325 | enum boot_device get_boot_device(void) |
| 326 | { |
| 327 | volatile gd_t *pgd = gd; |
| 328 | int ret; |
| 329 | u32 boot; |
| 330 | u16 boot_type; |
| 331 | u8 boot_instance; |
| 332 | enum boot_device boot_dev = SD1_BOOT; |
| 333 | |
| 334 | ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, |
| 335 | ((uintptr_t)&boot) ^ QUERY_BT_DEV); |
| 336 | gd = pgd; |
| 337 | |
| 338 | if (ret != ROM_API_OKAY) { |
| 339 | puts("ROMAPI: failure at query_boot_info\n"); |
| 340 | return -1; |
| 341 | } |
| 342 | |
| 343 | boot_type = boot >> 16; |
| 344 | boot_instance = (boot >> 8) & 0xff; |
| 345 | |
| 346 | switch (boot_type) { |
| 347 | case BT_DEV_TYPE_SD: |
| 348 | boot_dev = boot_instance + SD1_BOOT; |
| 349 | break; |
| 350 | case BT_DEV_TYPE_MMC: |
| 351 | boot_dev = boot_instance + MMC1_BOOT; |
| 352 | break; |
| 353 | case BT_DEV_TYPE_NAND: |
| 354 | boot_dev = NAND_BOOT; |
| 355 | break; |
| 356 | case BT_DEV_TYPE_FLEXSPINOR: |
| 357 | boot_dev = QSPI_BOOT; |
| 358 | break; |
| 359 | case BT_DEV_TYPE_USB: |
| 360 | boot_dev = USB_BOOT; |
| 361 | break; |
| 362 | default: |
| 363 | break; |
| 364 | } |
| 365 | |
| 366 | return boot_dev; |
| 367 | } |
| 368 | #endif |
| 369 | |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 370 | bool is_usb_boot(void) |
| 371 | { |
| 372 | return get_boot_device() == USB_BOOT; |
| 373 | } |
| 374 | |
| 375 | #ifdef CONFIG_OF_SYSTEM_SETUP |
| 376 | int ft_system_setup(void *blob, bd_t *bd) |
| 377 | { |
| 378 | int i = 0; |
| 379 | int rc; |
| 380 | int nodeoff; |
| 381 | |
| 382 | /* Disable the CPU idle for A0 chip since the HW does not support it */ |
| 383 | if (is_soc_rev(CHIP_REV_1_0)) { |
| 384 | static const char * const nodes_path[] = { |
| 385 | "/cpus/cpu@0", |
| 386 | "/cpus/cpu@1", |
| 387 | "/cpus/cpu@2", |
| 388 | "/cpus/cpu@3", |
| 389 | }; |
| 390 | |
| 391 | for (i = 0; i < ARRAY_SIZE(nodes_path); i++) { |
| 392 | nodeoff = fdt_path_offset(blob, nodes_path[i]); |
| 393 | if (nodeoff < 0) |
| 394 | continue; /* Not found, skip it */ |
| 395 | |
Marek Vasut | dabaabd | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 396 | debug("Found %s node\n", nodes_path[i]); |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 397 | |
| 398 | rc = fdt_delprop(blob, nodeoff, "cpu-idle-states"); |
Marek Vasut | dabaabd | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 399 | if (rc == -FDT_ERR_NOTFOUND) |
| 400 | continue; |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 401 | if (rc) { |
| 402 | printf("Unable to update property %s:%s, err=%s\n", |
| 403 | nodes_path[i], "status", fdt_strerror(rc)); |
| 404 | return rc; |
| 405 | } |
| 406 | |
Marek Vasut | dabaabd | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 407 | debug("Remove %s:%s\n", nodes_path[i], |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 408 | "cpu-idle-states"); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | #endif |
| 415 | |
Marek Vasut | efa1a62 | 2020-04-29 15:04:21 +0200 | [diff] [blame] | 416 | #if !CONFIG_IS_ENABLED(SYSRESET) |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 417 | void reset_cpu(ulong addr) |
| 418 | { |
Claudius Heine | c5635a0 | 2020-04-29 15:04:23 +0200 | [diff] [blame] | 419 | struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 420 | |
Ye Li | 7247974 | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 421 | /* Clear WDA to trigger WDOG_B immediately */ |
| 422 | writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr); |
Peng Fan | d204172 | 2019-08-27 06:25:41 +0000 | [diff] [blame] | 423 | |
Ye Li | 7247974 | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 424 | while (1) { |
| 425 | /* |
Harald Seiler | 568af92 | 2020-04-29 15:04:22 +0200 | [diff] [blame] | 426 | * spin for .5 seconds before reset |
Ye Li | 7247974 | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 427 | */ |
| 428 | } |
Peng Fan | fcdbde7 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 429 | } |
Peng Fan | d204172 | 2019-08-27 06:25:41 +0000 | [diff] [blame] | 430 | #endif |
Peng Fan | a07bcec | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 431 | |
| 432 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 433 | static void acquire_buildinfo(void) |
| 434 | { |
| 435 | u64 atf_commit = 0; |
Peng Fan | a2f143e | 2020-05-11 15:14:04 +0800 | [diff] [blame^] | 436 | struct arm_smccc_res res; |
Peng Fan | a07bcec | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 437 | |
| 438 | /* Get ARM Trusted Firmware commit id */ |
Peng Fan | a2f143e | 2020-05-11 15:14:04 +0800 | [diff] [blame^] | 439 | arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH, |
| 440 | 0, 0 , 0, 0, 0, 0, &res); |
| 441 | atf_commit = res.a0; |
Peng Fan | a07bcec | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 442 | if (atf_commit == 0xffffffff) { |
| 443 | debug("ATF does not support build info\n"); |
| 444 | atf_commit = 0x30; /* Display 0, 0 ascii is 0x30 */ |
| 445 | } |
| 446 | |
| 447 | printf("\n BuildInfo:\n - ATF %s\n\n", (char *)&atf_commit); |
| 448 | } |
| 449 | |
| 450 | int arch_misc_init(void) |
| 451 | { |
| 452 | acquire_buildinfo(); |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | #endif |
Ye Li | 70487ff | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 457 | |
| 458 | void imx_tmu_arch_init(void *reg_base) |
| 459 | { |
Ye Li | 94c693d | 2020-05-03 22:19:53 +0800 | [diff] [blame] | 460 | if (is_imx8mm() || is_imx8mn()) { |
Ye Li | 70487ff | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 461 | /* Load TCALIV and TASR from fuses */ |
| 462 | struct ocotp_regs *ocotp = |
| 463 | (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 464 | struct fuse_bank *bank = &ocotp->bank[3]; |
| 465 | struct fuse_bank3_regs *fuse = |
| 466 | (struct fuse_bank3_regs *)bank->fuse_regs; |
| 467 | |
| 468 | u32 tca_rt, tca_hr, tca_en; |
| 469 | u32 buf_vref, buf_slope; |
| 470 | |
| 471 | tca_rt = fuse->ana0 & 0xFF; |
| 472 | tca_hr = (fuse->ana0 & 0xFF00) >> 8; |
| 473 | tca_en = (fuse->ana0 & 0x2000000) >> 25; |
| 474 | |
| 475 | buf_vref = (fuse->ana0 & 0x1F00000) >> 20; |
| 476 | buf_slope = (fuse->ana0 & 0xF0000) >> 16; |
| 477 | |
| 478 | writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28); |
| 479 | writel((tca_en << 31) | (tca_hr << 16) | tca_rt, |
| 480 | (ulong)reg_base + 0x30); |
| 481 | } |
Ye Li | ebb9aab | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 482 | #ifdef CONFIG_IMX8MP |
| 483 | /* Load TCALIV0/1/m40 and TRIM from fuses */ |
| 484 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 485 | struct fuse_bank *bank = &ocotp->bank[38]; |
| 486 | struct fuse_bank38_regs *fuse = |
| 487 | (struct fuse_bank38_regs *)bank->fuse_regs; |
| 488 | struct fuse_bank *bank2 = &ocotp->bank[39]; |
| 489 | struct fuse_bank39_regs *fuse2 = |
| 490 | (struct fuse_bank39_regs *)bank2->fuse_regs; |
| 491 | u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr; |
| 492 | u32 reg; |
| 493 | u32 tca40[2], tca25[2], tca105[2]; |
| 494 | |
| 495 | /* For blank sample */ |
| 496 | if (!fuse->ana_trim2 && !fuse->ana_trim3 && |
| 497 | !fuse->ana_trim4 && !fuse2->ana_trim5) { |
| 498 | /* Use a default 25C binary codes */ |
| 499 | tca25[0] = 1596; |
Ye Li | 3462b55 | 2020-05-03 22:19:55 +0800 | [diff] [blame] | 500 | tca25[1] = 1596; |
Ye Li | ebb9aab | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 501 | writel(tca25[0], (ulong)reg_base + 0x30); |
Ye Li | 3462b55 | 2020-05-03 22:19:55 +0800 | [diff] [blame] | 502 | writel(tca25[1], (ulong)reg_base + 0x34); |
Ye Li | ebb9aab | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 503 | return; |
| 504 | } |
| 505 | |
| 506 | buf_vref = (fuse->ana_trim2 & 0xc0) >> 6; |
| 507 | buf_slope = (fuse->ana_trim2 & 0xF00) >> 8; |
| 508 | bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12; |
| 509 | bgr = (fuse->ana_trim2 & 0xF0000) >> 16; |
| 510 | vlsb = (fuse->ana_trim2 & 0xF00000) >> 20; |
| 511 | writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28); |
| 512 | |
| 513 | reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7); |
| 514 | writel(reg, (ulong)reg_base + 0x3c); |
| 515 | |
| 516 | tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16; |
| 517 | tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28; |
| 518 | tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4); |
| 519 | tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8; |
| 520 | tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20; |
| 521 | tca25[1] = fuse2->ana_trim5 & 0xFFF; |
| 522 | tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12; |
| 523 | |
| 524 | /* use 25c for 1p calibration */ |
| 525 | writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30); |
| 526 | writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34); |
| 527 | writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38); |
| 528 | #endif |
Ye Li | 70487ff | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 529 | } |