soc-realview.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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
  38. manufacturer_show(struct device *dev, struct device_attribute *attr, char *buf)
  39. {
  40. return sprintf(buf, "%02x\n", realview_coreid >> 24);
  41. }
  42. static DEVICE_ATTR_RO(manufacturer);
  43. static ssize_t
  44. board_show(struct device *dev, struct device_attribute *attr, char *buf)
  45. {
  46. return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
  47. }
  48. static DEVICE_ATTR_RO(board);
  49. static ssize_t
  50. fpga_show(struct device *dev, struct device_attribute *attr, char *buf)
  51. {
  52. return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
  53. }
  54. static DEVICE_ATTR_RO(fpga);
  55. static ssize_t
  56. build_show(struct device *dev, struct device_attribute *attr, char *buf)
  57. {
  58. return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
  59. }
  60. static DEVICE_ATTR_RO(build);
  61. static struct attribute *realview_attrs[] = {
  62. &dev_attr_manufacturer.attr,
  63. &dev_attr_board.attr,
  64. &dev_attr_fpga.attr,
  65. &dev_attr_build.attr,
  66. NULL
  67. };
  68. ATTRIBUTE_GROUPS(realview);
  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_attr->custom_attr_group = realview_groups[0];
  89. soc_dev = soc_device_register(soc_dev_attr);
  90. if (IS_ERR(soc_dev)) {
  91. kfree(soc_dev_attr);
  92. return -ENODEV;
  93. }
  94. ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
  95. &realview_coreid);
  96. if (ret)
  97. return -ENODEV;
  98. dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
  99. realview_coreid,
  100. ((realview_coreid >> 16) & 0xfff));
  101. /* FIXME: add attributes for SoC to sysfs */
  102. return 0;
  103. }
  104. static struct platform_driver realview_soc_driver = {
  105. .probe = realview_soc_probe,
  106. .driver = {
  107. .name = "realview-soc",
  108. .of_match_table = realview_soc_of_match,
  109. },
  110. };
  111. builtin_platform_driver(realview_soc_driver);