kernel: generic: update to 3.8-rc6
[openwrt.git] / target / linux / mvebu / patches-3.8 / 007-mmc_mvsdio_use_slot_gpio_for_cd.patch
1 From patchwork Wed Jan 16 13:13:58 2013
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 Subject: [3/5] mmc: mvsdio: use slot-gpio for card detect gpio
6 Date: Wed, 16 Jan 2013 13:13:58 -0000
7 From: Andrew Lunn <andrew@lunn.ch>
8 X-Patchwork-Id: 1987941
9 Message-Id: <1358342040-7130-4-git-send-email-andrew@lunn.ch>
10 To: Jason Cooper <jason@lakedaemon.net>
11 Cc: linux ARM <linux-arm-kernel@lists.infradead.org>,
12  linux-mmc@vger.kernel.org, linux@arm.linux.org.uk,
13  Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
14  Andrew Lunn <andrew@lunn.ch>
15
16 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
17
18 The MMC core subsystem provides in drivers/mmc/core/slot-gpio.c a nice
19 set of helper functions to simplify the management of the card detect
20 GPIO in MMC host drivers. This patch migrates the mvsdio driver to
21 using those helpers, which will make the ->probe() code simpler, and
22 therefore ease the process of adding a Device Tree binding for this
23 driver.
24
25 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
26 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
27 Tested-by: Stefan Peter <s.peter@mpl.ch>
28 Tested-by: Florian Fainelli <florian@openwrt.org>
29 Signed-off-by: Jason Cooper <jason@lakedaemon.net>
30
31 ---
32 drivers/mmc/host/mvsdio.c |   39 +++++++++------------------------------
33  1 file changed, 9 insertions(+), 30 deletions(-)
34
35 --- a/drivers/mmc/host/mvsdio.c
36 +++ b/drivers/mmc/host/mvsdio.c
37 @@ -52,7 +52,6 @@ struct mvsd_host {
38         struct mmc_host *mmc;
39         struct device *dev;
40         struct clk *clk;
41 -       int gpio_card_detect;
42  };
43  
44  #define mvsd_write(offs, val)  writel(val, iobase + (offs))
45 @@ -538,13 +537,6 @@ static void mvsd_timeout_timer(unsigned
46                 mmc_request_done(host->mmc, mrq);
47  }
48  
49 -static irqreturn_t mvsd_card_detect_irq(int irq, void *dev)
50 -{
51 -       struct mvsd_host *host = dev;
52 -       mmc_detect_change(host->mmc, msecs_to_jiffies(100));
53 -       return IRQ_HANDLED;
54 -}
55 -
56  static void mvsd_enable_sdio_irq(struct mmc_host *mmc, int enable)
57  {
58         struct mvsd_host *host = mmc_priv(mmc);
59 @@ -757,26 +749,11 @@ static int __init mvsd_probe(struct plat
60         if (!IS_ERR(host->clk))
61                 clk_prepare_enable(host->clk);
62  
63 -       if (mvsd_data->gpio_card_detect) {
64 -               ret = devm_gpio_request_one(&pdev->dev,
65 -                                           mvsd_data->gpio_card_detect,
66 -                                           GPIOF_IN, DRIVER_NAME " cd");
67 -               if (ret == 0) {
68 -                       irq = gpio_to_irq(mvsd_data->gpio_card_detect);
69 -                       ret = devm_request_irq(&pdev->dev, irq,
70 -                                              mvsd_card_detect_irq,
71 -                                              IRQ_TYPE_EDGE_RISING |
72 -                                              IRQ_TYPE_EDGE_FALLING,
73 -                                              DRIVER_NAME " cd", host);
74 -                       if (ret == 0)
75 -                               host->gpio_card_detect =
76 -                                       mvsd_data->gpio_card_detect;
77 -                       else
78 -                               devm_gpio_free(&pdev->dev,
79 -                                              mvsd_data->gpio_card_detect);
80 -               }
81 -       }
82 -       if (!host->gpio_card_detect)
83 +       if (gpio_is_valid(mvsd_data->gpio_card_detect)) {
84 +               ret = mmc_gpio_request_cd(mmc, mvsd_data->gpio_card_detect);
85 +               if (ret)
86 +                       goto out;
87 +       } else
88                 mmc->caps |= MMC_CAP_NEEDS_POLL;
89  
90         mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
91 @@ -789,15 +766,16 @@ static int __init mvsd_probe(struct plat
92  
93         pr_notice("%s: %s driver initialized, ",
94                            mmc_hostname(mmc), DRIVER_NAME);
95 -       if (host->gpio_card_detect)
96 +       if (!(mmc->caps & MMC_CAP_NEEDS_POLL))
97                 printk("using GPIO %d for card detection\n",
98 -                      host->gpio_card_detect);
99 +                      mvsd_data->gpio_card_detect);
100         else
101                 printk("lacking card detect (fall back to polling)\n");
102         return 0;
103  
104  out:
105         if (mmc) {
106 +               mmc_gpio_free_cd(mmc);
107                 mmc_gpio_free_ro(mmc);
108                 if (!IS_ERR(host->clk))
109                         clk_disable_unprepare(host->clk);
110 @@ -813,6 +791,7 @@ static int __exit mvsd_remove(struct pla
111  
112         struct mvsd_host *host = mmc_priv(mmc);
113  
114 +       mmc_gpio_free_cd(mmc);
115         mmc_gpio_free_ro(mmc);
116         mmc_remove_host(mmc);
117         del_timer_sync(&host->timer);