blob: 792fa01ab9e2d88578db1b933dd7a7de73d96687 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkef3386f2004-10-10 21:27:30 +00002/*
3 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
4 * Scott McNutt <smcnutt@psyent.com>
wdenkef3386f2004-10-10 21:27:30 +00005 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <config.h>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Thomas Chouc6170262015-10-21 21:34:57 +08009#include <cpu.h>
Simon Glass63334482019-11-14 12:57:39 -070010#include <cpu_func.h>
Thomas Chouc6170262015-10-21 21:34:57 +080011#include <dm.h>
12#include <errno.h>
Simon Glassfc557362022-03-04 08:43:05 -070013#include <event.h>
Simon Glass97589732020-05-10 11:40:02 -060014#include <init.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070015#include <irq_func.h>
Joachim Foersterf2924742011-10-20 10:28:10 +020016#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060018#include <asm/system.h>
wdenkef3386f2004-10-10 21:27:30 +000019
Thomas Choucce3e752014-08-22 11:36:47 +080020DECLARE_GLOBAL_DATA_PTR;
21
Thomas Choucce3e752014-08-22 11:36:47 +080022#ifdef CONFIG_DISPLAY_CPUINFO
23int print_cpuinfo(void)
wdenkef3386f2004-10-10 21:27:30 +000024{
Thomas Chou36b9c9a2015-10-14 08:43:31 +080025 printf("CPU: Nios-II\n");
26 return 0;
wdenkef3386f2004-10-10 21:27:30 +000027}
Thomas Choucce3e752014-08-22 11:36:47 +080028#endif /* CONFIG_DISPLAY_CPUINFO */
wdenkef3386f2004-10-10 21:27:30 +000029
Thomas Chou48b42e62015-12-16 16:07:06 +080030#ifdef CONFIG_ALTERA_SYSID
31int checkboard(void)
32{
33 display_sysid();
34 return 0;
35}
36#endif
37
Simon Glassb5e687e2023-12-15 20:14:08 -070038void reset_cpu(void)
wdenkef3386f2004-10-10 21:27:30 +000039{
Thomas Chou5975e792010-08-16 10:49:44 +080040 disable_interrupts();
41 /* indirect call to go beyond 256MB limitation of toolchain */
Thomas Chou72b61982015-10-09 09:43:52 +080042 nios2_callr(gd->arch.reset_addr);
Simon Glassb5e687e2023-12-15 20:14:08 -070043}
44
45int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
46{
47 reset_cpu();
48
Thomas Chou5975e792010-08-16 10:49:44 +080049 return 0;
wdenkef3386f2004-10-10 21:27:30 +000050}
Joachim Foersterf2924742011-10-20 10:28:10 +020051
Thomas Chou93f96462015-10-06 14:09:19 +080052/*
53 * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
54 * exception address. Define CONFIG_ROM_STUBS to prevent
55 * the copy (e.g. exception in flash or in other
56 * softare/firmware component).
57 */
58#ifndef CONFIG_ROM_STUBS
59static void copy_exception_trampoline(void)
60{
61 extern int _except_start, _except_end;
62 void *except_target = (void *)gd->arch.exception_addr;
63
64 if (&_except_start != except_target) {
65 memcpy(except_target, &_except_start,
66 &_except_end - &_except_start);
67 flush_cache(gd->arch.exception_addr,
68 &_except_end - &_except_start);
69 }
70}
71#endif
72
Simon Glassb8357c12023-08-21 21:16:56 -060073static int nios_cpu_setup(void)
Thomas Choucce3e752014-08-22 11:36:47 +080074{
Thomas Chouc6170262015-10-21 21:34:57 +080075 struct udevice *dev;
76 int ret;
77
Simon Glassc7298e72016-02-11 13:23:26 -070078 ret = uclass_first_device_err(UCLASS_CPU, &dev);
Thomas Chouc6170262015-10-21 21:34:57 +080079 if (ret)
80 return ret;
Thomas Chouc6170262015-10-21 21:34:57 +080081
Tom Rinibb4dd962022-11-16 13:10:37 -050082 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Thomas Chou93f96462015-10-06 14:09:19 +080083#ifndef CONFIG_ROM_STUBS
84 copy_exception_trampoline();
85#endif
Thomas Choucce3e752014-08-22 11:36:47 +080086
87 return 0;
88}
Simon Glassb8357c12023-08-21 21:16:56 -060089EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, nios_cpu_setup);
Thomas Chouc6170262015-10-21 21:34:57 +080090
Simon Glass791fa452020-01-26 22:06:27 -070091static int altera_nios2_get_desc(const struct udevice *dev, char *buf,
92 int size)
Thomas Chouc6170262015-10-21 21:34:57 +080093{
94 const char *cpu_name = "Nios-II";
95
96 if (size < strlen(cpu_name))
97 return -ENOSPC;
98 strcpy(buf, cpu_name);
99
100 return 0;
101}
102
Simon Glass791fa452020-01-26 22:06:27 -0700103static int altera_nios2_get_info(const struct udevice *dev,
104 struct cpu_info *info)
Thomas Chouc6170262015-10-21 21:34:57 +0800105{
106 info->cpu_freq = gd->cpu_clk;
107 info->features = (1 << CPU_FEAT_L1_CACHE) |
108 (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
109
110 return 0;
111}
112
Simon Glass791fa452020-01-26 22:06:27 -0700113static int altera_nios2_get_count(const struct udevice *dev)
Thomas Chouc6170262015-10-21 21:34:57 +0800114{
115 return 1;
116}
117
118static int altera_nios2_probe(struct udevice *dev)
119{
120 const void *blob = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700121 int node = dev_of_offset(dev);
Thomas Chouc6170262015-10-21 21:34:57 +0800122
123 gd->cpu_clk = fdtdec_get_int(blob, node,
124 "clock-frequency", 0);
125 gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
126 "dcache-line-size", 0);
127 gd->arch.icache_line_size = fdtdec_get_int(blob, node,
128 "icache-line-size", 0);
129 gd->arch.dcache_size = fdtdec_get_int(blob, node,
130 "dcache-size", 0);
131 gd->arch.icache_size = fdtdec_get_int(blob, node,
132 "icache-size", 0);
133 gd->arch.reset_addr = fdtdec_get_int(blob, node,
134 "altr,reset-addr", 0);
135 gd->arch.exception_addr = fdtdec_get_int(blob, node,
136 "altr,exception-addr", 0);
137 gd->arch.has_initda = fdtdec_get_int(blob, node,
138 "altr,has-initda", 0);
139 gd->arch.has_mmu = fdtdec_get_int(blob, node,
140 "altr,has-mmu", 0);
Thomas Chouebf8aac2015-10-27 08:30:22 +0800141 gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
142 gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
Thomas Chou043a4972015-10-27 09:02:17 +0800143 gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
Thomas Chouc6170262015-10-21 21:34:57 +0800144
145 return 0;
146}
147
148static const struct cpu_ops altera_nios2_ops = {
149 .get_desc = altera_nios2_get_desc,
150 .get_info = altera_nios2_get_info,
151 .get_count = altera_nios2_get_count,
152};
153
154static const struct udevice_id altera_nios2_ids[] = {
155 { .compatible = "altr,nios2-1.0" },
156 { .compatible = "altr,nios2-1.1" },
157 { }
158};
159
160U_BOOT_DRIVER(altera_nios2) = {
161 .name = "altera_nios2",
162 .id = UCLASS_CPU,
163 .of_match = altera_nios2_ids,
164 .probe = altera_nios2_probe,
165 .ops = &altera_nios2_ops,
166 .flags = DM_FLAG_PRE_RELOC,
167};
Simon Glassd35f3382017-04-06 12:47:05 -0600168
169/* This is a dummy function on nios2 */
170int dram_init(void)
171{
172 return 0;
173}