1 // SPDX-License-Identifier: GPL-2.0
3 * Renesas SoC Identification
5 * Copyright (C) 2014-2016 Glider bvba
10 #include <linux/of_address.h>
11 #include <linux/slab.h>
12 #include <linux/string.h>
13 #include <linux/sys_soc.h>
15 struct renesas_family {
17 u32 reg; /* CCCR or PRR, if not in DT */
20 static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
22 .reg = 0xff000044, /* PRR (Product Register) */
25 static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
27 .reg = 0xff000044, /* PRR (Product Register) */
30 static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
32 .reg = 0xfff00044, /* PRR (Product Register) */
35 static const struct renesas_family fam_rcar_gen4 __initconst __maybe_unused = {
39 static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
41 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
44 static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
48 static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
52 static const struct renesas_family fam_rzfive __initconst __maybe_unused = {
56 static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
58 .reg = 0xff000044, /* PRR (Product Register) */
61 static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
63 .reg = 0xfff00044, /* PRR (Product Register) */
66 static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
70 static const struct renesas_family fam_rzg2ul __initconst __maybe_unused = {
74 static const struct renesas_family fam_rzg3s __initconst __maybe_unused = {
78 static const struct renesas_family fam_rzv2h __initconst __maybe_unused = {
82 static const struct renesas_family fam_rzv2l __initconst __maybe_unused = {
86 static const struct renesas_family fam_rzv2m __initconst __maybe_unused = {
90 static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
92 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
96 const struct renesas_family *family;
100 static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
104 static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
109 static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
110 .family = &fam_rmobile,
114 static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
115 .family = &fam_rmobile,
119 static const struct renesas_soc soc_rz_five __initconst __maybe_unused = {
120 .family = &fam_rzfive,
124 static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
129 static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
134 static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
139 static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
144 static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
149 static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
154 static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
159 static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
164 static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
169 static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
170 .family = &fam_rzg2l,
174 static const struct renesas_soc soc_rz_g2ul __initconst __maybe_unused = {
175 .family = &fam_rzg2ul,
179 static const struct renesas_soc soc_rz_g3s __initconst __maybe_unused = {
180 .family = &fam_rzg3s,
184 static const struct renesas_soc soc_rz_v2h __initconst __maybe_unused = {
185 .family = &fam_rzv2h,
189 static const struct renesas_soc soc_rz_v2l __initconst __maybe_unused = {
190 .family = &fam_rzv2l,
194 static const struct renesas_soc soc_rz_v2m __initconst __maybe_unused = {
195 .family = &fam_rzv2m,
198 static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
199 .family = &fam_rcar_gen1,
202 static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
203 .family = &fam_rcar_gen1,
207 static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
208 .family = &fam_rcar_gen2,
212 static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
213 .family = &fam_rcar_gen2,
217 static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
218 .family = &fam_rcar_gen2,
222 static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
223 .family = &fam_rcar_gen2,
227 static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
228 .family = &fam_rcar_gen2,
232 static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
233 .family = &fam_rcar_gen3,
237 static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
238 .family = &fam_rcar_gen3,
242 static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
243 .family = &fam_rcar_gen3,
247 static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
248 .family = &fam_rcar_gen3,
252 static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
253 .family = &fam_rcar_gen3,
257 static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
258 .family = &fam_rcar_gen3,
262 static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
263 .family = &fam_rcar_gen3,
267 static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
268 .family = &fam_rcar_gen4,
272 static const struct renesas_soc soc_rcar_s4 __initconst __maybe_unused = {
273 .family = &fam_rcar_gen4,
277 static const struct renesas_soc soc_rcar_v4h __initconst __maybe_unused = {
278 .family = &fam_rcar_gen4,
282 static const struct renesas_soc soc_rcar_v4m __initconst __maybe_unused = {
283 .family = &fam_rcar_gen4,
287 static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
288 .family = &fam_shmobile,
293 static const struct of_device_id renesas_socs[] __initconst __maybe_unused = {
294 #ifdef CONFIG_ARCH_R7S72100
295 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
297 #ifdef CONFIG_ARCH_R7S9210
298 { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
300 #ifdef CONFIG_ARCH_R8A73A4
301 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
303 #ifdef CONFIG_ARCH_R8A7740
304 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
306 #ifdef CONFIG_ARCH_R8A7742
307 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
309 #ifdef CONFIG_ARCH_R8A7743
310 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
312 #ifdef CONFIG_ARCH_R8A7744
313 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
315 #ifdef CONFIG_ARCH_R8A7745
316 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
318 #ifdef CONFIG_ARCH_R8A77470
319 { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
321 #ifdef CONFIG_ARCH_R8A774A1
322 { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
324 #ifdef CONFIG_ARCH_R8A774B1
325 { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n },
327 #ifdef CONFIG_ARCH_R8A774C0
328 { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
330 #ifdef CONFIG_ARCH_R8A774E1
331 { .compatible = "renesas,r8a774e1", .data = &soc_rz_g2h },
333 #ifdef CONFIG_ARCH_R8A7778
334 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
336 #ifdef CONFIG_ARCH_R8A7779
337 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
339 #ifdef CONFIG_ARCH_R8A7790
340 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
342 #ifdef CONFIG_ARCH_R8A7791
343 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
345 #ifdef CONFIG_ARCH_R8A7792
346 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
348 #ifdef CONFIG_ARCH_R8A7793
349 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
351 #ifdef CONFIG_ARCH_R8A7794
352 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
354 #ifdef CONFIG_ARCH_R8A77951
355 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
356 { .compatible = "renesas,r8a779m0", .data = &soc_rcar_h3 },
357 { .compatible = "renesas,r8a779m1", .data = &soc_rcar_h3 },
358 { .compatible = "renesas,r8a779m8", .data = &soc_rcar_h3 },
359 { .compatible = "renesas,r8a779mb", .data = &soc_rcar_h3 },
361 #ifdef CONFIG_ARCH_R8A77960
362 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
364 #ifdef CONFIG_ARCH_R8A77961
365 { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w },
366 { .compatible = "renesas,r8a779m2", .data = &soc_rcar_m3_w },
367 { .compatible = "renesas,r8a779m3", .data = &soc_rcar_m3_w },
369 #ifdef CONFIG_ARCH_R8A77965
370 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
371 { .compatible = "renesas,r8a779m4", .data = &soc_rcar_m3_n },
372 { .compatible = "renesas,r8a779m5", .data = &soc_rcar_m3_n },
374 #ifdef CONFIG_ARCH_R8A77970
375 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
377 #ifdef CONFIG_ARCH_R8A77980
378 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
380 #ifdef CONFIG_ARCH_R8A77990
381 { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
382 { .compatible = "renesas,r8a779m6", .data = &soc_rcar_e3 },
384 #ifdef CONFIG_ARCH_R8A77995
385 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
386 { .compatible = "renesas,r8a779m7", .data = &soc_rcar_d3 },
388 #ifdef CONFIG_ARCH_R8A779A0
389 { .compatible = "renesas,r8a779a0", .data = &soc_rcar_v3u },
391 #ifdef CONFIG_ARCH_R8A779F0
392 { .compatible = "renesas,r8a779f0", .data = &soc_rcar_s4 },
394 #ifdef CONFIG_ARCH_R8A779G0
395 { .compatible = "renesas,r8a779g0", .data = &soc_rcar_v4h },
397 #ifdef CONFIG_ARCH_R8A779H0
398 { .compatible = "renesas,r8a779h0", .data = &soc_rcar_v4m },
400 #ifdef CONFIG_ARCH_R9A07G043
402 { .compatible = "renesas,r9a07g043", .data = &soc_rz_five },
404 { .compatible = "renesas,r9a07g043", .data = &soc_rz_g2ul },
407 #ifdef CONFIG_ARCH_R9A07G044
408 { .compatible = "renesas,r9a07g044", .data = &soc_rz_g2l },
410 #ifdef CONFIG_ARCH_R9A07G054
411 { .compatible = "renesas,r9a07g054", .data = &soc_rz_v2l },
413 #ifdef CONFIG_ARCH_R9A08G045
414 { .compatible = "renesas,r9a08g045", .data = &soc_rz_g3s },
416 #ifdef CONFIG_ARCH_R9A09G011
417 { .compatible = "renesas,r9a09g011", .data = &soc_rz_v2m },
419 #ifdef CONFIG_ARCH_R9A09G057
420 { .compatible = "renesas,r9a09g057", .data = &soc_rz_v2h },
422 #ifdef CONFIG_ARCH_SH73A0
423 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
433 static const struct renesas_id id_bsid __initconst = {
437 * TODO: Upper 4 bits of BSID are for chip version, but the format is
438 * not known at this time so we don't know how to specify eshi and eslo
442 static const struct renesas_id id_rzg2l __initconst = {
447 static const struct renesas_id id_rzv2h __initconst = {
452 static const struct renesas_id id_rzv2m __initconst = {
457 static const struct renesas_id id_prr __initconst = {
462 static const struct of_device_id renesas_ids[] __initconst = {
463 { .compatible = "renesas,bsid", .data = &id_bsid },
464 { .compatible = "renesas,r9a07g043-sysc", .data = &id_rzg2l },
465 { .compatible = "renesas,r9a07g044-sysc", .data = &id_rzg2l },
466 { .compatible = "renesas,r9a07g054-sysc", .data = &id_rzg2l },
467 { .compatible = "renesas,r9a08g045-sysc", .data = &id_rzg2l },
468 { .compatible = "renesas,r9a09g011-sys", .data = &id_rzv2m },
469 { .compatible = "renesas,r9a09g057-sys", .data = &id_rzv2h },
470 { .compatible = "renesas,prr", .data = &id_prr },
474 static int __init renesas_soc_init(void)
476 struct soc_device_attribute *soc_dev_attr;
477 unsigned int product, eshi = 0, eslo;
478 const struct renesas_family *family;
479 const struct of_device_id *match;
480 const struct renesas_soc *soc;
481 const struct renesas_id *id;
482 void __iomem *chipid = NULL;
483 const char *rev_prefix = "";
484 struct soc_device *soc_dev;
485 struct device_node *np;
489 match = of_match_node(renesas_socs, of_root);
493 soc_id = strchr(match->compatible, ',') + 1;
495 family = soc->family;
497 np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
500 chipid = of_iomap(np, 0);
502 } else if (soc->id && family->reg) {
503 /* Try hardcoded CCCR/PRR fallback */
505 chipid = ioremap(family->reg, 4);
508 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
515 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
516 soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);
519 product = readl(chipid + id->offset);
523 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
524 if ((product & 0x7fff) == 0x5210)
526 /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
527 if ((product & 0x7fff) == 0x5211)
530 eshi = ((product >> 4) & 0x0f) + 1;
531 eslo = product & 0xf;
532 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
534 } else if (id == &id_rzg2l || id == &id_rzv2h) {
535 eshi = ((product >> 28) & 0x0f);
536 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u",
539 } else if (id == &id_rzv2m) {
540 eshi = ((product >> 4) & 0x0f);
541 eslo = product & 0xf;
542 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
547 ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
548 pr_warn("SoC mismatch (product = 0x%x)\n", product);
550 goto free_soc_dev_attr;
554 pr_info("Detected Renesas %s %s %s%s\n", soc_dev_attr->family,
555 soc_dev_attr->soc_id, rev_prefix, soc_dev_attr->revision ?: "");
557 soc_dev = soc_device_register(soc_dev_attr);
558 if (IS_ERR(soc_dev)) {
559 ret = PTR_ERR(soc_dev);
560 goto free_soc_dev_attr;
566 kfree(soc_dev_attr->revision);
567 kfree_const(soc_dev_attr->soc_id);
568 kfree_const(soc_dev_attr->family);
572 early_initcall(renesas_soc_init);