soc-realview.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2014 Linaro Ltd.
  4. *
  5. * Author: Linus Walleij <linus.walleij@linaro.org>
  6. */
  7. #include <linux/init.h>
  8. #include <linux/io.h>
  9. #include <linux/slab.h>
  10. #include <linux/sys_soc.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/mfd/syscon.h>
  13. #include <linux/regmap.h>
  14. #include <linux/of.h>
  15. /* System ID in syscon */
  16. #define REALVIEW_SYS_ID_OFFSET 0x00
  17. static const struct of_device_id realview_soc_of_match[] = {
  18. { .compatible = "arm,realview-eb-soc", },
  19. { .compatible = "arm,realview-pb1176-soc", },
  20. { .compatible = "arm,realview-pb11mp-soc", },
  21. { .compatible = "arm,realview-pba8-soc", },
  22. { .compatible = "arm,realview-pbx-soc", },
  23. { }
  24. };
  25. static u32 realview_coreid;
  26. static const char *realview_arch_str(u32 id)
  27. {
  28. switch ((id >> 8) & 0xf) {
  29. case 0x04:
  30. return "AHB";
  31. case 0x05:
  32. return "Multi-layer AXI";
  33. default:
  34. return "Unknown";
  35. }
  36. }
  37. static ssize_t realview_get_manf(struct device *dev,
  38. struct device_attribute *attr,
  39. char *buf)
  40. {
  41. return sprintf(buf, "%02x\n", realview_coreid >> 24);
  42. }
  43. static struct device_attribute realview_manf_attr =
  44. __ATTR(manufacturer, S_IRUGO, realview_get_manf, NULL);
  45. static ssize_t realview_get_board(struct device *dev,
  46. struct device_attribute *attr,
  47. char *buf)
  48. {
  49. return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
  50. }
  51. static struct device_attribute realview_board_attr =
  52. __ATTR(board, S_IRUGO, realview_get_board, NULL);
  53. static ssize_t realview_get_arch(struct device *dev,
  54. struct device_attribute *attr,
  55. char *buf)
  56. {
  57. return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
  58. }
  59. static struct device_attribute realview_arch_attr =
  60. __ATTR(fpga, S_IRUGO, realview_get_arch, NULL);
  61. static ssize_t realview_get_build(struct device *dev,
  62. struct device_attribute *attr,
  63. char *buf)
  64. {
  65. return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
  66. }
  67. static struct device_attribute realview_build_attr =
  68. __ATTR(build, S_IRUGO, realview_get_build, NULL);
  69. static int realview_soc_probe(struct platform_device *pdev)
  70. {
  71. struct regmap *syscon_regmap;
  72. struct soc_device *soc_dev;
  73. struct soc_device_attribute *soc_dev_attr;
  74. struct device_node *np = pdev->dev.of_node;
  75. int ret;
  76. syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
  77. if (IS_ERR(syscon_regmap))
  78. return PTR_ERR(syscon_regmap);
  79. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  80. if (!soc_dev_attr)
  81. return -ENOMEM;
  82. ret = of_property_read_string(np, "compatible",
  83. &soc_dev_attr->soc_id);
  84. if (ret)
  85. return -EINVAL;
  86. soc_dev_attr->machine = "RealView";
  87. soc_dev_attr->family = "Versatile";
  88. soc_dev = soc_device_register(soc_dev_attr);
  89. if (IS_ERR(soc_dev)) {
  90. kfree(soc_dev_attr);
  91. return -ENODEV;
  92. }
  93. ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
  94. &realview_coreid);
  95. if (ret)
  96. return -ENODEV;
  97. device_create_file(soc_device_to_device(soc_dev), &realview_manf_attr);
  98. device_create_file(soc_device_to_device(soc_dev), &realview_board_attr);
  99. device_create_file(soc_device_to_device(soc_dev), &realview_arch_attr);
  100. device_create_file(soc_device_to_device(soc_dev), &realview_build_attr);
  101. dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
  102. realview_coreid,
  103. ((realview_coreid >> 16) & 0xfff));
  104. /* FIXME: add attributes for SoC to sysfs */
  105. return 0;
  106. }
  107. static struct platform_driver realview_soc_driver = {
  108. .probe = realview_soc_probe,
  109. .driver = {
  110. .name = "realview-soc",
  111. .of_match_table = realview_soc_of_match,
  112. },
  113. };
  114. builtin_platform_driver(realview_soc_driver);