blob: 1d33e2aa9da361e78574a85d6f93bb061df7e224 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +09002/*
3 * (C) Copyright 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
Biju Das3e5f3db2021-03-17 14:11:50 +00004 * (C) Copyright 2012-2021 Renesas Solutions Corp.
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +09005 */
6#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -07007#include <cpu_func.h>
Simon Glass90526e92020-05-10 11:39:56 -06008#include <asm/cache.h>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090010#include <asm/io.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060011#include <env.h>
Marek Vasut00e4b572018-12-03 13:28:25 +010012#include <linux/ctype.h>
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090013
14#ifdef CONFIG_ARCH_CPU_INIT
15int arch_cpu_init(void)
16{
17 icache_enable();
18 return 0;
19}
20#endif
21
Hai Pham5a3b0742023-02-28 22:22:03 +010022/* R-Car Gen3 and Gen4 D-cache is enabled in memmap-gen3.c */
23#ifndef CONFIG_RCAR_64
Trevor Woerner10015022019-05-03 09:41:00 -040024#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090025void enable_caches(void)
26{
27 dcache_enable();
28}
29#endif
Marek Vasute5cb6bd2018-10-31 15:06:50 +010030#endif
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090031
32#ifdef CONFIG_DISPLAY_CPUINFO
Ralph Siemsen21563272023-05-12 21:36:55 -040033#if !defined(CONFIG_RZA1) && !defined(CONFIG_RZN1)
Biju Das3e5f3db2021-03-17 14:11:50 +000034__weak const u8 *rzg_get_cpu_name(void)
35{
36 return 0;
37}
38
Nobuhiro Iwamatsu1cdf2482012-08-19 04:40:05 +000039static u32 __rmobile_get_cpu_type(void)
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090040{
Nobuhiro Iwamatsu1cdf2482012-08-19 04:40:05 +000041 return 0x0;
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090042}
Nobuhiro Iwamatsu1cdf2482012-08-19 04:40:05 +000043u32 rmobile_get_cpu_type(void)
44 __attribute__((weak, alias("__rmobile_get_cpu_type")));
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090045
Tetsuyuki Kobayashi4f007b82012-07-25 18:24:21 +000046static u32 __rmobile_get_cpu_rev_integer(void)
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090047{
Nobuhiro Iwamatsu1cdf2482012-08-19 04:40:05 +000048 return 0;
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090049}
Tetsuyuki Kobayashi4f007b82012-07-25 18:24:21 +000050u32 rmobile_get_cpu_rev_integer(void)
51 __attribute__((weak, alias("__rmobile_get_cpu_rev_integer")));
52
53static u32 __rmobile_get_cpu_rev_fraction(void)
54{
55 return 0;
56}
57u32 rmobile_get_cpu_rev_fraction(void)
58 __attribute__((weak, alias("__rmobile_get_cpu_rev_fraction")));
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090059
Biju Das3e5f3db2021-03-17 14:11:50 +000060/* CPU information table */
Nobuhiro Iwamatsu73ff6802014-03-28 11:54:22 +090061static const struct {
62 u16 cpu_type;
63 u8 cpu_name[10];
64} rmobile_cpuinfo[] = {
Marek Vasut262e9152017-11-25 23:54:10 +010065 { RMOBILE_CPU_TYPE_R8A7740, "R8A7740" },
66 { RMOBILE_CPU_TYPE_R8A7790, "R8A7790" },
67 { RMOBILE_CPU_TYPE_R8A7791, "R8A7791" },
68 { RMOBILE_CPU_TYPE_R8A7792, "R8A7792" },
69 { RMOBILE_CPU_TYPE_R8A7793, "R8A7793" },
70 { RMOBILE_CPU_TYPE_R8A7794, "R8A7794" },
71 { RMOBILE_CPU_TYPE_R8A7795, "R8A7795" },
72 { RMOBILE_CPU_TYPE_R8A7796, "R8A7796" },
Marek Vasutf295a562018-02-26 10:35:15 +010073 { RMOBILE_CPU_TYPE_R8A77965, "R8A77965" },
Marek Vasut5cb19e72017-10-09 20:39:47 +020074 { RMOBILE_CPU_TYPE_R8A77970, "R8A77970" },
Marek Vasut57ede1a2019-07-29 19:59:44 +020075 { RMOBILE_CPU_TYPE_R8A77980, "R8A77980" },
Marek Vasuta0410a62018-04-26 10:09:06 +020076 { RMOBILE_CPU_TYPE_R8A77990, "R8A77990" },
Marek Vasut11545412017-10-08 20:52:52 +020077 { RMOBILE_CPU_TYPE_R8A77995, "R8A77995" },
Hai Pham0f08fa42020-05-21 14:11:13 +070078 { RMOBILE_CPU_TYPE_R8A779A0, "R8A779A0" },
Hai Pham8f098fd2023-02-28 22:34:45 +010079 { RMOBILE_CPU_TYPE_R8A779F0, "R8A779F0" },
Hai Phame4e242b2023-02-28 22:37:07 +010080 { RMOBILE_CPU_TYPE_R8A779G0, "R8A779G0" },
Nobuhiro Iwamatsu73ff6802014-03-28 11:54:22 +090081 { 0x0, "CPU" },
82};
83
Marek Vasut00e4b572018-12-03 13:28:25 +010084static int rmobile_cpuinfo_idx(void)
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090085{
Nobuhiro Iwamatsu73ff6802014-03-28 11:54:22 +090086 int i = 0;
87 u32 cpu_type = rmobile_get_cpu_type();
Marek Vasut00e4b572018-12-03 13:28:25 +010088
89 for (; i < ARRAY_SIZE(rmobile_cpuinfo); i++)
90 if (rmobile_cpuinfo[i].cpu_type == cpu_type)
Nobuhiro Iwamatsu73ff6802014-03-28 11:54:22 +090091 break;
Marek Vasut00e4b572018-12-03 13:28:25 +010092
93 return i;
94}
95
Biju Das3e5f3db2021-03-17 14:11:50 +000096static const u8 *get_cpu_name(int idx)
97{
98 const u8 *cpu_name = rzg_get_cpu_name();
99
100 return cpu_name ? cpu_name : rmobile_cpuinfo[idx].cpu_name;
101}
102
Marek Vasut00e4b572018-12-03 13:28:25 +0100103#ifdef CONFIG_ARCH_MISC_INIT
104int arch_misc_init(void)
105{
106 int i, idx = rmobile_cpuinfo_idx();
Biju Das3e5f3db2021-03-17 14:11:50 +0000107 const u8 *cpu_name = get_cpu_name(idx);
Marek Vasut00e4b572018-12-03 13:28:25 +0100108 char cpu[10] = { 0 };
109
110 for (i = 0; i < sizeof(cpu); i++)
Biju Das3e5f3db2021-03-17 14:11:50 +0000111 cpu[i] = tolower(cpu_name[i]);
Marek Vasut00e4b572018-12-03 13:28:25 +0100112
113 env_set("platform", cpu);
114
115 return 0;
116}
117#endif
118
119int print_cpuinfo(void)
120{
121 int i = rmobile_cpuinfo_idx();
122
Hiroyuki Yokoyama08260ef2018-09-26 18:14:41 +0900123 if (rmobile_cpuinfo[i].cpu_type == RMOBILE_CPU_TYPE_R8A7796 &&
124 rmobile_get_cpu_rev_integer() == 1 &&
125 rmobile_get_cpu_rev_fraction() == 1) {
126 printf("CPU: Renesas Electronics %s rev 1.1/1.2\n", get_cpu_name(i));
127 return 0;
128 }
129
Marek Vasut91c6a3a2021-07-04 17:27:27 +0200130 printf("CPU: Renesas Electronics %s rev %d.%d\n",
Biju Das3e5f3db2021-03-17 14:11:50 +0000131 get_cpu_name(i), rmobile_get_cpu_rev_integer(),
Marek Vasut00e4b572018-12-03 13:28:25 +0100132 rmobile_get_cpu_rev_fraction());
133
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +0900134 return 0;
135}
Ralph Siemsen21563272023-05-12 21:36:55 -0400136#elif defined(CONFIG_RZA1)
Chris Brandt35295962017-08-23 14:53:59 -0500137int print_cpuinfo(void)
138{
139 printf("CPU: Renesas Electronics RZ/A1\n");
140 return 0;
141}
Ralph Siemsen21563272023-05-12 21:36:55 -0400142#else /* CONFIG_RZN1 */
143int print_cpuinfo(void)
144{
145 printf("CPU: Renesas Electronics RZ/N1\n");
146 return 0;
147}
Chris Brandt35295962017-08-23 14:53:59 -0500148#endif
Nobuhiro Iwamatsu1cdf2482012-08-19 04:40:05 +0000149#endif /* CONFIG_DISPLAY_CPUINFO */