wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004, Psyent Corporation <www.psyent.com> |
| 3 | * Scott McNutt <smcnutt@psyent.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 9 | #include <cpu.h> |
| 10 | #include <dm.h> |
| 11 | #include <errno.h> |
Joachim Foerster | f292474 | 2011-10-20 10:28:10 +0200 | [diff] [blame] | 12 | #include <asm/cache.h> |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 13 | |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 16 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 17 | int print_cpuinfo(void) |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 18 | { |
Thomas Chou | 36b9c9a | 2015-10-14 08:43:31 +0800 | [diff] [blame^] | 19 | printf("CPU: Nios-II\n"); |
| 20 | return 0; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 21 | } |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 22 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 23 | |
Mike Frysinger | 6d1f698 | 2010-10-20 03:41:17 -0400 | [diff] [blame] | 24 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 25 | { |
Thomas Chou | 5975e79 | 2010-08-16 10:49:44 +0800 | [diff] [blame] | 26 | disable_interrupts(); |
| 27 | /* indirect call to go beyond 256MB limitation of toolchain */ |
| 28 | nios2_callr(CONFIG_SYS_RESET_ADDR); |
| 29 | return 0; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 30 | } |
Joachim Foerster | f292474 | 2011-10-20 10:28:10 +0200 | [diff] [blame] | 31 | |
| 32 | int dcache_status(void) |
| 33 | { |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | void dcache_enable(void) |
| 38 | { |
| 39 | flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE); |
| 40 | } |
| 41 | |
| 42 | void dcache_disable(void) |
| 43 | { |
| 44 | flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE); |
| 45 | } |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 46 | |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 47 | int arch_cpu_init_dm(void) |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 48 | { |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 49 | struct udevice *dev; |
| 50 | int ret; |
| 51 | |
| 52 | ret = uclass_first_device(UCLASS_CPU, &dev); |
| 53 | if (ret) |
| 54 | return ret; |
| 55 | if (!dev) |
| 56 | return -ENODEV; |
| 57 | |
Thomas Chou | cce3e75 | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 58 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 59 | |
| 60 | return 0; |
| 61 | } |
Thomas Chou | c617026 | 2015-10-21 21:34:57 +0800 | [diff] [blame] | 62 | |
| 63 | static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size) |
| 64 | { |
| 65 | const char *cpu_name = "Nios-II"; |
| 66 | |
| 67 | if (size < strlen(cpu_name)) |
| 68 | return -ENOSPC; |
| 69 | strcpy(buf, cpu_name); |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info) |
| 75 | { |
| 76 | info->cpu_freq = gd->cpu_clk; |
| 77 | info->features = (1 << CPU_FEAT_L1_CACHE) | |
| 78 | (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int altera_nios2_get_count(struct udevice *dev) |
| 84 | { |
| 85 | return 1; |
| 86 | } |
| 87 | |
| 88 | static int altera_nios2_probe(struct udevice *dev) |
| 89 | { |
| 90 | const void *blob = gd->fdt_blob; |
| 91 | int node = dev->of_offset; |
| 92 | |
| 93 | gd->cpu_clk = fdtdec_get_int(blob, node, |
| 94 | "clock-frequency", 0); |
| 95 | gd->arch.dcache_line_size = fdtdec_get_int(blob, node, |
| 96 | "dcache-line-size", 0); |
| 97 | gd->arch.icache_line_size = fdtdec_get_int(blob, node, |
| 98 | "icache-line-size", 0); |
| 99 | gd->arch.dcache_size = fdtdec_get_int(blob, node, |
| 100 | "dcache-size", 0); |
| 101 | gd->arch.icache_size = fdtdec_get_int(blob, node, |
| 102 | "icache-size", 0); |
| 103 | gd->arch.reset_addr = fdtdec_get_int(blob, node, |
| 104 | "altr,reset-addr", 0); |
| 105 | gd->arch.exception_addr = fdtdec_get_int(blob, node, |
| 106 | "altr,exception-addr", 0); |
| 107 | gd->arch.has_initda = fdtdec_get_int(blob, node, |
| 108 | "altr,has-initda", 0); |
| 109 | gd->arch.has_mmu = fdtdec_get_int(blob, node, |
| 110 | "altr,has-mmu", 0); |
| 111 | gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x8000000; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static const struct cpu_ops altera_nios2_ops = { |
| 117 | .get_desc = altera_nios2_get_desc, |
| 118 | .get_info = altera_nios2_get_info, |
| 119 | .get_count = altera_nios2_get_count, |
| 120 | }; |
| 121 | |
| 122 | static const struct udevice_id altera_nios2_ids[] = { |
| 123 | { .compatible = "altr,nios2-1.0" }, |
| 124 | { .compatible = "altr,nios2-1.1" }, |
| 125 | { } |
| 126 | }; |
| 127 | |
| 128 | U_BOOT_DRIVER(altera_nios2) = { |
| 129 | .name = "altera_nios2", |
| 130 | .id = UCLASS_CPU, |
| 131 | .of_match = altera_nios2_ids, |
| 132 | .probe = altera_nios2_probe, |
| 133 | .ops = &altera_nios2_ops, |
| 134 | .flags = DM_FLAG_PRE_RELOC, |
| 135 | }; |