blob: 9008db6aa512d61109e9cbc113d664c7fb3333ba [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>
Thomas Choubcae80e2015-10-21 21:34:57 +08008#include <cpu.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -07009#include <cpu_func.h>
Thomas Choubcae80e2015-10-21 21:34:57 +080010#include <dm.h>
11#include <errno.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glass36bf4462019-11-14 12:57:42 -070013#include <irq_func.h>
Joachim Foersterf956ad92011-10-20 10:28:10 +020014#include <asm/cache.h>
wdenk5c952cf2004-10-10 21:27:30 +000015
Thomas Chou5ff10aa2014-08-22 11:36:47 +080016DECLARE_GLOBAL_DATA_PTR;
17
Thomas Chou5ff10aa2014-08-22 11:36:47 +080018#ifdef CONFIG_DISPLAY_CPUINFO
19int print_cpuinfo(void)
wdenk5c952cf2004-10-10 21:27:30 +000020{
Thomas Chouca844dd2015-10-14 08:43:31 +080021 printf("CPU: Nios-II\n");
22 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000023}
Thomas Chou5ff10aa2014-08-22 11:36:47 +080024#endif /* CONFIG_DISPLAY_CPUINFO */
wdenk5c952cf2004-10-10 21:27:30 +000025
Thomas Chou4909f0e2015-12-16 16:07:06 +080026#ifdef CONFIG_ALTERA_SYSID
27int checkboard(void)
28{
29 display_sysid();
30 return 0;
31}
32#endif
33
Mike Frysinger882b7d72010-10-20 03:41:17 -040034int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk5c952cf2004-10-10 21:27:30 +000035{
Thomas Chou7a6a7d12010-08-16 10:49:44 +080036 disable_interrupts();
37 /* indirect call to go beyond 256MB limitation of toolchain */
Thomas Chou121e36d2015-10-09 09:43:52 +080038 nios2_callr(gd->arch.reset_addr);
Thomas Chou7a6a7d12010-08-16 10:49:44 +080039 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000040}
Joachim Foersterf956ad92011-10-20 10:28:10 +020041
Thomas Choub8112092015-10-06 14:09:19 +080042/*
43 * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
44 * exception address. Define CONFIG_ROM_STUBS to prevent
45 * the copy (e.g. exception in flash or in other
46 * softare/firmware component).
47 */
48#ifndef CONFIG_ROM_STUBS
49static void copy_exception_trampoline(void)
50{
51 extern int _except_start, _except_end;
52 void *except_target = (void *)gd->arch.exception_addr;
53
54 if (&_except_start != except_target) {
55 memcpy(except_target, &_except_start,
56 &_except_end - &_except_start);
57 flush_cache(gd->arch.exception_addr,
58 &_except_end - &_except_start);
59 }
60}
61#endif
62
Thomas Choubcae80e2015-10-21 21:34:57 +080063int arch_cpu_init_dm(void)
Thomas Chou5ff10aa2014-08-22 11:36:47 +080064{
Thomas Choubcae80e2015-10-21 21:34:57 +080065 struct udevice *dev;
66 int ret;
67
Simon Glass3f603cb2016-02-11 13:23:26 -070068 ret = uclass_first_device_err(UCLASS_CPU, &dev);
Thomas Choubcae80e2015-10-21 21:34:57 +080069 if (ret)
70 return ret;
Thomas Choubcae80e2015-10-21 21:34:57 +080071
Thomas Chou5ff10aa2014-08-22 11:36:47 +080072 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Thomas Choub8112092015-10-06 14:09:19 +080073#ifndef CONFIG_ROM_STUBS
74 copy_exception_trampoline();
75#endif
Thomas Chou5ff10aa2014-08-22 11:36:47 +080076
77 return 0;
78}
Thomas Choubcae80e2015-10-21 21:34:57 +080079
80static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
81{
82 const char *cpu_name = "Nios-II";
83
84 if (size < strlen(cpu_name))
85 return -ENOSPC;
86 strcpy(buf, cpu_name);
87
88 return 0;
89}
90
91static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
92{
93 info->cpu_freq = gd->cpu_clk;
94 info->features = (1 << CPU_FEAT_L1_CACHE) |
95 (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
96
97 return 0;
98}
99
100static int altera_nios2_get_count(struct udevice *dev)
101{
102 return 1;
103}
104
105static int altera_nios2_probe(struct udevice *dev)
106{
107 const void *blob = gd->fdt_blob;
Simon Glasse160f7d2017-01-17 16:52:55 -0700108 int node = dev_of_offset(dev);
Thomas Choubcae80e2015-10-21 21:34:57 +0800109
110 gd->cpu_clk = fdtdec_get_int(blob, node,
111 "clock-frequency", 0);
112 gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
113 "dcache-line-size", 0);
114 gd->arch.icache_line_size = fdtdec_get_int(blob, node,
115 "icache-line-size", 0);
116 gd->arch.dcache_size = fdtdec_get_int(blob, node,
117 "dcache-size", 0);
118 gd->arch.icache_size = fdtdec_get_int(blob, node,
119 "icache-size", 0);
120 gd->arch.reset_addr = fdtdec_get_int(blob, node,
121 "altr,reset-addr", 0);
122 gd->arch.exception_addr = fdtdec_get_int(blob, node,
123 "altr,exception-addr", 0);
124 gd->arch.has_initda = fdtdec_get_int(blob, node,
125 "altr,has-initda", 0);
126 gd->arch.has_mmu = fdtdec_get_int(blob, node,
127 "altr,has-mmu", 0);
Thomas Chou1ce61cb2015-10-27 08:30:22 +0800128 gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
129 gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
Thomas Chou2de48232015-10-27 09:02:17 +0800130 gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
Thomas Choubcae80e2015-10-21 21:34:57 +0800131
132 return 0;
133}
134
135static const struct cpu_ops altera_nios2_ops = {
136 .get_desc = altera_nios2_get_desc,
137 .get_info = altera_nios2_get_info,
138 .get_count = altera_nios2_get_count,
139};
140
141static const struct udevice_id altera_nios2_ids[] = {
142 { .compatible = "altr,nios2-1.0" },
143 { .compatible = "altr,nios2-1.1" },
144 { }
145};
146
147U_BOOT_DRIVER(altera_nios2) = {
148 .name = "altera_nios2",
149 .id = UCLASS_CPU,
150 .of_match = altera_nios2_ids,
151 .probe = altera_nios2_probe,
152 .ops = &altera_nios2_ops,
153 .flags = DM_FLAG_PRE_RELOC,
154};
Simon Glassf1683aa2017-04-06 12:47:05 -0600155
156/* This is a dummy function on nios2 */
157int dram_init(void)
158{
159 return 0;
160}