[PATCH v6 1/2] dt-bindings: gpio: add gpio-line-mux controller

Jonas Jelonek posted 2 patches 1 month, 1 week ago
[PATCH v6 1/2] dt-bindings: gpio: add gpio-line-mux controller
Posted by Jonas Jelonek 1 month, 1 week ago
Add dt-schema for a gpio-line-mux controller which exposes virtual
GPIOs for a shared GPIO controlled by a multiplexer, e.g. a gpio-mux.

The gpio-line-mux controller is a gpio-controller, thus has mostly the
same semantics. However, it requires a mux-control to be specified upon
which it will operate.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 .../bindings/gpio/gpio-line-mux.yaml          | 109 ++++++++++++++++++
 1 file changed, 109 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml

diff --git a/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml b/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml
new file mode 100644
index 000000000000..0228e9915b92
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml
@@ -0,0 +1,109 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GPIO line mux
+
+maintainers:
+  - Jonas Jelonek <jelonek.jonas@gmail.com>
+
+description: |
+  A GPIO controller to provide virtual GPIOs for a 1-to-many input-only mapping
+  backed by a single shared GPIO and a multiplexer. A simple illustrated
+  example is
+
+            +----- A
+    IN     /
+    <-----o------- B
+        / |\
+        | | +----- C
+        | |  \
+        | |   +--- D
+        | |
+       M1 M0
+
+    MUX CONTROL
+
+     M1 M0   IN
+      0  0   A
+      0  1   B
+      1  0   C
+      1  1   D
+
+  This can be used in case a real GPIO is connected to multiple inputs and
+  controlled by a multiplexer, and another subsystem/driver does not work
+  directly with the multiplexer subsystem.
+
+properties:
+  compatible:
+    const: gpio-line-mux
+
+  gpio-controller: true
+
+  "#gpio-cells":
+    const: 2
+
+  gpio-line-mux-states:
+    description: Mux states corresponding to the virtual GPIOs.
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+
+  gpio-line-names: true
+
+  mux-controls:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    maxItems: 1
+    description:
+      Phandle to the multiplexer to control access to the GPIOs.
+
+  ngpios: false
+
+  muxed-gpios:
+    maxItems: 1
+    description:
+      GPIO which is the '1' in 1-to-many and is shared by the virtual GPIOs
+      and controlled via the mux.
+
+required:
+  - compatible
+  - gpio-controller
+  - gpio-line-mux-states
+  - mux-controls
+  - muxed-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/mux/mux.h>
+
+    sfp_gpio_mux: mux-controller-1 {
+        compatible = "gpio-mux";
+        mux-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>,
+                    <&gpio0 1 GPIO_ACTIVE_HIGH>;
+        #mux-control-cells = <0>;
+        idle-state = <MUX_IDLE_AS_IS>;
+    };
+
+    sfp1_gpio: sfp-gpio-1 {
+        compatible = "gpio-line-mux";
+        gpio-controller;
+        #gpio-cells = <2>;
+
+        mux-controls = <&sfp_gpio_mux>;
+        muxed-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
+
+        gpio-line-names = "SFP1_LOS", "SFP1_MOD_ABS", "SFP1_TX_FAULT";
+        gpio-line-mux-states = <0>, <1>, <3>;
+    };
+
+    sfp1: sfp-p1 {
+        compatible = "sff,sfp";
+
+        i2c-bus = <&sfp1_i2c>;
+        los-gpios = <&sfp1_gpio 0 GPIO_ACTIVE_HIGH>;
+        mod-def0-gpios = <&sfp1_gpio 1 GPIO_ACTIVE_LOW>;
+        tx-fault-gpios = <&sfp1_gpio 2 GPIO_ACTIVE_HIGH>;
+    };
-- 
2.48.1
Re: [PATCH v6 1/2] dt-bindings: gpio: add gpio-line-mux controller
Posted by Rob Herring 1 month, 1 week ago
On Tue, Nov 11, 2025 at 09:27:03AM +0000, Jonas Jelonek wrote:
> Add dt-schema for a gpio-line-mux controller which exposes virtual
> GPIOs for a shared GPIO controlled by a multiplexer, e.g. a gpio-mux.
> 
> The gpio-line-mux controller is a gpio-controller, thus has mostly the
> same semantics. However, it requires a mux-control to be specified upon
> which it will operate.
> 
> Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
> Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  .../bindings/gpio/gpio-line-mux.yaml          | 109 ++++++++++++++++++
>  1 file changed, 109 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml
> 
> diff --git a/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml b/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml
> new file mode 100644
> index 000000000000..0228e9915b92
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml
> @@ -0,0 +1,109 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: GPIO line mux
> +
> +maintainers:
> +  - Jonas Jelonek <jelonek.jonas@gmail.com>
> +
> +description: |
> +  A GPIO controller to provide virtual GPIOs for a 1-to-many input-only mapping
> +  backed by a single shared GPIO and a multiplexer. A simple illustrated
> +  example is

colon on the end.

> +
> +            +----- A
> +    IN     /
> +    <-----o------- B
> +        / |\
> +        | | +----- C
> +        | |  \
> +        | |   +--- D
> +        | |
> +       M1 M0
> +
> +    MUX CONTROL
> +
> +     M1 M0   IN
> +      0  0   A
> +      0  1   B
> +      1  0   C
> +      1  1   D
> +
> +  This can be used in case a real GPIO is connected to multiple inputs and
> +  controlled by a multiplexer, and another subsystem/driver does not work
> +  directly with the multiplexer subsystem.
> +
> +properties:
> +  compatible:
> +    const: gpio-line-mux
> +
> +  gpio-controller: true
> +
> +  "#gpio-cells":
> +    const: 2
> +
> +  gpio-line-mux-states:
> +    description: Mux states corresponding to the virtual GPIOs.
> +    $ref: /schemas/types.yaml#/definitions/uint32-array
> +
> +  gpio-line-names: true
> +
> +  mux-controls:
> +    $ref: /schemas/types.yaml#/definitions/phandle-array

Already has a type. Drop the ref.

> +    maxItems: 1
> +    description:
> +      Phandle to the multiplexer to control access to the GPIOs.
> +
> +  ngpios: false

No need for this.

> +
> +  muxed-gpios:
> +    maxItems: 1
> +    description:
> +      GPIO which is the '1' in 1-to-many and is shared by the virtual GPIOs
> +      and controlled via the mux.
> +
> +required:
> +  - compatible
> +  - gpio-controller
> +  - gpio-line-mux-states
> +  - mux-controls
> +  - muxed-gpios
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +    #include <dt-bindings/mux/mux.h>
> +
> +    sfp_gpio_mux: mux-controller-1 {
> +        compatible = "gpio-mux";
> +        mux-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>,
> +                    <&gpio0 1 GPIO_ACTIVE_HIGH>;
> +        #mux-control-cells = <0>;
> +        idle-state = <MUX_IDLE_AS_IS>;
> +    };
> +
> +    sfp1_gpio: sfp-gpio-1 {
> +        compatible = "gpio-line-mux";
> +        gpio-controller;
> +        #gpio-cells = <2>;
> +
> +        mux-controls = <&sfp_gpio_mux>;
> +        muxed-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
> +
> +        gpio-line-names = "SFP1_LOS", "SFP1_MOD_ABS", "SFP1_TX_FAULT";
> +        gpio-line-mux-states = <0>, <1>, <3>;

gpio-line-names is defined to have an entry for all lines. So 
gpio-line-mux-states is not necessary. You can just do:

gpio-line-names = "SFP1_LOS", "SFP1_MOD_ABS", "", "SFP1_TX_FAULT";

Rob
Re: [PATCH v6 1/2] dt-bindings: gpio: add gpio-line-mux controller
Posted by Jonas Jelonek 1 month, 1 week ago
Hi Rob,

On 11.11.25 13:57, Rob Herring wrote:
> On Tue, Nov 11, 2025 at 09:27:03AM +0000, Jonas Jelonek wrote:
>> +    maxItems: 1
>> +    description:
>> +      Phandle to the multiplexer to control access to the GPIOs.
>> +
>> +  ngpios: false
> No need for this.
(...)
>> +        gpio-line-names = "SFP1_LOS", "SFP1_MOD_ABS", "SFP1_TX_FAULT";
>> +        gpio-line-mux-states = <0>, <1>, <3>;
> gpio-line-names is defined to have an entry for all lines. So 
> gpio-line-mux-states is not necessary. You can just do:
>
> gpio-line-names = "SFP1_LOS", "SFP1_MOD_ABS", "", "SFP1_TX_FAULT";

Not sure if I'm getting this wrong, but this ties the GPIO line index to the
multiplexer state. Is that still the correct way if my multiplexer needs
states '15', '17, '18'? Then I would need something like this:

gpio-line-names = "", "", "", "", "", "", "", "", "", "", "", "", "", "", "A", "", "B", "C"; 

And it would cause the virtual GPIO controller to provide more GPIO lines than
desired/expected/needed.

> Rob

Best,
Jonas