xref: /linux/drivers/soc/renesas/renesas-soc.c (revision 9c9f7891093b02eb64ca4e1c7ab776a4296c058f)
141c4567cSKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
28d6799a9SGeert Uytterhoeven /*
38d6799a9SGeert Uytterhoeven  * Renesas SoC Identification
48d6799a9SGeert Uytterhoeven  *
58d6799a9SGeert Uytterhoeven  * Copyright (C) 2014-2016 Glider bvba
68d6799a9SGeert Uytterhoeven  */
78d6799a9SGeert Uytterhoeven 
88d6799a9SGeert Uytterhoeven #include <linux/io.h>
98d6799a9SGeert Uytterhoeven #include <linux/of.h>
108d6799a9SGeert Uytterhoeven #include <linux/of_address.h>
118d6799a9SGeert Uytterhoeven #include <linux/slab.h>
128d6799a9SGeert Uytterhoeven #include <linux/string.h>
138d6799a9SGeert Uytterhoeven #include <linux/sys_soc.h>
148d6799a9SGeert Uytterhoeven 
158d6799a9SGeert Uytterhoeven 
168d6799a9SGeert Uytterhoeven struct renesas_family {
178d6799a9SGeert Uytterhoeven 	const char name[16];
188d6799a9SGeert Uytterhoeven 	u32 reg;			/* CCCR or PRR, if not in DT */
198d6799a9SGeert Uytterhoeven };
208d6799a9SGeert Uytterhoeven 
218d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
228d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen1",
238d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
248d6799a9SGeert Uytterhoeven };
258d6799a9SGeert Uytterhoeven 
268d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
278d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen2",
288d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
298d6799a9SGeert Uytterhoeven };
308d6799a9SGeert Uytterhoeven 
318d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
328d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen3",
338d6799a9SGeert Uytterhoeven 	.reg	= 0xfff00044,		/* PRR (Product Register) */
348d6799a9SGeert Uytterhoeven };
358d6799a9SGeert Uytterhoeven 
368d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
378d6799a9SGeert Uytterhoeven 	.name	= "R-Mobile",
388d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
398d6799a9SGeert Uytterhoeven };
408d6799a9SGeert Uytterhoeven 
41175f435fSChris Brandt static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
42175f435fSChris Brandt 	.name	= "RZ/A1",
43175f435fSChris Brandt };
44175f435fSChris Brandt 
45175f435fSChris Brandt static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
46175f435fSChris Brandt 	.name	= "RZ/A2",
478d6799a9SGeert Uytterhoeven };
488d6799a9SGeert Uytterhoeven 
492a4056a7SBiju Das static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
502a4056a7SBiju Das 	.name	= "RZ/G1",
518d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
528d6799a9SGeert Uytterhoeven };
538d6799a9SGeert Uytterhoeven 
542a4056a7SBiju Das static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
552a4056a7SBiju Das 	.name	= "RZ/G2",
562a4056a7SBiju Das 	.reg	= 0xfff00044,		/* PRR (Product Register) */
572a4056a7SBiju Das };
582a4056a7SBiju Das 
598d6799a9SGeert Uytterhoeven static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
608d6799a9SGeert Uytterhoeven 	.name	= "SH-Mobile",
618d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
628d6799a9SGeert Uytterhoeven };
638d6799a9SGeert Uytterhoeven 
648d6799a9SGeert Uytterhoeven 
658d6799a9SGeert Uytterhoeven struct renesas_soc {
668d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
678d6799a9SGeert Uytterhoeven 	u8 id;
688d6799a9SGeert Uytterhoeven };
698d6799a9SGeert Uytterhoeven 
708d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
71175f435fSChris Brandt 	.family	= &fam_rza1,
72175f435fSChris Brandt };
73175f435fSChris Brandt 
74175f435fSChris Brandt static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
75175f435fSChris Brandt 	.family	= &fam_rza2,
76175f435fSChris Brandt 	.id	= 0x3b,
778d6799a9SGeert Uytterhoeven };
788d6799a9SGeert Uytterhoeven 
798d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
808d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
818d6799a9SGeert Uytterhoeven 	.id	= 0x3f,
828d6799a9SGeert Uytterhoeven };
838d6799a9SGeert Uytterhoeven 
848d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
858d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
868d6799a9SGeert Uytterhoeven 	.id	= 0x40,
878d6799a9SGeert Uytterhoeven };
888d6799a9SGeert Uytterhoeven 
898848e1b1SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
902a4056a7SBiju Das 	.family	= &fam_rzg1,
918848e1b1SGeert Uytterhoeven 	.id	= 0x45,
928848e1b1SGeert Uytterhoeven };
938848e1b1SGeert Uytterhoeven 
948d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
952a4056a7SBiju Das 	.family	= &fam_rzg1,
968d6799a9SGeert Uytterhoeven 	.id	= 0x47,
978d6799a9SGeert Uytterhoeven };
988d6799a9SGeert Uytterhoeven 
99cd59de80SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
1002a4056a7SBiju Das 	.family	= &fam_rzg1,
101cd59de80SGeert Uytterhoeven 	.id	= 0x4b,
102cd59de80SGeert Uytterhoeven };
103cd59de80SGeert Uytterhoeven 
1048d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
1052a4056a7SBiju Das 	.family	= &fam_rzg1,
1068d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1078d6799a9SGeert Uytterhoeven };
1088d6799a9SGeert Uytterhoeven 
1091daf13baSBiju Das static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
1102a4056a7SBiju Das 	.family	= &fam_rzg1,
1111daf13baSBiju Das 	.id	= 0x53,
1121daf13baSBiju Das };
1131daf13baSBiju Das 
1142a4056a7SBiju Das static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
1152a4056a7SBiju Das 	.family	= &fam_rzg2,
1162a4056a7SBiju Das 	.id	= 0x52,
1172a4056a7SBiju Das };
1182a4056a7SBiju Das 
119574cb721SBiju Das static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
120574cb721SBiju Das 	.family = &fam_rzg2,
121574cb721SBiju Das 	.id     = 0x55,
122574cb721SBiju Das };
123574cb721SBiju Das 
1242bab3d80SFabrizio Castro static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
1252bab3d80SFabrizio Castro 	.family	= &fam_rzg2,
1262bab3d80SFabrizio Castro 	.id	= 0x57,
1272bab3d80SFabrizio Castro };
1282bab3d80SFabrizio Castro 
1298d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
1308d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1318d6799a9SGeert Uytterhoeven };
1328d6799a9SGeert Uytterhoeven 
1338d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
1348d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1358d6799a9SGeert Uytterhoeven 	.id	= 0x3b,
1368d6799a9SGeert Uytterhoeven };
1378d6799a9SGeert Uytterhoeven 
1388d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
1398d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1408d6799a9SGeert Uytterhoeven 	.id	= 0x45,
1418d6799a9SGeert Uytterhoeven };
1428d6799a9SGeert Uytterhoeven 
1438d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
1448d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1458d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1468d6799a9SGeert Uytterhoeven };
1478d6799a9SGeert Uytterhoeven 
1488d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
1498d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1508d6799a9SGeert Uytterhoeven 	.id	= 0x4a,
1518d6799a9SGeert Uytterhoeven };
1528d6799a9SGeert Uytterhoeven 
1538d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
1548d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1558d6799a9SGeert Uytterhoeven 	.id	= 0x4b,
1568d6799a9SGeert Uytterhoeven };
1578d6799a9SGeert Uytterhoeven 
1588d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
1598d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1608d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1618d6799a9SGeert Uytterhoeven };
1628d6799a9SGeert Uytterhoeven 
1638d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
1648d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1658d6799a9SGeert Uytterhoeven 	.id	= 0x4f,
1668d6799a9SGeert Uytterhoeven };
1678d6799a9SGeert Uytterhoeven 
1688d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
1698d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1708d6799a9SGeert Uytterhoeven 	.id	= 0x52,
1718d6799a9SGeert Uytterhoeven };
1728d6799a9SGeert Uytterhoeven 
173bfd83983SJacopo Mondi static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
174bfd83983SJacopo Mondi 	.family = &fam_rcar_gen3,
175bfd83983SJacopo Mondi 	.id     = 0x55,
176bfd83983SJacopo Mondi };
177bfd83983SJacopo Mondi 
178bb003075SSergei Shtylyov static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
179bb003075SSergei Shtylyov 	.family	= &fam_rcar_gen3,
180bb003075SSergei Shtylyov 	.id	= 0x54,
181bb003075SSergei Shtylyov };
182bb003075SSergei Shtylyov 
1838447756dSSergei Shtylyov static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
1848447756dSSergei Shtylyov 	.family	= &fam_rcar_gen3,
1858447756dSSergei Shtylyov 	.id	= 0x56,
1868447756dSSergei Shtylyov };
1878447756dSSergei Shtylyov 
18844842d45STakeshi Kihara static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
18944842d45STakeshi Kihara 	.family	= &fam_rcar_gen3,
19044842d45STakeshi Kihara 	.id	= 0x57,
19144842d45STakeshi Kihara };
19244842d45STakeshi Kihara 
1931b954784SGeert Uytterhoeven static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
1941b954784SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1951b954784SGeert Uytterhoeven 	.id	= 0x58,
1961b954784SGeert Uytterhoeven };
1971b954784SGeert Uytterhoeven 
1988d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
1998d6799a9SGeert Uytterhoeven 	.family	= &fam_shmobile,
2008d6799a9SGeert Uytterhoeven 	.id	= 0x37,
2018d6799a9SGeert Uytterhoeven };
2028d6799a9SGeert Uytterhoeven 
2038d6799a9SGeert Uytterhoeven 
2048d6799a9SGeert Uytterhoeven static const struct of_device_id renesas_socs[] __initconst = {
2058d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R7S72100
2068d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
2078d6799a9SGeert Uytterhoeven #endif
208175f435fSChris Brandt #ifdef CONFIG_ARCH_R7S9210
209175f435fSChris Brandt 	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
210175f435fSChris Brandt #endif
2118d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A73A4
2128d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
2138d6799a9SGeert Uytterhoeven #endif
2148d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7740
2158d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
2168d6799a9SGeert Uytterhoeven #endif
2178848e1b1SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7742
2188848e1b1SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
2198848e1b1SGeert Uytterhoeven #endif
2208d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7743
2218d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
2228d6799a9SGeert Uytterhoeven #endif
223cd59de80SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7744
224cd59de80SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
225cd59de80SGeert Uytterhoeven #endif
2268d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7745
2278d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
2288d6799a9SGeert Uytterhoeven #endif
2291daf13baSBiju Das #ifdef CONFIG_ARCH_R8A77470
2301daf13baSBiju Das 	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
2311daf13baSBiju Das #endif
2322a4056a7SBiju Das #ifdef CONFIG_ARCH_R8A774A1
2332a4056a7SBiju Das 	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
2342a4056a7SBiju Das #endif
235574cb721SBiju Das #ifdef CONFIG_ARCH_R8A774B1
236574cb721SBiju Das 	{ .compatible = "renesas,r8a774b1",	.data = &soc_rz_g2n },
237574cb721SBiju Das #endif
2382bab3d80SFabrizio Castro #ifdef CONFIG_ARCH_R8A774C0
2392bab3d80SFabrizio Castro 	{ .compatible = "renesas,r8a774c0",	.data = &soc_rz_g2e },
2402bab3d80SFabrizio Castro #endif
2418d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7778
2428d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
2438d6799a9SGeert Uytterhoeven #endif
2448d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7779
2458d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
2468d6799a9SGeert Uytterhoeven #endif
2478d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7790
2488d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
2498d6799a9SGeert Uytterhoeven #endif
2508d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7791
2518d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
2528d6799a9SGeert Uytterhoeven #endif
2538d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7792
2548d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
2558d6799a9SGeert Uytterhoeven #endif
2568d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7793
2578d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
2588d6799a9SGeert Uytterhoeven #endif
2598d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7794
2608d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
2618d6799a9SGeert Uytterhoeven #endif
2628d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7795
2638d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
2648d6799a9SGeert Uytterhoeven #endif
26539e57e14SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77960
2668d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
2678d6799a9SGeert Uytterhoeven #endif
268*9c9f7891SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77961
269*9c9f7891SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77961",	.data = &soc_rcar_m3_w },
270*9c9f7891SGeert Uytterhoeven #endif
271bfd83983SJacopo Mondi #ifdef CONFIG_ARCH_R8A77965
272bfd83983SJacopo Mondi 	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
273bfd83983SJacopo Mondi #endif
274bb003075SSergei Shtylyov #ifdef CONFIG_ARCH_R8A77970
275bb003075SSergei Shtylyov 	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
276bb003075SSergei Shtylyov #endif
2778447756dSSergei Shtylyov #ifdef CONFIG_ARCH_R8A77980
2788447756dSSergei Shtylyov 	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
2798447756dSSergei Shtylyov #endif
28044842d45STakeshi Kihara #ifdef CONFIG_ARCH_R8A77990
28144842d45STakeshi Kihara 	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
28244842d45STakeshi Kihara #endif
2831b954784SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77995
2841b954784SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
2851b954784SGeert Uytterhoeven #endif
2868d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_SH73A0
2878d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
2888d6799a9SGeert Uytterhoeven #endif
2898d6799a9SGeert Uytterhoeven 	{ /* sentinel */ }
2908d6799a9SGeert Uytterhoeven };
2918d6799a9SGeert Uytterhoeven 
2928d6799a9SGeert Uytterhoeven static int __init renesas_soc_init(void)
2938d6799a9SGeert Uytterhoeven {
2948d6799a9SGeert Uytterhoeven 	struct soc_device_attribute *soc_dev_attr;
2958d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
2968d6799a9SGeert Uytterhoeven 	const struct of_device_id *match;
2978d6799a9SGeert Uytterhoeven 	const struct renesas_soc *soc;
2988d6799a9SGeert Uytterhoeven 	void __iomem *chipid = NULL;
2998d6799a9SGeert Uytterhoeven 	struct soc_device *soc_dev;
3008d6799a9SGeert Uytterhoeven 	struct device_node *np;
301175f435fSChris Brandt 	unsigned int product, eshi = 0, eslo;
3028d6799a9SGeert Uytterhoeven 
3038d6799a9SGeert Uytterhoeven 	match = of_match_node(renesas_socs, of_root);
3048d6799a9SGeert Uytterhoeven 	if (!match)
3058d6799a9SGeert Uytterhoeven 		return -ENODEV;
3068d6799a9SGeert Uytterhoeven 
3078d6799a9SGeert Uytterhoeven 	soc = match->data;
3088d6799a9SGeert Uytterhoeven 	family = soc->family;
3098d6799a9SGeert Uytterhoeven 
310175f435fSChris Brandt 	np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
311175f435fSChris Brandt 	if (np) {
312175f435fSChris Brandt 		chipid = of_iomap(np, 0);
313175f435fSChris Brandt 		of_node_put(np);
314175f435fSChris Brandt 
315175f435fSChris Brandt 		if (chipid) {
316175f435fSChris Brandt 			product = readl(chipid);
317175f435fSChris Brandt 			iounmap(chipid);
318175f435fSChris Brandt 
319175f435fSChris Brandt 			if (soc->id && ((product >> 16) & 0xff) != soc->id) {
320175f435fSChris Brandt 				pr_warn("SoC mismatch (product = 0x%x)\n",
321175f435fSChris Brandt 					product);
322175f435fSChris Brandt 				return -ENODEV;
323175f435fSChris Brandt 			}
324175f435fSChris Brandt 		}
325175f435fSChris Brandt 
326175f435fSChris Brandt 		/*
327175f435fSChris Brandt 		 * TODO: Upper 4 bits of BSID are for chip version, but the
328175f435fSChris Brandt 		 * format is not known at this time so we don't know how to
329175f435fSChris Brandt 		 * specify eshi and eslo
330175f435fSChris Brandt 		 */
331175f435fSChris Brandt 
332175f435fSChris Brandt 		goto done;
333175f435fSChris Brandt 	}
334175f435fSChris Brandt 
3358d6799a9SGeert Uytterhoeven 	/* Try PRR first, then hardcoded fallback */
3368d6799a9SGeert Uytterhoeven 	np = of_find_compatible_node(NULL, NULL, "renesas,prr");
3378d6799a9SGeert Uytterhoeven 	if (np) {
3388d6799a9SGeert Uytterhoeven 		chipid = of_iomap(np, 0);
3398d6799a9SGeert Uytterhoeven 		of_node_put(np);
3404194b583SGeert Uytterhoeven 	} else if (soc->id && family->reg) {
3418d6799a9SGeert Uytterhoeven 		chipid = ioremap(family->reg, 4);
3428d6799a9SGeert Uytterhoeven 	}
3438d6799a9SGeert Uytterhoeven 	if (chipid) {
3448d6799a9SGeert Uytterhoeven 		product = readl(chipid);
3458d6799a9SGeert Uytterhoeven 		iounmap(chipid);
34690f0d2b3SGeert Uytterhoeven 		/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
34790f0d2b3SGeert Uytterhoeven 		if ((product & 0x7fff) == 0x5210)
34890f0d2b3SGeert Uytterhoeven 			product ^= 0x11;
34915160f6dSTakeshi Kihara 		/* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
35015160f6dSTakeshi Kihara 		if ((product & 0x7fff) == 0x5211)
35115160f6dSTakeshi Kihara 			product ^= 0x12;
3528d6799a9SGeert Uytterhoeven 		if (soc->id && ((product >> 8) & 0xff) != soc->id) {
3538d6799a9SGeert Uytterhoeven 			pr_warn("SoC mismatch (product = 0x%x)\n", product);
3548d6799a9SGeert Uytterhoeven 			return -ENODEV;
3558d6799a9SGeert Uytterhoeven 		}
356175f435fSChris Brandt 		eshi = ((product >> 4) & 0x0f) + 1;
357175f435fSChris Brandt 		eslo = product & 0xf;
3588d6799a9SGeert Uytterhoeven 	}
3598d6799a9SGeert Uytterhoeven 
360175f435fSChris Brandt done:
3618d6799a9SGeert Uytterhoeven 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
3628d6799a9SGeert Uytterhoeven 	if (!soc_dev_attr)
3638d6799a9SGeert Uytterhoeven 		return -ENOMEM;
3648d6799a9SGeert Uytterhoeven 
3658d6799a9SGeert Uytterhoeven 	np = of_find_node_by_path("/");
3668d6799a9SGeert Uytterhoeven 	of_property_read_string(np, "model", &soc_dev_attr->machine);
3678d6799a9SGeert Uytterhoeven 	of_node_put(np);
3688d6799a9SGeert Uytterhoeven 
3698d6799a9SGeert Uytterhoeven 	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
3708d6799a9SGeert Uytterhoeven 	soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
3718d6799a9SGeert Uytterhoeven 					     GFP_KERNEL);
372175f435fSChris Brandt 	if (eshi)
373175f435fSChris Brandt 		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
374175f435fSChris Brandt 						   eslo);
3758d6799a9SGeert Uytterhoeven 
3768d6799a9SGeert Uytterhoeven 	pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
3778d6799a9SGeert Uytterhoeven 		soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
3788d6799a9SGeert Uytterhoeven 
3798d6799a9SGeert Uytterhoeven 	soc_dev = soc_device_register(soc_dev_attr);
3808d6799a9SGeert Uytterhoeven 	if (IS_ERR(soc_dev)) {
3818d6799a9SGeert Uytterhoeven 		kfree(soc_dev_attr->revision);
3828d6799a9SGeert Uytterhoeven 		kfree_const(soc_dev_attr->soc_id);
3838d6799a9SGeert Uytterhoeven 		kfree_const(soc_dev_attr->family);
3848d6799a9SGeert Uytterhoeven 		kfree(soc_dev_attr);
3858d6799a9SGeert Uytterhoeven 		return PTR_ERR(soc_dev);
3868d6799a9SGeert Uytterhoeven 	}
3878d6799a9SGeert Uytterhoeven 
3888d6799a9SGeert Uytterhoeven 	return 0;
3898d6799a9SGeert Uytterhoeven }
390b1d134baSGeert Uytterhoeven early_initcall(renesas_soc_init);
391