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_rmobile __initconst __maybe_unused = {
38 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
41 static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
45 static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
49 static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
51 .reg = 0xff000044, /* PRR (Product Register) */
54 static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
56 .reg = 0xfff00044, /* PRR (Product Register) */
59 static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
63 static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
65 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
70 const struct renesas_family *family;
74 static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
78 static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
83 static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
84 .family = &fam_rmobile,
88 static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
89 .family = &fam_rmobile,
93 static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
98 static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
103 static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
108 static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
113 static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
118 static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
123 static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
128 static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
133 static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
138 static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
139 .family = &fam_rzg2l,
143 static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
144 .family = &fam_rcar_gen1,
147 static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
148 .family = &fam_rcar_gen1,
152 static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
153 .family = &fam_rcar_gen2,
157 static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
158 .family = &fam_rcar_gen2,
162 static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
163 .family = &fam_rcar_gen2,
167 static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
168 .family = &fam_rcar_gen2,
172 static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
173 .family = &fam_rcar_gen2,
177 static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
178 .family = &fam_rcar_gen3,
182 static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
183 .family = &fam_rcar_gen3,
187 static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
188 .family = &fam_rcar_gen3,
192 static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
193 .family = &fam_rcar_gen3,
197 static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
198 .family = &fam_rcar_gen3,
202 static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
203 .family = &fam_rcar_gen3,
207 static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
208 .family = &fam_rcar_gen3,
212 static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
213 .family = &fam_rcar_gen3,
217 static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
218 .family = &fam_shmobile,
223 static const struct of_device_id renesas_socs[] __initconst = {
224 #ifdef CONFIG_ARCH_R7S72100
225 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
227 #ifdef CONFIG_ARCH_R7S9210
228 { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
230 #ifdef CONFIG_ARCH_R8A73A4
231 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
233 #ifdef CONFIG_ARCH_R8A7740
234 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
236 #ifdef CONFIG_ARCH_R8A7742
237 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
239 #ifdef CONFIG_ARCH_R8A7743
240 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
242 #ifdef CONFIG_ARCH_R8A7744
243 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
245 #ifdef CONFIG_ARCH_R8A7745
246 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
248 #ifdef CONFIG_ARCH_R8A77470
249 { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
251 #ifdef CONFIG_ARCH_R8A774A1
252 { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
254 #ifdef CONFIG_ARCH_R8A774B1
255 { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n },
257 #ifdef CONFIG_ARCH_R8A774C0
258 { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
260 #ifdef CONFIG_ARCH_R8A774E1
261 { .compatible = "renesas,r8a774e1", .data = &soc_rz_g2h },
263 #ifdef CONFIG_ARCH_R8A7778
264 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
266 #ifdef CONFIG_ARCH_R8A7779
267 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
269 #ifdef CONFIG_ARCH_R8A7790
270 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
272 #ifdef CONFIG_ARCH_R8A7791
273 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
275 #ifdef CONFIG_ARCH_R8A7792
276 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
278 #ifdef CONFIG_ARCH_R8A7793
279 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
281 #ifdef CONFIG_ARCH_R8A7794
282 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
284 #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
285 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
287 #ifdef CONFIG_ARCH_R8A77960
288 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
290 #ifdef CONFIG_ARCH_R8A77961
291 { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w },
293 #ifdef CONFIG_ARCH_R8A77965
294 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
296 #ifdef CONFIG_ARCH_R8A77970
297 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
299 #ifdef CONFIG_ARCH_R8A77980
300 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
302 #ifdef CONFIG_ARCH_R8A77990
303 { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
305 #ifdef CONFIG_ARCH_R8A77995
306 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
308 #ifdef CONFIG_ARCH_R8A779A0
309 { .compatible = "renesas,r8a779a0", .data = &soc_rcar_v3u },
311 #if defined(CONFIG_ARCH_R9A07G044)
312 { .compatible = "renesas,r9a07g044", .data = &soc_rz_g2l },
314 #ifdef CONFIG_ARCH_SH73A0
315 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
320 static int __init renesas_soc_init(void)
322 struct soc_device_attribute *soc_dev_attr;
323 const struct renesas_family *family;
324 const struct of_device_id *match;
325 const struct renesas_soc *soc;
326 void __iomem *chipid = NULL;
327 struct soc_device *soc_dev;
328 struct device_node *np;
329 unsigned int product, eshi = 0, eslo;
331 match = of_match_node(renesas_socs, of_root);
336 family = soc->family;
338 np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
340 chipid = of_iomap(np, 0);
344 product = readl(chipid);
347 if (soc->id && ((product >> 16) & 0xff) != soc->id) {
348 pr_warn("SoC mismatch (product = 0x%x)\n",
355 * TODO: Upper 4 bits of BSID are for chip version, but the
356 * format is not known at this time so we don't know how to
357 * specify eshi and eslo
363 np = of_find_compatible_node(NULL, NULL, "renesas,r9a07g044-sysc");
365 chipid = of_iomap(np, 0);
369 product = readl(chipid + 0x0a04);
372 if (soc->id && (product & 0xfffffff) != soc->id) {
373 pr_warn("SoC mismatch (product = 0x%x)\n",
382 /* Try PRR first, then hardcoded fallback */
383 np = of_find_compatible_node(NULL, NULL, "renesas,prr");
385 chipid = of_iomap(np, 0);
387 } else if (soc->id && family->reg) {
388 chipid = ioremap(family->reg, 4);
391 product = readl(chipid);
393 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
394 if ((product & 0x7fff) == 0x5210)
396 /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
397 if ((product & 0x7fff) == 0x5211)
399 if (soc->id && ((product >> 8) & 0xff) != soc->id) {
400 pr_warn("SoC mismatch (product = 0x%x)\n", product);
403 eshi = ((product >> 4) & 0x0f) + 1;
404 eslo = product & 0xf;
408 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
412 np = of_find_node_by_path("/");
413 of_property_read_string(np, "model", &soc_dev_attr->machine);
416 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
417 soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
420 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
423 pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
424 soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
426 soc_dev = soc_device_register(soc_dev_attr);
427 if (IS_ERR(soc_dev)) {
428 kfree(soc_dev_attr->revision);
429 kfree_const(soc_dev_attr->soc_id);
430 kfree_const(soc_dev_attr->family);
432 return PTR_ERR(soc_dev);
437 early_initcall(renesas_soc_init);