arm-integrator-lm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 <[email protected]>
  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. of_node_put(child);
  50. return ret;
  51. }
  52. }
  53. }
  54. return 0;
  55. }
  56. static const struct of_device_id integrator_ap_syscon_match[] = {
  57. { .compatible = "arm,integrator-ap-syscon"},
  58. { },
  59. };
  60. static int integrator_ap_lm_probe(struct platform_device *pdev)
  61. {
  62. struct device *dev = &pdev->dev;
  63. struct device_node *syscon;
  64. static struct regmap *map;
  65. u32 val;
  66. int ret;
  67. int i;
  68. /* Look up the system controller */
  69. syscon = of_find_matching_node(NULL, integrator_ap_syscon_match);
  70. if (!syscon) {
  71. dev_err(dev,
  72. "could not find Integrator/AP system controller\n");
  73. return -ENODEV;
  74. }
  75. map = syscon_node_to_regmap(syscon);
  76. if (IS_ERR(map)) {
  77. dev_err(dev,
  78. "could not find Integrator/AP system controller\n");
  79. return PTR_ERR(map);
  80. }
  81. ret = regmap_read(map, INTEGRATOR_SC_DEC_OFFSET, &val);
  82. if (ret) {
  83. dev_err(dev, "could not read from Integrator/AP syscon\n");
  84. return ret;
  85. }
  86. /* Loop over the connected modules */
  87. for (i = 0; i < 4; i++) {
  88. if (!(val & BIT(4 + i)))
  89. continue;
  90. dev_info(dev, "detected module in slot %d\n", i);
  91. ret = integrator_lm_populate(i, dev);
  92. if (ret)
  93. return ret;
  94. }
  95. return 0;
  96. }
  97. static const struct of_device_id integrator_ap_lm_match[] = {
  98. { .compatible = "arm,integrator-ap-lm"},
  99. { },
  100. };
  101. static struct platform_driver integrator_ap_lm_driver = {
  102. .probe = integrator_ap_lm_probe,
  103. .driver = {
  104. .name = "integratorap-lm",
  105. .of_match_table = integrator_ap_lm_match,
  106. },
  107. };
  108. module_platform_driver(integrator_ap_lm_driver);
  109. MODULE_AUTHOR("Linus Walleij <[email protected]>");
  110. MODULE_DESCRIPTION("Integrator AP Logical Module driver");
  111. MODULE_LICENSE("GPL v2");