renesas-soc.c 6.8 KB

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