blob: f6d5cd399a3acea273007dfe0a28b6ff44c5aebb [file] [log] [blame]
wdenk5c952cf2004-10-10 21:27:30 +00001/*
2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk5c952cf2004-10-10 21:27:30 +00006 */
7
8#include <common.h>
Thomas Choubcae80e2015-10-21 21:34:57 +08009#include <cpu.h>
10#include <dm.h>
11#include <errno.h>
Joachim Foersterf956ad92011-10-20 10:28:10 +020012#include <asm/cache.h>
wdenk5c952cf2004-10-10 21:27:30 +000013
Thomas Chou5ff10aa2014-08-22 11:36:47 +080014DECLARE_GLOBAL_DATA_PTR;
15
Thomas Chou5ff10aa2014-08-22 11:36:47 +080016#ifdef CONFIG_DISPLAY_CPUINFO
17int print_cpuinfo(void)
wdenk5c952cf2004-10-10 21:27:30 +000018{
Thomas Chouca844dd2015-10-14 08:43:31 +080019 printf("CPU: Nios-II\n");
20 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000021}
Thomas Chou5ff10aa2014-08-22 11:36:47 +080022#endif /* CONFIG_DISPLAY_CPUINFO */
wdenk5c952cf2004-10-10 21:27:30 +000023
Mike Frysinger882b7d72010-10-20 03:41:17 -040024int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk5c952cf2004-10-10 21:27:30 +000025{
Thomas Chou7a6a7d12010-08-16 10:49:44 +080026 disable_interrupts();
27 /* indirect call to go beyond 256MB limitation of toolchain */
Thomas Chou121e36d2015-10-09 09:43:52 +080028 nios2_callr(gd->arch.reset_addr);
Thomas Chou7a6a7d12010-08-16 10:49:44 +080029 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000030}
Joachim Foersterf956ad92011-10-20 10:28:10 +020031
Thomas Choub8112092015-10-06 14:09:19 +080032/*
33 * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
34 * exception address. Define CONFIG_ROM_STUBS to prevent
35 * the copy (e.g. exception in flash or in other
36 * softare/firmware component).
37 */
38#ifndef CONFIG_ROM_STUBS
39static void copy_exception_trampoline(void)
40{
41 extern int _except_start, _except_end;
42 void *except_target = (void *)gd->arch.exception_addr;
43
44 if (&_except_start != except_target) {
45 memcpy(except_target, &_except_start,
46 &_except_end - &_except_start);
47 flush_cache(gd->arch.exception_addr,
48 &_except_end - &_except_start);
49 }
50}
51#endif
52
Thomas Choubcae80e2015-10-21 21:34:57 +080053int arch_cpu_init_dm(void)
Thomas Chou5ff10aa2014-08-22 11:36:47 +080054{
Thomas Choubcae80e2015-10-21 21:34:57 +080055 struct udevice *dev;
56 int ret;
57
58 ret = uclass_first_device(UCLASS_CPU, &dev);
59 if (ret)
60 return ret;
61 if (!dev)
62 return -ENODEV;
63
Thomas Chou5ff10aa2014-08-22 11:36:47 +080064 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Thomas Choub8112092015-10-06 14:09:19 +080065#ifndef CONFIG_ROM_STUBS
66 copy_exception_trampoline();
67#endif
Thomas Chou5ff10aa2014-08-22 11:36:47 +080068
69 return 0;
70}
Thomas Choubcae80e2015-10-21 21:34:57 +080071
72static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
73{
74 const char *cpu_name = "Nios-II";
75
76 if (size < strlen(cpu_name))
77 return -ENOSPC;
78 strcpy(buf, cpu_name);
79
80 return 0;
81}
82
83static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
84{
85 info->cpu_freq = gd->cpu_clk;
86 info->features = (1 << CPU_FEAT_L1_CACHE) |
87 (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
88
89 return 0;
90}
91
92static int altera_nios2_get_count(struct udevice *dev)
93{
94 return 1;
95}
96
97static int altera_nios2_probe(struct udevice *dev)
98{
99 const void *blob = gd->fdt_blob;
100 int node = dev->of_offset;
101
102 gd->cpu_clk = fdtdec_get_int(blob, node,
103 "clock-frequency", 0);
104 gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
105 "dcache-line-size", 0);
106 gd->arch.icache_line_size = fdtdec_get_int(blob, node,
107 "icache-line-size", 0);
108 gd->arch.dcache_size = fdtdec_get_int(blob, node,
109 "dcache-size", 0);
110 gd->arch.icache_size = fdtdec_get_int(blob, node,
111 "icache-size", 0);
112 gd->arch.reset_addr = fdtdec_get_int(blob, node,
113 "altr,reset-addr", 0);
114 gd->arch.exception_addr = fdtdec_get_int(blob, node,
115 "altr,exception-addr", 0);
116 gd->arch.has_initda = fdtdec_get_int(blob, node,
117 "altr,has-initda", 0);
118 gd->arch.has_mmu = fdtdec_get_int(blob, node,
119 "altr,has-mmu", 0);
Thomas Chou1ce61cb2015-10-27 08:30:22 +0800120 gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
121 gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
Thomas Chou2de48232015-10-27 09:02:17 +0800122 gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
Thomas Choubcae80e2015-10-21 21:34:57 +0800123
124 return 0;
125}
126
127static const struct cpu_ops altera_nios2_ops = {
128 .get_desc = altera_nios2_get_desc,
129 .get_info = altera_nios2_get_info,
130 .get_count = altera_nios2_get_count,
131};
132
133static const struct udevice_id altera_nios2_ids[] = {
134 { .compatible = "altr,nios2-1.0" },
135 { .compatible = "altr,nios2-1.1" },
136 { }
137};
138
139U_BOOT_DRIVER(altera_nios2) = {
140 .name = "altera_nios2",
141 .id = UCLASS_CPU,
142 .of_match = altera_nios2_ids,
143 .probe = altera_nios2_probe,
144 .ops = &altera_nios2_ops,
145 .flags = DM_FLAG_PRE_RELOC,
146};