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>
16 struct renesas_family {
18 u32 reg; /* CCCR or PRR, if not in DT */
21 static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
23 .reg = 0xff000044, /* PRR (Product Register) */
26 static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
28 .reg = 0xff000044, /* PRR (Product Register) */
31 static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
33 .reg = 0xfff00044, /* PRR (Product Register) */
36 static const struct renesas_family fam_rcar_gen4 __initconst __maybe_unused = {
40 static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
42 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
45 static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
49 static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
53 static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
55 .reg = 0xff000044, /* PRR (Product Register) */
58 static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
60 .reg = 0xfff00044, /* PRR (Product Register) */
63 static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
67 static const struct renesas_family fam_rzg2ul __initconst __maybe_unused = {
71 static const struct renesas_family fam_rzv2l __initconst __maybe_unused = {
75 static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
77 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
82 const struct renesas_family *family;
86 static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
90 static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
95 static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
96 .family = &fam_rmobile,
100 static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
101 .family = &fam_rmobile,
105 static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
110 static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
115 static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
120 static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
125 static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
130 static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
135 static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
140 static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
145 static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
150 static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
151 .family = &fam_rzg2l,
155 static const struct renesas_soc soc_rz_g2ul __initconst __maybe_unused = {
156 .family = &fam_rzg2ul,
160 static const struct renesas_soc soc_rz_v2l __initconst __maybe_unused = {
161 .family = &fam_rzv2l,
165 static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
166 .family = &fam_rcar_gen1,
169 static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
170 .family = &fam_rcar_gen1,
174 static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
175 .family = &fam_rcar_gen2,
179 static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
180 .family = &fam_rcar_gen2,
184 static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
185 .family = &fam_rcar_gen2,
189 static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
190 .family = &fam_rcar_gen2,
194 static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
195 .family = &fam_rcar_gen2,
199 static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
200 .family = &fam_rcar_gen3,
204 static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
205 .family = &fam_rcar_gen3,
209 static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
210 .family = &fam_rcar_gen3,
214 static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
215 .family = &fam_rcar_gen3,
219 static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
220 .family = &fam_rcar_gen3,
224 static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
225 .family = &fam_rcar_gen3,
229 static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
230 .family = &fam_rcar_gen3,
234 static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
235 .family = &fam_rcar_gen4,
239 static const struct renesas_soc soc_rcar_s4 __initconst __maybe_unused = {
240 .family = &fam_rcar_gen4,
244 static const struct renesas_soc soc_rcar_v4h __initconst __maybe_unused = {
245 .family = &fam_rcar_gen4,
249 static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
250 .family = &fam_shmobile,
255 static const struct of_device_id renesas_socs[] __initconst = {
256 #ifdef CONFIG_ARCH_R7S72100
257 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
259 #ifdef CONFIG_ARCH_R7S9210
260 { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
262 #ifdef CONFIG_ARCH_R8A73A4
263 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
265 #ifdef CONFIG_ARCH_R8A7740
266 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
268 #ifdef CONFIG_ARCH_R8A7742
269 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
271 #ifdef CONFIG_ARCH_R8A7743
272 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
274 #ifdef CONFIG_ARCH_R8A7744
275 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
277 #ifdef CONFIG_ARCH_R8A7745
278 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
280 #ifdef CONFIG_ARCH_R8A77470
281 { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
283 #ifdef CONFIG_ARCH_R8A774A1
284 { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
286 #ifdef CONFIG_ARCH_R8A774B1
287 { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n },
289 #ifdef CONFIG_ARCH_R8A774C0
290 { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
292 #ifdef CONFIG_ARCH_R8A774E1
293 { .compatible = "renesas,r8a774e1", .data = &soc_rz_g2h },
295 #ifdef CONFIG_ARCH_R8A7778
296 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
298 #ifdef CONFIG_ARCH_R8A7779
299 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
301 #ifdef CONFIG_ARCH_R8A7790
302 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
304 #ifdef CONFIG_ARCH_R8A7791
305 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
307 #ifdef CONFIG_ARCH_R8A7792
308 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
310 #ifdef CONFIG_ARCH_R8A7793
311 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
313 #ifdef CONFIG_ARCH_R8A7794
314 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
316 #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
317 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
319 #ifdef CONFIG_ARCH_R8A77951
320 { .compatible = "renesas,r8a779m0", .data = &soc_rcar_h3 },
321 { .compatible = "renesas,r8a779m1", .data = &soc_rcar_h3 },
322 { .compatible = "renesas,r8a779m8", .data = &soc_rcar_h3 },
323 { .compatible = "renesas,r8a779mb", .data = &soc_rcar_h3 },
325 #ifdef CONFIG_ARCH_R8A77960
326 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
328 #ifdef CONFIG_ARCH_R8A77961
329 { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w },
330 { .compatible = "renesas,r8a779m2", .data = &soc_rcar_m3_w },
331 { .compatible = "renesas,r8a779m3", .data = &soc_rcar_m3_w },
333 #ifdef CONFIG_ARCH_R8A77965
334 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
335 { .compatible = "renesas,r8a779m4", .data = &soc_rcar_m3_n },
336 { .compatible = "renesas,r8a779m5", .data = &soc_rcar_m3_n },
338 #ifdef CONFIG_ARCH_R8A77970
339 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
341 #ifdef CONFIG_ARCH_R8A77980
342 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
344 #ifdef CONFIG_ARCH_R8A77990
345 { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
346 { .compatible = "renesas,r8a779m6", .data = &soc_rcar_e3 },
348 #ifdef CONFIG_ARCH_R8A77995
349 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
350 { .compatible = "renesas,r8a779m7", .data = &soc_rcar_d3 },
352 #ifdef CONFIG_ARCH_R8A779A0
353 { .compatible = "renesas,r8a779a0", .data = &soc_rcar_v3u },
355 #ifdef CONFIG_ARCH_R8A779F0
356 { .compatible = "renesas,r8a779f0", .data = &soc_rcar_s4 },
358 #ifdef CONFIG_ARCH_R8A779G0
359 { .compatible = "renesas,r8a779g0", .data = &soc_rcar_v4h },
361 #if defined(CONFIG_ARCH_R9A07G043)
362 { .compatible = "renesas,r9a07g043", .data = &soc_rz_g2ul },
364 #if defined(CONFIG_ARCH_R9A07G044)
365 { .compatible = "renesas,r9a07g044", .data = &soc_rz_g2l },
367 #if defined(CONFIG_ARCH_R9A07G054)
368 { .compatible = "renesas,r9a07g054", .data = &soc_rz_v2l },
370 #ifdef CONFIG_ARCH_SH73A0
371 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
381 static const struct renesas_id id_bsid __initconst = {
385 * TODO: Upper 4 bits of BSID are for chip version, but the format is
386 * not known at this time so we don't know how to specify eshi and eslo
390 static const struct renesas_id id_rzg2l __initconst = {
395 static const struct renesas_id id_prr __initconst = {
400 static const struct of_device_id renesas_ids[] __initconst = {
401 { .compatible = "renesas,bsid", .data = &id_bsid },
402 { .compatible = "renesas,r9a07g043-sysc", .data = &id_rzg2l },
403 { .compatible = "renesas,r9a07g044-sysc", .data = &id_rzg2l },
404 { .compatible = "renesas,r9a07g054-sysc", .data = &id_rzg2l },
405 { .compatible = "renesas,prr", .data = &id_prr },
409 static int __init renesas_soc_init(void)
411 struct soc_device_attribute *soc_dev_attr;
412 unsigned int product, eshi = 0, eslo;
413 const struct renesas_family *family;
414 const struct of_device_id *match;
415 const struct renesas_soc *soc;
416 const struct renesas_id *id;
417 void __iomem *chipid = NULL;
418 const char *rev_prefix = "";
419 struct soc_device *soc_dev;
420 struct device_node *np;
424 match = of_match_node(renesas_socs, of_root);
428 soc_id = strchr(match->compatible, ',') + 1;
430 family = soc->family;
432 np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
435 chipid = of_iomap(np, 0);
437 } else if (soc->id && family->reg) {
438 /* Try hardcoded CCCR/PRR fallback */
440 chipid = ioremap(family->reg, 4);
443 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
447 np = of_find_node_by_path("/");
448 of_property_read_string(np, "model", &soc_dev_attr->machine);
451 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
452 soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);
455 product = readl(chipid + id->offset);
459 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
460 if ((product & 0x7fff) == 0x5210)
462 /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
463 if ((product & 0x7fff) == 0x5211)
466 eshi = ((product >> 4) & 0x0f) + 1;
467 eslo = product & 0xf;
468 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
470 } else if (id == &id_rzg2l) {
471 eshi = ((product >> 28) & 0x0f);
472 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u",
478 ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
479 pr_warn("SoC mismatch (product = 0x%x)\n", product);
481 goto free_soc_dev_attr;
485 pr_info("Detected Renesas %s %s %s%s\n", soc_dev_attr->family,
486 soc_dev_attr->soc_id, rev_prefix, soc_dev_attr->revision ?: "");
488 soc_dev = soc_device_register(soc_dev_attr);
489 if (IS_ERR(soc_dev)) {
490 ret = PTR_ERR(soc_dev);
491 goto free_soc_dev_attr;
497 kfree(soc_dev_attr->revision);
498 kfree_const(soc_dev_attr->soc_id);
499 kfree_const(soc_dev_attr->family);
503 early_initcall(renesas_soc_init);