1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Renesas SoC Identification
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2014-2016 Glider bvba
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <linux/io.h>
9*4882a593Smuzhiyun #include <linux/of.h>
10*4882a593Smuzhiyun #include <linux/of_address.h>
11*4882a593Smuzhiyun #include <linux/slab.h>
12*4882a593Smuzhiyun #include <linux/string.h>
13*4882a593Smuzhiyun #include <linux/sys_soc.h>
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun struct renesas_family {
17*4882a593Smuzhiyun const char name[16];
18*4882a593Smuzhiyun u32 reg; /* CCCR or PRR, if not in DT */
19*4882a593Smuzhiyun };
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
22*4882a593Smuzhiyun .name = "R-Car Gen1",
23*4882a593Smuzhiyun .reg = 0xff000044, /* PRR (Product Register) */
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
27*4882a593Smuzhiyun .name = "R-Car Gen2",
28*4882a593Smuzhiyun .reg = 0xff000044, /* PRR (Product Register) */
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
32*4882a593Smuzhiyun .name = "R-Car Gen3",
33*4882a593Smuzhiyun .reg = 0xfff00044, /* PRR (Product Register) */
34*4882a593Smuzhiyun };
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
37*4882a593Smuzhiyun .name = "R-Mobile",
38*4882a593Smuzhiyun .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
39*4882a593Smuzhiyun };
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
42*4882a593Smuzhiyun .name = "RZ/A1",
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
46*4882a593Smuzhiyun .name = "RZ/A2",
47*4882a593Smuzhiyun };
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
50*4882a593Smuzhiyun .name = "RZ/G1",
51*4882a593Smuzhiyun .reg = 0xff000044, /* PRR (Product Register) */
52*4882a593Smuzhiyun };
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
55*4882a593Smuzhiyun .name = "RZ/G2",
56*4882a593Smuzhiyun .reg = 0xfff00044, /* PRR (Product Register) */
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
60*4882a593Smuzhiyun .name = "SH-Mobile",
61*4882a593Smuzhiyun .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
62*4882a593Smuzhiyun };
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun struct renesas_soc {
66*4882a593Smuzhiyun const struct renesas_family *family;
67*4882a593Smuzhiyun u8 id;
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
71*4882a593Smuzhiyun .family = &fam_rza1,
72*4882a593Smuzhiyun };
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
75*4882a593Smuzhiyun .family = &fam_rza2,
76*4882a593Smuzhiyun .id = 0x3b,
77*4882a593Smuzhiyun };
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
80*4882a593Smuzhiyun .family = &fam_rmobile,
81*4882a593Smuzhiyun .id = 0x3f,
82*4882a593Smuzhiyun };
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
85*4882a593Smuzhiyun .family = &fam_rmobile,
86*4882a593Smuzhiyun .id = 0x40,
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
90*4882a593Smuzhiyun .family = &fam_rzg1,
91*4882a593Smuzhiyun .id = 0x45,
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
95*4882a593Smuzhiyun .family = &fam_rzg1,
96*4882a593Smuzhiyun .id = 0x47,
97*4882a593Smuzhiyun };
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
100*4882a593Smuzhiyun .family = &fam_rzg1,
101*4882a593Smuzhiyun .id = 0x4b,
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
105*4882a593Smuzhiyun .family = &fam_rzg1,
106*4882a593Smuzhiyun .id = 0x4c,
107*4882a593Smuzhiyun };
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
110*4882a593Smuzhiyun .family = &fam_rzg1,
111*4882a593Smuzhiyun .id = 0x53,
112*4882a593Smuzhiyun };
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
115*4882a593Smuzhiyun .family = &fam_rzg2,
116*4882a593Smuzhiyun .id = 0x52,
117*4882a593Smuzhiyun };
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
120*4882a593Smuzhiyun .family = &fam_rzg2,
121*4882a593Smuzhiyun .id = 0x55,
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
125*4882a593Smuzhiyun .family = &fam_rzg2,
126*4882a593Smuzhiyun .id = 0x57,
127*4882a593Smuzhiyun };
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
130*4882a593Smuzhiyun .family = &fam_rzg2,
131*4882a593Smuzhiyun .id = 0x4f,
132*4882a593Smuzhiyun };
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
135*4882a593Smuzhiyun .family = &fam_rcar_gen1,
136*4882a593Smuzhiyun };
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
139*4882a593Smuzhiyun .family = &fam_rcar_gen1,
140*4882a593Smuzhiyun .id = 0x3b,
141*4882a593Smuzhiyun };
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
144*4882a593Smuzhiyun .family = &fam_rcar_gen2,
145*4882a593Smuzhiyun .id = 0x45,
146*4882a593Smuzhiyun };
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
149*4882a593Smuzhiyun .family = &fam_rcar_gen2,
150*4882a593Smuzhiyun .id = 0x47,
151*4882a593Smuzhiyun };
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
154*4882a593Smuzhiyun .family = &fam_rcar_gen2,
155*4882a593Smuzhiyun .id = 0x4a,
156*4882a593Smuzhiyun };
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
159*4882a593Smuzhiyun .family = &fam_rcar_gen2,
160*4882a593Smuzhiyun .id = 0x4b,
161*4882a593Smuzhiyun };
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
164*4882a593Smuzhiyun .family = &fam_rcar_gen2,
165*4882a593Smuzhiyun .id = 0x4c,
166*4882a593Smuzhiyun };
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
169*4882a593Smuzhiyun .family = &fam_rcar_gen3,
170*4882a593Smuzhiyun .id = 0x4f,
171*4882a593Smuzhiyun };
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
174*4882a593Smuzhiyun .family = &fam_rcar_gen3,
175*4882a593Smuzhiyun .id = 0x52,
176*4882a593Smuzhiyun };
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
179*4882a593Smuzhiyun .family = &fam_rcar_gen3,
180*4882a593Smuzhiyun .id = 0x55,
181*4882a593Smuzhiyun };
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
184*4882a593Smuzhiyun .family = &fam_rcar_gen3,
185*4882a593Smuzhiyun .id = 0x54,
186*4882a593Smuzhiyun };
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
189*4882a593Smuzhiyun .family = &fam_rcar_gen3,
190*4882a593Smuzhiyun .id = 0x56,
191*4882a593Smuzhiyun };
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
194*4882a593Smuzhiyun .family = &fam_rcar_gen3,
195*4882a593Smuzhiyun .id = 0x57,
196*4882a593Smuzhiyun };
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
199*4882a593Smuzhiyun .family = &fam_rcar_gen3,
200*4882a593Smuzhiyun .id = 0x58,
201*4882a593Smuzhiyun };
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
204*4882a593Smuzhiyun .family = &fam_rcar_gen3,
205*4882a593Smuzhiyun .id = 0x59,
206*4882a593Smuzhiyun };
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
209*4882a593Smuzhiyun .family = &fam_shmobile,
210*4882a593Smuzhiyun .id = 0x37,
211*4882a593Smuzhiyun };
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun static const struct of_device_id renesas_socs[] __initconst = {
215*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R7S72100
216*4882a593Smuzhiyun { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
217*4882a593Smuzhiyun #endif
218*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R7S9210
219*4882a593Smuzhiyun { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
220*4882a593Smuzhiyun #endif
221*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A73A4
222*4882a593Smuzhiyun { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
223*4882a593Smuzhiyun #endif
224*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7740
225*4882a593Smuzhiyun { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
226*4882a593Smuzhiyun #endif
227*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7742
228*4882a593Smuzhiyun { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
229*4882a593Smuzhiyun #endif
230*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7743
231*4882a593Smuzhiyun { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
232*4882a593Smuzhiyun #endif
233*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7744
234*4882a593Smuzhiyun { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
235*4882a593Smuzhiyun #endif
236*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7745
237*4882a593Smuzhiyun { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
238*4882a593Smuzhiyun #endif
239*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A77470
240*4882a593Smuzhiyun { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
241*4882a593Smuzhiyun #endif
242*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A774A1
243*4882a593Smuzhiyun { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
244*4882a593Smuzhiyun #endif
245*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A774B1
246*4882a593Smuzhiyun { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n },
247*4882a593Smuzhiyun #endif
248*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A774C0
249*4882a593Smuzhiyun { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
250*4882a593Smuzhiyun #endif
251*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A774E1
252*4882a593Smuzhiyun { .compatible = "renesas,r8a774e1", .data = &soc_rz_g2h },
253*4882a593Smuzhiyun #endif
254*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7778
255*4882a593Smuzhiyun { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
256*4882a593Smuzhiyun #endif
257*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7779
258*4882a593Smuzhiyun { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
259*4882a593Smuzhiyun #endif
260*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7790
261*4882a593Smuzhiyun { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
262*4882a593Smuzhiyun #endif
263*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7791
264*4882a593Smuzhiyun { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
265*4882a593Smuzhiyun #endif
266*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7792
267*4882a593Smuzhiyun { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
268*4882a593Smuzhiyun #endif
269*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7793
270*4882a593Smuzhiyun { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
271*4882a593Smuzhiyun #endif
272*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A7794
273*4882a593Smuzhiyun { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
274*4882a593Smuzhiyun #endif
275*4882a593Smuzhiyun #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
276*4882a593Smuzhiyun { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
277*4882a593Smuzhiyun #endif
278*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A77960
279*4882a593Smuzhiyun { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
280*4882a593Smuzhiyun #endif
281*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A77961
282*4882a593Smuzhiyun { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w },
283*4882a593Smuzhiyun #endif
284*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A77965
285*4882a593Smuzhiyun { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
286*4882a593Smuzhiyun #endif
287*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A77970
288*4882a593Smuzhiyun { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
289*4882a593Smuzhiyun #endif
290*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A77980
291*4882a593Smuzhiyun { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
292*4882a593Smuzhiyun #endif
293*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A77990
294*4882a593Smuzhiyun { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
295*4882a593Smuzhiyun #endif
296*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A77995
297*4882a593Smuzhiyun { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
298*4882a593Smuzhiyun #endif
299*4882a593Smuzhiyun #ifdef CONFIG_ARCH_R8A779A0
300*4882a593Smuzhiyun { .compatible = "renesas,r8a779a0", .data = &soc_rcar_v3u },
301*4882a593Smuzhiyun #endif
302*4882a593Smuzhiyun #ifdef CONFIG_ARCH_SH73A0
303*4882a593Smuzhiyun { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
304*4882a593Smuzhiyun #endif
305*4882a593Smuzhiyun { /* sentinel */ }
306*4882a593Smuzhiyun };
307*4882a593Smuzhiyun
renesas_soc_init(void)308*4882a593Smuzhiyun static int __init renesas_soc_init(void)
309*4882a593Smuzhiyun {
310*4882a593Smuzhiyun struct soc_device_attribute *soc_dev_attr;
311*4882a593Smuzhiyun const struct renesas_family *family;
312*4882a593Smuzhiyun const struct of_device_id *match;
313*4882a593Smuzhiyun const struct renesas_soc *soc;
314*4882a593Smuzhiyun void __iomem *chipid = NULL;
315*4882a593Smuzhiyun struct soc_device *soc_dev;
316*4882a593Smuzhiyun struct device_node *np;
317*4882a593Smuzhiyun unsigned int product, eshi = 0, eslo;
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun match = of_match_node(renesas_socs, of_root);
320*4882a593Smuzhiyun if (!match)
321*4882a593Smuzhiyun return -ENODEV;
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun soc = match->data;
324*4882a593Smuzhiyun family = soc->family;
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
327*4882a593Smuzhiyun if (np) {
328*4882a593Smuzhiyun chipid = of_iomap(np, 0);
329*4882a593Smuzhiyun of_node_put(np);
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun if (chipid) {
332*4882a593Smuzhiyun product = readl(chipid);
333*4882a593Smuzhiyun iounmap(chipid);
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun if (soc->id && ((product >> 16) & 0xff) != soc->id) {
336*4882a593Smuzhiyun pr_warn("SoC mismatch (product = 0x%x)\n",
337*4882a593Smuzhiyun product);
338*4882a593Smuzhiyun return -ENODEV;
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun /*
343*4882a593Smuzhiyun * TODO: Upper 4 bits of BSID are for chip version, but the
344*4882a593Smuzhiyun * format is not known at this time so we don't know how to
345*4882a593Smuzhiyun * specify eshi and eslo
346*4882a593Smuzhiyun */
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun goto done;
349*4882a593Smuzhiyun }
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun /* Try PRR first, then hardcoded fallback */
352*4882a593Smuzhiyun np = of_find_compatible_node(NULL, NULL, "renesas,prr");
353*4882a593Smuzhiyun if (np) {
354*4882a593Smuzhiyun chipid = of_iomap(np, 0);
355*4882a593Smuzhiyun of_node_put(np);
356*4882a593Smuzhiyun } else if (soc->id && family->reg) {
357*4882a593Smuzhiyun chipid = ioremap(family->reg, 4);
358*4882a593Smuzhiyun }
359*4882a593Smuzhiyun if (chipid) {
360*4882a593Smuzhiyun product = readl(chipid);
361*4882a593Smuzhiyun iounmap(chipid);
362*4882a593Smuzhiyun /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
363*4882a593Smuzhiyun if ((product & 0x7fff) == 0x5210)
364*4882a593Smuzhiyun product ^= 0x11;
365*4882a593Smuzhiyun /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
366*4882a593Smuzhiyun if ((product & 0x7fff) == 0x5211)
367*4882a593Smuzhiyun product ^= 0x12;
368*4882a593Smuzhiyun if (soc->id && ((product >> 8) & 0xff) != soc->id) {
369*4882a593Smuzhiyun pr_warn("SoC mismatch (product = 0x%x)\n", product);
370*4882a593Smuzhiyun return -ENODEV;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun eshi = ((product >> 4) & 0x0f) + 1;
373*4882a593Smuzhiyun eslo = product & 0xf;
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun done:
377*4882a593Smuzhiyun soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
378*4882a593Smuzhiyun if (!soc_dev_attr)
379*4882a593Smuzhiyun return -ENOMEM;
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun np = of_find_node_by_path("/");
382*4882a593Smuzhiyun of_property_read_string(np, "model", &soc_dev_attr->machine);
383*4882a593Smuzhiyun of_node_put(np);
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
386*4882a593Smuzhiyun soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
387*4882a593Smuzhiyun GFP_KERNEL);
388*4882a593Smuzhiyun if (eshi)
389*4882a593Smuzhiyun soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
390*4882a593Smuzhiyun eslo);
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
393*4882a593Smuzhiyun soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun soc_dev = soc_device_register(soc_dev_attr);
396*4882a593Smuzhiyun if (IS_ERR(soc_dev)) {
397*4882a593Smuzhiyun kfree(soc_dev_attr->revision);
398*4882a593Smuzhiyun kfree_const(soc_dev_attr->soc_id);
399*4882a593Smuzhiyun kfree_const(soc_dev_attr->family);
400*4882a593Smuzhiyun kfree(soc_dev_attr);
401*4882a593Smuzhiyun return PTR_ERR(soc_dev);
402*4882a593Smuzhiyun }
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun return 0;
405*4882a593Smuzhiyun }
406*4882a593Smuzhiyun early_initcall(renesas_soc_init);
407