renesas-soc.c 7.2 KB

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