nios2: convert altera sysid to driver model
[platform/kernel/u-boot.git] / arch / nios2 / cpu / cpu.c
1 /*
2  * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3  * Scott McNutt <smcnutt@psyent.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <cpu.h>
10 #include <dm.h>
11 #include <errno.h>
12 #include <asm/cache.h>
13
14 DECLARE_GLOBAL_DATA_PTR;
15
16 #ifdef CONFIG_DISPLAY_CPUINFO
17 int print_cpuinfo(void)
18 {
19         printf("CPU:   Nios-II\n");
20         return 0;
21 }
22 #endif /* CONFIG_DISPLAY_CPUINFO */
23
24 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
25 {
26         disable_interrupts();
27         /* indirect call to go beyond 256MB limitation of toolchain */
28         nios2_callr(CONFIG_SYS_RESET_ADDR);
29         return 0;
30 }
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 }
46
47 int arch_cpu_init_dm(void)
48 {
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
58         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
59
60         return 0;
61 }
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 };