4f8cc2011f40c4ea0f0fe60d40e8d9b79e6fe69c
[openwrt.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 diff --git a/Documentation/devicetree/bindings/mmc/orion-sdio.txt b/Documentation/devicetree/bindings/mmc/orion-sdio.txt
21 new file mode 100644
22 index 0000000..84f0ebd
23 --- /dev/null
24 +++ b/Documentation/devicetree/bindings/mmc/orion-sdio.txt
25 @@ -0,0 +1,17 @@
26 +* Marvell orion-sdio controller
27 +
28 +This file documents differences between the core properties in mmc.txt
29 +and the properties used by the orion-sdio driver.
30 +
31 +- compatible: Should be "marvell,orion-sdio"
32 +- clocks: reference to the clock of the SDIO interface
33 +
34 +Example:
35 +
36 +       mvsdio@d00d4000 {
37 +               compatible = "marvell,orion-sdio";
38 +               reg = <0xd00d4000 0x200>;
39 +               interrupts = <54>;
40 +               clocks = <&gateclk 17>;
41 +               status = "disabled";
42 +       };
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
47 @@ -21,6 +21,8 @@
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>
55  
56 @@ -683,17 +685,17 @@ mv_conf_mbus_windows(struct mvsd_host *host,
57  
58  static int __init mvsd_probe(struct platform_device *pdev)
59  {
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;
65         struct resource *r;
66         int ret, irq;
67 +       int gpio_card_detect, gpio_write_protect;
68  
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)
73 +       if (!r || irq < 0)
74                 return -ENXIO;
75  
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)
78         host->mmc = mmc;
79         host->dev = &pdev->dev;
80         host->res = r;
81 -       host->base_clock = mvsd_data->clock / 2;
82 +
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);
91 +
92 +       if (np) {
93 +               if (IS_ERR(host->clk)) {
94 +                       dev_err(&pdev->dev, "DT platforms must have a clock associated\n");
95 +                       ret = -EINVAL;
96 +                       goto out;
97 +               }
98 +
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);
102 +       } else {
103 +               const struct mvsdio_platform_data *mvsd_data;
104 +               mvsd_data = pdev->dev.platform_data;
105 +               if (!mvsd_data)
106 +                       return -ENXIO;
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;
110 +       }
111  
112         mmc->ops = &mvsd_ops;
113  
114 @@ -750,21 +780,14 @@ static int __init mvsd_probe(struct platform_device *pdev)
115         } else
116                 host->irq = irq;
117  
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);
123 -       }
124 -
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);
129                 if (ret)
130                         goto out;
131         } else
132                 mmc->caps |= MMC_CAP_NEEDS_POLL;
133  
134 -       mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
135 +       mmc_gpio_request_ro(mmc, gpio_write_protect);
136  
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);
144 +                      gpio_card_detect);
145         else
146                 printk("lacking card detect (fall back to polling)\n");
147         return 0;
148 @@ -855,12 +878,19 @@ static int mvsd_resume(struct platform_device *dev)
149  #define mvsd_resume    NULL
150  #endif
151  
152 +static const struct of_device_id mvsdio_dt_ids[] = {
153 +       { .compatible = "marvell,orion-sdio" },
154 +       { /* sentinel */ }
155 +};
156 +MODULE_DEVICE_TABLE(of, mvsdio_dt_ids);
157 +
158  static struct platform_driver mvsd_driver = {
159         .remove         = __exit_p(mvsd_remove),
160         .suspend        = mvsd_suspend,
161         .resume         = mvsd_resume,
162         .driver         = {
163                 .name   = DRIVER_NAME,
164 +               .of_match_table = mvsdio_dt_ids,
165         },
166  };
167  
168 -- 
169 1.7.9.5