Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2022 NXP |
| 4 | * |
| 5 | * Peng Fan <peng.fan@nxp.com> |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <cpu_func.h> |
| 10 | #include <init.h> |
| 11 | #include <log.h> |
| 12 | #include <asm/arch/imx-regs.h> |
| 13 | #include <asm/global_data.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/clock.h> |
| 16 | #include <asm/arch/sys_proto.h> |
| 17 | #include <asm/mach-imx/boot_mode.h> |
| 18 | #include <asm/mach-imx/syscounter.h> |
| 19 | #include <asm/armv8/mmu.h> |
| 20 | #include <dm/uclass.h> |
| 21 | #include <env.h> |
| 22 | #include <env_internal.h> |
| 23 | #include <errno.h> |
| 24 | #include <fdt_support.h> |
| 25 | #include <linux/bitops.h> |
| 26 | #include <asm/setup.h> |
| 27 | #include <asm/bootm.h> |
| 28 | #include <asm/arch-imx/cpu.h> |
| 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | u32 get_cpu_rev(void) |
| 33 | { |
| 34 | return (MXC_CPU_IMX93 << 12) | CHIP_REV_1_0; |
| 35 | } |
| 36 | |
Ye Li | 9e19ff9 | 2022-07-26 16:40:47 +0800 | [diff] [blame^] | 37 | #define UNLOCK_WORD 0xD928C520 /* unlock word */ |
| 38 | #define REFRESH_WORD 0xB480A602 /* refresh word */ |
| 39 | |
| 40 | static void disable_wdog(void __iomem *wdog_base) |
| 41 | { |
| 42 | u32 val_cs = readl(wdog_base + 0x00); |
| 43 | |
| 44 | if (!(val_cs & 0x80)) |
| 45 | return; |
| 46 | |
| 47 | /* default is 32bits cmd */ |
| 48 | writel(REFRESH_WORD, (wdog_base + 0x04)); /* Refresh the CNT */ |
| 49 | |
| 50 | if (!(val_cs & 0x800)) { |
| 51 | writel(UNLOCK_WORD, (wdog_base + 0x04)); |
| 52 | while (!(readl(wdog_base + 0x00) & 0x800)) |
| 53 | ; |
| 54 | } |
| 55 | writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */ |
| 56 | writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */ |
| 57 | writel(0x2120, (wdog_base + 0x00)); /* Disable it and set update */ |
| 58 | |
| 59 | while (!(readl(wdog_base + 0x00) & 0x400)) |
| 60 | ; |
| 61 | } |
| 62 | |
| 63 | void init_wdog(void) |
| 64 | { |
| 65 | u32 src_val; |
| 66 | |
| 67 | disable_wdog((void __iomem *)WDG3_BASE_ADDR); |
| 68 | disable_wdog((void __iomem *)WDG4_BASE_ADDR); |
| 69 | disable_wdog((void __iomem *)WDG5_BASE_ADDR); |
| 70 | |
| 71 | src_val = readl(0x54460018); /* reset mask */ |
| 72 | src_val &= ~0x1c; |
| 73 | writel(src_val, 0x54460018); |
| 74 | } |
| 75 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 76 | static struct mm_region imx93_mem_map[] = { |
| 77 | { |
| 78 | /* ROM */ |
| 79 | .virt = 0x0UL, |
| 80 | .phys = 0x0UL, |
| 81 | .size = 0x100000UL, |
| 82 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 83 | PTE_BLOCK_OUTER_SHARE |
| 84 | }, { |
| 85 | /* OCRAM */ |
| 86 | .virt = 0x20480000UL, |
| 87 | .phys = 0x20480000UL, |
| 88 | .size = 0xA0000UL, |
| 89 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 90 | PTE_BLOCK_OUTER_SHARE |
| 91 | }, { |
| 92 | /* AIPS */ |
| 93 | .virt = 0x40000000UL, |
| 94 | .phys = 0x40000000UL, |
| 95 | .size = 0x40000000UL, |
| 96 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 97 | PTE_BLOCK_NON_SHARE | |
| 98 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 99 | }, { |
| 100 | /* Flexible Serial Peripheral Interface */ |
| 101 | .virt = 0x28000000UL, |
| 102 | .phys = 0x28000000UL, |
| 103 | .size = 0x30000000UL, |
| 104 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 105 | PTE_BLOCK_NON_SHARE | |
| 106 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 107 | }, { |
| 108 | /* DRAM1 */ |
| 109 | .virt = 0x80000000UL, |
| 110 | .phys = 0x80000000UL, |
| 111 | .size = PHYS_SDRAM_SIZE, |
| 112 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 113 | PTE_BLOCK_OUTER_SHARE |
| 114 | }, { |
| 115 | /* empty entrie to split table entry 5 if needed when TEEs are used */ |
| 116 | 0, |
| 117 | }, { |
| 118 | /* List terminator */ |
| 119 | 0, |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | struct mm_region *mem_map = imx93_mem_map; |
| 124 | |
| 125 | int dram_init(void) |
| 126 | { |
| 127 | gd->ram_size = PHYS_SDRAM_SIZE; |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 133 | { |
| 134 | mac[0] = 0x1; |
| 135 | mac[1] = 0x2; |
| 136 | mac[2] = 0x3; |
| 137 | mac[3] = 0x4; |
| 138 | mac[4] = 0x5; |
| 139 | mac[5] = 0x6; |
| 140 | } |
| 141 | |
| 142 | int print_cpuinfo(void) |
| 143 | { |
| 144 | u32 cpurev; |
| 145 | |
| 146 | cpurev = get_cpu_rev(); |
| 147 | |
| 148 | printf("CPU: i.MX93 rev%d.%d\n", (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0); |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | int arch_misc_init(void) |
| 154 | { |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | int ft_system_setup(void *blob, struct bd_info *bd) |
| 159 | { |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | int arch_cpu_init(void) |
| 164 | { |
Ye Li | 9e19ff9 | 2022-07-26 16:40:47 +0800 | [diff] [blame^] | 165 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 166 | /* Disable wdog */ |
| 167 | init_wdog(); |
| 168 | |
Peng Fan | 28b5cb5 | 2022-07-26 16:40:43 +0800 | [diff] [blame] | 169 | clock_init(); |
Ye Li | 9e19ff9 | 2022-07-26 16:40:47 +0800 | [diff] [blame^] | 170 | } |
Peng Fan | 28b5cb5 | 2022-07-26 16:40:43 +0800 | [diff] [blame] | 171 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 172 | return 0; |
| 173 | } |
Jian Li | acf41a3 | 2022-07-26 16:40:46 +0800 | [diff] [blame] | 174 | |
| 175 | int timer_init(void) |
| 176 | { |
| 177 | #ifdef CONFIG_SPL_BUILD |
| 178 | struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR; |
| 179 | unsigned long freq = readl(&sctr->cntfid0); |
| 180 | |
| 181 | /* Update with accurate clock frequency */ |
| 182 | asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory"); |
| 183 | |
| 184 | clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1, |
| 185 | SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG); |
| 186 | #endif |
| 187 | |
| 188 | gd->arch.tbl = 0; |
| 189 | gd->arch.tbu = 0; |
| 190 | |
| 191 | return 0; |
| 192 | } |