mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Antoniu Miclaus <antoniu.miclaus@analog.com>
To: Peter Rosin <peda@axentia.se>, Rob Herring <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
	Srinivas Kandagatla <srini@kernel.org>,
	Linus Walleij <linusw@kernel.org>,
	Johan Hovold <johan+linaro@kernel.org>,
	David Lechner <dlechner@baylibre.com>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v6 2/2] mux: gpio-mux: add support for enable GPIO
Date: Thu, 29 Jan 2026 17:56:21 +0200	[thread overview]
Message-ID: <20260129155633.3985-3-antoniu.miclaus@analog.com> (raw)
In-Reply-To: <20260129155633.3985-1-antoniu.miclaus@analog.com>

Add support for an optional enable GPIO to the gpio-mux driver. This
allows the mux to be disabled before changing address lines and
re-enabled after, preventing glitches that could briefly activate
unintended channels during transitions.

The enable GPIO is optional and the driver maintains backward
compatibility with existing gpio-mux users.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
Changes in v6:
 - Add error handling for gpiod functions
 - Make enable-gpios required for MUX_IDLE_DISCONNECT, optional otherwise
 - Remove redundant if (mux_gpio->enable) checks
---
 drivers/mux/gpio.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/drivers/mux/gpio.c b/drivers/mux/gpio.c
index 4cc3202c58f3..eeeff9587013 100644
--- a/drivers/mux/gpio.c
+++ b/drivers/mux/gpio.c
@@ -19,6 +19,7 @@
 
 struct mux_gpio {
 	struct gpio_descs *gpios;
+	struct gpio_desc *enable;
 };
 
 static int mux_gpio_set(struct mux_control *mux, int state)
@@ -26,12 +27,30 @@ static int mux_gpio_set(struct mux_control *mux, int state)
 	struct mux_gpio *mux_gpio = mux_chip_priv(mux->chip);
 	DECLARE_BITMAP(values, BITS_PER_TYPE(state));
 	u32 value = state;
+	int ret;
+
+	if (state == MUX_IDLE_DISCONNECT)
+		return gpiod_set_value_cansleep(mux_gpio->enable, 0);
+
+	/*
+	 * Disable the mux before changing address lines to prevent
+	 * glitches where an unintended channel could be briefly
+	 * activated during the transition. When disabled, all mux
+	 * outputs enter high-impedance (high-Z) state. For analog
+	 * signals, downstream capacitance typically maintains the
+	 * signal level during this brief disconnection.
+	 */
+	ret = gpiod_set_value_cansleep(mux_gpio->enable, 0);
+	if (ret)
+		return ret;
 
 	bitmap_from_arr32(values, &value, BITS_PER_TYPE(value));
 
-	gpiod_multi_set_value_cansleep(mux_gpio->gpios, values);
+	ret = gpiod_multi_set_value_cansleep(mux_gpio->gpios, values);
+	if (ret)
+		return ret;
 
-	return 0;
+	return gpiod_set_value_cansleep(mux_gpio->enable, 1);
 }
 
 static const struct mux_control_ops mux_gpio_ops = {
@@ -73,12 +92,24 @@ static int mux_gpio_probe(struct platform_device *pdev)
 
 	ret = device_property_read_u32(dev, "idle-state", (u32 *)&idle_state);
 	if (ret >= 0 && idle_state != MUX_IDLE_AS_IS) {
-		if (idle_state < 0 || idle_state >= mux_chip->mux->states) {
+		if (idle_state == MUX_IDLE_DISCONNECT) {
+			mux_gpio->enable = devm_gpiod_get(dev, "enable",
+							  GPIOD_OUT_LOW);
+			if (IS_ERR(mux_gpio->enable))
+				return dev_err_probe(dev, PTR_ERR(mux_gpio->enable),
+						     "MUX_IDLE_DISCONNECT requires enable-gpios\n");
+		} else if (idle_state < 0 || idle_state >= mux_chip->mux->states) {
 			dev_err(dev, "invalid idle-state %u\n", idle_state);
 			return -EINVAL;
 		}
 
 		mux_chip->mux->idle_state = idle_state;
+	} else {
+		mux_gpio->enable = devm_gpiod_get_optional(dev, "enable",
+							   GPIOD_OUT_LOW);
+		if (IS_ERR(mux_gpio->enable))
+			return dev_err_probe(dev, PTR_ERR(mux_gpio->enable),
+					     "failed to get enable gpio\n");
 	}
 
 	ret = devm_regulator_get_enable_optional(dev, "mux");
-- 
2.43.0


  parent reply	other threads:[~2026-01-29 15:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29 15:56 [PATCH v6 0/2] mux: gpio-mux: add enable GPIO support Antoniu Miclaus
2026-01-29 15:56 ` [PATCH v6 1/2] dt-bindings: mux: gpio-mux: add enable-gpios support Antoniu Miclaus
2026-01-29 15:56 ` Antoniu Miclaus [this message]
2026-01-30 10:41 ` [PATCH v6 0/2] mux: gpio-mux: add enable GPIO support Linus Walleij

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=20260129155633.3985-3-antoniu.miclaus@analog.com \
    --to=antoniu.miclaus@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=johan+linaro@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@axentia.se \
    --cc=robh@kernel.org \
    --cc=srini@kernel.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

all inboxes | Powered by JetHome®