From patchwork Wed Jan 15 15:51:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 23240 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 73B8E206A0 for ; Wed, 15 Jan 2014 15:53:19 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id y10sf2630704pdj.10 for ; Wed, 15 Jan 2014 07:53:18 -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:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=/2usyDjZ74LYz/S4TsmjBX6R9B+V6asgYySTFwvMrWs=; b=T9UUjZ1QotiVW0yoKdKy6yzXdqUm7u+YXXe+nRzdwEEL5GXG5xZDIE9QZU2J6hisD9 4LsZwVpZcZWV0NZ+Y1IjvAKQ5EsaMWScx4gA4XAiRpchv78Sf30+AECQz6YppIIBDvUy WJFaw7DAnJe3FnF34jFcojHhyMiHtmyp+k2rjoTfLG0xUotg/gbHcdFGsStk12sEiWFu C4+O5XFlLzIh4v8DSMEGDXio1voWyoEryg//i+dxNO78RImUYXQaC/83n6d7U5NkUQeM tryw2W5c2KSXmsxh/Rg3z2Foy1x4jkIXq556UC2MhWL6EfEkRsD+eYJoJ9XSLapSLD1L FeLA== X-Gm-Message-State: ALoCoQnbmTXE+gIpK5Ul/JGIj9rhUtXp815XmTZYfQml6DEyEtELt64jt3SQ6s7aVkcgiLZme8h0 X-Received: by 10.68.213.1 with SMTP id no1mr1078031pbc.2.1389801198701; Wed, 15 Jan 2014 07:53:18 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.39.102 with SMTP id o6ls625845qek.28.gmail; Wed, 15 Jan 2014 07:53:18 -0800 (PST) X-Received: by 10.58.235.3 with SMTP id ui3mr208011vec.63.1389801198587; Wed, 15 Jan 2014 07:53:18 -0800 (PST) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx.google.com with ESMTPS id tj7si1854733vdc.46.2014.01.15.07.53.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jan 2014 07:53:18 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.54; Received: by mail-vb0-f54.google.com with SMTP id w20so476278vbb.13 for ; Wed, 15 Jan 2014 07:53:18 -0800 (PST) X-Received: by 10.53.11.69 with SMTP id eg5mr1869774vdd.54.1389801198515; Wed, 15 Jan 2014 07:53:18 -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 ey3csp283612ved; Wed, 15 Jan 2014 07:53:17 -0800 (PST) X-Received: by 10.66.249.134 with SMTP id yu6mr3603412pac.37.1389801197547; Wed, 15 Jan 2014 07:53:17 -0800 (PST) Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com [209.85.160.48]) by mx.google.com with ESMTPS id rt6si4077651pbc.258.2014.01.15.07.53.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jan 2014 07:53:17 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.48 is neither permitted nor denied by best guess record for domain of zhangfei.gao@linaro.org) client-ip=209.85.160.48; Received: by mail-pb0-f48.google.com with SMTP id rr13so1299571pbb.35 for ; Wed, 15 Jan 2014 07:53:17 -0800 (PST) X-Received: by 10.66.27.201 with SMTP id v9mr3730148pag.136.1389801197076; Wed, 15 Jan 2014 07:53:17 -0800 (PST) Received: from localhost.localdomain ([124.73.90.72]) by mx.google.com with ESMTPSA id vp4sm11454721pab.8.2014.01.15.07.53.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jan 2014 07:53:16 -0800 (PST) From: Zhangfei Gao To: 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] mmc: dw_mmc: fix dw_mci_get_cd Date: Wed, 15 Jan 2014 23:51:01 +0800 Message-Id: <1389801061-6023-1-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <52D6A9FF.3000603@linaro.org> References: <52D6A9FF.3000603@linaro.org> 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.212.54 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 --- drivers/mmc/host/dw_mmc.c | 12 +++++++++--- include/linux/mmc/dw_mmc.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index a776f24f4311..8326e54b96a8 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 ^ brd->cd_inverted; 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_get_property(np, "cd-inverted", NULL)) + pdata->cd_inverted = 1; + return pdata; } diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h index 6ce7d2cd3c7a..4535282589ab 100644 --- a/include/linux/mmc/dw_mmc.h +++ b/include/linux/mmc/dw_mmc.h @@ -238,6 +238,7 @@ struct dw_mci_board { u32 caps; /* Capabilities */ u32 caps2; /* More capabilities */ u32 pm_caps; /* PM capabilities */ + u8 cd_inverted; /* * Override fifo depth. If 0, autodetect it from the FIFOTH register, * but note that this may not be reliable after a bootloader has used