From patchwork Tue Apr 15 08:33:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 3990061 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9D00BBFF02 for ; Tue, 15 Apr 2014 08:33:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 80872201FB for ; Tue, 15 Apr 2014 08:33:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74E7F201B9 for ; Tue, 15 Apr 2014 08:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751012AbaDOId0 (ORCPT ); Tue, 15 Apr 2014 04:33:26 -0400 Received: from mail-we0-f181.google.com ([74.125.82.181]:50170 "EHLO mail-we0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751001AbaDOIdW (ORCPT ); Tue, 15 Apr 2014 04:33:22 -0400 Received: by mail-we0-f181.google.com with SMTP id q58so8908062wes.26 for ; Tue, 15 Apr 2014 01:33:21 -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; bh=jx8x5eulaMtZggTC9d/JEGMeijEecPYUDWsZa2RTUyE=; b=cMOE2Y9RHyr1dHMJi0SlMRtwKhpsghaCWbLMbZoJmvt2t0+cbNNh4g9LLd/fYi5vmd LWi3/tDFdKJd+iGtAvckzGmPN060EXRifUY4B2jw9YAAikLGH6VFvbjnIPOaSbQ8Qxjp xzCLG7f9PNDlUDNgww71Uv4x6gf4soWPPDZBNatoits+dfN5oseOzuWfc9lnMP+353p1 C0B5bfOoQu88tkFU+ps3dwSV93ZBnqNHqanLqfEw657kPZVehls10A5KT4wo0LsWUfON RzScvFex+pCkozLcHIT4H1OAyr08J0Vqi/mQ42khMy0Cpr0TV7tpXrH2y6faWnt5R66E rhpw== X-Gm-Message-State: ALoCoQmCK4yMIC5QqsGzytMRn+XuDfRFvtB/U+IPyL5z6p2H9LUjMfGbyUhEdrYgTKglL3hEMhgM X-Received: by 10.180.37.178 with SMTP id z18mr13333944wij.46.1397550800841; Tue, 15 Apr 2014 01:33:20 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id kp5sm28704094wjb.30.2014.04.15.01.33.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Apr 2014 01:33:19 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Russell King , Ulf Hansson , Linus Walleij , Alexandre Courbot , Ulf Hansson Subject: [PATCH] mmc: mmci: switch the driver to using gpio descriptors Date: Tue, 15 Apr 2014 10:33:06 +0200 Message-Id: <1397550786-8146-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 The next step in modernization of GPIO is to let drivers handle descriptors rather than integer numbers representing GPIO pins, akin to how clocks or regulators are already handled today. This patch makes the MMCI driver use GPIO descriptos in the core code with fallback code using the platform data if that is not possible. After all platforms with MMCI have been migrated to use descriptors, the platform data entries for GPIO pins can be removed. Cc: Alexandre Courbot Cc: Ulf Hansson Cc: Russell King Signed-off-by: Linus Walleij Reviewed-by: Alexandre Courbot --- Hi Russell,Ulf: there is no hurry to do these changes (only used for my very corner-case MMCI PL181 experiments) but it's the desired direction to use descriptors for GPIOs going forward. I can rebase this on top of Ulf's patch stack any time, no problem. --- drivers/mmc/host/mmci.c | 76 ++++++++++++++++++++++++------------------------- drivers/mmc/host/mmci.h | 4 +-- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 771c60ab4a32..f84e39a5d592 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -1330,10 +1330,10 @@ static int mmci_get_ro(struct mmc_host *mmc) { struct mmci_host *host = mmc_priv(mmc); - if (host->gpio_wp == -ENOSYS) + if (IS_ERR(host->gpio_wp)) return -ENOSYS; - return gpio_get_value_cansleep(host->gpio_wp); + return gpiod_get_value_cansleep(host->gpio_wp); } static int mmci_get_cd(struct mmc_host *mmc) @@ -1342,13 +1342,13 @@ static int mmci_get_cd(struct mmc_host *mmc) struct mmci_platform_data *plat = host->plat; unsigned int status; - if (host->gpio_cd == -ENOSYS) { + if (IS_ERR(host->gpio_cd)) { if (!plat->status) return 1; /* Assume always present */ status = plat->status(mmc_dev(host->mmc)); } else - status = !!gpio_get_value_cansleep(host->gpio_cd) + status = !!gpiod_get_value_cansleep(host->gpio_cd) ^ plat->cd_invert; /* @@ -1412,13 +1412,10 @@ static struct mmc_host_ops mmci_ops = { #ifdef CONFIG_OF static void mmci_dt_populate_generic_pdata(struct device_node *np, - struct mmci_platform_data *pdata) + struct mmci_platform_data *pdata) { int bus_width = 0; - pdata->gpio_wp = of_get_named_gpio(np, "wp-gpios", 0); - pdata->gpio_cd = of_get_named_gpio(np, "cd-gpios", 0); - if (of_get_property(np, "cd-inverted", NULL)) pdata->cd_invert = true; else @@ -1494,9 +1491,20 @@ 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_wp = ERR_PTR(-ENOSYS); + host->gpio_cd = ERR_PTR(-ENOSYS); host->gpio_cd_irq = -1; + /* + * TODO: when we finally get rid of all platform data for all + * platforms deploying the MMCI block, we can delete the + * gpio_to_desc() calls. + */ + host->gpio_wp = gpiod_get(&dev->dev, "wp"); + if (IS_ERR(host->gpio_wp) && gpio_is_valid(plat->gpio_wp)) + host->gpio_wp = gpio_to_desc(plat->gpio_wp); + host->gpio_cd = gpiod_get(&dev->dev, "cd"); + if (IS_ERR(host->gpio_cd) && gpio_is_valid(plat->gpio_wp)) + host->gpio_cd = gpio_to_desc(plat->gpio_cd); host->hw_designer = amba_manf(dev); host->hw_revision = amba_rev(dev); @@ -1616,17 +1624,13 @@ static int mmci_probe(struct amba_device *dev, writel(0, host->base + MMCIMASK1); writel(0xfff, host->base + MMCICLEAR); - if (plat->gpio_cd == -EPROBE_DEFER) { + if (PTR_ERR(host->gpio_cd) == -EPROBE_DEFER) { ret = -EPROBE_DEFER; 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) + if (!IS_ERR(host->gpio_cd)) { + ret = gpiod_direction_input(host->gpio_cd); + if (ret < 0 && ret != -ENOSYS) goto err_gpio_cd; /* @@ -1636,28 +1640,24 @@ static int mmci_probe(struct amba_device *dev, * for the inverted case) so we request triggers on both * edges. */ - ret = request_any_context_irq(gpio_to_irq(plat->gpio_cd), + ret = request_any_context_irq(gpiod_to_irq(host->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); + host->gpio_cd_irq = gpiod_to_irq(host->gpio_cd); } - if (plat->gpio_wp == -EPROBE_DEFER) { + if (PTR_ERR(host->gpio_wp) == -EPROBE_DEFER) { ret = -EPROBE_DEFER; goto err_gpio_wp; } - 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) + if (!IS_ERR(host->gpio_wp)) { + ret = gpiod_direction_input(host->gpio_wp); + if (ret < 0 && ret != -ENOSYS) goto err_gpio_wp; } - if ((host->plat->status || host->gpio_cd != -ENOSYS) + if ((host->plat->status || !IS_ERR(host->gpio_cd)) && host->gpio_cd_irq < 0) mmc->caps |= MMC_CAP_NEEDS_POLL; @@ -1696,13 +1696,13 @@ 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); + if (!IS_ERR(host->gpio_wp)) + gpiod_put(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); + if (!IS_ERR(host->gpio_cd)) + gpiod_put(host->gpio_cd); err_gpio_cd: iounmap(host->base); clk_disable: @@ -1741,12 +1741,12 @@ 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 (!IS_ERR(host->gpio_wp)) + gpiod_put(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); + if (!IS_ERR(host->gpio_cd)) + gpiod_put(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 58b1b8896bf2..b1c1de28201f 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -176,8 +176,8 @@ struct mmci_host { struct mmc_data *data; struct mmc_host *mmc; struct clk *clk; - int gpio_cd; - int gpio_wp; + struct gpio_desc *gpio_cd; + struct gpio_desc *gpio_wp; int gpio_cd_irq; bool singleirq;