From patchwork Fri Nov 16 14:28:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 1755311 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F423EDF288 for ; Fri, 16 Nov 2012 14:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751696Ab2KPO24 (ORCPT ); Fri, 16 Nov 2012 09:28:56 -0500 Received: from mailout3.samsung.com ([203.254.224.33]:59100 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751672Ab2KPO2y (ORCPT ); Fri, 16 Nov 2012 09:28:54 -0500 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MDL003OH47YHJB0@mailout3.samsung.com>; Fri, 16 Nov 2012 23:28:53 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-04-50a64da56dc5 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id BB.17.01231.5AD46A05; Fri, 16 Nov 2012 23:28:53 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MDL007QX479D970@mmp1.samsung.com>; Fri, 16 Nov 2012 23:28:53 +0900 (KST) From: Tomasz Figa To: linux-mmc@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org, kgene.kim@samsung.com, cjb@laptop.org, ben-linux@fluff.org, kyungmin.park@samsung.com, m.szyprowski@samsung.com, t.figa@samsung.com, tomasz.figa@gmail.com Subject: [PATCH v2 1/2] mmc: host: sdhci-s3c: Use devm_gpio_request to request GPIOs Date: Fri, 16 Nov 2012 15:28:16 +0100 Message-id: <1353076097-22498-2-git-send-email-t.figa@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1353076097-22498-1-git-send-email-t.figa@samsung.com> References: <1353076097-22498-1-git-send-email-t.figa@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOJMWRmVeSWpSXmKPExsVy+t9jAd2lvssCDFZfNbE48r+f0WLG+X1M DkwenzfJBTBGcdmkpOZklqUW6dslcGVcX3mEpeCgUsW+JUeYGxiXyHQxcnJICJhIrJ00mRnC FpO4cG89WxcjF4eQwCJGiTXbJrBAOF1MEjf2TmEHqWITUJP43PCIDcQWEZCV+PnnApjNLHCU UeJzlxGILSwQJtG9dyrYVBYBVYlZn6eD9fIKOEncau1lgtgmL/H0fh9YL6eAs8T3BXNZQGwh oJp939eyTmDkXcDIsIpRNLUguaA4KT3XUK84Mbe4NC9dLzk/dxMj2PvPpHYwrmywOMQowMGo xMMreHtpgBBrYllxZe4hRgkOZiUR3mjbZQFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeZs9UgKE BNITS1KzU1MLUotgskwcnFINjLZShyY/mB8WwvszJvyA4U0RwV+f25yqsv/tS7u1eovEXrVX VTlHQtbOchf40JL0j+HIrODHWc85TuflLr0VJf51y/sNnS6iO39GvlnzPud3+tr+EwzxbXK3 BE6LZm9/sO64TbDwTpOLHkFPanwW2VUVvvDiOLtHUtZg9SYeL7m1P9xTN6p8/avEUpyRaKjF XFScCABiZgxa+gEAAA== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The set of GPIO pins used by sdhci-s3c driver varies between configurations, such as card detect method, pinctrl availability, etc. This overly complicates the code requesting and freeing GPIO pins, which must check which pins are used, when freeing them. This patch modifies the sdhci-s3c driver to use devm_gpio_request to free requested pins automatically after unbinding the driver. Signed-off-by: Tomasz Figa Acked-by: Thomas Abraham --- drivers/mmc/host/sdhci-s3c.c | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c index 2903949..75f85fd 100644 --- a/drivers/mmc/host/sdhci-s3c.c +++ b/drivers/mmc/host/sdhci-s3c.c @@ -406,7 +406,7 @@ static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc) struct s3c_sdhci_platdata *pdata = sc->pdata; struct device *dev = &sc->pdev->dev; - if (gpio_request(pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) { + if (devm_gpio_request(dev, pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) { sc->ext_cd_gpio = pdata->ext_cd_gpio; sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio); if (sc->ext_cd_irq && @@ -487,7 +487,7 @@ static int __devinit sdhci_s3c_parse_dt(struct device *dev, if (of_get_property(node, "cd-inverted", NULL)) pdata->ext_cd_gpio_invert = 1; } else if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) { - ret = gpio_request(gpio, "sdhci-cd"); + ret = devm_gpio_request(dev, gpio, "sdhci-cd"); if (ret) { dev_err(dev, "card detect gpio request failed\n"); return -EINVAL; @@ -501,28 +501,20 @@ static int __devinit sdhci_s3c_parse_dt(struct device *dev, gpio = of_get_gpio(node, cnt); if (!gpio_is_valid(gpio)) { dev_err(dev, "invalid gpio[%d]\n", cnt); - goto err_free_dt_cd_gpio; + return -EINVAL; } ourhost->gpios[cnt] = gpio; } for (cnt = 0; cnt < NUM_GPIOS(pdata->max_width); cnt++) { - ret = gpio_request(ourhost->gpios[cnt], "sdhci-gpio"); + ret = devm_gpio_request(dev, ourhost->gpios[cnt], "sdhci-gpio"); if (ret) { dev_err(dev, "gpio[%d] request failed\n", cnt); - goto err_free_dt_gpios; + return -EINVAL; } } return 0; - - err_free_dt_gpios: - while (--cnt >= 0) - gpio_free(ourhost->gpios[cnt]); - err_free_dt_cd_gpio: - if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) - gpio_free(ourhost->ext_cd_gpio); - return -EINVAL; } #else static int __devinit sdhci_s3c_parse_dt(struct device *dev, @@ -579,13 +571,13 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { ret = -ENOMEM; - goto err_pdata; + goto err_pdata_io_clk; } if (pdev->dev.of_node) { ret = sdhci_s3c_parse_dt(&pdev->dev, host, pdata); if (ret) - goto err_pdata; + goto err_pdata_io_clk; } else { memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); sc->ext_cd_gpio = -1; /* invalid gpio number */ @@ -603,7 +595,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) if (IS_ERR(sc->clk_io)) { dev_err(dev, "failed to get io clock\n"); ret = PTR_ERR(sc->clk_io); - goto err_io_clk; + goto err_pdata_io_clk; } /* enable the local io clock and keep it running for the moment. */ @@ -765,13 +757,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) clk_disable(sc->clk_io); clk_put(sc->clk_io); - err_io_clk: - for (ptr = 0; ptr < NUM_GPIOS(sc->pdata->max_width); ptr++) - gpio_free(sc->gpios[ptr]); - if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) - gpio_free(sc->ext_cd_gpio); - - err_pdata: + err_pdata_io_clk: sdhci_free_host(host); return ret; @@ -790,9 +776,6 @@ static int __devexit sdhci_s3c_remove(struct platform_device *pdev) if (sc->ext_cd_irq) free_irq(sc->ext_cd_irq, sc); - if (gpio_is_valid(sc->ext_cd_gpio)) - gpio_free(sc->ext_cd_gpio); - #ifdef CONFIG_PM_RUNTIME clk_enable(sc->clk_io); #endif @@ -812,11 +795,6 @@ static int __devexit sdhci_s3c_remove(struct platform_device *pdev) clk_disable(sc->clk_io); clk_put(sc->clk_io); - if (pdev->dev.of_node) { - for (ptr = 0; ptr < NUM_GPIOS(sc->pdata->max_width); ptr++) - gpio_free(sc->gpios[ptr]); - } - sdhci_free_host(host); platform_set_drvdata(pdev, NULL);