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