guts.c 6.1 KB

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