renesas-soc.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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_rcar_m1a __initconst __maybe_unused = {
  84. .family = &fam_rcar_gen1,
  85. };
  86. static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
  87. .family = &fam_rcar_gen1,
  88. .id = 0x3b,
  89. };
  90. static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
  91. .family = &fam_rcar_gen2,
  92. .id = 0x45,
  93. };
  94. static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
  95. .family = &fam_rcar_gen2,
  96. .id = 0x47,
  97. };
  98. static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
  99. .family = &fam_rcar_gen2,
  100. .id = 0x4a,
  101. };
  102. static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
  103. .family = &fam_rcar_gen2,
  104. .id = 0x4b,
  105. };
  106. static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
  107. .family = &fam_rcar_gen2,
  108. .id = 0x4c,
  109. };
  110. static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
  111. .family = &fam_rcar_gen3,
  112. .id = 0x4f,
  113. };
  114. static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
  115. .family = &fam_rcar_gen3,
  116. .id = 0x52,
  117. };
  118. static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
  119. .family = &fam_rcar_gen3,
  120. .id = 0x58,
  121. };
  122. static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
  123. .family = &fam_shmobile,
  124. .id = 0x37,
  125. };
  126. static const struct of_device_id renesas_socs[] __initconst = {
  127. #ifdef CONFIG_ARCH_R7S72100
  128. { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
  129. #endif
  130. #ifdef CONFIG_ARCH_R8A73A4
  131. { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
  132. #endif
  133. #ifdef CONFIG_ARCH_R8A7740
  134. { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
  135. #endif
  136. #ifdef CONFIG_ARCH_R8A7742
  137. { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
  138. #endif
  139. #ifdef CONFIG_ARCH_R8A7743
  140. { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
  141. #endif
  142. #ifdef CONFIG_ARCH_R8A7744
  143. { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
  144. #endif
  145. #ifdef CONFIG_ARCH_R8A7745
  146. { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
  147. #endif
  148. #ifdef CONFIG_ARCH_R8A7778
  149. { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
  150. #endif
  151. #ifdef CONFIG_ARCH_R8A7779
  152. { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
  153. #endif
  154. #ifdef CONFIG_ARCH_R8A7790
  155. { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
  156. #endif
  157. #ifdef CONFIG_ARCH_R8A7791
  158. { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
  159. #endif
  160. #ifdef CONFIG_ARCH_R8A7792
  161. { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
  162. #endif
  163. #ifdef CONFIG_ARCH_R8A7793
  164. { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
  165. #endif
  166. #ifdef CONFIG_ARCH_R8A7794
  167. { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
  168. #endif
  169. #ifdef CONFIG_ARCH_R8A7795
  170. { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
  171. #endif
  172. #ifdef CONFIG_ARCH_R8A7796
  173. { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
  174. #endif
  175. #ifdef CONFIG_ARCH_R8A77995
  176. { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
  177. #endif
  178. #ifdef CONFIG_ARCH_SH73A0
  179. { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
  180. #endif
  181. { /* sentinel */ }
  182. };
  183. static int __init renesas_soc_init(void)
  184. {
  185. struct soc_device_attribute *soc_dev_attr;
  186. const struct renesas_family *family;
  187. const struct of_device_id *match;
  188. const struct renesas_soc *soc;
  189. void __iomem *chipid = NULL;
  190. struct soc_device *soc_dev;
  191. struct device_node *np;
  192. unsigned int product;
  193. match = of_match_node(renesas_socs, of_root);
  194. if (!match)
  195. return -ENODEV;
  196. soc = match->data;
  197. family = soc->family;
  198. /* Try PRR first, then hardcoded fallback */
  199. np = of_find_compatible_node(NULL, NULL, "renesas,prr");
  200. if (np) {
  201. chipid = of_iomap(np, 0);
  202. of_node_put(np);
  203. } else if (soc->id) {
  204. chipid = ioremap(family->reg, 4);
  205. }
  206. if (chipid) {
  207. product = readl(chipid);
  208. iounmap(chipid);
  209. if (soc->id && ((product >> 8) & 0xff) != soc->id) {
  210. pr_warn("SoC mismatch (product = 0x%x)\n", product);
  211. return -ENODEV;
  212. }
  213. }
  214. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  215. if (!soc_dev_attr)
  216. return -ENOMEM;
  217. np = of_find_node_by_path("/");
  218. of_property_read_string(np, "model", &soc_dev_attr->machine);
  219. of_node_put(np);
  220. soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
  221. soc_dev_attr->soc_id = kstrdup_const(strchr(match->compatible, ',') + 1,
  222. GFP_KERNEL);
  223. if (chipid)
  224. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
  225. ((product >> 4) & 0x0f) + 1,
  226. product & 0xf);
  227. pr_info("Detected Renesas %s %s %s\n", soc_dev_attr->family,
  228. soc_dev_attr->soc_id, soc_dev_attr->revision ?: "");
  229. soc_dev = soc_device_register(soc_dev_attr);
  230. if (IS_ERR(soc_dev)) {
  231. kfree(soc_dev_attr->revision);
  232. kfree_const(soc_dev_attr->soc_id);
  233. kfree_const(soc_dev_attr->family);
  234. kfree(soc_dev_attr);
  235. return PTR_ERR(soc_dev);
  236. }
  237. return 0;
  238. }
  239. early_initcall(renesas_soc_init);