blob: 35cfef2e1ab0e69d3d850ff27e061a0935f388a1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +09002/*
3 * (C) Copyright 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
Biju Das2f611af2021-03-17 14:11:50 +00004 * (C) Copyright 2012-2021 Renesas Solutions Corp.
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +09005 */
Paul Barker442ce1c2023-11-01 20:05:53 +00006
Simon Glass1d91ba72019-11-14 12:57:37 -07007#include <cpu_func.h>
Simon Glass274e0b02020-05-10 11:39:56 -06008#include <asm/cache.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090010#include <asm/io.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Marek Vasutb90dc692018-12-03 13:28:25 +010012#include <linux/ctype.h>
Nobuhiro Iwamatsuf3db9da2012-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 Pham9046b5f2023-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 Woerner43ec7e02019-05-03 09:41:00 -040024#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090025void enable_caches(void)
26{
27 dcache_enable();
28}
29#endif
Marek Vasut970fd8c2018-10-31 15:06:50 +010030#endif
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090031
32#ifdef CONFIG_DISPLAY_CPUINFO
Ralph Siemsen7159e2c2023-05-12 21:36:55 -040033#if !defined(CONFIG_RZA1) && !defined(CONFIG_RZN1)
Biju Das2f611af2021-03-17 14:11:50 +000034__weak const u8 *rzg_get_cpu_name(void)
35{
36 return 0;
37}
38
Nobuhiro Iwamatsu940103d2012-08-19 04:40:05 +000039static u32 __rmobile_get_cpu_type(void)
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090040{
Nobuhiro Iwamatsu940103d2012-08-19 04:40:05 +000041 return 0x0;
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090042}
Marek Vasut30fe98e2024-02-27 17:05:45 +010043u32 renesas_get_cpu_type(void)
Nobuhiro Iwamatsu940103d2012-08-19 04:40:05 +000044 __attribute__((weak, alias("__rmobile_get_cpu_type")));
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090045
Tetsuyuki Kobayashi7811e542012-07-25 18:24:21 +000046static u32 __rmobile_get_cpu_rev_integer(void)
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090047{
Nobuhiro Iwamatsu940103d2012-08-19 04:40:05 +000048 return 0;
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090049}
Marek Vasut17602322024-02-27 17:05:46 +010050u32 renesas_get_cpu_rev_integer(void)
Tetsuyuki Kobayashi7811e542012-07-25 18:24:21 +000051 __attribute__((weak, alias("__rmobile_get_cpu_rev_integer")));
52
53static u32 __rmobile_get_cpu_rev_fraction(void)
54{
55 return 0;
56}
Marek Vasut17602322024-02-27 17:05:46 +010057u32 renesas_get_cpu_rev_fraction(void)
Tetsuyuki Kobayashi7811e542012-07-25 18:24:21 +000058 __attribute__((weak, alias("__rmobile_get_cpu_rev_fraction")));
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090059
Biju Das2f611af2021-03-17 14:11:50 +000060/* CPU information table */
Nobuhiro Iwamatsu524ed8b2014-03-28 11:54:22 +090061static const struct {
62 u16 cpu_type;
63 u8 cpu_name[10];
64} rmobile_cpuinfo[] = {
Marek Vasutb8f814b2017-11-25 23:54:10 +010065 { RMOBILE_CPU_TYPE_R8A7790, "R8A7790" },
66 { RMOBILE_CPU_TYPE_R8A7791, "R8A7791" },
67 { RMOBILE_CPU_TYPE_R8A7792, "R8A7792" },
68 { RMOBILE_CPU_TYPE_R8A7793, "R8A7793" },
69 { RMOBILE_CPU_TYPE_R8A7794, "R8A7794" },
70 { RMOBILE_CPU_TYPE_R8A7795, "R8A7795" },
71 { RMOBILE_CPU_TYPE_R8A7796, "R8A7796" },
Marek Vasut1ecc0bd2018-02-26 10:35:15 +010072 { RMOBILE_CPU_TYPE_R8A77965, "R8A77965" },
Marek Vasut46175fc2017-10-09 20:39:47 +020073 { RMOBILE_CPU_TYPE_R8A77970, "R8A77970" },
Marek Vasutcf567852019-07-29 19:59:44 +020074 { RMOBILE_CPU_TYPE_R8A77980, "R8A77980" },
Marek Vasut001dbf32018-04-26 10:09:06 +020075 { RMOBILE_CPU_TYPE_R8A77990, "R8A77990" },
Marek Vasut04cd2e22017-10-08 20:52:52 +020076 { RMOBILE_CPU_TYPE_R8A77995, "R8A77995" },
Hai Pham47fc7be2020-05-21 14:11:13 +070077 { RMOBILE_CPU_TYPE_R8A779A0, "R8A779A0" },
Hai Phamb35c7182023-02-28 22:34:45 +010078 { RMOBILE_CPU_TYPE_R8A779F0, "R8A779F0" },
Hai Pham09c8cdf2023-02-28 22:37:07 +010079 { RMOBILE_CPU_TYPE_R8A779G0, "R8A779G0" },
Hai Phama7ce29a2024-01-28 16:52:04 +010080 { RMOBILE_CPU_TYPE_R8A779H0, "R8A779H0" },
Nobuhiro Iwamatsu524ed8b2014-03-28 11:54:22 +090081 { 0x0, "CPU" },
82};
83
Marek Vasutb90dc692018-12-03 13:28:25 +010084static int rmobile_cpuinfo_idx(void)
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +090085{
Marek Vasut30fe98e2024-02-27 17:05:45 +010086 u32 cpu_type = renesas_get_cpu_type();
Marek Vasutd1eb93b2023-08-19 16:39:13 +020087 int i;
Marek Vasutb90dc692018-12-03 13:28:25 +010088
Marek Vasutd1eb93b2023-08-19 16:39:13 +020089 for (i = 0; i < ARRAY_SIZE(rmobile_cpuinfo) - 1; i++)
Marek Vasutb90dc692018-12-03 13:28:25 +010090 if (rmobile_cpuinfo[i].cpu_type == cpu_type)
Marek Vasutd1eb93b2023-08-19 16:39:13 +020091 return i;
Marek Vasutb90dc692018-12-03 13:28:25 +010092
Marek Vasutd1eb93b2023-08-19 16:39:13 +020093 /* Unknown "CPU" entry */
94 return ARRAY_SIZE(rmobile_cpuinfo) - 1;
Marek Vasutb90dc692018-12-03 13:28:25 +010095}
96
Biju Das2f611af2021-03-17 14:11:50 +000097static const u8 *get_cpu_name(int idx)
98{
99 const u8 *cpu_name = rzg_get_cpu_name();
100
101 return cpu_name ? cpu_name : rmobile_cpuinfo[idx].cpu_name;
102}
103
Marek Vasutb90dc692018-12-03 13:28:25 +0100104#ifdef CONFIG_ARCH_MISC_INIT
105int arch_misc_init(void)
106{
107 int i, idx = rmobile_cpuinfo_idx();
Biju Das2f611af2021-03-17 14:11:50 +0000108 const u8 *cpu_name = get_cpu_name(idx);
Marek Vasutb90dc692018-12-03 13:28:25 +0100109 char cpu[10] = { 0 };
110
111 for (i = 0; i < sizeof(cpu); i++)
Biju Das2f611af2021-03-17 14:11:50 +0000112 cpu[i] = tolower(cpu_name[i]);
Marek Vasutb90dc692018-12-03 13:28:25 +0100113
114 env_set("platform", cpu);
115
116 return 0;
117}
118#endif
119
120int print_cpuinfo(void)
121{
122 int i = rmobile_cpuinfo_idx();
123
Hiroyuki Yokoyama1c6f3dc2018-09-26 18:14:41 +0900124 if (rmobile_cpuinfo[i].cpu_type == RMOBILE_CPU_TYPE_R8A7796 &&
Marek Vasut17602322024-02-27 17:05:46 +0100125 renesas_get_cpu_rev_integer() == 1 &&
126 renesas_get_cpu_rev_fraction() == 1) {
Hiroyuki Yokoyama1c6f3dc2018-09-26 18:14:41 +0900127 printf("CPU: Renesas Electronics %s rev 1.1/1.2\n", get_cpu_name(i));
128 return 0;
129 }
130
Marek Vasut5dea8b42021-07-04 17:27:27 +0200131 printf("CPU: Renesas Electronics %s rev %d.%d\n",
Marek Vasut17602322024-02-27 17:05:46 +0100132 get_cpu_name(i), renesas_get_cpu_rev_integer(),
133 renesas_get_cpu_rev_fraction());
Marek Vasutb90dc692018-12-03 13:28:25 +0100134
Nobuhiro Iwamatsuf3db9da2012-06-13 16:29:47 +0900135 return 0;
136}
Ralph Siemsen7159e2c2023-05-12 21:36:55 -0400137#elif defined(CONFIG_RZA1)
Chris Brandt43b11d92017-08-23 14:53:59 -0500138int print_cpuinfo(void)
139{
140 printf("CPU: Renesas Electronics RZ/A1\n");
141 return 0;
142}
Ralph Siemsen7159e2c2023-05-12 21:36:55 -0400143#else /* CONFIG_RZN1 */
144int print_cpuinfo(void)
145{
146 printf("CPU: Renesas Electronics RZ/N1\n");
147 return 0;
148}
Chris Brandt43b11d92017-08-23 14:53:59 -0500149#endif
Nobuhiro Iwamatsu940103d2012-08-19 04:40:05 +0000150#endif /* CONFIG_DISPLAY_CPUINFO */