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_shmobile __initconst __maybe_unused = {
61 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
66 const struct renesas_family *family;
70 static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
74 static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
79 static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
80 .family = &fam_rmobile,
84 static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
85 .family = &fam_rmobile,
89 static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
94 static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
99 static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
104 static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
109 static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
114 static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
119 static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
124 static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
129 static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
134 static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
135 .family = &fam_rcar_gen1,
138 static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
139 .family = &fam_rcar_gen1,
143 static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
144 .family = &fam_rcar_gen2,
148 static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
149 .family = &fam_rcar_gen2,
153 static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
154 .family = &fam_rcar_gen2,
158 static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
159 .family = &fam_rcar_gen2,
163 static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
164 .family = &fam_rcar_gen2,
168 static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
169 .family = &fam_rcar_gen3,
173 static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
174 .family = &fam_rcar_gen3,
178 static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
179 .family = &fam_rcar_gen3,
183 static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
184 .family = &fam_rcar_gen3,
188 static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
189 .family = &fam_rcar_gen3,
193 static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
194 .family = &fam_rcar_gen3,
198 static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
199 .family = &fam_rcar_gen3,
203 static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
204 .family = &fam_rcar_gen3,
208 static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
209 .family = &fam_shmobile,
214 static const struct of_device_id renesas_socs[] __initconst = {
215 #ifdef CONFIG_ARCH_R7S72100
216 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
218 #ifdef CONFIG_ARCH_R7S9210
219 { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
221 #ifdef CONFIG_ARCH_R8A73A4
222 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
224 #ifdef CONFIG_ARCH_R8A7740
225 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
227 #ifdef CONFIG_ARCH_R8A7742
228 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
230 #ifdef CONFIG_ARCH_R8A7743
231 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
233 #ifdef CONFIG_ARCH_R8A7744
234 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
236 #ifdef CONFIG_ARCH_R8A7745
237 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
239 #ifdef CONFIG_ARCH_R8A77470
240 { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
242 #ifdef CONFIG_ARCH_R8A774A1
243 { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
245 #ifdef CONFIG_ARCH_R8A774B1
246 { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n },
248 #ifdef CONFIG_ARCH_R8A774C0
249 { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
251 #ifdef CONFIG_ARCH_R8A774E1
252 { .compatible = "renesas,r8a774e1", .data = &soc_rz_g2h },
254 #ifdef CONFIG_ARCH_R8A7778
255 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
257 #ifdef CONFIG_ARCH_R8A7779
258 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
260 #ifdef CONFIG_ARCH_R8A7790
261 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
263 #ifdef CONFIG_ARCH_R8A7791
264 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
266 #ifdef CONFIG_ARCH_R8A7792
267 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
269 #ifdef CONFIG_ARCH_R8A7793
270 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
272 #ifdef CONFIG_ARCH_R8A7794
273 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
275 #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
276 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
278 #ifdef CONFIG_ARCH_R8A77960
279 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
281 #ifdef CONFIG_ARCH_R8A77961
282 { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w },
284 #ifdef CONFIG_ARCH_R8A77965
285 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
287 #ifdef CONFIG_ARCH_R8A77970
288 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
290 #ifdef CONFIG_ARCH_R8A77980
291 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
293 #ifdef CONFIG_ARCH_R8A77990
294 { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
296 #ifdef CONFIG_ARCH_R8A77995
297 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
299 #ifdef CONFIG_ARCH_R8A779A0
300 { .compatible = "renesas,r8a779a0", .data = &soc_rcar_v3u },
302 #ifdef CONFIG_ARCH_SH73A0
303 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
308 static int __init renesas_soc_init(void)
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;
317 unsigned int product, eshi = 0, eslo;
319 match = of_match_node(renesas_socs, of_root);
324 family = soc->family;
326 np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
328 chipid = of_iomap(np, 0);
332 product = readl(chipid);
335 if (soc->id && ((product >> 16) & 0xff) != soc->id) {
336 pr_warn("SoC mismatch (product = 0x%x)\n",
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
351 /* Try PRR first, then hardcoded fallback */
352 np = of_find_compatible_node(NULL, NULL, "renesas,prr");
354 chipid = of_iomap(np, 0);
356 } else if (soc->id && family->reg) {
357 chipid = ioremap(family->reg, 4);
360 product = readl(chipid);
362 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
363 if ((product & 0x7fff) == 0x5210)
365 /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
366 if ((product & 0x7fff) == 0x5211)
368 if (soc->id && ((product >> 8) & 0xff) != soc->id) {
369 pr_warn("SoC mismatch (product = 0x%x)\n", product);
372 eshi = ((product >> 4) & 0x0f) + 1;
373 eslo = product & 0xf;
377 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
381 np = of_find_node_by_path("/");
382 of_property_read_string(np, "model", &soc_dev_attr->machine);
385 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
386 soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
389 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
392 pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
393 soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
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);
401 return PTR_ERR(soc_dev);
406 early_initcall(renesas_soc_init);