mvebu: switch to 3.10
[openwrt/staging/chunkeey.git] / target / linux / mvebu / patches-3.8 / 008-mmc_mvsdio_implement_a_device_tree_binding.patch
1 From patchwork Wed Jan 16 13:13:59 2013
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 Subject: [4/5] mmc: mvsdio: implement a Device Tree binding
6 Date: Wed, 16 Jan 2013 13:13:59 -0000
7 From: Andrew Lunn <andrew@lunn.ch>
8 X-Patchwork-Id: 1987921
9 Message-Id: <1358342040-7130-5-git-send-email-andrew@lunn.ch>
10 To: Jason Cooper <jason@lakedaemon.net>
11 Cc: linux ARM <linux-arm-kernel@lists.infradead.org>,
12 linux-mmc@vger.kernel.org, linux@arm.linux.org.uk,
13 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
14 Andrew Lunn <andrew@lunn.ch>
15
16 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
17
18 This patch adds a simple Device Tree binding for the mvsdio driver, as
19 well as the necessary documentation for it. Compatibility with non-DT
20 platforms is preserved, by keeping the platform_data based
21 initialization.
22
23 We introduce a small difference between non-DT and DT platforms: DT
24 platforms are required to provide a clocks = <...> property, which the
25 driver uses to get the frequency of the clock that goes to the SDIO
26 IP. The behaviour on non-DT platforms is kept unchanged: a clock
27 reference is not mandatory, but the clock frequency must be passed in
28 the "clock" field of the mvsdio_platform_data structure.
29
30 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
31 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
32 Tested-by: Stefan Peter <s.peter@mpl.ch>
33 Tested-by: Florian Fainelli <florian@openwrt.org>
34 Signed-off-by: Jason Cooper <jason@lakedaemon.net>
35
36 ---
37 .../devicetree/bindings/mmc/orion-sdio.txt | 17 ++++++
38 drivers/mmc/host/mvsdio.c | 62 +++++++++++++++-----
39 2 files changed, 64 insertions(+), 15 deletions(-)
40 create mode 100644 Documentation/devicetree/bindings/mmc/orion-sdio.txt
41
42 --- /dev/null
43 +++ b/Documentation/devicetree/bindings/mmc/orion-sdio.txt
44 @@ -0,0 +1,17 @@
45 +* Marvell orion-sdio controller
46 +
47 +This file documents differences between the core properties in mmc.txt
48 +and the properties used by the orion-sdio driver.
49 +
50 +- compatible: Should be "marvell,orion-sdio"
51 +- clocks: reference to the clock of the SDIO interface
52 +
53 +Example:
54 +
55 + mvsdio@d00d4000 {
56 + compatible = "marvell,orion-sdio";
57 + reg = <0xd00d4000 0x200>;
58 + interrupts = <54>;
59 + clocks = <&gateclk 17>;
60 + status = "disabled";
61 + };
62 --- a/drivers/mmc/host/mvsdio.c
63 +++ b/drivers/mmc/host/mvsdio.c
64 @@ -21,6 +21,8 @@
65 #include <linux/irq.h>
66 #include <linux/clk.h>
67 #include <linux/gpio.h>
68 +#include <linux/of_gpio.h>
69 +#include <linux/of_irq.h>
70 #include <linux/mmc/host.h>
71 #include <linux/mmc/slot-gpio.h>
72
73 @@ -681,17 +683,17 @@ mv_conf_mbus_windows(struct mvsd_host *h
74
75 static int __init mvsd_probe(struct platform_device *pdev)
76 {
77 + struct device_node *np = pdev->dev.of_node;
78 struct mmc_host *mmc = NULL;
79 struct mvsd_host *host = NULL;
80 - const struct mvsdio_platform_data *mvsd_data;
81 const struct mbus_dram_target_info *dram;
82 struct resource *r;
83 int ret, irq;
84 + int gpio_card_detect, gpio_write_protect;
85
86 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
87 irq = platform_get_irq(pdev, 0);
88 - mvsd_data = pdev->dev.platform_data;
89 - if (!r || irq < 0 || !mvsd_data)
90 + if (!r || irq < 0)
91 return -ENXIO;
92
93 mmc = mmc_alloc_host(sizeof(struct mvsd_host), &pdev->dev);
94 @@ -703,8 +705,37 @@ static int __init mvsd_probe(struct plat
95 host = mmc_priv(mmc);
96 host->mmc = mmc;
97 host->dev = &pdev->dev;
98 - host->base_clock = mvsd_data->clock / 2;
99 - host->clk = ERR_PTR(-EINVAL);
100 +
101 + /* Some non-DT platforms do not pass a clock, and the clock
102 + frequency is passed through platform_data. On DT platforms,
103 + a clock must always be passed, even if there is no gatable
104 + clock associated to the SDIO interface (it can simply be a
105 + fixed rate clock). */
106 + host->clk = devm_clk_get(&pdev->dev, NULL);
107 + if (!IS_ERR(host->clk))
108 + clk_prepare_enable(host->clk);
109 +
110 + if (np) {
111 + if (IS_ERR(host->clk)) {
112 + dev_err(&pdev->dev, "DT platforms must have a clock associated\n");
113 + ret = -EINVAL;
114 + goto out;
115 + }
116 +
117 + host->base_clock = clk_get_rate(host->clk) / 2;
118 + gpio_card_detect = of_get_named_gpio(np, "cd-gpios", 0);
119 + gpio_write_protect = of_get_named_gpio(np, "wp-gpios", 0);
120 + } else {
121 + const struct mvsdio_platform_data *mvsd_data;
122 + mvsd_data = pdev->dev.platform_data;
123 + if (!mvsd_data) {
124 + ret = -ENXIO;
125 + goto out;
126 + }
127 + host->base_clock = mvsd_data->clock / 2;
128 + gpio_card_detect = mvsd_data->gpio_card_detect;
129 + gpio_write_protect = mvsd_data->gpio_write_protect;
130 + }
131
132 mmc->ops = &mvsd_ops;
133
134 @@ -743,20 +774,14 @@ static int __init mvsd_probe(struct plat
135 goto out;
136 }
137
138 - /* Not all platforms can gate the clock, so it is not
139 - an error if the clock does not exists. */
140 - host->clk = devm_clk_get(&pdev->dev, NULL);
141 - if (!IS_ERR(host->clk))
142 - clk_prepare_enable(host->clk);
143 -
144 - if (gpio_is_valid(mvsd_data->gpio_card_detect)) {
145 - ret = mmc_gpio_request_cd(mmc, mvsd_data->gpio_card_detect);
146 + if (gpio_is_valid(gpio_card_detect)) {
147 + ret = mmc_gpio_request_cd(mmc, gpio_card_detect);
148 if (ret)
149 goto out;
150 } else
151 mmc->caps |= MMC_CAP_NEEDS_POLL;
152
153 - mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
154 + mmc_gpio_request_ro(mmc, gpio_write_protect);
155
156 setup_timer(&host->timer, mvsd_timeout_timer, (unsigned long)host);
157 platform_set_drvdata(pdev, mmc);
158 @@ -768,7 +793,7 @@ static int __init mvsd_probe(struct plat
159 mmc_hostname(mmc), DRIVER_NAME);
160 if (!(mmc->caps & MMC_CAP_NEEDS_POLL))
161 printk("using GPIO %d for card detection\n",
162 - mvsd_data->gpio_card_detect);
163 + gpio_card_detect);
164 else
165 printk("lacking card detect (fall back to polling)\n");
166 return 0;
167 @@ -832,12 +857,19 @@ static int mvsd_resume(struct platform_d
168 #define mvsd_resume NULL
169 #endif
170
171 +static const struct of_device_id mvsdio_dt_ids[] = {
172 + { .compatible = "marvell,orion-sdio" },
173 + { /* sentinel */ }
174 +};
175 +MODULE_DEVICE_TABLE(of, mvsdio_dt_ids);
176 +
177 static struct platform_driver mvsd_driver = {
178 .remove = __exit_p(mvsd_remove),
179 .suspend = mvsd_suspend,
180 .resume = mvsd_resume,
181 .driver = {
182 .name = DRIVER_NAME,
183 + .of_match_table = mvsdio_dt_ids,
184 },
185 };
186