Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2004, Psyent Corporation <www.psyent.com> |
| 4 | * Scott McNutt <smcnutt@psyent.com> |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <command.h> |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 9 | #include <cpu.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 11 | #include <dm.h> |
| 12 | #include <errno.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 13 | #include <init.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 14 | #include <irq_func.h> |
Joachim Foerster | f292474 | 2011-10-20 10:28:10 +0200 | [diff] [blame] | 15 | #include <asm/cache.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 16 | #include <asm/system.h> |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 17 | |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 20 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 21 | int print_cpuinfo(void) |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 22 | { |
Thomas Chou | 36b9c9a | 2015-10-14 08:43:31 +0800 | [diff] [blame] | 23 | printf("CPU: Nios-II\n"); |
| 24 | return 0; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 25 | } |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 26 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 27 | |
Thomas Chou | 48b42e6 | 2015-12-16 16:07:06 +0800 | [diff] [blame] | 28 | #ifdef CONFIG_ALTERA_SYSID |
| 29 | int checkboard(void) |
| 30 | { |
| 31 | display_sysid(); |
| 32 | return 0; |
| 33 | } |
| 34 | #endif |
| 35 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 36 | int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 37 | { |
Thomas Chou | 5975e79 | 2010-08-16 10:49:44 +0800 | [diff] [blame] | 38 | disable_interrupts(); |
| 39 | /* indirect call to go beyond 256MB limitation of toolchain */ |
Thomas Chou | 72b6198 | 2015-10-09 09:43:52 +0800 | [diff] [blame] | 40 | nios2_callr(gd->arch.reset_addr); |
Thomas Chou | 5975e79 | 2010-08-16 10:49:44 +0800 | [diff] [blame] | 41 | return 0; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 42 | } |
Joachim Foerster | f292474 | 2011-10-20 10:28:10 +0200 | [diff] [blame] | 43 | |
Thomas Chou | 93f9646 | 2015-10-06 14:09:19 +0800 | [diff] [blame] | 44 | /* |
| 45 | * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the |
| 46 | * exception address. Define CONFIG_ROM_STUBS to prevent |
| 47 | * the copy (e.g. exception in flash or in other |
| 48 | * softare/firmware component). |
| 49 | */ |
| 50 | #ifndef CONFIG_ROM_STUBS |
| 51 | static void copy_exception_trampoline(void) |
| 52 | { |
| 53 | extern int _except_start, _except_end; |
| 54 | void *except_target = (void *)gd->arch.exception_addr; |
| 55 | |
| 56 | if (&_except_start != except_target) { |
| 57 | memcpy(except_target, &_except_start, |
| 58 | &_except_end - &_except_start); |
| 59 | flush_cache(gd->arch.exception_addr, |
| 60 | &_except_end - &_except_start); |
| 61 | } |
| 62 | } |
| 63 | #endif |
| 64 | |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 65 | int arch_cpu_init_dm(void) |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 66 | { |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 67 | struct udevice *dev; |
| 68 | int ret; |
| 69 | |
Simon Glass | c7298e7 | 2016-02-11 13:23:26 -0700 | [diff] [blame] | 70 | ret = uclass_first_device_err(UCLASS_CPU, &dev); |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 71 | if (ret) |
| 72 | return ret; |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 73 | |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 74 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
Thomas Chou | 93f9646 | 2015-10-06 14:09:19 +0800 | [diff] [blame] | 75 | #ifndef CONFIG_ROM_STUBS |
| 76 | copy_exception_trampoline(); |
| 77 | #endif |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 78 | |
| 79 | return 0; |
| 80 | } |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 81 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 82 | static int altera_nios2_get_desc(const struct udevice *dev, char *buf, |
| 83 | int size) |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 84 | { |
| 85 | const char *cpu_name = "Nios-II"; |
| 86 | |
| 87 | if (size < strlen(cpu_name)) |
| 88 | return -ENOSPC; |
| 89 | strcpy(buf, cpu_name); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 94 | static int altera_nios2_get_info(const struct udevice *dev, |
| 95 | struct cpu_info *info) |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 96 | { |
| 97 | info->cpu_freq = gd->cpu_clk; |
| 98 | info->features = (1 << CPU_FEAT_L1_CACHE) | |
| 99 | (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 104 | static int altera_nios2_get_count(const struct udevice *dev) |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 105 | { |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | static int altera_nios2_probe(struct udevice *dev) |
| 110 | { |
| 111 | const void *blob = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 112 | int node = dev_of_offset(dev); |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 113 | |
| 114 | gd->cpu_clk = fdtdec_get_int(blob, node, |
| 115 | "clock-frequency", 0); |
| 116 | gd->arch.dcache_line_size = fdtdec_get_int(blob, node, |
| 117 | "dcache-line-size", 0); |
| 118 | gd->arch.icache_line_size = fdtdec_get_int(blob, node, |
| 119 | "icache-line-size", 0); |
| 120 | gd->arch.dcache_size = fdtdec_get_int(blob, node, |
| 121 | "dcache-size", 0); |
| 122 | gd->arch.icache_size = fdtdec_get_int(blob, node, |
| 123 | "icache-size", 0); |
| 124 | gd->arch.reset_addr = fdtdec_get_int(blob, node, |
| 125 | "altr,reset-addr", 0); |
| 126 | gd->arch.exception_addr = fdtdec_get_int(blob, node, |
| 127 | "altr,exception-addr", 0); |
| 128 | gd->arch.has_initda = fdtdec_get_int(blob, node, |
| 129 | "altr,has-initda", 0); |
| 130 | gd->arch.has_mmu = fdtdec_get_int(blob, node, |
| 131 | "altr,has-mmu", 0); |
Thomas Chou | ebf8aac | 2015-10-27 08:30:22 +0800 | [diff] [blame] | 132 | gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000; |
| 133 | gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000; |
Thomas Chou | 043a497 | 2015-10-27 09:02:17 +0800 | [diff] [blame] | 134 | gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff; |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static const struct cpu_ops altera_nios2_ops = { |
| 140 | .get_desc = altera_nios2_get_desc, |
| 141 | .get_info = altera_nios2_get_info, |
| 142 | .get_count = altera_nios2_get_count, |
| 143 | }; |
| 144 | |
| 145 | static const struct udevice_id altera_nios2_ids[] = { |
| 146 | { .compatible = "altr,nios2-1.0" }, |
| 147 | { .compatible = "altr,nios2-1.1" }, |
| 148 | { } |
| 149 | }; |
| 150 | |
| 151 | U_BOOT_DRIVER(altera_nios2) = { |
| 152 | .name = "altera_nios2", |
| 153 | .id = UCLASS_CPU, |
| 154 | .of_match = altera_nios2_ids, |
| 155 | .probe = altera_nios2_probe, |
| 156 | .ops = &altera_nios2_ops, |
| 157 | .flags = DM_FLAG_PRE_RELOC, |
| 158 | }; |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 159 | |
| 160 | /* This is a dummy function on nios2 */ |
| 161 | int dram_init(void) |
| 162 | { |
| 163 | return 0; |
| 164 | } |