From patchwork Thu Apr 10 12:20:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 28165 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7AB6620671 for ; Thu, 10 Apr 2014 12:21:16 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf12673038pab.9 for ; Thu, 10 Apr 2014 05:21: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: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=39F6dJEVurv9nzN/PI2iaOTPr6Iunuo2890hh8WM9xg=; b=LMXRU9mApe7kxFwdBtnLgbgKnWhR4vWt2wV2I94Dc4KJUK0CIdyOtXjLXIPAsWBPrZ 2e1M4gTBCCgnKkbZWO5jvZ85w1Y1VFKfCXuNtL0SIK6SUTU+A/CP8u/mhBmh145QENsw 0q6u8ItdHk3usFXJPSDrqFt72rsJWkyRW0L8VdM71sNQAhS/vSHWsWMBaocVqfPRf3Xo /OHx1p5MxYc2An0MYpOgZTC18BB+6nEqJll6RNrK1li7rlM0kc4uKSpLJUQByLoQfeS8 my7TWOJuXNipeMONhKdhr0GULQeuteBTcxpsIn5tKJauN0UCQdJ++4+y3trRmh1rrgiW eKJQ== X-Gm-Message-State: ALoCoQnJ0m+tsLy3BivhOWK+4WBr5XFBTWXSDFR9H4d6IIh8Ar0rMq9Fxoj4NvvOKiUdc9B9vXOi X-Received: by 10.66.65.109 with SMTP id w13mr7670662pas.21.1397132475694; Thu, 10 Apr 2014 05:21:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.177 with SMTP id r46ls568232qgd.98.gmail; Thu, 10 Apr 2014 05:21:15 -0700 (PDT) X-Received: by 10.58.126.4 with SMTP id mu4mr14588601veb.0.1397132475554; Thu, 10 Apr 2014 05:21:15 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id xv15si659938veb.98.2014.04.10.05.21.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 10 Apr 2014 05:21:15 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.182 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.182; Received: by mail-ve0-f182.google.com with SMTP id jw12so3425451veb.27 for ; Thu, 10 Apr 2014 05:21:15 -0700 (PDT) X-Received: by 10.221.74.200 with SMTP id yx8mr14149397vcb.3.1397132475460; Thu, 10 Apr 2014 05:21:15 -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.221.72 with SMTP id ib8csp54546vcb; Thu, 10 Apr 2014 05:21:15 -0700 (PDT) X-Received: by 10.194.76.10 with SMTP id g10mr1603924wjw.67.1397132474409; Thu, 10 Apr 2014 05:21:14 -0700 (PDT) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by mx.google.com with ESMTPS id gm5si1489939wjc.6.2014.04.10.05.21.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 10 Apr 2014 05:21:14 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.182 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=209.85.212.182; Received: by mail-wi0-f182.google.com with SMTP id d1so4873564wiv.15 for ; Thu, 10 Apr 2014 05:21:14 -0700 (PDT) X-Received: by 10.180.91.114 with SMTP id cd18mr14976883wib.28.1397132473898; Thu, 10 Apr 2014 05:21:13 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id ej7sm16437292wib.9.2014.04.10.05.21.12 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 10 Apr 2014 05:21:13 -0700 (PDT) From: Ulf Hansson To: linux-arm-kernel@lists.infradead.org, Russell King , Linus Walleij Cc: devicetree@vger.kernel.org, Rob Herring , Ulf Hansson Subject: [PATCH V3 01/19] mmc: mmci: Convert to the mmc gpio API Date: Thu, 10 Apr 2014 14:20:44 +0200 Message-Id: <1397132462-8005-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1397132462-8005-1-git-send-email-ulf.hansson@linaro.org> References: <1397132462-8005-1-git-send-email-ulf.hansson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.182 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: , To avoid duplication of code while handling card detect and write protect GPIO pins/irqs, let's convert to use the mmc gpio API. Signed-off-by: Ulf Hansson --- drivers/mmc/host/mmci.c | 97 ++++++++--------------------------------------- drivers/mmc/host/mmci.h | 3 -- 2 files changed, 15 insertions(+), 85 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 771c60a..b0b81ac 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1326,35 +1327,18 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) pm_runtime_put_autosuspend(mmc_dev(mmc)); } -static int mmci_get_ro(struct mmc_host *mmc) -{ - struct mmci_host *host = mmc_priv(mmc); - - if (host->gpio_wp == -ENOSYS) - return -ENOSYS; - - return gpio_get_value_cansleep(host->gpio_wp); -} - static int mmci_get_cd(struct mmc_host *mmc) { struct mmci_host *host = mmc_priv(mmc); struct mmci_platform_data *plat = host->plat; - unsigned int status; + unsigned int status = mmc_gpio_get_cd(mmc); - if (host->gpio_cd == -ENOSYS) { + if (status == -ENOSYS) { if (!plat->status) return 1; /* Assume always present */ status = plat->status(mmc_dev(host->mmc)); - } else - status = !!gpio_get_value_cansleep(host->gpio_cd) - ^ plat->cd_invert; - - /* - * Use positive logic throughout - status is zero for no card, - * non-zero for card inserted. - */ + } return status; } @@ -1391,21 +1375,12 @@ static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios) return ret; } -static irqreturn_t mmci_cd_irq(int irq, void *dev_id) -{ - struct mmci_host *host = dev_id; - - mmc_detect_change(host->mmc, msecs_to_jiffies(500)); - - return IRQ_HANDLED; -} - static struct mmc_host_ops mmci_ops = { .request = mmci_request, .pre_req = mmci_pre_request, .post_req = mmci_post_request, .set_ios = mmci_set_ios, - .get_ro = mmci_get_ro, + .get_ro = mmc_gpio_get_ro, .get_cd = mmci_get_cd, .start_signal_voltage_switch = mmci_sig_volt_switch, }; @@ -1494,10 +1469,6 @@ static int mmci_probe(struct amba_device *dev, host = mmc_priv(mmc); host->mmc = mmc; - host->gpio_wp = -ENOSYS; - host->gpio_cd = -ENOSYS; - host->gpio_cd_irq = -1; - host->hw_designer = amba_manf(dev); host->hw_revision = amba_rev(dev); dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer); @@ -1568,6 +1539,9 @@ static int mmci_probe(struct amba_device *dev, mmc->caps = plat->capabilities; mmc->caps2 = plat->capabilities2; + if (!plat->cd_invert) + mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; + mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; if (variant->busy_detect) { mmci_ops.card_busy = mmci_card_busy; @@ -1621,49 +1595,23 @@ static int mmci_probe(struct amba_device *dev, goto err_gpio_cd; } if (gpio_is_valid(plat->gpio_cd)) { - ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)"); - if (ret == 0) - ret = gpio_direction_input(plat->gpio_cd); - if (ret == 0) - host->gpio_cd = plat->gpio_cd; - else if (ret != -ENOSYS) + ret = mmc_gpio_request_cd(mmc, plat->gpio_cd, 0); + if (ret) goto err_gpio_cd; - - /* - * A gpio pin that will detect cards when inserted and removed - * will most likely want to trigger on the edges if it is - * 0 when ejected and 1 when inserted (or mutatis mutandis - * for the inverted case) so we request triggers on both - * edges. - */ - ret = request_any_context_irq(gpio_to_irq(plat->gpio_cd), - mmci_cd_irq, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, - DRIVER_NAME " (cd)", host); - if (ret >= 0) - host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd); } if (plat->gpio_wp == -EPROBE_DEFER) { ret = -EPROBE_DEFER; - goto err_gpio_wp; + goto err_gpio_cd; } if (gpio_is_valid(plat->gpio_wp)) { - ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)"); - if (ret == 0) - ret = gpio_direction_input(plat->gpio_wp); - if (ret == 0) - host->gpio_wp = plat->gpio_wp; - else if (ret != -ENOSYS) - goto err_gpio_wp; + ret = mmc_gpio_request_ro(mmc, plat->gpio_wp); + if (ret) + goto err_gpio_cd; } - if ((host->plat->status || host->gpio_cd != -ENOSYS) - && host->gpio_cd_irq < 0) - mmc->caps |= MMC_CAP_NEEDS_POLL; - ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host); if (ret) - goto unmap; + goto err_gpio_cd; if (!dev->irq[1]) host->singleirq = true; @@ -1695,14 +1643,6 @@ static int mmci_probe(struct amba_device *dev, irq0_free: free_irq(dev->irq[0], host); - unmap: - if (host->gpio_wp != -ENOSYS) - gpio_free(host->gpio_wp); - err_gpio_wp: - if (host->gpio_cd_irq >= 0) - free_irq(host->gpio_cd_irq, host); - if (host->gpio_cd != -ENOSYS) - gpio_free(host->gpio_cd); err_gpio_cd: iounmap(host->base); clk_disable: @@ -1741,13 +1681,6 @@ static int mmci_remove(struct amba_device *dev) if (!host->singleirq) free_irq(dev->irq[1], host); - if (host->gpio_wp != -ENOSYS) - gpio_free(host->gpio_wp); - if (host->gpio_cd_irq >= 0) - free_irq(host->gpio_cd_irq, host); - if (host->gpio_cd != -ENOSYS) - gpio_free(host->gpio_cd); - iounmap(host->base); clk_disable_unprepare(host->clk); diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h index 58b1b88..8fc5814 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -176,9 +176,6 @@ struct mmci_host { struct mmc_data *data; struct mmc_host *mmc; struct clk *clk; - int gpio_cd; - int gpio_wp; - int gpio_cd_irq; bool singleirq; spinlock_t lock;