guts.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Freescale QorIQ Platforms GUTS Driver
  4. *
  5. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  6. */
  7. #include <linux/io.h>
  8. #include <linux/slab.h>
  9. #include <linux/module.h>
  10. #include <linux/of_fdt.h>
  11. #include <linux/sys_soc.h>
  12. #include <linux/of_address.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/fsl/guts.h>
  15. struct guts {
  16. struct ccsr_guts __iomem *regs;
  17. bool little_endian;
  18. };
  19. struct fsl_soc_die_attr {
  20. char *die;
  21. u32 svr;
  22. u32 mask;
  23. };
  24. static struct guts *guts;
  25. static struct soc_device_attribute soc_dev_attr;
  26. static struct soc_device *soc_dev;
  27. /* SoC die attribute definition for QorIQ platform */
  28. static const struct fsl_soc_die_attr fsl_soc_die[] = {
  29. /*
  30. * Power Architecture-based SoCs T Series
  31. */
  32. /* Die: T4240, SoC: T4240/T4160/T4080 */
  33. { .die = "T4240",
  34. .svr = 0x82400000,
  35. .mask = 0xfff00000,
  36. },
  37. /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */
  38. { .die = "T1040",
  39. .svr = 0x85200000,
  40. .mask = 0xfff00000,
  41. },
  42. /* Die: T2080, SoC: T2080/T2081 */
  43. { .die = "T2080",
  44. .svr = 0x85300000,
  45. .mask = 0xfff00000,
  46. },
  47. /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */
  48. { .die = "T1024",
  49. .svr = 0x85400000,
  50. .mask = 0xfff00000,
  51. },
  52. /*
  53. * ARM-based SoCs LS Series
  54. */
  55. /* Die: LS1043A, SoC: LS1043A/LS1023A */
  56. { .die = "LS1043A",
  57. .svr = 0x87920000,
  58. .mask = 0xffff0000,
  59. },
  60. /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */
  61. { .die = "LS2080A",
  62. .svr = 0x87010000,
  63. .mask = 0xff3f0000,
  64. },
  65. /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */
  66. { .die = "LS1088A",
  67. .svr = 0x87030000,
  68. .mask = 0xff3f0000,
  69. },
  70. /* Die: LS1012A, SoC: LS1012A */
  71. { .die = "LS1012A",
  72. .svr = 0x87040000,
  73. .mask = 0xffff0000,
  74. },
  75. /* Die: LS1046A, SoC: LS1046A/LS1026A */
  76. { .die = "LS1046A",
  77. .svr = 0x87070000,
  78. .mask = 0xffff0000,
  79. },
  80. /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */
  81. { .die = "LS2088A",
  82. .svr = 0x87090000,
  83. .mask = 0xff3f0000,
  84. },
  85. /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */
  86. { .die = "LS1021A",
  87. .svr = 0x87000000,
  88. .mask = 0xfff70000,
  89. },
  90. /* Die: LX2160A, SoC: LX2160A/LX2120A/LX2080A */
  91. { .die = "LX2160A",
  92. .svr = 0x87360000,
  93. .mask = 0xff3f0000,
  94. },
  95. /* Die: LS1028A, SoC: LS1028A */
  96. { .die = "LS1028A",
  97. .svr = 0x870b0000,
  98. .mask = 0xff3f0000,
  99. },
  100. { },
  101. };
  102. static const struct fsl_soc_die_attr *fsl_soc_die_match(
  103. u32 svr, const struct fsl_soc_die_attr *matches)
  104. {
  105. while (matches->svr) {
  106. if (matches->svr == (svr & matches->mask))
  107. return matches;
  108. matches++;
  109. };
  110. return NULL;
  111. }
  112. static u32 fsl_guts_get_svr(void)
  113. {
  114. u32 svr = 0;
  115. if (!guts || !guts->regs)
  116. return svr;
  117. if (guts->little_endian)
  118. svr = ioread32(&guts->regs->svr);
  119. else
  120. svr = ioread32be(&guts->regs->svr);
  121. return svr;
  122. }
  123. static int fsl_guts_probe(struct platform_device *pdev)
  124. {
  125. struct device_node *root, *np = pdev->dev.of_node;
  126. struct device *dev = &pdev->dev;
  127. struct resource *res;
  128. const struct fsl_soc_die_attr *soc_die;
  129. const char *machine;
  130. u32 svr;
  131. /* Initialize guts */
  132. guts = devm_kzalloc(dev, sizeof(*guts), GFP_KERNEL);
  133. if (!guts)
  134. return -ENOMEM;
  135. guts->little_endian = of_property_read_bool(np, "little-endian");
  136. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  137. guts->regs = devm_ioremap_resource(dev, res);
  138. if (IS_ERR(guts->regs))
  139. return PTR_ERR(guts->regs);
  140. /* Register soc device */
  141. root = of_find_node_by_path("/");
  142. if (of_property_read_string(root, "model", &machine))
  143. of_property_read_string_index(root, "compatible", 0, &machine);
  144. if (machine) {
  145. soc_dev_attr.machine = devm_kstrdup(dev, machine, GFP_KERNEL);
  146. if (!soc_dev_attr.machine) {
  147. of_node_put(root);
  148. return -ENOMEM;
  149. }
  150. }
  151. of_node_put(root);
  152. svr = fsl_guts_get_svr();
  153. soc_die = fsl_soc_die_match(svr, fsl_soc_die);
  154. if (soc_die) {
  155. soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL,
  156. "QorIQ %s", soc_die->die);
  157. } else {
  158. soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ");
  159. }
  160. if (!soc_dev_attr.family)
  161. return -ENOMEM;
  162. soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL,
  163. "svr:0x%08x", svr);
  164. if (!soc_dev_attr.soc_id)
  165. return -ENOMEM;
  166. soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d",
  167. (svr >> 4) & 0xf, svr & 0xf);
  168. if (!soc_dev_attr.revision)
  169. return -ENOMEM;
  170. soc_dev = soc_device_register(&soc_dev_attr);
  171. if (IS_ERR(soc_dev))
  172. return PTR_ERR(soc_dev);
  173. pr_info("Machine: %s\n", soc_dev_attr.machine);
  174. pr_info("SoC family: %s\n", soc_dev_attr.family);
  175. pr_info("SoC ID: %s, Revision: %s\n",
  176. soc_dev_attr.soc_id, soc_dev_attr.revision);
  177. return 0;
  178. }
  179. static int fsl_guts_remove(struct platform_device *dev)
  180. {
  181. soc_device_unregister(soc_dev);
  182. return 0;
  183. }
  184. /*
  185. * Table for matching compatible strings, for device tree
  186. * guts node, for Freescale QorIQ SOCs.
  187. */
  188. static const struct of_device_id fsl_guts_of_match[] = {
  189. { .compatible = "fsl,qoriq-device-config-1.0", },
  190. { .compatible = "fsl,qoriq-device-config-2.0", },
  191. { .compatible = "fsl,p1010-guts", },
  192. { .compatible = "fsl,p1020-guts", },
  193. { .compatible = "fsl,p1021-guts", },
  194. { .compatible = "fsl,p1022-guts", },
  195. { .compatible = "fsl,p1023-guts", },
  196. { .compatible = "fsl,p2020-guts", },
  197. { .compatible = "fsl,bsc9131-guts", },
  198. { .compatible = "fsl,bsc9132-guts", },
  199. { .compatible = "fsl,mpc8536-guts", },
  200. { .compatible = "fsl,mpc8544-guts", },
  201. { .compatible = "fsl,mpc8548-guts", },
  202. { .compatible = "fsl,mpc8568-guts", },
  203. { .compatible = "fsl,mpc8569-guts", },
  204. { .compatible = "fsl,mpc8572-guts", },
  205. { .compatible = "fsl,ls1021a-dcfg", },
  206. { .compatible = "fsl,ls1043a-dcfg", },
  207. { .compatible = "fsl,ls2080a-dcfg", },
  208. { .compatible = "fsl,ls1088a-dcfg", },
  209. { .compatible = "fsl,ls1012a-dcfg", },
  210. { .compatible = "fsl,ls1046a-dcfg", },
  211. { .compatible = "fsl,lx2160a-dcfg", },
  212. { .compatible = "fsl,ls1028a-dcfg", },
  213. {}
  214. };
  215. MODULE_DEVICE_TABLE(of, fsl_guts_of_match);
  216. static struct platform_driver fsl_guts_driver = {
  217. .driver = {
  218. .name = "fsl-guts",
  219. .of_match_table = fsl_guts_of_match,
  220. },
  221. .probe = fsl_guts_probe,
  222. .remove = fsl_guts_remove,
  223. };
  224. static int __init fsl_guts_init(void)
  225. {
  226. return platform_driver_register(&fsl_guts_driver);
  227. }
  228. core_initcall(fsl_guts_init);
  229. static void __exit fsl_guts_exit(void)
  230. {
  231. platform_driver_unregister(&fsl_guts_driver);
  232. }
  233. module_exit(fsl_guts_exit);