1 // SPDX-License-Identifier: GPL-2.0+
5 * Peng Fan <peng.fan@nxp.com>
9 #include <asm/arch/imx-regs.h>
11 #include <asm/arch/clock.h>
12 #include <asm/arch/sys_proto.h>
13 #include <asm/mach-imx/hab.h>
14 #include <asm/mach-imx/boot_mode.h>
15 #include <asm/mach-imx/syscounter.h>
16 #include <asm/armv8/mmu.h>
18 #include <fdt_support.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 #if defined(CONFIG_SECURE_BOOT)
25 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
33 #ifdef CONFIG_SPL_BUILD
34 struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
35 unsigned long freq = readl(&sctr->cntfid0);
37 /* Update with accurate clock frequency */
38 asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory");
40 clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
41 SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
50 void enable_tzc380(void)
52 struct iomuxc_gpr_base_regs *gpr =
53 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
55 /* Enable TZASC and lock setting */
56 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN);
57 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK);
58 if (IS_ENABLED(CONFIG_IMX8MM))
59 setbits_le32(&gpr->gpr[10], BIT(1));
61 * set Region 0 attribute to allow secure and non-secure
62 * read/write permission. Found some masters like usb dwc3
63 * controllers can't work with secure memory.
65 writel(0xf0000000, TZASC_BASE_ADDR + 0x108);
68 void set_wdog_reset(struct wdog_regs *wdog)
71 * Output WDOG_B signal to reset external pmic or POR_B decided by
72 * the board design. Without external reset, the peripherals/DDR/
73 * PMIC are not reset, that may cause system working abnormal.
74 * WDZST bit is write-once only bit. Align this bit in kernel,
75 * otherwise kernel code will have no chance to set this bit.
77 setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK);
80 static struct mm_region imx8m_mem_map[] = {
86 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
93 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
95 PTE_BLOCK_PXN | PTE_BLOCK_UXN
101 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
102 PTE_BLOCK_NON_SHARE |
103 PTE_BLOCK_PXN | PTE_BLOCK_UXN
109 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
110 PTE_BLOCK_OUTER_SHARE
115 .size = 0x3f500000UL,
116 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
117 PTE_BLOCK_NON_SHARE |
118 PTE_BLOCK_PXN | PTE_BLOCK_UXN
121 .virt = 0x40000000UL,
122 .phys = 0x40000000UL,
123 .size = PHYS_SDRAM_SIZE,
124 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
125 PTE_BLOCK_OUTER_SHARE
126 #ifdef PHYS_SDRAM_2_SIZE
129 .virt = 0x100000000UL,
130 .phys = 0x100000000UL,
131 .size = PHYS_SDRAM_2_SIZE,
132 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
133 PTE_BLOCK_OUTER_SHARE
136 /* List terminator */
141 struct mm_region *mem_map = imx8m_mem_map;
143 void enable_caches(void)
146 * If OPTEE runs, remove OPTEE memory from MMU table to
147 * avoid speculative prefetch. OPTEE runs at the top of
148 * the first memory bank
151 imx8m_mem_map[5].size -= rom_pointer[1];
157 static u32 get_cpu_variant_type(u32 type)
159 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
160 struct fuse_bank *bank = &ocotp->bank[1];
161 struct fuse_bank1_regs *fuse =
162 (struct fuse_bank1_regs *)bank->fuse_regs;
164 u32 value = readl(&fuse->tester4);
166 if (type == MXC_CPU_IMX8MM) {
167 switch (value & 0x3) {
169 if (value & 0x1c0000)
170 return MXC_CPU_IMX8MMDL;
172 return MXC_CPU_IMX8MMD;
174 if (value & 0x1c0000)
175 return MXC_CPU_IMX8MMSL;
177 return MXC_CPU_IMX8MMS;
179 if (value & 0x1c0000)
180 return MXC_CPU_IMX8MML;
188 u32 get_cpu_rev(void)
190 struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR;
191 u32 reg = readl(&ana_pll->digprog);
192 u32 type = (reg >> 16) & 0xff;
193 u32 major_low = (reg >> 8) & 0xff;
199 if (major_low == 0x41) {
200 type = get_cpu_variant_type(MXC_CPU_IMX8MM);
202 if (reg == CHIP_REV_1_0) {
204 * For B0 chip, the DIGPROG is not updated, still TO1.0.
205 * we have to check ROM version further
207 rom_version = readl((void __iomem *)ROM_VERSION_A0);
208 if (rom_version != CHIP_REV_1_0) {
209 rom_version = readl((void __iomem *)ROM_VERSION_B0);
210 if (rom_version >= CHIP_REV_2_0)
216 return (type << 12) | reg;
219 static void imx_set_wdog_powerdown(bool enable)
221 struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
222 struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
223 struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
225 /* Write to the PDE (Power Down Enable) bit */
226 writew(enable, &wdog1->wmcr);
227 writew(enable, &wdog2->wmcr);
228 writew(enable, &wdog3->wmcr);
231 int arch_cpu_init(void)
233 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
235 * Init timer at very early state, because sscg pll setting
240 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
242 imx_set_wdog_powerdown(false);
246 clock_enable(CCGR_OCOTP, 1);
247 if (readl(&ocotp->ctrl) & 0x200)
248 writel(0x200, &ocotp->ctrl_clr);
254 bool is_usb_boot(void)
256 return get_boot_device() == USB_BOOT;
259 #ifdef CONFIG_OF_SYSTEM_SETUP
260 int ft_system_setup(void *blob, bd_t *bd)
266 /* Disable the CPU idle for A0 chip since the HW does not support it */
267 if (is_soc_rev(CHIP_REV_1_0)) {
268 static const char * const nodes_path[] = {
275 for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
276 nodeoff = fdt_path_offset(blob, nodes_path[i]);
278 continue; /* Not found, skip it */
280 printf("Found %s node\n", nodes_path[i]);
282 rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
284 printf("Unable to update property %s:%s, err=%s\n",
285 nodes_path[i], "status", fdt_strerror(rc));
289 printf("Remove %s:%s\n", nodes_path[i],
298 void reset_cpu(ulong addr)
300 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
302 /* Clear WDA to trigger WDOG_B immediately */
303 writew((WCR_WDE | WCR_SRS), &wdog->wcr);
307 * spin for .5 seconds before reset