xref: /linux/drivers/soc/renesas/renesas-soc.c (revision 05b22caa7490e4f4c94bbde33c61cf72d187b8f7)
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 
59187cd57dSLad Prabhakar static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
60187cd57dSLad Prabhakar 	.name	= "RZ/G2L",
61187cd57dSLad Prabhakar };
62187cd57dSLad Prabhakar 
638d6799a9SGeert Uytterhoeven static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
648d6799a9SGeert Uytterhoeven 	.name	= "SH-Mobile",
658d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
668d6799a9SGeert Uytterhoeven };
678d6799a9SGeert Uytterhoeven 
688d6799a9SGeert Uytterhoeven 
698d6799a9SGeert Uytterhoeven struct renesas_soc {
708d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
71187cd57dSLad Prabhakar 	u32 id;
728d6799a9SGeert Uytterhoeven };
738d6799a9SGeert Uytterhoeven 
748d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
75175f435fSChris Brandt 	.family	= &fam_rza1,
76175f435fSChris Brandt };
77175f435fSChris Brandt 
78175f435fSChris Brandt static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
79175f435fSChris Brandt 	.family	= &fam_rza2,
80175f435fSChris Brandt 	.id	= 0x3b,
818d6799a9SGeert Uytterhoeven };
828d6799a9SGeert Uytterhoeven 
838d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
848d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
858d6799a9SGeert Uytterhoeven 	.id	= 0x3f,
868d6799a9SGeert Uytterhoeven };
878d6799a9SGeert Uytterhoeven 
888d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
898d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
908d6799a9SGeert Uytterhoeven 	.id	= 0x40,
918d6799a9SGeert Uytterhoeven };
928d6799a9SGeert Uytterhoeven 
938848e1b1SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
942a4056a7SBiju Das 	.family	= &fam_rzg1,
958848e1b1SGeert Uytterhoeven 	.id	= 0x45,
968848e1b1SGeert Uytterhoeven };
978848e1b1SGeert Uytterhoeven 
988d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
992a4056a7SBiju Das 	.family	= &fam_rzg1,
1008d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1018d6799a9SGeert Uytterhoeven };
1028d6799a9SGeert Uytterhoeven 
103cd59de80SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
1042a4056a7SBiju Das 	.family	= &fam_rzg1,
105cd59de80SGeert Uytterhoeven 	.id	= 0x4b,
106cd59de80SGeert Uytterhoeven };
107cd59de80SGeert Uytterhoeven 
1088d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
1092a4056a7SBiju Das 	.family	= &fam_rzg1,
1108d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1118d6799a9SGeert Uytterhoeven };
1128d6799a9SGeert Uytterhoeven 
1131daf13baSBiju Das static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
1142a4056a7SBiju Das 	.family	= &fam_rzg1,
1151daf13baSBiju Das 	.id	= 0x53,
1161daf13baSBiju Das };
1171daf13baSBiju Das 
1182a4056a7SBiju Das static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
1192a4056a7SBiju Das 	.family	= &fam_rzg2,
1202a4056a7SBiju Das 	.id	= 0x52,
1212a4056a7SBiju Das };
1222a4056a7SBiju Das 
123574cb721SBiju Das static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
124574cb721SBiju Das 	.family = &fam_rzg2,
125574cb721SBiju Das 	.id     = 0x55,
126574cb721SBiju Das };
127574cb721SBiju Das 
1282bab3d80SFabrizio Castro static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
1292bab3d80SFabrizio Castro 	.family	= &fam_rzg2,
1302bab3d80SFabrizio Castro 	.id	= 0x57,
1312bab3d80SFabrizio Castro };
1322bab3d80SFabrizio Castro 
1335b83cc42SMarian-Cristian Rotariu static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
1345b83cc42SMarian-Cristian Rotariu 	.family	= &fam_rzg2,
1355b83cc42SMarian-Cristian Rotariu 	.id	= 0x4f,
1365b83cc42SMarian-Cristian Rotariu };
1375b83cc42SMarian-Cristian Rotariu 
138187cd57dSLad Prabhakar static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
139187cd57dSLad Prabhakar 	.family = &fam_rzg2l,
140187cd57dSLad Prabhakar 	.id     = 0x841c447,
141187cd57dSLad Prabhakar };
142187cd57dSLad Prabhakar 
1438d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
1448d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1458d6799a9SGeert Uytterhoeven };
1468d6799a9SGeert Uytterhoeven 
1478d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
1488d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1498d6799a9SGeert Uytterhoeven 	.id	= 0x3b,
1508d6799a9SGeert Uytterhoeven };
1518d6799a9SGeert Uytterhoeven 
1528d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
1538d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1548d6799a9SGeert Uytterhoeven 	.id	= 0x45,
1558d6799a9SGeert Uytterhoeven };
1568d6799a9SGeert Uytterhoeven 
1578d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
1588d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1598d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1608d6799a9SGeert Uytterhoeven };
1618d6799a9SGeert Uytterhoeven 
1628d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
1638d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1648d6799a9SGeert Uytterhoeven 	.id	= 0x4a,
1658d6799a9SGeert Uytterhoeven };
1668d6799a9SGeert Uytterhoeven 
1678d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
1688d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1698d6799a9SGeert Uytterhoeven 	.id	= 0x4b,
1708d6799a9SGeert Uytterhoeven };
1718d6799a9SGeert Uytterhoeven 
1728d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
1738d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1748d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1758d6799a9SGeert Uytterhoeven };
1768d6799a9SGeert Uytterhoeven 
1778d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
1788d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1798d6799a9SGeert Uytterhoeven 	.id	= 0x4f,
1808d6799a9SGeert Uytterhoeven };
1818d6799a9SGeert Uytterhoeven 
1828d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
1838d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1848d6799a9SGeert Uytterhoeven 	.id	= 0x52,
1858d6799a9SGeert Uytterhoeven };
1868d6799a9SGeert Uytterhoeven 
187bfd83983SJacopo Mondi static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
188bfd83983SJacopo Mondi 	.family = &fam_rcar_gen3,
189bfd83983SJacopo Mondi 	.id     = 0x55,
190bfd83983SJacopo Mondi };
191bfd83983SJacopo Mondi 
192bb003075SSergei Shtylyov static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
193bb003075SSergei Shtylyov 	.family	= &fam_rcar_gen3,
194bb003075SSergei Shtylyov 	.id	= 0x54,
195bb003075SSergei Shtylyov };
196bb003075SSergei Shtylyov 
1978447756dSSergei Shtylyov static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
1988447756dSSergei Shtylyov 	.family	= &fam_rcar_gen3,
1998447756dSSergei Shtylyov 	.id	= 0x56,
2008447756dSSergei Shtylyov };
2018447756dSSergei Shtylyov 
20244842d45STakeshi Kihara static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
20344842d45STakeshi Kihara 	.family	= &fam_rcar_gen3,
20444842d45STakeshi Kihara 	.id	= 0x57,
20544842d45STakeshi Kihara };
20644842d45STakeshi Kihara 
2071b954784SGeert Uytterhoeven static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
2081b954784SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2091b954784SGeert Uytterhoeven 	.id	= 0x58,
2101b954784SGeert Uytterhoeven };
2111b954784SGeert Uytterhoeven 
212090e87e7SYoshihiro Shimoda static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
213090e87e7SYoshihiro Shimoda 	.family	= &fam_rcar_gen3,
214090e87e7SYoshihiro Shimoda 	.id	= 0x59,
215090e87e7SYoshihiro Shimoda };
216090e87e7SYoshihiro Shimoda 
2178d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
2188d6799a9SGeert Uytterhoeven 	.family	= &fam_shmobile,
2198d6799a9SGeert Uytterhoeven 	.id	= 0x37,
2208d6799a9SGeert Uytterhoeven };
2218d6799a9SGeert Uytterhoeven 
2228d6799a9SGeert Uytterhoeven 
2238d6799a9SGeert Uytterhoeven static const struct of_device_id renesas_socs[] __initconst = {
2248d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R7S72100
2258d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
2268d6799a9SGeert Uytterhoeven #endif
227175f435fSChris Brandt #ifdef CONFIG_ARCH_R7S9210
228175f435fSChris Brandt 	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
229175f435fSChris Brandt #endif
2308d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A73A4
2318d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
2328d6799a9SGeert Uytterhoeven #endif
2338d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7740
2348d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
2358d6799a9SGeert Uytterhoeven #endif
2368848e1b1SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7742
2378848e1b1SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
2388848e1b1SGeert Uytterhoeven #endif
2398d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7743
2408d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
2418d6799a9SGeert Uytterhoeven #endif
242cd59de80SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7744
243cd59de80SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
244cd59de80SGeert Uytterhoeven #endif
2458d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7745
2468d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
2478d6799a9SGeert Uytterhoeven #endif
2481daf13baSBiju Das #ifdef CONFIG_ARCH_R8A77470
2491daf13baSBiju Das 	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
2501daf13baSBiju Das #endif
2512a4056a7SBiju Das #ifdef CONFIG_ARCH_R8A774A1
2522a4056a7SBiju Das 	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
2532a4056a7SBiju Das #endif
254574cb721SBiju Das #ifdef CONFIG_ARCH_R8A774B1
255574cb721SBiju Das 	{ .compatible = "renesas,r8a774b1",	.data = &soc_rz_g2n },
256574cb721SBiju Das #endif
2572bab3d80SFabrizio Castro #ifdef CONFIG_ARCH_R8A774C0
2582bab3d80SFabrizio Castro 	{ .compatible = "renesas,r8a774c0",	.data = &soc_rz_g2e },
2592bab3d80SFabrizio Castro #endif
2605b83cc42SMarian-Cristian Rotariu #ifdef CONFIG_ARCH_R8A774E1
2615b83cc42SMarian-Cristian Rotariu 	{ .compatible = "renesas,r8a774e1",	.data = &soc_rz_g2h },
2625b83cc42SMarian-Cristian Rotariu #endif
2638d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7778
2648d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
2658d6799a9SGeert Uytterhoeven #endif
2668d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7779
2678d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
2688d6799a9SGeert Uytterhoeven #endif
2698d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7790
2708d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
2718d6799a9SGeert Uytterhoeven #endif
2728d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7791
2738d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
2748d6799a9SGeert Uytterhoeven #endif
2758d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7792
2768d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
2778d6799a9SGeert Uytterhoeven #endif
2788d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7793
2798d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
2808d6799a9SGeert Uytterhoeven #endif
2818d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7794
2828d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
2838d6799a9SGeert Uytterhoeven #endif
2844ff27112SGeert Uytterhoeven #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
2858d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
2868d6799a9SGeert Uytterhoeven #endif
287bfe6b559SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77951
2882ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m0",	.data = &soc_rcar_h3 },
289bfe6b559SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m1",	.data = &soc_rcar_h3 },
2902ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m8",	.data = &soc_rcar_h3 },
291bfe6b559SGeert Uytterhoeven #endif
29239e57e14SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77960
2938d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
2948d6799a9SGeert Uytterhoeven #endif
2959c9f7891SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77961
2969c9f7891SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77961",	.data = &soc_rcar_m3_w },
2972ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m2",	.data = &soc_rcar_m3_w },
298bfe6b559SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m3",	.data = &soc_rcar_m3_w },
2999c9f7891SGeert Uytterhoeven #endif
300bfd83983SJacopo Mondi #ifdef CONFIG_ARCH_R8A77965
301bfd83983SJacopo Mondi 	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
3022ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m4",	.data = &soc_rcar_m3_n },
3032ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m5",	.data = &soc_rcar_m3_n },
304bfd83983SJacopo Mondi #endif
305bb003075SSergei Shtylyov #ifdef CONFIG_ARCH_R8A77970
306bb003075SSergei Shtylyov 	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
307bb003075SSergei Shtylyov #endif
3088447756dSSergei Shtylyov #ifdef CONFIG_ARCH_R8A77980
3098447756dSSergei Shtylyov 	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
3108447756dSSergei Shtylyov #endif
31144842d45STakeshi Kihara #ifdef CONFIG_ARCH_R8A77990
31244842d45STakeshi Kihara 	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
3132ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m6",	.data = &soc_rcar_e3 },
31444842d45STakeshi Kihara #endif
3151b954784SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77995
3161b954784SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
3172ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m7",	.data = &soc_rcar_d3 },
3181b954784SGeert Uytterhoeven #endif
319090e87e7SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779A0
320090e87e7SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779a0",	.data = &soc_rcar_v3u },
321090e87e7SYoshihiro Shimoda #endif
322187cd57dSLad Prabhakar #if defined(CONFIG_ARCH_R9A07G044)
323187cd57dSLad Prabhakar 	{ .compatible = "renesas,r9a07g044",	.data = &soc_rz_g2l },
324187cd57dSLad Prabhakar #endif
3258d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_SH73A0
3268d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
3278d6799a9SGeert Uytterhoeven #endif
3288d6799a9SGeert Uytterhoeven 	{ /* sentinel */ }
3298d6799a9SGeert Uytterhoeven };
3308d6799a9SGeert Uytterhoeven 
331*05b22caaSGeert Uytterhoeven struct renesas_id {
332*05b22caaSGeert Uytterhoeven 	unsigned int offset;
333*05b22caaSGeert Uytterhoeven 	u32 mask;
334*05b22caaSGeert Uytterhoeven };
335*05b22caaSGeert Uytterhoeven 
336*05b22caaSGeert Uytterhoeven static const struct renesas_id id_bsid __initconst = {
337*05b22caaSGeert Uytterhoeven 	.offset = 0,
338*05b22caaSGeert Uytterhoeven 	.mask = 0xff0000,
339*05b22caaSGeert Uytterhoeven 	/*
340*05b22caaSGeert Uytterhoeven 	 * TODO: Upper 4 bits of BSID are for chip version, but the format is
341*05b22caaSGeert Uytterhoeven 	 * not known at this time so we don't know how to specify eshi and eslo
342*05b22caaSGeert Uytterhoeven 	 */
343*05b22caaSGeert Uytterhoeven };
344*05b22caaSGeert Uytterhoeven 
345*05b22caaSGeert Uytterhoeven static const struct renesas_id id_rzg2l __initconst = {
346*05b22caaSGeert Uytterhoeven 	.offset = 0xa04,
347*05b22caaSGeert Uytterhoeven 	.mask = 0xfffffff,
348*05b22caaSGeert Uytterhoeven };
349*05b22caaSGeert Uytterhoeven 
350*05b22caaSGeert Uytterhoeven static const struct renesas_id id_prr __initconst = {
351*05b22caaSGeert Uytterhoeven 	.offset = 0,
352*05b22caaSGeert Uytterhoeven 	.mask = 0xff00,
353*05b22caaSGeert Uytterhoeven };
354*05b22caaSGeert Uytterhoeven 
355*05b22caaSGeert Uytterhoeven static const struct of_device_id renesas_ids[] __initconst = {
356*05b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,bsid",			.data = &id_bsid },
357*05b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,r9a07g044-sysc",	.data = &id_rzg2l },
358*05b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,prr",			.data = &id_prr },
359*05b22caaSGeert Uytterhoeven 	{ /* sentinel */ }
360*05b22caaSGeert Uytterhoeven };
361*05b22caaSGeert Uytterhoeven 
3628d6799a9SGeert Uytterhoeven static int __init renesas_soc_init(void)
3638d6799a9SGeert Uytterhoeven {
3648d6799a9SGeert Uytterhoeven 	struct soc_device_attribute *soc_dev_attr;
365*05b22caaSGeert Uytterhoeven 	unsigned int product, eshi = 0, eslo;
3668d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
3678d6799a9SGeert Uytterhoeven 	const struct of_device_id *match;
3688d6799a9SGeert Uytterhoeven 	const struct renesas_soc *soc;
369*05b22caaSGeert Uytterhoeven 	const struct renesas_id *id;
3708d6799a9SGeert Uytterhoeven 	void __iomem *chipid = NULL;
3718d6799a9SGeert Uytterhoeven 	struct soc_device *soc_dev;
3728d6799a9SGeert Uytterhoeven 	struct device_node *np;
373*05b22caaSGeert Uytterhoeven 	const char *soc_id;
3748d6799a9SGeert Uytterhoeven 
3758d6799a9SGeert Uytterhoeven 	match = of_match_node(renesas_socs, of_root);
3768d6799a9SGeert Uytterhoeven 	if (!match)
3778d6799a9SGeert Uytterhoeven 		return -ENODEV;
3788d6799a9SGeert Uytterhoeven 
379*05b22caaSGeert Uytterhoeven 	soc_id = strchr(match->compatible, ',') + 1;
3808d6799a9SGeert Uytterhoeven 	soc = match->data;
3818d6799a9SGeert Uytterhoeven 	family = soc->family;
3828d6799a9SGeert Uytterhoeven 
383*05b22caaSGeert Uytterhoeven 	np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
384175f435fSChris Brandt 	if (np) {
385*05b22caaSGeert Uytterhoeven 		id = match->data;
3868d6799a9SGeert Uytterhoeven 		chipid = of_iomap(np, 0);
3878d6799a9SGeert Uytterhoeven 		of_node_put(np);
3884194b583SGeert Uytterhoeven 	} else if (soc->id && family->reg) {
389*05b22caaSGeert Uytterhoeven 		/* Try hardcoded CCCR/PRR fallback */
390*05b22caaSGeert Uytterhoeven 		id = &id_prr;
3918d6799a9SGeert Uytterhoeven 		chipid = ioremap(family->reg, 4);
3928d6799a9SGeert Uytterhoeven 	}
393*05b22caaSGeert Uytterhoeven 
3948d6799a9SGeert Uytterhoeven 	if (chipid) {
395*05b22caaSGeert Uytterhoeven 		product = readl(chipid + id->offset);
3968d6799a9SGeert Uytterhoeven 		iounmap(chipid);
397*05b22caaSGeert Uytterhoeven 
398*05b22caaSGeert Uytterhoeven 		if (id == &id_prr) {
39990f0d2b3SGeert Uytterhoeven 			/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
40090f0d2b3SGeert Uytterhoeven 			if ((product & 0x7fff) == 0x5210)
40190f0d2b3SGeert Uytterhoeven 				product ^= 0x11;
40215160f6dSTakeshi Kihara 			/* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
40315160f6dSTakeshi Kihara 			if ((product & 0x7fff) == 0x5211)
40415160f6dSTakeshi Kihara 				product ^= 0x12;
405*05b22caaSGeert Uytterhoeven 
406175f435fSChris Brandt 			eshi = ((product >> 4) & 0x0f) + 1;
407175f435fSChris Brandt 			eslo = product & 0xf;
4088d6799a9SGeert Uytterhoeven 		}
4098d6799a9SGeert Uytterhoeven 
410*05b22caaSGeert Uytterhoeven 		if (soc->id &&
411*05b22caaSGeert Uytterhoeven 		    ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
412*05b22caaSGeert Uytterhoeven 			pr_warn("SoC mismatch (product = 0x%x)\n", product);
413*05b22caaSGeert Uytterhoeven 			return -ENODEV;
414*05b22caaSGeert Uytterhoeven 		}
415*05b22caaSGeert Uytterhoeven 	}
416*05b22caaSGeert Uytterhoeven 
4178d6799a9SGeert Uytterhoeven 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
4188d6799a9SGeert Uytterhoeven 	if (!soc_dev_attr)
4198d6799a9SGeert Uytterhoeven 		return -ENOMEM;
4208d6799a9SGeert Uytterhoeven 
4218d6799a9SGeert Uytterhoeven 	np = of_find_node_by_path("/");
4228d6799a9SGeert Uytterhoeven 	of_property_read_string(np, "model", &soc_dev_attr->machine);
4238d6799a9SGeert Uytterhoeven 	of_node_put(np);
4248d6799a9SGeert Uytterhoeven 
4258d6799a9SGeert Uytterhoeven 	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
426*05b22caaSGeert Uytterhoeven 	soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);
427175f435fSChris Brandt 	if (eshi)
428175f435fSChris Brandt 		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
429175f435fSChris Brandt 						   eslo);
4308d6799a9SGeert Uytterhoeven 
4318d6799a9SGeert Uytterhoeven 	pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
4328d6799a9SGeert Uytterhoeven 		soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
4338d6799a9SGeert Uytterhoeven 
4348d6799a9SGeert Uytterhoeven 	soc_dev = soc_device_register(soc_dev_attr);
4358d6799a9SGeert Uytterhoeven 	if (IS_ERR(soc_dev)) {
4368d6799a9SGeert Uytterhoeven 		kfree(soc_dev_attr->revision);
4378d6799a9SGeert Uytterhoeven 		kfree_const(soc_dev_attr->soc_id);
4388d6799a9SGeert Uytterhoeven 		kfree_const(soc_dev_attr->family);
4398d6799a9SGeert Uytterhoeven 		kfree(soc_dev_attr);
4408d6799a9SGeert Uytterhoeven 		return PTR_ERR(soc_dev);
4418d6799a9SGeert Uytterhoeven 	}
4428d6799a9SGeert Uytterhoeven 
4438d6799a9SGeert Uytterhoeven 	return 0;
4448d6799a9SGeert Uytterhoeven }
445b1d134baSGeert Uytterhoeven early_initcall(renesas_soc_init);
446