2 * Renesas SoC Identification
4 * Copyright (C) 2014-2016 Glider bvba
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.
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.
18 #include <linux/of_address.h>
19 #include <linux/slab.h>
20 #include <linux/string.h>
21 #include <linux/sys_soc.h>
24 struct renesas_family
{
26 u32 reg
; /* CCCR or PRR, if not in DT */
29 static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused
= {
31 .reg
= 0xff000044, /* PRR (Product Register) */
34 static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused
= {
36 .reg
= 0xff000044, /* PRR (Product Register) */
39 static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused
= {
41 .reg
= 0xfff00044, /* PRR (Product Register) */
44 static const struct renesas_family fam_rmobile __initconst __maybe_unused
= {
46 .reg
= 0xe600101c, /* CCCR (Common Chip Code Register) */
49 static const struct renesas_family fam_rza __initconst __maybe_unused
= {
53 static const struct renesas_family fam_rzg __initconst __maybe_unused
= {
55 .reg
= 0xff000044, /* PRR (Product Register) */
58 static const struct renesas_family fam_shmobile __initconst __maybe_unused
= {
60 .reg
= 0xe600101c, /* CCCR (Common Chip Code Register) */
65 const struct renesas_family
*family
;
69 static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused
= {
73 static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused
= {
74 .family
= &fam_rmobile
,
78 static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused
= {
79 .family
= &fam_rmobile
,
83 static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused
= {
88 static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused
= {
93 static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused
= {
98 static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused
= {
103 static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused
= {
104 .family
= &fam_rcar_gen1
,
107 static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused
= {
108 .family
= &fam_rcar_gen1
,
112 static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused
= {
113 .family
= &fam_rcar_gen2
,
117 static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused
= {
118 .family
= &fam_rcar_gen2
,
122 static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused
= {
123 .family
= &fam_rcar_gen2
,
127 static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused
= {
128 .family
= &fam_rcar_gen2
,
132 static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused
= {
133 .family
= &fam_rcar_gen2
,
137 static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused
= {
138 .family
= &fam_rcar_gen3
,
142 static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused
= {
143 .family
= &fam_rcar_gen3
,
147 static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused
= {
148 .family
= &fam_shmobile
,
153 static const struct of_device_id renesas_socs
[] __initconst
= {
154 #ifdef CONFIG_ARCH_R7S72100
155 { .compatible
= "renesas,r7s72100", .data
= &soc_rz_a1h
},
157 #ifdef CONFIG_ARCH_R8A73A4
158 { .compatible
= "renesas,r8a73a4", .data
= &soc_rmobile_ape6
},
160 #ifdef CONFIG_ARCH_R8A7740
161 { .compatible
= "renesas,r8a7740", .data
= &soc_rmobile_a1
},
163 #ifdef CONFIG_ARCH_R8A7742
164 { .compatible
= "renesas,r8a7742", .data
= &soc_rz_g1h
},
166 #ifdef CONFIG_ARCH_R8A7743
167 { .compatible
= "renesas,r8a7743", .data
= &soc_rz_g1m
},
169 #ifdef CONFIG_ARCH_R8A7744
170 { .compatible
= "renesas,r8a7744", .data
= &soc_rz_g1n
},
172 #ifdef CONFIG_ARCH_R8A7745
173 { .compatible
= "renesas,r8a7745", .data
= &soc_rz_g1e
},
175 #ifdef CONFIG_ARCH_R8A7778
176 { .compatible
= "renesas,r8a7778", .data
= &soc_rcar_m1a
},
178 #ifdef CONFIG_ARCH_R8A7779
179 { .compatible
= "renesas,r8a7779", .data
= &soc_rcar_h1
},
181 #ifdef CONFIG_ARCH_R8A7790
182 { .compatible
= "renesas,r8a7790", .data
= &soc_rcar_h2
},
184 #ifdef CONFIG_ARCH_R8A7791
185 { .compatible
= "renesas,r8a7791", .data
= &soc_rcar_m2_w
},
187 #ifdef CONFIG_ARCH_R8A7792
188 { .compatible
= "renesas,r8a7792", .data
= &soc_rcar_v2h
},
190 #ifdef CONFIG_ARCH_R8A7793
191 { .compatible
= "renesas,r8a7793", .data
= &soc_rcar_m2_n
},
193 #ifdef CONFIG_ARCH_R8A7794
194 { .compatible
= "renesas,r8a7794", .data
= &soc_rcar_e2
},
196 #ifdef CONFIG_ARCH_R8A7795
197 { .compatible
= "renesas,r8a7795", .data
= &soc_rcar_h3
},
199 #ifdef CONFIG_ARCH_R8A7796
200 { .compatible
= "renesas,r8a7796", .data
= &soc_rcar_m3_w
},
202 #ifdef CONFIG_ARCH_SH73A0
203 { .compatible
= "renesas,sh73a0", .data
= &soc_shmobile_ag5
},
208 static int __init
renesas_soc_init(void)
210 struct soc_device_attribute
*soc_dev_attr
;
211 const struct renesas_family
*family
;
212 const struct of_device_id
*match
;
213 const struct renesas_soc
*soc
;
214 void __iomem
*chipid
= NULL
;
215 struct soc_device
*soc_dev
;
216 struct device_node
*np
;
217 unsigned int product
;
219 match
= of_match_node(renesas_socs
, of_root
);
224 family
= soc
->family
;
226 /* Try PRR first, then hardcoded fallback */
227 np
= of_find_compatible_node(NULL
, NULL
, "renesas,prr");
229 chipid
= of_iomap(np
, 0);
231 } else if (soc
->id
) {
232 chipid
= ioremap(family
->reg
, 4);
235 product
= readl(chipid
);
237 if (soc
->id
&& ((product
>> 8) & 0xff) != soc
->id
) {
238 pr_warn("SoC mismatch (product = 0x%x)\n", product
);
243 soc_dev_attr
= kzalloc(sizeof(*soc_dev_attr
), GFP_KERNEL
);
247 np
= of_find_node_by_path("/");
248 of_property_read_string(np
, "model", &soc_dev_attr
->machine
);
251 soc_dev_attr
->family
= kstrdup_const(family
->name
, GFP_KERNEL
);
252 soc_dev_attr
->soc_id
= kstrdup_const(strchr(match
->compatible
, ',') + 1,
255 soc_dev_attr
->revision
= kasprintf(GFP_KERNEL
, "ES%u.%u",
256 ((product
>> 4) & 0x0f) + 1,
259 pr_info("Detected Renesas %s %s %s\n", soc_dev_attr
->family
,
260 soc_dev_attr
->soc_id
, soc_dev_attr
->revision
?: "");
262 soc_dev
= soc_device_register(soc_dev_attr
);
263 if (IS_ERR(soc_dev
)) {
264 kfree(soc_dev_attr
->revision
);
265 kfree_const(soc_dev_attr
->soc_id
);
266 kfree_const(soc_dev_attr
->family
);
268 return PTR_ERR(soc_dev
);
273 early_initcall(renesas_soc_init
);