1 From patchwork Wed Jan 16 13:13:59 2013
2 Content-Type: text/plain; charset="utf-8"
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>
16 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
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
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.
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>
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
43 +++ b/Documentation/devicetree/bindings/mmc/orion-sdio.txt
45 +* Marvell orion-sdio controller
47 +This file documents differences between the core properties in mmc.txt
48 +and the properties used by the orion-sdio driver.
50 +- compatible: Should be "marvell,orion-sdio"
51 +- clocks: reference to the clock of the SDIO interface
56 + compatible = "marvell,orion-sdio";
57 + reg = <0xd00d4000 0x200>;
59 + clocks = <&gateclk 17>;
60 + status = "disabled";
62 --- a/drivers/mmc/host/mvsdio.c
63 +++ b/drivers/mmc/host/mvsdio.c
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>
73 @@ -681,17 +683,17 @@ mv_conf_mbus_windows(struct mvsd_host *h
75 static int __init mvsd_probe(struct platform_device *pdev)
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;
84 + int gpio_card_detect, gpio_write_protect;
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)
93 mmc = mmc_alloc_host(sizeof(struct mvsd_host), &pdev->dev);
94 @@ -703,8 +705,37 @@ static int __init mvsd_probe(struct plat
97 host->dev = &pdev->dev;
98 - host->base_clock = mvsd_data->clock / 2;
99 - host->clk = ERR_PTR(-EINVAL);
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);
111 + if (IS_ERR(host->clk)) {
112 + dev_err(&pdev->dev, "DT platforms must have a clock associated\n");
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);
121 + const struct mvsdio_platform_data *mvsd_data;
122 + mvsd_data = pdev->dev.platform_data;
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;
132 mmc->ops = &mvsd_ops;
134 @@ -743,20 +774,14 @@ static int __init mvsd_probe(struct plat
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);
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);
151 mmc->caps |= MMC_CAP_NEEDS_POLL;
153 - mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
154 + mmc_gpio_request_ro(mmc, gpio_write_protect);
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);
165 printk("lacking card detect (fall back to polling)\n");
167 @@ -832,12 +857,19 @@ static int mvsd_resume(struct platform_d
168 #define mvsd_resume NULL
171 +static const struct of_device_id mvsdio_dt_ids[] = {
172 + { .compatible = "marvell,orion-sdio" },
175 +MODULE_DEVICE_TABLE(of, mvsdio_dt_ids);
177 static struct platform_driver mvsd_driver = {
178 .remove = __exit_p(mvsd_remove),
179 .suspend = mvsd_suspend,
180 .resume = mvsd_resume,
183 + .of_match_table = mvsdio_dt_ids,