18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Renesas SoC Identification
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2014-2016 Glider bvba
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/io.h>
98c2ecf20Sopenharmony_ci#include <linux/of.h>
108c2ecf20Sopenharmony_ci#include <linux/of_address.h>
118c2ecf20Sopenharmony_ci#include <linux/slab.h>
128c2ecf20Sopenharmony_ci#include <linux/string.h>
138c2ecf20Sopenharmony_ci#include <linux/sys_soc.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistruct renesas_family {
178c2ecf20Sopenharmony_ci	const char name[16];
188c2ecf20Sopenharmony_ci	u32 reg;			/* CCCR or PRR, if not in DT */
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
228c2ecf20Sopenharmony_ci	.name	= "R-Car Gen1",
238c2ecf20Sopenharmony_ci	.reg	= 0xff000044,		/* PRR (Product Register) */
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
278c2ecf20Sopenharmony_ci	.name	= "R-Car Gen2",
288c2ecf20Sopenharmony_ci	.reg	= 0xff000044,		/* PRR (Product Register) */
298c2ecf20Sopenharmony_ci};
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
328c2ecf20Sopenharmony_ci	.name	= "R-Car Gen3",
338c2ecf20Sopenharmony_ci	.reg	= 0xfff00044,		/* PRR (Product Register) */
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic const struct renesas_family fam_rmobile __initconst __maybe_unused = {
378c2ecf20Sopenharmony_ci	.name	= "R-Mobile",
388c2ecf20Sopenharmony_ci	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic const struct renesas_family fam_rza1 __initconst __maybe_unused = {
428c2ecf20Sopenharmony_ci	.name	= "RZ/A1",
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic const struct renesas_family fam_rza2 __initconst __maybe_unused = {
468c2ecf20Sopenharmony_ci	.name	= "RZ/A2",
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
508c2ecf20Sopenharmony_ci	.name	= "RZ/G1",
518c2ecf20Sopenharmony_ci	.reg	= 0xff000044,		/* PRR (Product Register) */
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
558c2ecf20Sopenharmony_ci	.name	= "RZ/G2",
568c2ecf20Sopenharmony_ci	.reg	= 0xfff00044,		/* PRR (Product Register) */
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic const struct renesas_family fam_shmobile __initconst __maybe_unused = {
608c2ecf20Sopenharmony_ci	.name	= "SH-Mobile",
618c2ecf20Sopenharmony_ci	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistruct renesas_soc {
668c2ecf20Sopenharmony_ci	const struct renesas_family *family;
678c2ecf20Sopenharmony_ci	u8 id;
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
718c2ecf20Sopenharmony_ci	.family	= &fam_rza1,
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
758c2ecf20Sopenharmony_ci	.family	= &fam_rza2,
768c2ecf20Sopenharmony_ci	.id	= 0x3b,
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
808c2ecf20Sopenharmony_ci	.family	= &fam_rmobile,
818c2ecf20Sopenharmony_ci	.id	= 0x3f,
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
858c2ecf20Sopenharmony_ci	.family	= &fam_rmobile,
868c2ecf20Sopenharmony_ci	.id	= 0x40,
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
908c2ecf20Sopenharmony_ci	.family	= &fam_rzg1,
918c2ecf20Sopenharmony_ci	.id	= 0x45,
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
958c2ecf20Sopenharmony_ci	.family	= &fam_rzg1,
968c2ecf20Sopenharmony_ci	.id	= 0x47,
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
1008c2ecf20Sopenharmony_ci	.family	= &fam_rzg1,
1018c2ecf20Sopenharmony_ci	.id	= 0x4b,
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
1058c2ecf20Sopenharmony_ci	.family	= &fam_rzg1,
1068c2ecf20Sopenharmony_ci	.id	= 0x4c,
1078c2ecf20Sopenharmony_ci};
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
1108c2ecf20Sopenharmony_ci	.family	= &fam_rzg1,
1118c2ecf20Sopenharmony_ci	.id	= 0x53,
1128c2ecf20Sopenharmony_ci};
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
1158c2ecf20Sopenharmony_ci	.family	= &fam_rzg2,
1168c2ecf20Sopenharmony_ci	.id	= 0x52,
1178c2ecf20Sopenharmony_ci};
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
1208c2ecf20Sopenharmony_ci	.family = &fam_rzg2,
1218c2ecf20Sopenharmony_ci	.id     = 0x55,
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
1258c2ecf20Sopenharmony_ci	.family	= &fam_rzg2,
1268c2ecf20Sopenharmony_ci	.id	= 0x57,
1278c2ecf20Sopenharmony_ci};
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
1308c2ecf20Sopenharmony_ci	.family	= &fam_rzg2,
1318c2ecf20Sopenharmony_ci	.id	= 0x4f,
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
1358c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen1,
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
1398c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen1,
1408c2ecf20Sopenharmony_ci	.id	= 0x3b,
1418c2ecf20Sopenharmony_ci};
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
1448c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen2,
1458c2ecf20Sopenharmony_ci	.id	= 0x45,
1468c2ecf20Sopenharmony_ci};
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
1498c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen2,
1508c2ecf20Sopenharmony_ci	.id	= 0x47,
1518c2ecf20Sopenharmony_ci};
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
1548c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen2,
1558c2ecf20Sopenharmony_ci	.id	= 0x4a,
1568c2ecf20Sopenharmony_ci};
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
1598c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen2,
1608c2ecf20Sopenharmony_ci	.id	= 0x4b,
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
1648c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen2,
1658c2ecf20Sopenharmony_ci	.id	= 0x4c,
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
1698c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen3,
1708c2ecf20Sopenharmony_ci	.id	= 0x4f,
1718c2ecf20Sopenharmony_ci};
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
1748c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen3,
1758c2ecf20Sopenharmony_ci	.id	= 0x52,
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
1798c2ecf20Sopenharmony_ci	.family = &fam_rcar_gen3,
1808c2ecf20Sopenharmony_ci	.id     = 0x55,
1818c2ecf20Sopenharmony_ci};
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
1848c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen3,
1858c2ecf20Sopenharmony_ci	.id	= 0x54,
1868c2ecf20Sopenharmony_ci};
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
1898c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen3,
1908c2ecf20Sopenharmony_ci	.id	= 0x56,
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
1948c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen3,
1958c2ecf20Sopenharmony_ci	.id	= 0x57,
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
1998c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen3,
2008c2ecf20Sopenharmony_ci	.id	= 0x58,
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
2048c2ecf20Sopenharmony_ci	.family	= &fam_rcar_gen3,
2058c2ecf20Sopenharmony_ci	.id	= 0x59,
2068c2ecf20Sopenharmony_ci};
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cistatic const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
2098c2ecf20Sopenharmony_ci	.family	= &fam_shmobile,
2108c2ecf20Sopenharmony_ci	.id	= 0x37,
2118c2ecf20Sopenharmony_ci};
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic const struct of_device_id renesas_socs[] __initconst = {
2158c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R7S72100
2168c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
2178c2ecf20Sopenharmony_ci#endif
2188c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R7S9210
2198c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
2208c2ecf20Sopenharmony_ci#endif
2218c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A73A4
2228c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
2238c2ecf20Sopenharmony_ci#endif
2248c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7740
2258c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
2268c2ecf20Sopenharmony_ci#endif
2278c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7742
2288c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
2298c2ecf20Sopenharmony_ci#endif
2308c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7743
2318c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
2328c2ecf20Sopenharmony_ci#endif
2338c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7744
2348c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
2358c2ecf20Sopenharmony_ci#endif
2368c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7745
2378c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
2388c2ecf20Sopenharmony_ci#endif
2398c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A77470
2408c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
2418c2ecf20Sopenharmony_ci#endif
2428c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A774A1
2438c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
2448c2ecf20Sopenharmony_ci#endif
2458c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A774B1
2468c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a774b1",	.data = &soc_rz_g2n },
2478c2ecf20Sopenharmony_ci#endif
2488c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A774C0
2498c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a774c0",	.data = &soc_rz_g2e },
2508c2ecf20Sopenharmony_ci#endif
2518c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A774E1
2528c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a774e1",	.data = &soc_rz_g2h },
2538c2ecf20Sopenharmony_ci#endif
2548c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7778
2558c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
2568c2ecf20Sopenharmony_ci#endif
2578c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7779
2588c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
2598c2ecf20Sopenharmony_ci#endif
2608c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7790
2618c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
2628c2ecf20Sopenharmony_ci#endif
2638c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7791
2648c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
2658c2ecf20Sopenharmony_ci#endif
2668c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7792
2678c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
2688c2ecf20Sopenharmony_ci#endif
2698c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7793
2708c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
2718c2ecf20Sopenharmony_ci#endif
2728c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A7794
2738c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
2748c2ecf20Sopenharmony_ci#endif
2758c2ecf20Sopenharmony_ci#if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
2768c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
2778c2ecf20Sopenharmony_ci#endif
2788c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A77960
2798c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
2808c2ecf20Sopenharmony_ci#endif
2818c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A77961
2828c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a77961",	.data = &soc_rcar_m3_w },
2838c2ecf20Sopenharmony_ci#endif
2848c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A77965
2858c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
2868c2ecf20Sopenharmony_ci#endif
2878c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A77970
2888c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
2898c2ecf20Sopenharmony_ci#endif
2908c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A77980
2918c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
2928c2ecf20Sopenharmony_ci#endif
2938c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A77990
2948c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
2958c2ecf20Sopenharmony_ci#endif
2968c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A77995
2978c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
2988c2ecf20Sopenharmony_ci#endif
2998c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_R8A779A0
3008c2ecf20Sopenharmony_ci	{ .compatible = "renesas,r8a779a0",	.data = &soc_rcar_v3u },
3018c2ecf20Sopenharmony_ci#endif
3028c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_SH73A0
3038c2ecf20Sopenharmony_ci	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
3048c2ecf20Sopenharmony_ci#endif
3058c2ecf20Sopenharmony_ci	{ /* sentinel */ }
3068c2ecf20Sopenharmony_ci};
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistatic int __init renesas_soc_init(void)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	struct soc_device_attribute *soc_dev_attr;
3118c2ecf20Sopenharmony_ci	const struct renesas_family *family;
3128c2ecf20Sopenharmony_ci	const struct of_device_id *match;
3138c2ecf20Sopenharmony_ci	const struct renesas_soc *soc;
3148c2ecf20Sopenharmony_ci	void __iomem *chipid = NULL;
3158c2ecf20Sopenharmony_ci	struct soc_device *soc_dev;
3168c2ecf20Sopenharmony_ci	struct device_node *np;
3178c2ecf20Sopenharmony_ci	unsigned int product, eshi = 0, eslo;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	match = of_match_node(renesas_socs, of_root);
3208c2ecf20Sopenharmony_ci	if (!match)
3218c2ecf20Sopenharmony_ci		return -ENODEV;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	soc = match->data;
3248c2ecf20Sopenharmony_ci	family = soc->family;
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
3278c2ecf20Sopenharmony_ci	if (np) {
3288c2ecf20Sopenharmony_ci		chipid = of_iomap(np, 0);
3298c2ecf20Sopenharmony_ci		of_node_put(np);
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci		if (chipid) {
3328c2ecf20Sopenharmony_ci			product = readl(chipid);
3338c2ecf20Sopenharmony_ci			iounmap(chipid);
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci			if (soc->id && ((product >> 16) & 0xff) != soc->id) {
3368c2ecf20Sopenharmony_ci				pr_warn("SoC mismatch (product = 0x%x)\n",
3378c2ecf20Sopenharmony_ci					product);
3388c2ecf20Sopenharmony_ci				return -ENODEV;
3398c2ecf20Sopenharmony_ci			}
3408c2ecf20Sopenharmony_ci		}
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci		/*
3438c2ecf20Sopenharmony_ci		 * TODO: Upper 4 bits of BSID are for chip version, but the
3448c2ecf20Sopenharmony_ci		 * format is not known at this time so we don't know how to
3458c2ecf20Sopenharmony_ci		 * specify eshi and eslo
3468c2ecf20Sopenharmony_ci		 */
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci		goto done;
3498c2ecf20Sopenharmony_ci	}
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	/* Try PRR first, then hardcoded fallback */
3528c2ecf20Sopenharmony_ci	np = of_find_compatible_node(NULL, NULL, "renesas,prr");
3538c2ecf20Sopenharmony_ci	if (np) {
3548c2ecf20Sopenharmony_ci		chipid = of_iomap(np, 0);
3558c2ecf20Sopenharmony_ci		of_node_put(np);
3568c2ecf20Sopenharmony_ci	} else if (soc->id && family->reg) {
3578c2ecf20Sopenharmony_ci		chipid = ioremap(family->reg, 4);
3588c2ecf20Sopenharmony_ci	}
3598c2ecf20Sopenharmony_ci	if (chipid) {
3608c2ecf20Sopenharmony_ci		product = readl(chipid);
3618c2ecf20Sopenharmony_ci		iounmap(chipid);
3628c2ecf20Sopenharmony_ci		/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
3638c2ecf20Sopenharmony_ci		if ((product & 0x7fff) == 0x5210)
3648c2ecf20Sopenharmony_ci			product ^= 0x11;
3658c2ecf20Sopenharmony_ci		/* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
3668c2ecf20Sopenharmony_ci		if ((product & 0x7fff) == 0x5211)
3678c2ecf20Sopenharmony_ci			product ^= 0x12;
3688c2ecf20Sopenharmony_ci		if (soc->id && ((product >> 8) & 0xff) != soc->id) {
3698c2ecf20Sopenharmony_ci			pr_warn("SoC mismatch (product = 0x%x)\n", product);
3708c2ecf20Sopenharmony_ci			return -ENODEV;
3718c2ecf20Sopenharmony_ci		}
3728c2ecf20Sopenharmony_ci		eshi = ((product >> 4) & 0x0f) + 1;
3738c2ecf20Sopenharmony_ci		eslo = product & 0xf;
3748c2ecf20Sopenharmony_ci	}
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cidone:
3778c2ecf20Sopenharmony_ci	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
3788c2ecf20Sopenharmony_ci	if (!soc_dev_attr)
3798c2ecf20Sopenharmony_ci		return -ENOMEM;
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	np = of_find_node_by_path("/");
3828c2ecf20Sopenharmony_ci	of_property_read_string(np, "model", &soc_dev_attr->machine);
3838c2ecf20Sopenharmony_ci	of_node_put(np);
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
3868c2ecf20Sopenharmony_ci	soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
3878c2ecf20Sopenharmony_ci					     GFP_KERNEL);
3888c2ecf20Sopenharmony_ci	if (eshi)
3898c2ecf20Sopenharmony_ci		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
3908c2ecf20Sopenharmony_ci						   eslo);
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci	pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
3938c2ecf20Sopenharmony_ci		soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	soc_dev = soc_device_register(soc_dev_attr);
3968c2ecf20Sopenharmony_ci	if (IS_ERR(soc_dev)) {
3978c2ecf20Sopenharmony_ci		kfree(soc_dev_attr->revision);
3988c2ecf20Sopenharmony_ci		kfree_const(soc_dev_attr->soc_id);
3998c2ecf20Sopenharmony_ci		kfree_const(soc_dev_attr->family);
4008c2ecf20Sopenharmony_ci		kfree(soc_dev_attr);
4018c2ecf20Sopenharmony_ci		return PTR_ERR(soc_dev);
4028c2ecf20Sopenharmony_ci	}
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	return 0;
4058c2ecf20Sopenharmony_ci}
4068c2ecf20Sopenharmony_ciearly_initcall(renesas_soc_init);
407