public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/4] input: add GPIO-based charlieplex keypad
@ 2026-03-05 19:20 Hugo Villeneuve
  2026-03-05 19:20 ` [PATCH v4 1/4] dt-bindings: input: add debounce-delay-ms common property Hugo Villeneuve
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-05 19:20 UTC (permalink / raw)
  To: robin, andy, geert, robh, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz
  Cc: devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek, hugo

From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

Hello,
this patch series add a new GPIO charlieplex keypad driver.

The first two patches simply commonize two properties that are present in
a few bindings, so that the actual patches for the charlieplex keypad driver
can reuse them instead of also redefining them.

I have tested the driver on a custom board with a Solidrun RZ/G2LC SOM
with three charlieplex keyboards, all connected thru a single PCAL6416 I2C GPIO
expander.

Link: [v1] https://lore.kernel.org/all/20260203155023.536103-1-hugo@hugovil.com/
Link: [v2] https://lore.kernel.org/all/20260213171431.2228814-1-hugo@hugovil.com/
Link: [v3] https://lore.kernel.org/all/20260225155409.612478-1-hugo@hugovil.com/

Changes for v4:
- Fix indentation in comments (Andy)
- Add missing includes (Andy)
- Remove OF dependency (Andy/Dmitry)
- Uniformize return code variables to "err" (Andy/Dmitry)
- Change signed iterator to unsigned and move within loop (Andy)
- Remove unused platform_set_drvdata() (Andy)
- Fixed typo in cover letter PCAL6416 (Geert)
- Changed name in bindings example (Geert)
- Added pull resistors to bindings doc and example (Geert)
- Add debounce-delay-ms common property
- Add settling-time-us common property

Changes for v3:
- Add ASCII diagram in bindings, and reference to it in example
- Reorder properties alphabetically
- Add patch to define common input settling-time-us property
- Add patch to define common input debounce-delay-ms property

Changes for v2:
- Fix yamllint error for example
- Remove unused debug variable (nkeys)
- Remove support for custom linux,no-autorepeat DT property
- Remove support for custom gpio-activelow DT property

Thank you.

Hugo Villeneuve (4):
  dt-bindings: input: add debounce-delay-ms common property
  dt-bindings: input: add settling-time-us common property
  dt-bindings: input: add GPIO charlieplex keypad
  Input: charlieplex_keypad: add GPIO charlieplex keypad

 .../bindings/auxdisplay/holtek,ht16k33.yaml   |   5 +-
 .../bindings/input/cirrus,ep9307-keypad.yaml  |   7 +-
 .../input/gpio-charlieplex-keypad.yaml        | 108 +++++++++
 .../bindings/input/gpio-matrix-keypad.yaml    |   5 +-
 .../devicetree/bindings/input/input.yaml      |  16 ++
 .../input/mediatek,mt6779-keypad.yaml         |   1 +
 .../devicetree/bindings/mfd/fsl,mc13xxx.yaml  |   2 -
 MAINTAINERS                                   |   7 +
 drivers/input/keyboard/Kconfig                |  14 ++
 drivers/input/keyboard/Makefile               |   1 +
 drivers/input/keyboard/charlieplex_keypad.c   | 214 ++++++++++++++++++
 11 files changed, 368 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
 create mode 100644 drivers/input/keyboard/charlieplex_keypad.c


base-commit: 3bf5404fc93825ddde89992acad095a297ed9a31
-- 
2.47.3


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

* [PATCH v4 1/4] dt-bindings: input: add debounce-delay-ms common property
  2026-03-05 19:20 [PATCH v4 0/4] input: add GPIO-based charlieplex keypad Hugo Villeneuve
@ 2026-03-05 19:20 ` Hugo Villeneuve
  2026-03-12 15:03   ` Rob Herring (Arm)
  2026-03-05 19:20 ` [PATCH v4 2/4] dt-bindings: input: add settling-time-us " Hugo Villeneuve
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-05 19:20 UTC (permalink / raw)
  To: robin, andy, geert, robh, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz
  Cc: devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek, hugo

From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

A few bindings are already defining a debounce-delay-ms property, so
add it to the input binding to reduce redundant redefines.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 .../devicetree/bindings/auxdisplay/holtek,ht16k33.yaml    | 5 ++---
 .../devicetree/bindings/input/cirrus,ep9307-keypad.yaml   | 7 +++----
 .../devicetree/bindings/input/gpio-matrix-keypad.yaml     | 5 ++---
 Documentation/devicetree/bindings/input/input.yaml        | 8 ++++++++
 .../devicetree/bindings/input/mediatek,mt6779-keypad.yaml | 1 +
 Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml    | 2 --
 6 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml b/Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml
index b90eec2077b4b..c46a2471f8b10 100644
--- a/Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml
+++ b/Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml
@@ -10,6 +10,7 @@ maintainers:
   - Robin van der Gracht <robin@protonic.nl>
 
 allOf:
+  - $ref: /schemas/input/input.yaml#
   - $ref: /schemas/input/matrix-keymap.yaml#
 
 properties:
@@ -33,9 +34,7 @@ properties:
   interrupts:
     maxItems: 1
 
-  debounce-delay-ms:
-    maxItems: 1
-    description: Debouncing interval time in milliseconds
+  debounce-delay-ms: true
 
   linux,keymap: true
 
diff --git a/Documentation/devicetree/bindings/input/cirrus,ep9307-keypad.yaml b/Documentation/devicetree/bindings/input/cirrus,ep9307-keypad.yaml
index a0d2460c55ab6..25b8b29c87d70 100644
--- a/Documentation/devicetree/bindings/input/cirrus,ep9307-keypad.yaml
+++ b/Documentation/devicetree/bindings/input/cirrus,ep9307-keypad.yaml
@@ -10,6 +10,7 @@ maintainers:
   - Alexander Sverdlin <alexander.sverdlin@gmail.com>
 
 allOf:
+  - $ref: input.yaml#
   - $ref: /schemas/input/matrix-keymap.yaml#
 
 description:
@@ -37,10 +38,8 @@ properties:
   clocks:
     maxItems: 1
 
-  debounce-delay-ms:
-    description: |
-          Time in microseconds that key must be pressed or
-          released for state change interrupt to trigger.
+  # Time for state change interrupt to trigger
+  debounce-delay-ms: true
 
   cirrus,prescale:
     description: row/column counter pre-scaler load value
diff --git a/Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml b/Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml
index ebfff9e42a365..69df24a5ae701 100644
--- a/Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml
+++ b/Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml
@@ -18,6 +18,7 @@ description:
   report the event using GPIO interrupts to the cpu.
 
 allOf:
+  - $ref: input.yaml#
   - $ref: /schemas/input/matrix-keymap.yaml#
 
 properties:
@@ -46,9 +47,7 @@ properties:
       Force GPIO polarity to active low.
       In the absence of this property GPIOs are treated as active high.
 
-  debounce-delay-ms:
-    description: Debounce interval in milliseconds.
-    default: 0
+  debounce-delay-ms: true
 
   col-scan-delay-us:
     description:
diff --git a/Documentation/devicetree/bindings/input/input.yaml b/Documentation/devicetree/bindings/input/input.yaml
index 94f7942189e8c..502e0b7eb500a 100644
--- a/Documentation/devicetree/bindings/input/input.yaml
+++ b/Documentation/devicetree/bindings/input/input.yaml
@@ -14,6 +14,14 @@ properties:
     description: Enable autorepeat when key is pressed and held down.
     type: boolean
 
+  debounce-delay-ms:
+    description:
+      Debounce delay in milliseconds. This is the time during which the key
+      press or release signal must remain stable before it is considered valid.
+    minimum: 0
+    maximum: 999
+    default: 0
+
   linux,keycodes:
     description:
       Specifies an array of numeric keycode values to be used for reporting
diff --git a/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml b/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
index e365413732e7b..914dd3283df33 100644
--- a/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
+++ b/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
@@ -10,6 +10,7 @@ maintainers:
   - Mattijs Korpershoek <mkorpershoek@kernel.org>
 
 allOf:
+  - $ref: input.yaml#
   - $ref: /schemas/input/matrix-keymap.yaml#
 
 description: |
diff --git a/Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml b/Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml
index d2886f2686a8d..542ba51144243 100644
--- a/Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml
+++ b/Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml
@@ -76,8 +76,6 @@ properties:
           debounce-delay-ms:
             enum: [0, 30, 150, 750]
             default: 30
-            description:
-              Sets the debouncing delay in milliseconds.
 
           active-low:
             description: Set active when pin is pulled low.
-- 
2.47.3


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

* [PATCH v4 2/4] dt-bindings: input: add settling-time-us common property
  2026-03-05 19:20 [PATCH v4 0/4] input: add GPIO-based charlieplex keypad Hugo Villeneuve
  2026-03-05 19:20 ` [PATCH v4 1/4] dt-bindings: input: add debounce-delay-ms common property Hugo Villeneuve
@ 2026-03-05 19:20 ` Hugo Villeneuve
  2026-03-12 15:02   ` Rob Herring
  2026-03-05 19:20 ` [PATCH v4 3/4] dt-bindings: input: add GPIO charlieplex keypad Hugo Villeneuve
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-05 19:20 UTC (permalink / raw)
  To: robin, andy, geert, robh, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz
  Cc: devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek, hugo

From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

Add common property that can be reused by other bindings.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
Note: a similar property is used by gpio-matrix-keypad.yaml:
  col-scan-delay-us
---
 Documentation/devicetree/bindings/input/input.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/input.yaml b/Documentation/devicetree/bindings/input/input.yaml
index 502e0b7eb500a..14652d324e2ca 100644
--- a/Documentation/devicetree/bindings/input/input.yaml
+++ b/Documentation/devicetree/bindings/input/input.yaml
@@ -66,6 +66,14 @@ properties:
       reset automatically. Device with key pressed reset feature can specify
       this property.
 
+  settling-time-us:
+    description:
+      Delay, in microseconds, when activating an output line/col/row GPIO
+      before we can reliably read other input GPIOs that maybe affected by this
+      output. This can be the case for an output with a RC circuit that affects
+      ramp-up/down times.
+    default: 0
+
 dependencies:
   linux,input-type: [ "linux,code" ]
 
-- 
2.47.3


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

* [PATCH v4 3/4] dt-bindings: input: add GPIO charlieplex keypad
  2026-03-05 19:20 [PATCH v4 0/4] input: add GPIO-based charlieplex keypad Hugo Villeneuve
  2026-03-05 19:20 ` [PATCH v4 1/4] dt-bindings: input: add debounce-delay-ms common property Hugo Villeneuve
  2026-03-05 19:20 ` [PATCH v4 2/4] dt-bindings: input: add settling-time-us " Hugo Villeneuve
@ 2026-03-05 19:20 ` Hugo Villeneuve
  2026-03-12 15:02   ` Rob Herring (Arm)
  2026-03-05 19:20 ` [PATCH v4 4/4] Input: charlieplex_keypad: " Hugo Villeneuve
  2026-03-05 19:23 ` [PATCH v4 0/4] input: add GPIO-based " Hugo Villeneuve
  4 siblings, 1 reply; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-05 19:20 UTC (permalink / raw)
  To: robin, andy, geert, robh, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz
  Cc: devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek, hugo

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        | 108 ++++++++++++++++++
 1 file changed, 108 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 0000000000000..c085de6dab854
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
@@ -0,0 +1,108 @@
+# 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 I/O 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, as well as pull-up or pull-down
+  resistors on all I/O lines.
+  This mechanism doesn't allow to detect simultaneous key presses.
+
+  Wiring example for 3 lines keyboard with 6 switches and 3 diodes (pull-up/down
+  resistors not shown but needed on L0, L1 and L2):
+
+  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>
+
+    keyboard {
+        compatible = "gpio-charlieplex-keypad";
+        debounce-delay-ms = <20>;
+        poll-interval = <5>;
+        settling-time-us = <2>;
+
+        line-gpios = <&gpio2 25 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)
+                      &gpio2 26 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)
+                      &gpio2 27 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
+
+        /* 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


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

* [PATCH v4 4/4] Input: charlieplex_keypad: add GPIO charlieplex keypad
  2026-03-05 19:20 [PATCH v4 0/4] input: add GPIO-based charlieplex keypad Hugo Villeneuve
                   ` (2 preceding siblings ...)
  2026-03-05 19:20 ` [PATCH v4 3/4] dt-bindings: input: add GPIO charlieplex keypad Hugo Villeneuve
@ 2026-03-05 19:20 ` Hugo Villeneuve
  2026-03-06 14:21   ` Andy Shevchenko
  2026-03-05 19:23 ` [PATCH v4 0/4] input: add GPIO-based " Hugo Villeneuve
  4 siblings, 1 reply; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-05 19:20 UTC (permalink / raw)
  To: robin, andy, geert, robh, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz
  Cc: devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek, hugo

From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

Add support for GPIO-based charlieplex keypad, allowing to control
N^2-N keys using N GPIO lines.

Reuse matrix keypad keymap to simplify, even if there is no concept
of rows and columns in this type of keyboard.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 MAINTAINERS                                 |   7 +
 drivers/input/keyboard/Kconfig              |  14 ++
 drivers/input/keyboard/Makefile             |   1 +
 drivers/input/keyboard/charlieplex_keypad.c | 214 ++++++++++++++++++++
 4 files changed, 236 insertions(+)
 create mode 100644 drivers/input/keyboard/charlieplex_keypad.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 9ed6d11a77466..0b2d71f32b400 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5765,6 +5765,13 @@ S:	Maintained
 F:	Documentation/hwmon/powerz.rst
 F:	drivers/hwmon/powerz.c
 
+CHARLIEPLEX KEYPAD DRIVER
+M:	Hugo Villeneuve <hvilleneuve@dimonoff.com>
+S:	Supported
+W:	http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/electronic-circuits/matrix-keypad-scan-decode
+F:	Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
+F:	drivers/input/keyboard/charlieplex_keypad.c
+
 CHECKPATCH
 M:	Andy Whitcroft <apw@canonical.com>
 M:	Joe Perches <joe@perches.com>
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 2ff4fef322c24..ae54b4b7e2d8a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -289,6 +289,20 @@ config KEYBOARD_MATRIX
 	  To compile this driver as a module, choose M here: the
 	  module will be called matrix_keypad.
 
+config KEYBOARD_CHARLIEPLEX
+	tristate "GPIO driven chearlieplex keypad support"
+	depends on GPIOLIB || COMPILE_TEST
+	select INPUT_MATRIXKMAP
+	help
+	  Enable support for GPIO driven charlieplex keypad. A charlieplex
+	  keypad allows to use fewer GPIO lines to interface to key switches.
+	  For example, an N lines charlieplex keypad can be used to interface
+	  to N^2-N different key switches. However, this type of keypad
+	  cannot detect more than one key press at a time.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called charlieplex_keypad.
+
 config KEYBOARD_HIL_OLD
 	tristate "HP HIL keyboard support (simple driver)"
 	depends on GSC || HP300
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 2d906e14f3e27..40b5cf5d374d2 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_LOCOMO)		+= locomokbd.o
 obj-$(CONFIG_KEYBOARD_LPC32XX)		+= lpc32xx-keys.o
 obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
 obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
+obj-$(CONFIG_KEYBOARD_CHARLIEPLEX)	+= charlieplex_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7360)		+= max7360-keypad.o
 obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o
diff --git a/drivers/input/keyboard/charlieplex_keypad.c b/drivers/input/keyboard/charlieplex_keypad.c
new file mode 100644
index 0000000000000..53d6060e83fe9
--- /dev/null
+++ b/drivers/input/keyboard/charlieplex_keypad.c
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * GPIO driven charlieplex keypad driver
+ *
+ * Copyright (c) 2025 Hugo Villeneuve <hvilleneuve@dimonoff.com>
+ *
+ * Based on matrix_keyboard.c
+ */
+
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/dev_printk.h>
+#include <linux/device/devres.h>
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/input.h>
+#include <linux/input/matrix_keypad.h>
+#include <linux/math.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/types.h>
+
+struct charlieplex_keypad {
+	struct input_dev *input_dev;
+	struct gpio_descs *line_gpios;
+	unsigned int nlines;
+	unsigned int settling_time_us;
+	unsigned int debounce_threshold;
+	unsigned int debounce_count;
+	int debounce_code;
+	int current_code;
+};
+
+static void charlieplex_keypad_report_key(struct input_dev *input)
+{
+	struct charlieplex_keypad *keypad = input_get_drvdata(input);
+	const unsigned short *keycodes = input->keycode;
+
+	if (keypad->current_code > 0) {
+		input_event(input, EV_MSC, MSC_SCAN, keypad->current_code);
+		input_report_key(input, keycodes[keypad->current_code], 0);
+	}
+
+	if (keypad->debounce_code) {
+		input_event(input, EV_MSC, MSC_SCAN, keypad->debounce_code);
+		input_report_key(input, keycodes[keypad->debounce_code], 1);
+	}
+
+	input_sync(input);
+	keypad->current_code = keypad->debounce_code;
+}
+
+static void charlieplex_keypad_check_switch_change(struct input_dev *input,
+						   int code)
+{
+	struct charlieplex_keypad *keypad = input_get_drvdata(input);
+
+	if (code != keypad->debounce_code) {
+		keypad->debounce_count = 0;
+		keypad->debounce_code = code;
+	} else if (keypad->debounce_count < keypad->debounce_threshold) {
+		keypad->debounce_count++;
+
+		if (keypad->debounce_count >= keypad->debounce_threshold &&
+		    keypad->debounce_code != keypad->current_code)
+			charlieplex_keypad_report_key(input);
+	}
+}
+
+static void charlieplex_keypad_poll(struct input_dev *input)
+{
+	struct charlieplex_keypad *keypad = input_get_drvdata(input);
+	int oline;
+	int code;
+
+	for (code = 0, oline = 0; oline < keypad->nlines; oline++) {
+		DECLARE_BITMAP(values, MATRIX_MAX_ROWS);
+		int iline;
+		int err;
+
+		/* Activate only one line as output at a time. */
+		gpiod_direction_output(keypad->line_gpios->desc[oline], 1);
+
+		if (keypad->settling_time_us)
+			fsleep(keypad->settling_time_us);
+
+		/* Read input on all other lines. */
+		err = gpiod_get_array_value_cansleep(keypad->line_gpios->ndescs,
+						     keypad->line_gpios->desc,
+						     keypad->line_gpios->info, values);
+		if (err)
+			return;
+
+		for (iline = 0; iline < keypad->nlines; iline++) {
+			if (iline == oline)
+				continue; /* Do not read active output line. */
+
+			/* Check if GPIO is asserted. */
+			if (test_bit(iline, values)) {
+				code = MATRIX_SCAN_CODE(oline, iline,
+							get_count_order(keypad->nlines));
+				/*
+				 * Exit loop immediately since we cannot detect
+				 * more than one key press at a time.
+				 */
+				break;
+			}
+		}
+
+		gpiod_direction_input(keypad->line_gpios->desc[oline]);
+
+		if (code)
+			break;
+	}
+
+	charlieplex_keypad_check_switch_change(input, code);
+}
+
+static int charlieplex_keypad_init_gpio(struct platform_device *pdev,
+					struct charlieplex_keypad *keypad)
+{
+	keypad->line_gpios = devm_gpiod_get_array(&pdev->dev, "line", GPIOD_IN);
+	if (IS_ERR(keypad->line_gpios))
+		return PTR_ERR(keypad->line_gpios);
+
+	keypad->nlines = keypad->line_gpios->ndescs;
+
+	if (keypad->nlines > MATRIX_MAX_ROWS)
+		return -EINVAL;
+
+	for (unsigned int i = 0; i < keypad->nlines; i++)
+		gpiod_set_consumer_name(keypad->line_gpios->desc[i], "charlieplex_kbd_line");
+
+	return 0;
+}
+
+static int charlieplex_keypad_probe(struct platform_device *pdev)
+{
+	struct charlieplex_keypad *keypad;
+	unsigned int debounce_interval_ms;
+	unsigned int poll_interval_ms;
+	struct input_dev *input_dev;
+	int err;
+
+	keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL);
+	if (!keypad)
+		return -ENOMEM;
+
+	input_dev = devm_input_allocate_device(&pdev->dev);
+	if (!input_dev)
+		return -ENOMEM;
+
+	keypad->input_dev = input_dev;
+
+	device_property_read_u32(&pdev->dev, "poll-interval", &poll_interval_ms);
+	device_property_read_u32(&pdev->dev, "debounce-delay-ms", &debounce_interval_ms);
+	device_property_read_u32(&pdev->dev, "settling-time-us", &keypad->settling_time_us);
+
+	keypad->current_code = -1;
+	keypad->debounce_code = -1;
+	keypad->debounce_threshold = DIV_ROUND_UP(debounce_interval_ms, poll_interval_ms);
+
+	err = charlieplex_keypad_init_gpio(pdev, keypad);
+	if (err)
+		return err;
+
+	input_dev->name		= pdev->name;
+	input_dev->id.bustype	= BUS_HOST;
+
+	err = matrix_keypad_build_keymap(NULL, NULL, keypad->nlines,
+					 keypad->nlines, NULL, input_dev);
+	if (err)
+		dev_err_probe(&pdev->dev, -ENOMEM, "failed to build keymap\n");
+
+	if (device_property_read_bool(&pdev->dev, "autorepeat"))
+		__set_bit(EV_REP, input_dev->evbit);
+
+	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
+
+	err = input_setup_polling(input_dev, charlieplex_keypad_poll);
+	if (err)
+		dev_err_probe(&pdev->dev, err, "unable to set up polling\n");
+
+	input_set_poll_interval(input_dev, poll_interval_ms);
+
+	input_set_drvdata(input_dev, keypad);
+
+	err = input_register_device(keypad->input_dev);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static const struct of_device_id charlieplex_keypad_dt_match[] = {
+	{ .compatible = "gpio-charlieplex-keypad" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, charlieplex_keypad_dt_match);
+
+static struct platform_driver charlieplex_keypad_driver = {
+	.probe		= charlieplex_keypad_probe,
+	.driver		= {
+		.name	= "charlieplex-keypad",
+		.of_match_table = charlieplex_keypad_dt_match,
+	},
+};
+module_platform_driver(charlieplex_keypad_driver);
+
+MODULE_AUTHOR("Hugo Villeneuve <hvilleneuve@dimonoff.com>");
+MODULE_DESCRIPTION("GPIO driven charlieplex keypad driver");
+MODULE_LICENSE("GPL");
-- 
2.47.3


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

* Re: [PATCH v4 0/4] input: add GPIO-based charlieplex keypad
  2026-03-05 19:20 [PATCH v4 0/4] input: add GPIO-based charlieplex keypad Hugo Villeneuve
                   ` (3 preceding siblings ...)
  2026-03-05 19:20 ` [PATCH v4 4/4] Input: charlieplex_keypad: " Hugo Villeneuve
@ 2026-03-05 19:23 ` Hugo Villeneuve
  4 siblings, 0 replies; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-05 19:23 UTC (permalink / raw)
  To: Hugo Villeneuve
  Cc: robin, andy, geert, robh, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz, devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek

On Thu,  5 Mar 2026 14:20:46 -0500
Hugo Villeneuve <hugo@hugovil.com> wrote:

> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> Hello,
> this patch series add a new GPIO charlieplex keypad driver.
> 
> The first two patches simply commonize two properties that are present in
> a few bindings, so that the actual patches for the charlieplex keypad driver
> can reuse them instead of also redefining them.
> 
> I have tested the driver on a custom board with a Solidrun RZ/G2LC SOM
> with three charlieplex keyboards, all connected thru a single PCAL6416 I2C GPIO
> expander.
> 
> Link: [v1] https://lore.kernel.org/all/20260203155023.536103-1-hugo@hugovil.com/
> Link: [v2] https://lore.kernel.org/all/20260213171431.2228814-1-hugo@hugovil.com/
> Link: [v3] https://lore.kernel.org/all/20260225155409.612478-1-hugo@hugovil.com/
> 
> Changes for v4:
> - Fix indentation in comments (Andy)
> - Add missing includes (Andy)
> - Remove OF dependency (Andy/Dmitry)
> - Uniformize return code variables to "err" (Andy/Dmitry)
> - Change signed iterator to unsigned and move within loop (Andy)
> - Remove unused platform_set_drvdata() (Andy)
> - Fixed typo in cover letter PCAL6416 (Geert)
> - Changed name in bindings example (Geert)
> - Added pull resistors to bindings doc and example (Geert)
> - Add debounce-delay-ms common property
> - Add settling-time-us common property

Please ignore the last two lines that were already mentioned for V3.

Hugo.


> 
> Changes for v3:
> - Add ASCII diagram in bindings, and reference to it in example
> - Reorder properties alphabetically
> - Add patch to define common input settling-time-us property
> - Add patch to define common input debounce-delay-ms property
> 
> Changes for v2:
> - Fix yamllint error for example
> - Remove unused debug variable (nkeys)
> - Remove support for custom linux,no-autorepeat DT property
> - Remove support for custom gpio-activelow DT property
> 
> Thank you.
> 
> Hugo Villeneuve (4):
>   dt-bindings: input: add debounce-delay-ms common property
>   dt-bindings: input: add settling-time-us common property
>   dt-bindings: input: add GPIO charlieplex keypad
>   Input: charlieplex_keypad: add GPIO charlieplex keypad
> 
>  .../bindings/auxdisplay/holtek,ht16k33.yaml   |   5 +-
>  .../bindings/input/cirrus,ep9307-keypad.yaml  |   7 +-
>  .../input/gpio-charlieplex-keypad.yaml        | 108 +++++++++
>  .../bindings/input/gpio-matrix-keypad.yaml    |   5 +-
>  .../devicetree/bindings/input/input.yaml      |  16 ++
>  .../input/mediatek,mt6779-keypad.yaml         |   1 +
>  .../devicetree/bindings/mfd/fsl,mc13xxx.yaml  |   2 -
>  MAINTAINERS                                   |   7 +
>  drivers/input/keyboard/Kconfig                |  14 ++
>  drivers/input/keyboard/Makefile               |   1 +
>  drivers/input/keyboard/charlieplex_keypad.c   | 214 ++++++++++++++++++
>  11 files changed, 368 insertions(+), 12 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
>  create mode 100644 drivers/input/keyboard/charlieplex_keypad.c
> 
> 
> base-commit: 3bf5404fc93825ddde89992acad095a297ed9a31
> -- 
> 2.47.3
> 
> 


-- 
Hugo Villeneuve

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

* Re: [PATCH v4 4/4] Input: charlieplex_keypad: add GPIO charlieplex keypad
  2026-03-05 19:20 ` [PATCH v4 4/4] Input: charlieplex_keypad: " Hugo Villeneuve
@ 2026-03-06 14:21   ` Andy Shevchenko
  2026-03-10 18:37     ` Dmitry Torokhov
  2026-03-12 16:12     ` Hugo Villeneuve
  0 siblings, 2 replies; 15+ messages in thread
From: Andy Shevchenko @ 2026-03-06 14:21 UTC (permalink / raw)
  To: Hugo Villeneuve
  Cc: robin, andy, geert, robh, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz, devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek

On Thu, Mar 05, 2026 at 02:20:50PM -0500, Hugo Villeneuve wrote:

> Add support for GPIO-based charlieplex keypad, allowing to control
> N^2-N keys using N GPIO lines.
> 
> Reuse matrix keypad keymap to simplify, even if there is no concept
> of rows and columns in this type of keyboard.

...

> --- a/drivers/input/keyboard/Makefile
> +++ b/drivers/input/keyboard/Makefile
> @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_LOCOMO)		+= locomokbd.o
>  obj-$(CONFIG_KEYBOARD_LPC32XX)		+= lpc32xx-keys.o
>  obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
>  obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
> +obj-$(CONFIG_KEYBOARD_CHARLIEPLEX)	+= charlieplex_keypad.o

Seem unordered. At least the all around it is ordered AFAICS.

>  obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
>  obj-$(CONFIG_KEYBOARD_MAX7360)		+= max7360-keypad.o
>  obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o

...

> +/*
> + * GPIO driven charlieplex keypad driver
> + *
> + * Copyright (c) 2025 Hugo Villeneuve <hvilleneuve@dimonoff.com>

2026?

> + *
> + * Based on matrix_keyboard.c
> + */

...

> +#include <linux/bitops.h>
> +#include <linux/delay.h>
> +#include <linux/dev_printk.h>
> +#include <linux/device/devres.h>
> +#include <linux/err.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/input.h>
> +#include <linux/input/matrix_keypad.h>
> +#include <linux/math.h>
> +#include <linux/module.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/types.h>

> +static void charlieplex_keypad_poll(struct input_dev *input)
> +{
> +	struct charlieplex_keypad *keypad = input_get_drvdata(input);

> +	int oline;

Why signed?

> +	int code;
> +
> +	for (code = 0, oline = 0; oline < keypad->nlines; oline++) {

Can be like

	code = 0;
	for (unsigned int oline = 0; oline < keypad->nlines; oline++) {

as iterator is not used outside the loop.

> +		DECLARE_BITMAP(values, MATRIX_MAX_ROWS);

> +		int iline;

Why signed?

> +		int err;
> +
> +		/* Activate only one line as output at a time. */
> +		gpiod_direction_output(keypad->line_gpios->desc[oline], 1);
> +
> +		if (keypad->settling_time_us)
> +			fsleep(keypad->settling_time_us);
> +
> +		/* Read input on all other lines. */
> +		err = gpiod_get_array_value_cansleep(keypad->line_gpios->ndescs,
> +						     keypad->line_gpios->desc,
> +						     keypad->line_gpios->info, values);
> +		if (err)
> +			return;

> +		for (iline = 0; iline < keypad->nlines; iline++) {

Can be just

		for (unsigned int iline = 0; iline < keypad->nlines; iline++) {

as iterator is not used outside the loop.

> +			if (iline == oline)
> +				continue; /* Do not read active output line. */
> +
> +			/* Check if GPIO is asserted. */
> +			if (test_bit(iline, values)) {
> +				code = MATRIX_SCAN_CODE(oline, iline,
> +							get_count_order(keypad->nlines));
> +				/*
> +				 * Exit loop immediately since we cannot detect
> +				 * more than one key press at a time.
> +				 */
> +				break;
> +			}
> +		}
> +
> +		gpiod_direction_input(keypad->line_gpios->desc[oline]);
> +
> +		if (code)
> +			break;
> +	}
> +
> +	charlieplex_keypad_check_switch_change(input, code);
> +}

...

> +	for (unsigned int i = 0; i < keypad->nlines; i++)
> +		gpiod_set_consumer_name(keypad->line_gpios->desc[i], "charlieplex_kbd_line");

Hmm... Don't you want to give it an index?

(In case you go this direction, see the kasprintf_strarray() or
 its managed variant.)

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v4 4/4] Input: charlieplex_keypad: add GPIO charlieplex keypad
  2026-03-06 14:21   ` Andy Shevchenko
@ 2026-03-10 18:37     ` Dmitry Torokhov
  2026-03-10 19:18       ` Andy Shevchenko
  2026-03-12 16:12     ` Hugo Villeneuve
  1 sibling, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2026-03-10 18:37 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Hugo Villeneuve, robin, andy, geert, robh, krzk+dt, conor+dt,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz, devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek

On Fri, Mar 06, 2026 at 04:21:09PM +0200, Andy Shevchenko wrote:
> On Thu, Mar 05, 2026 at 02:20:50PM -0500, Hugo Villeneuve wrote:
> > +static void charlieplex_keypad_poll(struct input_dev *input)
> > +{
> > +	struct charlieplex_keypad *keypad = input_get_drvdata(input);
> 
> > +	int oline;
> 
> Why signed?
> 
> > +	int code;
> > +
> > +	for (code = 0, oline = 0; oline < keypad->nlines; oline++) {
> 
> Can be like
> 
> 	code = 0;
> 	for (unsigned int oline = 0; oline < keypad->nlines; oline++) {
> 
> as iterator is not used outside the loop.
> 
> > +		DECLARE_BITMAP(values, MATRIX_MAX_ROWS);
> 
> > +		int iline;
> 
> Why signed?

Does it make any difference given practical limits on nlines?

Thanks.

-- 
Dmitry

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

* Re: [PATCH v4 4/4] Input: charlieplex_keypad: add GPIO charlieplex keypad
  2026-03-10 18:37     ` Dmitry Torokhov
@ 2026-03-10 19:18       ` Andy Shevchenko
  2026-03-11 14:26         ` Hugo Villeneuve
  0 siblings, 1 reply; 15+ messages in thread
From: Andy Shevchenko @ 2026-03-10 19:18 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Hugo Villeneuve, robin, andy, geert, robh, krzk+dt, conor+dt,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz, devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek

On Tue, Mar 10, 2026 at 06:37:34PM +0000, Dmitry Torokhov wrote:
> On Fri, Mar 06, 2026 at 04:21:09PM +0200, Andy Shevchenko wrote:
> > On Thu, Mar 05, 2026 at 02:20:50PM -0500, Hugo Villeneuve wrote:

...

> > > +	int oline;
> > 
> > Why signed?
> > 
> > > +	int code;
> > > +
> > > +	for (code = 0, oline = 0; oline < keypad->nlines; oline++) {
> > 
> > Can be like
> > 
> > 	code = 0;
> > 	for (unsigned int oline = 0; oline < keypad->nlines; oline++) {
> > 
> > as iterator is not used outside the loop.
> > 
> > > +		DECLARE_BITMAP(values, MATRIX_MAX_ROWS);
> > 
> > > +		int iline;
> > 
> > Why signed?
> 
> Does it make any difference given practical limits on nlines?

Maybe not, but might lead to interesting bugs in the future in case if used in
some arithmetics.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v4 4/4] Input: charlieplex_keypad: add GPIO charlieplex keypad
  2026-03-10 19:18       ` Andy Shevchenko
@ 2026-03-11 14:26         ` Hugo Villeneuve
  0 siblings, 0 replies; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-11 14:26 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Dmitry Torokhov, robin, andy, geert, robh, krzk+dt, conor+dt,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz, devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek

Hi Andy,

On Tue, 10 Mar 2026 21:18:25 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Tue, Mar 10, 2026 at 06:37:34PM +0000, Dmitry Torokhov wrote:
> > On Fri, Mar 06, 2026 at 04:21:09PM +0200, Andy Shevchenko wrote:
> > > On Thu, Mar 05, 2026 at 02:20:50PM -0500, Hugo Villeneuve wrote:
> 
> ...
> 
> > > > +	int oline;
> > > 
> > > Why signed?
> > > 
> > > > +	int code;
> > > > +
> > > > +	for (code = 0, oline = 0; oline < keypad->nlines; oline++) {
> > > 
> > > Can be like
> > > 
> > > 	code = 0;
> > > 	for (unsigned int oline = 0; oline < keypad->nlines; oline++) {
> > > 
> > > as iterator is not used outside the loop.
> > > 
> > > > +		DECLARE_BITMAP(values, MATRIX_MAX_ROWS);
> > > 
> > > > +		int iline;
> > > 
> > > Why signed?
> > 
> > Does it make any difference given practical limits on nlines?
> 
> Maybe not, but might lead to interesting bugs in the future in case if used in
> some arithmetics.

I'll fix this in next version.

Hugo.


> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 


-- 
Hugo Villeneuve

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

* Re: [PATCH v4 2/4] dt-bindings: input: add settling-time-us common property
  2026-03-05 19:20 ` [PATCH v4 2/4] dt-bindings: input: add settling-time-us " Hugo Villeneuve
@ 2026-03-12 15:02   ` Rob Herring
  2026-03-12 15:44     ` Hugo Villeneuve
  0 siblings, 1 reply; 15+ messages in thread
From: Rob Herring @ 2026-03-12 15:02 UTC (permalink / raw)
  To: Hugo Villeneuve
  Cc: robin, andy, geert, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz, devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek

On Thu, Mar 05, 2026 at 02:20:48PM -0500, Hugo Villeneuve wrote:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> Add common property that can be reused by other bindings.
> 
> Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> ---
> Note: a similar property is used by gpio-matrix-keypad.yaml:
>   col-scan-delay-us
> ---
>  Documentation/devicetree/bindings/input/input.yaml | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/input/input.yaml b/Documentation/devicetree/bindings/input/input.yaml
> index 502e0b7eb500a..14652d324e2ca 100644
> --- a/Documentation/devicetree/bindings/input/input.yaml
> +++ b/Documentation/devicetree/bindings/input/input.yaml
> @@ -66,6 +66,14 @@ properties:
>        reset automatically. Device with key pressed reset feature can specify
>        this property.
>  
> +  settling-time-us:
> +    description:
> +      Delay, in microseconds, when activating an output line/col/row GPIO
> +      before we can reliably read other input GPIOs that maybe affected by this
> +      output. This can be the case for an output with a RC circuit that affects
> +      ramp-up/down times.

Whether it is GPIOs or not depends on the implementation. Just drop 
'GPIO' and replace 'GPIOs' with 'lines'.

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>

Rob

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

* Re: [PATCH v4 3/4] dt-bindings: input: add GPIO charlieplex keypad
  2026-03-05 19:20 ` [PATCH v4 3/4] dt-bindings: input: add GPIO charlieplex keypad Hugo Villeneuve
@ 2026-03-12 15:02   ` Rob Herring (Arm)
  0 siblings, 0 replies; 15+ messages in thread
From: Rob Herring (Arm) @ 2026-03-12 15:02 UTC (permalink / raw)
  To: Hugo Villeneuve
  Cc: akurz, linux-mediatek, mkorpershoek, andy, devicetree,
	alexander.sverdlin, dmitry.torokhov, linux-arm-kernel,
	linux-kernel, krzk+dt, matthias.bgg, lee, robin, linux-input,
	conor+dt, marek.vasut, hvilleneuve, geert,
	angelogioacchino.delregno


On Thu, 05 Mar 2026 14:20:49 -0500, Hugo Villeneuve wrote:
> 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        | 108 ++++++++++++++++++
>  1 file changed, 108 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


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

* Re: [PATCH v4 1/4] dt-bindings: input: add debounce-delay-ms common property
  2026-03-05 19:20 ` [PATCH v4 1/4] dt-bindings: input: add debounce-delay-ms common property Hugo Villeneuve
@ 2026-03-12 15:03   ` Rob Herring (Arm)
  0 siblings, 0 replies; 15+ messages in thread
From: Rob Herring (Arm) @ 2026-03-12 15:03 UTC (permalink / raw)
  To: Hugo Villeneuve
  Cc: matthias.bgg, linux-kernel, akurz, linux-mediatek, geert, lee,
	hvilleneuve, conor+dt, linux-input, angelogioacchino.delregno,
	andy, robin, mkorpershoek, krzk+dt, alexander.sverdlin,
	devicetree, dmitry.torokhov, marek.vasut, linux-arm-kernel


On Thu, 05 Mar 2026 14:20:47 -0500, Hugo Villeneuve wrote:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> A few bindings are already defining a debounce-delay-ms property, so
> add it to the input binding to reduce redundant redefines.
> 
> Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> ---
>  .../devicetree/bindings/auxdisplay/holtek,ht16k33.yaml    | 5 ++---
>  .../devicetree/bindings/input/cirrus,ep9307-keypad.yaml   | 7 +++----
>  .../devicetree/bindings/input/gpio-matrix-keypad.yaml     | 5 ++---
>  Documentation/devicetree/bindings/input/input.yaml        | 8 ++++++++
>  .../devicetree/bindings/input/mediatek,mt6779-keypad.yaml | 1 +
>  Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml    | 2 --
>  6 files changed, 16 insertions(+), 12 deletions(-)
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


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

* Re: [PATCH v4 2/4] dt-bindings: input: add settling-time-us common property
  2026-03-12 15:02   ` Rob Herring
@ 2026-03-12 15:44     ` Hugo Villeneuve
  0 siblings, 0 replies; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-12 15:44 UTC (permalink / raw)
  To: Rob Herring
  Cc: robin, andy, geert, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz, devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek

Hi Rob,

On Thu, 12 Mar 2026 10:02:10 -0500
Rob Herring <robh@kernel.org> wrote:

> On Thu, Mar 05, 2026 at 02:20:48PM -0500, Hugo Villeneuve wrote:
> > From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > 
> > Add common property that can be reused by other bindings.
> > 
> > Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > ---
> > Note: a similar property is used by gpio-matrix-keypad.yaml:
> >   col-scan-delay-us
> > ---
> >  Documentation/devicetree/bindings/input/input.yaml | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/input/input.yaml b/Documentation/devicetree/bindings/input/input.yaml
> > index 502e0b7eb500a..14652d324e2ca 100644
> > --- a/Documentation/devicetree/bindings/input/input.yaml
> > +++ b/Documentation/devicetree/bindings/input/input.yaml
> > @@ -66,6 +66,14 @@ properties:
> >        reset automatically. Device with key pressed reset feature can specify
> >        this property.
> >  
> > +  settling-time-us:
> > +    description:
> > +      Delay, in microseconds, when activating an output line/col/row GPIO
> > +      before we can reliably read other input GPIOs that maybe affected by this
> > +      output. This can be the case for an output with a RC circuit that affects
> > +      ramp-up/down times.
> 
> Whether it is GPIOs or not depends on the implementation. Just drop 
> 'GPIO' and replace 'GPIOs' with 'lines'.

Ok, will do for V5.

Hugo

> 
> Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
> 
> Rob
> 

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

* Re: [PATCH v4 4/4] Input: charlieplex_keypad: add GPIO charlieplex keypad
  2026-03-06 14:21   ` Andy Shevchenko
  2026-03-10 18:37     ` Dmitry Torokhov
@ 2026-03-12 16:12     ` Hugo Villeneuve
  1 sibling, 0 replies; 15+ messages in thread
From: Hugo Villeneuve @ 2026-03-12 16:12 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: robin, andy, geert, robh, krzk+dt, conor+dt, dmitry.torokhov,
	hvilleneuve, mkorpershoek, matthias.bgg,
	angelogioacchino.delregno, lee, alexander.sverdlin, marek.vasut,
	akurz, devicetree, linux-kernel, linux-input, linux-arm-kernel,
	linux-mediatek

Hi Andy,

On Fri, 6 Mar 2026 16:21:09 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Thu, Mar 05, 2026 at 02:20:50PM -0500, Hugo Villeneuve wrote:
> 
> > Add support for GPIO-based charlieplex keypad, allowing to control
> > N^2-N keys using N GPIO lines.
> > 
> > Reuse matrix keypad keymap to simplify, even if there is no concept
> > of rows and columns in this type of keyboard.
> 
> ...
> 
> > --- a/drivers/input/keyboard/Makefile
> > +++ b/drivers/input/keyboard/Makefile
> > @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_LOCOMO)		+= locomokbd.o
> >  obj-$(CONFIG_KEYBOARD_LPC32XX)		+= lpc32xx-keys.o
> >  obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
> >  obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
> > +obj-$(CONFIG_KEYBOARD_CHARLIEPLEX)	+= charlieplex_keypad.o
> 
> Seem unordered. At least the all around it is ordered AFAICS.

Will fix it.


> 
> >  obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MAX7360)		+= max7360-keypad.o
> >  obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o
> 
> ...
> 
> > +/*
> > + * GPIO driven charlieplex keypad driver
> > + *
> > + * Copyright (c) 2025 Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> 2026?

Ok


> 
> > + *
> > + * Based on matrix_keyboard.c
> > + */
> 
> ...
> 
> > +#include <linux/bitops.h>
> > +#include <linux/delay.h>
> > +#include <linux/dev_printk.h>
> > +#include <linux/device/devres.h>
> > +#include <linux/err.h>
> > +#include <linux/gpio/consumer.h>
> > +#include <linux/input.h>
> > +#include <linux/input/matrix_keypad.h>
> > +#include <linux/math.h>
> > +#include <linux/module.h>
> > +#include <linux/mod_devicetable.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/property.h>
> > +#include <linux/types.h>
> 
> > +static void charlieplex_keypad_poll(struct input_dev *input)
> > +{
> > +	struct charlieplex_keypad *keypad = input_get_drvdata(input);
> 
> > +	int oline;
> 
> Why signed?

Will change this one, and others noted below to unsigned.


> 
> > +	int code;
> > +
> > +	for (code = 0, oline = 0; oline < keypad->nlines; oline++) {
> 
> Can be like
> 
> 	code = 0;
> 	for (unsigned int oline = 0; oline < keypad->nlines; oline++) {
> 
> as iterator is not used outside the loop.

Ok, will do.


> 
> > +		DECLARE_BITMAP(values, MATRIX_MAX_ROWS);
> 
> > +		int iline;
> 
> Why signed?
> 
> > +		int err;
> > +
> > +		/* Activate only one line as output at a time. */
> > +		gpiod_direction_output(keypad->line_gpios->desc[oline], 1);
> > +
> > +		if (keypad->settling_time_us)
> > +			fsleep(keypad->settling_time_us);
> > +
> > +		/* Read input on all other lines. */
> > +		err = gpiod_get_array_value_cansleep(keypad->line_gpios->ndescs,
> > +						     keypad->line_gpios->desc,
> > +						     keypad->line_gpios->info, values);
> > +		if (err)
> > +			return;
> 
> > +		for (iline = 0; iline < keypad->nlines; iline++) {
> 
> Can be just
> 
> 		for (unsigned int iline = 0; iline < keypad->nlines; iline++) {
> 
> as iterator is not used outside the loop.

Ok.


> 
> > +			if (iline == oline)
> > +				continue; /* Do not read active output line. */
> > +
> > +			/* Check if GPIO is asserted. */
> > +			if (test_bit(iline, values)) {
> > +				code = MATRIX_SCAN_CODE(oline, iline,
> > +							get_count_order(keypad->nlines));
> > +				/*
> > +				 * Exit loop immediately since we cannot detect
> > +				 * more than one key press at a time.
> > +				 */
> > +				break;
> > +			}
> > +		}
> > +
> > +		gpiod_direction_input(keypad->line_gpios->desc[oline]);
> > +
> > +		if (code)
> > +			break;
> > +	}
> > +
> > +	charlieplex_keypad_check_switch_change(input, code);
> > +}
> 
> ...
> 
> > +	for (unsigned int i = 0; i < keypad->nlines; i++)
> > +		(keypad->line_gpios->desc[i], "charlieplex_kbd_line");
> 
> Hmm... Don't you want to give it an index?

Makes sense, will do.

I will also change for "keypad->line_gpios->ndescs" in the loop
iterator.


> 
> (In case you go this direction, see the kasprintf_strarray() or
>  its managed variant.)
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 


-- 
Hugo Villeneuve

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

end of thread, other threads:[~2026-03-12 16:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 19:20 [PATCH v4 0/4] input: add GPIO-based charlieplex keypad Hugo Villeneuve
2026-03-05 19:20 ` [PATCH v4 1/4] dt-bindings: input: add debounce-delay-ms common property Hugo Villeneuve
2026-03-12 15:03   ` Rob Herring (Arm)
2026-03-05 19:20 ` [PATCH v4 2/4] dt-bindings: input: add settling-time-us " Hugo Villeneuve
2026-03-12 15:02   ` Rob Herring
2026-03-12 15:44     ` Hugo Villeneuve
2026-03-05 19:20 ` [PATCH v4 3/4] dt-bindings: input: add GPIO charlieplex keypad Hugo Villeneuve
2026-03-12 15:02   ` Rob Herring (Arm)
2026-03-05 19:20 ` [PATCH v4 4/4] Input: charlieplex_keypad: " Hugo Villeneuve
2026-03-06 14:21   ` Andy Shevchenko
2026-03-10 18:37     ` Dmitry Torokhov
2026-03-10 19:18       ` Andy Shevchenko
2026-03-11 14:26         ` Hugo Villeneuve
2026-03-12 16:12     ` Hugo Villeneuve
2026-03-05 19:23 ` [PATCH v4 0/4] input: add GPIO-based " Hugo Villeneuve

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox