All of lore.kernel.org
 help / color / mirror / Atom feed
From: thomas.petazzoni@free-electrons.com (Thomas Petazzoni)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 02/18] mmc: mvsdio: use slot-gpio for card detect gpio
Date: Tue, 18 Dec 2012 15:33:47 +0100	[thread overview]
Message-ID: <1355841243-3254-3-git-send-email-thomas.petazzoni@free-electrons.com> (raw)
In-Reply-To: <1355841243-3254-1-git-send-email-thomas.petazzoni@free-electrons.com>

The MMC core subsystem provides in drivers/mmc/core/slot-gpio.c a nice
set of helper functions to simplify the management of the card detect
GPIO in MMC host drivers. This patch migrates the mvsdio driver to
using those helpers, which will make the ->probe() code simpler, and
therefore ease the process of adding a Device Tree binding for this
driver.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 drivers/mmc/host/mvsdio.c |   44 +++++++++-----------------------------------
 1 file changed, 9 insertions(+), 35 deletions(-)

diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index a24a22f..baf19fc 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -54,7 +54,6 @@ struct mvsd_host {
 	struct resource *res;
 	int irq;
 	struct clk *clk;
-	int gpio_card_detect;
 };
 
 #define mvsd_write(offs, val)	writel(val, iobase + (offs))
@@ -540,13 +539,6 @@ static void mvsd_timeout_timer(unsigned long data)
 		mmc_request_done(host->mmc, mrq);
 }
 
-static irqreturn_t mvsd_card_detect_irq(int irq, void *dev)
-{
-	struct mvsd_host *host = dev;
-	mmc_detect_change(host->mmc, msecs_to_jiffies(100));
-	return IRQ_HANDLED;
-}
-
 static void mvsd_enable_sdio_irq(struct mmc_host *mmc, int enable)
 {
 	struct mvsd_host *host = mmc_priv(mmc);
@@ -765,23 +757,11 @@ static int __init mvsd_probe(struct platform_device *pdev)
 		clk_prepare_enable(host->clk);
 	}
 
-	if (mvsd_data->gpio_card_detect) {
-		ret = gpio_request(mvsd_data->gpio_card_detect,
-				   DRIVER_NAME " cd");
-		if (ret == 0) {
-			gpio_direction_input(mvsd_data->gpio_card_detect);
-			irq = gpio_to_irq(mvsd_data->gpio_card_detect);
-			ret = request_irq(irq, mvsd_card_detect_irq,
-					  IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING,
-					  DRIVER_NAME " cd", host);
-			if (ret == 0)
-				host->gpio_card_detect =
-					mvsd_data->gpio_card_detect;
-			else
-				gpio_free(mvsd_data->gpio_card_detect);
-		}
-	}
-	if (!host->gpio_card_detect)
+	if (gpio_is_valid(mvsd_data->gpio_card_detect)) {
+		ret = mmc_gpio_request_cd(mmc, mvsd_data->gpio_card_detect);
+		if (ret)
+			goto out;
+	} else
 		mmc->caps |= MMC_CAP_NEEDS_POLL;
 
 	mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
@@ -794,9 +774,9 @@ static int __init mvsd_probe(struct platform_device *pdev)
 
 	pr_notice("%s: %s driver initialized, ",
 			   mmc_hostname(mmc), DRIVER_NAME);
-	if (host->gpio_card_detect)
+	if (!(mmc->caps & MMC_CAP_NEEDS_POLL))
 		printk("using GPIO %d for card detection\n",
-		       host->gpio_card_detect);
+		       mvsd_data->gpio_card_detect);
 	else
 		printk("lacking card detect (fall back to polling)\n");
 	return 0;
@@ -805,10 +785,7 @@ out:
 	if (host) {
 		if (host->irq)
 			free_irq(host->irq, host);
-		if (host->gpio_card_detect) {
-			free_irq(gpio_to_irq(host->gpio_card_detect), host);
-			gpio_free(host->gpio_card_detect);
-		}
+		mmc_gpio_free_cd(mmc);
 		mmc_gpio_free_ro(mmc);
 		if (host->base)
 			iounmap(host->base);
@@ -832,10 +809,7 @@ static int __exit mvsd_remove(struct platform_device *pdev)
 	if (mmc) {
 		struct mvsd_host *host = mmc_priv(mmc);
 
-		if (host->gpio_card_detect) {
-			free_irq(gpio_to_irq(host->gpio_card_detect), host);
-			gpio_free(host->gpio_card_detect);
-		}
+		mmc_gpio_free_cd(mmc);
 		mmc_remove_host(mmc);
 		free_irq(host->irq, host);
 		mmc_gpio_free_ro(mmc);
-- 
1.7.9.5

  parent reply	other threads:[~2012-12-18 14:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-18 14:33 Device Tree binding for the mvsdio driver and related changes Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 01/18] mmc: mvsdio: use slot-gpio infrastructure for write protect gpio Thomas Petazzoni
2012-12-18 14:33 ` Thomas Petazzoni [this message]
2012-12-18 14:33 ` [PATCH 03/18] mmc: mvsdio: implement a Device Tree binding Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 04/18] mmc: mvsdio: add pinctrl integration Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 05/18] arm: mvebu: add DT information for the SDIO interface of Armada 370/XP Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 06/18] arm: mvebu: add pin muxing options for the SDIO interface on Armada 370 Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 07/18] arm: mvebu: add pin muxing options for the SDIO interface on Armada XP Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 08/18] arm: mvebu: enable the SD card slot on Armada XP DB board Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 09/18] arm: mvebu: enable the SD card slot on Armada 370 " Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 10/18] arm: mvebu: enable the SDIO interface on the Globalscale Mirabox Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 11/18] arm: kirkwood: add Device Tree informations for the SDIO controller Thomas Petazzoni
2012-12-18 14:33 ` [PATCH 12/18] arm: kirkwood: dreamplug: use Device Tree to probe SDIO Thomas Petazzoni
2012-12-18 16:28   ` Andrew Lunn
2012-12-18 14:33 ` [PATCH 13/18] arm: kirkwood: mplcec4: " Thomas Petazzoni
2012-12-18 16:31   ` Andrew Lunn
2012-12-18 14:33 ` [PATCH 14/18] arm: kirkwood: topkick: " Thomas Petazzoni
2012-12-18 14:34 ` [PATCH 15/18] arm: kirkwood: dockstar: remove useless include of SDIO header Thomas Petazzoni
2012-12-18 14:34 ` [PATCH 16/18] arm: mvebu: enable SDIO support in mvebu_defconfig Thomas Petazzoni
2012-12-18 14:34 ` [PATCH 17/18] arm: mvebu: enable mwifiex driver " Thomas Petazzoni
2012-12-18 16:35   ` Andrew Lunn
2012-12-18 14:34 ` [PATCH 18/18] arm: mvebu: enable btmrvl " Thomas Petazzoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1355841243-3254-3-git-send-email-thomas.petazzoni@free-electrons.com \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.