Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Renesas SoC Identification
  4 *
  5 * Copyright (C) 2014-2016 Glider bvba
 
 
 
 
 
 
 
 
 
  6 */
  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_rcar_gen4 __initconst __maybe_unused = {
 37	.name	= "R-Car Gen4",
 38};
 39
 40static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
 41	.name	= "R-Mobile",
 42	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
 43};
 44
 45static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
 46	.name	= "RZ/A1",
 47};
 48
 49static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
 50	.name	= "RZ/A2",
 51};
 52
 53static const struct renesas_family fam_rzfive __initconst __maybe_unused = {
 54	.name	= "RZ/Five",
 55};
 56
 57static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
 58	.name	= "RZ/G1",
 59	.reg	= 0xff000044,		/* PRR (Product Register) */
 60};
 61
 62static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
 63	.name	= "RZ/G2",
 64	.reg	= 0xfff00044,		/* PRR (Product Register) */
 65};
 66
 67static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
 68	.name	= "RZ/G2L",
 69};
 70
 71static const struct renesas_family fam_rzg2ul __initconst __maybe_unused = {
 72	.name	= "RZ/G2UL",
 73};
 74
 75static const struct renesas_family fam_rzv2l __initconst __maybe_unused = {
 76	.name	= "RZ/V2L",
 77};
 78
 79static const struct renesas_family fam_rzv2m __initconst __maybe_unused = {
 80	.name	= "RZ/V2M",
 81};
 82
 83static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
 84	.name	= "SH-Mobile",
 85	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
 86};
 87
 88
 89struct renesas_soc {
 90	const struct renesas_family *family;
 91	u32 id;
 92};
 93
 94static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
 95	.family	= &fam_rza1,
 96};
 97
 98static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
 99	.family	= &fam_rza2,
100	.id	= 0x3b,
101};
102
103static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
104	.family	= &fam_rmobile,
105	.id	= 0x3f,
106};
107
108static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
109	.family	= &fam_rmobile,
110	.id	= 0x40,
111};
112
113static const struct renesas_soc soc_rz_five __initconst __maybe_unused = {
114	.family = &fam_rzfive,
115	.id     = 0x847c447,
116};
117
118static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
119	.family	= &fam_rzg1,
120	.id	= 0x45,
121};
122
123static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
124	.family	= &fam_rzg1,
125	.id	= 0x47,
126};
127
128static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
129	.family	= &fam_rzg1,
130	.id	= 0x4b,
131};
132
133static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
134	.family	= &fam_rzg1,
135	.id	= 0x4c,
136};
137
138static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
139	.family	= &fam_rzg1,
140	.id	= 0x53,
141};
142
143static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
144	.family	= &fam_rzg2,
145	.id	= 0x52,
146};
147
148static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
149	.family = &fam_rzg2,
150	.id     = 0x55,
151};
152
153static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
154	.family	= &fam_rzg2,
155	.id	= 0x57,
156};
157
158static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
159	.family	= &fam_rzg2,
160	.id	= 0x4f,
161};
162
163static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
164	.family = &fam_rzg2l,
165	.id     = 0x841c447,
166};
167
168static const struct renesas_soc soc_rz_g2ul __initconst __maybe_unused = {
169	.family = &fam_rzg2ul,
170	.id     = 0x8450447,
171};
172
173static const struct renesas_soc soc_rz_v2l __initconst __maybe_unused = {
174	.family = &fam_rzv2l,
175	.id     = 0x8447447,
176};
177
178static const struct renesas_soc soc_rz_v2m __initconst __maybe_unused = {
179	.family = &fam_rzv2m,
180};
181
182static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
183	.family	= &fam_rcar_gen1,
184};
185
186static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
187	.family	= &fam_rcar_gen1,
188	.id	= 0x3b,
189};
190
191static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
192	.family	= &fam_rcar_gen2,
193	.id	= 0x45,
194};
195
196static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
197	.family	= &fam_rcar_gen2,
198	.id	= 0x47,
199};
200
201static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
202	.family	= &fam_rcar_gen2,
203	.id	= 0x4a,
204};
205
206static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
207	.family	= &fam_rcar_gen2,
208	.id	= 0x4b,
209};
210
211static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
212	.family	= &fam_rcar_gen2,
213	.id	= 0x4c,
214};
215
216static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
217	.family	= &fam_rcar_gen3,
218	.id	= 0x4f,
219};
220
221static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
222	.family	= &fam_rcar_gen3,
223	.id	= 0x52,
224};
225
226static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
227	.family = &fam_rcar_gen3,
228	.id     = 0x55,
229};
230
231static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
232	.family	= &fam_rcar_gen3,
233	.id	= 0x54,
234};
235
236static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
237	.family	= &fam_rcar_gen3,
238	.id	= 0x56,
239};
240
241static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
242	.family	= &fam_rcar_gen3,
243	.id	= 0x57,
244};
245
246static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
247	.family	= &fam_rcar_gen3,
248	.id	= 0x58,
249};
250
251static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
252	.family	= &fam_rcar_gen4,
253	.id	= 0x59,
254};
255
256static const struct renesas_soc soc_rcar_s4 __initconst __maybe_unused = {
257	.family	= &fam_rcar_gen4,
258	.id	= 0x5a,
259};
260
261static const struct renesas_soc soc_rcar_v4h __initconst __maybe_unused = {
262	.family	= &fam_rcar_gen4,
263	.id	= 0x5c,
264};
265
266static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
267	.family	= &fam_shmobile,
268	.id	= 0x37,
269};
270
271
272static const struct of_device_id renesas_socs[] __initconst = {
273#ifdef CONFIG_ARCH_R7S72100
274	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
275#endif
276#ifdef CONFIG_ARCH_R7S9210
277	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
278#endif
279#ifdef CONFIG_ARCH_R8A73A4
280	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
281#endif
282#ifdef CONFIG_ARCH_R8A7740
283	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
284#endif
285#ifdef CONFIG_ARCH_R8A7742
286	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
287#endif
288#ifdef CONFIG_ARCH_R8A7743
289	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
290#endif
291#ifdef CONFIG_ARCH_R8A7744
292	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
293#endif
294#ifdef CONFIG_ARCH_R8A7745
295	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
296#endif
297#ifdef CONFIG_ARCH_R8A77470
298	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
299#endif
300#ifdef CONFIG_ARCH_R8A774A1
301	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
302#endif
303#ifdef CONFIG_ARCH_R8A774B1
304	{ .compatible = "renesas,r8a774b1",	.data = &soc_rz_g2n },
305#endif
306#ifdef CONFIG_ARCH_R8A774C0
307	{ .compatible = "renesas,r8a774c0",	.data = &soc_rz_g2e },
308#endif
309#ifdef CONFIG_ARCH_R8A774E1
310	{ .compatible = "renesas,r8a774e1",	.data = &soc_rz_g2h },
311#endif
312#ifdef CONFIG_ARCH_R8A7778
313	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
314#endif
315#ifdef CONFIG_ARCH_R8A7779
316	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
317#endif
318#ifdef CONFIG_ARCH_R8A7790
319	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
320#endif
321#ifdef CONFIG_ARCH_R8A7791
322	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
323#endif
324#ifdef CONFIG_ARCH_R8A7792
325	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
326#endif
327#ifdef CONFIG_ARCH_R8A7793
328	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
329#endif
330#ifdef CONFIG_ARCH_R8A7794
331	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
332#endif
333#if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
334	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
335#endif
336#ifdef CONFIG_ARCH_R8A77951
337	{ .compatible = "renesas,r8a779m0",	.data = &soc_rcar_h3 },
338	{ .compatible = "renesas,r8a779m1",	.data = &soc_rcar_h3 },
339	{ .compatible = "renesas,r8a779m8",	.data = &soc_rcar_h3 },
340	{ .compatible = "renesas,r8a779mb",	.data = &soc_rcar_h3 },
341#endif
342#ifdef CONFIG_ARCH_R8A77960
343	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
344#endif
345#ifdef CONFIG_ARCH_R8A77961
346	{ .compatible = "renesas,r8a77961",	.data = &soc_rcar_m3_w },
347	{ .compatible = "renesas,r8a779m2",	.data = &soc_rcar_m3_w },
348	{ .compatible = "renesas,r8a779m3",	.data = &soc_rcar_m3_w },
349#endif
350#ifdef CONFIG_ARCH_R8A77965
351	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
352	{ .compatible = "renesas,r8a779m4",	.data = &soc_rcar_m3_n },
353	{ .compatible = "renesas,r8a779m5",	.data = &soc_rcar_m3_n },
354#endif
355#ifdef CONFIG_ARCH_R8A77970
356	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
357#endif
358#ifdef CONFIG_ARCH_R8A77980
359	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
360#endif
361#ifdef CONFIG_ARCH_R8A77990
362	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
363	{ .compatible = "renesas,r8a779m6",	.data = &soc_rcar_e3 },
364#endif
365#ifdef CONFIG_ARCH_R8A77995
366	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
367	{ .compatible = "renesas,r8a779m7",	.data = &soc_rcar_d3 },
368#endif
369#ifdef CONFIG_ARCH_R8A779A0
370	{ .compatible = "renesas,r8a779a0",	.data = &soc_rcar_v3u },
371#endif
372#ifdef CONFIG_ARCH_R8A779F0
373	{ .compatible = "renesas,r8a779f0",	.data = &soc_rcar_s4 },
374#endif
375#ifdef CONFIG_ARCH_R8A779G0
376	{ .compatible = "renesas,r8a779g0",	.data = &soc_rcar_v4h },
377#endif
378#if defined(CONFIG_ARCH_R9A07G043)
379#ifdef CONFIG_RISCV
380	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_five },
381#else
382	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_g2ul },
383#endif
384#endif
385#if defined(CONFIG_ARCH_R9A07G044)
386	{ .compatible = "renesas,r9a07g044",	.data = &soc_rz_g2l },
387#endif
388#if defined(CONFIG_ARCH_R9A07G054)
389	{ .compatible = "renesas,r9a07g054",	.data = &soc_rz_v2l },
390#endif
391#if defined(CONFIG_ARCH_R9A09G011)
392	{ .compatible = "renesas,r9a09g011",	.data = &soc_rz_v2m },
393#endif
394#ifdef CONFIG_ARCH_SH73A0
395	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
396#endif
397	{ /* sentinel */ }
398};
399
400struct renesas_id {
401	unsigned int offset;
402	u32 mask;
403};
404
405static const struct renesas_id id_bsid __initconst = {
406	.offset = 0,
407	.mask = 0xff0000,
408	/*
409	 * TODO: Upper 4 bits of BSID are for chip version, but the format is
410	 * not known at this time so we don't know how to specify eshi and eslo
411	 */
412};
413
414static const struct renesas_id id_rzg2l __initconst = {
415	.offset = 0xa04,
416	.mask = 0xfffffff,
417};
418
419static const struct renesas_id id_rzv2m __initconst = {
420	.offset = 0x104,
421	.mask = 0xff,
422};
423
424static const struct renesas_id id_prr __initconst = {
425	.offset = 0,
426	.mask = 0xff00,
427};
428
429static const struct of_device_id renesas_ids[] __initconst = {
430	{ .compatible = "renesas,bsid",			.data = &id_bsid },
431	{ .compatible = "renesas,r9a07g043-sysc",	.data = &id_rzg2l },
432	{ .compatible = "renesas,r9a07g044-sysc",	.data = &id_rzg2l },
433	{ .compatible = "renesas,r9a07g054-sysc",	.data = &id_rzg2l },
434	{ .compatible = "renesas,r9a09g011-sys",	.data = &id_rzv2m },
435	{ .compatible = "renesas,prr",			.data = &id_prr },
436	{ /* sentinel */ }
437};
438
439static int __init renesas_soc_init(void)
440{
441	struct soc_device_attribute *soc_dev_attr;
442	unsigned int product, eshi = 0, eslo;
443	const struct renesas_family *family;
444	const struct of_device_id *match;
445	const struct renesas_soc *soc;
446	const struct renesas_id *id;
447	void __iomem *chipid = NULL;
448	const char *rev_prefix = "";
449	struct soc_device *soc_dev;
450	struct device_node *np;
451	const char *soc_id;
452	int ret;
453
454	match = of_match_node(renesas_socs, of_root);
455	if (!match)
456		return -ENODEV;
457
458	soc_id = strchr(match->compatible, ',') + 1;
459	soc = match->data;
460	family = soc->family;
461
462	np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
 
463	if (np) {
464		id = match->data;
465		chipid = of_iomap(np, 0);
466		of_node_put(np);
467	} else if (soc->id && family->reg) {
468		/* Try hardcoded CCCR/PRR fallback */
469		id = &id_prr;
470		chipid = ioremap(family->reg, 4);
471	}
 
 
 
 
 
 
 
 
472
473	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
474	if (!soc_dev_attr)
475		return -ENOMEM;
476
477	np = of_find_node_by_path("/");
478	of_property_read_string(np, "model", &soc_dev_attr->machine);
479	of_node_put(np);
480
481	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
482	soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);
 
 
 
 
 
483
484	if (chipid) {
485		product = readl(chipid + id->offset);
486		iounmap(chipid);
487
488		if (id == &id_prr) {
489			/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
490			if ((product & 0x7fff) == 0x5210)
491				product ^= 0x11;
492			/* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
493			if ((product & 0x7fff) == 0x5211)
494				product ^= 0x12;
495
496			eshi = ((product >> 4) & 0x0f) + 1;
497			eslo = product & 0xf;
498			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
499							   eshi, eslo);
500		}  else if (id == &id_rzg2l) {
501			eshi =  ((product >> 28) & 0x0f);
502			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u",
503							   eshi);
504			rev_prefix = "Rev ";
505		} else if (id == &id_rzv2m) {
506			eshi = ((product >> 4) & 0x0f);
507			eslo = product & 0xf;
508			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
509							   eshi, eslo);
510		}
511
512		if (soc->id &&
513		    ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
514			pr_warn("SoC mismatch (product = 0x%x)\n", product);
515			ret = -ENODEV;
516			goto free_soc_dev_attr;
517		}
518	}
519
520	pr_info("Detected Renesas %s %s %s%s\n", soc_dev_attr->family,
521		soc_dev_attr->soc_id, rev_prefix, soc_dev_attr->revision ?: "");
522
523	soc_dev = soc_device_register(soc_dev_attr);
524	if (IS_ERR(soc_dev)) {
525		ret = PTR_ERR(soc_dev);
526		goto free_soc_dev_attr;
 
 
 
527	}
528
529	return 0;
530
531free_soc_dev_attr:
532	kfree(soc_dev_attr->revision);
533	kfree_const(soc_dev_attr->soc_id);
534	kfree_const(soc_dev_attr->family);
535	kfree(soc_dev_attr);
536	return ret;
537}
538early_initcall(renesas_soc_init);
v4.10.11
 
  1/*
  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
 
 
 
 
 
 
 
 
 
 
 83static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
 84	.family	= &fam_rzg,
 85	.id	= 0x47,
 86};
 87
 
 
 
 
 
 88static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
 89	.family	= &fam_rzg,
 90	.id	= 0x4c,
 91};
 92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 93static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
 94	.family	= &fam_rcar_gen1,
 95};
 96
 97static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
 98	.family	= &fam_rcar_gen1,
 99	.id	= 0x3b,
100};
101
102static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
103	.family	= &fam_rcar_gen2,
104	.id	= 0x45,
105};
106
107static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
108	.family	= &fam_rcar_gen2,
109	.id	= 0x47,
110};
111
112static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
113	.family	= &fam_rcar_gen2,
114	.id	= 0x4a,
115};
116
117static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
118	.family	= &fam_rcar_gen2,
119	.id	= 0x4b,
120};
121
122static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
123	.family	= &fam_rcar_gen2,
124	.id	= 0x4c,
125};
126
127static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
128	.family	= &fam_rcar_gen3,
129	.id	= 0x4f,
130};
131
132static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
133	.family	= &fam_rcar_gen3,
134	.id	= 0x52,
135};
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
138	.family	= &fam_shmobile,
139	.id	= 0x37,
140};
141
142
143static const struct of_device_id renesas_socs[] __initconst = {
144#ifdef CONFIG_ARCH_R7S72100
145	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
146#endif
 
 
 
147#ifdef CONFIG_ARCH_R8A73A4
148	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
149#endif
150#ifdef CONFIG_ARCH_R8A7740
151	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
152#endif
 
 
 
153#ifdef CONFIG_ARCH_R8A7743
154	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
155#endif
 
 
 
156#ifdef CONFIG_ARCH_R8A7745
157	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
158#endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159#ifdef CONFIG_ARCH_R8A7778
160	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
161#endif
162#ifdef CONFIG_ARCH_R8A7779
163	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
164#endif
165#ifdef CONFIG_ARCH_R8A7790
166	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
167#endif
168#ifdef CONFIG_ARCH_R8A7791
169	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
170#endif
171#ifdef CONFIG_ARCH_R8A7792
172	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
173#endif
174#ifdef CONFIG_ARCH_R8A7793
175	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
176#endif
177#ifdef CONFIG_ARCH_R8A7794
178	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
179#endif
180#ifdef CONFIG_ARCH_R8A7795
181	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
182#endif
183#ifdef CONFIG_ARCH_R8A7796
 
 
 
 
 
 
184	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
185#endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186#ifdef CONFIG_ARCH_SH73A0
187	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
188#endif
189	{ /* sentinel */ }
190};
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192static int __init renesas_soc_init(void)
193{
194	struct soc_device_attribute *soc_dev_attr;
 
195	const struct renesas_family *family;
196	const struct of_device_id *match;
197	const struct renesas_soc *soc;
 
198	void __iomem *chipid = NULL;
 
199	struct soc_device *soc_dev;
200	struct device_node *np;
201	unsigned int product;
 
202
203	match = of_match_node(renesas_socs, of_root);
204	if (!match)
205		return -ENODEV;
206
 
207	soc = match->data;
208	family = soc->family;
209
210	/* Try PRR first, then hardcoded fallback */
211	np = of_find_compatible_node(NULL, NULL, "renesas,prr");
212	if (np) {
 
213		chipid = of_iomap(np, 0);
214		of_node_put(np);
215	} else if (soc->id) {
 
 
216		chipid = ioremap(family->reg, 4);
217	}
218	if (chipid) {
219		product = readl(chipid);
220		iounmap(chipid);
221		if (soc->id && ((product >> 8) & 0xff) != soc->id) {
222			pr_warn("SoC mismatch (product = 0x%x)\n", product);
223			return -ENODEV;
224		}
225	}
226
227	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
228	if (!soc_dev_attr)
229		return -ENOMEM;
230
231	np = of_find_node_by_path("/");
232	of_property_read_string(np, "model", &soc_dev_attr->machine);
233	of_node_put(np);
234
235	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
236	soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
237					     GFP_KERNEL);
238	if (chipid)
239		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
240						   ((product >> 4) & 0x0f) + 1,
241						   product & 0xf);
242
243	pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
244		soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
246	soc_dev = soc_device_register(soc_dev_attr);
247	if (IS_ERR(soc_dev)) {
248		kfree(soc_dev_attr->revision);
249		kfree_const(soc_dev_attr->soc_id);
250		kfree_const(soc_dev_attr->family);
251		kfree(soc_dev_attr);
252		return PTR_ERR(soc_dev);
253	}
254
255	return 0;
 
 
 
 
 
 
 
256}
257core_initcall(renesas_soc_init);