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: 23244 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f199.google.com (mail-gg0-f199.google.com [209.85.161.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4D52A202DA for ; Thu, 16 Jan 2014 02:34:07 +0000 (UTC) Received: by mail-gg0-f199.google.com with SMTP id n5sf3517516ggj.6 for ; Wed, 15 Jan 2014 18:34:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=idj0SJDg7M8QzdiRIvy79V3jLzyIXjyWWeQC3f+31LA=; b=ETtquS+FxsYd4H1heK2rk6HAxPlNuvHDoE9s7/33qOSKdt3J9aoEc/XsXCxuh4jC5f 9uuD9d5njjg/gX8FiIvxPXbB6yW6fLDdF4xPVdFhhYkW3ULo9q6Qh5TjEkt6aLk0m+xP ZFd2sZJrJmZpBAH0bS4/F9E49S8JW6LQ6gnBOCuFcU6f3EtueSUfqaMxlm01zClMl30V +9vUlQXNZBj9nHWsysen/ERHKaORZg18AFh75d192w7fFAHf/n6wP8UDYZGQVP1uoc2A KSZSt5mpdmfHsDkRMjmGnHzA9LotMnOg2cMA1RuZ4S8QzvdKsRz75RJwhTMaCU6MrF7+ wmQg== X-Gm-Message-State: ALoCoQlalL8j2ri1XBNxDsZB6eVn5QTS4UASieWGRfqvo8H1kcFl/gdGHr61S+9a/4GPj+iu5ayz X-Received: by 10.236.13.36 with SMTP id a24mr2038340yha.50.1389839646530; Wed, 15 Jan 2014 18:34:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.35.144 with SMTP id h16ls869589qej.29.gmail; Wed, 15 Jan 2014 18:34:06 -0800 (PST) X-Received: by 10.58.119.161 with SMTP id kv1mr130897veb.21.1389839646461; Wed, 15 Jan 2014 18:34:06 -0800 (PST) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id tc7si2512049vdc.35.2014.01.15.18.34.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jan 2014 18:34:06 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id jy13so756702veb.18 for ; Wed, 15 Jan 2014 18:34:06 -0800 (PST) X-Received: by 10.53.13.44 with SMTP id ev12mr3597638vdd.17.1389839646391; Wed, 15 Jan 2014 18:34:06 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp316116ved; Wed, 15 Jan 2014 18:34:05 -0800 (PST) X-Received: by 10.68.226.200 with SMTP id ru8mr6748654pbc.77.1389839645256; Wed, 15 Jan 2014 18:34:05 -0800 (PST) Received: from mail-pd0-f181.google.com (mail-pd0-f181.google.com [209.85.192.181]) by mx.google.com with ESMTPS id ng9si5482298pbc.136.2014.01.15.18.34.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jan 2014 18:34:05 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.181 is neither permitted nor denied by best guess record for domain of zhangfei.gao@linaro.org) client-ip=209.85.192.181; Received: by mail-pd0-f181.google.com with SMTP id p10so1952316pdj.12 for ; Wed, 15 Jan 2014 18:34:04 -0800 (PST) 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 Cc: linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, patches@linaro.org, Zhangfei Gao 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: zhangfei.gao@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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; }