mmc: slot-gpio: Add debouncing capability to mmc_gpio_request_cd()
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Thu, 8 Aug 2013 10:38:31 +0000 (12:38 +0200)
committerlintao <lintao@rock-chips.com>
Fri, 7 Mar 2014 06:12:09 +0000 (14:12 +0800)
Add a debounce parameter to the mmc_gpio_request_cd() function that
enables GPIO debouncing when set to a non-zero value. This can be used
by MMC host drivers to enable debouncing on the card detect signal.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
Conflicts:
drivers/mmc/host/jz4740_mmc.c
drivers/mmc/host/mvsdio.c

drivers/mmc/core/host.c
drivers/mmc/core/slot-gpio.c
drivers/mmc/host/jz4740_mmc.c
drivers/mmc/host/mvsdio.c
drivers/mmc/host/rk_sdmmc.c
drivers/mmc/host/sdhci-esdhc-imx.c
drivers/mmc/host/sdhci-pxav3.c
drivers/mmc/host/sdhci-sirf.c
drivers/mmc/host/sh_mmcif.c
drivers/mmc/host/tmio_mmc_pio.c
include/linux/mmc/slot-gpio.h

index 5b6182874bcddc0ed633188281e10ada10365d0a..2c886ae341986c0287d599e4c9d80ac19955de7b 100644 (file)
@@ -374,7 +374,7 @@ int mmc_of_parse(struct mmc_host *host)
                        if (!(flags & OF_GPIO_ACTIVE_LOW))
                                gpio_inv_cd = true;
 
-                       ret = mmc_gpio_request_cd(host, gpio);
+                       ret = mmc_gpio_request_cd(host, gpio, 0);
                        if (ret < 0) {
                                dev_err(host->parent,
                                        "Failed to request CD GPIO #%d: %d!\n",
index 324235105519ec0045f2f54c6a833bc6fa639b6e..46596b71a32f49d5934c62d3f5323b26cf6c1658 100644 (file)
@@ -135,6 +135,7 @@ EXPORT_SYMBOL(mmc_gpio_request_ro);
  * mmc_gpio_request_cd - request a gpio for card-detection
  * @host: mmc host
  * @gpio: gpio number requested
+ * @debounce: debounce time in microseconds
  *
  * As devm_* managed functions are used in mmc_gpio_request_cd(), client
  * drivers do not need to explicitly call mmc_gpio_free_cd() for freeing up,
@@ -143,9 +144,14 @@ EXPORT_SYMBOL(mmc_gpio_request_ro);
  * switching for card-detection, they are responsible for calling
  * mmc_gpio_request_cd() and mmc_gpio_free_cd() as a pair on their own.
  *
+ * If GPIO debouncing is desired, set the debounce parameter to a non-zero
+ * value. The caller is responsible for ensuring that the GPIO driver associated
+ * with the GPIO supports debouncing, otherwise an error will be returned.
+ *
  * Returns zero on success, else an error.
  */
-int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
+int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio,
+                       unsigned int debounce)
 {
        struct mmc_gpio *ctx;
        int irq = gpio_to_irq(gpio);
@@ -167,6 +173,12 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
                 */
                return ret;
 
+       if (debounce) {
+               ret = gpio_set_debounce(gpio, debounce);
+               if (ret < 0)
+                       return ret;
+       }
+
        /*
         * Even if gpio_to_irq() returns a valid IRQ number, the platform might
         * still prefer to poll, e.g., because that IRQ number is already used
index 2391c6b7a4bb7ce2629d4bf74c7e70b615560392..ac4885ca88da976e8e82e1a4df7857bdbda40f83 100644 (file)
@@ -741,6 +741,11 @@ static int jz4740_mmc_request_gpios(struct platform_device *pdev)
                        "MMC read only", false, 0);
        if (ret)
                goto err_free_gpio_card_detect;
+       if (gpio_is_valid(pdata->gpio_card_detect)) {
+               ret = mmc_gpio_request_cd(mmc, pdata->gpio_card_detect, 0);
+               if (ret)
+                       return ret;
+       }
 
        ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power,
                        "MMC read only", true, pdata->power_active_low);
index 8960fc846c772c36b5d9bed5ecd06845cad551dd..333568386e2c67d36f8a07a2ca7dbc5034860e40 100644 (file)
@@ -738,6 +738,21 @@ static int __init mvsd_probe(struct platform_device *pdev)
                host->base_clock = mvsd_data->clock / 2;
                gpio_card_detect = mvsd_data->gpio_card_detect ? : -EINVAL;
                gpio_write_protect = mvsd_data->gpio_write_protect ? : -EINVAL;
+               /* GPIO 0 regarded as invalid for backward compatibility */
+               if (mvsd_data->gpio_card_detect &&
+                   gpio_is_valid(mvsd_data->gpio_card_detect)) {
+                       ret = mmc_gpio_request_cd(mmc,
+                                                 mvsd_data->gpio_card_detect,
+                                                 0);
+                       if (ret)
+                               goto out;
+               } else {
+                       mmc->caps |= MMC_CAP_NEEDS_POLL;
+               }
+
+               if (mvsd_data->gpio_write_protect &&
+                   gpio_is_valid(mvsd_data->gpio_write_protect))
+                       mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect);
        }
 
        mmc->ops = &mvsd_ops;
index f2e826235e4ca281babe45b897240434e6574924..0a31358816be8d3c1838cfc64910f55fe6ecc50a 100755 (executable)
@@ -2133,7 +2133,7 @@ static void dw_mci_of_get_cd_gpio(struct device *dev, u8 slot,
        if (!gpio_is_valid(gpio))
                return;
 
-       if (mmc_gpio_request_cd(mmc, gpio))
+       if (mmc_gpio_request_cd(mmc, gpio, 0))
                dev_warn(dev, "gpio [%d] request failed\n", gpio);
 }
 #else /* CONFIG_OF */
index d5f0d59e13104957b7539f28ec743b5713f6bb2e..a0317abb71388d58e5c078e53e0ac4b5e5309367 100644 (file)
@@ -592,7 +592,7 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
        /* card_detect */
        switch (boarddata->cd_type) {
        case ESDHC_CD_GPIO:
-               err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio);
+               err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio, 0);
                if (err) {
                        dev_err(mmc_dev(host->mmc),
                                "failed to request card-detect gpio!\n");
index 1ae358e0662daa4a955cbe86afd784d56e519fc2..ce84208db8aee9dcf5d20555e2d3df5f4cf5f1bd 100644 (file)
@@ -276,7 +276,8 @@ static int sdhci_pxav3_probe(struct platform_device *pdev)
                        host->mmc->pm_caps |= pdata->pm_caps;
 
                if (gpio_is_valid(pdata->ext_cd_gpio)) {
-                       ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio);
+                       ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio,
+                                                 0);
                        if (ret) {
                                dev_err(mmc_dev(host->mmc),
                                        "failed to allocate card detect gpio\n");
index 09805af0526de11b9d723fb384603353f561ef95..b665326d878e422d366b4c34f7e6acb2669dabee 100644 (file)
@@ -97,7 +97,7 @@ static int sdhci_sirf_probe(struct platform_device *pdev)
         * gets setup in sdhci_add_host() and we oops.
         */
        if (gpio_is_valid(priv->gpio_cd)) {
-               ret = mmc_gpio_request_cd(host->mmc, priv->gpio_cd);
+               ret = mmc_gpio_request_cd(host->mmc, priv->gpio_cd, 0);
                if (ret) {
                        dev_err(&pdev->dev, "card detect irq request failed: %d\n",
                                ret);
index ba76a532ae3047d5b3b232a3fa69097c5bfb702e..a23f6c06a282cc635fcc88f465502533dc763c2c 100644 (file)
@@ -1431,7 +1431,7 @@ static int sh_mmcif_probe(struct platform_device *pdev)
        }
 
        if (pd && pd->use_cd_gpio) {
-               ret = mmc_gpio_request_cd(mmc, pd->cd_gpio);
+               ret = mmc_gpio_request_cd(mmc, pd->cd_gpio, 0);
                if (ret < 0)
                        goto erqcd;
        }
index f508ecb5b8a7dcd446aafcfdf4b6a0be857d4f1d..5a1bc3b4ec8b4f3875add73cdf6d9e87611b44e0 100644 (file)
@@ -1091,7 +1091,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host **host,
        dev_pm_qos_expose_latency_limit(&pdev->dev, 100);
 
        if (pdata->flags & TMIO_MMC_USE_GPIO_CD) {
-               ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio);
+               ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio, 0);
                if (ret < 0) {
                        tmio_mmc_host_remove(_host);
                        return ret;
index 7d88d27bfafaf9a337dc201bc8b3296b59fdb6d1..b0c73e4cacea1484fe4790a49514cb004e0af024 100644 (file)
@@ -18,7 +18,8 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio);
 void mmc_gpio_free_ro(struct mmc_host *host);
 
 int mmc_gpio_get_cd(struct mmc_host *host);
-int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio);
+int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio,
+                       unsigned int debounce);
 void mmc_gpio_free_cd(struct mmc_host *host);
 
 #endif