Skip to contentSkip to conversation

mmc: sdhci-s3c: Use mmc_gpio_request_cd function

PATCH Superseded Beomho Seo 2 participants 2 messages Apr 30, 2014

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Beomho Seo

author
#0 lore raw

PATCH v3 1/1 mmc: sdhci-s3c: Use mmc_gpio_request_cd function

This patch use mmc_gpio_request_cd function.

---
changes in v3:
- rebased to recent mmc-next branch.

changes in v2:
- Fix "err_req_cd:".
- Remove mmc_gpio_free_cd() and then, used sdhci_remove_host().

---
 drivers/mmc/host/sdhci-s3c.c |   56 +++++++++++-------------------------------
 1 file changed, 14 insertions(+), 42 deletions(-)
drivers/mmc/host/sdhci-s3c.c +14 -42
index c12301e..9c0ccdc 100644
@@ -27,6 +27,7 @@
 #include <linux/pm_runtime.h>
 
 #include <linux/mmc/host.h>
+#include <linux/mmc/slot-gpio.h>
 
 #include "sdhci-s3c-regs.h"
 #include "sdhci.h"
@@ -396,44 +397,6 @@ static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
 	}
 }
 
-static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
-{
-	struct sdhci_s3c *sc = dev_id;
-	int status = gpio_get_value(sc->ext_cd_gpio);
-	if (sc->pdata->ext_cd_gpio_invert)
-		status = !status;
-	sdhci_s3c_notify_change(sc->pdev, status);
-	return IRQ_HANDLED;
-}
-
-static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
-{
-	struct s3c_sdhci_platdata *pdata = sc->pdata;
-	struct device *dev = &sc->pdev->dev;
-
-	if (devm_gpio_request(dev, pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) {
-		sc->ext_cd_gpio = pdata->ext_cd_gpio;
-		sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio);
-		if (sc->ext_cd_irq &&
-		    request_threaded_irq(sc->ext_cd_irq, NULL,
-					 sdhci_s3c_gpio_card_detect_thread,
-					 IRQF_TRIGGER_RISING |
-					 IRQF_TRIGGER_FALLING |
-					 IRQF_ONESHOT,
-					 dev_name(dev), sc) == 0) {
-			int status = gpio_get_value(sc->ext_cd_gpio);
-			if (pdata->ext_cd_gpio_invert)
-				status = !status;
-			sdhci_s3c_notify_change(sc->pdev, status);
-		} else {
-			dev_warn(dev, "cannot request irq for card detect\n");
-			sc->ext_cd_irq = 0;
-		}
-	} else {
-		dev_err(dev, "cannot request gpio for card detect\n");
-	}
-}
-
 #ifdef CONFIG_OF
 static int sdhci_s3c_parse_dt(struct device *dev,
 		struct sdhci_host *host, struct s3c_sdhci_platdata *pdata)
@@ -685,8 +648,14 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
 	if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_init)
 		pdata->ext_cd_init(&sdhci_s3c_notify_change);
 	if (pdata->cd_type == S3C_SDHCI_CD_GPIO &&
-	    gpio_is_valid(pdata->ext_cd_gpio))
-		sdhci_s3c_setup_card_detect_gpio(sc);
+	    gpio_is_valid(pdata->ext_cd_gpio)) {
+		ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio, 0);
+		if (ret) {
+			dev_err(dev,
+				"failed to reqeust card detect gpio\n");
+			goto err_req_cd;
+		}
+	}
 
 #ifdef CONFIG_PM_RUNTIME
 	if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL)
@@ -694,6 +663,9 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
 #endif
 	return 0;
 
+ err_req_cd:
+	sdhci_remove_host(host, 1);
+
  err_req_regs:
  err_no_busclks:
 	clk_disable_unprepare(sc->clk_io);
@@ -713,8 +685,8 @@ static int sdhci_s3c_remove(struct platform_device *pdev)
 	if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup)
 		pdata->ext_cd_cleanup(&sdhci_s3c_notify_change);
 
-	if (sc->ext_cd_irq)
-		free_irq(sc->ext_cd_irq, sc);
+	if (pdata->ext_cd_gpio)
+		mmc_gpio_free_cd(host->mmc);
 
 #ifdef CONFIG_PM_RUNTIME
 	if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL)
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 102 lines · Beomho Seo

This patch use mmc_gpio_request_cd function.

---
changes in v3:
- rebased to recent mmc-next branch.

changes in v2:
- Fix "err_req_cd:".
- Remove mmc_gpio_free_cd() and then, used sdhci_remove_host().

---
 drivers/mmc/host/sdhci-s3c.c |   56 +++++++++++-------------------------------
 1 file changed, 14 insertions(+), 42 deletions(-)
drivers/mmc/host/sdhci-s3c.c +12 -40
index c12301e..9c0ccdc 100644
@@ -27,6 +27,7 @@
 #include <linux/pm_runtime.h>
 
 #include <linux/mmc/host.h>
+#include <linux/mmc/slot-gpio.h>
 
 #include "sdhci-s3c-regs.h"
 #include "sdhci.h"
@@ -396,44 +397,6 @@ static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
        }
 }
 
-static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
-{
-       struct sdhci_s3c *sc = dev_id;
-       int status = gpio_get_value(sc->ext_cd_gpio);
-       if (sc->pdata->ext_cd_gpio_invert)
-               status = !status;
-       sdhci_s3c_notify_change(sc->pdev, status);
-       return IRQ_HANDLED;
-}
-
-static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
-{
-       struct s3c_sdhci_platdata *pdata = sc->pdata;
-       struct device *dev = &sc->pdev->dev;
-
-       if (devm_gpio_request(dev, pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) {
-               sc->ext_cd_gpio = pdata->ext_cd_gpio;
-               sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio);
-               if (sc->ext_cd_irq &&
-                   request_threaded_irq(sc->ext_cd_irq, NULL,
-                                        sdhci_s3c_gpio_card_detect_thread,
-                                        IRQF_TRIGGER_RISING |
-                                        IRQF_TRIGGER_FALLING |
-                                        IRQF_ONESHOT,
-                                        dev_name(dev), sc) == 0) {
-                       int status = gpio_get_value(sc->ext_cd_gpio);
-                       if (pdata->ext_cd_gpio_invert)
-                               status = !status;
-                       sdhci_s3c_notify_change(sc->pdev, status);
-               } else {
-                       dev_warn(dev, "cannot request irq for card detect\n");
-                       sc->ext_cd_irq = 0;
-               }
-       } else {
-               dev_err(dev, "cannot request gpio for card detect\n");
-       }
-}
-
 #ifdef CONFIG_OF
 static int sdhci_s3c_parse_dt(struct device *dev,
                struct sdhci_host *host, struct s3c_sdhci_platdata *pdata)
@@ -685,8 +648,14 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
        if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_init)
                pdata->ext_cd_init(&sdhci_s3c_notify_change);
        if (pdata->cd_type == S3C_SDHCI_CD_GPIO &&
-           gpio_is_valid(pdata->ext_cd_gpio))
-               sdhci_s3c_setup_card_detect_gpio(sc);
+           gpio_is_valid(pdata->ext_cd_gpio)) {
+               ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio, 0);
+               if (ret) {
+                       dev_err(dev,
+                               "failed to reqeust card detect gpio\n");
+                       goto err_req_cd;
+               }
+       }
 
 #ifdef CONFIG_PM_RUNTIME
        if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL)
@@ -694,6 +663,9 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
 #endif
        return 0;
 
+ err_req_cd:
+       sdhci_remove_host(host, 1);
+
  err_req_regs:
  err_no_busclks:
        clk_disable_unprepare(sc->clk_io);

drivers/mmc/host/sdhci-s3c.c static int sdhci_s3c_remove(struct platform_device *pdev) · line 689

Quoted 7 lines
drivers/mmc/host/sdhci-s3c.c +2 -2
@@ -713,8 +685,8 @@ static int sdhci_s3c_remove(struct platform_device *pdev)
        if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup)
                pdata->ext_cd_cleanup(&sdhci_s3c_notify_change);
 
-       if (sc->ext_cd_irq)
-               free_irq(sc->ext_cd_irq, sc);
+       if (pdata->ext_cd_gpio)
+               mmc_gpio_free_cd(host->mmc);

This should not be needed since it's handled by the devm* functions.

Kind regards
Ulf Hansson

Quoted 5 lines
drivers/mmc/host/sdhci-s3c.c +0 -1
 #ifdef CONFIG_PM_RUNTIME
        if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL)
--

1.7.9.5