blob: 1fc79213e202e6da084ddf76fd1637a2518e567c [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>
9#include <dm.h>
10#include <errno.h>
Joachim Foersterf956ad92011-10-20 10:28:10 +020011#include <asm/cache.h>
wdenk5c952cf2004-10-10 21:27:30 +000012
Thomas Chou5ff10aa2014-08-22 11:36:47 +080013DECLARE_GLOBAL_DATA_PTR;
14
Thomas Chou5ff10aa2014-08-22 11:36:47 +080015#ifdef CONFIG_DISPLAY_CPUINFO
16int print_cpuinfo(void)
wdenk5c952cf2004-10-10 21:27:30 +000017{
Thomas Chouca844dd2015-10-14 08:43:31 +080018 printf("CPU: Nios-II\n");
19 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000020}
Thomas Chou5ff10aa2014-08-22 11:36:47 +080021#endif /* CONFIG_DISPLAY_CPUINFO */
wdenk5c952cf2004-10-10 21:27:30 +000022
Thomas Chou4909f0e2015-12-16 16:07:06 +080023#ifdef CONFIG_ALTERA_SYSID
24int checkboard(void)
25{
26 display_sysid();
27 return 0;
28}
29#endif
30
Mike Frysinger882b7d72010-10-20 03:41:17 -040031int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk5c952cf2004-10-10 21:27:30 +000032{
Thomas Chou7a6a7d12010-08-16 10:49:44 +080033 disable_interrupts();
34 /* indirect call to go beyond 256MB limitation of toolchain */
Thomas Chou121e36d2015-10-09 09:43:52 +080035 nios2_callr(gd->arch.reset_addr);
Thomas Chou7a6a7d12010-08-16 10:49:44 +080036 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000037}
Joachim Foersterf956ad92011-10-20 10:28:10 +020038
Thomas Choub8112092015-10-06 14:09:19 +080039/*
40 * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
41 * exception address. Define CONFIG_ROM_STUBS to prevent
42 * the copy (e.g. exception in flash or in other
43 * softare/firmware component).
44 */
45#ifndef CONFIG_ROM_STUBS
46static void copy_exception_trampoline(void)
47{
48 extern int _except_start, _except_end;
49 void *except_target = (void *)gd->arch.exception_addr;
50
51 if (&_except_start != except_target) {
52 memcpy(except_target, &_except_start,
53 &_except_end - &_except_start);
54 flush_cache(gd->arch.exception_addr,
55 &_except_end - &_except_start);
56 }
57}
58#endif
59
Thomas Choubcae80e2015-10-21 21:34:57 +080060int arch_cpu_init_dm(void)
Thomas Chou5ff10aa2014-08-22 11:36:47 +080061{
Thomas Choubcae80e2015-10-21 21:34:57 +080062 struct udevice *dev;
63 int ret;
64
Simon Glass3f603cb2016-02-11 13:23:26 -070065 ret = uclass_first_device_err(UCLASS_CPU, &dev);
Thomas Choubcae80e2015-10-21 21:34:57 +080066 if (ret)
67 return ret;
Thomas Choubcae80e2015-10-21 21:34:57 +080068
Thomas Chou5ff10aa2014-08-22 11:36:47 +080069 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Thomas Choub8112092015-10-06 14:09:19 +080070#ifndef CONFIG_ROM_STUBS
71 copy_exception_trampoline();
72#endif
Thomas Chou5ff10aa2014-08-22 11:36:47 +080073
74 return 0;
75}
Thomas Choubcae80e2015-10-21 21:34:57 +080076
77static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
78{
79 const char *cpu_name = "Nios-II";
80
81 if (size < strlen(cpu_name))
82 return -ENOSPC;
83 strcpy(buf, cpu_name);
84
85 return 0;
86}
87
88static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
89{
90 info->cpu_freq = gd->cpu_clk;
91 info->features = (1 << CPU_FEAT_L1_CACHE) |
92 (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
93
94 return 0;
95}
96
97static int altera_nios2_get_count(struct udevice *dev)
98{
99 return 1;
100}
101
102static int altera_nios2_probe(struct udevice *dev)
103{
104 const void *blob = gd->fdt_blob;
Simon Glasse160f7d2017-01-17 16:52:55 -0700105 int node = dev_of_offset(dev);
Thomas Choubcae80e2015-10-21 21:34:57 +0800106
107 gd->cpu_clk = fdtdec_get_int(blob, node,
108 "clock-frequency", 0);
109 gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
110 "dcache-line-size", 0);
111 gd->arch.icache_line_size = fdtdec_get_int(blob, node,
112 "icache-line-size", 0);
113 gd->arch.dcache_size = fdtdec_get_int(blob, node,
114 "dcache-size", 0);
115 gd->arch.icache_size = fdtdec_get_int(blob, node,
116 "icache-size", 0);
117 gd->arch.reset_addr = fdtdec_get_int(blob, node,
118 "altr,reset-addr", 0);
119 gd->arch.exception_addr = fdtdec_get_int(blob, node,
120 "altr,exception-addr", 0);
121 gd->arch.has_initda = fdtdec_get_int(blob, node,
122 "altr,has-initda", 0);
123 gd->arch.has_mmu = fdtdec_get_int(blob, node,
124 "altr,has-mmu", 0);
Thomas Chou1ce61cb2015-10-27 08:30:22 +0800125 gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
126 gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
Thomas Chou2de48232015-10-27 09:02:17 +0800127 gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
Thomas Choubcae80e2015-10-21 21:34:57 +0800128
129 return 0;
130}
131
132static const struct cpu_ops altera_nios2_ops = {
133 .get_desc = altera_nios2_get_desc,
134 .get_info = altera_nios2_get_info,
135 .get_count = altera_nios2_get_count,
136};
137
138static const struct udevice_id altera_nios2_ids[] = {
139 { .compatible = "altr,nios2-1.0" },
140 { .compatible = "altr,nios2-1.1" },
141 { }
142};
143
144U_BOOT_DRIVER(altera_nios2) = {
145 .name = "altera_nios2",
146 .id = UCLASS_CPU,
147 .of_match = altera_nios2_ids,
148 .probe = altera_nios2_probe,
149 .ops = &altera_nios2_ops,
150 .flags = DM_FLAG_PRE_RELOC,
151};
Simon Glassf1683aa2017-04-06 12:47:05 -0600152
153/* This is a dummy function on nios2 */
154int dram_init(void)
155{
156 return 0;
157}