Skip to content

Commit aa0e26b

Browse files
David Rivshindtor
authored andcommitted
Input: matrix_keypad - add option to drive inactive columns
The gpio-matrix-keypad driver normally sets inactive columns as inputs while scanning. This does not work for all hardware, which may require the inactive columns to be actively driven in order to overcome any pull-ups/downs on the columns. Signed-off-by: David Rivshin <drivshin@allworx.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 4896fb1 commit aa0e26b

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

Documentation/devicetree/bindings/input/gpio-matrix-keypad.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Optional Properties:
2424
- debounce-delay-ms: debounce interval in milliseconds
2525
- col-scan-delay-us: delay, measured in microseconds, that is needed
2626
before we can scan keypad after activating column gpio
27+
- drive-inactive-cols: drive inactive columns during scan,
28+
default is to turn inactive columns into inputs.
2729

2830
Example:
2931
matrix-keypad {

drivers/input/keyboard/matrix_keypad.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ struct matrix_keypad {
4242
};
4343

4444
/*
45-
* NOTE: normally the GPIO has to be put into HiZ when de-activated to cause
46-
* minmal side effect when scanning other columns, here it is configured to
47-
* be input, and it should work on most platforms.
45+
* NOTE: If drive_inactive_cols is false, then the GPIO has to be put into
46+
* HiZ when de-activated to cause minmal side effect when scanning other
47+
* columns. In that case it is configured here to be input, otherwise it is
48+
* driven with the inactive value.
4849
*/
4950
static void __activate_col(const struct matrix_keypad_platform_data *pdata,
5051
int col, bool on)
@@ -55,7 +56,8 @@ static void __activate_col(const struct matrix_keypad_platform_data *pdata,
5556
gpio_direction_output(pdata->col_gpios[col], level_on);
5657
} else {
5758
gpio_set_value_cansleep(pdata->col_gpios[col], !level_on);
58-
gpio_direction_input(pdata->col_gpios[col]);
59+
if (!pdata->drive_inactive_cols)
60+
gpio_direction_input(pdata->col_gpios[col]);
5961
}
6062
}
6163

@@ -432,6 +434,9 @@ matrix_keypad_parse_dt(struct device *dev)
432434
if (of_get_property(np, "gpio-activelow", NULL))
433435
pdata->active_low = true;
434436

437+
pdata->drive_inactive_cols =
438+
of_property_read_bool(np, "drive-inactive-cols");
439+
435440
of_property_read_u32(np, "debounce-delay-ms", &pdata->debounce_ms);
436441
of_property_read_u32(np, "col-scan-delay-us",
437442
&pdata->col_scan_delay_us);

include/linux/input/matrix_keypad.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct matrix_keymap_data {
4949
* @wakeup: controls whether the device should be set up as wakeup
5050
* source
5151
* @no_autorepeat: disable key autorepeat
52+
* @drive_inactive_cols: drive inactive columns during scan, rather than
53+
* making them inputs.
5254
*
5355
* This structure represents platform-specific data that use used by
5456
* matrix_keypad driver to perform proper initialization.
@@ -73,6 +75,7 @@ struct matrix_keypad_platform_data {
7375
bool active_low;
7476
bool wakeup;
7577
bool no_autorepeat;
78+
bool drive_inactive_cols;
7679
};
7780

7881
int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,

0 commit comments

Comments
 (0)