renesas-soc.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. #include <linux/io.h>
  16. #include <linux/of.h>
  17. #include <linux/of_address.h>
  18. #include <linux/slab.h>
  19. #include <linux/string.h>
  20. #include <linux/sys_soc.h>
  21. struct renesas_family {
  22. const char name[16];
  23. u32 reg; /* CCCR or PRR, if not in DT */
  24. };
  25. static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
  26. .name = "R-Car Gen1",
  27. .reg = 0xff000044, /* PRR (Product Register) */
  28. };
  29. static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
  30. .name = "R-Car Gen2",
  31. .reg = 0xff000044, /* PRR (Product Register) */
  32. };
  33. static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
  34. .name = "R-Car Gen3",
  35. .reg = 0xfff00044, /* PRR (Product Register) */
  36. };
  37. static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
  38. .name = "R-Mobile",
  39. .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
  40. };
  41. static const struct renesas_family fam_rza __initconst __maybe_unused = {
  42. .name = "RZ/A",
  43. };
  44. static const struct renesas_family fam_rzg __initconst __maybe_unused = {
  45. .name = "RZ/G",
  46. .reg = 0xff000044, /* PRR (Product Register) */
  47. };
  48. static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
  49. .name = "SH-Mobile",
  50. .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
  51. };
  52. struct renesas_soc {
  53. const struct renesas_family *family;
  54. u8 id;
  55. };
  56. static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
  57. .family = &fam_rza,
  58. };
  59. static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
  60. .family = &fam_rmobile,
  61. .id = 0x3f,
  62. };
  63. static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
  64. .family = &fam_rmobile,
  65. .id = 0x40,
  66. };
  67. static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
  68. .family = &fam_rzg,
  69. .id = 0x45,
  70. };
  71. static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
  72. .family = &fam_rzg,
  73. .id = 0x47,
  74. };
  75. static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
  76. .family = &fam_rzg,
  77. .id = 0x4b,
  78. };
  79. static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
  80. .family = &fam_rzg,
  81. .id = 0x4c,
  82. };
  83. static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
  84. .family = &fam_rzg,
  85. .id = 0x53,
  86. };
  87. static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
  88. .family = &fam_rcar_gen1,
  89. };
  90. static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
  91. .family = &fam_rcar_gen1,
  92. .id = 0x3b,
  93. };
  94. static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
  95. .family = &fam_rcar_gen2,
  96. .id = 0x45,
  97. };
  98. static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
  99. .family = &fam_rcar_gen2,
  100. .id = 0x47,
  101. };
  102. static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
  103. .family = &fam_rcar_gen2,
  104. .id = 0x4a,
  105. };
  106. static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
  107. .family = &fam_rcar_gen2,
  108. .id = 0x4b,
  109. };
  110. static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
  111. .family = &fam_rcar_gen2,
  112. .id = 0x4c,
  113. };
  114. static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
  115. .family = &fam_rcar_gen3,
  116. .id = 0x4f,
  117. };
  118. static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
  119. .family = &fam_rcar_gen3,
  120. .id = 0x52,
  121. };
  122. static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
  123. .family = &fam_rcar_gen3,
  124. .id = 0x55,
  125. };
  126. static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
  127. .family = &fam_rcar_gen3,
  128. .id = 0x54,
  129. };
  130. static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
  131. .family = &fam_rcar_gen3,
  132. .id = 0x56,
  133. };
  134. static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
  135. .family = &fam_rcar_gen3,
  136. .id = 0x57,
  137. };
  138. static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
  139. .family = &fam_rcar_gen3,
  140. .id = 0x58,
  141. };
  142. static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
  143. .family = &fam_shmobile,
  144. .id = 0x37,
  145. };
  146. static const struct of_device_id renesas_socs[] __initconst = {
  147. #ifdef CONFIG_ARCH_R7S72100
  148. { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
  149. #endif
  150. #ifdef CONFIG_ARCH_R8A73A4
  151. { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
  152. #endif
  153. #ifdef CONFIG_ARCH_R8A7740
  154. { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
  155. #endif
  156. #ifdef CONFIG_ARCH_R8A7742
  157. { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
  158. #endif
  159. #ifdef CONFIG_ARCH_R8A7743
  160. { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
  161. #endif
  162. #ifdef CONFIG_ARCH_R8A7744
  163. { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
  164. #endif
  165. #ifdef CONFIG_ARCH_R8A7745
  166. { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
  167. #endif
  168. #ifdef CONFIG_ARCH_R8A77470
  169. { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
  170. #endif
  171. #ifdef CONFIG_ARCH_R8A7778
  172. { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
  173. #endif
  174. #ifdef CONFIG_ARCH_R8A7779
  175. { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
  176. #endif
  177. #ifdef CONFIG_ARCH_R8A7790
  178. { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
  179. #endif
  180. #ifdef CONFIG_ARCH_R8A7791
  181. { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
  182. #endif
  183. #ifdef CONFIG_ARCH_R8A7792
  184. { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
  185. #endif
  186. #ifdef CONFIG_ARCH_R8A7793
  187. { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
  188. #endif
  189. #ifdef CONFIG_ARCH_R8A7794
  190. { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
  191. #endif
  192. #ifdef CONFIG_ARCH_R8A7795
  193. { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
  194. #endif
  195. #ifdef CONFIG_ARCH_R8A7796
  196. { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
  197. #endif
  198. #ifdef CONFIG_ARCH_R8A77965
  199. { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
  200. #endif
  201. #ifdef CONFIG_ARCH_R8A77970
  202. { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
  203. #endif
  204. #ifdef CONFIG_ARCH_R8A77980
  205. { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
  206. #endif
  207. #ifdef CONFIG_ARCH_R8A77990
  208. { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
  209. #endif
  210. #ifdef CONFIG_ARCH_R8A77995
  211. { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
  212. #endif
  213. #ifdef CONFIG_ARCH_SH73A0
  214. { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
  215. #endif
  216. { /* sentinel */ }
  217. };
  218. static int __init renesas_soc_init(void)
  219. {
  220. struct soc_device_attribute *soc_dev_attr;
  221. const struct renesas_family *family;
  222. const struct of_device_id *match;
  223. const struct renesas_soc *soc;
  224. void __iomem *chipid = NULL;
  225. struct soc_device *soc_dev;
  226. struct device_node *np;
  227. unsigned int product;
  228. match = of_match_node(renesas_socs, of_root);
  229. if (!match)
  230. return -ENODEV;
  231. soc = match->data;
  232. family = soc->family;
  233. /* Try PRR first, then hardcoded fallback */
  234. np = of_find_compatible_node(NULL, NULL, "renesas,prr");
  235. if (np) {
  236. chipid = of_iomap(np, 0);
  237. of_node_put(np);
  238. } else if (soc->id) {
  239. chipid = ioremap(family->reg, 4);
  240. }
  241. if (chipid) {
  242. product = readl(chipid);
  243. iounmap(chipid);
  244. /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
  245. if ((product & 0x7fff) == 0x5210)
  246. product ^= 0x11;
  247. /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
  248. if ((product & 0x7fff) == 0x5211)
  249. product ^= 0x12;
  250. if (soc->id && ((product >> 8) & 0xff) != soc->id) {
  251. pr_warn("SoC mismatch (product = 0x%x)\n", product);
  252. return -ENODEV;
  253. }
  254. }
  255. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  256. if (!soc_dev_attr)
  257. return -ENOMEM;
  258. np = of_find_node_by_path("/");
  259. of_property_read_string(np, "model", &soc_dev_attr->machine);
  260. of_node_put(np);
  261. soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
  262. soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
  263. GFP_KERNEL);
  264. if (chipid)
  265. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
  266. ((product >> 4) & 0x0f) + 1,
  267. product & 0xf);
  268. pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
  269. soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
  270. soc_dev = soc_device_register(soc_dev_attr);
  271. if (IS_ERR(soc_dev)) {
  272. kfree(soc_dev_attr->revision);
  273. kfree_const(soc_dev_attr->soc_id);
  274. kfree_const(soc_dev_attr->family);
  275. kfree(soc_dev_attr);
  276. return PTR_ERR(soc_dev);
  277. }
  278. return 0;
  279. }
  280. early_initcall(renesas_soc_init);