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: 3074591 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4C5F69F372 for ; Mon, 21 Oct 2013 07:15:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2EA502040F for ; Mon, 21 Oct 2013 07:15:22 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ECDDC203F4 for ; Mon, 21 Oct 2013 07:15:20 +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 1VY9ha-0005DX-E3; Mon, 21 Oct 2013 07:14:58 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VY9hT-0003G5-Q7; Mon, 21 Oct 2013 07:14:51 +0000 Received: from mail-pd0-f179.google.com ([209.85.192.179]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VY9hF-0003Dh-NH for linux-arm-kernel@lists.infradead.org; Mon, 21 Oct 2013 07:14:38 +0000 Received: by mail-pd0-f179.google.com with SMTP id y10so4169850pdj.38 for ; Mon, 21 Oct 2013 00:14:15 -0700 (PDT) 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:in-reply-to :references; bh=L2n1hovF47IjaXY329xf2u3Ux2N3j02LbA59vrNOczs=; b=LByUbasugicHtS7q512sDkF8ugsR7MvkSK6ld0csp95idCh2AT/yi6yCt9hrElwo1K S5sRCYp1BPIj8XODWVSZAPMhnfiBQjUqQ9oH7jPfqLPIev9haDcjOc4jrqdkFbg1MqEQ PhoOcSOO2ni1LuXScR4fqVQprKFBYiGKU4pS+q7JezWlerjQLzjvplDd/oo+Po7+hDV0 2c1ALQZ+dDGFmX5ug4BdeUJCNGBsqEps+7he3TJxhprKoi3DB30kjxB41rpnF2LSZInm reyDFYOwVI7y/Qw1OIGJsNAs3f1X9fMCnyDtU4c2M7iNRY08U1CuMHomzH7OIbcgjywI ywEQ== X-Gm-Message-State: ALoCoQkwKtQ+SZltqBDPvYNhxuM8snVbg2MhdWdzdzrPl65bQm5nXMmpK3litWnGmNP9JCF5BE58 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131021_031437_825446_ACC91F2A X-CRM114-Status: GOOD ( 14.57 ) X-Spam-Score: -1.9 (-) Cc: devicetree@vger.kernel.org, linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Zhangfei Gao 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.6 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 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)