From patchwork Thu Jan 16 02:31:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 3496651 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 03776C02DC for ; Thu, 16 Jan 2014 02:34:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3855E2017D for ; Thu, 16 Jan 2014 02:34:47 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 24E9D20165 for ; Thu, 16 Jan 2014 02:34:46 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W3cmv-0004jh-Sl; Thu, 16 Jan 2014 02:34:34 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W3cmt-00036r-Fw; Thu, 16 Jan 2014 02:34:31 +0000 Received: from mail-pd0-f174.google.com ([209.85.192.174]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W3cmq-00035y-Cj for linux-arm-kernel@lists.infradead.org; Thu, 16 Jan 2014 02:34:29 +0000 Received: by mail-pd0-f174.google.com with SMTP id w10so1962356pde.33 for ; Wed, 15 Jan 2014 18:34:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=idj0SJDg7M8QzdiRIvy79V3jLzyIXjyWWeQC3f+31LA=; b=eMy273qJYX15eq2SVrcUjxqj4+sJS/8FktiqDtDBXpAYzJIhNeYfwXQNc2cyWTzFEV qOOsizP6jxVTNVwAhlhAXKEwg4Aa8SIJzuMCKHKc4yi1ApkAILttM1zuApQl0q2Syai+ MxRl+gTedXiuPLRqcTOy+6QOXqFGMdTxmOTw1htI+4348UUlyoKzxTE03BTXqfsohwqp RSUK6dajLtEZ7J22NSEsS4FBS/R8TH43OZfb9jwRONOqFGnZPTFUq61dYL1eXT1yeQiK vaMrll0TvBQg5ekRCHS3Rh/DmIypmYHen57t5bE/k6aU7NCZUhOt7Gun/VIWNhpvZDs7 TAPA== X-Gm-Message-State: ALoCoQnKxYwc4vklJjPpVRjMZLmHYwn2asdKzm9KxsL+EoUVOErSKGwDiiaKuBUvIBrWKDpMJdZD X-Received: by 10.66.122.40 with SMTP id lp8mr6897390pab.82.1389839644815; Wed, 15 Jan 2014 18:34:04 -0800 (PST) Received: from localhost.localdomain ([124.73.90.72]) by mx.google.com with ESMTPSA id xu8sm14696873pab.0.2014.01.15.18.33.54 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jan 2014 18:34:04 -0800 (PST) From: Zhangfei Gao To: Russell King - ARM Linux , Kevin Hilman , Sachin Kamat , Chris Ball , Arnd Bergmann , Mike Turquette , Jaehoon Chung , Seungwon Jeon Subject: [PATCH v2] mmc: dw_mmc: fix dw_mci_get_cd Date: Thu, 16 Jan 2014 10:31:42 +0800 Message-Id: <1389839502-13046-1-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140115_213428_525149_3D0A4FB9 X-CRM114-Status: GOOD ( 14.70 ) X-Spam-Score: -1.9 (-) Cc: Zhangfei Gao , linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, patches@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduced from commit bf626e5550f24aec24975a0e85ad8e572ca76a6b CDETECT is ignored since negated return value of mmc_gpio_get_cd(mmc) can not be checked by IS_ERR_VALUE. Add spin_lock_bh(&host->lock) for atomic accessing DW_MMC_CARD_PRESENT, otherwise sd detect may occasionally fail. Signed-off-by: Zhangfei Gao Reported-by: Kevin Hilman Reviewed-by: Sachin Kamat Tested-by: Sachin Kamat --- .../devicetree/bindings/mmc/synopsys-dw-mshc.txt | 2 ++ drivers/mmc/host/dw_mmc.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt b/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt index 8f3f13315358..18b0819bafe0 100644 --- a/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt +++ b/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt @@ -73,6 +73,8 @@ Optional properties: * caps2-mmc-hs200-1_2v: Supports mmc HS200 SDR 1.2V mode +* caps2-mmc-cd-active-high: cd pin is high when card present + * broken-cd: as documented in mmc core bindings. * vmmc-supply: The phandle to the regulator to use for vmmc. If this is diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index a776f24f4311..ad65b895d34c 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -1033,7 +1033,8 @@ static int dw_mci_get_cd(struct mmc_host *mmc) int present; struct dw_mci_slot *slot = mmc_priv(mmc); struct dw_mci_board *brd = slot->host->pdata; - int gpio_cd = !mmc_gpio_get_cd(mmc); + struct dw_mci *host = slot->host; + int gpio_cd = mmc_gpio_get_cd(mmc); /* Use platform get_cd function, else try onboard card detect */ if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) @@ -1041,11 +1042,12 @@ static int dw_mci_get_cd(struct mmc_host *mmc) else if (brd->get_cd) present = !brd->get_cd(slot->id); else if (!IS_ERR_VALUE(gpio_cd)) - present = !!gpio_cd; + present = gpio_cd; else present = (mci_readl(slot->host, CDETECT) & (1 << slot->id)) == 0 ? 1 : 0; + spin_lock_bh(&host->lock); if (present) { set_bit(DW_MMC_CARD_PRESENT, &slot->flags); dev_dbg(&mmc->class_dev, "card is present\n"); @@ -1053,6 +1055,7 @@ static int dw_mci_get_cd(struct mmc_host *mmc) clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); dev_dbg(&mmc->class_dev, "card is not present\n"); } + spin_unlock_bh(&host->lock); return present; } @@ -2081,7 +2084,7 @@ static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot) return gpio; } -/* find the cd gpio for a given slot; or -1 if none specified */ +/* find the cd gpio for a given slot */ static void dw_mci_of_get_cd_gpio(struct device *dev, u8 slot, struct mmc_host *mmc) { @@ -2411,6 +2414,9 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) if (of_find_property(np, "caps2-mmc-hs200-1_2v", NULL)) pdata->caps2 |= MMC_CAP2_HS200_1_2V_SDR; + if (of_find_property(np, "caps2-mmc-cd-active-high", NULL)) + pdata->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; + return pdata; }