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 | |
| 37 | static struct mm_region imx93_mem_map[] = { |
| 38 | { |
| 39 | /* ROM */ |
| 40 | .virt = 0x0UL, |
| 41 | .phys = 0x0UL, |
| 42 | .size = 0x100000UL, |
| 43 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 44 | PTE_BLOCK_OUTER_SHARE |
| 45 | }, { |
| 46 | /* OCRAM */ |
| 47 | .virt = 0x20480000UL, |
| 48 | .phys = 0x20480000UL, |
| 49 | .size = 0xA0000UL, |
| 50 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 51 | PTE_BLOCK_OUTER_SHARE |
| 52 | }, { |
| 53 | /* AIPS */ |
| 54 | .virt = 0x40000000UL, |
| 55 | .phys = 0x40000000UL, |
| 56 | .size = 0x40000000UL, |
| 57 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 58 | PTE_BLOCK_NON_SHARE | |
| 59 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 60 | }, { |
| 61 | /* Flexible Serial Peripheral Interface */ |
| 62 | .virt = 0x28000000UL, |
| 63 | .phys = 0x28000000UL, |
| 64 | .size = 0x30000000UL, |
| 65 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 66 | PTE_BLOCK_NON_SHARE | |
| 67 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 68 | }, { |
| 69 | /* DRAM1 */ |
| 70 | .virt = 0x80000000UL, |
| 71 | .phys = 0x80000000UL, |
| 72 | .size = PHYS_SDRAM_SIZE, |
| 73 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 74 | PTE_BLOCK_OUTER_SHARE |
| 75 | }, { |
| 76 | /* empty entrie to split table entry 5 if needed when TEEs are used */ |
| 77 | 0, |
| 78 | }, { |
| 79 | /* List terminator */ |
| 80 | 0, |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | struct mm_region *mem_map = imx93_mem_map; |
| 85 | |
| 86 | int dram_init(void) |
| 87 | { |
| 88 | gd->ram_size = PHYS_SDRAM_SIZE; |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 94 | { |
| 95 | mac[0] = 0x1; |
| 96 | mac[1] = 0x2; |
| 97 | mac[2] = 0x3; |
| 98 | mac[3] = 0x4; |
| 99 | mac[4] = 0x5; |
| 100 | mac[5] = 0x6; |
| 101 | } |
| 102 | |
| 103 | int print_cpuinfo(void) |
| 104 | { |
| 105 | u32 cpurev; |
| 106 | |
| 107 | cpurev = get_cpu_rev(); |
| 108 | |
| 109 | printf("CPU: i.MX93 rev%d.%d\n", (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0); |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | int arch_misc_init(void) |
| 115 | { |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | int ft_system_setup(void *blob, struct bd_info *bd) |
| 120 | { |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | int arch_cpu_init(void) |
| 125 | { |
Peng Fan | 28b5cb5 | 2022-07-26 16:40:43 +0800 | [diff] [blame] | 126 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 127 | clock_init(); |
| 128 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 129 | return 0; |
| 130 | } |
Jian Li | acf41a3 | 2022-07-26 16:40:46 +0800 | [diff] [blame^] | 131 | |
| 132 | int timer_init(void) |
| 133 | { |
| 134 | #ifdef CONFIG_SPL_BUILD |
| 135 | struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR; |
| 136 | unsigned long freq = readl(&sctr->cntfid0); |
| 137 | |
| 138 | /* Update with accurate clock frequency */ |
| 139 | asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory"); |
| 140 | |
| 141 | clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1, |
| 142 | SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG); |
| 143 | #endif |
| 144 | |
| 145 | gd->arch.tbl = 0; |
| 146 | gd->arch.tbu = 0; |
| 147 | |
| 148 | return 0; |
| 149 | } |