mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 3/4] gpio: Fix GPIOD_ASIS flag
Date: Mon, 05 Jan 2026 11:45:00 +0100	[thread overview]
Message-ID: <20260105-riotboard-v1-3-789b844d7e36@pengutronix.de> (raw)
In-Reply-To: <20260105-riotboard-v1-0-789b844d7e36@pengutronix.de>

GPIOs can be requested with GPIOD_ASIS and with this the GPIO should be
kept in its current state. This doesn't work currently as GPIOD_ASIS is
defined as 0 and the flags are then interpreted as GPIOF_INIT_LOW (also
0).

To fix this set GPIOD_ASIS to a bit value which makes it a flag which
can be explicitly tested for.

Note this is different than in Linux. Linux defines GPIOD_ASIS to 0 just
like barebox did, but in Linux the other GPIOD_* flags have an explicit
"change this setting" flag which we don't have in barebox. Introducing
these flags in barebox would mean we have to add the "change this
setting" flags in various other places, like for example
gpiod_request_one().

Motivation for this patch is the only current user of GPIOD_ASIS, the
fixed regulator driver. Without this patch regulators will already be
enabled in the fixed regulator drivers probe function.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/gpio/gpiolib.c        | 15 +++++++++------
 include/gpio.h                |  2 ++
 include/linux/gpio/consumer.h |  2 +-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index ec4d8e889bb1e7671f844c5c158188b7b9a23888..e1493ffb6640bc417996f81c45197c32441a8d69 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -622,6 +622,7 @@ static int gpiodesc_request_one(struct gpio_desc *desc, unsigned long lflags,
 	const bool logical     = (dflags & GPIOF_LOGICAL) == GPIOF_LOGICAL;
 	const bool init_active = (dflags & GPIOF_INIT_ACTIVE) == GPIOF_INIT_ACTIVE;
 	const bool init_high   = (dflags & GPIOF_INIT_HIGH) == GPIOF_INIT_HIGH;
+	const bool set         = (dflags & GPIOF_ASIS) == GPIOF_ASIS;
 
 	err = gpiodesc_request(desc, label);
 	if (err)
@@ -631,12 +632,14 @@ static int gpiodesc_request_one(struct gpio_desc *desc, unsigned long lflags,
 	if (active_low)
 		desc->flags |= OF_GPIO_ACTIVE_LOW;
 
-	if (dir_in)
-		err = gpiod_direction_input(desc);
-	else if (logical)
-		err = gpiod_direction_output(desc, init_active);
-	else
-		err = gpiod_direction_output_raw(desc, init_high);
+	if (!set) {
+		if (dir_in)
+			err = gpiod_direction_input(desc);
+		else if (logical)
+			err = gpiod_direction_output(desc, init_active);
+		else
+			err = gpiod_direction_output_raw(desc, init_high);
+	}
 
 	if (err)
 		gpiodesc_free(desc);
diff --git a/include/gpio.h b/include/gpio.h
index 92fd27b2b996eed8777e9321b4f34e245ceca480..2264d0c495a4439f0f8b23e023e28f7472c90889 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -114,6 +114,8 @@ static inline int gpio_is_valid(int gpio)
 #define GPIOF_OUT_INIT_ACTIVE	(GPIOF_DIR_OUT | GPIOF_INIT_ACTIVE)
 #define GPIOF_OUT_INIT_INACTIVE	(GPIOF_DIR_OUT | GPIOF_INIT_INACTIVE)
 
+#define GPIOF_ASIS	BIT(4)
+
 /**
  * struct gpio - a structure describing a GPIO with configuration
  * @gpio:	the GPIO number
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index c461f3f3108bd9e31777df2a37ffb469fafb36bd..a425145351b0da1476e9327dfebb2e13801488f3 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -13,7 +13,7 @@
  * and output value. These values cannot be OR'd.
  */
 enum gpiod_flags {
-	GPIOD_ASIS	= 0,
+	GPIOD_ASIS	= GPIOF_ASIS,
 	GPIOD_IN	= GPIOF_IN,
 	/*
 	 * To change this later to a different logic level (i.e. taking

-- 
2.47.3




  parent reply	other threads:[~2026-01-05 10:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 10:44 [PATCH 0/4] i.MX6 Riotboard related patches Sascha Hauer
2026-01-05 10:44 ` [PATCH 1/4] ARM: i.MX6: Riotboard: ungate peripheral clocks Sascha Hauer
2026-01-05 10:44 ` [PATCH 2/4] ARM: i.MX6: Riotboard: Add hint how to enable DEBUG_LL Sascha Hauer
2026-01-05 10:45 ` Sascha Hauer [this message]
2026-01-05 10:45 ` [PATCH 4/4] ARM: boards: remove #define DEBUG in board files Sascha Hauer
2026-01-06  7:46 ` (subset) [PATCH 0/4] i.MX6 Riotboard related patches Sascha Hauer
2026-01-06  7:46 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260105-riotboard-v1-3-789b844d7e36@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox