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 <asm/io.h>
8 #include <linux/ctype.h>
9 
10 #ifdef CONFIG_ARCH_CPU_INIT
11 int arch_cpu_init(void)
12 {
13 	icache_enable();
14 	return 0;
15 }
16 #endif
17 
18 /* R-Car Gen3 D-cache is enabled in memmap-gen3.c */
19 #ifndef CONFIG_RCAR_GEN3
20 #ifndef CONFIG_SYS_DCACHE_OFF
21 void enable_caches(void)
22 {
23 	dcache_enable();
24 }
25 #endif
26 #endif
27 
28 #ifdef CONFIG_DISPLAY_CPUINFO
29 static u32 __rmobile_get_cpu_type(void)
30 {
31 	return 0x0;
32 }
33 u32 rmobile_get_cpu_type(void)
34 		__attribute__((weak, alias("__rmobile_get_cpu_type")));
35 
36 static u32 __rmobile_get_cpu_rev_integer(void)
37 {
38 	return 0;
39 }
40 u32 rmobile_get_cpu_rev_integer(void)
41 		__attribute__((weak, alias("__rmobile_get_cpu_rev_integer")));
42 
43 static u32 __rmobile_get_cpu_rev_fraction(void)
44 {
45 	return 0;
46 }
47 u32 rmobile_get_cpu_rev_fraction(void)
48 		__attribute__((weak, alias("__rmobile_get_cpu_rev_fraction")));
49 
50 /* CPU infomation table */
51 static const struct {
52 	u16 cpu_type;
53 	u8 cpu_name[10];
54 } rmobile_cpuinfo[] = {
55 	{ RMOBILE_CPU_TYPE_SH73A0, "SH73A0" },
56 	{ RMOBILE_CPU_TYPE_R8A7740, "R8A7740" },
57 	{ RMOBILE_CPU_TYPE_R8A7790, "R8A7790" },
58 	{ RMOBILE_CPU_TYPE_R8A7791, "R8A7791" },
59 	{ RMOBILE_CPU_TYPE_R8A7792, "R8A7792" },
60 	{ RMOBILE_CPU_TYPE_R8A7793, "R8A7793" },
61 	{ RMOBILE_CPU_TYPE_R8A7794, "R8A7794" },
62 	{ RMOBILE_CPU_TYPE_R8A7795, "R8A7795" },
63 	{ RMOBILE_CPU_TYPE_R8A7796, "R8A7796" },
64 	{ RMOBILE_CPU_TYPE_R8A77965, "R8A77965" },
65 	{ RMOBILE_CPU_TYPE_R8A77970, "R8A77970" },
66 	{ RMOBILE_CPU_TYPE_R8A77990, "R8A77990" },
67 	{ RMOBILE_CPU_TYPE_R8A77995, "R8A77995" },
68 	{ 0x0, "CPU" },
69 };
70 
71 static int rmobile_cpuinfo_idx(void)
72 {
73 	int i = 0;
74 	u32 cpu_type = rmobile_get_cpu_type();
75 
76 	for (; i < ARRAY_SIZE(rmobile_cpuinfo); i++)
77 		if (rmobile_cpuinfo[i].cpu_type == cpu_type)
78 			break;
79 
80 	return i;
81 }
82 
83 #ifdef CONFIG_ARCH_MISC_INIT
84 int arch_misc_init(void)
85 {
86 	int i, idx = rmobile_cpuinfo_idx();
87 	char cpu[10] = { 0 };
88 
89 	for (i = 0; i < sizeof(cpu); i++)
90 		cpu[i] = tolower(rmobile_cpuinfo[idx].cpu_name[i]);
91 
92 	env_set("platform", cpu);
93 
94 	return 0;
95 }
96 #endif
97 
98 int print_cpuinfo(void)
99 {
100 	int i = rmobile_cpuinfo_idx();
101 
102 	printf("CPU: Renesas Electronics %s rev %d.%d\n",
103 		rmobile_cpuinfo[i].cpu_name, rmobile_get_cpu_rev_integer(),
104 		rmobile_get_cpu_rev_fraction());
105 
106 	return 0;
107 }
108 #endif /* CONFIG_DISPLAY_CPUINFO */
109