From patchwork Tue Sep 30 14:05:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 38154 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8C1DD20549 for ; Tue, 30 Sep 2014 14:06:01 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id e51sf1943292eek.7 for ; Tue, 30 Sep 2014 07:06:00 -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=79KF28PTfs3V0eP49Iy7eIwyGwq/ySLSO4kUWLuPK8w=; b=PTBoFjhOeKPeEOCJ5xRIoqnTx3Zo49Oy0ek+7bz/ro696i6a5hwyAZL7Q1WFu0faVb fhj+ItKYCKIUUUx/IMYqxgy9fjshhzQM81f5QUadgge1CgtJDzUclPTCpf+XYell4Tlk 2C1S//vI3WByhwaOUSr6Ybqf4VyKJy3necI1R1UpL3l85YigTh/8j5fcG3p0RuI7xu4Z H7Sh/5dDHZTSmhK1319NwE/xGyUGt/a4u6CFGn0CWVfXZO8TnBf1To3b7GxX9QiXKEs8 SjnQr6FzSsax4PUUEq3vW/8T0keNDefawIbnBIS11rfPp4nxQr3JTulKSjsyMTltHjwf Qk3g== X-Gm-Message-State: ALoCoQnTcoPe+qU9y5c8ta3cgt5uyHJKHEMwI8XS4EXdfVCyvDsmz7PgJpFlkGrkVpS66I4GpLIM X-Received: by 10.152.4.4 with SMTP id g4mr6984064lag.2.1412085959590; Tue, 30 Sep 2014 07:05:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.18.131 with SMTP id w3ls49322lad.79.gmail; Tue, 30 Sep 2014 07:05:59 -0700 (PDT) X-Received: by 10.152.29.129 with SMTP id k1mr47953059lah.81.1412085959439; Tue, 30 Sep 2014 07:05:59 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com [209.85.215.43]) by mx.google.com with ESMTPS id y9si23029744lbr.1.2014.09.30.07.05.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Sep 2014 07:05:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id gb8so10808833lab.30 for ; Tue, 30 Sep 2014 07:05:59 -0700 (PDT) X-Received: by 10.152.7.73 with SMTP id h9mr15723640laa.27.1412085959308; Tue, 30 Sep 2014 07:05:59 -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.112.130.169 with SMTP id of9csp353411lbb; Tue, 30 Sep 2014 07:05:58 -0700 (PDT) X-Received: by 10.66.145.35 with SMTP id sr3mr7054520pab.55.1412085957740; Tue, 30 Sep 2014 07:05:57 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cw5si27000762pbc.133.2014.09.30.07.05.57 for ; Tue, 30 Sep 2014 07:05:57 -0700 (PDT) Received-SPF: none (google.com: linux-gpio-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751830AbaI3OF4 (ORCPT ); Tue, 30 Sep 2014 10:05:56 -0400 Received: from mail-wg0-f43.google.com ([74.125.82.43]:54042 "EHLO mail-wg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751845AbaI3OF4 (ORCPT ); Tue, 30 Sep 2014 10:05:56 -0400 Received: by mail-wg0-f43.google.com with SMTP id a1so3773707wgh.14 for ; Tue, 30 Sep 2014 07:05:54 -0700 (PDT) X-Received: by 10.194.103.41 with SMTP id ft9mr54206998wjb.93.1412085954312; Tue, 30 Sep 2014 07:05:54 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id ic7sm15290728wid.11.2014.09.30.07.05.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Sep 2014 07:05:53 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Chris Ball , Ulf Hansson , Javier Martinez Canillas Cc: linux-gpio@vger.kernel.org, Linus Walleij Subject: [PATCH] mmc: core: restore detect line inversion semantics Date: Tue, 30 Sep 2014 16:05:43 +0200 Message-Id: <1412085943-16872-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-gpio@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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) 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: , commit 98e90de99a0c43bd434da814c882c4332441871e "mmc: host: switch OF parser to use gpio descriptors" switched the semantic behaviour of card detect and read only flags such that the inversion capability flag would only be set if inversion was explicitly specified in the device tree, in the hopes that no-one was using double inversion. It turns out that the XOR:ing between the explicit inversion was indeed in use, so we need to restore the old semantics where both ways of inversion are checked and the end result XOR:ed. Reported-by: Javier Martinez Canillas Signed-off-by: Linus Walleij Tested-by: Javier Martinez Canillas --- drivers/mmc/core/host.c | 32 ++++++++++++++++++++++++++++---- drivers/mmc/core/slot-gpio.c | 10 ++++++++-- drivers/mmc/host/mmci.c | 5 +++-- include/linux/mmc/slot-gpio.h | 4 ++-- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 31969436d77c..480100515067 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -311,6 +311,7 @@ int mmc_of_parse(struct mmc_host *host) struct device_node *np; u32 bus_width; int len, ret; + bool cap_invert, gpio_invert; if (!host->parent || !host->parent->of_node) return 0; @@ -359,12 +360,15 @@ int mmc_of_parse(struct mmc_host *host) host->caps |= MMC_CAP_NONREMOVABLE; } else { if (of_property_read_bool(np, "cd-inverted")) - host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; + cap_invert = true; + else + cap_invert = false; if (of_find_property(np, "broken-cd", &len)) host->caps |= MMC_CAP_NEEDS_POLL; - ret = mmc_gpiod_request_cd(host, "cd", 0, false, 0); + ret = mmc_gpiod_request_cd(host, "cd", 0, false, + 0, &gpio_invert); if (ret) { if (ret == -EPROBE_DEFER) return ret; @@ -375,13 +379,29 @@ int mmc_of_parse(struct mmc_host *host) } } else dev_info(host->parent, "Got CD GPIO\n"); + + /* + * There are two ways to flag that the CD line is inverted: + * through the cd-inverted flag and by the GPIO line itself + * being inverted from the GPIO subsystem. This is a leftover + * from the times when the GPIO subsystem did not make it + * possible to flag a line as inverted. + * + * If the capability on the host AND the GPIO line are + * both inverted, the end result is that the CD line is + * not inverted. + */ + if (cap_invert ^ gpio_invert) + host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; } /* Parse Write Protection */ if (of_property_read_bool(np, "wp-inverted")) - host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; + cap_invert = true; + else + cap_invert = false; - ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0); + ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &gpio_invert); if (ret) { if (ret == -EPROBE_DEFER) goto out; @@ -393,6 +413,10 @@ int mmc_of_parse(struct mmc_host *host) } else dev_info(host->parent, "Got WP GPIO\n"); + /* See the comment on CD inversion above */ + if (cap_invert ^ gpio_invert) + host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; + if (of_find_property(np, "cap-sd-highspeed", &len)) host->caps |= MMC_CAP_SD_HIGHSPEED; if (of_find_property(np, "cap-mmc-highspeed", &len)) diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c index 38f76555d4bf..e069acba93f5 100644 --- a/drivers/mmc/core/slot-gpio.c +++ b/drivers/mmc/core/slot-gpio.c @@ -281,6 +281,7 @@ EXPORT_SYMBOL(mmc_gpio_free_cd); * @idx: index of the GPIO to obtain in the consumer * @override_active_level: ignore %GPIO_ACTIVE_LOW flag * @debounce: debounce time in microseconds + * @gpio_invert: will return whether the GPIO line is inverted or not * * Use this function in place of mmc_gpio_request_cd() to use the GPIO * descriptor API. Note that it is paired with mmc_gpiod_free_cd() not @@ -291,7 +292,7 @@ EXPORT_SYMBOL(mmc_gpio_free_cd); */ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, unsigned int idx, bool override_active_level, - unsigned int debounce) + unsigned int debounce, bool *gpio_invert) { struct mmc_gpio *ctx; struct gpio_desc *desc; @@ -316,6 +317,8 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, return ret; } + *gpio_invert = gpiod_is_active_low(desc); + ctx->override_cd_active_level = override_active_level; ctx->cd_gpio = desc; @@ -330,6 +333,7 @@ EXPORT_SYMBOL(mmc_gpiod_request_cd); * @idx: index of the GPIO to obtain in the consumer * @override_active_level: ignore %GPIO_ACTIVE_LOW flag * @debounce: debounce time in microseconds + * @gpio_invert: will return whether the GPIO line is inverted or not * * Use this function in place of mmc_gpio_request_ro() to use the GPIO * descriptor API. Note that it is paired with mmc_gpiod_free_ro() not @@ -339,7 +343,7 @@ EXPORT_SYMBOL(mmc_gpiod_request_cd); */ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id, unsigned int idx, bool override_active_level, - unsigned int debounce) + unsigned int debounce, bool *gpio_invert) { struct mmc_gpio *ctx; struct gpio_desc *desc; @@ -364,6 +368,8 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id, return ret; } + *gpio_invert = gpiod_is_active_low(desc); + ctx->override_ro_active_level = override_active_level; ctx->ro_gpio = desc; diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index c9dafed550f2..5c9f2d543144 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1512,6 +1512,7 @@ static int mmci_probe(struct amba_device *dev, struct variant_data *variant = id->data; struct mmci_host *host; struct mmc_host *mmc; + bool dummy; int ret; /* Must have platform data or Device Tree. */ @@ -1682,7 +1683,7 @@ static int mmci_probe(struct amba_device *dev, * silently of these do not exist and proceed to try platform data */ if (!np) { - ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0); + ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0, &dummy); if (ret < 0) { if (ret == -EPROBE_DEFER) goto clk_disable; @@ -1693,7 +1694,7 @@ static int mmci_probe(struct amba_device *dev, } } - ret = mmc_gpiod_request_ro(mmc, "wp", 0, false, 0); + ret = mmc_gpiod_request_ro(mmc, "wp", 0, false, 0, &dummy); if (ret < 0) { if (ret == -EPROBE_DEFER) goto clk_disable; diff --git a/include/linux/mmc/slot-gpio.h b/include/linux/mmc/slot-gpio.h index a0d0442c15bf..e56fa24c9322 100644 --- a/include/linux/mmc/slot-gpio.h +++ b/include/linux/mmc/slot-gpio.h @@ -24,10 +24,10 @@ void mmc_gpio_free_cd(struct mmc_host *host); int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, unsigned int idx, bool override_active_level, - unsigned int debounce); + unsigned int debounce, bool *gpio_invert); int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id, unsigned int idx, bool override_active_level, - unsigned int debounce); + unsigned int debounce, bool *gpio_invert); void mmc_gpiod_free_cd(struct mmc_host *host); void mmc_gpiod_request_cd_irq(struct mmc_host *host);