xref: /linux/drivers/soc/renesas/renesas-soc.c (revision 1b37236de8c1ac56969efd130bb38edf8ac4b7f6)
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 
532a4056a7SBiju Das static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
542a4056a7SBiju Das 	.name	= "RZ/G1",
558d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
568d6799a9SGeert Uytterhoeven };
578d6799a9SGeert Uytterhoeven 
582a4056a7SBiju Das static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
592a4056a7SBiju Das 	.name	= "RZ/G2",
602a4056a7SBiju Das 	.reg	= 0xfff00044,		/* PRR (Product Register) */
612a4056a7SBiju Das };
622a4056a7SBiju Das 
63187cd57dSLad Prabhakar static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
64187cd57dSLad Prabhakar 	.name	= "RZ/G2L",
65187cd57dSLad Prabhakar };
66187cd57dSLad Prabhakar 
672f89bef9SBiju Das static const struct renesas_family fam_rzg2ul __initconst __maybe_unused = {
682f89bef9SBiju Das 	.name	= "RZ/G2UL",
692f89bef9SBiju Das };
702f89bef9SBiju Das 
71860122d8SBiju Das static const struct renesas_family fam_rzv2l __initconst __maybe_unused = {
72860122d8SBiju Das 	.name	= "RZ/V2L",
73860122d8SBiju Das };
74860122d8SBiju Das 
758d6799a9SGeert Uytterhoeven static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
768d6799a9SGeert Uytterhoeven 	.name	= "SH-Mobile",
778d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
788d6799a9SGeert Uytterhoeven };
798d6799a9SGeert Uytterhoeven 
808d6799a9SGeert Uytterhoeven 
818d6799a9SGeert Uytterhoeven struct renesas_soc {
828d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
83187cd57dSLad Prabhakar 	u32 id;
848d6799a9SGeert Uytterhoeven };
858d6799a9SGeert Uytterhoeven 
868d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
87175f435fSChris Brandt 	.family	= &fam_rza1,
88175f435fSChris Brandt };
89175f435fSChris Brandt 
90175f435fSChris Brandt static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
91175f435fSChris Brandt 	.family	= &fam_rza2,
92175f435fSChris Brandt 	.id	= 0x3b,
938d6799a9SGeert Uytterhoeven };
948d6799a9SGeert Uytterhoeven 
958d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
968d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
978d6799a9SGeert Uytterhoeven 	.id	= 0x3f,
988d6799a9SGeert Uytterhoeven };
998d6799a9SGeert Uytterhoeven 
1008d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
1018d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
1028d6799a9SGeert Uytterhoeven 	.id	= 0x40,
1038d6799a9SGeert Uytterhoeven };
1048d6799a9SGeert Uytterhoeven 
1058848e1b1SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
1062a4056a7SBiju Das 	.family	= &fam_rzg1,
1078848e1b1SGeert Uytterhoeven 	.id	= 0x45,
1088848e1b1SGeert Uytterhoeven };
1098848e1b1SGeert Uytterhoeven 
1108d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
1112a4056a7SBiju Das 	.family	= &fam_rzg1,
1128d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1138d6799a9SGeert Uytterhoeven };
1148d6799a9SGeert Uytterhoeven 
115cd59de80SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
1162a4056a7SBiju Das 	.family	= &fam_rzg1,
117cd59de80SGeert Uytterhoeven 	.id	= 0x4b,
118cd59de80SGeert Uytterhoeven };
119cd59de80SGeert Uytterhoeven 
1208d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
1212a4056a7SBiju Das 	.family	= &fam_rzg1,
1228d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1238d6799a9SGeert Uytterhoeven };
1248d6799a9SGeert Uytterhoeven 
1251daf13baSBiju Das static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
1262a4056a7SBiju Das 	.family	= &fam_rzg1,
1271daf13baSBiju Das 	.id	= 0x53,
1281daf13baSBiju Das };
1291daf13baSBiju Das 
1302a4056a7SBiju Das static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
1312a4056a7SBiju Das 	.family	= &fam_rzg2,
1322a4056a7SBiju Das 	.id	= 0x52,
1332a4056a7SBiju Das };
1342a4056a7SBiju Das 
135574cb721SBiju Das static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
136574cb721SBiju Das 	.family = &fam_rzg2,
137574cb721SBiju Das 	.id     = 0x55,
138574cb721SBiju Das };
139574cb721SBiju Das 
1402bab3d80SFabrizio Castro static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
1412bab3d80SFabrizio Castro 	.family	= &fam_rzg2,
1422bab3d80SFabrizio Castro 	.id	= 0x57,
1432bab3d80SFabrizio Castro };
1442bab3d80SFabrizio Castro 
1455b83cc42SMarian-Cristian Rotariu static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
1465b83cc42SMarian-Cristian Rotariu 	.family	= &fam_rzg2,
1475b83cc42SMarian-Cristian Rotariu 	.id	= 0x4f,
1485b83cc42SMarian-Cristian Rotariu };
1495b83cc42SMarian-Cristian Rotariu 
150187cd57dSLad Prabhakar static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
151187cd57dSLad Prabhakar 	.family = &fam_rzg2l,
152187cd57dSLad Prabhakar 	.id     = 0x841c447,
153187cd57dSLad Prabhakar };
154187cd57dSLad Prabhakar 
1552f89bef9SBiju Das static const struct renesas_soc soc_rz_g2ul __initconst __maybe_unused = {
1562f89bef9SBiju Das 	.family = &fam_rzg2ul,
1572f89bef9SBiju Das 	.id     = 0x8450447,
1582f89bef9SBiju Das };
1592f89bef9SBiju Das 
160860122d8SBiju Das static const struct renesas_soc soc_rz_v2l __initconst __maybe_unused = {
161860122d8SBiju Das 	.family = &fam_rzv2l,
162860122d8SBiju Das 	.id     = 0x8447447,
163860122d8SBiju Das };
164860122d8SBiju Das 
1658d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
1668d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1678d6799a9SGeert Uytterhoeven };
1688d6799a9SGeert Uytterhoeven 
1698d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
1708d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1718d6799a9SGeert Uytterhoeven 	.id	= 0x3b,
1728d6799a9SGeert Uytterhoeven };
1738d6799a9SGeert Uytterhoeven 
1748d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
1758d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1768d6799a9SGeert Uytterhoeven 	.id	= 0x45,
1778d6799a9SGeert Uytterhoeven };
1788d6799a9SGeert Uytterhoeven 
1798d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
1808d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1818d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1828d6799a9SGeert Uytterhoeven };
1838d6799a9SGeert Uytterhoeven 
1848d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
1858d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1868d6799a9SGeert Uytterhoeven 	.id	= 0x4a,
1878d6799a9SGeert Uytterhoeven };
1888d6799a9SGeert Uytterhoeven 
1898d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
1908d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1918d6799a9SGeert Uytterhoeven 	.id	= 0x4b,
1928d6799a9SGeert Uytterhoeven };
1938d6799a9SGeert Uytterhoeven 
1948d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
1958d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1968d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1978d6799a9SGeert Uytterhoeven };
1988d6799a9SGeert Uytterhoeven 
1998d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
2008d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2018d6799a9SGeert Uytterhoeven 	.id	= 0x4f,
2028d6799a9SGeert Uytterhoeven };
2038d6799a9SGeert Uytterhoeven 
2048d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
2058d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2068d6799a9SGeert Uytterhoeven 	.id	= 0x52,
2078d6799a9SGeert Uytterhoeven };
2088d6799a9SGeert Uytterhoeven 
209bfd83983SJacopo Mondi static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
210bfd83983SJacopo Mondi 	.family = &fam_rcar_gen3,
211bfd83983SJacopo Mondi 	.id     = 0x55,
212bfd83983SJacopo Mondi };
213bfd83983SJacopo Mondi 
214bb003075SSergei Shtylyov static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
215bb003075SSergei Shtylyov 	.family	= &fam_rcar_gen3,
216bb003075SSergei Shtylyov 	.id	= 0x54,
217bb003075SSergei Shtylyov };
218bb003075SSergei Shtylyov 
2198447756dSSergei Shtylyov static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
2208447756dSSergei Shtylyov 	.family	= &fam_rcar_gen3,
2218447756dSSergei Shtylyov 	.id	= 0x56,
2228447756dSSergei Shtylyov };
2238447756dSSergei Shtylyov 
22444842d45STakeshi Kihara static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
22544842d45STakeshi Kihara 	.family	= &fam_rcar_gen3,
22644842d45STakeshi Kihara 	.id	= 0x57,
22744842d45STakeshi Kihara };
22844842d45STakeshi Kihara 
2291b954784SGeert Uytterhoeven static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
2301b954784SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
2311b954784SGeert Uytterhoeven 	.id	= 0x58,
2321b954784SGeert Uytterhoeven };
2331b954784SGeert Uytterhoeven 
234090e87e7SYoshihiro Shimoda static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
23527e7657aSGeert Uytterhoeven 	.family	= &fam_rcar_gen4,
236090e87e7SYoshihiro Shimoda 	.id	= 0x59,
237090e87e7SYoshihiro Shimoda };
238090e87e7SYoshihiro Shimoda 
23997116335SYoshihiro Shimoda static const struct renesas_soc soc_rcar_s4 __initconst __maybe_unused = {
24097116335SYoshihiro Shimoda 	.family	= &fam_rcar_gen4,
24197116335SYoshihiro Shimoda 	.id	= 0x5a,
24297116335SYoshihiro Shimoda };
24397116335SYoshihiro Shimoda 
24487ab58e1SYoshihiro Shimoda static const struct renesas_soc soc_rcar_v4h __initconst __maybe_unused = {
24587ab58e1SYoshihiro Shimoda 	.family	= &fam_rcar_gen4,
24687ab58e1SYoshihiro Shimoda 	.id	= 0x5c,
24787ab58e1SYoshihiro Shimoda };
24887ab58e1SYoshihiro Shimoda 
2498d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
2508d6799a9SGeert Uytterhoeven 	.family	= &fam_shmobile,
2518d6799a9SGeert Uytterhoeven 	.id	= 0x37,
2528d6799a9SGeert Uytterhoeven };
2538d6799a9SGeert Uytterhoeven 
2548d6799a9SGeert Uytterhoeven 
2558d6799a9SGeert Uytterhoeven static const struct of_device_id renesas_socs[] __initconst = {
2568d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R7S72100
2578d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
2588d6799a9SGeert Uytterhoeven #endif
259175f435fSChris Brandt #ifdef CONFIG_ARCH_R7S9210
260175f435fSChris Brandt 	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
261175f435fSChris Brandt #endif
2628d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A73A4
2638d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
2648d6799a9SGeert Uytterhoeven #endif
2658d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7740
2668d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
2678d6799a9SGeert Uytterhoeven #endif
2688848e1b1SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7742
2698848e1b1SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
2708848e1b1SGeert Uytterhoeven #endif
2718d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7743
2728d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
2738d6799a9SGeert Uytterhoeven #endif
274cd59de80SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7744
275cd59de80SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
276cd59de80SGeert Uytterhoeven #endif
2778d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7745
2788d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
2798d6799a9SGeert Uytterhoeven #endif
2801daf13baSBiju Das #ifdef CONFIG_ARCH_R8A77470
2811daf13baSBiju Das 	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
2821daf13baSBiju Das #endif
2832a4056a7SBiju Das #ifdef CONFIG_ARCH_R8A774A1
2842a4056a7SBiju Das 	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
2852a4056a7SBiju Das #endif
286574cb721SBiju Das #ifdef CONFIG_ARCH_R8A774B1
287574cb721SBiju Das 	{ .compatible = "renesas,r8a774b1",	.data = &soc_rz_g2n },
288574cb721SBiju Das #endif
2892bab3d80SFabrizio Castro #ifdef CONFIG_ARCH_R8A774C0
2902bab3d80SFabrizio Castro 	{ .compatible = "renesas,r8a774c0",	.data = &soc_rz_g2e },
2912bab3d80SFabrizio Castro #endif
2925b83cc42SMarian-Cristian Rotariu #ifdef CONFIG_ARCH_R8A774E1
2935b83cc42SMarian-Cristian Rotariu 	{ .compatible = "renesas,r8a774e1",	.data = &soc_rz_g2h },
2945b83cc42SMarian-Cristian Rotariu #endif
2958d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7778
2968d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
2978d6799a9SGeert Uytterhoeven #endif
2988d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7779
2998d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
3008d6799a9SGeert Uytterhoeven #endif
3018d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7790
3028d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
3038d6799a9SGeert Uytterhoeven #endif
3048d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7791
3058d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
3068d6799a9SGeert Uytterhoeven #endif
3078d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7792
3088d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
3098d6799a9SGeert Uytterhoeven #endif
3108d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7793
3118d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
3128d6799a9SGeert Uytterhoeven #endif
3138d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7794
3148d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
3158d6799a9SGeert Uytterhoeven #endif
3164ff27112SGeert Uytterhoeven #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
3178d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
3188d6799a9SGeert Uytterhoeven #endif
319bfe6b559SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77951
3202ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m0",	.data = &soc_rcar_h3 },
321bfe6b559SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m1",	.data = &soc_rcar_h3 },
3222ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m8",	.data = &soc_rcar_h3 },
323*1b37236dSGeert Uytterhoeven 	{ .compatible = "renesas,r8a779mb",	.data = &soc_rcar_h3 },
324bfe6b559SGeert Uytterhoeven #endif
32539e57e14SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77960
3268d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
3278d6799a9SGeert Uytterhoeven #endif
3289c9f7891SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77961
3299c9f7891SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77961",	.data = &soc_rcar_m3_w },
3302ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m2",	.data = &soc_rcar_m3_w },
331bfe6b559SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m3",	.data = &soc_rcar_m3_w },
3329c9f7891SGeert Uytterhoeven #endif
333bfd83983SJacopo Mondi #ifdef CONFIG_ARCH_R8A77965
334bfd83983SJacopo Mondi 	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
3352ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m4",	.data = &soc_rcar_m3_n },
3362ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m5",	.data = &soc_rcar_m3_n },
337bfd83983SJacopo Mondi #endif
338bb003075SSergei Shtylyov #ifdef CONFIG_ARCH_R8A77970
339bb003075SSergei Shtylyov 	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
340bb003075SSergei Shtylyov #endif
3418447756dSSergei Shtylyov #ifdef CONFIG_ARCH_R8A77980
3428447756dSSergei Shtylyov 	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
3438447756dSSergei Shtylyov #endif
34444842d45STakeshi Kihara #ifdef CONFIG_ARCH_R8A77990
34544842d45STakeshi Kihara 	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
3462ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m6",	.data = &soc_rcar_e3 },
34744842d45STakeshi Kihara #endif
3481b954784SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77995
3491b954784SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
3502ed1e481SGeert Uytterhoeven 	{ .compatible = "renesas,r8a779m7",	.data = &soc_rcar_d3 },
3511b954784SGeert Uytterhoeven #endif
352090e87e7SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779A0
353090e87e7SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779a0",	.data = &soc_rcar_v3u },
354090e87e7SYoshihiro Shimoda #endif
35597116335SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779F0
35697116335SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779f0",	.data = &soc_rcar_s4 },
35797116335SYoshihiro Shimoda #endif
35887ab58e1SYoshihiro Shimoda #ifdef CONFIG_ARCH_R8A779G0
35987ab58e1SYoshihiro Shimoda 	{ .compatible = "renesas,r8a779g0",	.data = &soc_rcar_v4h },
36087ab58e1SYoshihiro Shimoda #endif
3612f89bef9SBiju Das #if defined(CONFIG_ARCH_R9A07G043)
3622f89bef9SBiju Das 	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_g2ul },
3632f89bef9SBiju Das #endif
364187cd57dSLad Prabhakar #if defined(CONFIG_ARCH_R9A07G044)
365187cd57dSLad Prabhakar 	{ .compatible = "renesas,r9a07g044",	.data = &soc_rz_g2l },
366187cd57dSLad Prabhakar #endif
367860122d8SBiju Das #if defined(CONFIG_ARCH_R9A07G054)
368860122d8SBiju Das 	{ .compatible = "renesas,r9a07g054",	.data = &soc_rz_v2l },
369860122d8SBiju Das #endif
3708d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_SH73A0
3718d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
3728d6799a9SGeert Uytterhoeven #endif
3738d6799a9SGeert Uytterhoeven 	{ /* sentinel */ }
3748d6799a9SGeert Uytterhoeven };
3758d6799a9SGeert Uytterhoeven 
37605b22caaSGeert Uytterhoeven struct renesas_id {
37705b22caaSGeert Uytterhoeven 	unsigned int offset;
37805b22caaSGeert Uytterhoeven 	u32 mask;
37905b22caaSGeert Uytterhoeven };
38005b22caaSGeert Uytterhoeven 
38105b22caaSGeert Uytterhoeven static const struct renesas_id id_bsid __initconst = {
38205b22caaSGeert Uytterhoeven 	.offset = 0,
38305b22caaSGeert Uytterhoeven 	.mask = 0xff0000,
38405b22caaSGeert Uytterhoeven 	/*
38505b22caaSGeert Uytterhoeven 	 * TODO: Upper 4 bits of BSID are for chip version, but the format is
38605b22caaSGeert Uytterhoeven 	 * not known at this time so we don't know how to specify eshi and eslo
38705b22caaSGeert Uytterhoeven 	 */
38805b22caaSGeert Uytterhoeven };
38905b22caaSGeert Uytterhoeven 
39005b22caaSGeert Uytterhoeven static const struct renesas_id id_rzg2l __initconst = {
39105b22caaSGeert Uytterhoeven 	.offset = 0xa04,
39205b22caaSGeert Uytterhoeven 	.mask = 0xfffffff,
39305b22caaSGeert Uytterhoeven };
39405b22caaSGeert Uytterhoeven 
39505b22caaSGeert Uytterhoeven static const struct renesas_id id_prr __initconst = {
39605b22caaSGeert Uytterhoeven 	.offset = 0,
39705b22caaSGeert Uytterhoeven 	.mask = 0xff00,
39805b22caaSGeert Uytterhoeven };
39905b22caaSGeert Uytterhoeven 
40005b22caaSGeert Uytterhoeven static const struct of_device_id renesas_ids[] __initconst = {
40105b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,bsid",			.data = &id_bsid },
4022f89bef9SBiju Das 	{ .compatible = "renesas,r9a07g043-sysc",	.data = &id_rzg2l },
40305b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,r9a07g044-sysc",	.data = &id_rzg2l },
404860122d8SBiju Das 	{ .compatible = "renesas,r9a07g054-sysc",	.data = &id_rzg2l },
40505b22caaSGeert Uytterhoeven 	{ .compatible = "renesas,prr",			.data = &id_prr },
40605b22caaSGeert Uytterhoeven 	{ /* sentinel */ }
40705b22caaSGeert Uytterhoeven };
40805b22caaSGeert Uytterhoeven 
4098d6799a9SGeert Uytterhoeven static int __init renesas_soc_init(void)
4108d6799a9SGeert Uytterhoeven {
4118d6799a9SGeert Uytterhoeven 	struct soc_device_attribute *soc_dev_attr;
41205b22caaSGeert Uytterhoeven 	unsigned int product, eshi = 0, eslo;
4138d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
4148d6799a9SGeert Uytterhoeven 	const struct of_device_id *match;
4158d6799a9SGeert Uytterhoeven 	const struct renesas_soc *soc;
41605b22caaSGeert Uytterhoeven 	const struct renesas_id *id;
4178d6799a9SGeert Uytterhoeven 	void __iomem *chipid = NULL;
418cb5508e4SBiju Das 	const char *rev_prefix = "";
4198d6799a9SGeert Uytterhoeven 	struct soc_device *soc_dev;
4208d6799a9SGeert Uytterhoeven 	struct device_node *np;
42105b22caaSGeert Uytterhoeven 	const char *soc_id;
422cb5508e4SBiju Das 	int ret;
4238d6799a9SGeert Uytterhoeven 
4248d6799a9SGeert Uytterhoeven 	match = of_match_node(renesas_socs, of_root);
4258d6799a9SGeert Uytterhoeven 	if (!match)
4268d6799a9SGeert Uytterhoeven 		return -ENODEV;
4278d6799a9SGeert Uytterhoeven 
42805b22caaSGeert Uytterhoeven 	soc_id = strchr(match->compatible, ',') + 1;
4298d6799a9SGeert Uytterhoeven 	soc = match->data;
4308d6799a9SGeert Uytterhoeven 	family = soc->family;
4318d6799a9SGeert Uytterhoeven 
43205b22caaSGeert Uytterhoeven 	np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
433175f435fSChris Brandt 	if (np) {
43405b22caaSGeert Uytterhoeven 		id = match->data;
4358d6799a9SGeert Uytterhoeven 		chipid = of_iomap(np, 0);
4368d6799a9SGeert Uytterhoeven 		of_node_put(np);
4374194b583SGeert Uytterhoeven 	} else if (soc->id && family->reg) {
43805b22caaSGeert Uytterhoeven 		/* Try hardcoded CCCR/PRR fallback */
43905b22caaSGeert Uytterhoeven 		id = &id_prr;
4408d6799a9SGeert Uytterhoeven 		chipid = ioremap(family->reg, 4);
4418d6799a9SGeert Uytterhoeven 	}
44205b22caaSGeert Uytterhoeven 
443cb5508e4SBiju Das 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
444cb5508e4SBiju Das 	if (!soc_dev_attr)
445cb5508e4SBiju Das 		return -ENOMEM;
446cb5508e4SBiju Das 
447cb5508e4SBiju Das 	np = of_find_node_by_path("/");
448cb5508e4SBiju Das 	of_property_read_string(np, "model", &soc_dev_attr->machine);
449cb5508e4SBiju Das 	of_node_put(np);
450cb5508e4SBiju Das 
451cb5508e4SBiju Das 	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
452cb5508e4SBiju Das 	soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);
453cb5508e4SBiju Das 
4548d6799a9SGeert Uytterhoeven 	if (chipid) {
45505b22caaSGeert Uytterhoeven 		product = readl(chipid + id->offset);
4568d6799a9SGeert Uytterhoeven 		iounmap(chipid);
45705b22caaSGeert Uytterhoeven 
45805b22caaSGeert Uytterhoeven 		if (id == &id_prr) {
45990f0d2b3SGeert Uytterhoeven 			/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
46090f0d2b3SGeert Uytterhoeven 			if ((product & 0x7fff) == 0x5210)
46190f0d2b3SGeert Uytterhoeven 				product ^= 0x11;
46215160f6dSTakeshi Kihara 			/* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
46315160f6dSTakeshi Kihara 			if ((product & 0x7fff) == 0x5211)
46415160f6dSTakeshi Kihara 				product ^= 0x12;
46505b22caaSGeert Uytterhoeven 
466175f435fSChris Brandt 			eshi = ((product >> 4) & 0x0f) + 1;
467175f435fSChris Brandt 			eslo = product & 0xf;
468cb5508e4SBiju Das 			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
469cb5508e4SBiju Das 							   eshi, eslo);
470cb5508e4SBiju Das 		}  else if (id == &id_rzg2l) {
471cb5508e4SBiju Das 			eshi =  ((product >> 28) & 0x0f);
472cb5508e4SBiju Das 			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u",
473cb5508e4SBiju Das 							   eshi);
474cb5508e4SBiju Das 			rev_prefix = "Rev ";
4758d6799a9SGeert Uytterhoeven 		}
4768d6799a9SGeert Uytterhoeven 
47705b22caaSGeert Uytterhoeven 		if (soc->id &&
47805b22caaSGeert Uytterhoeven 		    ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
47905b22caaSGeert Uytterhoeven 			pr_warn("SoC mismatch (product = 0x%x)\n", product);
480cb5508e4SBiju Das 			ret = -ENODEV;
481cb5508e4SBiju Das 			goto free_soc_dev_attr;
48205b22caaSGeert Uytterhoeven 		}
48305b22caaSGeert Uytterhoeven 	}
48405b22caaSGeert Uytterhoeven 
485cb5508e4SBiju Das 	pr_info("Detected Renesas %s %s %s%s\n", soc_dev_attr->family,
486cb5508e4SBiju Das 		soc_dev_attr->soc_id, rev_prefix, soc_dev_attr->revision ?: "");
4878d6799a9SGeert Uytterhoeven 
4888d6799a9SGeert Uytterhoeven 	soc_dev = soc_device_register(soc_dev_attr);
4898d6799a9SGeert Uytterhoeven 	if (IS_ERR(soc_dev)) {
490cb5508e4SBiju Das 		ret = PTR_ERR(soc_dev);
491cb5508e4SBiju Das 		goto free_soc_dev_attr;
492cb5508e4SBiju Das 	}
493cb5508e4SBiju Das 
494cb5508e4SBiju Das 	return 0;
495cb5508e4SBiju Das 
496cb5508e4SBiju Das free_soc_dev_attr:
4978d6799a9SGeert Uytterhoeven 	kfree(soc_dev_attr->revision);
4988d6799a9SGeert Uytterhoeven 	kfree_const(soc_dev_attr->soc_id);
4998d6799a9SGeert Uytterhoeven 	kfree_const(soc_dev_attr->family);
5008d6799a9SGeert Uytterhoeven 	kfree(soc_dev_attr);
501cb5508e4SBiju Das 	return ret;
5028d6799a9SGeert Uytterhoeven }
503b1d134baSGeert Uytterhoeven early_initcall(renesas_soc_init);
504