From patchwork Mon Dec 17 22:02:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10734337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F4BC13AD for ; Mon, 17 Dec 2018 22:04:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 690FD2A448 for ; Mon, 17 Dec 2018 22:04:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D2992A44B; Mon, 17 Dec 2018 22:04:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB1A12A448 for ; Mon, 17 Dec 2018 22:04:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbeLQWE1 (ORCPT ); Mon, 17 Dec 2018 17:04:27 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:43010 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726574AbeLQWE0 (ORCPT ); Mon, 17 Dec 2018 17:04:26 -0500 Received: by mail-lf1-f66.google.com with SMTP id u18so10666036lff.10 for ; Mon, 17 Dec 2018 14:04:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cbazjhF7huEWDTZErOgo/kqVELQAAzm94Bb/Lm6Ky1A=; b=Jfit70kKbGtOW5aQa9g3Pi9U+Dpc5fYR98pUcFZw0mskXFkrtrARyq+2iB9cUve7/R Ciu6WsORogMWKzp/QLgyKjZOgeYsTxeOxSJRPCIUtd3H4FRrKVMwrqq2AJaZCFHvfNE6 2UW2Ct/GNQDps0uELiHj6CHsy72TVkjlaUbes= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cbazjhF7huEWDTZErOgo/kqVELQAAzm94Bb/Lm6Ky1A=; b=hvNTK82OBqMtgM3+K4cOH3ubYPT2uSkSjIld7Lor9vWnBxo2tp6h+8MRoF44Nz1GWk gqy7tW0fd0gTPOs4P+KyYRBYO53yi4E5UGIPkCKRgQa0nJhTPSHSaNMRKBs6+6NLiOn2 f6Ic+/zNxAnKkGRKpwopf4NUvr3tOgouuyyieRkleXPo7fExYOH9aBD/V5F8IDE9pjre mD6uFbDoitiMEE0MhMTo4tc96zBmpW4LngdTIC0mCO0r8hwSg92T13oRP3HAhbjSaXCD KhUWvCEps8ISdPXaOBj0jNQ8Noz/BO28eyIfBH5AaVeHSk0Nzd5j/9L0TgzmebV3gyK2 rEOA== X-Gm-Message-State: AA+aEWaAZF0BJlVybiUqGMOSNYta3egCfRrylzbNjpHbKvv8sdUJjuPj xoRhEqysXAanZdRwR6H9CV9fnZqfELtwoA== X-Google-Smtp-Source: AFSGD/Wd9uJa68sXsSw4zXxDnPHJbnGi2aA05+EHXbQUiB0vH1/vGx7DkeERnFwjlUsa8iqYPpoNcg== X-Received: by 2002:a19:690d:: with SMTP id e13mr8218339lfc.84.1545084264341; Mon, 17 Dec 2018 14:04:24 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id m4-v6sm2655747ljb.58.2018.12.17.14.04.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Dec 2018 14:04:22 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij , Bartosz Golaszewski , Guenter Roeck Subject: [PATCH] gpio/mmc/of: Respect polarity in the device tree Date: Mon, 17 Dec 2018 23:02:16 +0100 Message-Id: <20181217220216.22233-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The device tree bindings for the MMC card detect and write protect lines specify that these should be active low unless "cd-inverted" or "wp-inverted" has been specified. However that is not how the kernel code has worked. It has always respected the flags passed to the phandle in the device tree, but respected the "cd-inverted" and "wp-inverted" flags such that if those are set, the polarity will be the inverse of that specified in the device tree. Switch to behaving like the old code did and fix the regression. Fixes: 81c85ec15a19 ("gpio: OF: Parse MMC-specific CD and WP properties") Cc: Bartosz Golaszewski Cc: Guenter Roeck Reported-by: Guenter Roeck Signed-off-by: Linus Walleij --- Ulf: I will apply this to the GPIO tree because of patches hitting this code, things should work fine in linux-next and in the merge window. --- drivers/gpio/gpiolib-of.c | 49 +++++++++++++-------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index fa8044228f0e..a6e1891217e2 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -54,6 +54,7 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, } static void of_gpio_flags_quirks(struct device_node *np, + const char *propname, enum of_gpio_flags *flags, int index) { @@ -61,39 +62,21 @@ static void of_gpio_flags_quirks(struct device_node *np, * Handle MMC "cd-inverted" and "wp-inverted" semantics. */ if (IS_ENABLED(CONFIG_MMC)) { - if (of_property_read_bool(np, "cd-gpios")) { - if (of_property_read_bool(np, "cd-inverted")) { - if (*flags & OF_GPIO_ACTIVE_LOW) { - /* "cd-inverted" takes precedence */ - *flags &= ~OF_GPIO_ACTIVE_LOW; - pr_warn("%s GPIO handle specifies CD active low - ignored\n", - of_node_full_name(np)); - } - } else { - /* - * Active low is the default according to the - * SDHCI specification. If the GPIO handle - * specifies the same thing - good. - */ - *flags |= OF_GPIO_ACTIVE_LOW; - } + /* + * Active low is the default according to the + * SDHCI specification and the device tree + * bindings. However the code in the current + * kernel was written such that the phandle + * flags were always respected, and "cd-inverted" + * would invert the flag from the device phandle. + */ + if (!strcmp(propname, "cd-gpios")) { + if (of_property_read_bool(np, "cd-inverted")) + *flags ^= OF_GPIO_ACTIVE_LOW; } - if (of_property_read_bool(np, "wp-gpios")) { - if (of_property_read_bool(np, "wp-inverted")) { - /* "wp-inverted" takes precedence */ - if (*flags & OF_GPIO_ACTIVE_LOW) { - *flags &= ~OF_GPIO_ACTIVE_LOW; - pr_warn("%s GPIO handle specifies WP active low - ignored\n", - of_node_full_name(np)); - } - } else { - /* - * Active low is the default according to the - * SDHCI specification. If the GPIO handle - * specifies the same thing - good. - */ - *flags |= OF_GPIO_ACTIVE_LOW; - } + if (!strcmp(propname, "wp-gpios")) { + if (of_property_read_bool(np, "wp-inverted")) + *flags ^= OF_GPIO_ACTIVE_LOW; } } /* @@ -213,7 +196,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, goto out; if (flags) - of_gpio_flags_quirks(np, flags, index); + of_gpio_flags_quirks(np, propname, flags, index); pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", __func__, propname, np, index,