200-mmc-add-sdio-function-subnode.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. From 8c2057afe84c074ef7cd3ee2ec8e9bed835b9e93 Mon Sep 17 00:00:00 2001
  2. From: Sascha Hauer <s.hauer@pengutronix.de>
  3. Date: Wed, 21 May 2014 19:50:04 +0200
  4. Subject: [PATCH] mmc: Add SDIO function devicetree subnode parsing
  5. This adds SDIO devicetree subnode parsing to the mmc core. While
  6. SDIO devices are runtime probable they sometimes need nonprobable
  7. additional information on embedded systems, like an additional gpio
  8. interrupt or a clock. This patch makes it possible to supply this
  9. information from the devicetree. SDIO drivers will find a pointer
  10. to the devicenode in their devices of_node pointer.
  11. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
  12. [hdegoede@redhat.com: Misc. cleanups]
  13. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  14. ---
  15. drivers/mmc/core/bus.c | 4 ++++
  16. drivers/mmc/core/core.c | 28 ++++++++++++++++++++++++++++
  17. drivers/mmc/core/core.h | 3 +++
  18. drivers/mmc/core/sdio_bus.c | 11 +++++++++++
  19. 4 files changed, 46 insertions(+)
  20. --- a/drivers/mmc/core/bus.c
  21. +++ b/drivers/mmc/core/bus.c
  22. @@ -16,6 +16,7 @@
  23. #include <linux/err.h>
  24. #include <linux/slab.h>
  25. #include <linux/stat.h>
  26. +#include <linux/of.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/mmc/card.h>
  29. @@ -352,6 +353,8 @@ int mmc_add_card(struct mmc_card *card)
  30. #endif
  31. mmc_init_context_info(card->host);
  32. + card->dev.of_node = mmc_of_find_child_device(card->host, 0);
  33. +
  34. ret = device_add(&card->dev);
  35. if (ret)
  36. return ret;
  37. @@ -380,6 +383,7 @@ void mmc_remove_card(struct mmc_card *ca
  38. mmc_hostname(card->host), card->rca);
  39. }
  40. device_del(&card->dev);
  41. + of_node_put(card->dev.of_node);
  42. }
  43. put_device(&card->dev);
  44. --- a/drivers/mmc/core/core.c
  45. +++ b/drivers/mmc/core/core.c
  46. @@ -1231,6 +1231,34 @@ EXPORT_SYMBOL(mmc_of_parse_voltage);
  47. #endif /* CONFIG_OF */
  48. +static int mmc_of_get_func_num(struct device_node *node)
  49. +{
  50. + u32 reg;
  51. + int ret;
  52. +
  53. + ret = of_property_read_u32(node, "reg", &reg);
  54. + if (ret < 0)
  55. + return ret;
  56. +
  57. + return reg;
  58. +}
  59. +
  60. +struct device_node *mmc_of_find_child_device(struct mmc_host *host,
  61. + unsigned func_num)
  62. +{
  63. + struct device_node *node;
  64. +
  65. + if (!host->parent || !host->parent->of_node)
  66. + return NULL;
  67. +
  68. + for_each_child_of_node(host->parent->of_node, node) {
  69. + if (mmc_of_get_func_num(node) == func_num)
  70. + return node;
  71. + }
  72. +
  73. + return NULL;
  74. +}
  75. +
  76. #ifdef CONFIG_REGULATOR
  77. /**
  78. --- a/drivers/mmc/core/core.h
  79. +++ b/drivers/mmc/core/core.h
  80. @@ -32,6 +32,9 @@ struct mmc_bus_ops {
  81. void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
  82. void mmc_detach_bus(struct mmc_host *host);
  83. +struct device_node *mmc_of_find_child_device(struct mmc_host *host,
  84. + unsigned func_num);
  85. +
  86. void mmc_init_erase(struct mmc_card *card);
  87. void mmc_set_chip_select(struct mmc_host *host, int mode);
  88. --- a/drivers/mmc/core/sdio_bus.c
  89. +++ b/drivers/mmc/core/sdio_bus.c
  90. @@ -22,7 +22,9 @@
  91. #include <linux/mmc/card.h>
  92. #include <linux/mmc/host.h>
  93. #include <linux/mmc/sdio_func.h>
  94. +#include <linux/of.h>
  95. +#include "core.h"
  96. #include "sdio_cis.h"
  97. #include "sdio_bus.h"
  98. @@ -303,6 +305,13 @@ static void sdio_acpi_set_handle(struct
  99. static inline void sdio_acpi_set_handle(struct sdio_func *func) {}
  100. #endif
  101. +static void sdio_set_of_node(struct sdio_func *func)
  102. +{
  103. + struct mmc_host *host = func->card->host;
  104. +
  105. + func->dev.of_node = mmc_of_find_child_device(host, func->num);
  106. +}
  107. +
  108. /*
  109. * Register a new SDIO function with the driver model.
  110. */
  111. @@ -312,6 +321,7 @@ int sdio_add_func(struct sdio_func *func
  112. dev_set_name(&func->dev, "%s:%d", mmc_card_id(func->card), func->num);
  113. + sdio_set_of_node(func);
  114. sdio_acpi_set_handle(func);
  115. ret = device_add(&func->dev);
  116. if (ret == 0) {
  117. @@ -335,6 +345,7 @@ void sdio_remove_func(struct sdio_func *
  118. dev_pm_domain_detach(&func->dev, false);
  119. device_del(&func->dev);
  120. + of_node_put(func->dev.of_node);
  121. put_device(&func->dev);
  122. }