Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017 NXP |
| 3 | * |
| 4 | * Peng Fan <peng.fan@nxp.com> |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/arch/imx-regs.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <asm/mach-imx/hab.h> |
| 15 | #include <asm/mach-imx/boot_mode.h> |
| 16 | #include <asm/mach-imx/syscounter.h> |
| 17 | #include <asm/armv8/mmu.h> |
| 18 | #include <errno.h> |
| 19 | #include <fdt_support.h> |
| 20 | #include <fsl_wdog.h> |
| 21 | #include <imx_sip.h> |
| 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
| 25 | #if defined(CONFIG_SECURE_BOOT) |
| 26 | struct imx_sec_config_fuse_t const imx_sec_config_fuse = { |
| 27 | .bank = 1, |
| 28 | .word = 3, |
| 29 | }; |
| 30 | #endif |
| 31 | |
| 32 | int timer_init(void) |
| 33 | { |
| 34 | #ifdef CONFIG_SPL_BUILD |
| 35 | struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR; |
| 36 | unsigned long freq = readl(&sctr->cntfid0); |
| 37 | |
| 38 | /* Update with accurate clock frequency */ |
| 39 | asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory"); |
| 40 | |
| 41 | clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1, |
| 42 | SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG); |
| 43 | #endif |
| 44 | |
| 45 | gd->arch.tbl = 0; |
| 46 | gd->arch.tbu = 0; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | void enable_tzc380(void) |
| 52 | { |
| 53 | struct iomuxc_gpr_base_regs *gpr = |
| 54 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 55 | |
| 56 | /* Enable TZASC and lock setting */ |
| 57 | setbits_le32(&gpr->gpr[10], GPR_TZASC_EN); |
| 58 | setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK); |
| 59 | } |
| 60 | |
| 61 | void set_wdog_reset(struct wdog_regs *wdog) |
| 62 | { |
| 63 | /* |
| 64 | * Output WDOG_B signal to reset external pmic or POR_B decided by |
| 65 | * the board design. Without external reset, the peripherals/DDR/ |
| 66 | * PMIC are not reset, that may cause system working abnormal. |
| 67 | * WDZST bit is write-once only bit. Align this bit in kernel, |
| 68 | * otherwise kernel code will have no chance to set this bit. |
| 69 | */ |
| 70 | setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK); |
| 71 | } |
| 72 | |
| 73 | static struct mm_region imx8m_mem_map[] = { |
| 74 | { |
| 75 | /* ROM */ |
| 76 | .virt = 0x0UL, |
| 77 | .phys = 0x0UL, |
| 78 | .size = 0x100000UL, |
| 79 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 80 | PTE_BLOCK_OUTER_SHARE |
| 81 | }, { |
| 82 | /* OCRAM */ |
| 83 | .virt = 0x900000UL, |
| 84 | .phys = 0x900000UL, |
| 85 | .size = 0x200000UL, |
| 86 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 87 | PTE_BLOCK_OUTER_SHARE |
| 88 | }, { |
| 89 | /* AIPS */ |
| 90 | .virt = 0xB00000UL, |
| 91 | .phys = 0xB00000UL, |
| 92 | .size = 0x3f500000UL, |
| 93 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 94 | PTE_BLOCK_NON_SHARE | |
| 95 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 96 | }, { |
| 97 | /* DRAM1 */ |
| 98 | .virt = 0x40000000UL, |
| 99 | .phys = 0x40000000UL, |
| 100 | .size = 0xC0000000UL, |
| 101 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 102 | PTE_BLOCK_OUTER_SHARE |
| 103 | }, { |
| 104 | /* DRAM2 */ |
| 105 | .virt = 0x100000000UL, |
| 106 | .phys = 0x100000000UL, |
| 107 | .size = 0x040000000UL, |
| 108 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 109 | PTE_BLOCK_OUTER_SHARE |
| 110 | }, { |
| 111 | /* List terminator */ |
| 112 | 0, |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | struct mm_region *mem_map = imx8m_mem_map; |
| 117 | |
| 118 | u32 get_cpu_rev(void) |
| 119 | { |
| 120 | struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR; |
| 121 | u32 reg = readl(&ana_pll->digprog); |
| 122 | u32 type = (reg >> 16) & 0xff; |
| 123 | u32 rom_version; |
| 124 | |
| 125 | reg &= 0xff; |
| 126 | |
| 127 | if (reg == CHIP_REV_1_0) { |
| 128 | /* |
| 129 | * For B0 chip, the DIGPROG is not updated, still TO1.0. |
| 130 | * we have to check ROM version further |
| 131 | */ |
| 132 | rom_version = readl((void __iomem *)ROM_VERSION_A0); |
| 133 | if (rom_version != CHIP_REV_1_0) { |
| 134 | rom_version = readl((void __iomem *)ROM_VERSION_B0); |
| 135 | if (rom_version >= CHIP_REV_2_0) |
| 136 | reg = CHIP_REV_2_0; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return (type << 12) | reg; |
| 141 | } |
| 142 | |
| 143 | static void imx_set_wdog_powerdown(bool enable) |
| 144 | { |
| 145 | struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 146 | struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR; |
| 147 | struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR; |
| 148 | |
| 149 | /* Write to the PDE (Power Down Enable) bit */ |
| 150 | writew(enable, &wdog1->wmcr); |
| 151 | writew(enable, &wdog2->wmcr); |
| 152 | writew(enable, &wdog3->wmcr); |
| 153 | } |
| 154 | |
| 155 | int arch_cpu_init(void) |
| 156 | { |
| 157 | /* |
| 158 | * Init timer at very early state, because sscg pll setting |
| 159 | * will use it |
| 160 | */ |
| 161 | timer_init(); |
| 162 | |
| 163 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 164 | clock_init(); |
| 165 | imx_set_wdog_powerdown(false); |
| 166 | } |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | bool is_usb_boot(void) |
| 172 | { |
| 173 | return get_boot_device() == USB_BOOT; |
| 174 | } |
| 175 | |
| 176 | #ifdef CONFIG_OF_SYSTEM_SETUP |
| 177 | int ft_system_setup(void *blob, bd_t *bd) |
| 178 | { |
| 179 | int i = 0; |
| 180 | int rc; |
| 181 | int nodeoff; |
| 182 | |
| 183 | /* Disable the CPU idle for A0 chip since the HW does not support it */ |
| 184 | if (is_soc_rev(CHIP_REV_1_0)) { |
| 185 | static const char * const nodes_path[] = { |
| 186 | "/cpus/cpu@0", |
| 187 | "/cpus/cpu@1", |
| 188 | "/cpus/cpu@2", |
| 189 | "/cpus/cpu@3", |
| 190 | }; |
| 191 | |
| 192 | for (i = 0; i < ARRAY_SIZE(nodes_path); i++) { |
| 193 | nodeoff = fdt_path_offset(blob, nodes_path[i]); |
| 194 | if (nodeoff < 0) |
| 195 | continue; /* Not found, skip it */ |
| 196 | |
| 197 | printf("Found %s node\n", nodes_path[i]); |
| 198 | |
| 199 | rc = fdt_delprop(blob, nodeoff, "cpu-idle-states"); |
| 200 | if (rc) { |
| 201 | printf("Unable to update property %s:%s, err=%s\n", |
| 202 | nodes_path[i], "status", fdt_strerror(rc)); |
| 203 | return rc; |
| 204 | } |
| 205 | |
| 206 | printf("Remove %s:%s\n", nodes_path[i], |
| 207 | "cpu-idle-states"); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | #endif |
| 214 | |
| 215 | void reset_cpu(ulong addr) |
| 216 | { |
| 217 | struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; |
| 218 | |
| 219 | /* Clear WDA to trigger WDOG_B immediately */ |
| 220 | writew((WCR_WDE | WCR_SRS), &wdog->wcr); |
| 221 | |
| 222 | while (1) { |
| 223 | /* |
| 224 | * spin for .5 seconds before reset |
| 225 | */ |
| 226 | } |
| 227 | } |