blob: 3912a71bd417ff341696a759a5c4a186fb168286 [file] [log] [blame]
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +01001/*
2 * Renesas SoC Identification
3 *
4 * Copyright (C) 2014-2016 Glider bvba
5 *
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.
9 *
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.
14 */
15
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>
22
23
24struct renesas_family {
25 const char name[16];
26 u32 reg; /* CCCR or PRR, if not in DT */
27};
28
29static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
30 .name = "R-Car Gen1",
31 .reg = 0xff000044, /* PRR (Product Register) */
32};
33
34static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
35 .name = "R-Car Gen2",
36 .reg = 0xff000044, /* PRR (Product Register) */
37};
38
39static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
40 .name = "R-Car Gen3",
41 .reg = 0xfff00044, /* PRR (Product Register) */
42};
43
44static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
45 .name = "R-Mobile",
46 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
47};
48
49static const struct renesas_family fam_rza __initconst __maybe_unused = {
50 .name = "RZ/A",
51};
52
53static const struct renesas_family fam_rzg __initconst __maybe_unused = {
54 .name = "RZ/G",
55 .reg = 0xff000044, /* PRR (Product Register) */
56};
57
58static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
59 .name = "SH-Mobile",
60 .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
61};
62
63
64struct renesas_soc {
65 const struct renesas_family *family;
66 u8 id;
67};
68
69static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
70 .family = &fam_rza,
71};
72
73static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
74 .family = &fam_rmobile,
75 .id = 0x3f,
76};
77
78static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
79 .family = &fam_rmobile,
80 .id = 0x40,
81};
82
Geert Uytterhoeven8848e1b2017-03-10 14:48:29 +010083static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
84 .family = &fam_rzg,
85 .id = 0x45,
86};
87
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +010088static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
89 .family = &fam_rzg,
90 .id = 0x47,
91};
92
Geert Uytterhoevencd59de82017-03-10 14:48:30 +010093static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
94 .family = &fam_rzg,
95 .id = 0x4b,
96};
97
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +010098static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
99 .family = &fam_rzg,
100 .id = 0x4c,
101};
102
Biju Das1daf13b2018-03-27 15:37:13 +0100103static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
104 .family = &fam_rzg,
105 .id = 0x53,
106};
107
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100108static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
109 .family = &fam_rcar_gen1,
110};
111
112static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
113 .family = &fam_rcar_gen1,
114 .id = 0x3b,
115};
116
117static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
118 .family = &fam_rcar_gen2,
119 .id = 0x45,
120};
121
122static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
123 .family = &fam_rcar_gen2,
124 .id = 0x47,
125};
126
127static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
128 .family = &fam_rcar_gen2,
129 .id = 0x4a,
130};
131
132static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
133 .family = &fam_rcar_gen2,
134 .id = 0x4b,
135};
136
137static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
138 .family = &fam_rcar_gen2,
139 .id = 0x4c,
140};
141
142static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
143 .family = &fam_rcar_gen3,
144 .id = 0x4f,
145};
146
147static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
148 .family = &fam_rcar_gen3,
149 .id = 0x52,
150};
151
Jacopo Mondibfd83982018-02-20 16:12:05 +0100152static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
153 .family = &fam_rcar_gen3,
154 .id = 0x55,
155};
156
Sergei Shtylyovbb0030752017-09-12 23:37:17 +0300157static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
158 .family = &fam_rcar_gen3,
159 .id = 0x54,
160};
161
Sergei Shtylyov84477562018-02-02 21:22:14 +0300162static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
163 .family = &fam_rcar_gen3,
164 .id = 0x56,
165};
166
Geert Uytterhoeven1b954782017-07-20 14:34:51 +0200167static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
168 .family = &fam_rcar_gen3,
169 .id = 0x58,
170};
171
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100172static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
173 .family = &fam_shmobile,
174 .id = 0x37,
175};
176
177
178static const struct of_device_id renesas_socs[] __initconst = {
179#ifdef CONFIG_ARCH_R7S72100
180 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
181#endif
182#ifdef CONFIG_ARCH_R8A73A4
183 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
184#endif
185#ifdef CONFIG_ARCH_R8A7740
186 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
187#endif
Geert Uytterhoeven8848e1b2017-03-10 14:48:29 +0100188#ifdef CONFIG_ARCH_R8A7742
189 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
190#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100191#ifdef CONFIG_ARCH_R8A7743
192 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
193#endif
Geert Uytterhoevencd59de82017-03-10 14:48:30 +0100194#ifdef CONFIG_ARCH_R8A7744
195 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
196#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100197#ifdef CONFIG_ARCH_R8A7745
198 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
199#endif
Biju Das1daf13b2018-03-27 15:37:13 +0100200#ifdef CONFIG_ARCH_R8A77470
201 { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
202#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100203#ifdef CONFIG_ARCH_R8A7778
204 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
205#endif
206#ifdef CONFIG_ARCH_R8A7779
207 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
208#endif
209#ifdef CONFIG_ARCH_R8A7790
210 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
211#endif
212#ifdef CONFIG_ARCH_R8A7791
213 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
214#endif
215#ifdef CONFIG_ARCH_R8A7792
216 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
217#endif
218#ifdef CONFIG_ARCH_R8A7793
219 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
220#endif
221#ifdef CONFIG_ARCH_R8A7794
222 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
223#endif
224#ifdef CONFIG_ARCH_R8A7795
225 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
226#endif
227#ifdef CONFIG_ARCH_R8A7796
228 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
229#endif
Jacopo Mondibfd83982018-02-20 16:12:05 +0100230#ifdef CONFIG_ARCH_R8A77965
231 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
232#endif
Sergei Shtylyovbb0030752017-09-12 23:37:17 +0300233#ifdef CONFIG_ARCH_R8A77970
234 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
235#endif
Sergei Shtylyov84477562018-02-02 21:22:14 +0300236#ifdef CONFIG_ARCH_R8A77980
237 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
238#endif
Geert Uytterhoeven1b954782017-07-20 14:34:51 +0200239#ifdef CONFIG_ARCH_R8A77995
240 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
241#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100242#ifdef CONFIG_ARCH_SH73A0
243 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
244#endif
245 { /* sentinel */ }
246};
247
248static int __init renesas_soc_init(void)
249{
250 struct soc_device_attribute *soc_dev_attr;
251 const struct renesas_family *family;
252 const struct of_device_id *match;
253 const struct renesas_soc *soc;
254 void __iomem *chipid = NULL;
255 struct soc_device *soc_dev;
256 struct device_node *np;
257 unsigned int product;
258
259 match = of_match_node(renesas_socs, of_root);
260 if (!match)
261 return -ENODEV;
262
263 soc = match->data;
264 family = soc->family;
265
266 /* Try PRR first, then hardcoded fallback */
267 np = of_find_compatible_node(NULL, NULL, "renesas,prr");
268 if (np) {
269 chipid = of_iomap(np, 0);
270 of_node_put(np);
271 } else if (soc->id) {
272 chipid = ioremap(family->reg, 4);
273 }
274 if (chipid) {
275 product = readl(chipid);
276 iounmap(chipid);
Geert Uytterhoeven90f0d2b2017-10-30 18:29:58 +0100277 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
278 if ((product & 0x7fff) == 0x5210)
279 product ^= 0x11;
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100280 if (soc->id && ((product >> 8) & 0xff) != soc->id) {
281 pr_warn("SoC mismatch (product = 0x%x)\n", product);
282 return -ENODEV;
283 }
284 }
285
286 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
287 if (!soc_dev_attr)
288 return -ENOMEM;
289
290 np = of_find_node_by_path("/");
291 of_property_read_string(np, "model", &soc_dev_attr->machine);
292 of_node_put(np);
293
294 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
295 soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
296 GFP_KERNEL);
297 if (chipid)
298 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
299 ((product >> 4) & 0x0f) + 1,
300 product & 0xf);
301
302 pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
303 soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
304
305 soc_dev = soc_device_register(soc_dev_attr);
306 if (IS_ERR(soc_dev)) {
307 kfree(soc_dev_attr->revision);
308 kfree_const(soc_dev_attr->soc_id);
309 kfree_const(soc_dev_attr->family);
310 kfree(soc_dev_attr);
311 return PTR_ERR(soc_dev);
312 }
313
314 return 0;
315}
Geert Uytterhoevenb1d134b2017-03-31 11:01:54 +0200316early_initcall(renesas_soc_init);