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_rcar_m1a __initconst __maybe_unused = {
130 .family = &fam_rcar_gen1,
133 static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
134 .family = &fam_rcar_gen1,
138 static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
139 .family = &fam_rcar_gen2,
143 static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
144 .family = &fam_rcar_gen2,
148 static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
149 .family = &fam_rcar_gen2,
153 static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
154 .family = &fam_rcar_gen2,
158 static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
159 .family = &fam_rcar_gen2,
163 static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
164 .family = &fam_rcar_gen3,
168 static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
169 .family = &fam_rcar_gen3,
173 static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
174 .family = &fam_rcar_gen3,
178 static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
179 .family = &fam_rcar_gen3,
183 static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
184 .family = &fam_rcar_gen3,
188 static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
189 .family = &fam_rcar_gen3,
193 static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
194 .family = &fam_rcar_gen3,
198 static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
199 .family = &fam_shmobile,
204 static const struct of_device_id renesas_socs[] __initconst = {
205 #ifdef CONFIG_ARCH_R7S72100
206 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
208 #ifdef CONFIG_ARCH_R7S9210
209 { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
211 #ifdef CONFIG_ARCH_R8A73A4
212 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
214 #ifdef CONFIG_ARCH_R8A7740
215 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
217 #ifdef CONFIG_ARCH_R8A7742
218 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
220 #ifdef CONFIG_ARCH_R8A7743
221 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
223 #ifdef CONFIG_ARCH_R8A7744
224 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
226 #ifdef CONFIG_ARCH_R8A7745
227 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
229 #ifdef CONFIG_ARCH_R8A77470
230 { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
232 #ifdef CONFIG_ARCH_R8A774A1
233 { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
235 #ifdef CONFIG_ARCH_R8A774B1
236 { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n },
238 #ifdef CONFIG_ARCH_R8A774C0
239 { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
241 #ifdef CONFIG_ARCH_R8A7778
242 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
244 #ifdef CONFIG_ARCH_R8A7779
245 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
247 #ifdef CONFIG_ARCH_R8A7790
248 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
250 #ifdef CONFIG_ARCH_R8A7791
251 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
253 #ifdef CONFIG_ARCH_R8A7792
254 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
256 #ifdef CONFIG_ARCH_R8A7793
257 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
259 #ifdef CONFIG_ARCH_R8A7794
260 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
262 #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
263 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
265 #ifdef CONFIG_ARCH_R8A77960
266 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
268 #ifdef CONFIG_ARCH_R8A77961
269 { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w },
271 #ifdef CONFIG_ARCH_R8A77965
272 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
274 #ifdef CONFIG_ARCH_R8A77970
275 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
277 #ifdef CONFIG_ARCH_R8A77980
278 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
280 #ifdef CONFIG_ARCH_R8A77990
281 { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
283 #ifdef CONFIG_ARCH_R8A77995
284 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
286 #ifdef CONFIG_ARCH_SH73A0
287 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
292 static int __init renesas_soc_init(void)
294 struct soc_device_attribute *soc_dev_attr;
295 const struct renesas_family *family;
296 const struct of_device_id *match;
297 const struct renesas_soc *soc;
298 void __iomem *chipid = NULL;
299 struct soc_device *soc_dev;
300 struct device_node *np;
301 unsigned int product, eshi = 0, eslo;
303 match = of_match_node(renesas_socs, of_root);
308 family = soc->family;
310 np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
312 chipid = of_iomap(np, 0);
316 product = readl(chipid);
319 if (soc->id && ((product >> 16) & 0xff) != soc->id) {
320 pr_warn("SoC mismatch (product = 0x%x)\n",
327 * TODO: Upper 4 bits of BSID are for chip version, but the
328 * format is not known at this time so we don't know how to
329 * specify eshi and eslo
335 /* Try PRR first, then hardcoded fallback */
336 np = of_find_compatible_node(NULL, NULL, "renesas,prr");
338 chipid = of_iomap(np, 0);
340 } else if (soc->id && family->reg) {
341 chipid = ioremap(family->reg, 4);
344 product = readl(chipid);
346 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
347 if ((product & 0x7fff) == 0x5210)
349 /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
350 if ((product & 0x7fff) == 0x5211)
352 if (soc->id && ((product >> 8) & 0xff) != soc->id) {
353 pr_warn("SoC mismatch (product = 0x%x)\n", product);
356 eshi = ((product >> 4) & 0x0f) + 1;
357 eslo = product & 0xf;
361 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
365 np = of_find_node_by_path("/");
366 of_property_read_string(np, "model", &soc_dev_attr->machine);
369 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
370 soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
373 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
376 pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
377 soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
379 soc_dev = soc_device_register(soc_dev_attr);
380 if (IS_ERR(soc_dev)) {
381 kfree(soc_dev_attr->revision);
382 kfree_const(soc_dev_attr->soc_id);
383 kfree_const(soc_dev_attr->family);
385 return PTR_ERR(soc_dev);
390 early_initcall(renesas_soc_init);