9b34cba047558bbf88c52b2f16315882bc984e5f
[pandora-u-boot.git] / arch / arm / mach-rmobile / cpu_info.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
4  * (C) Copyright 2012 Renesas Solutions Corp.
5  */
6 #include <common.h>
7 #include <cpu_func.h>
8 #include <asm/cache.h>
9 #include <asm/io.h>
10 #include <env.h>
11 #include <linux/ctype.h>
12
13 #ifdef CONFIG_ARCH_CPU_INIT
14 int arch_cpu_init(void)
15 {
16         icache_enable();
17         return 0;
18 }
19 #endif
20
21 /* R-Car Gen3 D-cache is enabled in memmap-gen3.c */
22 #ifndef CONFIG_RCAR_GEN3
23 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
24 void enable_caches(void)
25 {
26         dcache_enable();
27 }
28 #endif
29 #endif
30
31 #ifdef CONFIG_DISPLAY_CPUINFO
32 #ifndef CONFIG_RZA1
33 static u32 __rmobile_get_cpu_type(void)
34 {
35         return 0x0;
36 }
37 u32 rmobile_get_cpu_type(void)
38                 __attribute__((weak, alias("__rmobile_get_cpu_type")));
39
40 static u32 __rmobile_get_cpu_rev_integer(void)
41 {
42         return 0;
43 }
44 u32 rmobile_get_cpu_rev_integer(void)
45                 __attribute__((weak, alias("__rmobile_get_cpu_rev_integer")));
46
47 static u32 __rmobile_get_cpu_rev_fraction(void)
48 {
49         return 0;
50 }
51 u32 rmobile_get_cpu_rev_fraction(void)
52                 __attribute__((weak, alias("__rmobile_get_cpu_rev_fraction")));
53
54 /* CPU infomation table */
55 static const struct {
56         u16 cpu_type;
57         u8 cpu_name[10];
58 } rmobile_cpuinfo[] = {
59         { RMOBILE_CPU_TYPE_SH73A0, "SH73A0" },
60         { RMOBILE_CPU_TYPE_R8A7740, "R8A7740" },
61         { RMOBILE_CPU_TYPE_R8A7790, "R8A7790" },
62         { RMOBILE_CPU_TYPE_R8A7791, "R8A7791" },
63         { RMOBILE_CPU_TYPE_R8A7792, "R8A7792" },
64         { RMOBILE_CPU_TYPE_R8A7793, "R8A7793" },
65         { RMOBILE_CPU_TYPE_R8A7794, "R8A7794" },
66         { RMOBILE_CPU_TYPE_R8A7795, "R8A7795" },
67         { RMOBILE_CPU_TYPE_R8A7796, "R8A7796" },
68         { RMOBILE_CPU_TYPE_R8A77965, "R8A77965" },
69         { RMOBILE_CPU_TYPE_R8A77970, "R8A77970" },
70         { RMOBILE_CPU_TYPE_R8A77980, "R8A77980" },
71         { RMOBILE_CPU_TYPE_R8A77990, "R8A77990" },
72         { RMOBILE_CPU_TYPE_R8A77995, "R8A77995" },
73         { 0x0, "CPU" },
74 };
75
76 static int rmobile_cpuinfo_idx(void)
77 {
78         int i = 0;
79         u32 cpu_type = rmobile_get_cpu_type();
80
81         for (; i < ARRAY_SIZE(rmobile_cpuinfo); i++)
82                 if (rmobile_cpuinfo[i].cpu_type == cpu_type)
83                         break;
84
85         return i;
86 }
87
88 #ifdef CONFIG_ARCH_MISC_INIT
89 int arch_misc_init(void)
90 {
91         int i, idx = rmobile_cpuinfo_idx();
92         char cpu[10] = { 0 };
93
94         for (i = 0; i < sizeof(cpu); i++)
95                 cpu[i] = tolower(rmobile_cpuinfo[idx].cpu_name[i]);
96
97         env_set("platform", cpu);
98
99         return 0;
100 }
101 #endif
102
103 int print_cpuinfo(void)
104 {
105         int i = rmobile_cpuinfo_idx();
106
107         printf("CPU: Renesas Electronics %s rev %d.%d\n",
108                 rmobile_cpuinfo[i].cpu_name, rmobile_get_cpu_rev_integer(),
109                 rmobile_get_cpu_rev_fraction());
110
111         return 0;
112 }
113 #else
114 int print_cpuinfo(void)
115 {
116         printf("CPU: Renesas Electronics RZ/A1\n");
117         return 0;
118 }
119 #endif
120 #endif /* CONFIG_DISPLAY_CPUINFO */