mvebu: refresh patches
[librecmc/librecmc.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 --- a/drivers/mmc/host/mvsdio.c
14 +++ b/drivers/mmc/host/mvsdio.c
15 @@ -54,7 +54,6 @@ struct mvsd_host {
16         struct resource *res;
17         int irq;
18         struct clk *clk;
19 -       int gpio_card_detect;
20  };
21  
22  #define mvsd_write(offs, val)  writel(val, iobase + (offs))
23 @@ -540,13 +539,6 @@ static void mvsd_timeout_timer(unsigned
24                 mmc_request_done(host->mmc, mrq);
25  }
26  
27 -static irqreturn_t mvsd_card_detect_irq(int irq, void *dev)
28 -{
29 -       struct mvsd_host *host = dev;
30 -       mmc_detect_change(host->mmc, msecs_to_jiffies(100));
31 -       return IRQ_HANDLED;
32 -}
33 -
34  static void mvsd_enable_sdio_irq(struct mmc_host *mmc, int enable)
35  {
36         struct mvsd_host *host = mmc_priv(mmc);
37 @@ -765,23 +757,11 @@ static int __init mvsd_probe(struct plat
38                 clk_prepare_enable(host->clk);
39         }
40  
41 -       if (mvsd_data->gpio_card_detect) {
42 -               ret = gpio_request(mvsd_data->gpio_card_detect,
43 -                                  DRIVER_NAME " cd");
44 -               if (ret == 0) {
45 -                       gpio_direction_input(mvsd_data->gpio_card_detect);
46 -                       irq = gpio_to_irq(mvsd_data->gpio_card_detect);
47 -                       ret = request_irq(irq, mvsd_card_detect_irq,
48 -                                         IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING,
49 -                                         DRIVER_NAME " cd", host);
50 -                       if (ret == 0)
51 -                               host->gpio_card_detect =
52 -                                       mvsd_data->gpio_card_detect;
53 -                       else
54 -                               gpio_free(mvsd_data->gpio_card_detect);
55 -               }
56 -       }
57 -       if (!host->gpio_card_detect)
58 +       if (gpio_is_valid(mvsd_data->gpio_card_detect)) {
59 +               ret = mmc_gpio_request_cd(mmc, mvsd_data->gpio_card_detect);
60 +               if (ret)
61 +                       goto out;
62 +       } else
63                 mmc->caps |= MMC_CAP_NEEDS_POLL;
64  
65         mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
66 @@ -794,9 +774,9 @@ static int __init mvsd_probe(struct plat
67  
68         pr_notice("%s: %s driver initialized, ",
69                            mmc_hostname(mmc), DRIVER_NAME);
70 -       if (host->gpio_card_detect)
71 +       if (!(mmc->caps & MMC_CAP_NEEDS_POLL))
72                 printk("using GPIO %d for card detection\n",
73 -                      host->gpio_card_detect);
74 +                      mvsd_data->gpio_card_detect);
75         else
76                 printk("lacking card detect (fall back to polling)\n");
77         return 0;
78 @@ -805,10 +785,7 @@ out:
79         if (host) {
80                 if (host->irq)
81                         free_irq(host->irq, host);
82 -               if (host->gpio_card_detect) {
83 -                       free_irq(gpio_to_irq(host->gpio_card_detect), host);
84 -                       gpio_free(host->gpio_card_detect);
85 -               }
86 +               mmc_gpio_free_cd(mmc);
87                 mmc_gpio_free_ro(mmc);
88                 if (host->base)
89                         iounmap(host->base);
90 @@ -832,10 +809,7 @@ static int __exit mvsd_remove(struct pla
91         if (mmc) {
92                 struct mvsd_host *host = mmc_priv(mmc);
93  
94 -               if (host->gpio_card_detect) {
95 -                       free_irq(gpio_to_irq(host->gpio_card_detect), host);
96 -                       gpio_free(host->gpio_card_detect);
97 -               }
98 +               mmc_gpio_free_cd(mmc);
99                 mmc_remove_host(mmc);
100                 free_irq(host->irq, host);
101                 mmc_gpio_free_ro(mmc);