soc-integrator.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 integrator_get_manf(struct device *dev,
  54. struct device_attribute *attr,
  55. char *buf)
  56. {
  57. return sprintf(buf, "%02x\n", integrator_coreid >> 24);
  58. }
  59. static struct device_attribute integrator_manf_attr =
  60. __ATTR(manufacturer, S_IRUGO, integrator_get_manf, NULL);
  61. static ssize_t integrator_get_arch(struct device *dev,
  62. struct device_attribute *attr,
  63. char *buf)
  64. {
  65. return sprintf(buf, "%s\n", integrator_arch_str(integrator_coreid));
  66. }
  67. static struct device_attribute integrator_arch_attr =
  68. __ATTR(arch, S_IRUGO, integrator_get_arch, NULL);
  69. static ssize_t integrator_get_fpga(struct device *dev,
  70. struct device_attribute *attr,
  71. char *buf)
  72. {
  73. return sprintf(buf, "%s\n", integrator_fpga_str(integrator_coreid));
  74. }
  75. static struct device_attribute integrator_fpga_attr =
  76. __ATTR(fpga, S_IRUGO, integrator_get_fpga, NULL);
  77. static ssize_t integrator_get_build(struct device *dev,
  78. struct device_attribute *attr,
  79. char *buf)
  80. {
  81. return sprintf(buf, "%02x\n", (integrator_coreid >> 4) & 0xFF);
  82. }
  83. static struct device_attribute integrator_build_attr =
  84. __ATTR(build, S_IRUGO, integrator_get_build, NULL);
  85. static int __init integrator_soc_init(void)
  86. {
  87. static 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 = soc_device_register(soc_dev_attr);
  112. if (IS_ERR(soc_dev)) {
  113. kfree(soc_dev_attr);
  114. return -ENODEV;
  115. }
  116. dev = soc_device_to_device(soc_dev);
  117. device_create_file(dev, &integrator_manf_attr);
  118. device_create_file(dev, &integrator_arch_attr);
  119. device_create_file(dev, &integrator_fpga_attr);
  120. device_create_file(dev, &integrator_build_attr);
  121. dev_info(dev, "Detected ARM core module:\n");
  122. dev_info(dev, " Manufacturer: %02x\n", (val >> 24));
  123. dev_info(dev, " Architecture: %s\n", integrator_arch_str(val));
  124. dev_info(dev, " FPGA: %s\n", integrator_fpga_str(val));
  125. dev_info(dev, " Build: %02x\n", (val >> 4) & 0xFF);
  126. dev_info(dev, " Rev: %c\n", ('A' + (val & 0x03)));
  127. return 0;
  128. }
  129. device_initcall(integrator_soc_init);