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 <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
__rmobile_get_cpu_type(void)34 static u32 __rmobile_get_cpu_type(void)
35 {
36 	return 0x0;
37 }
38 u32 rmobile_get_cpu_type(void)
39 		__attribute__((weak, alias("__rmobile_get_cpu_type")));
40 
__rmobile_get_cpu_rev_integer(void)41 static u32 __rmobile_get_cpu_rev_integer(void)
42 {
43 	return 0;
44 }
45 u32 rmobile_get_cpu_rev_integer(void)
46 		__attribute__((weak, alias("__rmobile_get_cpu_rev_integer")));
47 
__rmobile_get_cpu_rev_fraction(void)48 static u32 __rmobile_get_cpu_rev_fraction(void)
49 {
50 	return 0;
51 }
52 u32 rmobile_get_cpu_rev_fraction(void)
53 		__attribute__((weak, alias("__rmobile_get_cpu_rev_fraction")));
54 
55 /* CPU infomation table */
56 static const struct {
57 	u16 cpu_type;
58 	u8 cpu_name[10];
59 } rmobile_cpuinfo[] = {
60 	{ RMOBILE_CPU_TYPE_SH73A0, "SH73A0" },
61 	{ RMOBILE_CPU_TYPE_R8A7740, "R8A7740" },
62 	{ RMOBILE_CPU_TYPE_R8A7790, "R8A7790" },
63 	{ RMOBILE_CPU_TYPE_R8A7791, "R8A7791" },
64 	{ RMOBILE_CPU_TYPE_R8A7792, "R8A7792" },
65 	{ RMOBILE_CPU_TYPE_R8A7793, "R8A7793" },
66 	{ RMOBILE_CPU_TYPE_R8A7794, "R8A7794" },
67 	{ RMOBILE_CPU_TYPE_R8A7795, "R8A7795" },
68 	{ RMOBILE_CPU_TYPE_R8A7796, "R8A7796" },
69 	{ RMOBILE_CPU_TYPE_R8A77965, "R8A77965" },
70 	{ RMOBILE_CPU_TYPE_R8A77970, "R8A77970" },
71 	{ RMOBILE_CPU_TYPE_R8A77980, "R8A77980" },
72 	{ RMOBILE_CPU_TYPE_R8A77990, "R8A77990" },
73 	{ RMOBILE_CPU_TYPE_R8A77995, "R8A77995" },
74 	{ 0x0, "CPU" },
75 };
76 
rmobile_cpuinfo_idx(void)77 static int rmobile_cpuinfo_idx(void)
78 {
79 	int i = 0;
80 	u32 cpu_type = rmobile_get_cpu_type();
81 
82 	for (; i < ARRAY_SIZE(rmobile_cpuinfo); i++)
83 		if (rmobile_cpuinfo[i].cpu_type == cpu_type)
84 			break;
85 
86 	return i;
87 }
88 
89 #ifdef CONFIG_ARCH_MISC_INIT
arch_misc_init(void)90 int arch_misc_init(void)
91 {
92 	int i, idx = rmobile_cpuinfo_idx();
93 	char cpu[10] = { 0 };
94 
95 	for (i = 0; i < sizeof(cpu); i++)
96 		cpu[i] = tolower(rmobile_cpuinfo[idx].cpu_name[i]);
97 
98 	env_set("platform", cpu);
99 
100 	return 0;
101 }
102 #endif
103 
print_cpuinfo(void)104 int print_cpuinfo(void)
105 {
106 	int i = rmobile_cpuinfo_idx();
107 
108 	printf("CPU: Renesas Electronics %s rev %d.%d\n",
109 		rmobile_cpuinfo[i].cpu_name, rmobile_get_cpu_rev_integer(),
110 		rmobile_get_cpu_rev_fraction());
111 
112 	return 0;
113 }
114 #else
print_cpuinfo(void)115 int print_cpuinfo(void)
116 {
117 	printf("CPU: Renesas Electronics RZ/A1\n");
118 	return 0;
119 }
120 #endif
121 #endif /* CONFIG_DISPLAY_CPUINFO */
122