Linux 4.19.133
[linux/fpc-iii.git] / drivers / soc / renesas / renesas-soc.c
blob2a43d6e99962f856382f7f6d93cb1e856f712d2a
1 /*
2 * Renesas SoC Identification
4 * Copyright (C) 2014-2016 Glider bvba
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/io.h>
17 #include <linux/of.h>
18 #include <linux/of_address.h>
19 #include <linux/slab.h>
20 #include <linux/string.h>
21 #include <linux/sys_soc.h>
24 struct renesas_family {
25 const char name[16];
26 u32 reg; /* CCCR or PRR, if not in DT */
29 static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
30 .name = "R-Car Gen1",
31 .reg = 0xff000044, /* PRR (Product Register) */
34 static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
35 .name = "R-Car Gen2",
36 .reg = 0xff000044, /* PRR (Product Register) */
39 static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
40 .name = "R-Car Gen3",
41 .reg = 0xfff00044, /* PRR (Product Register) */
44 static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
45 .name = "R-Mobile",
46 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
49 static const struct renesas_family fam_rza __initconst __maybe_unused = {
50 .name = "RZ/A",
53 static const struct renesas_family fam_rzg __initconst __maybe_unused = {
54 .name = "RZ/G",
55 .reg = 0xff000044, /* PRR (Product Register) */
58 static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
59 .name = "SH-Mobile",
60 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
64 struct renesas_soc {
65 const struct renesas_family *family;
66 u8 id;
69 static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
70 .family = &fam_rza,
73 static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
74 .family = &fam_rmobile,
75 .id = 0x3f,
78 static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
79 .family = &fam_rmobile,
80 .id = 0x40,
83 static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
84 .family = &fam_rzg,
85 .id = 0x45,
88 static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
89 .family = &fam_rzg,
90 .id = 0x47,
93 static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
94 .family = &fam_rzg,
95 .id = 0x4b,
98 static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
99 .family = &fam_rzg,
100 .id = 0x4c,
103 static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
104 .family = &fam_rzg,
105 .id = 0x53,
108 static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
109 .family = &fam_rcar_gen1,
112 static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
113 .family = &fam_rcar_gen1,
114 .id = 0x3b,
117 static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
118 .family = &fam_rcar_gen2,
119 .id = 0x45,
122 static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
123 .family = &fam_rcar_gen2,
124 .id = 0x47,
127 static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
128 .family = &fam_rcar_gen2,
129 .id = 0x4a,
132 static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
133 .family = &fam_rcar_gen2,
134 .id = 0x4b,
137 static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
138 .family = &fam_rcar_gen2,
139 .id = 0x4c,
142 static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
143 .family = &fam_rcar_gen3,
144 .id = 0x4f,
147 static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
148 .family = &fam_rcar_gen3,
149 .id = 0x52,
152 static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
153 .family = &fam_rcar_gen3,
154 .id = 0x55,
157 static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
158 .family = &fam_rcar_gen3,
159 .id = 0x54,
162 static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
163 .family = &fam_rcar_gen3,
164 .id = 0x56,
167 static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
168 .family = &fam_rcar_gen3,
169 .id = 0x57,
172 static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
173 .family = &fam_rcar_gen3,
174 .id = 0x58,
177 static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
178 .family = &fam_shmobile,
179 .id = 0x37,
183 static const struct of_device_id renesas_socs[] __initconst = {
184 #ifdef CONFIG_ARCH_R7S72100
185 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
186 #endif
187 #ifdef CONFIG_ARCH_R8A73A4
188 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
189 #endif
190 #ifdef CONFIG_ARCH_R8A7740
191 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
192 #endif
193 #ifdef CONFIG_ARCH_R8A7742
194 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
195 #endif
196 #ifdef CONFIG_ARCH_R8A7743
197 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
198 #endif
199 #ifdef CONFIG_ARCH_R8A7744
200 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
201 #endif
202 #ifdef CONFIG_ARCH_R8A7745
203 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
204 #endif
205 #ifdef CONFIG_ARCH_R8A77470
206 { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
207 #endif
208 #ifdef CONFIG_ARCH_R8A7778
209 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
210 #endif
211 #ifdef CONFIG_ARCH_R8A7779
212 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
213 #endif
214 #ifdef CONFIG_ARCH_R8A7790
215 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
216 #endif
217 #ifdef CONFIG_ARCH_R8A7791
218 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
219 #endif
220 #ifdef CONFIG_ARCH_R8A7792
221 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
222 #endif
223 #ifdef CONFIG_ARCH_R8A7793
224 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
225 #endif
226 #ifdef CONFIG_ARCH_R8A7794
227 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
228 #endif
229 #ifdef CONFIG_ARCH_R8A7795
230 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
231 #endif
232 #ifdef CONFIG_ARCH_R8A7796
233 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
234 #endif
235 #ifdef CONFIG_ARCH_R8A77965
236 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
237 #endif
238 #ifdef CONFIG_ARCH_R8A77970
239 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
240 #endif
241 #ifdef CONFIG_ARCH_R8A77980
242 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
243 #endif
244 #ifdef CONFIG_ARCH_R8A77990
245 { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
246 #endif
247 #ifdef CONFIG_ARCH_R8A77995
248 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
249 #endif
250 #ifdef CONFIG_ARCH_SH73A0
251 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
252 #endif
253 { /* sentinel */ }
256 static int __init renesas_soc_init(void)
258 struct soc_device_attribute *soc_dev_attr;
259 const struct renesas_family *family;
260 const struct of_device_id *match;
261 const struct renesas_soc *soc;
262 void __iomem *chipid = NULL;
263 struct soc_device *soc_dev;
264 struct device_node *np;
265 unsigned int product;
267 match = of_match_node(renesas_socs, of_root);
268 if (!match)
269 return -ENODEV;
271 soc = match->data;
272 family = soc->family;
274 /* Try PRR first, then hardcoded fallback */
275 np = of_find_compatible_node(NULL, NULL, "renesas,prr");
276 if (np) {
277 chipid = of_iomap(np, 0);
278 of_node_put(np);
279 } else if (soc->id) {
280 chipid = ioremap(family->reg, 4);
282 if (chipid) {
283 product = readl(chipid);
284 iounmap(chipid);
285 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
286 if ((product & 0x7fff) == 0x5210)
287 product ^= 0x11;
288 /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
289 if ((product & 0x7fff) == 0x5211)
290 product ^= 0x12;
291 if (soc->id && ((product >> 8) & 0xff) != soc->id) {
292 pr_warn("SoC mismatch (product = 0x%x)\n", product);
293 return -ENODEV;
297 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
298 if (!soc_dev_attr)
299 return -ENOMEM;
301 np = of_find_node_by_path("/");
302 of_property_read_string(np, "model", &soc_dev_attr->machine);
303 of_node_put(np);
305 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
306 soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
307 GFP_KERNEL);
308 if (chipid)
309 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
310 ((product >> 4) & 0x0f) + 1,
311 product & 0xf);
313 pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
314 soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
316 soc_dev = soc_device_register(soc_dev_attr);
317 if (IS_ERR(soc_dev)) {
318 kfree(soc_dev_attr->revision);
319 kfree_const(soc_dev_attr->soc_id);
320 kfree_const(soc_dev_attr->family);
321 kfree(soc_dev_attr);
322 return PTR_ERR(soc_dev);
325 return 0;
327 early_initcall(renesas_soc_init);