1 This patch adds a simple Device Tree binding for the mvsdio driver, as
2 well as the necessary documentation for it. Compatibility with non-DT
3 platforms is preserved, by keeping the platform_data based
6 We introduce a small difference between non-DT and DT platforms: DT
7 platforms are required to provide a clocks = <...> property, which the
8 driver uses to get the frequency of the clock that goes to the SDIO
9 IP. The behaviour on non-DT platforms is kept unchanged: a clock
10 reference is not mandatory, but the clock frequency must be passed in
11 the "clock" field of the mvsdio_platform_data structure.
13 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
15 .../devicetree/bindings/mmc/orion-sdio.txt | 17 ++++++
16 drivers/mmc/host/mvsdio.c | 60 +++++++++++++++-----
17 2 files changed, 62 insertions(+), 15 deletions(-)
18 create mode 100644 Documentation/devicetree/bindings/mmc/orion-sdio.txt
20 diff --git a/Documentation/devicetree/bindings/mmc/orion-sdio.txt b/Documentation/devicetree/bindings/mmc/orion-sdio.txt
22 index 0000000..84f0ebd
24 +++ b/Documentation/devicetree/bindings/mmc/orion-sdio.txt
26 +* Marvell orion-sdio controller
28 +This file documents differences between the core properties in mmc.txt
29 +and the properties used by the orion-sdio driver.
31 +- compatible: Should be "marvell,orion-sdio"
32 +- clocks: reference to the clock of the SDIO interface
37 + compatible = "marvell,orion-sdio";
38 + reg = <0xd00d4000 0x200>;
40 + clocks = <&gateclk 17>;
41 + status = "disabled";
43 diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
44 index baf19fc..56954bc 100644
45 --- a/drivers/mmc/host/mvsdio.c
46 +++ b/drivers/mmc/host/mvsdio.c
48 #include <linux/irq.h>
49 #include <linux/clk.h>
50 #include <linux/gpio.h>
51 +#include <linux/of_gpio.h>
52 +#include <linux/of_irq.h>
53 #include <linux/mmc/host.h>
54 #include <linux/mmc/slot-gpio.h>
56 @@ -683,17 +685,17 @@ mv_conf_mbus_windows(struct mvsd_host *host,
58 static int __init mvsd_probe(struct platform_device *pdev)
60 + struct device_node *np = pdev->dev.of_node;
61 struct mmc_host *mmc = NULL;
62 struct mvsd_host *host = NULL;
63 - const struct mvsdio_platform_data *mvsd_data;
64 const struct mbus_dram_target_info *dram;
67 + int gpio_card_detect, gpio_write_protect;
69 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
70 irq = platform_get_irq(pdev, 0);
71 - mvsd_data = pdev->dev.platform_data;
72 - if (!r || irq < 0 || !mvsd_data)
76 r = request_mem_region(r->start, SZ_1K, DRIVER_NAME);
77 @@ -710,7 +712,35 @@ static int __init mvsd_probe(struct platform_device *pdev)
79 host->dev = &pdev->dev;
81 - host->base_clock = mvsd_data->clock / 2;
83 + /* Some non-DT platforms do not pass a clock, and the clock
84 + frequency is passed through platform_data. On DT platforms,
85 + a clock must always be passed, even if there is no gatable
86 + clock associated to the SDIO interface (it can simply be a
87 + fixed rate clock). */
88 + host->clk = clk_get(&pdev->dev, NULL);
89 + if (!IS_ERR(host->clk))
90 + clk_prepare_enable(host->clk);
93 + if (IS_ERR(host->clk)) {
94 + dev_err(&pdev->dev, "DT platforms must have a clock associated\n");
99 + host->base_clock = clk_get_rate(host->clk) / 2;
100 + gpio_card_detect = of_get_named_gpio(np, "cd-gpios", 0);
101 + gpio_write_protect = of_get_named_gpio(np, "wp-gpios", 0);
103 + const struct mvsdio_platform_data *mvsd_data;
104 + mvsd_data = pdev->dev.platform_data;
107 + host->base_clock = mvsd_data->clock / 2;
108 + gpio_card_detect = mvsd_data->gpio_card_detect;
109 + gpio_write_protect = mvsd_data->gpio_write_protect;
112 mmc->ops = &mvsd_ops;
114 @@ -750,21 +780,14 @@ static int __init mvsd_probe(struct platform_device *pdev)
118 - /* Not all platforms can gate the clock, so it is not
119 - an error if the clock does not exists. */
120 - host->clk = clk_get(&pdev->dev, NULL);
121 - if (!IS_ERR(host->clk)) {
122 - clk_prepare_enable(host->clk);
125 - if (gpio_is_valid(mvsd_data->gpio_card_detect)) {
126 - ret = mmc_gpio_request_cd(mmc, mvsd_data->gpio_card_detect);
127 + if (gpio_is_valid(gpio_card_detect)) {
128 + ret = mmc_gpio_request_cd(mmc, gpio_card_detect);
132 mmc->caps |= MMC_CAP_NEEDS_POLL;
134 - mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
135 + mmc_gpio_request_ro(mmc, gpio_write_protect);
137 setup_timer(&host->timer, mvsd_timeout_timer, (unsigned long)host);
138 platform_set_drvdata(pdev, mmc);
139 @@ -776,7 +799,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
140 mmc_hostname(mmc), DRIVER_NAME);
141 if (!(mmc->caps & MMC_CAP_NEEDS_POLL))
142 printk("using GPIO %d for card detection\n",
143 - mvsd_data->gpio_card_detect);
146 printk("lacking card detect (fall back to polling)\n");
148 @@ -855,12 +878,19 @@ static int mvsd_resume(struct platform_device *dev)
149 #define mvsd_resume NULL
152 +static const struct of_device_id mvsdio_dt_ids[] = {
153 + { .compatible = "marvell,orion-sdio" },
156 +MODULE_DEVICE_TABLE(of, mvsdio_dt_ids);
158 static struct platform_driver mvsd_driver = {
159 .remove = __exit_p(mvsd_remove),
160 .suspend = mvsd_suspend,
161 .resume = mvsd_resume,
164 + .of_match_table = mvsdio_dt_ids,