From patchwork Mon Oct 21 07:13:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 21193 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F1FD920356 for ; Mon, 21 Oct 2013 07:14:17 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id db12sf15467198veb.11 for ; Mon, 21 Oct 2013 00:14:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state: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=L2n1hovF47IjaXY329xf2u3Ux2N3j02LbA59vrNOczs=; b=I/1bwaty+ZCGLV6o1OBp3r5W7Qx44vSJ3Tz3+IExW7wr+mhbYsUWKL8r8uCk9iHlYv Zcp/QQTxk22eU2zVS/p/IvIpnL62xUroy3Bh8AF1QbjlcwBQWSMZ2EcDRWLYEH52q/RK j9qegi7DJ/8e2kZjHPDjX8jPIDPFueDmvWCNFV2q/0ddMHc4J9+rKeElhsqb88qPLLB6 mwirZknd2D7K3LnJYV6+U0Cv6EruMA7Kt4AFUHyevQeVb8ecSjiUfzdxsdzclpNlw5gL yHU955wGViVWu0nrhiDEyslnpnWBcVzP7RwtUbOMi8wEzVuTVmTPjilWsf+65C23tpiy nrqQ== X-Received: by 10.58.187.197 with SMTP id fu5mr1715168vec.34.1382339657582; Mon, 21 Oct 2013 00:14:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.47.82 with SMTP id b18ls2066287qen.53.gmail; Mon, 21 Oct 2013 00:14:17 -0700 (PDT) X-Received: by 10.52.37.69 with SMTP id w5mr154997vdj.32.1382339657304; Mon, 21 Oct 2013 00:14:17 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id ta5si1090776veb.69.2013.10.21.00.14.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Oct 2013 00:14:17 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.176 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.176; Received: by mail-ve0-f176.google.com with SMTP id jz11so3785298veb.35 for ; Mon, 21 Oct 2013 00:14:17 -0700 (PDT) X-Gm-Message-State: ALoCoQn1YigPXkwvOVWsEdw82WnWiLCsPA21v3WsGClBTt/QdE3S8MvT9qe3kLrWzwjE0DridJb9 X-Received: by 10.58.107.204 with SMTP id he12mr194511veb.26.1382339657039; Mon, 21 Oct 2013 00:14:17 -0700 (PDT) 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.220.174.196 with SMTP id u4csp130692vcz; Mon, 21 Oct 2013 00:14:16 -0700 (PDT) X-Received: by 10.68.178.197 with SMTP id da5mr16435854pbc.28.1382339656132; Mon, 21 Oct 2013 00:14:16 -0700 (PDT) Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) by mx.google.com with ESMTPS id ds3si7806147pbb.19.2013.10.21.00.14.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Oct 2013 00:14:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.178 is neither permitted nor denied by best guess record for domain of zhangfei.gao@linaro.org) client-ip=209.85.192.178; Received: by mail-pd0-f178.google.com with SMTP id w10so7951748pde.37 for ; Mon, 21 Oct 2013 00:14:15 -0700 (PDT) X-Received: by 10.66.27.4 with SMTP id p4mr16864428pag.25.1382339655728; Mon, 21 Oct 2013 00:14:15 -0700 (PDT) Received: from localhost.localdomain ([60.166.208.201]) by mx.google.com with ESMTPSA id ed3sm18894681pbc.6.2013.10.21.00.14.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Oct 2013 00:14:15 -0700 (PDT) From: Zhangfei Gao To: Chris Ball , Jaehoon Chung , Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Zhangfei Gao Subject: [PATCH 1/2] mmc: dw_mmc: add dw_mci_of_get_cd_gpio to handle cd pin Date: Mon, 21 Oct 2013 15:13:58 +0800 Message-Id: <1382339639-16764-2-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1382339639-16764-1-git-send-email-zhangfei.gao@linaro.org> References: <1382339639-16764-1-git-send-email-zhangfei.gao@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.128.176 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: , Add function dw_mci_of_get_cd_gpio to check "cd-gpios" from dts. mmc_gpio_request_cd and mmc_gpio_get_cd are used to handle cd pin Signed-off-by: Zhangfei Gao CC: Jaehoon Chung --- drivers/mmc/host/dw_mmc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 018f365..b8bb9a5 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "dw_mmc.h" @@ -872,12 +873,15 @@ 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); /* Use platform get_cd function, else try onboard card detect */ if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) present = 1; else if (brd->get_cd) present = !brd->get_cd(slot->id); + else if (!IS_ERR_VALUE(gpio_cd)) + present = !!gpio_cd; else present = (mci_readl(slot->host, CDETECT) & (1 << slot->id)) == 0 ? 1 : 0; @@ -1876,6 +1880,30 @@ 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 */ +static int dw_mci_of_get_cd_gpio(struct device *dev, u8 slot, + struct mmc_host *mmc) +{ + struct device_node *np = dw_mci_of_find_slot_node(dev, slot); + int gpio; + + if (!np) + return -EINVAL; + + gpio = of_get_named_gpio(np, "cd-gpios", 0); + + /* Having a missing entry is valid; return silently */ + if (!gpio_is_valid(gpio)) + return -EINVAL; + + if (mmc_gpio_request_cd(mmc, gpio, 0)) { + dev_warn(dev, "gpio [%d] request failed\n", gpio); + return -EINVAL; + } + + return gpio; +} #else /* CONFIG_OF */ static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) { @@ -1893,6 +1921,11 @@ static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot) { return -EINVAL; } +static int dw_mci_of_get_cd_gpio(struct device *dev, u8 slot, + struct mmc_host *mmc) +{ + return -EINVAL; +} #endif /* CONFIG_OF */ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) @@ -1996,6 +2029,7 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); slot->wp_gpio = dw_mci_of_get_wp_gpio(host->dev, slot->id); + dw_mci_of_get_cd_gpio(host->dev, slot->id, mmc); ret = mmc_add_host(mmc); if (ret)