mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v6 0/2] mux: gpio-mux: add enable GPIO support
@ 2026-01-29 15:56 Antoniu Miclaus
  2026-01-29 15:56 ` [PATCH v6 1/2] dt-bindings: mux: gpio-mux: add enable-gpios support Antoniu Miclaus
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Antoniu Miclaus @ 2026-01-29 15:56 UTC (permalink / raw)
  To: Peter Rosin, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Srinivas Kandagatla, Antoniu Miclaus, David Lechner,
	Johan Hovold, Linus Walleij, devicetree, linux-kernel

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

This feature is useful for devices like the Analog Devices ADG2404
(4:1 mux) that require enable control for glitch-free operation. The
binding documentation now includes ADG2404 as a supported device with
a dedicated example.

Antoniu Miclaus (2):
  dt-bindings: mux: gpio-mux: add enable-gpios support
  mux: gpio-mux: add support for enable GPIO

 .../devicetree/bindings/mux/gpio-mux.yaml     | 16 ++++++++
 drivers/mux/gpio.c                            | 37 +++++++++++++++++--
 2 files changed, 50 insertions(+), 3 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v6 1/2] dt-bindings: mux: gpio-mux: add enable-gpios support
  2026-01-29 15:56 [PATCH v6 0/2] mux: gpio-mux: add enable GPIO support Antoniu Miclaus
@ 2026-01-29 15:56 ` Antoniu Miclaus
  2026-01-29 15:56 ` [PATCH v6 2/2] mux: gpio-mux: add support for enable GPIO Antoniu Miclaus
  2026-01-30 10:41 ` [PATCH v6 0/2] mux: gpio-mux: add enable GPIO support Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Antoniu Miclaus @ 2026-01-29 15:56 UTC (permalink / raw)
  To: Peter Rosin, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Antoniu Miclaus, Srinivas Kandagatla, Linus Walleij,
	Johan Hovold, David Lechner, devicetree, linux-kernel
  Cc: Conor Dooley

Add support for an optional enable GPIO that allows the multiplexer
to be disabled before changing address lines and re-enabled after,
preventing glitches during channel transitions.

This is useful for devices like the Analog Devices ADG2404 (4:1 mux)
that benefit from enable control to ensure clean channel switching.

Acked-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
Changes in v6:
 - No code changes.
---
 .../devicetree/bindings/mux/gpio-mux.yaml        | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Documentation/devicetree/bindings/mux/gpio-mux.yaml b/Documentation/devicetree/bindings/mux/gpio-mux.yaml
index ef7e33ec85d4..798e0a73d77b 100644
--- a/Documentation/devicetree/bindings/mux/gpio-mux.yaml
+++ b/Documentation/devicetree/bindings/mux/gpio-mux.yaml
@@ -17,6 +17,9 @@ description: |+
   multiplexer GPIO pins, where the first pin is the least significant
   bit. An active pin is a binary 1, an inactive pin is a binary 0.
 
+  This binding supports GPIO-controlled multiplexers such as the Analog
+  Devices ADG2404 (4:1 mux with enable control).
+
 properties:
   compatible:
     const: gpio-mux
@@ -25,6 +28,18 @@ properties:
     description:
       List of gpios used to control the multiplexer, least significant bit first.
 
+  enable-gpios:
+    description: |
+      Optional GPIO to enable the multiplexer. When present, the mux is
+      disabled before changing address lines and re-enabled after. This
+      prevents glitches where an unintended channel could be briefly activated
+      during address line transitions. When disabled, all outputs enter a
+      high-impedance (high-Z) state rather than holding their previous value.
+      This is suitable for analog multiplexers where downstream capacitance
+      maintains the signal level during the brief disconnection.
+      Required for MUX_IDLE_DISCONNECT idle-state.
+    maxItems: 1
+
   mux-supply:
     description:
       Regulator to power on the multiplexer.
@@ -59,6 +74,7 @@ examples:
 
         mux-gpios = <&pioA 0 GPIO_ACTIVE_HIGH>,
               <&pioA 1 GPIO_ACTIVE_HIGH>;
+        enable-gpios = <&pioA 2 GPIO_ACTIVE_HIGH>;
     };
 
     adc-mux {
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v6 2/2] mux: gpio-mux: add support for enable GPIO
  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
  2026-01-30 10:41 ` [PATCH v6 0/2] mux: gpio-mux: add enable GPIO support Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Antoniu Miclaus @ 2026-01-29 15:56 UTC (permalink / raw)
  To: Peter Rosin, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Antoniu Miclaus, Srinivas Kandagatla, Linus Walleij,
	Johan Hovold, David Lechner, devicetree, linux-kernel

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v6 0/2] mux: gpio-mux: add enable GPIO support
  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 ` [PATCH v6 2/2] mux: gpio-mux: add support for enable GPIO Antoniu Miclaus
@ 2026-01-30 10:41 ` Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2026-01-30 10:41 UTC (permalink / raw)
  To: Antoniu Miclaus
  Cc: Peter Rosin, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Srinivas Kandagatla, David Lechner, Johan Hovold, devicetree,
	linux-kernel

On Thu, Jan 29, 2026 at 4:57 PM Antoniu Miclaus
<antoniu.miclaus@analog.com> wrote:

> This series adds optional enable GPIO support to the gpio-mux driver.
> The enable GPIO allows the multiplexer to be disabled before changing
> address lines and re-enabled after, preventing glitches that could
> briefly activate unintended channels during transitions.
>
> This feature is useful for devices like the Analog Devices ADG2404
> (4:1 mux) that require enable control for glitch-free operation. The
> binding documentation now includes ADG2404 as a supported device with
> a dedicated example.

This version of the patches look good to me!
Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-30 10:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v6 2/2] mux: gpio-mux: add support for enable GPIO Antoniu Miclaus
2026-01-30 10:41 ` [PATCH v6 0/2] mux: gpio-mux: add enable GPIO support Linus Walleij

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®