xref: /linux/drivers/soc/renesas/renesas-soc.c (revision fc187a46a8e682f0f1167b230792b88de01ceaa0)
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 
3697116335SYoshihiro Shimoda static const struct renesas_family fam_rcar_gen4 __initconst __maybe_unused = {
3797116335SYoshihiro Shimoda 	.name	= "R-Car Gen4",
3897116335SYoshihiro Shimoda };
3997116335SYoshihiro Shimoda 
408d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
418d6799a9SGeert Uytterhoeven 	.name	= "R-Mobile",
428d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
438d6799a9SGeert Uytterhoeven };
448d6799a9SGeert Uytterhoeven 
45175f435fSChris Brandt static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
46175f435fSChris Brandt 	.name	= "RZ/A1",
47175f435fSChris Brandt };
48175f435fSChris Brandt 
49175f435fSChris Brandt static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
50175f435fSChris Brandt 	.name	= "RZ/A2",
518d6799a9SGeert Uytterhoeven };
528d6799a9SGeert Uytterhoeven 
53ebd0e06fSLad Prabhakar static const struct renesas_family fam_rzfive __initconst __maybe_unused = {
54ebd0e06fSLad Prabhakar 	.name	= "RZ/Five",
55ebd0e06fSLad Prabhakar };
56ebd0e06fSLad Prabhakar 
572a4056a7SBiju Das static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
582a4056a7SBiju Das 	.name	= "RZ/G1",
598d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
608d6799a9SGeert Uytterhoeven };
618d6799a9SGeert Uytterhoeven 
622a4056a7SBiju Das static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
632a4056a7SBiju Das 	.name	= "RZ/G2",
642a4056a7SBiju Das 	.reg	= 0xfff00044,		/* PRR (Product Register) */
652a4056a7SBiju Das };
662a4056a7SBiju Das 
67187cd57dSLad Prabhakar static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
68187cd57dSLad Prabhakar 	.name	= "RZ/G2L",
69187cd57dSLad Prabhakar };
70187cd57dSLad Prabhakar 
712f89bef9SBiju Das static const struct renesas_family fam_rzg2ul __initconst __maybe_unused = {
722f89bef9SBiju Das 	.name	= "RZ/G2UL",
732f89bef9SBiju Das };
742f89bef9SBiju Das 
75860122d8SBiju Das static const struct renesas_family fam_rzv2l __initconst __maybe_unused = {
76860122d8SBiju Das 	.name	= "RZ/V2L",
77860122d8SBiju Das };
78860122d8SBiju Das 
797e200440SPhil Edworthy static const struct renesas_family fam_rzv2m __initconst __maybe_unused = {
807e200440SPhil Edworthy 	.name	= "RZ/V2M",
817e200440SPhil Edworthy };
827e200440SPhil Edworthy 
838d6799a9SGeert Uytterhoeven static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
848d6799a9SGeert Uytterhoeven 	.name	= "SH-Mobile",
858d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
868d6799a9SGeert Uytterhoeven };
878d6799a9SGeert Uytterhoeven 
888d6799a9SGeert Uytterhoeven 
898d6799a9SGeert Uytterhoeven struct renesas_soc {
908d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
91187cd57dSLad Prabhakar 	u32 id;
928d6799a9SGeert Uytterhoeven };
938d6799a9SGeert Uytterhoeven 
948d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
95175f435fSChris Brandt 	.family	= &fam_rza1,
96175f435fSChris Brandt };
97175f435fSChris Brandt 
98175f435fSChris Brandt static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
99175f435fSChris Brandt 	.family	= &fam_rza2,
100175f435fSChris Brandt 	.id	= 0x3b,
1018d6799a9SGeert Uytterhoeven };
1028d6799a9SGeert Uytterhoeven 
1038d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
1048d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
1058d6799a9SGeert Uytterhoeven 	.id	= 0x3f,
1068d6799a9SGeert Uytterhoeven };
1078d6799a9SGeert Uytterhoeven 
1088d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
1098d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
1108d6799a9SGeert Uytterhoeven 	.id	= 0x40,
1118d6799a9SGeert Uytterhoeven };
1128d6799a9SGeert Uytterhoeven 
113ebd0e06fSLad Prabhakar static const struct renesas_soc soc_rz_five __initconst __maybe_unused = {
114ebd0e06fSLad Prabhakar 	.family = &fam_rzfive,
115ebd0e06fSLad Prabhakar 	.id     = 0x847c447,
116ebd0e06fSLad Prabhakar };
117ebd0e06fSLad Prabhakar 
1188848e1b1SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
1192a4056a7SBiju Das 	.family	= &fam_rzg1,
1208848e1b1SGeert Uytterhoeven 	.id	= 0x45,
1218848e1b1SGeert Uytterhoeven };
1228848e1b1SGeert Uytterhoeven 
1238d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
1242a4056a7SBiju Das 	.family	= &fam_rzg1,
1258d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1268d6799a9SGeert Uytterhoeven };
1278d6799a9SGeert Uytterhoeven 
128cd59de80SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
1292a4056a7SBiju Das 	.family	= &fam_rzg1,
130cd59de80SGeert Uytterhoeven 	.id	= 0x4b,
131cd59de80SGeert Uytterhoeven };
132cd59de80SGeert Uytterhoeven 
1338d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
1342a4056a7SBiju Das 	.family	= &fam_rzg1,
1358d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1368d6799a9SGeert Uytterhoeven };
1378d6799a9SGeert Uytterhoeven 
1381daf13baSBiju Das static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
1392a4056a7SBiju Das 	.family	= &fam_rzg1,
1401daf13baSBiju Das 	.id	= 0x53,
1411daf13baSBiju Das };
1421daf13baSBiju Das 
1432a4056a7SBiju Das static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
1442a4056a7SBiju Das 	.family	= &fam_rzg2,
1452a4056a7SBiju Das 	.id	= 0x52,
1462a4056a7SBiju Das };
1472a4056a7SBiju Das 
148574cb721SBiju Das static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
149574cb721SBiju Das 	.family = &fam_rzg2,
150574cb721SBiju Das 	.id     = 0x55,
151574cb721SBiju Das };
152574cb721SBiju Das 
1532bab3d80SFabrizio Castro static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
1542bab3d80SFabrizio Castro 	.family	= &fam_rzg2,
1552bab3d80SFabrizio Castro 	.id	= 0x57,
1562bab3d80SFabrizio Castro };
1572bab3d80SFabrizio Castro 
1585b83cc42SMarian-Cristian Rotariu static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
1595b83cc42SMarian-Cristian Rotariu 	.family	= &fam_rzg2,
1605b83cc42SMarian-Cristian Rotariu 	.id	= 0x4f,
1615b83cc42SMarian-Cristian Rotariu };
1625b83cc42SMarian-Cristian Rotariu 
163187cd57dSLad Prabhakar static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
164187cd57dSLad Prabhakar 	.family = &fam_rzg2l,
165187cd57dSLad Prabhakar 	.id     = 0x841c447,
166187cd57dSLad Prabhakar };
167187cd57dSLad Prabhakar 
1682f89bef9SBiju Das static const struct renesas_soc soc_rz_g2ul __initconst __maybe_unused = {
1692f89bef9SBiju Das 	.family = &fam_rzg2ul,
1702f89bef9SBiju Das 	.id     = 0x8450447,
1712f89bef9SBiju Das };
1722f89bef9SBiju Das 
173860122d8SBiju Das static const struct renesas_soc soc_rz_v2l __initconst __maybe_unused = {
174860122d8SBiju Das 	.family = &fam_rzv2l,
175860122d8SBiju Das 	.id     = 0x8447447,
176860122d8SBiju Das };
177860122d8SBiju Das 
1787e200440SPhil Edworthy static const struct renesas_soc soc_rz_v2m __initconst __maybe_unused = {
1797e200440SPhil Edworthy 	.family = &fam_rzv2m,
1807e200440SPhil Edworthy };
1817e200440SPhil Edworthy 
1828d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
1838d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1848d6799a9SGeert Uytterhoeven };
1858d6799a9SGeert Uytterhoeven 
1868d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
1878d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1888d6799a9SGeert Uytterhoeven 	.id	= 0x3b,
1898d6799a9SGeert Uytterhoeven };
1908d6799a9SGeert Uytterhoeven 
1918d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
1928d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1938d6799a9SGeert Uytterhoeven 	.id	= 0x45,
1948d6799a9SGeert Uytterhoeven };
1958d6799a9SGeert Uytterhoeven 
1968d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
1978d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1988d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1998d6799a9SGeert Uytterhoeven };
2008d6799a9SGeert Uytterhoeven 
2018d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
2028d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
2038d6799a9SGeert Uytterhoeven 	.id	= 0x4a,
2048d6799a9SGeert Uytterhoeven };
2058d6799a9SGeert Uytterhoeven 
2068d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
2078d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
2088d6799a9SGeert Uytterhoeven 	.id	= 0x4b,
2098d6799a9SGeert Uytterhoeven };
2108d6799a9SGeert Uytterhoeven 
2118d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
2128d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
2138d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
2148d6799a9SGeert Uytterhoeven };
2158d6799a9SGeert Uytterhoeven 
2168d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
2178d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2188d6799a9SGeert Uytterhoeven 	.id	= 0x4f,
2198d6799a9SGeert Uytterhoeven };
2208d6799a9SGeert Uytterhoeven 
2218d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
2228d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2238d6799a9SGeert Uytterhoeven 	.id	= 0x52,
2248d6799a9SGeert Uytterhoeven };
2258d6799a9SGeert Uytterhoeven 
226bfd83983SJacopo Mondi static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
227bfd83983SJacopo Mondi 	.family = &fam_rcar_gen3,
228bfd83983SJacopo Mondi 	.id     = 0x55,
229bfd83983SJacopo Mondi };
230bfd83983SJacopo Mondi 
231bb003075SSergei Shtylyov static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
232bb003075SSergei Shtylyov 	.family	= &fam_rcar_gen3,
233bb003075SSergei Shtylyov 	.id	= 0x54,
234bb003075SSergei Shtylyov };
235bb003075SSergei Shtylyov 
2368447756dSSergei Shtylyov static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
2378447756dSSergei Shtylyov 	.family	= &fam_rcar_gen3,
2388447756dSSergei Shtylyov 	.id	= 0x56,
2398447756dSSergei Shtylyov };
2408447756dSSergei Shtylyov 
24144842d45STakeshi Kihara static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
24244842d45STakeshi Kihara 	.family	= &fam_rcar_gen3,
24344842d45STakeshi Kihara 	.id	= 0x57,
24444842d45STakeshi Kihara };
24544842d45STakeshi Kihara 
2461b954784SGeert Uytterhoeven static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
2471b954784SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2481b954784SGeert Uytterhoeven 	.id	= 0x58,
2491b954784SGeert Uytterhoeven };
2501b954784SGeert Uytterhoeven 
251090e87e7SYoshihiro Shimoda static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
25227e7657aSGeert Uytterhoeven 	.family	= &fam_rcar_gen4,
253090e87e7SYoshihiro Shimoda 	.id	= 0x59,
254090e87e7SYoshihiro Shimoda };
255090e87e7SYoshihiro Shimoda 
25697116335SYoshihiro Shimoda static const struct renesas_soc soc_rcar_s4 __initconst __maybe_unused = {
25797116335SYoshihiro Shimoda 	.family	= &fam_rcar_gen4,
25897116335SYoshihiro Shimoda 	.id	= 0x5a,
25997116335SYoshihiro Shimoda };
26097116335SYoshihiro Shimoda 
26187ab58e1SYoshihiro Shimoda static const struct renesas_soc soc_rcar_v4h __initconst __maybe_unused = {
26287ab58e1SYoshihiro Shimoda 	.family	= &fam_rcar_gen4,
26387ab58e1SYoshihiro Shimoda 	.id	= 0x5c,
26487ab58e1SYoshihiro Shimoda };
26587ab58e1SYoshihiro Shimoda 
2668d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
2678d6799a9SGeert Uytterhoeven 	.family	= &fam_shmobile,
2688d6799a9SGeert Uytterhoeven 	.id	= 0x37,
2698d6799a9SGeert Uytterhoeven };
2708d6799a9SGeert Uytterhoeven 
2718d6799a9SGeert Uytterhoeven 
272ddb705deSKrzysztof Kozlowski static const struct of_device_id renesas_socs[] __initconst __maybe_unused = {
2738d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R7S72100
2748d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
2758d6799a9SGeert Uytterhoeven #endif
276175f435fSChris Brandt #ifdef CONFIG_ARCH_R7S9210
277175f435fSChris Brandt 	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
278175f435fSChris Brandt #endif
2798d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A73A4
2808d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
2818d6799a9SGeert Uytterhoeven #endif
2828d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7740
2838d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
2848d6799a9SGeert Uytterhoeven #endif
2858848e1b1SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7742
2868848e1b1SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
2878848e1b1SGeert Uytterhoeven #endif
2888d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7743
2898d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
2908d6799a9SGeert Uytterhoeven #endif
291cd59de80SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7744
292cd59de80SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
293cd59de80SGeert Uytterhoeven #endif
2948d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7745
2958d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
2968d6799a9SGeert Uytterhoeven #endif
2971daf13baSBiju Das #ifdef CONFIG_ARCH_R8A77470
2981daf13baSBiju Das 	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
2991daf13baSBiju Das #endif
3002a4056a7SBiju Das #ifdef CONFIG_ARCH_R8A774A1
3012a4056a7SBiju Das 	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
3022a4056a7SBiju Das #endif
303574cb721SBiju Das #ifdef CONFIG_ARCH_R8A774B1
304574cb721SBiju Das 	{ .compatible = "renesas,r8a774b1",	.data = &soc_rz_g2n },
305574cb721SBiju Das #endif
3062bab3d80SFabrizio Castro #ifdef CONFIG_ARCH_R8A774C0
3072bab3d80SFabrizio Castro 	{ .compatible = "renesas,r8a774c0",	.data = &soc_rz_g2e },
3082bab3d80SFabrizio Castro #endif
3095b83cc42SMarian-Cristian Rotariu #ifdef CONFIG_ARCH_R8A774E1
3105b83cc42SMarian-Cristian Rotariu 	{ .compatible = "renesas,r8a774e1",	.data = &soc_rz_g2h },
3115b83cc42SMarian-Cristian Rotariu #endif
3128d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7778
3138d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
3148d6799a9SGeert Uytterhoeven #endif
3158d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7779
3168d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
3178d6799a9SGeert Uytterhoeven #endif
3188d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7790
3198d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
3208d6799a9SGeert Uytterhoeven #endif
3218d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7791
3228d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
3238d6799a9SGeert Uytterhoeven #endif
3248d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7792
3258d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
3268d6799a9SGeert Uytterhoeven #endif
3278d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7793
3288d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
3298d6799a9SGeert Uytterhoeven #endif
3308d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7794
3318d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
3328d6799a9SGeert Uytterhoeven #endif
333bfe6b559SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77951
33418ecaaeaSWolfram Sang 	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
3352ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m0",	.data = &soc_rcar_h3 },
336bfe6b559SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m1",	.data = &soc_rcar_h3 },
3372ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m8",	.data = &soc_rcar_h3 },
3381b37236dSGeert Uytterhoeven 	{ .compatible = "renesas,r8a779mb",	.data = &soc_rcar_h3 },
339bfe6b559SGeert Uytterhoeven #endif
34039e57e14SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77960
3418d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
3428d6799a9SGeert Uytterhoeven #endif
3439c9f7891SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77961
3449c9f7891SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77961",	.data = &soc_rcar_m3_w },
3452ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m2",	.data = &soc_rcar_m3_w },
346bfe6b559SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m3",	.data = &soc_rcar_m3_w },
3479c9f7891SGeert Uytterhoeven #endif
348bfd83983SJacopo Mondi #ifdef CONFIG_ARCH_R8A77965
349bfd83983SJacopo Mondi 	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
3502ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m4",	.data = &soc_rcar_m3_n },
3512ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m5",	.data = &soc_rcar_m3_n },
352bfd83983SJacopo Mondi #endif
353bb003075SSergei Shtylyov #ifdef CONFIG_ARCH_R8A77970
354bb003075SSergei Shtylyov 	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
355bb003075SSergei Shtylyov #endif
3568447756dSSergei Shtylyov #ifdef CONFIG_ARCH_R8A77980
3578447756dSSergei Shtylyov 	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
3588447756dSSergei Shtylyov #endif
35944842d45STakeshi Kihara #ifdef CONFIG_ARCH_R8A77990
36044842d45STakeshi Kihara 	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
3612ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m6",	.data = &soc_rcar_e3 },
36244842d45STakeshi Kihara #endif
3631b954784SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77995
3641b954784SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
3652ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m7",	.data = &soc_rcar_d3 },
3661b954784SGeert Uytterhoeven #endif
367090e87e7SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779A0
368090e87e7SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779a0",	.data = &soc_rcar_v3u },
369090e87e7SYoshihiro Shimoda #endif
37097116335SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779F0
37197116335SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779f0",	.data = &soc_rcar_s4 },
37297116335SYoshihiro Shimoda #endif
37387ab58e1SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779G0
37487ab58e1SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779g0",	.data = &soc_rcar_v4h },
37587ab58e1SYoshihiro Shimoda #endif
3762653d5bfSGeert Uytterhoeven #ifdef CONFIG_ARCH_R9A07G043
377ebd0e06fSLad Prabhakar #ifdef CONFIG_RISCV
378ebd0e06fSLad Prabhakar 	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_five },
379ebd0e06fSLad Prabhakar #else
3802f89bef9SBiju Das 	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_g2ul },
3812f89bef9SBiju Das #endif
382ebd0e06fSLad Prabhakar #endif
3832653d5bfSGeert Uytterhoeven #ifdef CONFIG_ARCH_R9A07G044
384187cd57dSLad Prabhakar 	{ .compatible = "renesas,r9a07g044",	.data = &soc_rz_g2l },
385187cd57dSLad Prabhakar #endif
3862653d5bfSGeert Uytterhoeven #ifdef CONFIG_ARCH_R9A07G054
387860122d8SBiju Das 	{ .compatible = "renesas,r9a07g054",	.data = &soc_rz_v2l },
388860122d8SBiju Das #endif
3892653d5bfSGeert Uytterhoeven #ifdef CONFIG_ARCH_R9A09G011
3907e200440SPhil Edworthy 	{ .compatible = "renesas,r9a09g011",	.data = &soc_rz_v2m },
3917e200440SPhil Edworthy #endif
3928d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_SH73A0
3938d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
3948d6799a9SGeert Uytterhoeven #endif
3958d6799a9SGeert Uytterhoeven 	{ /* sentinel */ }
3968d6799a9SGeert Uytterhoeven };
3978d6799a9SGeert Uytterhoeven 
39805b22caaSGeert Uytterhoeven struct renesas_id {
39905b22caaSGeert Uytterhoeven 	unsigned int offset;
40005b22caaSGeert Uytterhoeven 	u32 mask;
40105b22caaSGeert Uytterhoeven };
40205b22caaSGeert Uytterhoeven 
40305b22caaSGeert Uytterhoeven static const struct renesas_id id_bsid __initconst = {
40405b22caaSGeert Uytterhoeven 	.offset = 0,
40505b22caaSGeert Uytterhoeven 	.mask = 0xff0000,
40605b22caaSGeert Uytterhoeven 	/*
40705b22caaSGeert Uytterhoeven 	 * TODO: Upper 4 bits of BSID are for chip version, but the format is
40805b22caaSGeert Uytterhoeven 	 * not known at this time so we don't know how to specify eshi and eslo
40905b22caaSGeert Uytterhoeven 	 */
41005b22caaSGeert Uytterhoeven };
41105b22caaSGeert Uytterhoeven 
41205b22caaSGeert Uytterhoeven static const struct renesas_id id_rzg2l __initconst = {
41305b22caaSGeert Uytterhoeven 	.offset = 0xa04,
41405b22caaSGeert Uytterhoeven 	.mask = 0xfffffff,
41505b22caaSGeert Uytterhoeven };
41605b22caaSGeert Uytterhoeven 
4177e200440SPhil Edworthy static const struct renesas_id id_rzv2m __initconst = {
4187e200440SPhil Edworthy 	.offset = 0x104,
4197e200440SPhil Edworthy 	.mask = 0xff,
4207e200440SPhil Edworthy };
4217e200440SPhil Edworthy 
42205b22caaSGeert Uytterhoeven static const struct renesas_id id_prr __initconst = {
42305b22caaSGeert Uytterhoeven 	.offset = 0,
42405b22caaSGeert Uytterhoeven 	.mask = 0xff00,
42505b22caaSGeert Uytterhoeven };
42605b22caaSGeert Uytterhoeven 
42705b22caaSGeert Uytterhoeven static const struct of_device_id renesas_ids[] __initconst = {
42805b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,bsid",			.data = &id_bsid },
4292f89bef9SBiju Das 	{ .compatible = "renesas,r9a07g043-sysc",	.data = &id_rzg2l },
43005b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,r9a07g044-sysc",	.data = &id_rzg2l },
431860122d8SBiju Das 	{ .compatible = "renesas,r9a07g054-sysc",	.data = &id_rzg2l },
4327e200440SPhil Edworthy 	{ .compatible = "renesas,r9a09g011-sys",	.data = &id_rzv2m },
43305b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,prr",			.data = &id_prr },
43405b22caaSGeert Uytterhoeven 	{ /* sentinel */ }
43505b22caaSGeert Uytterhoeven };
43605b22caaSGeert Uytterhoeven 
4378d6799a9SGeert Uytterhoeven static int __init renesas_soc_init(void)
4388d6799a9SGeert Uytterhoeven {
4398d6799a9SGeert Uytterhoeven 	struct soc_device_attribute *soc_dev_attr;
44005b22caaSGeert Uytterhoeven 	unsigned int product, eshi = 0, eslo;
4418d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
4428d6799a9SGeert Uytterhoeven 	const struct of_device_id *match;
4438d6799a9SGeert Uytterhoeven 	const struct renesas_soc *soc;
44405b22caaSGeert Uytterhoeven 	const struct renesas_id *id;
4458d6799a9SGeert Uytterhoeven 	void __iomem *chipid = NULL;
446cb5508e4SBiju Das 	const char *rev_prefix = "";
4478d6799a9SGeert Uytterhoeven 	struct soc_device *soc_dev;
4488d6799a9SGeert Uytterhoeven 	struct device_node *np;
44905b22caaSGeert Uytterhoeven 	const char *soc_id;
450cb5508e4SBiju Das 	int ret;
4518d6799a9SGeert Uytterhoeven 
4528d6799a9SGeert Uytterhoeven 	match = of_match_node(renesas_socs, of_root);
4538d6799a9SGeert Uytterhoeven 	if (!match)
4548d6799a9SGeert Uytterhoeven 		return -ENODEV;
4558d6799a9SGeert Uytterhoeven 
45605b22caaSGeert Uytterhoeven 	soc_id = strchr(match->compatible, ',') + 1;
4578d6799a9SGeert Uytterhoeven 	soc = match->data;
4588d6799a9SGeert Uytterhoeven 	family = soc->family;
4598d6799a9SGeert Uytterhoeven 
46005b22caaSGeert Uytterhoeven 	np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
461175f435fSChris Brandt 	if (np) {
46205b22caaSGeert Uytterhoeven 		id = match->data;
4638d6799a9SGeert Uytterhoeven 		chipid = of_iomap(np, 0);
4648d6799a9SGeert Uytterhoeven 		of_node_put(np);
4654194b583SGeert Uytterhoeven 	} else if (soc->id && family->reg) {
46605b22caaSGeert Uytterhoeven 		/* Try hardcoded CCCR/PRR fallback */
46705b22caaSGeert Uytterhoeven 		id = &id_prr;
4688d6799a9SGeert Uytterhoeven 		chipid = ioremap(family->reg, 4);
4698d6799a9SGeert Uytterhoeven 	}
47005b22caaSGeert Uytterhoeven 
471cb5508e4SBiju Das 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
472*fc187a46SLi Yang 	if (!soc_dev_attr) {
473*fc187a46SLi Yang 		if (chipid)
474*fc187a46SLi Yang 			iounmap(chipid);
475cb5508e4SBiju Das 		return -ENOMEM;
476*fc187a46SLi Yang 	}
477cb5508e4SBiju Das 
478cb5508e4SBiju Das 	np = of_find_node_by_path("/");
479cb5508e4SBiju Das 	of_property_read_string(np, "model", &soc_dev_attr->machine);
480cb5508e4SBiju Das 	of_node_put(np);
481cb5508e4SBiju Das 
482cb5508e4SBiju Das 	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
483cb5508e4SBiju Das 	soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);
484cb5508e4SBiju Das 
4858d6799a9SGeert Uytterhoeven 	if (chipid) {
48605b22caaSGeert Uytterhoeven 		product = readl(chipid + id->offset);
4878d6799a9SGeert Uytterhoeven 		iounmap(chipid);
48805b22caaSGeert Uytterhoeven 
48905b22caaSGeert Uytterhoeven 		if (id == &id_prr) {
49090f0d2b3SGeert Uytterhoeven 			/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
49190f0d2b3SGeert Uytterhoeven 			if ((product & 0x7fff) == 0x5210)
49290f0d2b3SGeert Uytterhoeven 				product ^= 0x11;
49315160f6dSTakeshi Kihara 			/* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
49415160f6dSTakeshi Kihara 			if ((product & 0x7fff) == 0x5211)
49515160f6dSTakeshi Kihara 				product ^= 0x12;
49605b22caaSGeert Uytterhoeven 
497175f435fSChris Brandt 			eshi = ((product >> 4) & 0x0f) + 1;
498175f435fSChris Brandt 			eslo = product & 0xf;
499cb5508e4SBiju Das 			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
500cb5508e4SBiju Das 							   eshi, eslo);
501cb5508e4SBiju Das 		}  else if (id == &id_rzg2l) {
502cb5508e4SBiju Das 			eshi =  ((product >> 28) & 0x0f);
503cb5508e4SBiju Das 			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u",
504cb5508e4SBiju Das 							   eshi);
505cb5508e4SBiju Das 			rev_prefix = "Rev ";
5067e200440SPhil Edworthy 		} else if (id == &id_rzv2m) {
5077e200440SPhil Edworthy 			eshi = ((product >> 4) & 0x0f);
5087e200440SPhil Edworthy 			eslo = product & 0xf;
5097e200440SPhil Edworthy 			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
5107e200440SPhil Edworthy 							   eshi, eslo);
5118d6799a9SGeert Uytterhoeven 		}
5128d6799a9SGeert Uytterhoeven 
51305b22caaSGeert Uytterhoeven 		if (soc->id &&
51405b22caaSGeert Uytterhoeven 		    ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
51505b22caaSGeert Uytterhoeven 			pr_warn("SoC mismatch (product = 0x%x)\n", product);
516cb5508e4SBiju Das 			ret = -ENODEV;
517cb5508e4SBiju Das 			goto free_soc_dev_attr;
51805b22caaSGeert Uytterhoeven 		}
51905b22caaSGeert Uytterhoeven 	}
52005b22caaSGeert Uytterhoeven 
521cb5508e4SBiju Das 	pr_info("Detected Renesas %s %s %s%s\n", soc_dev_attr->family,
522cb5508e4SBiju Das 		soc_dev_attr->soc_id, rev_prefix, soc_dev_attr->revision ?: "");
5238d6799a9SGeert Uytterhoeven 
5248d6799a9SGeert Uytterhoeven 	soc_dev = soc_device_register(soc_dev_attr);
5258d6799a9SGeert Uytterhoeven 	if (IS_ERR(soc_dev)) {
526cb5508e4SBiju Das 		ret = PTR_ERR(soc_dev);
527cb5508e4SBiju Das 		goto free_soc_dev_attr;
528cb5508e4SBiju Das 	}
529cb5508e4SBiju Das 
530cb5508e4SBiju Das 	return 0;
531cb5508e4SBiju Das 
532cb5508e4SBiju Das free_soc_dev_attr:
5338d6799a9SGeert Uytterhoeven 	kfree(soc_dev_attr->revision);
5348d6799a9SGeert Uytterhoeven 	kfree_const(soc_dev_attr->soc_id);
5358d6799a9SGeert Uytterhoeven 	kfree_const(soc_dev_attr->family);
5368d6799a9SGeert Uytterhoeven 	kfree(soc_dev_attr);
537cb5508e4SBiju Das 	return ret;
5388d6799a9SGeert Uytterhoeven }
539b1d134baSGeert Uytterhoeven early_initcall(renesas_soc_init);
540