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

Jonas Jelonek posted 2 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v2 1/2] dt-bindings: gpio: add gpio-line-mux controller
Posted by Jonas Jelonek 3 months, 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>
---
 .../bindings/gpio/gpio-line-mux.yaml          | 108 ++++++++++++++++++
 .../devicetree/bindings/mux/gpio-mux.yaml     |  30 +++++
 2 files changed, 138 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..4c907a35eb4d
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml
@@ -0,0 +1,108 @@
+# 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 mapping backed by
+  a single shared GPIO and a multiplexer. A simple illustrated example is
+
+            +----- A
+    IN/OUT /
+    <-----o------- B
+        / |\
+        | | +----- C
+        | |  \
+        | |   +--- D
+        | |
+       M1 M0
+
+    MUX CONTROL
+
+     M1 M0   IN/OUT
+      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/outputs
+  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.
+    minItems: 1
+    items:
+      type: string
+
+  gpio-line-names: true
+
+  mux-controls:
+    maxItems: 1
+    $ref: /schemas/mux/mux-controller.yaml#
+    description:
+      Phandle to the multiplexer to control access to the GPIOs.
+
+  ngpios: false
+
+  shared-gpio:
+    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
+  - shared-gpio
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/mux/mux.h>
+
+    sfp_gpio_mux: gpio-mux {
+        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>;
+        shared-gpio = <&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";
+
+        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>;
+    };
diff --git a/Documentation/devicetree/bindings/mux/gpio-mux.yaml b/Documentation/devicetree/bindings/mux/gpio-mux.yaml
index ef7e33ec85d4..57eb1e9ef4cf 100644
--- a/Documentation/devicetree/bindings/mux/gpio-mux.yaml
+++ b/Documentation/devicetree/bindings/mux/gpio-mux.yaml
@@ -100,4 +100,34 @@ examples:
             };
         };
     };
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    sfp_mux: mux-controller {
+        compatible = "gpio-mux";
+        #mux-control-cells = <0>;
+
+        mux-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>,
+                    <&gpio0 1 GPIO_ACTIVE_HIGH>;
+    };
+
+    sfp_gpio: sfp-gpio-1 {
+        compatible = "gpio-line-mux";
+        gpio-controller;
+        #gpio-cells = <2>;
+
+        mux-controls = <&sfp_mux>;
+        shared-gpio = <&gpio0 2 GPIO_ACTIVE_HIGH>;
+
+        gpio-line-names = "SFP_LOS", "SFP_MOD_ABS", "SFP_TX_F";
+        gpio-line-mux-states = <0>, <1>, <2>;
+    };
+
+    sfp0: sfp-p0 {
+        compatible = "sff,sfp";
+
+        los-gpios = <&sfp_gpio 0 GPIO_ACTIVE_HIGH>;
+        mod-def0-gpios = <&sfp_gpio 1 GPIO_ACTIVE_LOW>;
+        tx-fault-gpios = <&sfp_gpio 2 GPIO_ACTIVE_HIGH>;
+    };
 ...
-- 
2.48.1
Re: [PATCH v2 1/2] dt-bindings: gpio: add gpio-line-mux controller
Posted by Rob Herring 3 months, 1 week ago
On Sun, Oct 26, 2025 at 11:17:53PM +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>
> ---
>  .../bindings/gpio/gpio-line-mux.yaml          | 108 ++++++++++++++++++
>  .../devicetree/bindings/mux/gpio-mux.yaml     |  30 +++++
>  2 files changed, 138 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..4c907a35eb4d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml
> @@ -0,0 +1,108 @@
> +# 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:

You need '>' or '|' to preserve formatting here.

> +  A GPIO controller to provide virtual GPIOs for a 1-to-many mapping backed by
> +  a single shared GPIO and a multiplexer. A simple illustrated example is
> +
> +            +----- A
> +    IN/OUT /
> +    <-----o------- B
> +        / |\
> +        | | +----- C
> +        | |  \
> +        | |   +--- D
> +        | |
> +       M1 M0
> +
> +    MUX CONTROL
> +
> +     M1 M0   IN/OUT
> +      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/outputs
> +  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.
> +    minItems: 1
> +    items:
> +      type: string
> +
> +  gpio-line-names: true
> +
> +  mux-controls:
> +    maxItems: 1
> +    $ref: /schemas/mux/mux-controller.yaml#
> +    description:
> +      Phandle to the multiplexer to control access to the GPIOs.
> +
> +  ngpios: false
> +
> +  shared-gpio:

'-gpio' is deprecated. Use '-gpios'.

> +    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
> +  - shared-gpio
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +    #include <dt-bindings/mux/mux.h>
> +
> +    sfp_gpio_mux: gpio-mux {
> +        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>;
> +        shared-gpio = <&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";
> +
> +        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>;
> +    };
> diff --git a/Documentation/devicetree/bindings/mux/gpio-mux.yaml b/Documentation/devicetree/bindings/mux/gpio-mux.yaml
> index ef7e33ec85d4..57eb1e9ef4cf 100644
> --- a/Documentation/devicetree/bindings/mux/gpio-mux.yaml
> +++ b/Documentation/devicetree/bindings/mux/gpio-mux.yaml
> @@ -100,4 +100,34 @@ examples:
>              };
>          };
>      };
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +
> +    sfp_mux: mux-controller {
> +        compatible = "gpio-mux";
> +        #mux-control-cells = <0>;
> +
> +        mux-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>,
> +                    <&gpio0 1 GPIO_ACTIVE_HIGH>;
> +    };
> +
> +    sfp_gpio: sfp-gpio-1 {
> +        compatible = "gpio-line-mux";
> +        gpio-controller;
> +        #gpio-cells = <2>;
> +
> +        mux-controls = <&sfp_mux>;
> +        shared-gpio = <&gpio0 2 GPIO_ACTIVE_HIGH>;
> +
> +        gpio-line-names = "SFP_LOS", "SFP_MOD_ABS", "SFP_TX_F";
> +        gpio-line-mux-states = <0>, <1>, <2>;
> +    };
> +
> +    sfp0: sfp-p0 {
> +        compatible = "sff,sfp";
> +
> +        los-gpios = <&sfp_gpio 0 GPIO_ACTIVE_HIGH>;
> +        mod-def0-gpios = <&sfp_gpio 1 GPIO_ACTIVE_LOW>;
> +        tx-fault-gpios = <&sfp_gpio 2 GPIO_ACTIVE_HIGH>;

Drop. We don't need the same example twice.

Rob
Re: [PATCH v2 1/2] dt-bindings: gpio: add gpio-line-mux controller
Posted by Rob Herring (Arm) 3 months, 1 week ago
On Sun, 26 Oct 2025 23:17:53 +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>
> ---
>  .../bindings/gpio/gpio-line-mux.yaml          | 108 ++++++++++++++++++
>  .../devicetree/bindings/mux/gpio-mux.yaml     |  30 +++++
>  2 files changed, 138 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml
> 

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml: gpio-line-mux-states: missing type definition
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: gpio-mux (gpio-mux): $nodename:0: 'gpio-mux' does not match '^mux-controller(@.*|-([0-9]|[1-9][0-9]+))?$'
	from schema $id: http://devicetree.org/schemas/mux/mux-controller.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:0: 0 is not of type 'string'
	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:1: 1 is not of type 'string'
	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:2: 3 is not of type 'string'
	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): mux-controls: [[1]] is not of type 'object'
	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-p1 (sff,sfp): 'i2c-bus' is a required property
	from schema $id: http://devicetree.org/schemas/net/sff,sfp.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:0: 0 is not of type 'string'
	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:1: 1 is not of type 'string'
	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:2: 2 is not of type 'string'
	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): mux-controls: [[2]] is not of type 'object'
	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-p0 (sff,sfp): 'i2c-bus' is a required property
	from schema $id: http://devicetree.org/schemas/net/sff,sfp.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20251026231754.2368904-2-jelonek.jonas@gmail.com

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v2 1/2] dt-bindings: gpio: add gpio-line-mux controller
Posted by Jonas Jelonek 3 months, 1 week ago

On 27.10.25 12:39, Rob Herring (Arm) wrote:
> My bot found errors running 'make dt_binding_check' on your patch:
>
> yamllint warnings/errors:
>
> dtschema/dtc warnings/errors:
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml: gpio-line-mux-states: missing type definition
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: gpio-mux (gpio-mux): $nodename:0: 'gpio-mux' does not match '^mux-controller(@.*|-([0-9]|[1-9][0-9]+))?$'
> 	from schema $id: http://devicetree.org/schemas/mux/mux-controller.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:0: 0 is not of type 'string'
> 	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:1: 1 is not of type 'string'
> 	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:2: 3 is not of type 'string'
> 	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): mux-controls: [[1]] is not of type 'object'
> 	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/gpio/gpio-line-mux.example.dtb: sfp-p1 (sff,sfp): 'i2c-bus' is a required property
> 	from schema $id: http://devicetree.org/schemas/net/sff,sfp.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:0: 0 is not of type 'string'
> 	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:1: 1 is not of type 'string'
> 	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): gpio-line-mux-states:2: 2 is not of type 'string'
> 	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-gpio-1 (gpio-line-mux): mux-controls: [[2]] is not of type 'object'
> 	from schema $id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mux/gpio-mux.example.dtb: sfp-p0 (sff,sfp): 'i2c-bus' is a required property
> 	from schema $id: http://devicetree.org/schemas/net/sff,sfp.yaml
>
sorry for these silly errors, I'll fix them in the next iteration.

Best,
Jonas