guts.c 6.2 KB

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