From: Kevin Liu Subject: [PATCH 2/2] mmc: sdhci: add function get_cd Date: Tue, 26 Feb 2013 17:48:26 +0800 Message-ID: <1361872106-24385-1-git-send-email-kliu5@marvell.com> References: Return-path: Received: from na3sys009aog127.obsmtp.com ([74.125.149.107]:56532 "EHLO na3sys009aog127.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932643Ab3BZJsP (ORCPT ); Tue, 26 Feb 2013 04:48:15 -0500 In-Reply-To: Sender: linux-mmc-owner@vger.kernel.org List-Id: linux-mmc@vger.kernel.org To: linux-mmc@vger.kernel.org, Chris Ball , Guennadi Liakhovetski , Sujit Reddy Thumma , Jaehoon Chung , Andy Shevchenko , Aaron Lu , Ulf Hansson , Alexander Stein , Wei WANG , Fabio Estevam , Anton Vorontsov Cc: Stephen Warren , Lars-Peter Clausen , Mike Rapoport , Nicolas Pitre , Adrian Hunter , Philip Rakity , Shawn Guo , Johan Rudholm , Daniel Drake , Jerry Huang , Girish K S , Haijun Zhang , Viresh Kumar , Heiko Stuebner , Thomas Abraham , Chander Kashyap , Sebastian Hesselbarth , Zhangfei Gao , Haojian Zhuang , Chao Xie , Kevin Liu , Kevin Liu 1. mmc_rescan will call get_cd to know whether the card is present before mmc_rescan_try_freq to avoid useless trials during card removal or start host is called when card is not present. 2. get_cd need to be checked to resolve slow card removal issue. Signed-off-by: Kevin Liu --- drivers/mmc/host/sdhci.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 51bbba4..6779760 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1581,6 +1581,36 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) sdhci_runtime_pm_put(host); } +static int sdhci_do_get_cd(struct sdhci_host *host) +{ + int is_detected; + int gpio_cd = mmc_gpio_get_cd(host->mmc); + + if (host->flags & SDHCI_DEVICE_DEAD) + is_detected = 0; + else if (!IS_ERR_VALUE(gpio_cd)) + is_detected = gpio_cd; + else if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) || + (host->mmc->caps & MMC_CAP_NONREMOVABLE)) + is_detected = 1; + else + is_detected = (sdhci_readl(host, SDHCI_PRESENT_STATE) + & SDHCI_CARD_PRESENT); + + return is_detected; +} + +static int sdhci_get_cd(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + int ret; + + sdhci_runtime_pm_get(host); + ret = sdhci_do_get_cd(host); + sdhci_runtime_pm_put(host); + return ret; +} + static int sdhci_check_ro(struct sdhci_host *host) { unsigned long flags; @@ -2038,6 +2068,7 @@ static void sdhci_card_event(struct mmc_host *mmc) static const struct mmc_host_ops sdhci_ops = { .request = sdhci_request, .set_ios = sdhci_set_ios, + .get_cd = sdhci_get_cd, .get_ro = sdhci_get_ro, .hw_reset = sdhci_hw_reset, .enable_sdio_irq = sdhci_enable_sdio_irq, -- 1.7.9.5