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: 154036 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2968959ljp; Mon, 17 Dec 2018 14:04:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/X6Ls7zVYfuDklBrVS7RL3531n6B5arOpIrhs4qgnmGXpUtCWZxyOKpgU/lNDiNG9g9TI+S X-Received: by 2002:a17:902:ac1:: with SMTP id 59mr13957692plp.36.1545084267882; Mon, 17 Dec 2018 14:04:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545084267; cv=none; d=google.com; s=arc-20160816; b=FkVbR+rcRDNKpoywdHRu/0zRUqv2gKo0SNO/gqn7nYkVWKAMhYSFC8C1t8tNvzELNK Y04bCwyn24eoftSkCA8i69s0YtGawbwl2+vqxNlFmyitYe+8n30MS0sUqRGeYeRi0HpZ 1eNW6hlW8sOZuzIret4NUWoRSaqQ6p/5k+XSJyiZiZDkQtia4yLqtAUKjBTQC8iNEHoy ddrz1zqTCawEBPx4LcDt8MN6G3ZFN7s+QTImtcuWCJlBP2NoGTW6tI3ZWsWfWQ4Cf45v V/GpAnLNcGPyiysQ7g9+g2/C80E7NDfGlmwajHGKecpJpNAbf+LrsfuBKjbkTRT25zzw Fqmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=cbazjhF7huEWDTZErOgo/kqVELQAAzm94Bb/Lm6Ky1A=; b=I1j1sy/quCNaRNNQK3aLAPKCLYwI10jkGD0oZs52sm2oTnMM2OpAQrfFoW7N8XKKBf DCV25i8bowG8B53deXsJBZFkm6DpDR0p82P5n0q0cDao4v1bKIoS087fblFhGlrMTqLC 8cSqEYEurXjdZGMP5vEpSjF0OlxenRWJ2NjMGqBadhb0sBK4MQCJbIKoJE3PNRoO3YmB jSVVubovbdkkx9FDMnaJu2s5Og2lc38WVY0ED7ILHze03qtzvOKL3bxgLoBg5oPI4BR2 GmX/m4Rq6O51+PLGpDw680bTX/CjvRNoc/s0Sqdif61y6HKDwxcVOOWoADWOuhEjjJiE qx3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jfit70kK; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 35si12050948plf.177.2018.12.17.14.04.27; Mon, 17 Dec 2018 14:04:27 -0800 (PST) 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; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jfit70kK; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbeLQWE1 (ORCPT + 5 others); 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-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 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(-) -- 2.19.2 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,