soc-realview.c 3.8 KB

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