blob: 37ffa8f4a43223af329c1170b85c1506162ff339 [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
7#include <common.h>
Thomas Chouc6170262015-10-21 21:34:57 +08008#include <cpu.h>
Simon Glass63334482019-11-14 12:57:39 -07009#include <cpu_func.h>
Thomas Chouc6170262015-10-21 21:34:57 +080010#include <dm.h>
11#include <errno.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070012#include <irq_func.h>
Joachim Foersterf2924742011-10-20 10:28:10 +020013#include <asm/cache.h>
wdenkef3386f2004-10-10 21:27:30 +000014
Thomas Choucce3e752014-08-22 11:36:47 +080015DECLARE_GLOBAL_DATA_PTR;
16
Thomas Choucce3e752014-08-22 11:36:47 +080017#ifdef CONFIG_DISPLAY_CPUINFO
18int print_cpuinfo(void)
wdenkef3386f2004-10-10 21:27:30 +000019{
Thomas Chou36b9c9a2015-10-14 08:43:31 +080020 printf("CPU: Nios-II\n");
21 return 0;
wdenkef3386f2004-10-10 21:27:30 +000022}
Thomas Choucce3e752014-08-22 11:36:47 +080023#endif /* CONFIG_DISPLAY_CPUINFO */
wdenkef3386f2004-10-10 21:27:30 +000024
Thomas Chou48b42e62015-12-16 16:07:06 +080025#ifdef CONFIG_ALTERA_SYSID
26int checkboard(void)
27{
28 display_sysid();
29 return 0;
30}
31#endif
32
Mike Frysinger6d1f6982010-10-20 03:41:17 -040033int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkef3386f2004-10-10 21:27:30 +000034{
Thomas Chou5975e792010-08-16 10:49:44 +080035 disable_interrupts();
36 /* indirect call to go beyond 256MB limitation of toolchain */
Thomas Chou72b61982015-10-09 09:43:52 +080037 nios2_callr(gd->arch.reset_addr);
Thomas Chou5975e792010-08-16 10:49:44 +080038 return 0;
wdenkef3386f2004-10-10 21:27:30 +000039}
Joachim Foersterf2924742011-10-20 10:28:10 +020040
Thomas Chou93f96462015-10-06 14:09:19 +080041/*
42 * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
43 * exception address. Define CONFIG_ROM_STUBS to prevent
44 * the copy (e.g. exception in flash or in other
45 * softare/firmware component).
46 */
47#ifndef CONFIG_ROM_STUBS
48static void copy_exception_trampoline(void)
49{
50 extern int _except_start, _except_end;
51 void *except_target = (void *)gd->arch.exception_addr;
52
53 if (&_except_start != except_target) {
54 memcpy(except_target, &_except_start,
55 &_except_end - &_except_start);
56 flush_cache(gd->arch.exception_addr,
57 &_except_end - &_except_start);
58 }
59}
60#endif
61
Thomas Chouc6170262015-10-21 21:34:57 +080062int arch_cpu_init_dm(void)
Thomas Choucce3e752014-08-22 11:36:47 +080063{
Thomas Chouc6170262015-10-21 21:34:57 +080064 struct udevice *dev;
65 int ret;
66
Simon Glassc7298e72016-02-11 13:23:26 -070067 ret = uclass_first_device_err(UCLASS_CPU, &dev);
Thomas Chouc6170262015-10-21 21:34:57 +080068 if (ret)
69 return ret;
Thomas Chouc6170262015-10-21 21:34:57 +080070
Thomas Choucce3e752014-08-22 11:36:47 +080071 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Thomas Chou93f96462015-10-06 14:09:19 +080072#ifndef CONFIG_ROM_STUBS
73 copy_exception_trampoline();
74#endif
Thomas Choucce3e752014-08-22 11:36:47 +080075
76 return 0;
77}
Thomas Chouc6170262015-10-21 21:34:57 +080078
79static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
80{
81 const char *cpu_name = "Nios-II";
82
83 if (size < strlen(cpu_name))
84 return -ENOSPC;
85 strcpy(buf, cpu_name);
86
87 return 0;
88}
89
90static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
91{
92 info->cpu_freq = gd->cpu_clk;
93 info->features = (1 << CPU_FEAT_L1_CACHE) |
94 (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
95
96 return 0;
97}
98
99static int altera_nios2_get_count(struct udevice *dev)
100{
101 return 1;
102}
103
104static int altera_nios2_probe(struct udevice *dev)
105{
106 const void *blob = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700107 int node = dev_of_offset(dev);
Thomas Chouc6170262015-10-21 21:34:57 +0800108
109 gd->cpu_clk = fdtdec_get_int(blob, node,
110 "clock-frequency", 0);
111 gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
112 "dcache-line-size", 0);
113 gd->arch.icache_line_size = fdtdec_get_int(blob, node,
114 "icache-line-size", 0);
115 gd->arch.dcache_size = fdtdec_get_int(blob, node,
116 "dcache-size", 0);
117 gd->arch.icache_size = fdtdec_get_int(blob, node,
118 "icache-size", 0);
119 gd->arch.reset_addr = fdtdec_get_int(blob, node,
120 "altr,reset-addr", 0);
121 gd->arch.exception_addr = fdtdec_get_int(blob, node,
122 "altr,exception-addr", 0);
123 gd->arch.has_initda = fdtdec_get_int(blob, node,
124 "altr,has-initda", 0);
125 gd->arch.has_mmu = fdtdec_get_int(blob, node,
126 "altr,has-mmu", 0);
Thomas Chouebf8aac2015-10-27 08:30:22 +0800127 gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
128 gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
Thomas Chou043a4972015-10-27 09:02:17 +0800129 gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
Thomas Chouc6170262015-10-21 21:34:57 +0800130
131 return 0;
132}
133
134static const struct cpu_ops altera_nios2_ops = {
135 .get_desc = altera_nios2_get_desc,
136 .get_info = altera_nios2_get_info,
137 .get_count = altera_nios2_get_count,
138};
139
140static const struct udevice_id altera_nios2_ids[] = {
141 { .compatible = "altr,nios2-1.0" },
142 { .compatible = "altr,nios2-1.1" },
143 { }
144};
145
146U_BOOT_DRIVER(altera_nios2) = {
147 .name = "altera_nios2",
148 .id = UCLASS_CPU,
149 .of_match = altera_nios2_ids,
150 .probe = altera_nios2_probe,
151 .ops = &altera_nios2_ops,
152 .flags = DM_FLAG_PRE_RELOC,
153};
Simon Glassd35f3382017-04-06 12:47:05 -0600154
155/* This is a dummy function on nios2 */
156int dram_init(void)
157{
158 return 0;
159}