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
21 +++ b/Documentation/devicetree/bindings/mmc/orion-sdio.txt
23 +* Marvell orion-sdio controller
25 +This file documents differences between the core properties in mmc.txt
26 +and the properties used by the orion-sdio driver.
28 +- compatible: Should be "marvell,orion-sdio"
29 +- clocks: reference to the clock of the SDIO interface
34 + compatible = "marvell,orion-sdio";
35 + reg = <0xd00d4000 0x200>;
37 + clocks = <&gateclk 17>;
38 + status = "disabled";
40 --- a/drivers/mmc/host/mvsdio.c
41 +++ b/drivers/mmc/host/mvsdio.c
43 #include <linux/irq.h>
44 #include <linux/clk.h>
45 #include <linux/gpio.h>
46 +#include <linux/of_gpio.h>
47 +#include <linux/of_irq.h>
48 #include <linux/mmc/host.h>
49 #include <linux/mmc/slot-gpio.h>
51 @@ -683,17 +685,17 @@ mv_conf_mbus_windows(struct mvsd_host *h
53 static int __init mvsd_probe(struct platform_device *pdev)
55 + struct device_node *np = pdev->dev.of_node;
56 struct mmc_host *mmc = NULL;
57 struct mvsd_host *host = NULL;
58 - const struct mvsdio_platform_data *mvsd_data;
59 const struct mbus_dram_target_info *dram;
62 + int gpio_card_detect, gpio_write_protect;
64 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
65 irq = platform_get_irq(pdev, 0);
66 - mvsd_data = pdev->dev.platform_data;
67 - if (!r || irq < 0 || !mvsd_data)
71 r = request_mem_region(r->start, SZ_1K, DRIVER_NAME);
72 @@ -710,7 +712,35 @@ static int __init mvsd_probe(struct plat
74 host->dev = &pdev->dev;
76 - host->base_clock = mvsd_data->clock / 2;
78 + /* Some non-DT platforms do not pass a clock, and the clock
79 + frequency is passed through platform_data. On DT platforms,
80 + a clock must always be passed, even if there is no gatable
81 + clock associated to the SDIO interface (it can simply be a
82 + fixed rate clock). */
83 + host->clk = clk_get(&pdev->dev, NULL);
84 + if (!IS_ERR(host->clk))
85 + clk_prepare_enable(host->clk);
88 + if (IS_ERR(host->clk)) {
89 + dev_err(&pdev->dev, "DT platforms must have a clock associated\n");
94 + host->base_clock = clk_get_rate(host->clk) / 2;
95 + gpio_card_detect = of_get_named_gpio(np, "cd-gpios", 0);
96 + gpio_write_protect = of_get_named_gpio(np, "wp-gpios", 0);
98 + const struct mvsdio_platform_data *mvsd_data;
99 + mvsd_data = pdev->dev.platform_data;
102 + host->base_clock = mvsd_data->clock / 2;
103 + gpio_card_detect = mvsd_data->gpio_card_detect;
104 + gpio_write_protect = mvsd_data->gpio_write_protect;
107 mmc->ops = &mvsd_ops;
109 @@ -750,21 +780,14 @@ static int __init mvsd_probe(struct plat
113 - /* Not all platforms can gate the clock, so it is not
114 - an error if the clock does not exists. */
115 - host->clk = clk_get(&pdev->dev, NULL);
116 - if (!IS_ERR(host->clk)) {
117 - clk_prepare_enable(host->clk);
120 - if (gpio_is_valid(mvsd_data->gpio_card_detect)) {
121 - ret = mmc_gpio_request_cd(mmc, mvsd_data->gpio_card_detect);
122 + if (gpio_is_valid(gpio_card_detect)) {
123 + ret = mmc_gpio_request_cd(mmc, gpio_card_detect);
127 mmc->caps |= MMC_CAP_NEEDS_POLL;
129 - mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
130 + mmc_gpio_request_ro(mmc, gpio_write_protect);
132 setup_timer(&host->timer, mvsd_timeout_timer, (unsigned long)host);
133 platform_set_drvdata(pdev, mmc);
134 @@ -776,7 +799,7 @@ static int __init mvsd_probe(struct plat
135 mmc_hostname(mmc), DRIVER_NAME);
136 if (!(mmc->caps & MMC_CAP_NEEDS_POLL))
137 printk("using GPIO %d for card detection\n",
138 - mvsd_data->gpio_card_detect);
141 printk("lacking card detect (fall back to polling)\n");
143 @@ -855,12 +878,19 @@ static int mvsd_resume(struct platform_d
144 #define mvsd_resume NULL
147 +static const struct of_device_id mvsdio_dt_ids[] = {
148 + { .compatible = "marvell,orion-sdio" },
151 +MODULE_DEVICE_TABLE(of, mvsdio_dt_ids);
153 static struct platform_driver mvsd_driver = {
154 .remove = __exit_p(mvsd_remove),
155 .suspend = mvsd_suspend,
156 .resume = mvsd_resume,
159 + .of_match_table = mvsdio_dt_ids,