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: 28398 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B94D72036A for ; Tue, 15 Apr 2014 08:33:29 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id wp18sf49898329obc.8 for ; Tue, 15 Apr 2014 01:33:29 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=XjKmybpvRW0mS1P7+DXKoSxKsdf7TMfnQaBgha4ZkjQ=; b=cb1VDJGWCrYrywWaLLMEKJdgmT8TLPHezmQTrXFFtJJdbAB75Olg7ltmRJVkEeM8fz OyFud8/bhSBGHHfkM5ONza69mR2yquH6e3MZ9iJc8FlahC98G9RIXoVSeTJHFzQgSFy4 JUdv7taXHFRvZZwxeYAynoN6KEe+w3o5n0nvo2BdOdanZzqZVuJKAwS+8Gz6LUX2QN/g qUrCgxFlFd9Hr4XALxf8hVWAVXcP8OZC9BxmeEsMkyIgDnLCXL8dZfaN56USdqREJ6Ru Z8AhA5j/+w1JPfod6E40UyBjGNMWHmyURx/JUhImsJlz7tDHvjsUbUB+NyTcQK++bLKj kt5Q== X-Gm-Message-State: ALoCoQkhe7wmA6iME5c28CXaKTHTUSFUspv61EtNEUBeyhh+somvKZ4x/yZjl6tKm2P0Zj8VBGC6 X-Received: by 10.50.50.211 with SMTP id e19mr856017igo.4.1397550809189; Tue, 15 Apr 2014 01:33:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.198 with SMTP id o64ls38788qga.66.gmail; Tue, 15 Apr 2014 01:33:29 -0700 (PDT) X-Received: by 10.220.4.132 with SMTP id 4mr209718vcr.9.1397550809047; Tue, 15 Apr 2014 01:33:29 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id wd2si3275858veb.5.2014.04.15.01.33.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Apr 2014 01:33:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.177 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.177; Received: by mail-ve0-f177.google.com with SMTP id sa20so8523094veb.8 for ; Tue, 15 Apr 2014 01:33:29 -0700 (PDT) X-Received: by 10.52.253.171 with SMTP id ab11mr217910vdd.14.1397550808964; Tue, 15 Apr 2014 01:33:28 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp212781vcb; Tue, 15 Apr 2014 01:33:28 -0700 (PDT) X-Received: by 10.66.66.202 with SMTP id h10mr564030pat.70.1397550808230; Tue, 15 Apr 2014 01:33:28 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hu10si2413180pbc.444.2014.04.15.01.33.27; Tue, 15 Apr 2014 01:33:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751012AbaDOId0 (ORCPT + 7 others); 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-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: list List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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;