xref: /linux/drivers/soc/renesas/renesas-soc.c (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
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 struct renesas_family {
168d6799a9SGeert Uytterhoeven 	const char name[16];
178d6799a9SGeert Uytterhoeven 	u32 reg;			/* CCCR or PRR, if not in DT */
188d6799a9SGeert Uytterhoeven };
198d6799a9SGeert Uytterhoeven 
208d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
218d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen1",
228d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
238d6799a9SGeert Uytterhoeven };
248d6799a9SGeert Uytterhoeven 
258d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
268d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen2",
278d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
288d6799a9SGeert Uytterhoeven };
298d6799a9SGeert Uytterhoeven 
308d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
318d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen3",
328d6799a9SGeert Uytterhoeven 	.reg	= 0xfff00044,		/* PRR (Product Register) */
338d6799a9SGeert Uytterhoeven };
348d6799a9SGeert Uytterhoeven 
3597116335SYoshihiro Shimoda static const struct renesas_family fam_rcar_gen4 __initconst __maybe_unused = {
3697116335SYoshihiro Shimoda 	.name	= "R-Car Gen4",
3797116335SYoshihiro Shimoda };
3897116335SYoshihiro Shimoda 
398d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
408d6799a9SGeert Uytterhoeven 	.name	= "R-Mobile",
418d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
428d6799a9SGeert Uytterhoeven };
438d6799a9SGeert Uytterhoeven 
44175f435fSChris Brandt static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
45175f435fSChris Brandt 	.name	= "RZ/A1",
46175f435fSChris Brandt };
47175f435fSChris Brandt 
48175f435fSChris Brandt static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
49175f435fSChris Brandt 	.name	= "RZ/A2",
508d6799a9SGeert Uytterhoeven };
518d6799a9SGeert Uytterhoeven 
52ebd0e06fSLad Prabhakar static const struct renesas_family fam_rzfive __initconst __maybe_unused = {
53ebd0e06fSLad Prabhakar 	.name	= "RZ/Five",
54ebd0e06fSLad Prabhakar };
55ebd0e06fSLad Prabhakar 
562a4056a7SBiju Das static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
572a4056a7SBiju Das 	.name	= "RZ/G1",
588d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
598d6799a9SGeert Uytterhoeven };
608d6799a9SGeert Uytterhoeven 
612a4056a7SBiju Das static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
622a4056a7SBiju Das 	.name	= "RZ/G2",
632a4056a7SBiju Das 	.reg	= 0xfff00044,		/* PRR (Product Register) */
642a4056a7SBiju Das };
652a4056a7SBiju Das 
66187cd57dSLad Prabhakar static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
67187cd57dSLad Prabhakar 	.name	= "RZ/G2L",
68187cd57dSLad Prabhakar };
69187cd57dSLad Prabhakar 
702f89bef9SBiju Das static const struct renesas_family fam_rzg2ul __initconst __maybe_unused = {
712f89bef9SBiju Das 	.name	= "RZ/G2UL",
722f89bef9SBiju Das };
732f89bef9SBiju Das 
740b9729cdSClaudiu Beznea static const struct renesas_family fam_rzg3s __initconst __maybe_unused = {
750b9729cdSClaudiu Beznea 	.name	= "RZ/G3S",
760b9729cdSClaudiu Beznea };
770b9729cdSClaudiu Beznea 
78*0be9a322SLad Prabhakar static const struct renesas_family fam_rzv2h __initconst __maybe_unused = {
79*0be9a322SLad Prabhakar 	.name	= "RZ/V2H",
80*0be9a322SLad Prabhakar };
81*0be9a322SLad Prabhakar 
82860122d8SBiju Das static const struct renesas_family fam_rzv2l __initconst __maybe_unused = {
83860122d8SBiju Das 	.name	= "RZ/V2L",
84860122d8SBiju Das };
85860122d8SBiju Das 
867e200440SPhil Edworthy static const struct renesas_family fam_rzv2m __initconst __maybe_unused = {
877e200440SPhil Edworthy 	.name	= "RZ/V2M",
887e200440SPhil Edworthy };
897e200440SPhil Edworthy 
908d6799a9SGeert Uytterhoeven static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
918d6799a9SGeert Uytterhoeven 	.name	= "SH-Mobile",
928d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
938d6799a9SGeert Uytterhoeven };
948d6799a9SGeert Uytterhoeven 
958d6799a9SGeert Uytterhoeven struct renesas_soc {
968d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
97187cd57dSLad Prabhakar 	u32 id;
988d6799a9SGeert Uytterhoeven };
998d6799a9SGeert Uytterhoeven 
1008d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
101175f435fSChris Brandt 	.family	= &fam_rza1,
102175f435fSChris Brandt };
103175f435fSChris Brandt 
104175f435fSChris Brandt static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
105175f435fSChris Brandt 	.family	= &fam_rza2,
106175f435fSChris Brandt 	.id	= 0x3b,
1078d6799a9SGeert Uytterhoeven };
1088d6799a9SGeert Uytterhoeven 
1098d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
1108d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
1118d6799a9SGeert Uytterhoeven 	.id	= 0x3f,
1128d6799a9SGeert Uytterhoeven };
1138d6799a9SGeert Uytterhoeven 
1148d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
1158d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
1168d6799a9SGeert Uytterhoeven 	.id	= 0x40,
1178d6799a9SGeert Uytterhoeven };
1188d6799a9SGeert Uytterhoeven 
119ebd0e06fSLad Prabhakar static const struct renesas_soc soc_rz_five __initconst __maybe_unused = {
120ebd0e06fSLad Prabhakar 	.family = &fam_rzfive,
121ebd0e06fSLad Prabhakar 	.id     = 0x847c447,
122ebd0e06fSLad Prabhakar };
123ebd0e06fSLad Prabhakar 
1248848e1b1SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
1252a4056a7SBiju Das 	.family	= &fam_rzg1,
1268848e1b1SGeert Uytterhoeven 	.id	= 0x45,
1278848e1b1SGeert Uytterhoeven };
1288848e1b1SGeert Uytterhoeven 
1298d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
1302a4056a7SBiju Das 	.family	= &fam_rzg1,
1318d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1328d6799a9SGeert Uytterhoeven };
1338d6799a9SGeert Uytterhoeven 
134cd59de80SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
1352a4056a7SBiju Das 	.family	= &fam_rzg1,
136cd59de80SGeert Uytterhoeven 	.id	= 0x4b,
137cd59de80SGeert Uytterhoeven };
138cd59de80SGeert Uytterhoeven 
1398d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
1402a4056a7SBiju Das 	.family	= &fam_rzg1,
1418d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1428d6799a9SGeert Uytterhoeven };
1438d6799a9SGeert Uytterhoeven 
1441daf13baSBiju Das static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
1452a4056a7SBiju Das 	.family	= &fam_rzg1,
1461daf13baSBiju Das 	.id	= 0x53,
1471daf13baSBiju Das };
1481daf13baSBiju Das 
1492a4056a7SBiju Das static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
1502a4056a7SBiju Das 	.family	= &fam_rzg2,
1512a4056a7SBiju Das 	.id	= 0x52,
1522a4056a7SBiju Das };
1532a4056a7SBiju Das 
154574cb721SBiju Das static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
155574cb721SBiju Das 	.family = &fam_rzg2,
156574cb721SBiju Das 	.id     = 0x55,
157574cb721SBiju Das };
158574cb721SBiju Das 
1592bab3d80SFabrizio Castro static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
1602bab3d80SFabrizio Castro 	.family	= &fam_rzg2,
1612bab3d80SFabrizio Castro 	.id	= 0x57,
1622bab3d80SFabrizio Castro };
1632bab3d80SFabrizio Castro 
1645b83cc42SMarian-Cristian Rotariu static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
1655b83cc42SMarian-Cristian Rotariu 	.family	= &fam_rzg2,
1665b83cc42SMarian-Cristian Rotariu 	.id	= 0x4f,
1675b83cc42SMarian-Cristian Rotariu };
1685b83cc42SMarian-Cristian Rotariu 
169187cd57dSLad Prabhakar static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
170187cd57dSLad Prabhakar 	.family = &fam_rzg2l,
171187cd57dSLad Prabhakar 	.id     = 0x841c447,
172187cd57dSLad Prabhakar };
173187cd57dSLad Prabhakar 
1742f89bef9SBiju Das static const struct renesas_soc soc_rz_g2ul __initconst __maybe_unused = {
1752f89bef9SBiju Das 	.family = &fam_rzg2ul,
1762f89bef9SBiju Das 	.id     = 0x8450447,
1772f89bef9SBiju Das };
1782f89bef9SBiju Das 
1790b9729cdSClaudiu Beznea static const struct renesas_soc soc_rz_g3s __initconst __maybe_unused = {
1800b9729cdSClaudiu Beznea 	.family = &fam_rzg3s,
1810b9729cdSClaudiu Beznea 	.id	= 0x85e0447,
1820b9729cdSClaudiu Beznea };
1830b9729cdSClaudiu Beznea 
184*0be9a322SLad Prabhakar static const struct renesas_soc soc_rz_v2h __initconst __maybe_unused = {
185*0be9a322SLad Prabhakar 	.family = &fam_rzv2h,
186*0be9a322SLad Prabhakar 	.id     = 0x847a447,
187*0be9a322SLad Prabhakar };
188*0be9a322SLad Prabhakar 
189860122d8SBiju Das static const struct renesas_soc soc_rz_v2l __initconst __maybe_unused = {
190860122d8SBiju Das 	.family = &fam_rzv2l,
191860122d8SBiju Das 	.id     = 0x8447447,
192860122d8SBiju Das };
193860122d8SBiju Das 
1947e200440SPhil Edworthy static const struct renesas_soc soc_rz_v2m __initconst __maybe_unused = {
1957e200440SPhil Edworthy 	.family = &fam_rzv2m,
1967e200440SPhil Edworthy };
1977e200440SPhil Edworthy 
1988d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
1998d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
2008d6799a9SGeert Uytterhoeven };
2018d6799a9SGeert Uytterhoeven 
2028d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
2038d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
2048d6799a9SGeert Uytterhoeven 	.id	= 0x3b,
2058d6799a9SGeert Uytterhoeven };
2068d6799a9SGeert Uytterhoeven 
2078d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
2088d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
2098d6799a9SGeert Uytterhoeven 	.id	= 0x45,
2108d6799a9SGeert Uytterhoeven };
2118d6799a9SGeert Uytterhoeven 
2128d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
2138d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
2148d6799a9SGeert Uytterhoeven 	.id	= 0x47,
2158d6799a9SGeert Uytterhoeven };
2168d6799a9SGeert Uytterhoeven 
2178d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
2188d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
2198d6799a9SGeert Uytterhoeven 	.id	= 0x4a,
2208d6799a9SGeert Uytterhoeven };
2218d6799a9SGeert Uytterhoeven 
2228d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
2238d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
2248d6799a9SGeert Uytterhoeven 	.id	= 0x4b,
2258d6799a9SGeert Uytterhoeven };
2268d6799a9SGeert Uytterhoeven 
2278d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
2288d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
2298d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
2308d6799a9SGeert Uytterhoeven };
2318d6799a9SGeert Uytterhoeven 
2328d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
2338d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2348d6799a9SGeert Uytterhoeven 	.id	= 0x4f,
2358d6799a9SGeert Uytterhoeven };
2368d6799a9SGeert Uytterhoeven 
2378d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
2388d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2398d6799a9SGeert Uytterhoeven 	.id	= 0x52,
2408d6799a9SGeert Uytterhoeven };
2418d6799a9SGeert Uytterhoeven 
242bfd83983SJacopo Mondi static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
243bfd83983SJacopo Mondi 	.family = &fam_rcar_gen3,
244bfd83983SJacopo Mondi 	.id     = 0x55,
245bfd83983SJacopo Mondi };
246bfd83983SJacopo Mondi 
247bb003075SSergei Shtylyov static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
248bb003075SSergei Shtylyov 	.family	= &fam_rcar_gen3,
249bb003075SSergei Shtylyov 	.id	= 0x54,
250bb003075SSergei Shtylyov };
251bb003075SSergei Shtylyov 
2528447756dSSergei Shtylyov static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
2538447756dSSergei Shtylyov 	.family	= &fam_rcar_gen3,
2548447756dSSergei Shtylyov 	.id	= 0x56,
2558447756dSSergei Shtylyov };
2568447756dSSergei Shtylyov 
25744842d45STakeshi Kihara static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
25844842d45STakeshi Kihara 	.family	= &fam_rcar_gen3,
25944842d45STakeshi Kihara 	.id	= 0x57,
26044842d45STakeshi Kihara };
26144842d45STakeshi Kihara 
2621b954784SGeert Uytterhoeven static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
2631b954784SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2641b954784SGeert Uytterhoeven 	.id	= 0x58,
2651b954784SGeert Uytterhoeven };
2661b954784SGeert Uytterhoeven 
267090e87e7SYoshihiro Shimoda static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
26827e7657aSGeert Uytterhoeven 	.family	= &fam_rcar_gen4,
269090e87e7SYoshihiro Shimoda 	.id	= 0x59,
270090e87e7SYoshihiro Shimoda };
271090e87e7SYoshihiro Shimoda 
27297116335SYoshihiro Shimoda static const struct renesas_soc soc_rcar_s4 __initconst __maybe_unused = {
27397116335SYoshihiro Shimoda 	.family	= &fam_rcar_gen4,
27497116335SYoshihiro Shimoda 	.id	= 0x5a,
27597116335SYoshihiro Shimoda };
27697116335SYoshihiro Shimoda 
27787ab58e1SYoshihiro Shimoda static const struct renesas_soc soc_rcar_v4h __initconst __maybe_unused = {
27887ab58e1SYoshihiro Shimoda 	.family	= &fam_rcar_gen4,
27987ab58e1SYoshihiro Shimoda 	.id	= 0x5c,
28087ab58e1SYoshihiro Shimoda };
28187ab58e1SYoshihiro Shimoda 
2822969768dSDuy Nguyen static const struct renesas_soc soc_rcar_v4m __initconst __maybe_unused = {
2832969768dSDuy Nguyen 	.family = &fam_rcar_gen4,
2842969768dSDuy Nguyen 	.id     = 0x5d,
2852969768dSDuy Nguyen };
2862969768dSDuy Nguyen 
2878d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
2888d6799a9SGeert Uytterhoeven 	.family	= &fam_shmobile,
2898d6799a9SGeert Uytterhoeven 	.id	= 0x37,
2908d6799a9SGeert Uytterhoeven };
2918d6799a9SGeert Uytterhoeven 
2928d6799a9SGeert Uytterhoeven 
293ddb705deSKrzysztof Kozlowski static const struct of_device_id renesas_socs[] __initconst __maybe_unused = {
2948d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R7S72100
2958d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
2968d6799a9SGeert Uytterhoeven #endif
297175f435fSChris Brandt #ifdef CONFIG_ARCH_R7S9210
298175f435fSChris Brandt 	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
299175f435fSChris Brandt #endif
3008d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A73A4
3018d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
3028d6799a9SGeert Uytterhoeven #endif
3038d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7740
3048d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
3058d6799a9SGeert Uytterhoeven #endif
3068848e1b1SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7742
3078848e1b1SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
3088848e1b1SGeert Uytterhoeven #endif
3098d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7743
3108d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
3118d6799a9SGeert Uytterhoeven #endif
312cd59de80SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7744
313cd59de80SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
314cd59de80SGeert Uytterhoeven #endif
3158d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7745
3168d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
3178d6799a9SGeert Uytterhoeven #endif
3181daf13baSBiju Das #ifdef CONFIG_ARCH_R8A77470
3191daf13baSBiju Das 	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
3201daf13baSBiju Das #endif
3212a4056a7SBiju Das #ifdef CONFIG_ARCH_R8A774A1
3222a4056a7SBiju Das 	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
3232a4056a7SBiju Das #endif
324574cb721SBiju Das #ifdef CONFIG_ARCH_R8A774B1
325574cb721SBiju Das 	{ .compatible = "renesas,r8a774b1",	.data = &soc_rz_g2n },
326574cb721SBiju Das #endif
3272bab3d80SFabrizio Castro #ifdef CONFIG_ARCH_R8A774C0
3282bab3d80SFabrizio Castro 	{ .compatible = "renesas,r8a774c0",	.data = &soc_rz_g2e },
3292bab3d80SFabrizio Castro #endif
3305b83cc42SMarian-Cristian Rotariu #ifdef CONFIG_ARCH_R8A774E1
3315b83cc42SMarian-Cristian Rotariu 	{ .compatible = "renesas,r8a774e1",	.data = &soc_rz_g2h },
3325b83cc42SMarian-Cristian Rotariu #endif
3338d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7778
3348d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
3358d6799a9SGeert Uytterhoeven #endif
3368d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7779
3378d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
3388d6799a9SGeert Uytterhoeven #endif
3398d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7790
3408d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
3418d6799a9SGeert Uytterhoeven #endif
3428d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7791
3438d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
3448d6799a9SGeert Uytterhoeven #endif
3458d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7792
3468d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
3478d6799a9SGeert Uytterhoeven #endif
3488d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7793
3498d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
3508d6799a9SGeert Uytterhoeven #endif
3518d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7794
3528d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
3538d6799a9SGeert Uytterhoeven #endif
354bfe6b559SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77951
35518ecaaeaSWolfram Sang 	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
3562ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m0",	.data = &soc_rcar_h3 },
357bfe6b559SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m1",	.data = &soc_rcar_h3 },
3582ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m8",	.data = &soc_rcar_h3 },
3591b37236dSGeert Uytterhoeven 	{ .compatible = "renesas,r8a779mb",	.data = &soc_rcar_h3 },
360bfe6b559SGeert Uytterhoeven #endif
36139e57e14SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77960
3628d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
3638d6799a9SGeert Uytterhoeven #endif
3649c9f7891SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77961
3659c9f7891SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77961",	.data = &soc_rcar_m3_w },
3662ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m2",	.data = &soc_rcar_m3_w },
367bfe6b559SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m3",	.data = &soc_rcar_m3_w },
3689c9f7891SGeert Uytterhoeven #endif
369bfd83983SJacopo Mondi #ifdef CONFIG_ARCH_R8A77965
370bfd83983SJacopo Mondi 	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
3712ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m4",	.data = &soc_rcar_m3_n },
3722ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m5",	.data = &soc_rcar_m3_n },
373bfd83983SJacopo Mondi #endif
374bb003075SSergei Shtylyov #ifdef CONFIG_ARCH_R8A77970
375bb003075SSergei Shtylyov 	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
376bb003075SSergei Shtylyov #endif
3778447756dSSergei Shtylyov #ifdef CONFIG_ARCH_R8A77980
3788447756dSSergei Shtylyov 	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
3798447756dSSergei Shtylyov #endif
38044842d45STakeshi Kihara #ifdef CONFIG_ARCH_R8A77990
38144842d45STakeshi Kihara 	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
3822ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m6",	.data = &soc_rcar_e3 },
38344842d45STakeshi Kihara #endif
3841b954784SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77995
3851b954784SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
3862ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m7",	.data = &soc_rcar_d3 },
3871b954784SGeert Uytterhoeven #endif
388090e87e7SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779A0
389090e87e7SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779a0",	.data = &soc_rcar_v3u },
390090e87e7SYoshihiro Shimoda #endif
39197116335SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779F0
39297116335SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779f0",	.data = &soc_rcar_s4 },
39397116335SYoshihiro Shimoda #endif
39487ab58e1SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779G0
39587ab58e1SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779g0",	.data = &soc_rcar_v4h },
39687ab58e1SYoshihiro Shimoda #endif
3972969768dSDuy Nguyen #ifdef CONFIG_ARCH_R8A779H0
3982969768dSDuy Nguyen 	{ .compatible = "renesas,r8a779h0",	.data = &soc_rcar_v4m },
3992969768dSDuy Nguyen #endif
4002653d5bfSGeert Uytterhoeven #ifdef CONFIG_ARCH_R9A07G043
401ebd0e06fSLad Prabhakar #ifdef CONFIG_RISCV
402ebd0e06fSLad Prabhakar 	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_five },
403ebd0e06fSLad Prabhakar #else
4042f89bef9SBiju Das 	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_g2ul },
4052f89bef9SBiju Das #endif
406ebd0e06fSLad Prabhakar #endif
4072653d5bfSGeert Uytterhoeven #ifdef CONFIG_ARCH_R9A07G044
408187cd57dSLad Prabhakar 	{ .compatible = "renesas,r9a07g044",	.data = &soc_rz_g2l },
409187cd57dSLad Prabhakar #endif
4102653d5bfSGeert Uytterhoeven #ifdef CONFIG_ARCH_R9A07G054
411860122d8SBiju Das 	{ .compatible = "renesas,r9a07g054",	.data = &soc_rz_v2l },
412860122d8SBiju Das #endif
4130b9729cdSClaudiu Beznea #ifdef CONFIG_ARCH_R9A08G045
4140b9729cdSClaudiu Beznea 	{ .compatible = "renesas,r9a08g045",	.data = &soc_rz_g3s },
4150b9729cdSClaudiu Beznea #endif
4162653d5bfSGeert Uytterhoeven #ifdef CONFIG_ARCH_R9A09G011
4177e200440SPhil Edworthy 	{ .compatible = "renesas,r9a09g011",	.data = &soc_rz_v2m },
4187e200440SPhil Edworthy #endif
419*0be9a322SLad Prabhakar #ifdef CONFIG_ARCH_R9A09G057
420*0be9a322SLad Prabhakar 	{ .compatible = "renesas,r9a09g057",	.data = &soc_rz_v2h },
421*0be9a322SLad Prabhakar #endif
4228d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_SH73A0
4238d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
4248d6799a9SGeert Uytterhoeven #endif
4258d6799a9SGeert Uytterhoeven 	{ /* sentinel */ }
4268d6799a9SGeert Uytterhoeven };
4278d6799a9SGeert Uytterhoeven 
42805b22caaSGeert Uytterhoeven struct renesas_id {
42905b22caaSGeert Uytterhoeven 	unsigned int offset;
43005b22caaSGeert Uytterhoeven 	u32 mask;
43105b22caaSGeert Uytterhoeven };
43205b22caaSGeert Uytterhoeven 
43305b22caaSGeert Uytterhoeven static const struct renesas_id id_bsid __initconst = {
43405b22caaSGeert Uytterhoeven 	.offset = 0,
43505b22caaSGeert Uytterhoeven 	.mask = 0xff0000,
43605b22caaSGeert Uytterhoeven 	/*
43705b22caaSGeert Uytterhoeven 	 * TODO: Upper 4 bits of BSID are for chip version, but the format is
43805b22caaSGeert Uytterhoeven 	 * not known at this time so we don't know how to specify eshi and eslo
43905b22caaSGeert Uytterhoeven 	 */
44005b22caaSGeert Uytterhoeven };
44105b22caaSGeert Uytterhoeven 
44205b22caaSGeert Uytterhoeven static const struct renesas_id id_rzg2l __initconst = {
44305b22caaSGeert Uytterhoeven 	.offset = 0xa04,
44405b22caaSGeert Uytterhoeven 	.mask = 0xfffffff,
44505b22caaSGeert Uytterhoeven };
44605b22caaSGeert Uytterhoeven 
447*0be9a322SLad Prabhakar static const struct renesas_id id_rzv2h __initconst = {
448*0be9a322SLad Prabhakar 	.offset = 0x304,
449*0be9a322SLad Prabhakar 	.mask = 0xfffffff,
450*0be9a322SLad Prabhakar };
451*0be9a322SLad Prabhakar 
4527e200440SPhil Edworthy static const struct renesas_id id_rzv2m __initconst = {
4537e200440SPhil Edworthy 	.offset = 0x104,
4547e200440SPhil Edworthy 	.mask = 0xff,
4557e200440SPhil Edworthy };
4567e200440SPhil Edworthy 
45705b22caaSGeert Uytterhoeven static const struct renesas_id id_prr __initconst = {
45805b22caaSGeert Uytterhoeven 	.offset = 0,
45905b22caaSGeert Uytterhoeven 	.mask = 0xff00,
46005b22caaSGeert Uytterhoeven };
46105b22caaSGeert Uytterhoeven 
46205b22caaSGeert Uytterhoeven static const struct of_device_id renesas_ids[] __initconst = {
46305b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,bsid",			.data = &id_bsid },
4642f89bef9SBiju Das 	{ .compatible = "renesas,r9a07g043-sysc",	.data = &id_rzg2l },
46505b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,r9a07g044-sysc",	.data = &id_rzg2l },
466860122d8SBiju Das 	{ .compatible = "renesas,r9a07g054-sysc",	.data = &id_rzg2l },
4670b9729cdSClaudiu Beznea 	{ .compatible = "renesas,r9a08g045-sysc",	.data = &id_rzg2l },
4687e200440SPhil Edworthy 	{ .compatible = "renesas,r9a09g011-sys",	.data = &id_rzv2m },
469*0be9a322SLad Prabhakar 	{ .compatible = "renesas,r9a09g057-sys",	.data = &id_rzv2h },
47005b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,prr",			.data = &id_prr },
47105b22caaSGeert Uytterhoeven 	{ /* sentinel */ }
47205b22caaSGeert Uytterhoeven };
47305b22caaSGeert Uytterhoeven 
renesas_soc_init(void)4748d6799a9SGeert Uytterhoeven static int __init renesas_soc_init(void)
4758d6799a9SGeert Uytterhoeven {
4768d6799a9SGeert Uytterhoeven 	struct soc_device_attribute *soc_dev_attr;
47705b22caaSGeert Uytterhoeven 	unsigned int product, eshi = 0, eslo;
4788d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
4798d6799a9SGeert Uytterhoeven 	const struct of_device_id *match;
4808d6799a9SGeert Uytterhoeven 	const struct renesas_soc *soc;
48105b22caaSGeert Uytterhoeven 	const struct renesas_id *id;
4828d6799a9SGeert Uytterhoeven 	void __iomem *chipid = NULL;
483cb5508e4SBiju Das 	const char *rev_prefix = "";
4848d6799a9SGeert Uytterhoeven 	struct soc_device *soc_dev;
4858d6799a9SGeert Uytterhoeven 	struct device_node *np;
48605b22caaSGeert Uytterhoeven 	const char *soc_id;
487cb5508e4SBiju Das 	int ret;
4888d6799a9SGeert Uytterhoeven 
4898d6799a9SGeert Uytterhoeven 	match = of_match_node(renesas_socs, of_root);
4908d6799a9SGeert Uytterhoeven 	if (!match)
4918d6799a9SGeert Uytterhoeven 		return -ENODEV;
4928d6799a9SGeert Uytterhoeven 
49305b22caaSGeert Uytterhoeven 	soc_id = strchr(match->compatible, ',') + 1;
4948d6799a9SGeert Uytterhoeven 	soc = match->data;
4958d6799a9SGeert Uytterhoeven 	family = soc->family;
4968d6799a9SGeert Uytterhoeven 
49705b22caaSGeert Uytterhoeven 	np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
498175f435fSChris Brandt 	if (np) {
49905b22caaSGeert Uytterhoeven 		id = match->data;
5008d6799a9SGeert Uytterhoeven 		chipid = of_iomap(np, 0);
5018d6799a9SGeert Uytterhoeven 		of_node_put(np);
5024194b583SGeert Uytterhoeven 	} else if (soc->id && family->reg) {
50305b22caaSGeert Uytterhoeven 		/* Try hardcoded CCCR/PRR fallback */
50405b22caaSGeert Uytterhoeven 		id = &id_prr;
5058d6799a9SGeert Uytterhoeven 		chipid = ioremap(family->reg, 4);
5068d6799a9SGeert Uytterhoeven 	}
50705b22caaSGeert Uytterhoeven 
508cb5508e4SBiju Das 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
509fc187a46SLi Yang 	if (!soc_dev_attr) {
510fc187a46SLi Yang 		if (chipid)
511fc187a46SLi Yang 			iounmap(chipid);
512cb5508e4SBiju Das 		return -ENOMEM;
513fc187a46SLi Yang 	}
514cb5508e4SBiju Das 
515cb5508e4SBiju Das 	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
516cb5508e4SBiju Das 	soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);
517cb5508e4SBiju Das 
5188d6799a9SGeert Uytterhoeven 	if (chipid) {
51905b22caaSGeert Uytterhoeven 		product = readl(chipid + id->offset);
5208d6799a9SGeert Uytterhoeven 		iounmap(chipid);
52105b22caaSGeert Uytterhoeven 
52205b22caaSGeert Uytterhoeven 		if (id == &id_prr) {
52390f0d2b3SGeert Uytterhoeven 			/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
52490f0d2b3SGeert Uytterhoeven 			if ((product & 0x7fff) == 0x5210)
52590f0d2b3SGeert Uytterhoeven 				product ^= 0x11;
52615160f6dSTakeshi Kihara 			/* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
52715160f6dSTakeshi Kihara 			if ((product & 0x7fff) == 0x5211)
52815160f6dSTakeshi Kihara 				product ^= 0x12;
52905b22caaSGeert Uytterhoeven 
530175f435fSChris Brandt 			eshi = ((product >> 4) & 0x0f) + 1;
531175f435fSChris Brandt 			eslo = product & 0xf;
532cb5508e4SBiju Das 			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
533cb5508e4SBiju Das 							   eshi, eslo);
534*0be9a322SLad Prabhakar 		}  else if (id == &id_rzg2l || id == &id_rzv2h) {
535cb5508e4SBiju Das 			eshi =  ((product >> 28) & 0x0f);
536cb5508e4SBiju Das 			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u",
537cb5508e4SBiju Das 							   eshi);
538cb5508e4SBiju Das 			rev_prefix = "Rev ";
5397e200440SPhil Edworthy 		} else if (id == &id_rzv2m) {
5407e200440SPhil Edworthy 			eshi = ((product >> 4) & 0x0f);
5417e200440SPhil Edworthy 			eslo = product & 0xf;
5427e200440SPhil Edworthy 			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
5437e200440SPhil Edworthy 							   eshi, eslo);
5448d6799a9SGeert Uytterhoeven 		}
5458d6799a9SGeert Uytterhoeven 
54605b22caaSGeert Uytterhoeven 		if (soc->id &&
54705b22caaSGeert Uytterhoeven 		    ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
54805b22caaSGeert Uytterhoeven 			pr_warn("SoC mismatch (product = 0x%x)\n", product);
549cb5508e4SBiju Das 			ret = -ENODEV;
550cb5508e4SBiju Das 			goto free_soc_dev_attr;
55105b22caaSGeert Uytterhoeven 		}
55205b22caaSGeert Uytterhoeven 	}
55305b22caaSGeert Uytterhoeven 
554cb5508e4SBiju Das 	pr_info("Detected Renesas %s %s %s%s\n", soc_dev_attr->family,
555cb5508e4SBiju Das 		soc_dev_attr->soc_id, rev_prefix, soc_dev_attr->revision ?: "");
5568d6799a9SGeert Uytterhoeven 
5578d6799a9SGeert Uytterhoeven 	soc_dev = soc_device_register(soc_dev_attr);
5588d6799a9SGeert Uytterhoeven 	if (IS_ERR(soc_dev)) {
559cb5508e4SBiju Das 		ret = PTR_ERR(soc_dev);
560cb5508e4SBiju Das 		goto free_soc_dev_attr;
561cb5508e4SBiju Das 	}
562cb5508e4SBiju Das 
563cb5508e4SBiju Das 	return 0;
564cb5508e4SBiju Das 
565cb5508e4SBiju Das free_soc_dev_attr:
5668d6799a9SGeert Uytterhoeven 	kfree(soc_dev_attr->revision);
5678d6799a9SGeert Uytterhoeven 	kfree_const(soc_dev_attr->soc_id);
5688d6799a9SGeert Uytterhoeven 	kfree_const(soc_dev_attr->family);
5698d6799a9SGeert Uytterhoeven 	kfree(soc_dev_attr);
570cb5508e4SBiju Das 	return ret;
5718d6799a9SGeert Uytterhoeven }
572b1d134baSGeert Uytterhoeven early_initcall(renesas_soc_init);
573