aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/soc/renesas/renesas-soc.c
blob: 27eae1a354ab23296fea4a873d72b038c323b290 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
// SPDX-License-Identifier: GPL-2.0
/*
 * Renesas SoC Identification
 *
 * Copyright (C) 2014-2016 Glider bvba
 */

#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/sys_soc.h>

struct renesas_family {
	const char name[16];
	u32 reg;			/* CCCR or PRR, if not in DT */
};

static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
	.name	= "R-Car Gen1",
	.reg	= 0xff000044,		/* PRR (Product Register) */
};

static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
	.name	= "R-Car Gen2",
	.reg	= 0xff000044,		/* PRR (Product Register) */
};

static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
	.name	= "R-Car Gen3",
	.reg	= 0xfff00044,		/* PRR (Product Register) */
};

static const struct renesas_family fam_rcar_gen4 __initconst __maybe_unused = {
	.name	= "R-Car Gen4",
};

static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
	.name	= "R-Mobile",
	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
};

static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
	.name	= "RZ/A1",
};

static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
	.name	= "RZ/A2",
};

static const struct renesas_family fam_rzfive __initconst __maybe_unused = {
	.name	= "RZ/Five",
};

static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
	.name	= "RZ/G1",
	.reg	= 0xff000044,		/* PRR (Product Register) */
};

static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
	.name	= "RZ/G2",
	.reg	= 0xfff00044,		/* PRR (Product Register) */
};

static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
	.name	= "RZ/G2L",
};

static const struct renesas_family fam_rzg2ul __initconst __maybe_unused = {
	.name	= "RZ/G2UL",
};

static const struct renesas_family fam_rzg3s __initconst __maybe_unused = {
	.name	= "RZ/G3S",
};

static const struct renesas_family fam_rzv2l __initconst __maybe_unused = {
	.name	= "RZ/V2L",
};

static const struct renesas_family fam_rzv2m __initconst __maybe_unused = {
	.name	= "RZ/V2M",
};

static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
	.name	= "SH-Mobile",
	.reg	= 0xe600101c,		/* CCCR (Common Chip Code Register) */
};

struct renesas_soc {
	const struct renesas_family *family;
	u32 id;
};

static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
	.family	= &fam_rza1,
};

static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
	.family	= &fam_rza2,
	.id	= 0x3b,
};

static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
	.family	= &fam_rmobile,
	.id	= 0x3f,
};

static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
	.family	= &fam_rmobile,
	.id	= 0x40,
};

static const struct renesas_soc soc_rz_five __initconst __maybe_unused = {
	.family = &fam_rzfive,
	.id     = 0x847c447,
};

static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
	.family	= &fam_rzg1,
	.id	= 0x45,
};

static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
	.family	= &fam_rzg1,
	.id	= 0x47,
};

static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
	.family	= &fam_rzg1,
	.id	= 0x4b,
};

static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
	.family	= &fam_rzg1,
	.id	= 0x4c,
};

static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
	.family	= &fam_rzg1,
	.id	= 0x53,
};

static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
	.family	= &fam_rzg2,
	.id	= 0x52,
};

static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
	.family = &fam_rzg2,
	.id     = 0x55,
};

static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
	.family	= &fam_rzg2,
	.id	= 0x57,
};

static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
	.family	= &fam_rzg2,
	.id	= 0x4f,
};

static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
	.family = &fam_rzg2l,
	.id     = 0x841c447,
};

static const struct renesas_soc soc_rz_g2ul __initconst __maybe_unused = {
	.family = &fam_rzg2ul,
	.id     = 0x8450447,
};

static const struct renesas_soc soc_rz_g3s __initconst __maybe_unused = {
	.family = &fam_rzg3s,
	.id	= 0x85e0447,
};

static const struct renesas_soc soc_rz_v2l __initconst __maybe_unused = {
	.family = &fam_rzv2l,
	.id     = 0x8447447,
};

static const struct renesas_soc soc_rz_v2m __initconst __maybe_unused = {
	.family = &fam_rzv2m,
};

static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
	.family	= &fam_rcar_gen1,
};

static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
	.family	= &fam_rcar_gen1,
	.id	= 0x3b,
};

static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
	.family	= &fam_rcar_gen2,
	.id	= 0x45,
};

static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
	.family	= &fam_rcar_gen2,
	.id	= 0x47,
};

static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
	.family	= &fam_rcar_gen2,
	.id	= 0x4a,
};

static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
	.family	= &fam_rcar_gen2,
	.id	= 0x4b,
};

static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
	.family	= &fam_rcar_gen2,
	.id	= 0x4c,
};

static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
	.family	= &fam_rcar_gen3,
	.id	= 0x4f,
};

static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
	.family	= &fam_rcar_gen3,
	.id	= 0x52,
};

static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
	.family = &fam_rcar_gen3,
	.id     = 0x55,
};

static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
	.family	= &fam_rcar_gen3,
	.id	= 0x54,
};

static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
	.family	= &fam_rcar_gen3,
	.id	= 0x56,
};

static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
	.family	= &fam_rcar_gen3,
	.id	= 0x57,
};

static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
	.family	= &fam_rcar_gen3,
	.id	= 0x58,
};

static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
	.family	= &fam_rcar_gen4,
	.id	= 0x59,
};

static const struct renesas_soc soc_rcar_s4 __initconst __maybe_unused = {
	.family	= &fam_rcar_gen4,
	.id	= 0x5a,
};

static const struct renesas_soc soc_rcar_v4h __initconst __maybe_unused = {
	.family	= &fam_rcar_gen4,
	.id	= 0x5c,
};

static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
	.family	= &fam_shmobile,
	.id	= 0x37,
};


static const struct of_device_id renesas_socs[] __initconst __maybe_unused = {
#ifdef CONFIG_ARCH_R7S72100
	{ .compatible = "renesas,r7s72100",	.data = &soc_rz_a1h },
#endif
#ifdef CONFIG_ARCH_R7S9210
	{ .compatible = "renesas,r7s9210",	.data = &soc_rz_a2m },
#endif
#ifdef CONFIG_ARCH_R8A73A4
	{ .compatible = "renesas,r8a73a4",	.data = &soc_rmobile_ape6 },
#endif
#ifdef CONFIG_ARCH_R8A7740
	{ .compatible = "renesas,r8a7740",	.data = &soc_rmobile_a1 },
#endif
#ifdef CONFIG_ARCH_R8A7742
	{ .compatible = "renesas,r8a7742",	.data = &soc_rz_g1h },
#endif
#ifdef CONFIG_ARCH_R8A7743
	{ .compatible = "renesas,r8a7743",	.data = &soc_rz_g1m },
#endif
#ifdef CONFIG_ARCH_R8A7744
	{ .compatible = "renesas,r8a7744",	.data = &soc_rz_g1n },
#endif
#ifdef CONFIG_ARCH_R8A7745
	{ .compatible = "renesas,r8a7745",	.data = &soc_rz_g1e },
#endif
#ifdef CONFIG_ARCH_R8A77470
	{ .compatible = "renesas,r8a77470",	.data = &soc_rz_g1c },
#endif
#ifdef CONFIG_ARCH_R8A774A1
	{ .compatible = "renesas,r8a774a1",	.data = &soc_rz_g2m },
#endif
#ifdef CONFIG_ARCH_R8A774B1
	{ .compatible = "renesas,r8a774b1",	.data = &soc_rz_g2n },
#endif
#ifdef CONFIG_ARCH_R8A774C0
	{ .compatible = "renesas,r8a774c0",	.data = &soc_rz_g2e },
#endif
#ifdef CONFIG_ARCH_R8A774E1
	{ .compatible = "renesas,r8a774e1",	.data = &soc_rz_g2h },
#endif
#ifdef CONFIG_ARCH_R8A7778
	{ .compatible = "renesas,r8a7778",	.data = &soc_rcar_m1a },
#endif
#ifdef CONFIG_ARCH_R8A7779
	{ .compatible = "renesas,r8a7779",	.data = &soc_rcar_h1 },
#endif
#ifdef CONFIG_ARCH_R8A7790
	{ .compatible = "renesas,r8a7790",	.data = &soc_rcar_h2 },
#endif
#ifdef CONFIG_ARCH_R8A7791
	{ .compatible = "renesas,r8a7791",	.data = &soc_rcar_m2_w },
#endif
#ifdef CONFIG_ARCH_R8A7792
	{ .compatible = "renesas,r8a7792",	.data = &soc_rcar_v2h },
#endif
#ifdef CONFIG_ARCH_R8A7793
	{ .compatible = "renesas,r8a7793",	.data = &soc_rcar_m2_n },
#endif
#ifdef CONFIG_ARCH_R8A7794
	{ .compatible = "renesas,r8a7794",	.data = &soc_rcar_e2 },
#endif
#ifdef CONFIG_ARCH_R8A77951
	{ .compatible = "renesas,r8a7795",	.data = &soc_rcar_h3 },
	{ .compatible = "renesas,r8a779m0",	.data = &soc_rcar_h3 },
	{ .compatible = "renesas,r8a779m1",	.data = &soc_rcar_h3 },
	{ .compatible = "renesas,r8a779m8",	.data = &soc_rcar_h3 },
	{ .compatible = "renesas,r8a779mb",	.data = &soc_rcar_h3 },
#endif
#ifdef CONFIG_ARCH_R8A77960
	{ .compatible = "renesas,r8a7796",	.data = &soc_rcar_m3_w },
#endif
#ifdef CONFIG_ARCH_R8A77961
	{ .compatible = "renesas,r8a77961",	.data = &soc_rcar_m3_w },
	{ .compatible = "renesas,r8a779m2",	.data = &soc_rcar_m3_w },
	{ .compatible = "renesas,r8a779m3",	.data = &soc_rcar_m3_w },
#endif
#ifdef CONFIG_ARCH_R8A77965
	{ .compatible = "renesas,r8a77965",	.data = &soc_rcar_m3_n },
	{ .compatible = "renesas,r8a779m4",	.data = &soc_rcar_m3_n },
	{ .compatible = "renesas,r8a779m5",	.data = &soc_rcar_m3_n },
#endif
#ifdef CONFIG_ARCH_R8A77970
	{ .compatible = "renesas,r8a77970",	.data = &soc_rcar_v3m },
#endif
#ifdef CONFIG_ARCH_R8A77980
	{ .compatible = "renesas,r8a77980",	.data = &soc_rcar_v3h },
#endif
#ifdef CONFIG_ARCH_R8A77990
	{ .compatible = "renesas,r8a77990",	.data = &soc_rcar_e3 },
	{ .compatible = "renesas,r8a779m6",	.data = &soc_rcar_e3 },
#endif
#ifdef CONFIG_ARCH_R8A77995
	{ .compatible = "renesas,r8a77995",	.data = &soc_rcar_d3 },
	{ .compatible = "renesas,r8a779m7",	.data = &soc_rcar_d3 },
#endif
#ifdef CONFIG_ARCH_R8A779A0
	{ .compatible = "renesas,r8a779a0",	.data = &soc_rcar_v3u },
#endif
#ifdef CONFIG_ARCH_R8A779F0
	{ .compatible = "renesas,r8a779f0",	.data = &soc_rcar_s4 },
#endif
#ifdef CONFIG_ARCH_R8A779G0
	{ .compatible = "renesas,r8a779g0",	.data = &soc_rcar_v4h },
#endif
#ifdef CONFIG_ARCH_R9A07G043
#ifdef CONFIG_RISCV
	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_five },
#else
	{ .compatible = "renesas,r9a07g043",	.data = &soc_rz_g2ul },
#endif
#endif
#ifdef CONFIG_ARCH_R9A07G044
	{ .compatible = "renesas,r9a07g044",	.data = &soc_rz_g2l },
#endif
#ifdef CONFIG_ARCH_R9A07G054
	{ .compatible = "renesas,r9a07g054",	.data = &soc_rz_v2l },
#endif
#ifdef CONFIG_ARCH_R9A08G045
	{ .compatible = "renesas,r9a08g045",	.data = &soc_rz_g3s },
#endif
#ifdef CONFIG_ARCH_R9A09G011
	{ .compatible = "renesas,r9a09g011",	.data = &soc_rz_v2m },
#endif
#ifdef CONFIG_ARCH_SH73A0
	{ .compatible = "renesas,sh73a0",	.data = &soc_shmobile_ag5 },
#endif
	{ /* sentinel */ }
};

struct renesas_id {
	unsigned int offset;
	u32 mask;
};

static const struct renesas_id id_bsid __initconst = {
	.offset = 0,
	.mask = 0xff0000,
	/*
	 * TODO: Upper 4 bits of BSID are for chip version, but the format is
	 * not known at this time so we don't know how to specify eshi and eslo
	 */
};

static const struct renesas_id id_rzg2l __initconst = {
	.offset = 0xa04,
	.mask = 0xfffffff,
};

static const struct renesas_id id_rzv2m __initconst = {
	.offset = 0x104,
	.mask = 0xff,
};

static const struct renesas_id id_prr __initconst = {
	.offset = 0,
	.mask = 0xff00,
};

static const struct of_device_id renesas_ids[] __initconst = {
	{ .compatible = "renesas,bsid",			.data = &id_bsid },
	{ .compatible = "renesas,r9a07g043-sysc",	.data = &id_rzg2l },
	{ .compatible = "renesas,r9a07g044-sysc",	.data = &id_rzg2l },
	{ .compatible = "renesas,r9a07g054-sysc",	.data = &id_rzg2l },
	{ .compatible = "renesas,r9a08g045-sysc",	.data = &id_rzg2l },
	{ .compatible = "renesas,r9a09g011-sys",	.data = &id_rzv2m },
	{ .compatible = "renesas,prr",			.data = &id_prr },
	{ /* sentinel */ }
};

static int __init renesas_soc_init(void)
{
	struct soc_device_attribute *soc_dev_attr;
	unsigned int product, eshi = 0, eslo;
	const struct renesas_family *family;
	const struct of_device_id *match;
	const struct renesas_soc *soc;
	const struct renesas_id *id;
	void __iomem *chipid = NULL;
	const char *rev_prefix = "";
	struct soc_device *soc_dev;
	struct device_node *np;
	const char *soc_id;
	int ret;

	match = of_match_node(renesas_socs, of_root);
	if (!match)
		return -ENODEV;

	soc_id = strchr(match->compatible, ',') + 1;
	soc = match->data;
	family = soc->family;

	np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
	if (np) {
		id = match->data;
		chipid = of_iomap(np, 0);
		of_node_put(np);
	} else if (soc->id && family->reg) {
		/* Try hardcoded CCCR/PRR fallback */
		id = &id_prr;
		chipid = ioremap(family->reg, 4);
	}

	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
	if (!soc_dev_attr) {
		if (chipid)
			iounmap(chipid);
		return -ENOMEM;
	}

	soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
	soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);

	if (chipid) {
		product = readl(chipid + id->offset);
		iounmap(chipid);

		if (id == &id_prr) {
			/* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
			if ((product & 0x7fff) == 0x5210)
				product ^= 0x11;
			/* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
			if ((product & 0x7fff) == 0x5211)
				product ^= 0x12;

			eshi = ((product >> 4) & 0x0f) + 1;
			eslo = product & 0xf;
			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
							   eshi, eslo);
		}  else if (id == &id_rzg2l) {
			eshi =  ((product >> 28) & 0x0f);
			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u",
							   eshi);
			rev_prefix = "Rev ";
		} else if (id == &id_rzv2m) {
			eshi = ((product >> 4) & 0x0f);
			eslo = product & 0xf;
			soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u.%u",
							   eshi, eslo);
		}

		if (soc->id &&
		    ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
			pr_warn("SoC mismatch (product = 0x%x)\n", product);
			ret = -ENODEV;
			goto free_soc_dev_attr;
		}
	}

	pr_info("Detected Renesas %s %s %s%s\n", soc_dev_attr->family,
		soc_dev_attr->soc_id, rev_prefix, soc_dev_attr->revision ?: "");

	soc_dev = soc_device_register(soc_dev_attr);
	if (IS_ERR(soc_dev)) {
		ret = PTR_ERR(soc_dev);
		goto free_soc_dev_attr;
	}

	return 0;

free_soc_dev_attr:
	kfree(soc_dev_attr->revision);
	kfree_const(soc_dev_attr->soc_id);
	kfree_const(soc_dev_attr->family);
	kfree(soc_dev_attr);
	return ret;
}
early_initcall(renesas_soc_init);