From patchwork Fri Nov 8 05:38:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 21413 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 934C2244F2 for ; Fri, 8 Nov 2013 05:39:19 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id tp5sf5284697ieb.5 for ; Thu, 07 Nov 2013 21:39:19 -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=DPI2sPFVkjd90jVr3jEn2LAfRY0u7QCN2DD/Q1XM8Bc=; b=Q0mj+bIXB++Dv4BamkBj93VDifd/7VHUVaudsagouYuBjy2wFHR9Y2GsPeFx7euQkS xqhrCwRZ60PptBM2R5lSgikltIdG/Hg/D3DgJIQ/BzvF9+EHvPKSYCaNRRdlIZJzJ2Od ACVrKKkc2nfw3jZTmrRNp5vVhZa2t4cqQcvIzMc4XIuW6xToDbFI9ZTEi9BtX9owevry yhS2F+15YfrWuJapAAbwxUtQMQTO36OzfMUxswDSpcPhqKJi4pFhggjhucLEV1HF6RdZ LLybukc4VVqQUlM92KzdMuxPM2UkIW73qLgdr+B1joAMwxmaQJ9MdfzjkX9I/h+6i3CM VxRw== X-Gm-Message-State: ALoCoQlElagkQ3TahDEXuCWThN3rKoV5j+ll4W08Mce0dDRLij7zCIxm0tY8seTdU3bqvT6gJl8Q X-Received: by 10.42.146.6 with SMTP id h6mr3575104icv.2.1383889159110; Thu, 07 Nov 2013 21:39:19 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.25.40 with SMTP id z8ls1428007qef.81.gmail; Thu, 07 Nov 2013 21:39:19 -0800 (PST) X-Received: by 10.52.27.243 with SMTP id w19mr8261051vdg.3.1383889159017; Thu, 07 Nov 2013 21:39:19 -0800 (PST) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id ud10si3222103vcb.66.2013.11.07.21.39.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Nov 2013 21:39:19 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ij19so1059613vcb.26 for ; Thu, 07 Nov 2013 21:39:18 -0800 (PST) X-Received: by 10.52.186.228 with SMTP id fn4mr325870vdc.34.1383889158931; Thu, 07 Nov 2013 21:39: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.220.174.196 with SMTP id u4csp5719vcz; Thu, 7 Nov 2013 21:39:18 -0800 (PST) X-Received: by 10.68.137.9 with SMTP id qe9mr13070906pbb.133.1383889157898; Thu, 07 Nov 2013 21:39:17 -0800 (PST) Received: from mail-pd0-f177.google.com (mail-pd0-f177.google.com [209.85.192.177]) by mx.google.com with ESMTPS id dk5si5163941pbc.256.2013.11.07.21.39.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Nov 2013 21:39:17 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.177 is neither permitted nor denied by best guess record for domain of zhangfei.gao@linaro.org) client-ip=209.85.192.177; Received: by mail-pd0-f177.google.com with SMTP id p10so1640157pdj.8 for ; Thu, 07 Nov 2013 21:39:17 -0800 (PST) X-Received: by 10.68.209.133 with SMTP id mm5mr12769651pbc.157.1383889157498; Thu, 07 Nov 2013 21:39:17 -0800 (PST) Received: from localhost.localdomain ([223.240.21.30]) by mx.google.com with ESMTPSA id rv9sm9285880pbc.4.2013.11.07.21.39.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Nov 2013 21:39:16 -0800 (PST) From: Zhangfei Gao To: Chris Ball , Jaehoon Chung , Seungwon Jeon , Kumar Gala 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: Fri, 8 Nov 2013 13:38:46 +0800 Message-Id: <1383889128-12540-2-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1383889128-12540-1-git-send-email-zhangfei.gao@linaro.org> References: <1383889128-12540-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.220.181 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 | 52 +++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 4bce0de..0d5ad80 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "dw_mmc.h" @@ -1032,20 +1033,26 @@ 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; - if (present) + if (present) { + set_bit(DW_MMC_CARD_PRESENT, &slot->flags); dev_dbg(&mmc->class_dev, "card is present\n"); - else + } else { + clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); dev_dbg(&mmc->class_dev, "card is not present\n"); + } return present; } @@ -1926,10 +1933,6 @@ static void dw_mci_work_routine_card(struct work_struct *work) /* Card change detected */ slot->last_detect_state = present; - /* Mark card as present if applicable */ - if (present != 0) - set_bit(DW_MMC_CARD_PRESENT, &slot->flags); - /* Clean up queue if present */ mrq = slot->mrq; if (mrq) { @@ -1977,8 +1980,6 @@ static void dw_mci_work_routine_card(struct work_struct *work) /* Power down slot */ if (present == 0) { - clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); - /* Clear down the FIFO */ dw_mci_fifo_reset(host); #ifdef CONFIG_MMC_DW_IDMAC @@ -2079,6 +2080,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) { @@ -2096,6 +2121,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) @@ -2197,12 +2227,8 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) #endif /* CONFIG_MMC_DW_IDMAC */ } - if (dw_mci_get_cd(mmc)) - set_bit(DW_MMC_CARD_PRESENT, &slot->flags); - else - 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)