soc-integrator.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #define INTEGRATOR_HDR_ID_OFFSET 0x00
  16. static u32 integrator_coreid;
  17. static const struct of_device_id integrator_cm_match[] = {
  18. { .compatible = "arm,core-module-integrator", },
  19. { }
  20. };
  21. static const char *integrator_arch_str(u32 id)
  22. {
  23. switch ((id >> 16) & 0xff) {
  24. case 0x00:
  25. return "ASB little-endian";
  26. case 0x01:
  27. return "AHB little-endian";
  28. case 0x03:
  29. return "AHB-Lite system bus, bi-endian";
  30. case 0x04:
  31. return "AHB";
  32. case 0x08:
  33. return "AHB system bus, ASB processor bus";
  34. default:
  35. return "Unknown";
  36. }
  37. }
  38. static const char *integrator_fpga_str(u32 id)
  39. {
  40. switch ((id >> 12) & 0xf) {
  41. case 0x01:
  42. return "XC4062";
  43. case 0x02:
  44. return "XC4085";
  45. case 0x03:
  46. return "XVC600";
  47. case 0x04:
  48. return "EPM7256AE (Altera PLD)";
  49. default:
  50. return "Unknown";
  51. }
  52. }
  53. static ssize_t
  54. manufacturer_show(struct device *dev, struct device_attribute *attr, char *buf)
  55. {
  56. return sprintf(buf, "%02x\n", integrator_coreid >> 24);
  57. }
  58. static DEVICE_ATTR_RO(manufacturer);
  59. static ssize_t
  60. arch_show(struct device *dev, struct device_attribute *attr, char *buf)
  61. {
  62. return sprintf(buf, "%s\n", integrator_arch_str(integrator_coreid));
  63. }
  64. static DEVICE_ATTR_RO(arch);
  65. static ssize_t
  66. fpga_show(struct device *dev, struct device_attribute *attr, char *buf)
  67. {
  68. return sprintf(buf, "%s\n", integrator_fpga_str(integrator_coreid));
  69. }
  70. static DEVICE_ATTR_RO(fpga);
  71. static ssize_t
  72. build_show(struct device *dev, struct device_attribute *attr, char *buf)
  73. {
  74. return sprintf(buf, "%02x\n", (integrator_coreid >> 4) & 0xFF);
  75. }
  76. static DEVICE_ATTR_RO(build);
  77. static struct attribute *integrator_attrs[] = {
  78. &dev_attr_manufacturer.attr,
  79. &dev_attr_arch.attr,
  80. &dev_attr_fpga.attr,
  81. &dev_attr_build.attr,
  82. NULL
  83. };
  84. ATTRIBUTE_GROUPS(integrator);
  85. static int __init integrator_soc_init(void)
  86. {
  87. struct regmap *syscon_regmap;
  88. struct soc_device *soc_dev;
  89. struct soc_device_attribute *soc_dev_attr;
  90. struct device_node *np;
  91. struct device *dev;
  92. u32 val;
  93. int ret;
  94. np = of_find_matching_node(NULL, integrator_cm_match);
  95. if (!np)
  96. return -ENODEV;
  97. syscon_regmap = syscon_node_to_regmap(np);
  98. if (IS_ERR(syscon_regmap))
  99. return PTR_ERR(syscon_regmap);
  100. ret = regmap_read(syscon_regmap, INTEGRATOR_HDR_ID_OFFSET,
  101. &val);
  102. if (ret)
  103. return -ENODEV;
  104. integrator_coreid = val;
  105. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  106. if (!soc_dev_attr)
  107. return -ENOMEM;
  108. soc_dev_attr->soc_id = "Integrator";
  109. soc_dev_attr->machine = "Integrator";
  110. soc_dev_attr->family = "Versatile";
  111. soc_dev_attr->custom_attr_group = integrator_groups[0];
  112. soc_dev = soc_device_register(soc_dev_attr);
  113. if (IS_ERR(soc_dev)) {
  114. kfree(soc_dev_attr);
  115. return -ENODEV;
  116. }
  117. dev = soc_device_to_device(soc_dev);
  118. dev_info(dev, "Detected ARM core module:\n");
  119. dev_info(dev, " Manufacturer: %02x\n", (val >> 24));
  120. dev_info(dev, " Architecture: %s\n", integrator_arch_str(val));
  121. dev_info(dev, " FPGA: %s\n", integrator_fpga_str(val));
  122. dev_info(dev, " Build: %02x\n", (val >> 4) & 0xFF);
  123. dev_info(dev, " Rev: %c\n", ('A' + (val & 0x03)));
  124. return 0;
  125. }
  126. device_initcall(integrator_soc_init);