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
8 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
10 drivers/mmc/host/mvsdio.c | 44 +++++++++-----------------------------------
11 1 file changed, 9 insertions(+), 35 deletions(-)
13 --- a/drivers/mmc/host/mvsdio.c
14 +++ b/drivers/mmc/host/mvsdio.c
15 @@ -54,7 +54,6 @@ struct mvsd_host {
19 - int gpio_card_detect;
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);
27 -static irqreturn_t mvsd_card_detect_irq(int irq, void *dev)
29 - struct mvsd_host *host = dev;
30 - mmc_detect_change(host->mmc, msecs_to_jiffies(100));
34 static void mvsd_enable_sdio_irq(struct mmc_host *mmc, int enable)
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);
41 - if (mvsd_data->gpio_card_detect) {
42 - ret = gpio_request(mvsd_data->gpio_card_detect,
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);
51 - host->gpio_card_detect =
52 - mvsd_data->gpio_card_detect;
54 - gpio_free(mvsd_data->gpio_card_detect);
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);
63 mmc->caps |= MMC_CAP_NEEDS_POLL;
65 mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
66 @@ -794,9 +774,9 @@ static int __init mvsd_probe(struct plat
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);
76 printk("lacking card detect (fall back to polling)\n");
78 @@ -805,10 +785,7 @@ out:
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);
86 + mmc_gpio_free_cd(mmc);
87 mmc_gpio_free_ro(mmc);
90 @@ -832,10 +809,7 @@ static int __exit mvsd_remove(struct pla
92 struct mvsd_host *host = mmc_priv(mmc);
94 - if (host->gpio_card_detect) {
95 - free_irq(gpio_to_irq(host->gpio_card_detect), host);
96 - gpio_free(host->gpio_card_detect);
98 + mmc_gpio_free_cd(mmc);
100 free_irq(host->irq, host);
101 mmc_gpio_free_ro(mmc);