Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com> |
Biju Das | 2f611af | 2021-03-17 14:11:50 +0000 | [diff] [blame] | 4 | * (C) Copyright 2012-2021 Renesas Solutions Corp. |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 5 | */ |
Paul Barker | 442ce1c | 2023-11-01 20:05:53 +0000 | [diff] [blame] | 6 | |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 8 | #include <asm/cache.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 10 | #include <asm/io.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 12 | #include <linux/ctype.h> |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 13 | |
| 14 | #ifdef CONFIG_ARCH_CPU_INIT |
| 15 | int arch_cpu_init(void) |
| 16 | { |
| 17 | icache_enable(); |
| 18 | return 0; |
| 19 | } |
| 20 | #endif |
| 21 | |
Hai Pham | 9046b5f | 2023-02-28 22:22:03 +0100 | [diff] [blame] | 22 | /* R-Car Gen3 and Gen4 D-cache is enabled in memmap-gen3.c */ |
| 23 | #ifndef CONFIG_RCAR_64 |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 24 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 25 | void enable_caches(void) |
| 26 | { |
| 27 | dcache_enable(); |
| 28 | } |
| 29 | #endif |
Marek Vasut | 970fd8c | 2018-10-31 15:06:50 +0100 | [diff] [blame] | 30 | #endif |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 31 | |
| 32 | #ifdef CONFIG_DISPLAY_CPUINFO |
Ralph Siemsen | 7159e2c | 2023-05-12 21:36:55 -0400 | [diff] [blame] | 33 | #if !defined(CONFIG_RZA1) && !defined(CONFIG_RZN1) |
Biju Das | 2f611af | 2021-03-17 14:11:50 +0000 | [diff] [blame] | 34 | __weak const u8 *rzg_get_cpu_name(void) |
| 35 | { |
| 36 | return 0; |
| 37 | } |
| 38 | |
Nobuhiro Iwamatsu | 940103d | 2012-08-19 04:40:05 +0000 | [diff] [blame] | 39 | static u32 __rmobile_get_cpu_type(void) |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 40 | { |
Nobuhiro Iwamatsu | 940103d | 2012-08-19 04:40:05 +0000 | [diff] [blame] | 41 | return 0x0; |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 42 | } |
Marek Vasut | 30fe98e | 2024-02-27 17:05:45 +0100 | [diff] [blame] | 43 | u32 renesas_get_cpu_type(void) |
Nobuhiro Iwamatsu | 940103d | 2012-08-19 04:40:05 +0000 | [diff] [blame] | 44 | __attribute__((weak, alias("__rmobile_get_cpu_type"))); |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 45 | |
Tetsuyuki Kobayashi | 7811e54 | 2012-07-25 18:24:21 +0000 | [diff] [blame] | 46 | static u32 __rmobile_get_cpu_rev_integer(void) |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 47 | { |
Nobuhiro Iwamatsu | 940103d | 2012-08-19 04:40:05 +0000 | [diff] [blame] | 48 | return 0; |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 49 | } |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 50 | u32 renesas_get_cpu_rev_integer(void) |
Tetsuyuki Kobayashi | 7811e54 | 2012-07-25 18:24:21 +0000 | [diff] [blame] | 51 | __attribute__((weak, alias("__rmobile_get_cpu_rev_integer"))); |
| 52 | |
| 53 | static u32 __rmobile_get_cpu_rev_fraction(void) |
| 54 | { |
| 55 | return 0; |
| 56 | } |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 57 | u32 renesas_get_cpu_rev_fraction(void) |
Tetsuyuki Kobayashi | 7811e54 | 2012-07-25 18:24:21 +0000 | [diff] [blame] | 58 | __attribute__((weak, alias("__rmobile_get_cpu_rev_fraction"))); |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 59 | |
Biju Das | 2f611af | 2021-03-17 14:11:50 +0000 | [diff] [blame] | 60 | /* CPU information table */ |
Nobuhiro Iwamatsu | 524ed8b | 2014-03-28 11:54:22 +0900 | [diff] [blame] | 61 | static const struct { |
| 62 | u16 cpu_type; |
| 63 | u8 cpu_name[10]; |
| 64 | } rmobile_cpuinfo[] = { |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 65 | { RENESAS_CPU_TYPE_R8A7790, "R8A7790" }, |
| 66 | { RENESAS_CPU_TYPE_R8A7791, "R8A7791" }, |
| 67 | { RENESAS_CPU_TYPE_R8A7792, "R8A7792" }, |
| 68 | { RENESAS_CPU_TYPE_R8A7793, "R8A7793" }, |
| 69 | { RENESAS_CPU_TYPE_R8A7794, "R8A7794" }, |
| 70 | { RENESAS_CPU_TYPE_R8A7795, "R8A7795" }, |
| 71 | { RENESAS_CPU_TYPE_R8A7796, "R8A7796" }, |
| 72 | { RENESAS_CPU_TYPE_R8A77965, "R8A77965" }, |
| 73 | { RENESAS_CPU_TYPE_R8A77970, "R8A77970" }, |
| 74 | { RENESAS_CPU_TYPE_R8A77980, "R8A77980" }, |
| 75 | { RENESAS_CPU_TYPE_R8A77990, "R8A77990" }, |
| 76 | { RENESAS_CPU_TYPE_R8A77995, "R8A77995" }, |
| 77 | { RENESAS_CPU_TYPE_R8A779A0, "R8A779A0" }, |
| 78 | { RENESAS_CPU_TYPE_R8A779F0, "R8A779F0" }, |
| 79 | { RENESAS_CPU_TYPE_R8A779G0, "R8A779G0" }, |
| 80 | { RENESAS_CPU_TYPE_R8A779H0, "R8A779H0" }, |
Nobuhiro Iwamatsu | 524ed8b | 2014-03-28 11:54:22 +0900 | [diff] [blame] | 81 | { 0x0, "CPU" }, |
| 82 | }; |
| 83 | |
Marek Vasut | 995f97a | 2024-02-27 17:05:48 +0100 | [diff] [blame^] | 84 | static int renesas_cpuinfo_idx(void) |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 85 | { |
Marek Vasut | 30fe98e | 2024-02-27 17:05:45 +0100 | [diff] [blame] | 86 | u32 cpu_type = renesas_get_cpu_type(); |
Marek Vasut | d1eb93b | 2023-08-19 16:39:13 +0200 | [diff] [blame] | 87 | int i; |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 88 | |
Marek Vasut | d1eb93b | 2023-08-19 16:39:13 +0200 | [diff] [blame] | 89 | for (i = 0; i < ARRAY_SIZE(rmobile_cpuinfo) - 1; i++) |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 90 | if (rmobile_cpuinfo[i].cpu_type == cpu_type) |
Marek Vasut | d1eb93b | 2023-08-19 16:39:13 +0200 | [diff] [blame] | 91 | return i; |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 92 | |
Marek Vasut | d1eb93b | 2023-08-19 16:39:13 +0200 | [diff] [blame] | 93 | /* Unknown "CPU" entry */ |
| 94 | return ARRAY_SIZE(rmobile_cpuinfo) - 1; |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Biju Das | 2f611af | 2021-03-17 14:11:50 +0000 | [diff] [blame] | 97 | static 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 Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 104 | #ifdef CONFIG_ARCH_MISC_INIT |
| 105 | int arch_misc_init(void) |
| 106 | { |
Marek Vasut | 995f97a | 2024-02-27 17:05:48 +0100 | [diff] [blame^] | 107 | int i, idx = renesas_cpuinfo_idx(); |
Biju Das | 2f611af | 2021-03-17 14:11:50 +0000 | [diff] [blame] | 108 | const u8 *cpu_name = get_cpu_name(idx); |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 109 | char cpu[10] = { 0 }; |
| 110 | |
| 111 | for (i = 0; i < sizeof(cpu); i++) |
Biju Das | 2f611af | 2021-03-17 14:11:50 +0000 | [diff] [blame] | 112 | cpu[i] = tolower(cpu_name[i]); |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 113 | |
| 114 | env_set("platform", cpu); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | int print_cpuinfo(void) |
| 121 | { |
Marek Vasut | 995f97a | 2024-02-27 17:05:48 +0100 | [diff] [blame^] | 122 | int i = renesas_cpuinfo_idx(); |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 123 | |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 124 | if (rmobile_cpuinfo[i].cpu_type == RENESAS_CPU_TYPE_R8A7796 && |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 125 | renesas_get_cpu_rev_integer() == 1 && |
| 126 | renesas_get_cpu_rev_fraction() == 1) { |
Hiroyuki Yokoyama | 1c6f3dc | 2018-09-26 18:14:41 +0900 | [diff] [blame] | 127 | printf("CPU: Renesas Electronics %s rev 1.1/1.2\n", get_cpu_name(i)); |
| 128 | return 0; |
| 129 | } |
| 130 | |
Marek Vasut | 5dea8b4 | 2021-07-04 17:27:27 +0200 | [diff] [blame] | 131 | printf("CPU: Renesas Electronics %s rev %d.%d\n", |
Marek Vasut | 1760232 | 2024-02-27 17:05:46 +0100 | [diff] [blame] | 132 | get_cpu_name(i), renesas_get_cpu_rev_integer(), |
| 133 | renesas_get_cpu_rev_fraction()); |
Marek Vasut | b90dc69 | 2018-12-03 13:28:25 +0100 | [diff] [blame] | 134 | |
Nobuhiro Iwamatsu | f3db9da | 2012-06-13 16:29:47 +0900 | [diff] [blame] | 135 | return 0; |
| 136 | } |
Ralph Siemsen | 7159e2c | 2023-05-12 21:36:55 -0400 | [diff] [blame] | 137 | #elif defined(CONFIG_RZA1) |
Chris Brandt | 43b11d9 | 2017-08-23 14:53:59 -0500 | [diff] [blame] | 138 | int print_cpuinfo(void) |
| 139 | { |
| 140 | printf("CPU: Renesas Electronics RZ/A1\n"); |
| 141 | return 0; |
| 142 | } |
Ralph Siemsen | 7159e2c | 2023-05-12 21:36:55 -0400 | [diff] [blame] | 143 | #else /* CONFIG_RZN1 */ |
| 144 | int print_cpuinfo(void) |
| 145 | { |
| 146 | printf("CPU: Renesas Electronics RZ/N1\n"); |
| 147 | return 0; |
| 148 | } |
Chris Brandt | 43b11d9 | 2017-08-23 14:53:59 -0500 | [diff] [blame] | 149 | #endif |
Nobuhiro Iwamatsu | 940103d | 2012-08-19 04:40:05 +0000 | [diff] [blame] | 150 | #endif /* CONFIG_DISPLAY_CPUINFO */ |