blob: 79a54d1bc2590b845c0a6938ae07da84d5b786c3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk5c952cf2004-10-10 21:27:30 +00002/*
3 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
4 * Scott McNutt <smcnutt@psyent.com>
wdenk5c952cf2004-10-10 21:27:30 +00005 */
6
7#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -06008#include <command.h>
Thomas Choubcae80e2015-10-21 21:34:57 +08009#include <cpu.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -070010#include <cpu_func.h>
Thomas Choubcae80e2015-10-21 21:34:57 +080011#include <dm.h>
12#include <errno.h>
Simon Glass7fe32b32022-03-04 08:43:05 -070013#include <event.h>
Simon Glass691d7192020-05-10 11:40:02 -060014#include <init.h>
Simon Glass36bf4462019-11-14 12:57:42 -070015#include <irq_func.h>
Joachim Foersterf956ad92011-10-20 10:28:10 +020016#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060017#include <asm/global_data.h>
Simon Glasscd93d622020-05-10 11:40:13 -060018#include <asm/system.h>
wdenk5c952cf2004-10-10 21:27:30 +000019
Thomas Chou5ff10aa2014-08-22 11:36:47 +080020DECLARE_GLOBAL_DATA_PTR;
21
Thomas Chou5ff10aa2014-08-22 11:36:47 +080022#ifdef CONFIG_DISPLAY_CPUINFO
23int print_cpuinfo(void)
wdenk5c952cf2004-10-10 21:27:30 +000024{
Thomas Chouca844dd2015-10-14 08:43:31 +080025 printf("CPU: Nios-II\n");
26 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000027}
Thomas Chou5ff10aa2014-08-22 11:36:47 +080028#endif /* CONFIG_DISPLAY_CPUINFO */
wdenk5c952cf2004-10-10 21:27:30 +000029
Thomas Chou4909f0e2015-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 Glass09140112020-05-10 11:40:03 -060038int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
wdenk5c952cf2004-10-10 21:27:30 +000039{
Thomas Chou7a6a7d12010-08-16 10:49:44 +080040 disable_interrupts();
41 /* indirect call to go beyond 256MB limitation of toolchain */
Thomas Chou121e36d2015-10-09 09:43:52 +080042 nios2_callr(gd->arch.reset_addr);
Thomas Chou7a6a7d12010-08-16 10:49:44 +080043 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000044}
Joachim Foersterf956ad92011-10-20 10:28:10 +020045
Thomas Choub8112092015-10-06 14:09:19 +080046/*
47 * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
48 * exception address. Define CONFIG_ROM_STUBS to prevent
49 * the copy (e.g. exception in flash or in other
50 * softare/firmware component).
51 */
52#ifndef CONFIG_ROM_STUBS
53static void copy_exception_trampoline(void)
54{
55 extern int _except_start, _except_end;
56 void *except_target = (void *)gd->arch.exception_addr;
57
58 if (&_except_start != except_target) {
59 memcpy(except_target, &_except_start,
60 &_except_end - &_except_start);
61 flush_cache(gd->arch.exception_addr,
62 &_except_end - &_except_start);
63 }
64}
65#endif
66
Simon Glassf72d0d42023-08-21 21:16:56 -060067static int nios_cpu_setup(void)
Thomas Chou5ff10aa2014-08-22 11:36:47 +080068{
Thomas Choubcae80e2015-10-21 21:34:57 +080069 struct udevice *dev;
70 int ret;
71
Simon Glass3f603cb2016-02-11 13:23:26 -070072 ret = uclass_first_device_err(UCLASS_CPU, &dev);
Thomas Choubcae80e2015-10-21 21:34:57 +080073 if (ret)
74 return ret;
Thomas Choubcae80e2015-10-21 21:34:57 +080075
Tom Riniaa6e94d2022-11-16 13:10:37 -050076 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Thomas Choub8112092015-10-06 14:09:19 +080077#ifndef CONFIG_ROM_STUBS
78 copy_exception_trampoline();
79#endif
Thomas Chou5ff10aa2014-08-22 11:36:47 +080080
81 return 0;
82}
Simon Glassf72d0d42023-08-21 21:16:56 -060083EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, nios_cpu_setup);
Thomas Choubcae80e2015-10-21 21:34:57 +080084
Simon Glass961420f2020-01-26 22:06:27 -070085static int altera_nios2_get_desc(const struct udevice *dev, char *buf,
86 int size)
Thomas Choubcae80e2015-10-21 21:34:57 +080087{
88 const char *cpu_name = "Nios-II";
89
90 if (size < strlen(cpu_name))
91 return -ENOSPC;
92 strcpy(buf, cpu_name);
93
94 return 0;
95}
96
Simon Glass961420f2020-01-26 22:06:27 -070097static int altera_nios2_get_info(const struct udevice *dev,
98 struct cpu_info *info)
Thomas Choubcae80e2015-10-21 21:34:57 +080099{
100 info->cpu_freq = gd->cpu_clk;
101 info->features = (1 << CPU_FEAT_L1_CACHE) |
102 (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
103
104 return 0;
105}
106
Simon Glass961420f2020-01-26 22:06:27 -0700107static int altera_nios2_get_count(const struct udevice *dev)
Thomas Choubcae80e2015-10-21 21:34:57 +0800108{
109 return 1;
110}
111
112static int altera_nios2_probe(struct udevice *dev)
113{
114 const void *blob = gd->fdt_blob;
Simon Glasse160f7d2017-01-17 16:52:55 -0700115 int node = dev_of_offset(dev);
Thomas Choubcae80e2015-10-21 21:34:57 +0800116
117 gd->cpu_clk = fdtdec_get_int(blob, node,
118 "clock-frequency", 0);
119 gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
120 "dcache-line-size", 0);
121 gd->arch.icache_line_size = fdtdec_get_int(blob, node,
122 "icache-line-size", 0);
123 gd->arch.dcache_size = fdtdec_get_int(blob, node,
124 "dcache-size", 0);
125 gd->arch.icache_size = fdtdec_get_int(blob, node,
126 "icache-size", 0);
127 gd->arch.reset_addr = fdtdec_get_int(blob, node,
128 "altr,reset-addr", 0);
129 gd->arch.exception_addr = fdtdec_get_int(blob, node,
130 "altr,exception-addr", 0);
131 gd->arch.has_initda = fdtdec_get_int(blob, node,
132 "altr,has-initda", 0);
133 gd->arch.has_mmu = fdtdec_get_int(blob, node,
134 "altr,has-mmu", 0);
Thomas Chou1ce61cb2015-10-27 08:30:22 +0800135 gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
136 gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
Thomas Chou2de48232015-10-27 09:02:17 +0800137 gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
Thomas Choubcae80e2015-10-21 21:34:57 +0800138
139 return 0;
140}
141
142static const struct cpu_ops altera_nios2_ops = {
143 .get_desc = altera_nios2_get_desc,
144 .get_info = altera_nios2_get_info,
145 .get_count = altera_nios2_get_count,
146};
147
148static const struct udevice_id altera_nios2_ids[] = {
149 { .compatible = "altr,nios2-1.0" },
150 { .compatible = "altr,nios2-1.1" },
151 { }
152};
153
154U_BOOT_DRIVER(altera_nios2) = {
155 .name = "altera_nios2",
156 .id = UCLASS_CPU,
157 .of_match = altera_nios2_ids,
158 .probe = altera_nios2_probe,
159 .ops = &altera_nios2_ops,
160 .flags = DM_FLAG_PRE_RELOC,
161};
Simon Glassf1683aa2017-04-06 12:47:05 -0600162
163/* This is a dummy function on nios2 */
164int dram_init(void)
165{
166 return 0;
167}