From patchwork Mon May 3 21:05:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 1473391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4FYwW66dkDz9sRR for ; Tue, 4 May 2021 07:06:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbhECVHD (ORCPT ); Mon, 3 May 2021 17:07:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbhECVHD (ORCPT ); Mon, 3 May 2021 17:07:03 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DB8EC061573 for ; Mon, 3 May 2021 14:06:09 -0700 (PDT) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldflV-0005uv-9g; Mon, 03 May 2021 23:06:05 +0200 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1ldflU-000417-Hh; Mon, 03 May 2021 23:06:04 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Linus Walleij , Bartosz Golaszewski , Rob Herring Cc: linux-gpio@vger.kernel.org, kernel@pengutronix.de, devicetree@vger.kernel.org Subject: [PATCH 1/2] dt-bindings: gpio: introduce hog properties with less ambiguity Date: Mon, 3 May 2021 23:05:26 +0200 Message-Id: <20210503210526.43455-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org For active low lines the semantic of output-low and output-high is hard to grasp because there is a double negation involved and so output-low is actually a request to drive the line high (aka inactive). So introduce output-inactive and output-active with the same semantic as output-low and output-high respectively have today, but with a more sensible name. Signed-off-by: Uwe Kleine-König Acked-by: Linus Walleij Acked-by: Rob Herring --- Hello, I already sent this patch back in July and Linus (Walleij) liked the patch but asked for an implementation. For that I added the second patch now. Best regards Uwe Documentation/devicetree/bindings/gpio/gpio.txt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/gpio/gpio.txt b/Documentation/devicetree/bindings/gpio/gpio.txt index a8895d339bfe..1061c346a619 100644 --- a/Documentation/devicetree/bindings/gpio/gpio.txt +++ b/Documentation/devicetree/bindings/gpio/gpio.txt @@ -196,11 +196,16 @@ Only one of the following properties scanned in the order shown below. This means that when multiple properties are present they will be searched in the order presented below and the first match is taken as the intended configuration. -- input: A property specifying to set the GPIO direction as input. -- output-low A property specifying to set the GPIO direction as output with - the value low. -- output-high A property specifying to set the GPIO direction as output with - the value high. +- input: A property specifying to set the GPIO direction as input. +- output-deasserted: A property specifying to set the GPIO direction as output + with the inactive value (depending on the line's polarity, + which is active-high by default) +- output-asserted: A property specifying to set the GPIO direction as output + with the active value. + +For backwards compatibility "output-low" and "output-high" should be supported +as aliases for "output-deasserted" and "output-asserted" respectively. Their +usage is misleading for active-low outputs, so their use is discouraged. Optional properties: - line-name: The GPIO label name. If not present the node name is used. From patchwork Mon May 3 21:05:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 1473393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4FYwWD5TVhz9sRR for ; Tue, 4 May 2021 07:06:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229619AbhECVHJ (ORCPT ); Mon, 3 May 2021 17:07:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbhECVHJ (ORCPT ); Mon, 3 May 2021 17:07:09 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0770CC061573 for ; Mon, 3 May 2021 14:06:16 -0700 (PDT) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldfle-0005z9-2B; Mon, 03 May 2021 23:06:14 +0200 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1ldfld-00041C-Oj; Mon, 03 May 2021 23:06:13 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Linus Walleij , Bartosz Golaszewski , Rob Herring Cc: linux-gpio@vger.kernel.org, kernel@pengutronix.de, devicetree@vger.kernel.org Subject: [PATCH 2/2] gpio: use "asserted" and "deasserted" instead of "high" and "low" Date: Mon, 3 May 2021 23:05:28 +0200 Message-Id: <20210503210526.43455-2-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210503210526.43455-1-u.kleine-koenig@pengutronix.de> References: <20210503210526.43455-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org For active-low GPIOs the currently available nomenclature requires regular explaination to the non-enlightened folks, e.g. because a hog defined as: someline { gpio-hog; gpios = <24 GPIO_ACTIVE_LOW>; output-high; } results in the line being set to the physical low level. So use the terms "asserted" and "deasserted" which are less ambigous and keep the old names as synonyms. The above example can now be written as: someline { gpio-hog; gpios = <24 GPIO_ACTIVE_LOW>; output-asserted; } where it is less surprising that the output is set to a low level. Signed-off-by: Uwe Kleine-König --- drivers/gpio/gpiolib-of.c | 10 ++++++++-- include/linux/gpio/consumer.h | 14 ++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index baf0153b7bca..89e852da6a61 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -624,10 +624,16 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, if (of_property_read_bool(np, "input")) *dflags |= GPIOD_IN; + else if (of_property_read_bool(np, "output-deasserted")) + *dflags |= GPIOD_OUT_DEASSERTED; + else if (of_property_read_bool(np, "output-asserted")) + *dflags |= GPIOD_OUT_ASSERTED; else if (of_property_read_bool(np, "output-low")) - *dflags |= GPIOD_OUT_LOW; + /* misleading alias for output-deasserted */ + *dflags |= GPIOD_OUT_DEASSERTED; else if (of_property_read_bool(np, "output-high")) - *dflags |= GPIOD_OUT_HIGH; + /* misleading alias for output-asserted */ + *dflags |= GPIOD_OUT_ASSERTED; else { pr_warn("GPIO line %d (%pOFn): no hogging state specified, bailing out\n", desc_to_gpio(desc), np); diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index c73b25bc9213..b40cc19cf419 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -49,11 +49,17 @@ struct gpio_descs { enum gpiod_flags { GPIOD_ASIS = 0, GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET, - GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, - GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | + GPIOD_OUT_DEASSERTED = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, + GPIOD_OUT_ASSERTED = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_DIR_VAL, - GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN, - GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN, + GPIOD_OUT_DEASSERTED_OPEN_DRAIN = GPIOD_OUT_DEASSERTED | GPIOD_FLAGS_BIT_OPEN_DRAIN, + GPIOD_OUT_ASSERTED_OPEN_DRAIN = GPIOD_OUT_ASSERTED | GPIOD_FLAGS_BIT_OPEN_DRAIN, + + /* old names that are confusing in combination with active-low GPIOs */ + GPIOD_OUT_LOW = GPIOD_OUT_DEASSERTED, + GPIOD_OUT_HIGH = GPIOD_OUT_ASSERTED, + GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_DEASSERTED_OPEN_DRAIN, + GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_ASSERTED_OPEN_DRAIN, }; #ifdef CONFIG_GPIOLIB