[wilink8-wlan/build-utilites.git] / patches / kernel_patches / imx-3.14.28 / 0010-mmc-Add-SDIO-function-devicetree-subnode-parsing.patch
1 From f7411890987cd0d0bd33b2fc86ebe34bddd81847 Mon Sep 17 00:00:00 2001
2 From: Sascha Hauer <s.hauer@pengutronix.de>
3 Date: Mon, 30 Jun 2014 11:07:25 +0200
4 Subject: [PATCH 10/10] mmc: Add SDIO function devicetree subnode parsing
6 This adds SDIO devicetree subnode parsing to the mmc core. While
7 SDIO devices are runtime probable they sometimes need nonprobable
8 additional information on embedded systems, like an additional gpio
9 interrupt or a clock. This patch makes it possible to supply this
10 information from the devicetree. SDIO drivers will find a pointer
11 to the devicenode in their devices of_node pointer.
13 Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
14 [hdegoede@redhat.com: Misc. cleanups]
15 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
16 Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
17 ---
18 drivers/mmc/core/bus.c | 4 ++++
19 drivers/mmc/core/core.c | 28 ++++++++++++++++++++++++++++
20 drivers/mmc/core/core.h | 3 +++
21 drivers/mmc/core/sdio_bus.c | 11 +++++++++++
22 4 files changed, 46 insertions(+)
24 diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
25 index 64145a3..0c431a2 100644
26 --- a/drivers/mmc/core/bus.c
27 +++ b/drivers/mmc/core/bus.c
28 @@ -16,6 +16,7 @@
29 #include <linux/err.h>
30 #include <linux/slab.h>
31 #include <linux/stat.h>
32 +#include <linux/of.h>
33 #include <linux/pm_runtime.h>
35 #include <linux/mmc/card.h>
36 @@ -367,6 +368,8 @@ int mmc_add_card(struct mmc_card *card)
37 #endif
38 mmc_init_context_info(card->host);
40 + card->dev.of_node = mmc_of_find_child_device(card->host, 0);
41 +
42 ret = device_add(&card->dev);
43 if (ret)
44 return ret;
45 @@ -395,6 +398,7 @@ void mmc_remove_card(struct mmc_card *card)
46 mmc_hostname(card->host), card->rca);
47 }
48 device_del(&card->dev);
49 + of_node_put(card->dev.of_node);
50 }
52 put_device(&card->dev);
53 diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
54 index e65a857..769d7a9 100644
55 --- a/drivers/mmc/core/core.c
56 +++ b/drivers/mmc/core/core.c
57 @@ -1217,6 +1217,34 @@ EXPORT_SYMBOL(mmc_of_parse_voltage);
59 #endif /* CONFIG_OF */
61 +static int mmc_of_get_func_num(struct device_node *node)
62 +{
63 + u32 reg;
64 + int ret;
65 +
66 + ret = of_property_read_u32(node, "reg", ®);
67 + if (ret < 0)
68 + return ret;
69 +
70 + return reg;
71 +}
72 +
73 +struct device_node *mmc_of_find_child_device(struct mmc_host *host,
74 + unsigned func_num)
75 +{
76 + struct device_node *node;
77 +
78 + if (!host->parent || !host->parent->of_node)
79 + return NULL;
80 +
81 + for_each_child_of_node(host->parent->of_node, node) {
82 + if (mmc_of_get_func_num(node) == func_num)
83 + return node;
84 + }
85 +
86 + return NULL;
87 +}
88 +
89 #ifdef CONFIG_REGULATOR
91 /**
92 diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
93 index 443a584..f712f6e 100644
94 --- a/drivers/mmc/core/core.h
95 +++ b/drivers/mmc/core/core.h
96 @@ -32,6 +32,9 @@ struct mmc_bus_ops {
97 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
98 void mmc_detach_bus(struct mmc_host *host);
100 +struct device_node *mmc_of_find_child_device(struct mmc_host *host,
101 + unsigned func_num);
102 +
103 void mmc_init_erase(struct mmc_card *card);
105 void mmc_set_chip_select(struct mmc_host *host, int mode);
106 diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
107 index 92d1ba8..35c23ae 100644
108 --- a/drivers/mmc/core/sdio_bus.c
109 +++ b/drivers/mmc/core/sdio_bus.c
110 @@ -21,7 +21,9 @@
111 #include <linux/mmc/card.h>
112 #include <linux/mmc/host.h>
113 #include <linux/mmc/sdio_func.h>
114 +#include <linux/of.h>
116 +#include "core.h"
117 #include "sdio_cis.h"
118 #include "sdio_bus.h"
120 @@ -314,6 +316,13 @@ static void sdio_acpi_set_handle(struct sdio_func *func)
121 static inline void sdio_acpi_set_handle(struct sdio_func *func) {}
122 #endif
124 +static void sdio_set_of_node(struct sdio_func *func)
125 +{
126 + struct mmc_host *host = func->card->host;
127 +
128 + func->dev.of_node = mmc_of_find_child_device(host, func->num);
129 +}
130 +
131 /*
132 * Register a new SDIO function with the driver model.
133 */
134 @@ -323,6 +332,7 @@ int sdio_add_func(struct sdio_func *func)
136 dev_set_name(&func->dev, "%s:%d", mmc_card_id(func->card), func->num);
138 + sdio_set_of_node(func);
139 sdio_acpi_set_handle(func);
140 ret = device_add(&func->dev);
141 if (ret == 0) {
142 @@ -346,6 +356,7 @@ void sdio_remove_func(struct sdio_func *func)
144 acpi_dev_pm_detach(&func->dev, false);
145 device_del(&func->dev);
146 + of_node_put(func->dev.of_node);
147 put_device(&func->dev);
148 }
150 --
151 1.7.9.5