From patchwork Fri Mar 21 12:13:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 26806 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 56C76203AB for ; Fri, 21 Mar 2014 12:14:45 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id oy12sf5462671veb.7 for ; Fri, 21 Mar 2014 05:14:45 -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=OjTG9bE3hn8NtBfZd220AaIscnoH07jhMLYRjwvgWLiKBQ0Uur7ymRuAIX3ooB74IS Qpzg79ffCjGQJ3nEcunsMF5QULJylc4O+FQzHKF2MUVLIrfBsx1UjgQmy1RVZdCrI0/T xSNTcVe6MTvWEIpA6eF7xX5ZVok4haaNkAAHodb4czr5M+fC5V0ZQHc6evnWZ1OPZNXq l6d95k7FkW997DSpdqPQygMBlPmXSlQqzArDIS4Mx8VUEjqG95vpKkKCT3qkDbtfuiFP djr4QakabGM3TPhXSXIRyzxWINDm9U8cTVZEPkcT9tMb2jtYkZjyU5nF3WkU7u98n9a1 u3uw== X-Gm-Message-State: ALoCoQkgeInT6TAatyPLCteixYiVkTnqt8OQvDBsWRL5DNyaHYAbBsGmZ/DwjNJ7MjK3wyu+6BX5 X-Received: by 10.58.210.2 with SMTP id mq2mr9448900vec.3.1395404084795; Fri, 21 Mar 2014 05:14:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.136 with SMTP id v8ls611733qgd.17.gmail; Fri, 21 Mar 2014 05:14:44 -0700 (PDT) X-Received: by 10.58.55.170 with SMTP id t10mr7905348vep.29.1395404084687; Fri, 21 Mar 2014 05:14:44 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id h7si1075560vcv.84.2014.03.21.05.14.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Mar 2014 05:14:44 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.179 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.179; Received: by mail-vc0-f179.google.com with SMTP id ij19so2520986vcb.10 for ; Fri, 21 Mar 2014 05:14:44 -0700 (PDT) X-Received: by 10.58.201.5 with SMTP id jw5mr35861081vec.6.1395404084594; Fri, 21 Mar 2014 05:14:44 -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.78.9 with SMTP id i9csp25954vck; Fri, 21 Mar 2014 05:14:43 -0700 (PDT) X-Received: by 10.152.10.72 with SMTP id g8mr442229lab.50.1395404083075; Fri, 21 Mar 2014 05:14:43 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com [209.85.217.175]) by mx.google.com with ESMTPS id w10si3895251lal.147.2014.03.21.05.14.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Mar 2014 05:14:43 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.217.175 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id w7so1562516lbi.20 for ; Fri, 21 Mar 2014 05:14:42 -0700 (PDT) X-Received: by 10.152.37.137 with SMTP id y9mr33454381laj.8.1395404082277; Fri, 21 Mar 2014 05:14:42 -0700 (PDT) Received: from linaro-ulf.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id tq9sm3255263lbb.10.2014.03.21.05.14.40 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Mar 2014 05:14:41 -0700 (PDT) From: Ulf Hansson To: linux-arm-kernel@lists.infradead.org, Russell King , Linus Walleij Cc: devicetree@vger.kernel.org, Ulf Hansson Subject: [PATCH 01/20] mmc: mmci: Convert to the mmc gpio API Date: Fri, 21 Mar 2014 13:13:58 +0100 Message-Id: <1395404057-27835-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1395404057-27835-1-git-send-email-ulf.hansson@linaro.org> References: <1395404057-27835-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.220.179 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;