From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Add DT bindings for GPIO charlieplex keypad.
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
.../input/gpio-charlieplex-keypad.yaml | 106 ++++++++++++++++++
1 file changed, 106 insertions(+)
create mode 100644 Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
diff --git a/Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml b/Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
new file mode 100644
index 000000000000..d3eeddc8e533
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
@@ -0,0 +1,106 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/input/gpio-charlieplex-keypad.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GPIO charlieplex keypad
+
+maintainers:
+ - Hugo Villeneuve <hvilleneuve@dimonoff.com>
+
+description: |
+ The charlieplex keypad supports N^2)-N different key combinations (where N is
+ the number of lines). Key presses and releases are detected by configuring
+ only one line as output at a time, and reading other line states. This process
+ is repeated for each line. Diodes are required to ensure current flows in only
+ one direction between any pair of pins.
+ This mechanism doesn't allow to detect simultaneous key presses.
+
+ Wiring example for 3 lines keyboard with 6 switches and 3 diodes:
+
+ L0 --+---------------------+----------------------+
+ | | |
+ L1 -------+-----------+---------------------+ |
+ | | | | | |
+ L2 -------------+----------------+-----+ | |
+ | | | | | | | | |
+ | | | | | | | | |
+ | S1 \ S2 \ | S3 \ S4 \ | S5 \ S6 \
+ | | | | | | | | |
+ | +--+--+ | +--+--+ | +--+--+
+ | | | | | |
+ | D1 v | D2 v | D3 v
+ | - (k) | - (k) | - (k)
+ | | | | | |
+ +-------+ +-------+ +-------+
+
+ L: GPIO line
+ S: switch
+ D: diode (k indicates cathode)
+
+allOf:
+ - $ref: input.yaml#
+ - $ref: /schemas/input/matrix-keymap.yaml#
+
+properties:
+ compatible:
+ const: gpio-charlieplex-keypad
+
+ autorepeat: true
+
+ debounce-delay-ms:
+ default: 5
+
+ line-gpios:
+ description:
+ List of GPIOs used as lines. The gpio specifier for this property
+ depends on the gpio controller to which these lines are connected.
+
+ linux,keymap: true
+
+ poll-interval: true
+
+ settling-time-us: true
+
+ wakeup-source: true
+
+required:
+ - compatible
+ - line-gpios
+ - linux,keymap
+ - poll-interval
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ #include <dt-bindings/input/input.h>
+
+ charlieplex-keypad {
+ compatible = "gpio-charlieplex-keypad";
+ debounce-delay-ms = <20>;
+ poll-interval = <5>;
+ settling-time-us = <2>;
+
+ line-gpios = <&gpio2 25 GPIO_ACTIVE_HIGH
+ &gpio2 26 GPIO_ACTIVE_HIGH
+ &gpio2 27 GPIO_ACTIVE_HIGH>;
+
+ /* MATRIX_KEY(output, input, key-code) */
+ linux,keymap = <
+ /*
+ * According to wiring diagram above, if L1 is configured as
+ * output and HIGH, and we detect a HIGH level on input L0,
+ * then it means S1 is pressed: MATRIX_KEY(L1, L0, KEY...)
+ */
+ MATRIX_KEY(1, 0, KEY_F1) /* S1 */
+ MATRIX_KEY(2, 0, KEY_F2) /* S2 */
+ MATRIX_KEY(0, 1, KEY_F3) /* S3 */
+ MATRIX_KEY(2, 1, KEY_F4) /* S4 */
+ MATRIX_KEY(1, 2, KEY_F5) /* S5 */
+ MATRIX_KEY(0, 2, KEY_F6) /* S6 */
+ >;
+ };
--
2.47.3
Hi Hugo,
On Wed, 25 Feb 2026 at 16:54, Hugo Villeneuve <hugo@hugovil.com> wrote:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
>
> Add DT bindings for GPIO charlieplex keypad.
>
> Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Thanks for your patch!
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
> @@ -0,0 +1,106 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +
> +$id: http://devicetree.org/schemas/input/gpio-charlieplex-keypad.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: GPIO charlieplex keypad
> +
> +maintainers:
> + - Hugo Villeneuve <hvilleneuve@dimonoff.com>
> +
> +description: |
> + The charlieplex keypad supports N^2)-N different key combinations (where N is
> + the number of lines). Key presses and releases are detected by configuring
> + only one line as output at a time, and reading other line states. This process
> + is repeated for each line. Diodes are required to ensure current flows in only
> + one direction between any pair of pins.
> + This mechanism doesn't allow to detect simultaneous key presses.
Indeed, e.g. pressing S1 and S2 simultaneously will show a ghost
S5 keypress.
> +
> + Wiring example for 3 lines keyboard with 6 switches and 3 diodes:
> +
> + L0 --+---------------------+----------------------+
> + | | |
> + L1 -------+-----------+---------------------+ |
> + | | | | | |
> + L2 -------------+----------------+-----+ | |
> + | | | | | | | | |
> + | | | | | | | | |
> + | S1 \ S2 \ | S3 \ S4 \ | S5 \ S6 \
> + | | | | | | | | |
> + | +--+--+ | +--+--+ | +--+--+
> + | | | | | |
> + | D1 v | D2 v | D3 v
> + | - (k) | - (k) | - (k)
> + | | | | | |
> + +-------+ +-------+ +-------+
Don't you need pull-down resistors on L[0-2], and/or a way to specify
in DT to enable internal poll-down on GPIO controllers that support it?
Some controllers may support internal pull-up only, but I guess that
can be handled using GPIO_ACTIVE_LOW?
> +
> + L: GPIO line
> + S: switch
> + D: diode (k indicates cathode)
> +
> +allOf:
> + - $ref: input.yaml#
> + - $ref: /schemas/input/matrix-keymap.yaml#
> +
> +properties:
> + compatible:
> + const: gpio-charlieplex-keypad
> +
> + autorepeat: true
> +
> + debounce-delay-ms:
> + default: 5
> +
> + line-gpios:
> + description:
> + List of GPIOs used as lines. The gpio specifier for this property
> + depends on the gpio controller to which these lines are connected.
> +
> + linux,keymap: true
> +
> + poll-interval: true
> +
> + settling-time-us: true
> +
> + wakeup-source: true
> +
> +required:
> + - compatible
> + - line-gpios
> + - linux,keymap
> + - poll-interval
> +
> +additionalProperties: false
> +
> +examples:
> + - |
> + #include <dt-bindings/gpio/gpio.h>
> + #include <dt-bindings/input/input.h>
> +
> + charlieplex-keypad {
"keyboard", as per Devicetree Specification Generic Names
Recommendation.
> + compatible = "gpio-charlieplex-keypad";
> + debounce-delay-ms = <20>;
> + poll-interval = <5>;
> + settling-time-us = <2>;
> +
> + line-gpios = <&gpio2 25 GPIO_ACTIVE_HIGH
> + &gpio2 26 GPIO_ACTIVE_HIGH
> + &gpio2 27 GPIO_ACTIVE_HIGH>;
> +
> + /* MATRIX_KEY(output, input, key-code) */
> + linux,keymap = <
> + /*
> + * According to wiring diagram above, if L1 is configured as
> + * output and HIGH, and we detect a HIGH level on input L0,
> + * then it means S1 is pressed: MATRIX_KEY(L1, L0, KEY...)
> + */
> + MATRIX_KEY(1, 0, KEY_F1) /* S1 */
> + MATRIX_KEY(2, 0, KEY_F2) /* S2 */
> + MATRIX_KEY(0, 1, KEY_F3) /* S3 */
> + MATRIX_KEY(2, 1, KEY_F4) /* S4 */
> + MATRIX_KEY(1, 2, KEY_F5) /* S5 */
> + MATRIX_KEY(0, 2, KEY_F6) /* S6 */
> + >;
> + };
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hi Geert,
On Thu, 26 Feb 2026 10:32:30 +0100
Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> Hi Hugo,
>
> On Wed, 25 Feb 2026 at 16:54, Hugo Villeneuve <hugo@hugovil.com> wrote:
> > From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> >
> > Add DT bindings for GPIO charlieplex keypad.
> >
> > Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
>
> Thanks for your patch!
>
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
> > @@ -0,0 +1,106 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +
> > +$id: http://devicetree.org/schemas/input/gpio-charlieplex-keypad.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: GPIO charlieplex keypad
> > +
> > +maintainers:
> > + - Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > +
> > +description: |
> > + The charlieplex keypad supports N^2)-N different key combinations (where N is
> > + the number of lines). Key presses and releases are detected by configuring
> > + only one line as output at a time, and reading other line states. This process
> > + is repeated for each line. Diodes are required to ensure current flows in only
> > + one direction between any pair of pins.
> > + This mechanism doesn't allow to detect simultaneous key presses.
>
> Indeed, e.g. pressing S1 and S2 simultaneously will show a ghost
> S5 keypress.
>
> > +
> > + Wiring example for 3 lines keyboard with 6 switches and 3 diodes:
> > +
> > + L0 --+---------------------+----------------------+
> > + | | |
> > + L1 -------+-----------+---------------------+ |
> > + | | | | | |
> > + L2 -------------+----------------+-----+ | |
> > + | | | | | | | | |
> > + | | | | | | | | |
> > + | S1 \ S2 \ | S3 \ S4 \ | S5 \ S6 \
> > + | | | | | | | | |
> > + | +--+--+ | +--+--+ | +--+--+
> > + | | | | | |
> > + | D1 v | D2 v | D3 v
> > + | - (k) | - (k) | - (k)
> > + | | | | | |
> > + +-------+ +-------+ +-------+
>
> Don't you need pull-down resistors on L[0-2], and/or a way to specify
> in DT to enable internal poll-down on GPIO controllers that support it?
> Some controllers may support internal pull-up only, but I guess that
> can be handled using GPIO_ACTIVE_LOW?
Yes, using something like this:
line-gpios = <&gpio2 25 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)
should work I think, although with my hardware unfortunately I cannot
test it.
Hugo.
>
> > +
> > + L: GPIO line
> > + S: switch
> > + D: diode (k indicates cathode)
> > +
> > +allOf:
> > + - $ref: input.yaml#
> > + - $ref: /schemas/input/matrix-keymap.yaml#
> > +
> > +properties:
> > + compatible:
> > + const: gpio-charlieplex-keypad
> > +
> > + autorepeat: true
> > +
> > + debounce-delay-ms:
> > + default: 5
> > +
> > + line-gpios:
> > + description:
> > + List of GPIOs used as lines. The gpio specifier for this property
> > + depends on the gpio controller to which these lines are connected.
> > +
> > + linux,keymap: true
> > +
> > + poll-interval: true
> > +
> > + settling-time-us: true
> > +
> > + wakeup-source: true
> > +
> > +required:
> > + - compatible
> > + - line-gpios
> > + - linux,keymap
> > + - poll-interval
> > +
> > +additionalProperties: false
> > +
> > +examples:
> > + - |
> > + #include <dt-bindings/gpio/gpio.h>
> > + #include <dt-bindings/input/input.h>
> > +
> > + charlieplex-keypad {
>
> "keyboard", as per Devicetree Specification Generic Names
> Recommendation.
>
> > + compatible = "gpio-charlieplex-keypad";
> > + debounce-delay-ms = <20>;
> > + poll-interval = <5>;
> > + settling-time-us = <2>;
> > +
> > + line-gpios = <&gpio2 25 GPIO_ACTIVE_HIGH
> > + &gpio2 26 GPIO_ACTIVE_HIGH
> > + &gpio2 27 GPIO_ACTIVE_HIGH>;
> > +
> > + /* MATRIX_KEY(output, input, key-code) */
> > + linux,keymap = <
> > + /*
> > + * According to wiring diagram above, if L1 is configured as
> > + * output and HIGH, and we detect a HIGH level on input L0,
> > + * then it means S1 is pressed: MATRIX_KEY(L1, L0, KEY...)
> > + */
> > + MATRIX_KEY(1, 0, KEY_F1) /* S1 */
> > + MATRIX_KEY(2, 0, KEY_F2) /* S2 */
> > + MATRIX_KEY(0, 1, KEY_F3) /* S3 */
> > + MATRIX_KEY(2, 1, KEY_F4) /* S4 */
> > + MATRIX_KEY(1, 2, KEY_F5) /* S5 */
> > + MATRIX_KEY(0, 2, KEY_F6) /* S6 */
> > + >;
> > + };
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
>
--
Hugo Villeneuve
Hi Geert,
On Thu, 26 Feb 2026 10:32:30 +0100
Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> Hi Hugo,
>
> On Wed, 25 Feb 2026 at 16:54, Hugo Villeneuve <hugo@hugovil.com> wrote:
> > From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> >
> > Add DT bindings for GPIO charlieplex keypad.
> >
> > Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
>
> Thanks for your patch!
>
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
> > @@ -0,0 +1,106 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +
> > +$id: http://devicetree.org/schemas/input/gpio-charlieplex-keypad.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: GPIO charlieplex keypad
> > +
> > +maintainers:
> > + - Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > +
> > +description: |
> > + The charlieplex keypad supports N^2)-N different key combinations (where N is
> > + the number of lines). Key presses and releases are detected by configuring
> > + only one line as output at a time, and reading other line states. This process
> > + is repeated for each line. Diodes are required to ensure current flows in only
> > + one direction between any pair of pins.
> > + This mechanism doesn't allow to detect simultaneous key presses.
>
> Indeed, e.g. pressing S1 and S2 simultaneously will show a ghost
> S5 keypress.
>
> > +
> > + Wiring example for 3 lines keyboard with 6 switches and 3 diodes:
> > +
> > + L0 --+---------------------+----------------------+
> > + | | |
> > + L1 -------+-----------+---------------------+ |
> > + | | | | | |
> > + L2 -------------+----------------+-----+ | |
> > + | | | | | | | | |
> > + | | | | | | | | |
> > + | S1 \ S2 \ | S3 \ S4 \ | S5 \ S6 \
> > + | | | | | | | | |
> > + | +--+--+ | +--+--+ | +--+--+
> > + | | | | | |
> > + | D1 v | D2 v | D3 v
> > + | - (k) | - (k) | - (k)
> > + | | | | | |
> > + +-------+ +-------+ +-------+
>
> Don't you need pull-down resistors on L[0-2], and/or a way to specify
> in DT to enable internal poll-down on GPIO controllers that support it?
> Some controllers may support internal pull-up only, but I guess that
> can be handled using GPIO_ACTIVE_LOW?
Yes, I did not put any resistors in the diagram in order to keep it
simple and clear.
You need pull-down resistors either on the board, or specified in the
DT like we do for our board (we use the PCAL6416 with pull-up/down
support):
line-gpios = <&gpio20 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)
...
I will add this to the example, and add a few lines explaining this in
the description.
> > +
> > + L: GPIO line
> > + S: switch
> > + D: diode (k indicates cathode)
> > +
> > +allOf:
> > + - $ref: input.yaml#
> > + - $ref: /schemas/input/matrix-keymap.yaml#
> > +
> > +properties:
> > + compatible:
> > + const: gpio-charlieplex-keypad
> > +
> > + autorepeat: true
> > +
> > + debounce-delay-ms:
> > + default: 5
> > +
> > + line-gpios:
> > + description:
> > + List of GPIOs used as lines. The gpio specifier for this property
> > + depends on the gpio controller to which these lines are connected.
> > +
> > + linux,keymap: true
> > +
> > + poll-interval: true
> > +
> > + settling-time-us: true
> > +
> > + wakeup-source: true
> > +
> > +required:
> > + - compatible
> > + - line-gpios
> > + - linux,keymap
> > + - poll-interval
> > +
> > +additionalProperties: false
> > +
> > +examples:
> > + - |
> > + #include <dt-bindings/gpio/gpio.h>
> > + #include <dt-bindings/input/input.h>
> > +
> > + charlieplex-keypad {
>
> "keyboard", as per Devicetree Specification Generic Names
> Recommendation.
Ok.
Thank you,
Hugo.
>
> > + compatible = "gpio-charlieplex-keypad";
> > + debounce-delay-ms = <20>;
> > + poll-interval = <5>;
> > + settling-time-us = <2>;
> > +
> > + line-gpios = <&gpio2 25 GPIO_ACTIVE_HIGH
> > + &gpio2 26 GPIO_ACTIVE_HIGH
> > + &gpio2 27 GPIO_ACTIVE_HIGH>;
> > +
> > + /* MATRIX_KEY(output, input, key-code) */
> > + linux,keymap = <
> > + /*
> > + * According to wiring diagram above, if L1 is configured as
> > + * output and HIGH, and we detect a HIGH level on input L0,
> > + * then it means S1 is pressed: MATRIX_KEY(L1, L0, KEY...)
> > + */
> > + MATRIX_KEY(1, 0, KEY_F1) /* S1 */
> > + MATRIX_KEY(2, 0, KEY_F2) /* S2 */
> > + MATRIX_KEY(0, 1, KEY_F3) /* S3 */
> > + MATRIX_KEY(2, 1, KEY_F4) /* S4 */
> > + MATRIX_KEY(1, 2, KEY_F5) /* S5 */
> > + MATRIX_KEY(0, 2, KEY_F6) /* S6 */
> > + >;
> > + };
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
>
--
Hugo Villeneuve
© 2016 - 2026 Red Hat, Inc.