* [PATCH v6 1/3] Input: matrix_keypad - add function for reading row state
2025-02-26 15:28 [PATCH v6 0/3] Input: matrix-keypad: Various performance improvements Markus Burri
@ 2025-02-26 15:28 ` Markus Burri
2025-02-26 15:28 ` [PATCH v6 2/3] dt-bindings: input: matrix_keypad - add missing property Markus Burri
2025-02-26 15:28 ` [PATCH v6 3/3] Input: matrix_keypad - detect change during scan Markus Burri
2 siblings, 0 replies; 5+ messages in thread
From: Markus Burri @ 2025-02-26 15:28 UTC (permalink / raw)
To: linux-kernel
Cc: Markus Burri, Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Marek Vasut, linux-input, devicetree, Markus Burri,
Manuel Traut
Move the evaluation of a row state into separate function.
It will be also used by a change later in this series.
Signed-off-by: Markus Burri <markus.burri@mt.com>
---
drivers/input/keyboard/matrix_keypad.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index e46473cb8..fdb349966 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -104,6 +104,16 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
disable_irq_nosync(keypad->row_irqs[i]);
}
+static uint32_t read_row_state(struct matrix_keypad *keypad)
+{
+ int row;
+ u32 row_state = 0;
+
+ for (row = 0; row < keypad->num_row_gpios; row++)
+ row_state |= row_asserted(keypad, row) ? BIT(row) : 0;
+ return row_state;
+}
+
/*
* This gets the keys from keyboard and reports it to input subsystem
*/
@@ -129,9 +139,7 @@ static void matrix_keypad_scan(struct work_struct *work)
activate_col(keypad, col, true);
- for (row = 0; row < keypad->num_row_gpios; row++)
- new_state[col] |=
- row_asserted(keypad, row) ? BIT(row) : 0;
+ new_state[col] = read_row_state(keypad);
activate_col(keypad, col, false);
}
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v6 2/3] dt-bindings: input: matrix_keypad - add missing property
2025-02-26 15:28 [PATCH v6 0/3] Input: matrix-keypad: Various performance improvements Markus Burri
2025-02-26 15:28 ` [PATCH v6 1/3] Input: matrix_keypad - add function for reading row state Markus Burri
@ 2025-02-26 15:28 ` Markus Burri
2025-02-28 1:07 ` Dmitry Torokhov
2025-02-26 15:28 ` [PATCH v6 3/3] Input: matrix_keypad - detect change during scan Markus Burri
2 siblings, 1 reply; 5+ messages in thread
From: Markus Burri @ 2025-02-26 15:28 UTC (permalink / raw)
To: linux-kernel
Cc: Markus Burri, Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Marek Vasut, linux-input, devicetree, Markus Burri,
Manuel Traut
The property is implemented in the driver but not described in dt-bindings.
Add missing property 'gpio-activelow' to DT schema.
Signed-off-by: Markus Burri <markus.burri@mt.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
---
.../devicetree/bindings/input/gpio-matrix-keypad.yaml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml b/Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml
index 4a5893edf..73bb153ed 100644
--- a/Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml
+++ b/Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml
@@ -40,6 +40,11 @@ properties:
type: boolean
description: Do not enable autorepeat feature.
+ gpio-activelow:
+ type: boolean
+ description:
+ 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.
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v6 2/3] dt-bindings: input: matrix_keypad - add missing property
2025-02-26 15:28 ` [PATCH v6 2/3] dt-bindings: input: matrix_keypad - add missing property Markus Burri
@ 2025-02-28 1:07 ` Dmitry Torokhov
0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Torokhov @ 2025-02-28 1:07 UTC (permalink / raw)
To: Markus Burri
Cc: linux-kernel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Marek Vasut, linux-input, devicetree, Markus Burri, Manuel Traut
On Wed, Feb 26, 2025 at 04:28:42PM +0100, Markus Burri wrote:
> The property is implemented in the driver but not described in dt-bindings.
> Add missing property 'gpio-activelow' to DT schema.
>
> Signed-off-by: Markus Burri <markus.burri@mt.com>
> Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Applied but dropped Rob's reviewed-by because the patch is different
from what he has reviewed.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v6 3/3] Input: matrix_keypad - detect change during scan
2025-02-26 15:28 [PATCH v6 0/3] Input: matrix-keypad: Various performance improvements Markus Burri
2025-02-26 15:28 ` [PATCH v6 1/3] Input: matrix_keypad - add function for reading row state Markus Burri
2025-02-26 15:28 ` [PATCH v6 2/3] dt-bindings: input: matrix_keypad - add missing property Markus Burri
@ 2025-02-26 15:28 ` Markus Burri
2 siblings, 0 replies; 5+ messages in thread
From: Markus Burri @ 2025-02-26 15:28 UTC (permalink / raw)
To: linux-kernel
Cc: Markus Burri, Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Marek Vasut, linux-input, devicetree, Markus Burri,
Manuel Traut
For a setup where the matrix keypad is connected over a slow interface
(e.g. a gpio-expansion over i2c), the scan can take a longer time to read.
Interrupts need to be disabled during scan. And therefore changes in this
period are not detected.
To improve this situation, scan the matrix again if the row state changed
during interrupts disabled.
The rescan is repeated until no change is detected anymore.
Signed-off-by: Markus Burri <markus.burri@mt.com>
---
drivers/input/keyboard/matrix_keypad.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index fdb349966..e50a6fea9 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -125,6 +125,10 @@ static void matrix_keypad_scan(struct work_struct *work)
const unsigned short *keycodes = input_dev->keycode;
uint32_t new_state[MATRIX_MAX_COLS];
int row, col, code;
+ u32 init_row_state, new_row_state;
+
+ /* read initial row state to detect changes between scan */
+ init_row_state = read_row_state(keypad);
/* de-activate all columns for scanning */
activate_all_cols(keypad, false);
@@ -173,6 +177,18 @@ static void matrix_keypad_scan(struct work_struct *work)
keypad->scan_pending = false;
enable_row_irqs(keypad);
}
+
+ /* read new row state and detect if value has changed */
+ new_row_state = read_row_state(keypad);
+ if (init_row_state != new_row_state) {
+ guard(spinlock_irq)(&keypad->lock);
+ if (unlikely(keypad->scan_pending || keypad->stopped))
+ return;
+ disable_row_irqs(keypad);
+ keypad->scan_pending = true;
+ schedule_delayed_work(&keypad->work,
+ msecs_to_jiffies(keypad->debounce_ms));
+ }
}
static irqreturn_t matrix_keypad_interrupt(int irq, void *id)
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread