blob: af594526094c5433a62d802bc10fa6e7edaee924 [file] [log] [blame]
Jim Liu147c0002022-09-27 16:45:15 +08001// 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 */
21struct 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
34DECLARE_GLOBAL_DATA_PTR;
35
36int 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;
Jim Liuc5cc4bc2023-07-04 16:00:14 +080071 case ARBEL_A2:
72 printf("A2 @ ");
73 break;
Jim Liu147c0002022-09-27 16:45:15 +080074 default:
75 printf("Unknown\n");
76 break;
77 }
78
79 return 0;
80}
81
82int arch_cpu_init(void)
83{
84 if (!IS_ENABLED(CONFIG_SYS_DCACHE_OFF)) {
85 /* Enable cache to speed up system running */
86 if (get_sctlr() & CR_M)
87 return 0;
88
89 icache_enable();
90 __asm_invalidate_dcache_all();
91 __asm_invalidate_tlb_all();
92 set_sctlr(get_sctlr() | CR_C);
93 }
94
95 return 0;
96}
97
Jim Liuc5cc4bc2023-07-04 16:00:14 +080098static struct mm_region npcm_mem_map[] = {
Jim Liu147c0002022-09-27 16:45:15 +080099 {
100 /* DRAM */
101 .phys = 0x0UL,
102 .virt = 0x0UL,
103 .size = 0x80000000UL,
104 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
105 PTE_BLOCK_INNER_SHARE
106 },
107 {
108 .phys = 0x80000000UL,
109 .virt = 0x80000000UL,
110 .size = 0x80000000UL,
111 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
112 PTE_BLOCK_NON_SHARE |
113 PTE_BLOCK_PXN | PTE_BLOCK_UXN
114 },
115 {
Jim Liuc5cc4bc2023-07-04 16:00:14 +0800116 .phys = 0x100000000UL,
117 .virt = 0x100000000UL,
118 .size = 0x80000000UL,
119 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
120 PTE_BLOCK_INNER_SHARE
121 },
122 {
Jim Liu147c0002022-09-27 16:45:15 +0800123 /* List terminator */
124 0,
125 }
126};
127
128struct mm_region *mem_map = npcm_mem_map;
129
130int timer_init(void)
131{
132 struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
133 u32 cntfrq_el0;
134
135 /* Enable system counter */
136 __asm__ __volatile__("mrs %0, CNTFRQ_EL0\n\t" : "=r" (cntfrq_el0) : : "memory");
137 writel(cntfrq_el0, &sctr->cntfid0);
138 clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
139 SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
140
141 gd->arch.tbl = 0;
142 gd->arch.tbu = 0;
143
144 return 0;
145}