blob: 2f9a4374a9687baf2b4ff7fd546ef00acd0a6915 [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 */
Paul Barker93565cc2023-11-01 20:05:53 +00006
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
Marek Vasut217d7192024-02-27 17:05:50 +010039__weak u32 renesas_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}
43
Marek Vasut217d7192024-02-27 17:05:50 +010044__weak u32 renesas_get_cpu_rev_integer(void)
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090045{
Nobuhiro Iwamatsu1cdf2482012-08-19 04:40:05 +000046 return 0;
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090047}
Tetsuyuki Kobayashi4f007b82012-07-25 18:24:21 +000048
Marek Vasut217d7192024-02-27 17:05:50 +010049__weak u32 renesas_get_cpu_rev_fraction(void)
Tetsuyuki Kobayashi4f007b82012-07-25 18:24:21 +000050{
51 return 0;
52}
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090053
Biju Das3e5f3db2021-03-17 14:11:50 +000054/* CPU information table */
Nobuhiro Iwamatsu73ff6802014-03-28 11:54:22 +090055static const struct {
56 u16 cpu_type;
57 u8 cpu_name[10];
Marek Vasut18c3f3a2024-02-27 17:05:49 +010058} renesas_cpuinfo[] = {
Marek Vasutc2cffb02024-02-27 17:05:47 +010059 { RENESAS_CPU_TYPE_R8A7790, "R8A7790" },
60 { RENESAS_CPU_TYPE_R8A7791, "R8A7791" },
61 { RENESAS_CPU_TYPE_R8A7792, "R8A7792" },
62 { RENESAS_CPU_TYPE_R8A7793, "R8A7793" },
63 { RENESAS_CPU_TYPE_R8A7794, "R8A7794" },
64 { RENESAS_CPU_TYPE_R8A7795, "R8A7795" },
65 { RENESAS_CPU_TYPE_R8A7796, "R8A7796" },
66 { RENESAS_CPU_TYPE_R8A77965, "R8A77965" },
67 { RENESAS_CPU_TYPE_R8A77970, "R8A77970" },
68 { RENESAS_CPU_TYPE_R8A77980, "R8A77980" },
69 { RENESAS_CPU_TYPE_R8A77990, "R8A77990" },
70 { RENESAS_CPU_TYPE_R8A77995, "R8A77995" },
71 { RENESAS_CPU_TYPE_R8A779A0, "R8A779A0" },
72 { RENESAS_CPU_TYPE_R8A779F0, "R8A779F0" },
73 { RENESAS_CPU_TYPE_R8A779G0, "R8A779G0" },
74 { RENESAS_CPU_TYPE_R8A779H0, "R8A779H0" },
Nobuhiro Iwamatsu73ff6802014-03-28 11:54:22 +090075 { 0x0, "CPU" },
76};
77
Marek Vasut74215bb2024-02-27 17:05:48 +010078static int renesas_cpuinfo_idx(void)
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +090079{
Marek Vasut6bd3a952024-02-27 17:05:45 +010080 u32 cpu_type = renesas_get_cpu_type();
Marek Vasut96912a92023-08-19 16:39:13 +020081 int i;
Marek Vasut00e4b572018-12-03 13:28:25 +010082
Marek Vasut18c3f3a2024-02-27 17:05:49 +010083 for (i = 0; i < ARRAY_SIZE(renesas_cpuinfo) - 1; i++)
84 if (renesas_cpuinfo[i].cpu_type == cpu_type)
Marek Vasut96912a92023-08-19 16:39:13 +020085 return i;
Marek Vasut00e4b572018-12-03 13:28:25 +010086
Marek Vasut96912a92023-08-19 16:39:13 +020087 /* Unknown "CPU" entry */
Marek Vasut18c3f3a2024-02-27 17:05:49 +010088 return ARRAY_SIZE(renesas_cpuinfo) - 1;
Marek Vasut00e4b572018-12-03 13:28:25 +010089}
90
Biju Das3e5f3db2021-03-17 14:11:50 +000091static const u8 *get_cpu_name(int idx)
92{
93 const u8 *cpu_name = rzg_get_cpu_name();
94
Marek Vasut18c3f3a2024-02-27 17:05:49 +010095 return cpu_name ? cpu_name : renesas_cpuinfo[idx].cpu_name;
Biju Das3e5f3db2021-03-17 14:11:50 +000096}
97
Marek Vasut00e4b572018-12-03 13:28:25 +010098#ifdef CONFIG_ARCH_MISC_INIT
99int arch_misc_init(void)
100{
Marek Vasut74215bb2024-02-27 17:05:48 +0100101 int i, idx = renesas_cpuinfo_idx();
Biju Das3e5f3db2021-03-17 14:11:50 +0000102 const u8 *cpu_name = get_cpu_name(idx);
Marek Vasut00e4b572018-12-03 13:28:25 +0100103 char cpu[10] = { 0 };
104
105 for (i = 0; i < sizeof(cpu); i++)
Biju Das3e5f3db2021-03-17 14:11:50 +0000106 cpu[i] = tolower(cpu_name[i]);
Marek Vasut00e4b572018-12-03 13:28:25 +0100107
108 env_set("platform", cpu);
109
110 return 0;
111}
112#endif
113
114int print_cpuinfo(void)
115{
Marek Vasut74215bb2024-02-27 17:05:48 +0100116 int i = renesas_cpuinfo_idx();
Marek Vasut00e4b572018-12-03 13:28:25 +0100117
Marek Vasut18c3f3a2024-02-27 17:05:49 +0100118 if (renesas_cpuinfo[i].cpu_type == RENESAS_CPU_TYPE_R8A7796 &&
Marek Vasutca40ed62024-02-27 17:05:46 +0100119 renesas_get_cpu_rev_integer() == 1 &&
120 renesas_get_cpu_rev_fraction() == 1) {
Hiroyuki Yokoyama08260ef2018-09-26 18:14:41 +0900121 printf("CPU: Renesas Electronics %s rev 1.1/1.2\n", get_cpu_name(i));
122 return 0;
123 }
124
Marek Vasut91c6a3a2021-07-04 17:27:27 +0200125 printf("CPU: Renesas Electronics %s rev %d.%d\n",
Marek Vasutca40ed62024-02-27 17:05:46 +0100126 get_cpu_name(i), renesas_get_cpu_rev_integer(),
127 renesas_get_cpu_rev_fraction());
Marek Vasut00e4b572018-12-03 13:28:25 +0100128
Nobuhiro Iwamatsu4fb44e22012-06-13 16:29:47 +0900129 return 0;
130}
Ralph Siemsen21563272023-05-12 21:36:55 -0400131#elif defined(CONFIG_RZA1)
Chris Brandt35295962017-08-23 14:53:59 -0500132int print_cpuinfo(void)
133{
134 printf("CPU: Renesas Electronics RZ/A1\n");
135 return 0;
136}
Ralph Siemsen21563272023-05-12 21:36:55 -0400137#else /* CONFIG_RZN1 */
138int print_cpuinfo(void)
139{
140 printf("CPU: Renesas Electronics RZ/N1\n");
141 return 0;
142}
Chris Brandt35295962017-08-23 14:53:59 -0500143#endif
Nobuhiro Iwamatsu1cdf2482012-08-19 04:40:05 +0000144#endif /* CONFIG_DISPLAY_CPUINFO */