soc-realview.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/device.h>
  8. #include <linux/init.h>
  9. #include <linux/io.h>
  10. #include <linux/slab.h>
  11. #include <linux/sys_soc.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/mfd/syscon.h>
  14. #include <linux/regmap.h>
  15. #include <linux/of.h>
  16. /* System ID in syscon */
  17. #define REALVIEW_SYS_ID_OFFSET 0x00
  18. static const struct of_device_id realview_soc_of_match[] = {
  19. { .compatible = "arm,realview-eb-soc", },
  20. { .compatible = "arm,realview-pb1176-soc", },
  21. { .compatible = "arm,realview-pb11mp-soc", },
  22. { .compatible = "arm,realview-pba8-soc", },
  23. { .compatible = "arm,realview-pbx-soc", },
  24. { }
  25. };
  26. static u32 realview_coreid;
  27. static const char *realview_arch_str(u32 id)
  28. {
  29. switch ((id >> 8) & 0xf) {
  30. case 0x04:
  31. return "AHB";
  32. case 0x05:
  33. return "Multi-layer AXI";
  34. default:
  35. return "Unknown";
  36. }
  37. }
  38. static ssize_t
  39. manufacturer_show(struct device *dev, struct device_attribute *attr, char *buf)
  40. {
  41. return sprintf(buf, "%02x\n", realview_coreid >> 24);
  42. }
  43. static DEVICE_ATTR_RO(manufacturer);
  44. static ssize_t
  45. board_show(struct device *dev, struct device_attribute *attr, char *buf)
  46. {
  47. return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
  48. }
  49. static DEVICE_ATTR_RO(board);
  50. static ssize_t
  51. fpga_show(struct device *dev, struct device_attribute *attr, char *buf)
  52. {
  53. return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
  54. }
  55. static DEVICE_ATTR_RO(fpga);
  56. static ssize_t
  57. build_show(struct device *dev, struct device_attribute *attr, char *buf)
  58. {
  59. return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
  60. }
  61. static DEVICE_ATTR_RO(build);
  62. static struct attribute *realview_attrs[] = {
  63. &dev_attr_manufacturer.attr,
  64. &dev_attr_board.attr,
  65. &dev_attr_fpga.attr,
  66. &dev_attr_build.attr,
  67. NULL
  68. };
  69. ATTRIBUTE_GROUPS(realview);
  70. static void realview_soc_socdev_release(void *data)
  71. {
  72. struct soc_device *soc_dev = data;
  73. soc_device_unregister(soc_dev);
  74. }
  75. static int realview_soc_probe(struct platform_device *pdev)
  76. {
  77. struct regmap *syscon_regmap;
  78. struct soc_device *soc_dev;
  79. struct soc_device_attribute *soc_dev_attr;
  80. struct device_node *np = pdev->dev.of_node;
  81. int ret;
  82. syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
  83. if (IS_ERR(syscon_regmap))
  84. return PTR_ERR(syscon_regmap);
  85. soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr), GFP_KERNEL);
  86. if (!soc_dev_attr)
  87. return -ENOMEM;
  88. ret = of_property_read_string(np, "compatible",
  89. &soc_dev_attr->soc_id);
  90. if (ret)
  91. return -EINVAL;
  92. soc_dev_attr->machine = "RealView";
  93. soc_dev_attr->family = "Versatile";
  94. soc_dev_attr->custom_attr_group = realview_groups[0];
  95. soc_dev = soc_device_register(soc_dev_attr);
  96. if (IS_ERR(soc_dev))
  97. return -ENODEV;
  98. ret = devm_add_action_or_reset(&pdev->dev, realview_soc_socdev_release,
  99. soc_dev);
  100. if (ret)
  101. return ret;
  102. ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
  103. &realview_coreid);
  104. if (ret)
  105. return -ENODEV;
  106. dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
  107. realview_coreid,
  108. ((realview_coreid >> 16) & 0xfff));
  109. /* FIXME: add attributes for SoC to sysfs */
  110. return 0;
  111. }
  112. static struct platform_driver realview_soc_driver = {
  113. .probe = realview_soc_probe,
  114. .driver = {
  115. .name = "realview-soc",
  116. .of_match_table = realview_soc_of_match,
  117. },
  118. };
  119. builtin_platform_driver(realview_soc_driver);