mvebu: add inital support for Marvell Armada XP/370 SoCs
[oweals/openwrt.git] / target / linux / mvebu / patches-3.8 / 007-mmc_mvsdio_use_slot_gpio_for_cd.patch
1 The MMC core subsystem provides in drivers/mmc/core/slot-gpio.c a nice
2 set of helper functions to simplify the management of the card detect
3 GPIO in MMC host drivers. This patch migrates the mvsdio driver to
4 using those helpers, which will make the ->probe() code simpler, and
5 therefore ease the process of adding a Device Tree binding for this
6 driver.
7
8 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
9 ---
10  drivers/mmc/host/mvsdio.c |   44 +++++++++-----------------------------------
11  1 file changed, 9 insertions(+), 35 deletions(-)
12
13 diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
14 index a24a22f..baf19fc 100644
15 --- a/drivers/mmc/host/mvsdio.c
16 +++ b/drivers/mmc/host/mvsdio.c
17 @@ -54,7 +54,6 @@ struct mvsd_host {
18         struct resource *res;
19         int irq;
20         struct clk *clk;
21 -       int gpio_card_detect;
22  };
23  
24  #define mvsd_write(offs, val)  writel(val, iobase + (offs))
25 @@ -540,13 +539,6 @@ static void mvsd_timeout_timer(unsigned long data)
26                 mmc_request_done(host->mmc, mrq);
27  }
28  
29 -static irqreturn_t mvsd_card_detect_irq(int irq, void *dev)
30 -{
31 -       struct mvsd_host *host = dev;
32 -       mmc_detect_change(host->mmc, msecs_to_jiffies(100));
33 -       return IRQ_HANDLED;
34 -}
35 -
36  static void mvsd_enable_sdio_irq(struct mmc_host *mmc, int enable)
37  {
38         struct mvsd_host *host = mmc_priv(mmc);
39 @@ -765,23 +757,11 @@ static int __init mvsd_probe(struct platform_device *pdev)
40                 clk_prepare_enable(host->clk);
41         }
42  
43 -       if (mvsd_data->gpio_card_detect) {
44 -               ret = gpio_request(mvsd_data->gpio_card_detect,
45 -                                  DRIVER_NAME " cd");
46 -               if (ret == 0) {
47 -                       gpio_direction_input(mvsd_data->gpio_card_detect);
48 -                       irq = gpio_to_irq(mvsd_data->gpio_card_detect);
49 -                       ret = request_irq(irq, mvsd_card_detect_irq,
50 -                                         IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING,
51 -                                         DRIVER_NAME " cd", host);
52 -                       if (ret == 0)
53 -                               host->gpio_card_detect =
54 -                                       mvsd_data->gpio_card_detect;
55 -                       else
56 -                               gpio_free(mvsd_data->gpio_card_detect);
57 -               }
58 -       }
59 -       if (!host->gpio_card_detect)
60 +       if (gpio_is_valid(mvsd_data->gpio_card_detect)) {
61 +               ret = mmc_gpio_request_cd(mmc, mvsd_data->gpio_card_detect);
62 +               if (ret)
63 +                       goto out;
64 +       } else
65                 mmc->caps |= MMC_CAP_NEEDS_POLL;
66  
67         mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
68 @@ -794,9 +774,9 @@ static int __init mvsd_probe(struct platform_device *pdev)
69  
70         pr_notice("%s: %s driver initialized, ",
71                            mmc_hostname(mmc), DRIVER_NAME);
72 -       if (host->gpio_card_detect)
73 +       if (!(mmc->caps & MMC_CAP_NEEDS_POLL))
74                 printk("using GPIO %d for card detection\n",
75 -                      host->gpio_card_detect);
76 +                      mvsd_data->gpio_card_detect);
77         else
78                 printk("lacking card detect (fall back to polling)\n");
79         return 0;
80 @@ -805,10 +785,7 @@ out:
81         if (host) {
82                 if (host->irq)
83                         free_irq(host->irq, host);
84 -               if (host->gpio_card_detect) {
85 -                       free_irq(gpio_to_irq(host->gpio_card_detect), host);
86 -                       gpio_free(host->gpio_card_detect);
87 -               }
88 +               mmc_gpio_free_cd(mmc);
89                 mmc_gpio_free_ro(mmc);
90                 if (host->base)
91                         iounmap(host->base);
92 @@ -832,10 +809,7 @@ static int __exit mvsd_remove(struct platform_device *pdev)
93         if (mmc) {
94                 struct mvsd_host *host = mmc_priv(mmc);
95  
96 -               if (host->gpio_card_detect) {
97 -                       free_irq(gpio_to_irq(host->gpio_card_detect), host);
98 -                       gpio_free(host->gpio_card_detect);
99 -               }
100 +               mmc_gpio_free_cd(mmc);
101                 mmc_remove_host(mmc);
102                 free_irq(host->irq, host);
103                 mmc_gpio_free_ro(mmc);
104 -- 
105 1.7.9.5