xref: /linux/drivers/soc/renesas/renesas-soc.c (revision cd59de80dd34dd2d1a3ca97d7a6e712c048b135a)
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 
498d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rza __initconst __maybe_unused = {
508d6799a9SGeert Uytterhoeven 	.name	= "RZ/A",
518d6799a9SGeert Uytterhoeven };
528d6799a9SGeert Uytterhoeven 
538d6799a9SGeert Uytterhoeven static const struct renesas_family fam_rzg __initconst __maybe_unused = {
548d6799a9SGeert Uytterhoeven 	.name	= "RZ/G",
558d6799a9SGeert Uytterhoeven 	.reg	= 0xff000044,		/* PRR (Product Register) */
568d6799a9SGeert Uytterhoeven };
578d6799a9SGeert Uytterhoeven 
588d6799a9SGeert Uytterhoeven static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
598d6799a9SGeert Uytterhoeven 	.name	= "SH-Mobile",
608d6799a9SGeert Uytterhoeven 	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
618d6799a9SGeert Uytterhoeven };
628d6799a9SGeert Uytterhoeven 
638d6799a9SGeert Uytterhoeven 
648d6799a9SGeert Uytterhoeven struct renesas_soc {
658d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
668d6799a9SGeert Uytterhoeven 	u8 id;
678d6799a9SGeert Uytterhoeven };
688d6799a9SGeert Uytterhoeven 
698d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
708d6799a9SGeert Uytterhoeven 	.family	= &fam_rza,
718d6799a9SGeert Uytterhoeven };
728d6799a9SGeert Uytterhoeven 
738d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
748d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
758d6799a9SGeert Uytterhoeven 	.id	= 0x3f,
768d6799a9SGeert Uytterhoeven };
778d6799a9SGeert Uytterhoeven 
788d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
798d6799a9SGeert Uytterhoeven 	.family	= &fam_rmobile,
808d6799a9SGeert Uytterhoeven 	.id	= 0x40,
818d6799a9SGeert Uytterhoeven };
828d6799a9SGeert Uytterhoeven 
838848e1b1SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
848848e1b1SGeert Uytterhoeven 	.family	= &fam_rzg,
858848e1b1SGeert Uytterhoeven 	.id	= 0x45,
868848e1b1SGeert Uytterhoeven };
878848e1b1SGeert Uytterhoeven 
888d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
898d6799a9SGeert Uytterhoeven 	.family	= &fam_rzg,
908d6799a9SGeert Uytterhoeven 	.id	= 0x47,
918d6799a9SGeert Uytterhoeven };
928d6799a9SGeert Uytterhoeven 
93*cd59de80SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
94*cd59de80SGeert Uytterhoeven 	.family	= &fam_rzg,
95*cd59de80SGeert Uytterhoeven 	.id	= 0x4b,
96*cd59de80SGeert Uytterhoeven };
97*cd59de80SGeert Uytterhoeven 
988d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
998d6799a9SGeert Uytterhoeven 	.family	= &fam_rzg,
1008d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1018d6799a9SGeert Uytterhoeven };
1028d6799a9SGeert Uytterhoeven 
1038d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
1048d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1058d6799a9SGeert Uytterhoeven };
1068d6799a9SGeert Uytterhoeven 
1078d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
1088d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen1,
1098d6799a9SGeert Uytterhoeven 	.id	= 0x3b,
1108d6799a9SGeert Uytterhoeven };
1118d6799a9SGeert Uytterhoeven 
1128d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
1138d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1148d6799a9SGeert Uytterhoeven 	.id	= 0x45,
1158d6799a9SGeert Uytterhoeven };
1168d6799a9SGeert Uytterhoeven 
1178d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
1188d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1198d6799a9SGeert Uytterhoeven 	.id	= 0x47,
1208d6799a9SGeert Uytterhoeven };
1218d6799a9SGeert Uytterhoeven 
1228d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
1238d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1248d6799a9SGeert Uytterhoeven 	.id	= 0x4a,
1258d6799a9SGeert Uytterhoeven };
1268d6799a9SGeert Uytterhoeven 
1278d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
1288d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1298d6799a9SGeert Uytterhoeven 	.id	= 0x4b,
1308d6799a9SGeert Uytterhoeven };
1318d6799a9SGeert Uytterhoeven 
1328d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
1338d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen2,
1348d6799a9SGeert Uytterhoeven 	.id	= 0x4c,
1358d6799a9SGeert Uytterhoeven };
1368d6799a9SGeert Uytterhoeven 
1378d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
1388d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1398d6799a9SGeert Uytterhoeven 	.id	= 0x4f,
1408d6799a9SGeert Uytterhoeven };
1418d6799a9SGeert Uytterhoeven 
1428d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
1438d6799a9SGeert Uytterhoeven 	.family	= &fam_rcar_gen3,
1448d6799a9SGeert Uytterhoeven 	.id	= 0x52,
1458d6799a9SGeert Uytterhoeven };
1468d6799a9SGeert Uytterhoeven 
1478d6799a9SGeert Uytterhoeven static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
1488d6799a9SGeert Uytterhoeven 	.family	= &fam_shmobile,
1498d6799a9SGeert Uytterhoeven 	.id	= 0x37,
1508d6799a9SGeert Uytterhoeven };
1518d6799a9SGeert Uytterhoeven 
1528d6799a9SGeert Uytterhoeven 
1538d6799a9SGeert Uytterhoeven static const struct of_device_id renesas_socs[] __initconst = {
1548d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R7S72100
1558d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
1568d6799a9SGeert Uytterhoeven #endif
1578d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A73A4
1588d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
1598d6799a9SGeert Uytterhoeven #endif
1608d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7740
1618d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
1628d6799a9SGeert Uytterhoeven #endif
1638848e1b1SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7742
1648848e1b1SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
1658848e1b1SGeert Uytterhoeven #endif
1668d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7743
1678d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
1688d6799a9SGeert Uytterhoeven #endif
169*cd59de80SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7744
170*cd59de80SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
171*cd59de80SGeert Uytterhoeven #endif
1728d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7745
1738d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
1748d6799a9SGeert Uytterhoeven #endif
1758d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7778
1768d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
1778d6799a9SGeert Uytterhoeven #endif
1788d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7779
1798d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
1808d6799a9SGeert Uytterhoeven #endif
1818d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7790
1828d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
1838d6799a9SGeert Uytterhoeven #endif
1848d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7791
1858d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
1868d6799a9SGeert Uytterhoeven #endif
1878d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7792
1888d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
1898d6799a9SGeert Uytterhoeven #endif
1908d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7793
1918d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
1928d6799a9SGeert Uytterhoeven #endif
1938d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7794
1948d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
1958d6799a9SGeert Uytterhoeven #endif
1968d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7795
1978d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
1988d6799a9SGeert Uytterhoeven #endif
1998d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_R8A7796
2008d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
2018d6799a9SGeert Uytterhoeven #endif
2028d6799a9SGeert Uytterhoeven #ifdef CONFIG_ARCH_SH73A0
2038d6799a9SGeert Uytterhoeven 	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
2048d6799a9SGeert Uytterhoeven #endif
2058d6799a9SGeert Uytterhoeven 	{ /* sentinel */ }
2068d6799a9SGeert Uytterhoeven };
2078d6799a9SGeert Uytterhoeven 
2088d6799a9SGeert Uytterhoeven static int __init renesas_soc_init(void)
2098d6799a9SGeert Uytterhoeven {
2108d6799a9SGeert Uytterhoeven 	struct soc_device_attribute *soc_dev_attr;
2118d6799a9SGeert Uytterhoeven 	const struct renesas_family *family;
2128d6799a9SGeert Uytterhoeven 	const struct of_device_id *match;
2138d6799a9SGeert Uytterhoeven 	const struct renesas_soc *soc;
2148d6799a9SGeert Uytterhoeven 	void __iomem *chipid = NULL;
2158d6799a9SGeert Uytterhoeven 	struct soc_device *soc_dev;
2168d6799a9SGeert Uytterhoeven 	struct device_node *np;
2178d6799a9SGeert Uytterhoeven 	unsigned int product;
2188d6799a9SGeert Uytterhoeven 
2198d6799a9SGeert Uytterhoeven 	match = of_match_node(renesas_socs, of_root);
2208d6799a9SGeert Uytterhoeven 	if (!match)
2218d6799a9SGeert Uytterhoeven 		return -ENODEV;
2228d6799a9SGeert Uytterhoeven 
2238d6799a9SGeert Uytterhoeven 	soc = match->data;
2248d6799a9SGeert Uytterhoeven 	family = soc->family;
2258d6799a9SGeert Uytterhoeven 
2268d6799a9SGeert Uytterhoeven 	/* Try PRR first, then hardcoded fallback */
2278d6799a9SGeert Uytterhoeven 	np = of_find_compatible_node(NULL, NULL, "renesas,prr");
2288d6799a9SGeert Uytterhoeven 	if (np) {
2298d6799a9SGeert Uytterhoeven 		chipid = of_iomap(np, 0);
2308d6799a9SGeert Uytterhoeven 		of_node_put(np);
2318d6799a9SGeert Uytterhoeven 	} else if (soc->id) {
2328d6799a9SGeert Uytterhoeven 		chipid = ioremap(family->reg, 4);
2338d6799a9SGeert Uytterhoeven 	}
2348d6799a9SGeert Uytterhoeven 	if (chipid) {
2358d6799a9SGeert Uytterhoeven 		product = readl(chipid);
2368d6799a9SGeert Uytterhoeven 		iounmap(chipid);
2378d6799a9SGeert Uytterhoeven 		if (soc->id && ((product >> 8) & 0xff) != soc->id) {
2388d6799a9SGeert Uytterhoeven 			pr_warn("SoC mismatch (product = 0x%x)\n", product);
2398d6799a9SGeert Uytterhoeven 			return -ENODEV;
2408d6799a9SGeert Uytterhoeven 		}
2418d6799a9SGeert Uytterhoeven 	}
2428d6799a9SGeert Uytterhoeven 
2438d6799a9SGeert Uytterhoeven 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
2448d6799a9SGeert Uytterhoeven 	if (!soc_dev_attr)
2458d6799a9SGeert Uytterhoeven 		return -ENOMEM;
2468d6799a9SGeert Uytterhoeven 
2478d6799a9SGeert Uytterhoeven 	np = of_find_node_by_path("/");
2488d6799a9SGeert Uytterhoeven 	of_property_read_string(np, "model", &soc_dev_attr->machine);
2498d6799a9SGeert Uytterhoeven 	of_node_put(np);
2508d6799a9SGeert Uytterhoeven 
2518d6799a9SGeert Uytterhoeven 	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
2528d6799a9SGeert Uytterhoeven 	soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
2538d6799a9SGeert Uytterhoeven 					     GFP_KERNEL);
2548d6799a9SGeert Uytterhoeven 	if (chipid)
2558d6799a9SGeert Uytterhoeven 		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
2568d6799a9SGeert Uytterhoeven 						   ((product >> 4) & 0x0f) + 1,
2578d6799a9SGeert Uytterhoeven 						   product & 0xf);
2588d6799a9SGeert Uytterhoeven 
2598d6799a9SGeert Uytterhoeven 	pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
2608d6799a9SGeert Uytterhoeven 		soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
2618d6799a9SGeert Uytterhoeven 
2628d6799a9SGeert Uytterhoeven 	soc_dev = soc_device_register(soc_dev_attr);
2638d6799a9SGeert Uytterhoeven 	if (IS_ERR(soc_dev)) {
2648d6799a9SGeert Uytterhoeven 		kfree(soc_dev_attr->revision);
2658d6799a9SGeert Uytterhoeven 		kfree_const(soc_dev_attr->soc_id);
2668d6799a9SGeert Uytterhoeven 		kfree_const(soc_dev_attr->family);
2678d6799a9SGeert Uytterhoeven 		kfree(soc_dev_attr);
2688d6799a9SGeert Uytterhoeven 		return PTR_ERR(soc_dev);
2698d6799a9SGeert Uytterhoeven 	}
2708d6799a9SGeert Uytterhoeven 
2718d6799a9SGeert Uytterhoeven 	return 0;
2728d6799a9SGeert Uytterhoeven }
2738d6799a9SGeert Uytterhoeven core_initcall(renesas_soc_init);
274