mvebu: refresh patches
[openwrt/svn-archive/archive.git] / target / linux / mvebu / patches-3.8 / 008-mmc_mvsdio_implement_a_device_tree_binding.patch
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
4 initialization.
5
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.
12
13 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
14 ---
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
19
20 --- /dev/null
21 +++ b/Documentation/devicetree/bindings/mmc/orion-sdio.txt
22 @@ -0,0 +1,17 @@
23 +* Marvell orion-sdio controller
24 +
25 +This file documents differences between the core properties in mmc.txt
26 +and the properties used by the orion-sdio driver.
27 +
28 +- compatible: Should be "marvell,orion-sdio"
29 +- clocks: reference to the clock of the SDIO interface
30 +
31 +Example:
32 +
33 + mvsdio@d00d4000 {
34 + compatible = "marvell,orion-sdio";
35 + reg = <0xd00d4000 0x200>;
36 + interrupts = <54>;
37 + clocks = <&gateclk 17>;
38 + status = "disabled";
39 + };
40 --- a/drivers/mmc/host/mvsdio.c
41 +++ b/drivers/mmc/host/mvsdio.c
42 @@ -21,6 +21,8 @@
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>
50
51 @@ -683,17 +685,17 @@ mv_conf_mbus_windows(struct mvsd_host *h
52
53 static int __init mvsd_probe(struct platform_device *pdev)
54 {
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;
60 struct resource *r;
61 int ret, irq;
62 + int gpio_card_detect, gpio_write_protect;
63
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)
68 + if (!r || irq < 0)
69 return -ENXIO;
70
71 r = request_mem_region(r->start, SZ_1K, DRIVER_NAME);
72 @@ -710,7 +712,35 @@ static int __init mvsd_probe(struct plat
73 host->mmc = mmc;
74 host->dev = &pdev->dev;
75 host->res = r;
76 - host->base_clock = mvsd_data->clock / 2;
77 +
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);
86 +
87 + if (np) {
88 + if (IS_ERR(host->clk)) {
89 + dev_err(&pdev->dev, "DT platforms must have a clock associated\n");
90 + ret = -EINVAL;
91 + goto out;
92 + }
93 +
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);
97 + } else {
98 + const struct mvsdio_platform_data *mvsd_data;
99 + mvsd_data = pdev->dev.platform_data;
100 + if (!mvsd_data)
101 + return -ENXIO;
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;
105 + }
106
107 mmc->ops = &mvsd_ops;
108
109 @@ -750,21 +780,14 @@ static int __init mvsd_probe(struct plat
110 } else
111 host->irq = irq;
112
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);
118 - }
119 -
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);
124 if (ret)
125 goto out;
126 } else
127 mmc->caps |= MMC_CAP_NEEDS_POLL;
128
129 - mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
130 + mmc_gpio_request_ro(mmc, gpio_write_protect);
131
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);
139 + gpio_card_detect);
140 else
141 printk("lacking card detect (fall back to polling)\n");
142 return 0;
143 @@ -855,12 +878,19 @@ static int mvsd_resume(struct platform_d
144 #define mvsd_resume NULL
145 #endif
146
147 +static const struct of_device_id mvsdio_dt_ids[] = {
148 + { .compatible = "marvell,orion-sdio" },
149 + { /* sentinel */ }
150 +};
151 +MODULE_DEVICE_TABLE(of, mvsdio_dt_ids);
152 +
153 static struct platform_driver mvsd_driver = {
154 .remove = __exit_p(mvsd_remove),
155 .suspend = mvsd_suspend,
156 .resume = mvsd_resume,
157 .driver = {
158 .name = DRIVER_NAME,
159 + .of_match_table = mvsdio_dt_ids,
160 },
161 };
162