Kuninori Morimoto | 41c4567 | 2018-09-07 02:04:19 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Renesas SoC Identification |
| 4 | * |
| 5 | * Copyright (C) 2014-2016 Glider bvba |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/io.h> |
| 9 | #include <linux/of.h> |
| 10 | #include <linux/of_address.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/sys_soc.h> |
| 14 | |
| 15 | |
| 16 | struct renesas_family { |
| 17 | const char name[16]; |
| 18 | u32 reg; /* CCCR or PRR, if not in DT */ |
| 19 | }; |
| 20 | |
| 21 | static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = { |
| 22 | .name = "R-Car Gen1", |
| 23 | .reg = 0xff000044, /* PRR (Product Register) */ |
| 24 | }; |
| 25 | |
| 26 | static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = { |
| 27 | .name = "R-Car Gen2", |
| 28 | .reg = 0xff000044, /* PRR (Product Register) */ |
| 29 | }; |
| 30 | |
| 31 | static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = { |
| 32 | .name = "R-Car Gen3", |
| 33 | .reg = 0xfff00044, /* PRR (Product Register) */ |
| 34 | }; |
| 35 | |
| 36 | static const struct renesas_family fam_rmobile __initconst __maybe_unused = { |
| 37 | .name = "R-Mobile", |
| 38 | .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */ |
| 39 | }; |
| 40 | |
Chris Brandt | 175f435 | 2018-07-27 11:53:32 -0500 | [diff] [blame] | 41 | static const struct renesas_family fam_rza1 __initconst __maybe_unused = { |
| 42 | .name = "RZ/A1", |
| 43 | }; |
| 44 | |
| 45 | static const struct renesas_family fam_rza2 __initconst __maybe_unused = { |
| 46 | .name = "RZ/A2", |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 49 | static const struct renesas_family fam_rzg1 __initconst __maybe_unused = { |
| 50 | .name = "RZ/G1", |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 51 | .reg = 0xff000044, /* PRR (Product Register) */ |
| 52 | }; |
| 53 | |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 54 | static const struct renesas_family fam_rzg2 __initconst __maybe_unused = { |
| 55 | .name = "RZ/G2", |
| 56 | .reg = 0xfff00044, /* PRR (Product Register) */ |
| 57 | }; |
| 58 | |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 59 | static const struct renesas_family fam_shmobile __initconst __maybe_unused = { |
| 60 | .name = "SH-Mobile", |
| 61 | .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */ |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | struct renesas_soc { |
| 66 | const struct renesas_family *family; |
| 67 | u8 id; |
| 68 | }; |
| 69 | |
| 70 | static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = { |
Chris Brandt | 175f435 | 2018-07-27 11:53:32 -0500 | [diff] [blame] | 71 | .family = &fam_rza1, |
| 72 | }; |
| 73 | |
| 74 | static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = { |
| 75 | .family = &fam_rza2, |
| 76 | .id = 0x3b, |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = { |
| 80 | .family = &fam_rmobile, |
| 81 | .id = 0x3f, |
| 82 | }; |
| 83 | |
| 84 | static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = { |
| 85 | .family = &fam_rmobile, |
| 86 | .id = 0x40, |
| 87 | }; |
| 88 | |
Geert Uytterhoeven | 8848e1b | 2017-03-10 14:48:29 +0100 | [diff] [blame] | 89 | static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = { |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 90 | .family = &fam_rzg1, |
Geert Uytterhoeven | 8848e1b | 2017-03-10 14:48:29 +0100 | [diff] [blame] | 91 | .id = 0x45, |
| 92 | }; |
| 93 | |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 94 | static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = { |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 95 | .family = &fam_rzg1, |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 96 | .id = 0x47, |
| 97 | }; |
| 98 | |
Geert Uytterhoeven | cd59de8 | 2017-03-10 14:48:30 +0100 | [diff] [blame] | 99 | static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = { |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 100 | .family = &fam_rzg1, |
Geert Uytterhoeven | cd59de8 | 2017-03-10 14:48:30 +0100 | [diff] [blame] | 101 | .id = 0x4b, |
| 102 | }; |
| 103 | |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 104 | static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = { |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 105 | .family = &fam_rzg1, |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 106 | .id = 0x4c, |
| 107 | }; |
| 108 | |
Biju Das | 1daf13b | 2018-03-27 15:37:13 +0100 | [diff] [blame] | 109 | static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = { |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 110 | .family = &fam_rzg1, |
Biju Das | 1daf13b | 2018-03-27 15:37:13 +0100 | [diff] [blame] | 111 | .id = 0x53, |
| 112 | }; |
| 113 | |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 114 | static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = { |
| 115 | .family = &fam_rzg2, |
| 116 | .id = 0x52, |
| 117 | }; |
| 118 | |
Biju Das | 574cb72 | 2019-09-05 10:30:42 +0100 | [diff] [blame] | 119 | static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = { |
| 120 | .family = &fam_rzg2, |
| 121 | .id = 0x55, |
| 122 | }; |
| 123 | |
Fabrizio Castro | 2bab3d8 | 2018-09-10 12:53:50 +0100 | [diff] [blame] | 124 | static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = { |
| 125 | .family = &fam_rzg2, |
| 126 | .id = 0x57, |
| 127 | }; |
| 128 | |
Marian-Cristian Rotariu | 5b83cc4 | 2020-07-07 17:18:01 +0100 | [diff] [blame] | 129 | static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = { |
| 130 | .family = &fam_rzg2, |
| 131 | .id = 0x4f, |
| 132 | }; |
| 133 | |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 134 | static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = { |
| 135 | .family = &fam_rcar_gen1, |
| 136 | }; |
| 137 | |
| 138 | static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = { |
| 139 | .family = &fam_rcar_gen1, |
| 140 | .id = 0x3b, |
| 141 | }; |
| 142 | |
| 143 | static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = { |
| 144 | .family = &fam_rcar_gen2, |
| 145 | .id = 0x45, |
| 146 | }; |
| 147 | |
| 148 | static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = { |
| 149 | .family = &fam_rcar_gen2, |
| 150 | .id = 0x47, |
| 151 | }; |
| 152 | |
| 153 | static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = { |
| 154 | .family = &fam_rcar_gen2, |
| 155 | .id = 0x4a, |
| 156 | }; |
| 157 | |
| 158 | static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = { |
| 159 | .family = &fam_rcar_gen2, |
| 160 | .id = 0x4b, |
| 161 | }; |
| 162 | |
| 163 | static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = { |
| 164 | .family = &fam_rcar_gen2, |
| 165 | .id = 0x4c, |
| 166 | }; |
| 167 | |
| 168 | static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = { |
| 169 | .family = &fam_rcar_gen3, |
| 170 | .id = 0x4f, |
| 171 | }; |
| 172 | |
| 173 | static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = { |
| 174 | .family = &fam_rcar_gen3, |
| 175 | .id = 0x52, |
| 176 | }; |
| 177 | |
Jacopo Mondi | bfd8398 | 2018-02-20 16:12:05 +0100 | [diff] [blame] | 178 | static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = { |
| 179 | .family = &fam_rcar_gen3, |
| 180 | .id = 0x55, |
| 181 | }; |
| 182 | |
Sergei Shtylyov | bb003075 | 2017-09-12 23:37:17 +0300 | [diff] [blame] | 183 | static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = { |
| 184 | .family = &fam_rcar_gen3, |
| 185 | .id = 0x54, |
| 186 | }; |
| 187 | |
Sergei Shtylyov | 8447756 | 2018-02-02 21:22:14 +0300 | [diff] [blame] | 188 | static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = { |
| 189 | .family = &fam_rcar_gen3, |
| 190 | .id = 0x56, |
| 191 | }; |
| 192 | |
Takeshi Kihara | 44842d4 | 2018-04-11 18:36:23 +0900 | [diff] [blame] | 193 | static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = { |
| 194 | .family = &fam_rcar_gen3, |
| 195 | .id = 0x57, |
| 196 | }; |
| 197 | |
Geert Uytterhoeven | 1b95478 | 2017-07-20 14:34:51 +0200 | [diff] [blame] | 198 | static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = { |
| 199 | .family = &fam_rcar_gen3, |
| 200 | .id = 0x58, |
| 201 | }; |
| 202 | |
Yoshihiro Shimoda | 090e87e | 2020-09-07 18:19:45 +0900 | [diff] [blame] | 203 | static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = { |
| 204 | .family = &fam_rcar_gen3, |
| 205 | .id = 0x59, |
| 206 | }; |
| 207 | |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 208 | static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = { |
| 209 | .family = &fam_shmobile, |
| 210 | .id = 0x37, |
| 211 | }; |
| 212 | |
| 213 | |
| 214 | static const struct of_device_id renesas_socs[] __initconst = { |
| 215 | #ifdef CONFIG_ARCH_R7S72100 |
| 216 | { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h }, |
| 217 | #endif |
Chris Brandt | 175f435 | 2018-07-27 11:53:32 -0500 | [diff] [blame] | 218 | #ifdef CONFIG_ARCH_R7S9210 |
| 219 | { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m }, |
| 220 | #endif |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 221 | #ifdef CONFIG_ARCH_R8A73A4 |
| 222 | { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 }, |
| 223 | #endif |
| 224 | #ifdef CONFIG_ARCH_R8A7740 |
| 225 | { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 }, |
| 226 | #endif |
Geert Uytterhoeven | 8848e1b | 2017-03-10 14:48:29 +0100 | [diff] [blame] | 227 | #ifdef CONFIG_ARCH_R8A7742 |
| 228 | { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h }, |
| 229 | #endif |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 230 | #ifdef CONFIG_ARCH_R8A7743 |
| 231 | { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m }, |
| 232 | #endif |
Geert Uytterhoeven | cd59de8 | 2017-03-10 14:48:30 +0100 | [diff] [blame] | 233 | #ifdef CONFIG_ARCH_R8A7744 |
| 234 | { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n }, |
| 235 | #endif |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 236 | #ifdef CONFIG_ARCH_R8A7745 |
| 237 | { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e }, |
| 238 | #endif |
Biju Das | 1daf13b | 2018-03-27 15:37:13 +0100 | [diff] [blame] | 239 | #ifdef CONFIG_ARCH_R8A77470 |
| 240 | { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c }, |
| 241 | #endif |
Biju Das | 2a4056a7 | 2018-07-24 16:47:18 +0100 | [diff] [blame] | 242 | #ifdef CONFIG_ARCH_R8A774A1 |
| 243 | { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m }, |
| 244 | #endif |
Biju Das | 574cb72 | 2019-09-05 10:30:42 +0100 | [diff] [blame] | 245 | #ifdef CONFIG_ARCH_R8A774B1 |
| 246 | { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n }, |
| 247 | #endif |
Fabrizio Castro | 2bab3d8 | 2018-09-10 12:53:50 +0100 | [diff] [blame] | 248 | #ifdef CONFIG_ARCH_R8A774C0 |
| 249 | { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e }, |
| 250 | #endif |
Marian-Cristian Rotariu | 5b83cc4 | 2020-07-07 17:18:01 +0100 | [diff] [blame] | 251 | #ifdef CONFIG_ARCH_R8A774E1 |
| 252 | { .compatible = "renesas,r8a774e1", .data = &soc_rz_g2h }, |
| 253 | #endif |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 254 | #ifdef CONFIG_ARCH_R8A7778 |
| 255 | { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a }, |
| 256 | #endif |
| 257 | #ifdef CONFIG_ARCH_R8A7779 |
| 258 | { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 }, |
| 259 | #endif |
| 260 | #ifdef CONFIG_ARCH_R8A7790 |
| 261 | { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 }, |
| 262 | #endif |
| 263 | #ifdef CONFIG_ARCH_R8A7791 |
| 264 | { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w }, |
| 265 | #endif |
| 266 | #ifdef CONFIG_ARCH_R8A7792 |
| 267 | { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h }, |
| 268 | #endif |
| 269 | #ifdef CONFIG_ARCH_R8A7793 |
| 270 | { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n }, |
| 271 | #endif |
| 272 | #ifdef CONFIG_ARCH_R8A7794 |
| 273 | { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 }, |
| 274 | #endif |
Geert Uytterhoeven | 4ff2711 | 2020-02-18 12:24:49 +0100 | [diff] [blame] | 275 | #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951) |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 276 | { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 }, |
| 277 | #endif |
Geert Uytterhoeven | 39e57e1 | 2019-10-23 14:33:33 +0200 | [diff] [blame] | 278 | #ifdef CONFIG_ARCH_R8A77960 |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 279 | { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w }, |
| 280 | #endif |
Geert Uytterhoeven | 9c9f789 | 2019-10-23 14:33:35 +0200 | [diff] [blame] | 281 | #ifdef CONFIG_ARCH_R8A77961 |
| 282 | { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w }, |
| 283 | #endif |
Jacopo Mondi | bfd8398 | 2018-02-20 16:12:05 +0100 | [diff] [blame] | 284 | #ifdef CONFIG_ARCH_R8A77965 |
| 285 | { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n }, |
| 286 | #endif |
Sergei Shtylyov | bb003075 | 2017-09-12 23:37:17 +0300 | [diff] [blame] | 287 | #ifdef CONFIG_ARCH_R8A77970 |
| 288 | { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m }, |
| 289 | #endif |
Sergei Shtylyov | 8447756 | 2018-02-02 21:22:14 +0300 | [diff] [blame] | 290 | #ifdef CONFIG_ARCH_R8A77980 |
| 291 | { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h }, |
| 292 | #endif |
Takeshi Kihara | 44842d4 | 2018-04-11 18:36:23 +0900 | [diff] [blame] | 293 | #ifdef CONFIG_ARCH_R8A77990 |
| 294 | { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 }, |
| 295 | #endif |
Geert Uytterhoeven | 1b95478 | 2017-07-20 14:34:51 +0200 | [diff] [blame] | 296 | #ifdef CONFIG_ARCH_R8A77995 |
| 297 | { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 }, |
| 298 | #endif |
Yoshihiro Shimoda | 090e87e | 2020-09-07 18:19:45 +0900 | [diff] [blame] | 299 | #ifdef CONFIG_ARCH_R8A779A0 |
| 300 | { .compatible = "renesas,r8a779a0", .data = &soc_rcar_v3u }, |
| 301 | #endif |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 302 | #ifdef CONFIG_ARCH_SH73A0 |
| 303 | { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 }, |
| 304 | #endif |
| 305 | { /* sentinel */ } |
| 306 | }; |
| 307 | |
| 308 | static int __init renesas_soc_init(void) |
| 309 | { |
| 310 | struct soc_device_attribute *soc_dev_attr; |
| 311 | const struct renesas_family *family; |
| 312 | const struct of_device_id *match; |
| 313 | const struct renesas_soc *soc; |
| 314 | void __iomem *chipid = NULL; |
| 315 | struct soc_device *soc_dev; |
| 316 | struct device_node *np; |
Chris Brandt | 175f435 | 2018-07-27 11:53:32 -0500 | [diff] [blame] | 317 | unsigned int product, eshi = 0, eslo; |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 318 | |
| 319 | match = of_match_node(renesas_socs, of_root); |
| 320 | if (!match) |
| 321 | return -ENODEV; |
| 322 | |
| 323 | soc = match->data; |
| 324 | family = soc->family; |
| 325 | |
Chris Brandt | 175f435 | 2018-07-27 11:53:32 -0500 | [diff] [blame] | 326 | np = of_find_compatible_node(NULL, NULL, "renesas,bsid"); |
| 327 | if (np) { |
| 328 | chipid = of_iomap(np, 0); |
| 329 | of_node_put(np); |
| 330 | |
| 331 | if (chipid) { |
| 332 | product = readl(chipid); |
| 333 | iounmap(chipid); |
| 334 | |
| 335 | if (soc->id && ((product >> 16) & 0xff) != soc->id) { |
| 336 | pr_warn("SoC mismatch (product = 0x%x)\n", |
| 337 | product); |
| 338 | return -ENODEV; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | * TODO: Upper 4 bits of BSID are for chip version, but the |
| 344 | * format is not known at this time so we don't know how to |
| 345 | * specify eshi and eslo |
| 346 | */ |
| 347 | |
| 348 | goto done; |
| 349 | } |
| 350 | |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 351 | /* Try PRR first, then hardcoded fallback */ |
| 352 | np = of_find_compatible_node(NULL, NULL, "renesas,prr"); |
| 353 | if (np) { |
| 354 | chipid = of_iomap(np, 0); |
| 355 | of_node_put(np); |
Geert Uytterhoeven | 4194b58 | 2019-10-16 16:33:06 +0200 | [diff] [blame] | 356 | } else if (soc->id && family->reg) { |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 357 | chipid = ioremap(family->reg, 4); |
| 358 | } |
| 359 | if (chipid) { |
| 360 | product = readl(chipid); |
| 361 | iounmap(chipid); |
Geert Uytterhoeven | 90f0d2b | 2017-10-30 18:29:58 +0100 | [diff] [blame] | 362 | /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */ |
| 363 | if ((product & 0x7fff) == 0x5210) |
| 364 | product ^= 0x11; |
Takeshi Kihara | 15160f6 | 2019-02-28 12:00:48 +0100 | [diff] [blame] | 365 | /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */ |
| 366 | if ((product & 0x7fff) == 0x5211) |
| 367 | product ^= 0x12; |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 368 | if (soc->id && ((product >> 8) & 0xff) != soc->id) { |
| 369 | pr_warn("SoC mismatch (product = 0x%x)\n", product); |
| 370 | return -ENODEV; |
| 371 | } |
Chris Brandt | 175f435 | 2018-07-27 11:53:32 -0500 | [diff] [blame] | 372 | eshi = ((product >> 4) & 0x0f) + 1; |
| 373 | eslo = product & 0xf; |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 374 | } |
| 375 | |
Chris Brandt | 175f435 | 2018-07-27 11:53:32 -0500 | [diff] [blame] | 376 | done: |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 377 | soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); |
| 378 | if (!soc_dev_attr) |
| 379 | return -ENOMEM; |
| 380 | |
| 381 | np = of_find_node_by_path("/"); |
| 382 | of_property_read_string(np, "model", &soc_dev_attr->machine); |
| 383 | of_node_put(np); |
| 384 | |
| 385 | soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL); |
| 386 | soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1, |
| 387 | GFP_KERNEL); |
Chris Brandt | 175f435 | 2018-07-27 11:53:32 -0500 | [diff] [blame] | 388 | if (eshi) |
| 389 | soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi, |
| 390 | eslo); |
Geert Uytterhoeven | 8d6799a | 2016-11-14 19:37:08 +0100 | [diff] [blame] | 391 | |
| 392 | pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family, |
| 393 | soc_dev_attr->soc_id, soc_dev_attr->revision ?: ""); |
| 394 | |
| 395 | soc_dev = soc_device_register(soc_dev_attr); |
| 396 | if (IS_ERR(soc_dev)) { |
| 397 | kfree(soc_dev_attr->revision); |
| 398 | kfree_const(soc_dev_attr->soc_id); |
| 399 | kfree_const(soc_dev_attr->family); |
| 400 | kfree(soc_dev_attr); |
| 401 | return PTR_ERR(soc_dev); |
| 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
Geert Uytterhoeven | b1d134b | 2017-03-31 11:01:54 +0200 | [diff] [blame] | 406 | early_initcall(renesas_soc_init); |