From patchwork Thu Dec 5 13:34:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 3288181 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 968DDC0D4A for ; Thu, 5 Dec 2013 13:35:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 693C9203E5 for ; Thu, 5 Dec 2013 13:35:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B8081203B4 for ; Thu, 5 Dec 2013 13:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932205Ab3LENfD (ORCPT ); Thu, 5 Dec 2013 08:35:03 -0500 Received: from metis.ext.pengutronix.de ([92.198.50.35]:49774 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932198Ab3LENfC (ORCPT ); Thu, 5 Dec 2013 08:35:02 -0500 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1VoZ4v-000685-3f; Thu, 05 Dec 2013 14:34:53 +0100 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1VoZ4u-0002oc-8k; Thu, 05 Dec 2013 14:34:52 +0100 From: Sascha Hauer To: linux-mmc@vger.kernel.org Cc: Chris Ball , , Sascha Hauer Subject: [PATCH 5/6] mmc: mxs: use mmc_gpio_get_ro for detecting read-only status Date: Thu, 5 Dec 2013 14:34:50 +0100 Message-Id: <1386250491-4708-6-git-send-email-s.hauer@pengutronix.de> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1386250491-4708-1-git-send-email-s.hauer@pengutronix.de> References: <1386250491-4708-1-git-send-email-s.hauer@pengutronix.de> X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mmc@vger.kernel.org Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.9 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 This also fixes that the read-only gpio was used without being requested. Signed-off-by: Sascha Hauer --- drivers/mmc/host/mxs-mmc.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c index 3dd2f4c..13016e2 100644 --- a/drivers/mmc/host/mxs-mmc.c +++ b/drivers/mmc/host/mxs-mmc.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -69,26 +70,8 @@ struct mxs_mmc_host { unsigned char bus_width; spinlock_t lock; int sdio_irq_en; - int wp_gpio; - bool wp_inverted; }; -static int mxs_mmc_get_ro(struct mmc_host *mmc) -{ - struct mxs_mmc_host *host = mmc_priv(mmc); - int ret; - - if (!gpio_is_valid(host->wp_gpio)) - return -EINVAL; - - ret = gpio_get_value(host->wp_gpio); - - if (host->wp_inverted) - ret = !ret; - - return ret; -} - static int mxs_mmc_get_cd(struct mmc_host *mmc) { struct mxs_mmc_host *host = mmc_priv(mmc); @@ -551,7 +534,7 @@ static void mxs_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) static const struct mmc_host_ops mxs_mmc_ops = { .request = mxs_mmc_request, - .get_ro = mxs_mmc_get_ro, + .get_ro = mmc_gpio_get_ro, .get_cd = mxs_mmc_get_cd, .set_ios = mxs_mmc_set_ios, .enable_sdio_irq = mxs_mmc_enable_sdio_irq, @@ -585,7 +568,7 @@ static int mxs_mmc_probe(struct platform_device *pdev) struct mxs_mmc_host *host; struct mmc_host *mmc; struct resource *iores; - int ret = 0, irq_err; + int ret = 0, irq_err, gpio; struct regulator *reg_vmmc; enum of_gpio_flags flags; struct mxs_ssp *ssp; @@ -659,9 +642,14 @@ static int mxs_mmc_probe(struct platform_device *pdev) mmc->caps |= MMC_CAP_NEEDS_POLL; if (of_property_read_bool(np, "non-removable")) mmc->caps |= MMC_CAP_NONREMOVABLE; - host->wp_gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags); - if (flags & OF_GPIO_ACTIVE_LOW) - host->wp_inverted = 1; + gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags); + if (gpio_is_valid(gpio)) { + ret = mmc_gpio_request_ro(mmc, gpio); + if (ret) + goto out_clk_disable; + if (!(flags & OF_GPIO_ACTIVE_LOW)) + mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; + } if (of_property_read_bool(np, "cd-inverted")) mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;