blob: ea71c413c9267d94adabe1f3465c0c4cee53b089 [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
103static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
104 .family = &fam_rcar_gen1,
105};
106
107static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
108 .family = &fam_rcar_gen1,
109 .id = 0x3b,
110};
111
112static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
113 .family = &fam_rcar_gen2,
114 .id = 0x45,
115};
116
117static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
118 .family = &fam_rcar_gen2,
119 .id = 0x47,
120};
121
122static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
123 .family = &fam_rcar_gen2,
124 .id = 0x4a,
125};
126
127static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
128 .family = &fam_rcar_gen2,
129 .id = 0x4b,
130};
131
132static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
133 .family = &fam_rcar_gen2,
134 .id = 0x4c,
135};
136
137static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
138 .family = &fam_rcar_gen3,
139 .id = 0x4f,
140};
141
142static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
143 .family = &fam_rcar_gen3,
144 .id = 0x52,
145};
146
Jacopo Mondibfd83982018-02-20 16:12:05 +0100147static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
148 .family = &fam_rcar_gen3,
149 .id = 0x55,
150};
151
Sergei Shtylyovbb0030752017-09-12 23:37:17 +0300152static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
153 .family = &fam_rcar_gen3,
154 .id = 0x54,
155};
156
Sergei Shtylyov84477562018-02-02 21:22:14 +0300157static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
158 .family = &fam_rcar_gen3,
159 .id = 0x56,
160};
161
Geert Uytterhoeven1b954782017-07-20 14:34:51 +0200162static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
163 .family = &fam_rcar_gen3,
164 .id = 0x58,
165};
166
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100167static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
168 .family = &fam_shmobile,
169 .id = 0x37,
170};
171
172
173static const struct of_device_id renesas_socs[] __initconst = {
174#ifdef CONFIG_ARCH_R7S72100
175 { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
176#endif
177#ifdef CONFIG_ARCH_R8A73A4
178 { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
179#endif
180#ifdef CONFIG_ARCH_R8A7740
181 { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
182#endif
Geert Uytterhoeven8848e1b2017-03-10 14:48:29 +0100183#ifdef CONFIG_ARCH_R8A7742
184 { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
185#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100186#ifdef CONFIG_ARCH_R8A7743
187 { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
188#endif
Geert Uytterhoevencd59de82017-03-10 14:48:30 +0100189#ifdef CONFIG_ARCH_R8A7744
190 { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
191#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100192#ifdef CONFIG_ARCH_R8A7745
193 { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
194#endif
195#ifdef CONFIG_ARCH_R8A7778
196 { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
197#endif
198#ifdef CONFIG_ARCH_R8A7779
199 { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
200#endif
201#ifdef CONFIG_ARCH_R8A7790
202 { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
203#endif
204#ifdef CONFIG_ARCH_R8A7791
205 { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
206#endif
207#ifdef CONFIG_ARCH_R8A7792
208 { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
209#endif
210#ifdef CONFIG_ARCH_R8A7793
211 { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
212#endif
213#ifdef CONFIG_ARCH_R8A7794
214 { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
215#endif
216#ifdef CONFIG_ARCH_R8A7795
217 { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
218#endif
219#ifdef CONFIG_ARCH_R8A7796
220 { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
221#endif
Jacopo Mondibfd83982018-02-20 16:12:05 +0100222#ifdef CONFIG_ARCH_R8A77965
223 { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
224#endif
Sergei Shtylyovbb0030752017-09-12 23:37:17 +0300225#ifdef CONFIG_ARCH_R8A77970
226 { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
227#endif
Sergei Shtylyov84477562018-02-02 21:22:14 +0300228#ifdef CONFIG_ARCH_R8A77980
229 { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
230#endif
Geert Uytterhoeven1b954782017-07-20 14:34:51 +0200231#ifdef CONFIG_ARCH_R8A77995
232 { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
233#endif
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100234#ifdef CONFIG_ARCH_SH73A0
235 { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
236#endif
237 { /* sentinel */ }
238};
239
240static int __init renesas_soc_init(void)
241{
242 struct soc_device_attribute *soc_dev_attr;
243 const struct renesas_family *family;
244 const struct of_device_id *match;
245 const struct renesas_soc *soc;
246 void __iomem *chipid = NULL;
247 struct soc_device *soc_dev;
248 struct device_node *np;
249 unsigned int product;
250
251 match = of_match_node(renesas_socs, of_root);
252 if (!match)
253 return -ENODEV;
254
255 soc = match->data;
256 family = soc->family;
257
258 /* Try PRR first, then hardcoded fallback */
259 np = of_find_compatible_node(NULL, NULL, "renesas,prr");
260 if (np) {
261 chipid = of_iomap(np, 0);
262 of_node_put(np);
263 } else if (soc->id) {
264 chipid = ioremap(family->reg, 4);
265 }
266 if (chipid) {
267 product = readl(chipid);
268 iounmap(chipid);
Geert Uytterhoeven90f0d2b2017-10-30 18:29:58 +0100269 /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
270 if ((product & 0x7fff) == 0x5210)
271 product ^= 0x11;
Geert Uytterhoeven8d6799a2016-11-14 19:37:08 +0100272 if (soc->id && ((product >> 8) & 0xff) != soc->id) {
273 pr_warn("SoC mismatch (product = 0x%x)\n", product);
274 return -ENODEV;
275 }
276 }
277
278 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
279 if (!soc_dev_attr)
280 return -ENOMEM;
281
282 np = of_find_node_by_path("/");
283 of_property_read_string(np, "model", &soc_dev_attr->machine);
284 of_node_put(np);
285
286 soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
287 soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
288 GFP_KERNEL);
289 if (chipid)
290 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
291 ((product >> 4) & 0x0f) + 1,
292 product & 0xf);
293
294 pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
295 soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
296
297 soc_dev = soc_device_register(soc_dev_attr);
298 if (IS_ERR(soc_dev)) {
299 kfree(soc_dev_attr->revision);
300 kfree_const(soc_dev_attr->soc_id);
301 kfree_const(soc_dev_attr->family);
302 kfree(soc_dev_attr);
303 return PTR_ERR(soc_dev);
304 }
305
306 return 0;
307}
Geert Uytterhoevenb1d134b2017-03-31 11:01:54 +0200308early_initcall(renesas_soc_init);