Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: slot-gpio: Add debouncing capability to mmc_gpio_request_cd()

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>

authored by

Laurent Pinchart and committed by
Chris Ball
214fc309 7725a52c

+25 -10
+1 -1
drivers/mmc/core/host.c
··· 374 374 if (!(flags & OF_GPIO_ACTIVE_LOW)) 375 375 gpio_inv_cd = true; 376 376 377 - ret = mmc_gpio_request_cd(host, gpio); 377 + ret = mmc_gpio_request_cd(host, gpio, 0); 378 378 if (ret < 0) { 379 379 dev_err(host->parent, 380 380 "Failed to request CD GPIO #%d: %d!\n",
+13 -1
drivers/mmc/core/slot-gpio.c
··· 135 135 * mmc_gpio_request_cd - request a gpio for card-detection 136 136 * @host: mmc host 137 137 * @gpio: gpio number requested 138 + * @debounce: debounce time in microseconds 138 139 * 139 140 * As devm_* managed functions are used in mmc_gpio_request_cd(), client 140 141 * drivers do not need to explicitly call mmc_gpio_free_cd() for freeing up, ··· 144 143 * switching for card-detection, they are responsible for calling 145 144 * mmc_gpio_request_cd() and mmc_gpio_free_cd() as a pair on their own. 146 145 * 146 + * If GPIO debouncing is desired, set the debounce parameter to a non-zero 147 + * value. The caller is responsible for ensuring that the GPIO driver associated 148 + * with the GPIO supports debouncing, otherwise an error will be returned. 149 + * 147 150 * Returns zero on success, else an error. 148 151 */ 149 - int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) 152 + int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio, 153 + unsigned int debounce) 150 154 { 151 155 struct mmc_gpio *ctx; 152 156 int irq = gpio_to_irq(gpio); ··· 172 166 * is destroyed. 173 167 */ 174 168 return ret; 169 + 170 + if (debounce) { 171 + ret = gpio_set_debounce(gpio, debounce); 172 + if (ret < 0) 173 + return ret; 174 + } 175 175 176 176 /* 177 177 * Even if gpio_to_irq() returns a valid IRQ number, the platform might
+1 -1
drivers/mmc/host/jz4740_mmc.c
··· 713 713 mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; 714 714 715 715 if (gpio_is_valid(pdata->gpio_card_detect)) { 716 - ret = mmc_gpio_request_cd(mmc, pdata->gpio_card_detect); 716 + ret = mmc_gpio_request_cd(mmc, pdata->gpio_card_detect, 0); 717 717 if (ret) 718 718 return ret; 719 719 }
+2 -1
drivers/mmc/host/mvsdio.c
··· 757 757 if (mvsd_data->gpio_card_detect && 758 758 gpio_is_valid(mvsd_data->gpio_card_detect)) { 759 759 ret = mmc_gpio_request_cd(mmc, 760 - mvsd_data->gpio_card_detect); 760 + mvsd_data->gpio_card_detect, 761 + 0); 761 762 if (ret) 762 763 goto out; 763 764 } else {
+1 -1
drivers/mmc/host/sdhci-esdhc-imx.c
··· 616 616 /* card_detect */ 617 617 switch (boarddata->cd_type) { 618 618 case ESDHC_CD_GPIO: 619 - err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio); 619 + err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio, 0); 620 620 if (err) { 621 621 dev_err(mmc_dev(host->mmc), 622 622 "failed to request card-detect gpio!\n");
+2 -1
drivers/mmc/host/sdhci-pxav3.c
··· 278 278 host->mmc->pm_caps |= pdata->pm_caps; 279 279 280 280 if (gpio_is_valid(pdata->ext_cd_gpio)) { 281 - ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio); 281 + ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio, 282 + 0); 282 283 if (ret) { 283 284 dev_err(mmc_dev(host->mmc), 284 285 "failed to allocate card detect gpio\n");
+1 -1
drivers/mmc/host/sdhci-sirf.c
··· 84 84 * gets setup in sdhci_add_host() and we oops. 85 85 */ 86 86 if (gpio_is_valid(priv->gpio_cd)) { 87 - ret = mmc_gpio_request_cd(host->mmc, priv->gpio_cd); 87 + ret = mmc_gpio_request_cd(host->mmc, priv->gpio_cd, 0); 88 88 if (ret) { 89 89 dev_err(&pdev->dev, "card detect irq request failed: %d\n", 90 90 ret);
+1 -1
drivers/mmc/host/sh_mmcif.c
··· 1436 1436 } 1437 1437 1438 1438 if (pd && pd->use_cd_gpio) { 1439 - ret = mmc_gpio_request_cd(mmc, pd->cd_gpio); 1439 + ret = mmc_gpio_request_cd(mmc, pd->cd_gpio, 0); 1440 1440 if (ret < 0) 1441 1441 goto erqcd; 1442 1442 }
+1 -1
drivers/mmc/host/tmio_mmc_pio.c
··· 1110 1110 dev_pm_qos_expose_latency_limit(&pdev->dev, 100); 1111 1111 1112 1112 if (pdata->flags & TMIO_MMC_USE_GPIO_CD) { 1113 - ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio); 1113 + ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio, 0); 1114 1114 if (ret < 0) { 1115 1115 tmio_mmc_host_remove(_host); 1116 1116 return ret;
+2 -1
include/linux/mmc/slot-gpio.h
··· 18 18 void mmc_gpio_free_ro(struct mmc_host *host); 19 19 20 20 int mmc_gpio_get_cd(struct mmc_host *host); 21 - int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio); 21 + int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio, 22 + unsigned int debounce); 22 23 void mmc_gpio_free_cd(struct mmc_host *host); 23 24 24 25 #endif