137e4dafaSPeter Tyser /* 237e4dafaSPeter Tyser * (C) Copyright 2004, Psyent Corporation <www.psyent.com> 337e4dafaSPeter Tyser * Scott McNutt <smcnutt@psyent.com> 437e4dafaSPeter Tyser * 51a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 637e4dafaSPeter Tyser */ 737e4dafaSPeter Tyser 837e4dafaSPeter Tyser #include <common.h> 9bcae80e9SThomas Chou #include <cpu.h> 10bcae80e9SThomas Chou #include <dm.h> 11bcae80e9SThomas Chou #include <errno.h> 12f956ad98SJoachim Foerster #include <asm/cache.h> 1337e4dafaSPeter Tyser 145ff10aa7SThomas Chou DECLARE_GLOBAL_DATA_PTR; 155ff10aa7SThomas Chou 165ff10aa7SThomas Chou #ifdef CONFIG_DISPLAY_CPUINFO 175ff10aa7SThomas Chou int print_cpuinfo(void) 1837e4dafaSPeter Tyser { 1937e4dafaSPeter Tyser printf("CPU: Nios-II\n"); 20ca844dd8SThomas Chou return 0; 2137e4dafaSPeter Tyser } 225ff10aa7SThomas Chou #endif /* CONFIG_DISPLAY_CPUINFO */ 2337e4dafaSPeter Tyser 244909f0e1SThomas Chou #ifdef CONFIG_ALTERA_SYSID 254909f0e1SThomas Chou int checkboard(void) 264909f0e1SThomas Chou { 274909f0e1SThomas Chou display_sysid(); 284909f0e1SThomas Chou return 0; 294909f0e1SThomas Chou } 304909f0e1SThomas Chou #endif 314909f0e1SThomas Chou 32882b7d72SMike Frysinger int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 3337e4dafaSPeter Tyser { 3437e4dafaSPeter Tyser disable_interrupts(); 357a6a7d10SThomas Chou /* indirect call to go beyond 256MB limitation of toolchain */ 36121e36daSThomas Chou nios2_callr(gd->arch.reset_addr); 377a6a7d10SThomas Chou return 0; 3837e4dafaSPeter Tyser } 39f956ad98SJoachim Foerster 40b8112091SThomas Chou /* 41b8112091SThomas Chou * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the 42b8112091SThomas Chou * exception address. Define CONFIG_ROM_STUBS to prevent 43b8112091SThomas Chou * the copy (e.g. exception in flash or in other 44b8112091SThomas Chou * softare/firmware component). 45b8112091SThomas Chou */ 46b8112091SThomas Chou #ifndef CONFIG_ROM_STUBS 47b8112091SThomas Chou static void copy_exception_trampoline(void) 48b8112091SThomas Chou { 49b8112091SThomas Chou extern int _except_start, _except_end; 50b8112091SThomas Chou void *except_target = (void *)gd->arch.exception_addr; 51b8112091SThomas Chou 52b8112091SThomas Chou if (&_except_start != except_target) { 53b8112091SThomas Chou memcpy(except_target, &_except_start, 54b8112091SThomas Chou &_except_end - &_except_start); 55b8112091SThomas Chou flush_cache(gd->arch.exception_addr, 56b8112091SThomas Chou &_except_end - &_except_start); 57b8112091SThomas Chou } 58b8112091SThomas Chou } 59b8112091SThomas Chou #endif 60b8112091SThomas Chou 61bcae80e9SThomas Chou int arch_cpu_init_dm(void) 625ff10aa7SThomas Chou { 63bcae80e9SThomas Chou struct udevice *dev; 64bcae80e9SThomas Chou int ret; 65bcae80e9SThomas Chou 66*3f603cbbSSimon Glass ret = uclass_first_device_err(UCLASS_CPU, &dev); 67bcae80e9SThomas Chou if (ret) 68bcae80e9SThomas Chou return ret; 69bcae80e9SThomas Chou 705ff10aa7SThomas Chou gd->ram_size = CONFIG_SYS_SDRAM_SIZE; 71b8112091SThomas Chou #ifndef CONFIG_ROM_STUBS 72b8112091SThomas Chou copy_exception_trampoline(); 73b8112091SThomas Chou #endif 745ff10aa7SThomas Chou 755ff10aa7SThomas Chou return 0; 765ff10aa7SThomas Chou } 77bcae80e9SThomas Chou 78bcae80e9SThomas Chou static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size) 79bcae80e9SThomas Chou { 80bcae80e9SThomas Chou const char *cpu_name = "Nios-II"; 81bcae80e9SThomas Chou 82bcae80e9SThomas Chou if (size < strlen(cpu_name)) 83bcae80e9SThomas Chou return -ENOSPC; 84bcae80e9SThomas Chou strcpy(buf, cpu_name); 85bcae80e9SThomas Chou 86bcae80e9SThomas Chou return 0; 87bcae80e9SThomas Chou } 88bcae80e9SThomas Chou 89bcae80e9SThomas Chou static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info) 90bcae80e9SThomas Chou { 91bcae80e9SThomas Chou info->cpu_freq = gd->cpu_clk; 92bcae80e9SThomas Chou info->features = (1 << CPU_FEAT_L1_CACHE) | 93bcae80e9SThomas Chou (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0); 94bcae80e9SThomas Chou 95bcae80e9SThomas Chou return 0; 96bcae80e9SThomas Chou } 97bcae80e9SThomas Chou 98bcae80e9SThomas Chou static int altera_nios2_get_count(struct udevice *dev) 99bcae80e9SThomas Chou { 100bcae80e9SThomas Chou return 1; 101bcae80e9SThomas Chou } 102bcae80e9SThomas Chou 103bcae80e9SThomas Chou static int altera_nios2_probe(struct udevice *dev) 104bcae80e9SThomas Chou { 105bcae80e9SThomas Chou const void *blob = gd->fdt_blob; 106bcae80e9SThomas Chou int node = dev->of_offset; 107bcae80e9SThomas Chou 108bcae80e9SThomas Chou gd->cpu_clk = fdtdec_get_int(blob, node, 109bcae80e9SThomas Chou "clock-frequency", 0); 110bcae80e9SThomas Chou gd->arch.dcache_line_size = fdtdec_get_int(blob, node, 111bcae80e9SThomas Chou "dcache-line-size", 0); 112bcae80e9SThomas Chou gd->arch.icache_line_size = fdtdec_get_int(blob, node, 113bcae80e9SThomas Chou "icache-line-size", 0); 114bcae80e9SThomas Chou gd->arch.dcache_size = fdtdec_get_int(blob, node, 115bcae80e9SThomas Chou "dcache-size", 0); 116bcae80e9SThomas Chou gd->arch.icache_size = fdtdec_get_int(blob, node, 117bcae80e9SThomas Chou "icache-size", 0); 118bcae80e9SThomas Chou gd->arch.reset_addr = fdtdec_get_int(blob, node, 119bcae80e9SThomas Chou "altr,reset-addr", 0); 120bcae80e9SThomas Chou gd->arch.exception_addr = fdtdec_get_int(blob, node, 121bcae80e9SThomas Chou "altr,exception-addr", 0); 122bcae80e9SThomas Chou gd->arch.has_initda = fdtdec_get_int(blob, node, 123bcae80e9SThomas Chou "altr,has-initda", 0); 124bcae80e9SThomas Chou gd->arch.has_mmu = fdtdec_get_int(blob, node, 125bcae80e9SThomas Chou "altr,has-mmu", 0); 1261ce61cbbSThomas Chou gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000; 1271ce61cbbSThomas Chou gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000; 1282de4823dSThomas Chou gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff; 129bcae80e9SThomas Chou 130bcae80e9SThomas Chou return 0; 131bcae80e9SThomas Chou } 132bcae80e9SThomas Chou 133bcae80e9SThomas Chou static const struct cpu_ops altera_nios2_ops = { 134bcae80e9SThomas Chou .get_desc = altera_nios2_get_desc, 135bcae80e9SThomas Chou .get_info = altera_nios2_get_info, 136bcae80e9SThomas Chou .get_count = altera_nios2_get_count, 137bcae80e9SThomas Chou }; 138bcae80e9SThomas Chou 139bcae80e9SThomas Chou static const struct udevice_id altera_nios2_ids[] = { 140bcae80e9SThomas Chou { .compatible = "altr,nios2-1.0" }, 141bcae80e9SThomas Chou { .compatible = "altr,nios2-1.1" }, 142bcae80e9SThomas Chou { } 143bcae80e9SThomas Chou }; 144bcae80e9SThomas Chou 145bcae80e9SThomas Chou U_BOOT_DRIVER(altera_nios2) = { 146bcae80e9SThomas Chou .name = "altera_nios2", 147bcae80e9SThomas Chou .id = UCLASS_CPU, 148bcae80e9SThomas Chou .of_match = altera_nios2_ids, 149bcae80e9SThomas Chou .probe = altera_nios2_probe, 150bcae80e9SThomas Chou .ops = &altera_nios2_ops, 151bcae80e9SThomas Chou .flags = DM_FLAG_PRE_RELOC, 152bcae80e9SThomas Chou }; 153