arm-integrator-lm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ARM Integrator Logical Module bus driver
  4. * Copyright (C) 2020 Linaro Ltd.
  5. * Author: Linus Walleij <linus.walleij@linaro.org>
  6. *
  7. * See the device tree bindings for this block for more details on the
  8. * hardware.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/err.h>
  12. #include <linux/io.h>
  13. #include <linux/of.h>
  14. #include <linux/of_address.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/init.h>
  17. #include <linux/slab.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/bitops.h>
  20. #include <linux/mfd/syscon.h>
  21. #include <linux/regmap.h>
  22. /* All information about the connected logic modules are in here */
  23. #define INTEGRATOR_SC_DEC_OFFSET 0x10
  24. /* Base address for the expansion modules */
  25. #define INTEGRATOR_AP_EXP_BASE 0xc0000000
  26. #define INTEGRATOR_AP_EXP_STRIDE 0x10000000
  27. static int integrator_lm_populate(int num, struct device *dev)
  28. {
  29. struct device_node *np = dev->of_node;
  30. struct device_node *child;
  31. u32 base;
  32. int ret;
  33. base = INTEGRATOR_AP_EXP_BASE + (num * INTEGRATOR_AP_EXP_STRIDE);
  34. /* Walk over the child nodes and see what chipselects we use */
  35. for_each_available_child_of_node(np, child) {
  36. struct resource res;
  37. ret = of_address_to_resource(child, 0, &res);
  38. if (ret) {
  39. dev_info(dev, "no valid address on child\n");
  40. continue;
  41. }
  42. /* First populate the syscon then any devices */
  43. if (res.start == base) {
  44. dev_info(dev, "populate module @0x%08x from DT\n",
  45. base);
  46. ret = of_platform_default_populate(child, NULL, dev);
  47. if (ret) {
  48. dev_err(dev, "failed to populate module\n");
  49. return ret;
  50. }
  51. }
  52. }
  53. return 0;
  54. }
  55. static const struct of_device_id integrator_ap_syscon_match[] = {
  56. { .compatible = "arm,integrator-ap-syscon"},
  57. { },
  58. };
  59. static int integrator_ap_lm_probe(struct platform_device *pdev)
  60. {
  61. struct device *dev = &pdev->dev;
  62. struct device_node *syscon;
  63. static struct regmap *map;
  64. u32 val;
  65. int ret;
  66. int i;
  67. /* Look up the system controller */
  68. syscon = of_find_matching_node(NULL, integrator_ap_syscon_match);
  69. if (!syscon) {
  70. dev_err(dev,
  71. "could not find Integrator/AP system controller\n");
  72. return -ENODEV;
  73. }
  74. map = syscon_node_to_regmap(syscon);
  75. if (IS_ERR(map)) {
  76. dev_err(dev,
  77. "could not find Integrator/AP system controller\n");
  78. return PTR_ERR(map);
  79. }
  80. ret = regmap_read(map, INTEGRATOR_SC_DEC_OFFSET, &val);
  81. if (ret) {
  82. dev_err(dev, "could not read from Integrator/AP syscon\n");
  83. return ret;
  84. }
  85. /* Loop over the connected modules */
  86. for (i = 0; i < 4; i++) {
  87. if (!(val & BIT(4 + i)))
  88. continue;
  89. dev_info(dev, "detected module in slot %d\n", i);
  90. ret = integrator_lm_populate(i, dev);
  91. if (ret)
  92. return ret;
  93. }
  94. return 0;
  95. }
  96. static const struct of_device_id integrator_ap_lm_match[] = {
  97. { .compatible = "arm,integrator-ap-lm"},
  98. { },
  99. };
  100. static struct platform_driver integrator_ap_lm_driver = {
  101. .probe = integrator_ap_lm_probe,
  102. .driver = {
  103. .name = "integratorap-lm",
  104. .of_match_table = integrator_ap_lm_match,
  105. },
  106. };
  107. module_platform_driver(integrator_ap_lm_driver);
  108. MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
  109. MODULE_DESCRIPTION("Integrator AP Logical Module driver");
  110. MODULE_LICENSE("GPL v2");