xref: /linux/drivers/soc/renesas/renesas-soc.c (revision 175f435f44b724e389f23c154d94fda45870c1f6)
18d6799a9SGeert Uytterhoeven /*
28d6799a9SGeert Uytterhoeven  * Renesas SoC Identification
38d6799a9SGeert Uytterhoeven  *
48d6799a9SGeert Uytterhoeven  * Copyright (C) 2014-2016 Glider bvba
58d6799a9SGeert Uytterhoeven  *
68d6799a9SGeert Uytterhoeven  * This program is free software; you can redistribute it and/or modify
78d6799a9SGeert Uytterhoeven  * it under the terms of the GNU General Public License as published by
88d6799a9SGeert Uytterhoeven  * the Free Software Foundation; version 2 of the License.
98d6799a9SGeert Uytterhoeven  *
108d6799a9SGeert Uytterhoeven  * This program is distributed in the hope that it will be useful,
118d6799a9SGeert Uytterhoeven  * but WITHOUT ANY WARRANTY; without even the implied warranty of
128d6799a9SGeert Uytterhoeven  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
138d6799a9SGeert Uytterhoeven  * GNU General Public License for more details.
148d6799a9SGeert Uytterhoeven  */
158d6799a9SGeert Uytterhoeven 
168d6799a9SGeert Uytterhoeven #include <linux/io.h>
178d6799a9SGeert Uytterhoeven #include <linux/of.h>
188d6799a9SGeert Uytterhoeven #include <linux/of_address.h>
198d6799a9SGeert Uytterhoeven #include <linux/slab.h>
208d6799a9SGeert Uytterhoeven #include <linux/string.h>
218d6799a9SGeert Uytterhoeven #include <linux/sys_soc.h>
228d6799a9SGeert Uytterhoeven 
238d6799a9SGeert Uytterhoeven 
248d6799a9SGeert Uytterhoeven struct renesas_family {
258d6799a9SGeert Uytterhoeven 	const char name[16];
268d6799a9SGeert Uytterhoeven 	u32 reg;			/* CCCR or PRR, if not in DT */
278d6799a9SGeert Uytterhoeven };
288d6799a9SGeert Uytterhoeven 
298d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
308d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen1",
318d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
328d6799a9SGeert Uytterhoeven };
338d6799a9SGeert Uytterhoeven 
348d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
358d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen2",
368d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
378d6799a9SGeert Uytterhoeven };
388d6799a9SGeert Uytterhoeven 
398d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
408d6799a9SGeert Uytterhoeven 	.name	= "R-Car Gen3",
418d6799a9SGeert Uytterhoeven 	.reg	= 0xfff00044,		/* PRR (Product Register) */
428d6799a9SGeert Uytterhoeven };
438d6799a9SGeert Uytterhoeven 
448d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
458d6799a9SGeert Uytterhoeven 	.name	= "R-Mobile",
468d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
478d6799a9SGeert Uytterhoeven };
488d6799a9SGeert Uytterhoeven 
49*175f435fSChris Brandt static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
50*175f435fSChris Brandt 	.name	= "RZ/A1",
51*175f435fSChris Brandt };
52*175f435fSChris Brandt 
53*175f435fSChris Brandt static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
54*175f435fSChris Brandt 	.name	= "RZ/A2",
558d6799a9SGeert Uytterhoeven };
568d6799a9SGeert Uytterhoeven 
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 
678d6799a9SGeert Uytterhoeven static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
688d6799a9SGeert Uytterhoeven 	.name	= "SH-Mobile",
698d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
708d6799a9SGeert Uytterhoeven };
718d6799a9SGeert Uytterhoeven 
728d6799a9SGeert Uytterhoeven 
738d6799a9SGeert Uytterhoeven struct renesas_soc {
748d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
758d6799a9SGeert Uytterhoeven 	u8 id;
768d6799a9SGeert Uytterhoeven };
778d6799a9SGeert Uytterhoeven 
788d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
79*175f435fSChris Brandt 	.family	= &fam_rza1,
80*175f435fSChris Brandt };
81*175f435fSChris Brandt 
82*175f435fSChris Brandt static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
83*175f435fSChris Brandt 	.family	= &fam_rza2,
84*175f435fSChris Brandt 	.id	= 0x3b,
858d6799a9SGeert Uytterhoeven };
868d6799a9SGeert Uytterhoeven 
878d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
888d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
898d6799a9SGeert Uytterhoeven 	.id	= 0x3f,
908d6799a9SGeert Uytterhoeven };
918d6799a9SGeert Uytterhoeven 
928d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
938d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
948d6799a9SGeert Uytterhoeven 	.id	= 0x40,
958d6799a9SGeert Uytterhoeven };
968d6799a9SGeert Uytterhoeven 
978848e1b1SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
982a4056a7SBiju Das 	.family	= &fam_rzg1,
998848e1b1SGeert Uytterhoeven 	.id	= 0x45,
1008848e1b1SGeert Uytterhoeven };
1018848e1b1SGeert Uytterhoeven 
1028d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
1032a4056a7SBiju Das 	.family	= &fam_rzg1,
1048d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1058d6799a9SGeert Uytterhoeven };
1068d6799a9SGeert Uytterhoeven 
107cd59de80SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
1082a4056a7SBiju Das 	.family	= &fam_rzg1,
109cd59de80SGeert Uytterhoeven 	.id	= 0x4b,
110cd59de80SGeert Uytterhoeven };
111cd59de80SGeert Uytterhoeven 
1128d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
1132a4056a7SBiju Das 	.family	= &fam_rzg1,
1148d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1158d6799a9SGeert Uytterhoeven };
1168d6799a9SGeert Uytterhoeven 
1171daf13baSBiju Das static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
1182a4056a7SBiju Das 	.family	= &fam_rzg1,
1191daf13baSBiju Das 	.id	= 0x53,
1201daf13baSBiju Das };
1211daf13baSBiju Das 
1222a4056a7SBiju Das static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
1232a4056a7SBiju Das 	.family	= &fam_rzg2,
1242a4056a7SBiju Das 	.id	= 0x52,
1252a4056a7SBiju Das };
1262a4056a7SBiju Das 
1278d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
1288d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1298d6799a9SGeert Uytterhoeven };
1308d6799a9SGeert Uytterhoeven 
1318d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
1328d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1338d6799a9SGeert Uytterhoeven 	.id	= 0x3b,
1348d6799a9SGeert Uytterhoeven };
1358d6799a9SGeert Uytterhoeven 
1368d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
1378d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1388d6799a9SGeert Uytterhoeven 	.id	= 0x45,
1398d6799a9SGeert Uytterhoeven };
1408d6799a9SGeert Uytterhoeven 
1418d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
1428d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1438d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1448d6799a9SGeert Uytterhoeven };
1458d6799a9SGeert Uytterhoeven 
1468d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
1478d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1488d6799a9SGeert Uytterhoeven 	.id	= 0x4a,
1498d6799a9SGeert Uytterhoeven };
1508d6799a9SGeert Uytterhoeven 
1518d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
1528d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1538d6799a9SGeert Uytterhoeven 	.id	= 0x4b,
1548d6799a9SGeert Uytterhoeven };
1558d6799a9SGeert Uytterhoeven 
1568d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
1578d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1588d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1598d6799a9SGeert Uytterhoeven };
1608d6799a9SGeert Uytterhoeven 
1618d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
1628d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1638d6799a9SGeert Uytterhoeven 	.id	= 0x4f,
1648d6799a9SGeert Uytterhoeven };
1658d6799a9SGeert Uytterhoeven 
1668d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
1678d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1688d6799a9SGeert Uytterhoeven 	.id	= 0x52,
1698d6799a9SGeert Uytterhoeven };
1708d6799a9SGeert Uytterhoeven 
171bfd83983SJacopo Mondi static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
172bfd83983SJacopo Mondi 	.family = &fam_rcar_gen3,
173bfd83983SJacopo Mondi 	.id     = 0x55,
174bfd83983SJacopo Mondi };
175bfd83983SJacopo Mondi 
176bb003075SSergei Shtylyov static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
177bb003075SSergei Shtylyov 	.family	= &fam_rcar_gen3,
178bb003075SSergei Shtylyov 	.id	= 0x54,
179bb003075SSergei Shtylyov };
180bb003075SSergei Shtylyov 
1818447756dSSergei Shtylyov static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
1828447756dSSergei Shtylyov 	.family	= &fam_rcar_gen3,
1838447756dSSergei Shtylyov 	.id	= 0x56,
1848447756dSSergei Shtylyov };
1858447756dSSergei Shtylyov 
18644842d45STakeshi Kihara static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
18744842d45STakeshi Kihara 	.family	= &fam_rcar_gen3,
18844842d45STakeshi Kihara 	.id	= 0x57,
18944842d45STakeshi Kihara };
19044842d45STakeshi Kihara 
1911b954784SGeert Uytterhoeven static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
1921b954784SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1931b954784SGeert Uytterhoeven 	.id	= 0x58,
1941b954784SGeert Uytterhoeven };
1951b954784SGeert Uytterhoeven 
1968d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
1978d6799a9SGeert Uytterhoeven 	.family	= &fam_shmobile,
1988d6799a9SGeert Uytterhoeven 	.id	= 0x37,
1998d6799a9SGeert Uytterhoeven };
2008d6799a9SGeert Uytterhoeven 
2018d6799a9SGeert Uytterhoeven 
2028d6799a9SGeert Uytterhoeven static const struct of_device_id renesas_socs[] __initconst = {
2038d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R7S72100
2048d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
2058d6799a9SGeert Uytterhoeven #endif
206*175f435fSChris Brandt #ifdef CONFIG_ARCH_R7S9210
207*175f435fSChris Brandt 	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
208*175f435fSChris Brandt #endif
2098d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A73A4
2108d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
2118d6799a9SGeert Uytterhoeven #endif
2128d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7740
2138d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
2148d6799a9SGeert Uytterhoeven #endif
2158848e1b1SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7742
2168848e1b1SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
2178848e1b1SGeert Uytterhoeven #endif
2188d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7743
2198d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
2208d6799a9SGeert Uytterhoeven #endif
221cd59de80SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7744
222cd59de80SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
223cd59de80SGeert Uytterhoeven #endif
2248d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7745
2258d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
2268d6799a9SGeert Uytterhoeven #endif
2271daf13baSBiju Das #ifdef CONFIG_ARCH_R8A77470
2281daf13baSBiju Das 	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
2291daf13baSBiju Das #endif
2302a4056a7SBiju Das #ifdef CONFIG_ARCH_R8A774A1
2312a4056a7SBiju Das 	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
2322a4056a7SBiju Das #endif
2338d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7778
2348d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
2358d6799a9SGeert Uytterhoeven #endif
2368d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7779
2378d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
2388d6799a9SGeert Uytterhoeven #endif
2398d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7790
2408d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
2418d6799a9SGeert Uytterhoeven #endif
2428d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7791
2438d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
2448d6799a9SGeert Uytterhoeven #endif
2458d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7792
2468d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
2478d6799a9SGeert Uytterhoeven #endif
2488d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7793
2498d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
2508d6799a9SGeert Uytterhoeven #endif
2518d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7794
2528d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
2538d6799a9SGeert Uytterhoeven #endif
2548d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7795
2558d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
2568d6799a9SGeert Uytterhoeven #endif
2578d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7796
2588d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
2598d6799a9SGeert Uytterhoeven #endif
260bfd83983SJacopo Mondi #ifdef CONFIG_ARCH_R8A77965
261bfd83983SJacopo Mondi 	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
262bfd83983SJacopo Mondi #endif
263bb003075SSergei Shtylyov #ifdef CONFIG_ARCH_R8A77970
264bb003075SSergei Shtylyov 	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
265bb003075SSergei Shtylyov #endif
2668447756dSSergei Shtylyov #ifdef CONFIG_ARCH_R8A77980
2678447756dSSergei Shtylyov 	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
2688447756dSSergei Shtylyov #endif
26944842d45STakeshi Kihara #ifdef CONFIG_ARCH_R8A77990
27044842d45STakeshi Kihara 	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
27144842d45STakeshi Kihara #endif
2721b954784SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A77995
2731b954784SGeert Uytterhoeven 	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
2741b954784SGeert Uytterhoeven #endif
2758d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_SH73A0
2768d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
2778d6799a9SGeert Uytterhoeven #endif
2788d6799a9SGeert Uytterhoeven 	{ /* sentinel */ }
2798d6799a9SGeert Uytterhoeven };
2808d6799a9SGeert Uytterhoeven 
2818d6799a9SGeert Uytterhoeven static int __init renesas_soc_init(void)
2828d6799a9SGeert Uytterhoeven {
2838d6799a9SGeert Uytterhoeven 	struct soc_device_attribute *soc_dev_attr;
2848d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
2858d6799a9SGeert Uytterhoeven 	const struct of_device_id *match;
2868d6799a9SGeert Uytterhoeven 	const struct renesas_soc *soc;
2878d6799a9SGeert Uytterhoeven 	void __iomem *chipid = NULL;
2888d6799a9SGeert Uytterhoeven 	struct soc_device *soc_dev;
2898d6799a9SGeert Uytterhoeven 	struct device_node *np;
290*175f435fSChris Brandt 	unsigned int product, eshi = 0, eslo;
2918d6799a9SGeert Uytterhoeven 
2928d6799a9SGeert Uytterhoeven 	match = of_match_node(renesas_socs, of_root);
2938d6799a9SGeert Uytterhoeven 	if (!match)
2948d6799a9SGeert Uytterhoeven 		return -ENODEV;
2958d6799a9SGeert Uytterhoeven 
2968d6799a9SGeert Uytterhoeven 	soc = match->data;
2978d6799a9SGeert Uytterhoeven 	family = soc->family;
2988d6799a9SGeert Uytterhoeven 
299*175f435fSChris Brandt 	np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
300*175f435fSChris Brandt 	if (np) {
301*175f435fSChris Brandt 		chipid = of_iomap(np, 0);
302*175f435fSChris Brandt 		of_node_put(np);
303*175f435fSChris Brandt 
304*175f435fSChris Brandt 		if (chipid) {
305*175f435fSChris Brandt 			product = readl(chipid);
306*175f435fSChris Brandt 			iounmap(chipid);
307*175f435fSChris Brandt 
308*175f435fSChris Brandt 			if (soc->id && ((product >> 16) & 0xff) != soc->id) {
309*175f435fSChris Brandt 				pr_warn("SoC mismatch (product = 0x%x)\n",
310*175f435fSChris Brandt 					product);
311*175f435fSChris Brandt 				return -ENODEV;
312*175f435fSChris Brandt 			}
313*175f435fSChris Brandt 		}
314*175f435fSChris Brandt 
315*175f435fSChris Brandt 		/*
316*175f435fSChris Brandt 		 * TODO: Upper 4 bits of BSID are for chip version, but the
317*175f435fSChris Brandt 		 * format is not known at this time so we don't know how to
318*175f435fSChris Brandt 		 * specify eshi and eslo
319*175f435fSChris Brandt 		 */
320*175f435fSChris Brandt 
321*175f435fSChris Brandt 		goto done;
322*175f435fSChris Brandt 	}
323*175f435fSChris Brandt 
3248d6799a9SGeert Uytterhoeven 	/* Try PRR first, then hardcoded fallback */
3258d6799a9SGeert Uytterhoeven 	np = of_find_compatible_node(NULL, NULL, "renesas,prr");
3268d6799a9SGeert Uytterhoeven 	if (np) {
3278d6799a9SGeert Uytterhoeven 		chipid = of_iomap(np, 0);
3288d6799a9SGeert Uytterhoeven 		of_node_put(np);
3298d6799a9SGeert Uytterhoeven 	} else if (soc->id) {
3308d6799a9SGeert Uytterhoeven 		chipid = ioremap(family->reg, 4);
3318d6799a9SGeert Uytterhoeven 	}
3328d6799a9SGeert Uytterhoeven 	if (chipid) {
3338d6799a9SGeert Uytterhoeven 		product = readl(chipid);
3348d6799a9SGeert Uytterhoeven 		iounmap(chipid);
33590f0d2b3SGeert Uytterhoeven 		/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
33690f0d2b3SGeert Uytterhoeven 		if ((product & 0x7fff) == 0x5210)
33790f0d2b3SGeert Uytterhoeven 			product ^= 0x11;
3388d6799a9SGeert Uytterhoeven 		if (soc->id && ((product >> 8) & 0xff) != soc->id) {
3398d6799a9SGeert Uytterhoeven 			pr_warn("SoC mismatch (product = 0x%x)\n", product);
3408d6799a9SGeert Uytterhoeven 			return -ENODEV;
3418d6799a9SGeert Uytterhoeven 		}
342*175f435fSChris Brandt 		eshi = ((product >> 4) & 0x0f) + 1;
343*175f435fSChris Brandt 		eslo = product & 0xf;
3448d6799a9SGeert Uytterhoeven 	}
3458d6799a9SGeert Uytterhoeven 
346*175f435fSChris Brandt done:
3478d6799a9SGeert Uytterhoeven 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
3488d6799a9SGeert Uytterhoeven 	if (!soc_dev_attr)
3498d6799a9SGeert Uytterhoeven 		return -ENOMEM;
3508d6799a9SGeert Uytterhoeven 
3518d6799a9SGeert Uytterhoeven 	np = of_find_node_by_path("/");
3528d6799a9SGeert Uytterhoeven 	of_property_read_string(np, "model", &soc_dev_attr->machine);
3538d6799a9SGeert Uytterhoeven 	of_node_put(np);
3548d6799a9SGeert Uytterhoeven 
3558d6799a9SGeert Uytterhoeven 	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
3568d6799a9SGeert Uytterhoeven 	soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
3578d6799a9SGeert Uytterhoeven 					     GFP_KERNEL);
358*175f435fSChris Brandt 	if (eshi)
359*175f435fSChris Brandt 		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
360*175f435fSChris Brandt 						   eslo);
3618d6799a9SGeert Uytterhoeven 
3628d6799a9SGeert Uytterhoeven 	pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
3638d6799a9SGeert Uytterhoeven 		soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
3648d6799a9SGeert Uytterhoeven 
3658d6799a9SGeert Uytterhoeven 	soc_dev = soc_device_register(soc_dev_attr);
3668d6799a9SGeert Uytterhoeven 	if (IS_ERR(soc_dev)) {
3678d6799a9SGeert Uytterhoeven 		kfree(soc_dev_attr->revision);
3688d6799a9SGeert Uytterhoeven 		kfree_const(soc_dev_attr->soc_id);
3698d6799a9SGeert Uytterhoeven 		kfree_const(soc_dev_attr->family);
3708d6799a9SGeert Uytterhoeven 		kfree(soc_dev_attr);
3718d6799a9SGeert Uytterhoeven 		return PTR_ERR(soc_dev);
3728d6799a9SGeert Uytterhoeven 	}
3738d6799a9SGeert Uytterhoeven 
3748d6799a9SGeert Uytterhoeven 	return 0;
3758d6799a9SGeert Uytterhoeven }
376b1d134baSGeert Uytterhoeven early_initcall(renesas_soc_init);
377