renesas-soc.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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_g2e __initconst __maybe_unused = {
  95. .family = &fam_rzg2,
  96. .id = 0x57,
  97. };
  98. static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
  99. .family = &fam_rcar_gen1,
  100. };
  101. static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
  102. .family = &fam_rcar_gen1,
  103. .id = 0x3b,
  104. };
  105. static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
  106. .family = &fam_rcar_gen2,
  107. .id = 0x45,
  108. };
  109. static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
  110. .family = &fam_rcar_gen2,
  111. .id = 0x47,
  112. };
  113. static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
  114. .family = &fam_rcar_gen2,
  115. .id = 0x4a,
  116. };
  117. static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
  118. .family = &fam_rcar_gen2,
  119. .id = 0x4b,
  120. };
  121. static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
  122. .family = &fam_rcar_gen2,
  123. .id = 0x4c,
  124. };
  125. static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
  126. .family = &fam_rcar_gen3,
  127. .id = 0x4f,
  128. };
  129. static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
  130. .family = &fam_rcar_gen3,
  131. .id = 0x52,
  132. };
  133. static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
  134. .family = &fam_rcar_gen3,
  135. .id = 0x55,
  136. };
  137. static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
  138. .family = &fam_rcar_gen3,
  139. .id = 0x54,
  140. };
  141. static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
  142. .family = &fam_rcar_gen3,
  143. .id = 0x56,
  144. };
  145. static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
  146. .family = &fam_rcar_gen3,
  147. .id = 0x57,
  148. };
  149. static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
  150. .family = &fam_rcar_gen3,
  151. .id = 0x58,
  152. };
  153. static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
  154. .family = &fam_shmobile,
  155. .id = 0x37,
  156. };
  157. static const struct of_device_id renesas_socs[] __initconst = {
  158. #ifdef CONFIG_ARCH_R7S72100
  159. { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
  160. #endif
  161. #ifdef CONFIG_ARCH_R7S9210
  162. { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
  163. #endif
  164. #ifdef CONFIG_ARCH_R8A73A4
  165. { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
  166. #endif
  167. #ifdef CONFIG_ARCH_R8A7740
  168. { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
  169. #endif
  170. #ifdef CONFIG_ARCH_R8A7742
  171. { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
  172. #endif
  173. #ifdef CONFIG_ARCH_R8A7743
  174. { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
  175. #endif
  176. #ifdef CONFIG_ARCH_R8A7744
  177. { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
  178. #endif
  179. #ifdef CONFIG_ARCH_R8A7745
  180. { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
  181. #endif
  182. #ifdef CONFIG_ARCH_R8A77470
  183. { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
  184. #endif
  185. #ifdef CONFIG_ARCH_R8A774A1
  186. { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
  187. #endif
  188. #ifdef CONFIG_ARCH_R8A774C0
  189. { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
  190. #endif
  191. #ifdef CONFIG_ARCH_R8A7778
  192. { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
  193. #endif
  194. #ifdef CONFIG_ARCH_R8A7779
  195. { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
  196. #endif
  197. #ifdef CONFIG_ARCH_R8A7790
  198. { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
  199. #endif
  200. #ifdef CONFIG_ARCH_R8A7791
  201. { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
  202. #endif
  203. #ifdef CONFIG_ARCH_R8A7792
  204. { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
  205. #endif
  206. #ifdef CONFIG_ARCH_R8A7793
  207. { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
  208. #endif
  209. #ifdef CONFIG_ARCH_R8A7794
  210. { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
  211. #endif
  212. #ifdef CONFIG_ARCH_R8A7795
  213. { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
  214. #endif
  215. #ifdef CONFIG_ARCH_R8A7796
  216. { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
  217. #endif
  218. #ifdef CONFIG_ARCH_R8A77965
  219. { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
  220. #endif
  221. #ifdef CONFIG_ARCH_R8A77970
  222. { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
  223. #endif
  224. #ifdef CONFIG_ARCH_R8A77980
  225. { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
  226. #endif
  227. #ifdef CONFIG_ARCH_R8A77990
  228. { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
  229. #endif
  230. #ifdef CONFIG_ARCH_R8A77995
  231. { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
  232. #endif
  233. #ifdef CONFIG_ARCH_SH73A0
  234. { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
  235. #endif
  236. { /* sentinel */ }
  237. };
  238. static int __init renesas_soc_init(void)
  239. {
  240. struct soc_device_attribute *soc_dev_attr;
  241. const struct renesas_family *family;
  242. const struct of_device_id *match;
  243. const struct renesas_soc *soc;
  244. void __iomem *chipid = NULL;
  245. struct soc_device *soc_dev;
  246. struct device_node *np;
  247. unsigned int product, eshi = 0, eslo;
  248. match = of_match_node(renesas_socs, of_root);
  249. if (!match)
  250. return -ENODEV;
  251. soc = match->data;
  252. family = soc->family;
  253. np = of_find_compatible_node(NULL, NULL, "renesas,bsid");
  254. if (np) {
  255. chipid = of_iomap(np, 0);
  256. of_node_put(np);
  257. if (chipid) {
  258. product = readl(chipid);
  259. iounmap(chipid);
  260. if (soc->id && ((product >> 16) & 0xff) != soc->id) {
  261. pr_warn("SoC mismatch (product = 0x%x)\n",
  262. product);
  263. return -ENODEV;
  264. }
  265. }
  266. /*
  267. * TODO: Upper 4 bits of BSID are for chip version, but the
  268. * format is not known at this time so we don't know how to
  269. * specify eshi and eslo
  270. */
  271. goto done;
  272. }
  273. /* Try PRR first, then hardcoded fallback */
  274. np = of_find_compatible_node(NULL, NULL, "renesas,prr");
  275. if (np) {
  276. chipid = of_iomap(np, 0);
  277. of_node_put(np);
  278. } else if (soc->id && family->reg) {
  279. chipid = ioremap(family->reg, 4);
  280. }
  281. if (chipid) {
  282. product = readl(chipid);
  283. iounmap(chipid);
  284. /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
  285. if ((product & 0x7fff) == 0x5210)
  286. product ^= 0x11;
  287. /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
  288. if ((product & 0x7fff) == 0x5211)
  289. product ^= 0x12;
  290. if (soc->id && ((product >> 8) & 0xff) != soc->id) {
  291. pr_warn("SoC mismatch (product = 0x%x)\n", product);
  292. return -ENODEV;
  293. }
  294. eshi = ((product >> 4) & 0x0f) + 1;
  295. eslo = product & 0xf;
  296. }
  297. done:
  298. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  299. if (!soc_dev_attr)
  300. return -ENOMEM;
  301. np = of_find_node_by_path("/");
  302. of_property_read_string(np, "model", &soc_dev_attr->machine);
  303. of_node_put(np);
  304. soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
  305. soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
  306. GFP_KERNEL);
  307. if (eshi)
  308. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u", eshi,
  309. eslo);
  310. pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
  311. soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
  312. soc_dev = soc_device_register(soc_dev_attr);
  313. if (IS_ERR(soc_dev)) {
  314. kfree(soc_dev_attr->revision);
  315. kfree_const(soc_dev_attr->soc_id);
  316. kfree_const(soc_dev_attr->family);
  317. kfree(soc_dev_attr);
  318. return PTR_ERR(soc_dev);
  319. }
  320. return 0;
  321. }
  322. early_initcall(renesas_soc_init);