]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
5c952cf0 WD |
2 | /* |
3 | * (C) Copyright 2004, Psyent Corporation <www.psyent.com> | |
4 | * Scott McNutt <[email protected]> | |
5c952cf0 WD |
5 | */ |
6 | ||
7 | #include <common.h> | |
09140113 | 8 | #include <command.h> |
bcae80e9 | 9 | #include <cpu.h> |
1eb69ae4 | 10 | #include <cpu_func.h> |
bcae80e9 TC |
11 | #include <dm.h> |
12 | #include <errno.h> | |
691d719d | 13 | #include <init.h> |
36bf446b | 14 | #include <irq_func.h> |
f956ad98 | 15 | #include <asm/cache.h> |
5c952cf0 | 16 | |
5ff10aa7 TC |
17 | DECLARE_GLOBAL_DATA_PTR; |
18 | ||
5ff10aa7 TC |
19 | #ifdef CONFIG_DISPLAY_CPUINFO |
20 | int print_cpuinfo(void) | |
5c952cf0 | 21 | { |
ca844dd8 TC |
22 | printf("CPU: Nios-II\n"); |
23 | return 0; | |
5c952cf0 | 24 | } |
5ff10aa7 | 25 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
5c952cf0 | 26 | |
4909f0e1 TC |
27 | #ifdef CONFIG_ALTERA_SYSID |
28 | int checkboard(void) | |
29 | { | |
30 | display_sysid(); | |
31 | return 0; | |
32 | } | |
33 | #endif | |
34 | ||
09140113 | 35 | int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
5c952cf0 | 36 | { |
7a6a7d10 TC |
37 | disable_interrupts(); |
38 | /* indirect call to go beyond 256MB limitation of toolchain */ | |
121e36da | 39 | nios2_callr(gd->arch.reset_addr); |
7a6a7d10 | 40 | return 0; |
5c952cf0 | 41 | } |
f956ad98 | 42 | |
b8112091 TC |
43 | /* |
44 | * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the | |
45 | * exception address. Define CONFIG_ROM_STUBS to prevent | |
46 | * the copy (e.g. exception in flash or in other | |
47 | * softare/firmware component). | |
48 | */ | |
49 | #ifndef CONFIG_ROM_STUBS | |
50 | static void copy_exception_trampoline(void) | |
51 | { | |
52 | extern int _except_start, _except_end; | |
53 | void *except_target = (void *)gd->arch.exception_addr; | |
54 | ||
55 | if (&_except_start != except_target) { | |
56 | memcpy(except_target, &_except_start, | |
57 | &_except_end - &_except_start); | |
58 | flush_cache(gd->arch.exception_addr, | |
59 | &_except_end - &_except_start); | |
60 | } | |
61 | } | |
62 | #endif | |
63 | ||
bcae80e9 | 64 | int arch_cpu_init_dm(void) |
5ff10aa7 | 65 | { |
bcae80e9 TC |
66 | struct udevice *dev; |
67 | int ret; | |
68 | ||
3f603cbb | 69 | ret = uclass_first_device_err(UCLASS_CPU, &dev); |
bcae80e9 TC |
70 | if (ret) |
71 | return ret; | |
bcae80e9 | 72 | |
5ff10aa7 | 73 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
b8112091 TC |
74 | #ifndef CONFIG_ROM_STUBS |
75 | copy_exception_trampoline(); | |
76 | #endif | |
5ff10aa7 TC |
77 | |
78 | return 0; | |
79 | } | |
bcae80e9 TC |
80 | |
81 | static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size) | |
82 | { | |
83 | const char *cpu_name = "Nios-II"; | |
84 | ||
85 | if (size < strlen(cpu_name)) | |
86 | return -ENOSPC; | |
87 | strcpy(buf, cpu_name); | |
88 | ||
89 | return 0; | |
90 | } | |
91 | ||
92 | static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info) | |
93 | { | |
94 | info->cpu_freq = gd->cpu_clk; | |
95 | info->features = (1 << CPU_FEAT_L1_CACHE) | | |
96 | (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0); | |
97 | ||
98 | return 0; | |
99 | } | |
100 | ||
101 | static int altera_nios2_get_count(struct udevice *dev) | |
102 | { | |
103 | return 1; | |
104 | } | |
105 | ||
106 | static int altera_nios2_probe(struct udevice *dev) | |
107 | { | |
108 | const void *blob = gd->fdt_blob; | |
e160f7d4 | 109 | int node = dev_of_offset(dev); |
bcae80e9 TC |
110 | |
111 | gd->cpu_clk = fdtdec_get_int(blob, node, | |
112 | "clock-frequency", 0); | |
113 | gd->arch.dcache_line_size = fdtdec_get_int(blob, node, | |
114 | "dcache-line-size", 0); | |
115 | gd->arch.icache_line_size = fdtdec_get_int(blob, node, | |
116 | "icache-line-size", 0); | |
117 | gd->arch.dcache_size = fdtdec_get_int(blob, node, | |
118 | "dcache-size", 0); | |
119 | gd->arch.icache_size = fdtdec_get_int(blob, node, | |
120 | "icache-size", 0); | |
121 | gd->arch.reset_addr = fdtdec_get_int(blob, node, | |
122 | "altr,reset-addr", 0); | |
123 | gd->arch.exception_addr = fdtdec_get_int(blob, node, | |
124 | "altr,exception-addr", 0); | |
125 | gd->arch.has_initda = fdtdec_get_int(blob, node, | |
126 | "altr,has-initda", 0); | |
127 | gd->arch.has_mmu = fdtdec_get_int(blob, node, | |
128 | "altr,has-mmu", 0); | |
1ce61cbb TC |
129 | gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000; |
130 | gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000; | |
2de4823d | 131 | gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff; |
bcae80e9 TC |
132 | |
133 | return 0; | |
134 | } | |
135 | ||
136 | static const struct cpu_ops altera_nios2_ops = { | |
137 | .get_desc = altera_nios2_get_desc, | |
138 | .get_info = altera_nios2_get_info, | |
139 | .get_count = altera_nios2_get_count, | |
140 | }; | |
141 | ||
142 | static const struct udevice_id altera_nios2_ids[] = { | |
143 | { .compatible = "altr,nios2-1.0" }, | |
144 | { .compatible = "altr,nios2-1.1" }, | |
145 | { } | |
146 | }; | |
147 | ||
148 | U_BOOT_DRIVER(altera_nios2) = { | |
149 | .name = "altera_nios2", | |
150 | .id = UCLASS_CPU, | |
151 | .of_match = altera_nios2_ids, | |
152 | .probe = altera_nios2_probe, | |
153 | .ops = &altera_nios2_ops, | |
154 | .flags = DM_FLAG_PRE_RELOC, | |
155 | }; | |
f1683aa7 SG |
156 | |
157 | /* This is a dummy function on nios2 */ | |
158 | int dram_init(void) | |
159 | { | |
160 | return 0; | |
161 | } |