renesas-soc.c 10 KB

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