Jim Liu | 147c000 | 2022-09-27 16:45:15 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2022 Nuvoton Technology Corp. |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <asm/global_data.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/system.h> |
| 11 | #include <asm/arch/gcr.h> |
| 12 | #include <asm/armv8/mmu.h> |
| 13 | |
| 14 | #define SYSCNT_CTRL_BASE_ADDR 0xF07FC000 |
| 15 | #define SC_CNTCR_ENABLE BIT(0) |
| 16 | #define SC_CNTCR_HDBG BIT(1) |
| 17 | #define SC_CNTCR_FREQ0 BIT(8) |
| 18 | #define SC_CNTCR_FREQ1 BIT(9) |
| 19 | |
| 20 | /* System Counter register map */ |
| 21 | struct sctr_regs { |
| 22 | u32 cntcr; |
| 23 | u32 cntsr; |
| 24 | u32 cntcv1; |
| 25 | u32 cntcv2; |
| 26 | u32 resv1[4]; |
| 27 | u32 cntfid0; |
| 28 | u32 cntfid1; |
| 29 | u32 cntfid2; |
| 30 | u32 resv2[1001]; |
| 31 | u32 counterid[1]; |
| 32 | }; |
| 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | int print_cpuinfo(void) |
| 37 | { |
| 38 | struct npcm_gcr *gcr = (struct npcm_gcr *)NPCM_GCR_BA; |
| 39 | unsigned int val; |
| 40 | unsigned long mpidr_val; |
| 41 | |
| 42 | asm volatile("mrs %0, mpidr_el1" : "=r" (mpidr_val)); |
| 43 | |
| 44 | val = readl(&gcr->mdlr); |
| 45 | |
| 46 | printf("CPU-%lu: ", mpidr_val & 0x3); |
| 47 | |
| 48 | switch (val) { |
| 49 | case ARBEL_NPCM845: |
| 50 | printf("NPCM845 "); |
| 51 | break; |
| 52 | case ARBEL_NPCM830: |
| 53 | printf("NPCM830 "); |
| 54 | break; |
| 55 | case ARBEL_NPCM810: |
| 56 | printf("NPCM810 "); |
| 57 | break; |
| 58 | default: |
| 59 | printf("NPCM8XX "); |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | val = readl(&gcr->pdid); |
| 64 | switch (val) { |
| 65 | case ARBEL_Z1: |
| 66 | printf("Z1 @ "); |
| 67 | break; |
| 68 | case ARBEL_A1: |
| 69 | printf("A1 @ "); |
| 70 | break; |
| 71 | default: |
| 72 | printf("Unknown\n"); |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | int arch_cpu_init(void) |
| 80 | { |
| 81 | if (!IS_ENABLED(CONFIG_SYS_DCACHE_OFF)) { |
| 82 | /* Enable cache to speed up system running */ |
| 83 | if (get_sctlr() & CR_M) |
| 84 | return 0; |
| 85 | |
| 86 | icache_enable(); |
| 87 | __asm_invalidate_dcache_all(); |
| 88 | __asm_invalidate_tlb_all(); |
| 89 | set_sctlr(get_sctlr() | CR_C); |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static struct mm_region npcm_mem_map[1 + CONFIG_NR_DRAM_BANKS + 1] = { |
| 96 | { |
| 97 | /* DRAM */ |
| 98 | .phys = 0x0UL, |
| 99 | .virt = 0x0UL, |
| 100 | .size = 0x80000000UL, |
| 101 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 102 | PTE_BLOCK_INNER_SHARE |
| 103 | }, |
| 104 | { |
| 105 | .phys = 0x80000000UL, |
| 106 | .virt = 0x80000000UL, |
| 107 | .size = 0x80000000UL, |
| 108 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 109 | PTE_BLOCK_NON_SHARE | |
| 110 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 111 | }, |
| 112 | { |
| 113 | /* List terminator */ |
| 114 | 0, |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | struct mm_region *mem_map = npcm_mem_map; |
| 119 | |
| 120 | int timer_init(void) |
| 121 | { |
| 122 | struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR; |
| 123 | u32 cntfrq_el0; |
| 124 | |
| 125 | /* Enable system counter */ |
| 126 | __asm__ __volatile__("mrs %0, CNTFRQ_EL0\n\t" : "=r" (cntfrq_el0) : : "memory"); |
| 127 | writel(cntfrq_el0, &sctr->cntfid0); |
| 128 | clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1, |
| 129 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG); |
| 130 | |
| 131 | gd->arch.tbl = 0; |
| 132 | gd->arch.tbu = 0; |
| 133 | |
| 134 | return 0; |
| 135 | } |