blob: 35dba8b8814e31f5a52a75cdb5b081b704f19d86 [file] [log] [blame]
Kuninori Morimoto41c45672018-09-07 02:04:19 +00001// SPDX-License-Identifier: GPL-2.0
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +01002/*
3 * Renesas SoC Identification
4 *
5 * Copyright (C) 2014-2016 Glider bvba
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +01006 */
7
8#include <linux/io.h>
9#include <linux/of.h>
10#include <linux/of_address.h>
11#include <linux/slab.h>
12#include <linux/string.h>
13#include <linux/sys_soc.h>
14
15
16struct renesas_family {
17 const char name[16];
18 u32 reg; /* CCCR or PRR, if not in DT */
19};
20
21static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
22 .name = "R-Car Gen1",
23 .reg = 0xff000044, /* PRR (Product Register) */
24};
25
26static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
27 .name = "R-Car Gen2",
28 .reg = 0xff000044, /* PRR (Product Register) */
29};
30
31static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
32 .name = "R-Car Gen3",
33 .reg = 0xfff00044, /* PRR (Product Register) */
34};
35
36static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
37 .name = "R-Mobile",
38 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
39};
40
Chris Brandt175f4352018-07-27 11:53:32 -050041static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
42 .name = "RZ/A1",
43};
44
45static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
46 .name = "RZ/A2",
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +010047};
48
Biju Das2a4056a72018-07-24 16:47:18 +010049static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
50 .name = "RZ/G1",
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +010051 .reg = 0xff000044, /* PRR (Product Register) */
52};
53
Biju Das2a4056a72018-07-24 16:47:18 +010054static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
55 .name = "RZ/G2",
56 .reg = 0xfff00044, /* PRR (Product Register) */
57};
58
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +010059static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
60 .name = "SH-Mobile",
61 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
62};
63
64
65struct renesas_soc {
66 const struct renesas_family *family;
67 u8 id;
68};
69
70static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
Chris Brandt175f4352018-07-27 11:53:32 -050071 .family = &fam_rza1,
72};
73
74static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
75 .family = &fam_rza2,
76 .id = 0x3b,
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +010077};
78
79static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
80 .family = &fam_rmobile,
81 .id = 0x3f,
82};
83
84static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
85 .family = &fam_rmobile,
86 .id = 0x40,
87};
88
Geert Uytterhoeven8848e1b2017-03-10 14:48:29 +010089static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
Biju Das2a4056a72018-07-24 16:47:18 +010090 .family = &fam_rzg1,
Geert Uytterhoeven8848e1b2017-03-10 14:48:29 +010091 .id = 0x45,
92};
93
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +010094static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
Biju Das2a4056a72018-07-24 16:47:18 +010095 .family = &fam_rzg1,
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +010096 .id = 0x47,
97};
98
Geert Uytterhoevencd59de82017-03-10 14:48:30 +010099static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
Biju Das2a4056a72018-07-24 16:47:18 +0100100 .family = &fam_rzg1,
Geert Uytterhoevencd59de82017-03-10 14:48:30 +0100101 .id = 0x4b,
102};
103
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100104static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
Biju Das2a4056a72018-07-24 16:47:18 +0100105 .family = &fam_rzg1,
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100106 .id = 0x4c,
107};
108
Biju Das1daf13b2018-03-27 15:37:13 +0100109static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
Biju Das2a4056a72018-07-24 16:47:18 +0100110 .family = &fam_rzg1,
Biju Das1daf13b2018-03-27 15:37:13 +0100111 .id = 0x53,
112};
113
Biju Das2a4056a72018-07-24 16:47:18 +0100114static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
115 .family = &fam_rzg2,
116 .id = 0x52,
117};
118
Biju Das574cb722019-09-05 10:30:42 +0100119static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
120 .family = &fam_rzg2,
121 .id = 0x55,
122};
123
Fabrizio Castro2bab3d82018-09-10 12:53:50 +0100124static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
125 .family = &fam_rzg2,
126 .id = 0x57,
127};
128
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100129static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
130 .family = &fam_rcar_gen1,
131};
132
133static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
134 .family = &fam_rcar_gen1,
135 .id = 0x3b,
136};
137
138static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
139 .family = &fam_rcar_gen2,
140 .id = 0x45,
141};
142
143static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
144 .family = &fam_rcar_gen2,
145 .id = 0x47,
146};
147
148static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
149 .family = &fam_rcar_gen2,
150 .id = 0x4a,
151};
152
153static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
154 .family = &fam_rcar_gen2,
155 .id = 0x4b,
156};
157
158static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
159 .family = &fam_rcar_gen2,
160 .id = 0x4c,
161};
162
163static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
164 .family = &fam_rcar_gen3,
165 .id = 0x4f,
166};
167
168static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
169 .family = &fam_rcar_gen3,
170 .id = 0x52,
171};
172
Jacopo Mondibfd83982018-02-20 16:12:05 +0100173static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
174 .family = &fam_rcar_gen3,
175 .id = 0x55,
176};
177
Sergei Shtylyovbb0030752017-09-12 23:37:17 +0300178static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
179 .family = &fam_rcar_gen3,
180 .id = 0x54,
181};
182
Sergei Shtylyov84477562018-02-02 21:22:14 +0300183static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
184 .family = &fam_rcar_gen3,
185 .id = 0x56,
186};
187
Takeshi Kihara44842d42018-04-11 18:36:23 +0900188static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
189 .family = &fam_rcar_gen3,
190 .id = 0x57,
191};
192
Geert Uytterhoeven1b954782017-07-20 14:34:51 +0200193static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
194 .family = &fam_rcar_gen3,
195 .id = 0x58,
196};
197
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100198static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
199 .family = &fam_shmobile,
200 .id = 0x37,
201};
202
203
204static const struct of_device_id renesas_socs[] __initconst = {
205#ifdef CONFIG_ARCH_R7S72100
206 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
207#endif
Chris Brandt175f4352018-07-27 11:53:32 -0500208#ifdef CONFIG_ARCH_R7S9210
209 { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
210#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100211#ifdef CONFIG_ARCH_R8A73A4
212 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
213#endif
214#ifdef CONFIG_ARCH_R8A7740
215 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
216#endif
Geert Uytterhoeven8848e1b2017-03-10 14:48:29 +0100217#ifdef CONFIG_ARCH_R8A7742
218 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
219#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100220#ifdef CONFIG_ARCH_R8A7743
221 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
222#endif
Geert Uytterhoevencd59de82017-03-10 14:48:30 +0100223#ifdef CONFIG_ARCH_R8A7744
224 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
225#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100226#ifdef CONFIG_ARCH_R8A7745
227 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
228#endif
Biju Das1daf13b2018-03-27 15:37:13 +0100229#ifdef CONFIG_ARCH_R8A77470
230 { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
231#endif
Biju Das2a4056a72018-07-24 16:47:18 +0100232#ifdef CONFIG_ARCH_R8A774A1
233 { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
234#endif
Biju Das574cb722019-09-05 10:30:42 +0100235#ifdef CONFIG_ARCH_R8A774B1
236 { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n },
237#endif
Fabrizio Castro2bab3d82018-09-10 12:53:50 +0100238#ifdef CONFIG_ARCH_R8A774C0
239 { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
240#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100241#ifdef CONFIG_ARCH_R8A7778
242 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
243#endif
244#ifdef CONFIG_ARCH_R8A7779
245 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
246#endif
247#ifdef CONFIG_ARCH_R8A7790
248 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
249#endif
250#ifdef CONFIG_ARCH_R8A7791
251 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
252#endif
253#ifdef CONFIG_ARCH_R8A7792
254 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
255#endif
256#ifdef CONFIG_ARCH_R8A7793
257 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
258#endif
259#ifdef CONFIG_ARCH_R8A7794
260 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
261#endif
Geert Uytterhoeven4ff27112020-02-18 12:24:49 +0100262#if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100263 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
264#endif
Geert Uytterhoeven39e57e12019-10-23 14:33:33 +0200265#ifdef CONFIG_ARCH_R8A77960
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100266 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
267#endif
Geert Uytterhoeven9c9f7892019-10-23 14:33:35 +0200268#ifdef CONFIG_ARCH_R8A77961
269 { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w },
270#endif
Jacopo Mondibfd83982018-02-20 16:12:05 +0100271#ifdef CONFIG_ARCH_R8A77965
272 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
273#endif
Sergei Shtylyovbb0030752017-09-12 23:37:17 +0300274#ifdef CONFIG_ARCH_R8A77970
275 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
276#endif
Sergei Shtylyov84477562018-02-02 21:22:14 +0300277#ifdef CONFIG_ARCH_R8A77980
278 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
279#endif
Takeshi Kihara44842d42018-04-11 18:36:23 +0900280#ifdef CONFIG_ARCH_R8A77990
281 { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
282#endif
Geert Uytterhoeven1b954782017-07-20 14:34:51 +0200283#ifdef CONFIG_ARCH_R8A77995
284 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
285#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100286#ifdef CONFIG_ARCH_SH73A0
287 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
288#endif
289 { /* sentinel */ }
290};
291
292static int __init renesas_soc_init(void)
293{
294 struct soc_device_attribute *soc_dev_attr;
295 const struct renesas_family *family;
296 const struct of_device_id *match;
297 const struct renesas_soc *soc;
298 void __iomem *chipid = NULL;
299 struct soc_device *soc_dev;
300 struct device_node *np;
Chris Brandt175f4352018-07-27 11:53:32 -0500301 unsigned int product, eshi = 0, eslo;
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100302
303 match = of_match_node(renesas_socs, of_root);
304 if (!match)
305 return -ENODEV;
306
307 soc = match->data;
308 family = soc->family;
309
Chris Brandt175f4352018-07-27 11:53:32 -0500310 np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
311 if (np) {
312 chipid = of_iomap(np, 0);
313 of_node_put(np);
314
315 if (chipid) {
316 product = readl(chipid);
317 iounmap(chipid);
318
319 if (soc->id && ((product >> 16) & 0xff) != soc->id) {
320 pr_warn("SoC mismatch (product = 0x%x)\n",
321 product);
322 return -ENODEV;
323 }
324 }
325
326 /*
327 * TODO: Upper 4 bits of BSID are for chip version, but the
328 * format is not known at this time so we don't know how to
329 * specify eshi and eslo
330 */
331
332 goto done;
333 }
334
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100335 /* Try PRR first, then hardcoded fallback */
336 np = of_find_compatible_node(NULL, NULL, "renesas,prr");
337 if (np) {
338 chipid = of_iomap(np, 0);
339 of_node_put(np);
Geert Uytterhoeven4194b582019-10-16 16:33:06 +0200340 } else if (soc->id && family->reg) {
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100341 chipid = ioremap(family->reg, 4);
342 }
343 if (chipid) {
344 product = readl(chipid);
345 iounmap(chipid);
Geert Uytterhoeven90f0d2b2017-10-30 18:29:58 +0100346 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
347 if ((product & 0x7fff) == 0x5210)
348 product ^= 0x11;
Takeshi Kihara15160f62019-02-28 12:00:48 +0100349 /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
350 if ((product & 0x7fff) == 0x5211)
351 product ^= 0x12;
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100352 if (soc->id && ((product >> 8) & 0xff) != soc->id) {
353 pr_warn("SoC mismatch (product = 0x%x)\n", product);
354 return -ENODEV;
355 }
Chris Brandt175f4352018-07-27 11:53:32 -0500356 eshi = ((product >> 4) & 0x0f) + 1;
357 eslo = product & 0xf;
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100358 }
359
Chris Brandt175f4352018-07-27 11:53:32 -0500360done:
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100361 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
362 if (!soc_dev_attr)
363 return -ENOMEM;
364
365 np = of_find_node_by_path("/");
366 of_property_read_string(np, "model", &soc_dev_attr->machine);
367 of_node_put(np);
368
369 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
370 soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
371 GFP_KERNEL);
Chris Brandt175f4352018-07-27 11:53:32 -0500372 if (eshi)
373 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
374 eslo);
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100375
376 pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
377 soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
378
379 soc_dev = soc_device_register(soc_dev_attr);
380 if (IS_ERR(soc_dev)) {
381 kfree(soc_dev_attr->revision);
382 kfree_const(soc_dev_attr->soc_id);
383 kfree_const(soc_dev_attr->family);
384 kfree(soc_dev_attr);
385 return PTR_ERR(soc_dev);
386 }
387
388 return 0;
389}
Geert Uytterhoevenb1d134b2017-03-31 11:01:54 +0200390early_initcall(renesas_soc_init);