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 24882b7d72SMike Frysinger int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 2537e4dafaSPeter Tyser { 2637e4dafaSPeter Tyser disable_interrupts(); 277a6a7d10SThomas Chou /* indirect call to go beyond 256MB limitation of toolchain */ 28121e36daSThomas Chou nios2_callr(gd->arch.reset_addr); 297a6a7d10SThomas Chou return 0; 3037e4dafaSPeter Tyser } 31f956ad98SJoachim Foerster 32b8112091SThomas Chou /* 33b8112091SThomas Chou * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the 34b8112091SThomas Chou * exception address. Define CONFIG_ROM_STUBS to prevent 35b8112091SThomas Chou * the copy (e.g. exception in flash or in other 36b8112091SThomas Chou * softare/firmware component). 37b8112091SThomas Chou */ 38b8112091SThomas Chou #ifndef CONFIG_ROM_STUBS 39b8112091SThomas Chou static void copy_exception_trampoline(void) 40b8112091SThomas Chou { 41b8112091SThomas Chou extern int _except_start, _except_end; 42b8112091SThomas Chou void *except_target = (void *)gd->arch.exception_addr; 43b8112091SThomas Chou 44b8112091SThomas Chou if (&_except_start != except_target) { 45b8112091SThomas Chou memcpy(except_target, &_except_start, 46b8112091SThomas Chou &_except_end - &_except_start); 47b8112091SThomas Chou flush_cache(gd->arch.exception_addr, 48b8112091SThomas Chou &_except_end - &_except_start); 49b8112091SThomas Chou } 50b8112091SThomas Chou } 51b8112091SThomas Chou #endif 52b8112091SThomas Chou 53bcae80e9SThomas Chou int arch_cpu_init_dm(void) 545ff10aa7SThomas Chou { 55bcae80e9SThomas Chou struct udevice *dev; 56bcae80e9SThomas Chou int ret; 57bcae80e9SThomas Chou 58bcae80e9SThomas Chou ret = uclass_first_device(UCLASS_CPU, &dev); 59bcae80e9SThomas Chou if (ret) 60bcae80e9SThomas Chou return ret; 61bcae80e9SThomas Chou if (!dev) 62bcae80e9SThomas Chou return -ENODEV; 63bcae80e9SThomas Chou 645ff10aa7SThomas Chou gd->ram_size = CONFIG_SYS_SDRAM_SIZE; 65b8112091SThomas Chou #ifndef CONFIG_ROM_STUBS 66b8112091SThomas Chou copy_exception_trampoline(); 67b8112091SThomas Chou #endif 685ff10aa7SThomas Chou 695ff10aa7SThomas Chou return 0; 705ff10aa7SThomas Chou } 71bcae80e9SThomas Chou 72bcae80e9SThomas Chou static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size) 73bcae80e9SThomas Chou { 74bcae80e9SThomas Chou const char *cpu_name = "Nios-II"; 75bcae80e9SThomas Chou 76bcae80e9SThomas Chou if (size < strlen(cpu_name)) 77bcae80e9SThomas Chou return -ENOSPC; 78bcae80e9SThomas Chou strcpy(buf, cpu_name); 79bcae80e9SThomas Chou 80bcae80e9SThomas Chou return 0; 81bcae80e9SThomas Chou } 82bcae80e9SThomas Chou 83bcae80e9SThomas Chou static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info) 84bcae80e9SThomas Chou { 85bcae80e9SThomas Chou info->cpu_freq = gd->cpu_clk; 86bcae80e9SThomas Chou info->features = (1 << CPU_FEAT_L1_CACHE) | 87bcae80e9SThomas Chou (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0); 88bcae80e9SThomas Chou 89bcae80e9SThomas Chou return 0; 90bcae80e9SThomas Chou } 91bcae80e9SThomas Chou 92bcae80e9SThomas Chou static int altera_nios2_get_count(struct udevice *dev) 93bcae80e9SThomas Chou { 94bcae80e9SThomas Chou return 1; 95bcae80e9SThomas Chou } 96bcae80e9SThomas Chou 97bcae80e9SThomas Chou static int altera_nios2_probe(struct udevice *dev) 98bcae80e9SThomas Chou { 99bcae80e9SThomas Chou const void *blob = gd->fdt_blob; 100bcae80e9SThomas Chou int node = dev->of_offset; 101bcae80e9SThomas Chou 102bcae80e9SThomas Chou gd->cpu_clk = fdtdec_get_int(blob, node, 103bcae80e9SThomas Chou "clock-frequency", 0); 104bcae80e9SThomas Chou gd->arch.dcache_line_size = fdtdec_get_int(blob, node, 105bcae80e9SThomas Chou "dcache-line-size", 0); 106bcae80e9SThomas Chou gd->arch.icache_line_size = fdtdec_get_int(blob, node, 107bcae80e9SThomas Chou "icache-line-size", 0); 108bcae80e9SThomas Chou gd->arch.dcache_size = fdtdec_get_int(blob, node, 109bcae80e9SThomas Chou "dcache-size", 0); 110bcae80e9SThomas Chou gd->arch.icache_size = fdtdec_get_int(blob, node, 111bcae80e9SThomas Chou "icache-size", 0); 112bcae80e9SThomas Chou gd->arch.reset_addr = fdtdec_get_int(blob, node, 113bcae80e9SThomas Chou "altr,reset-addr", 0); 114bcae80e9SThomas Chou gd->arch.exception_addr = fdtdec_get_int(blob, node, 115bcae80e9SThomas Chou "altr,exception-addr", 0); 116bcae80e9SThomas Chou gd->arch.has_initda = fdtdec_get_int(blob, node, 117bcae80e9SThomas Chou "altr,has-initda", 0); 118bcae80e9SThomas Chou gd->arch.has_mmu = fdtdec_get_int(blob, node, 119bcae80e9SThomas Chou "altr,has-mmu", 0); 120*1ce61cbbSThomas Chou gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000; 121*1ce61cbbSThomas Chou gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000; 122bcae80e9SThomas Chou 123bcae80e9SThomas Chou return 0; 124bcae80e9SThomas Chou } 125bcae80e9SThomas Chou 126bcae80e9SThomas Chou static const struct cpu_ops altera_nios2_ops = { 127bcae80e9SThomas Chou .get_desc = altera_nios2_get_desc, 128bcae80e9SThomas Chou .get_info = altera_nios2_get_info, 129bcae80e9SThomas Chou .get_count = altera_nios2_get_count, 130bcae80e9SThomas Chou }; 131bcae80e9SThomas Chou 132bcae80e9SThomas Chou static const struct udevice_id altera_nios2_ids[] = { 133bcae80e9SThomas Chou { .compatible = "altr,nios2-1.0" }, 134bcae80e9SThomas Chou { .compatible = "altr,nios2-1.1" }, 135bcae80e9SThomas Chou { } 136bcae80e9SThomas Chou }; 137bcae80e9SThomas Chou 138bcae80e9SThomas Chou U_BOOT_DRIVER(altera_nios2) = { 139bcae80e9SThomas Chou .name = "altera_nios2", 140bcae80e9SThomas Chou .id = UCLASS_CPU, 141bcae80e9SThomas Chou .of_match = altera_nios2_ids, 142bcae80e9SThomas Chou .probe = altera_nios2_probe, 143bcae80e9SThomas Chou .ops = &altera_nios2_ops, 144bcae80e9SThomas Chou .flags = DM_FLAG_PRE_RELOC, 145bcae80e9SThomas Chou }; 146