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