blob: d7ff290fd7e0945f252d43d6f25dc7b8fc75d4cd [file] [log] [blame]
wdenkef3386f2004-10-10 21:27:30 +00001/*
2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkef3386f2004-10-10 21:27:30 +00006 */
7
8#include <common.h>
Thomas Chouc6170262015-10-21 21:34:57 +08009#include <cpu.h>
10#include <dm.h>
11#include <errno.h>
Joachim Foersterf2924742011-10-20 10:28:10 +020012#include <asm/cache.h>
wdenkef3386f2004-10-10 21:27:30 +000013
Thomas Choucce3e752014-08-22 11:36:47 +080014DECLARE_GLOBAL_DATA_PTR;
15
Thomas Choucce3e752014-08-22 11:36:47 +080016#ifdef CONFIG_DISPLAY_CPUINFO
17int print_cpuinfo(void)
wdenkef3386f2004-10-10 21:27:30 +000018{
Thomas Chou36b9c9a2015-10-14 08:43:31 +080019 printf("CPU: Nios-II\n");
20 return 0;
wdenkef3386f2004-10-10 21:27:30 +000021}
Thomas Choucce3e752014-08-22 11:36:47 +080022#endif /* CONFIG_DISPLAY_CPUINFO */
wdenkef3386f2004-10-10 21:27:30 +000023
Mike Frysinger6d1f6982010-10-20 03:41:17 -040024int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkef3386f2004-10-10 21:27:30 +000025{
Thomas Chou5975e792010-08-16 10:49:44 +080026 disable_interrupts();
27 /* indirect call to go beyond 256MB limitation of toolchain */
28 nios2_callr(CONFIG_SYS_RESET_ADDR);
29 return 0;
wdenkef3386f2004-10-10 21:27:30 +000030}
Joachim Foersterf2924742011-10-20 10:28:10 +020031
32int dcache_status(void)
33{
34 return 1;
35}
36
37void dcache_enable(void)
38{
39 flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
40}
41
42void dcache_disable(void)
43{
44 flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
45}
Thomas Choucce3e752014-08-22 11:36:47 +080046
Thomas Chouc6170262015-10-21 21:34:57 +080047int arch_cpu_init_dm(void)
Thomas Choucce3e752014-08-22 11:36:47 +080048{
Thomas Chouc6170262015-10-21 21:34:57 +080049 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 Choucce3e752014-08-22 11:36:47 +080058 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
59
60 return 0;
61}
Thomas Chouc6170262015-10-21 21:34:57 +080062
63static 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
74static 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
83static int altera_nios2_get_count(struct udevice *dev)
84{
85 return 1;
86}
87
88static 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
116static 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
122static const struct udevice_id altera_nios2_ids[] = {
123 { .compatible = "altr,nios2-1.0" },
124 { .compatible = "altr,nios2-1.1" },
125 { }
126};
127
128U_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};