Skip to content

Commit 4384041

Browse files
sjg20Samuel Ortiz
authored andcommitted
input: matrix-keymap: Add function to read the new DT binding
We now have a binding which adds two parameters to the matrix keypad DT node. This is separate from the GPIO-driven matrix keypad binding, and unfortunately incompatible, since that uses row-gpios/col-gpios for the row and column counts. So the easiest option here is to provide a function for non-GPIO drivers to use to decode the binding. Note: We could in fact create an entirely separate structure to hold these two fields, but it does not seem worth it, yet. If we have more parameters then we can add this, and then refactor each driver to hold such a structure. Signed-off-by: Simon Glass <[email protected]> Acked-by: Dmitry Torokhov <[email protected]> Tested-by: Sourav Poddar <[email protected]> (v2) Signed-off-by: Samuel Ortiz <[email protected]>
1 parent a17d94f commit 4384041

File tree

5 files changed

+54
-18
lines changed

5 files changed

+54
-18
lines changed

drivers/input/keyboard/lpc32xx-keys.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,13 @@ static int lpc32xx_parse_dt(struct device *dev,
144144
{
145145
struct device_node *np = dev->of_node;
146146
u32 rows = 0, columns = 0;
147+
int err;
147148

148-
of_property_read_u32(np, "keypad,num-rows", &rows);
149-
of_property_read_u32(np, "keypad,num-columns", &columns);
150-
if (!rows || rows != columns) {
151-
dev_err(dev,
152-
"rows and columns must be specified and be equal!\n");
149+
err = matrix_keypad_parse_of_params(dev, &rows, &columns);
150+
if (err)
151+
return err;
152+
if (rows != columns) {
153+
dev_err(dev, "rows and columns must be equal!\n");
153154
return -EINVAL;
154155
}
155156

drivers/input/keyboard/omap4-keypad.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,12 @@ static int omap4_keypad_parse_dt(struct device *dev,
215215
struct omap4_keypad *keypad_data)
216216
{
217217
struct device_node *np = dev->of_node;
218+
int err;
218219

219-
if (!np) {
220-
dev_err(dev, "missing DT data");
221-
return -EINVAL;
222-
}
223-
224-
of_property_read_u32(np, "keypad,num-rows", &keypad_data->rows);
225-
of_property_read_u32(np, "keypad,num-columns", &keypad_data->cols);
226-
if (!keypad_data->rows || !keypad_data->cols) {
227-
dev_err(dev, "number of keypad rows/columns not specified\n");
228-
return -EINVAL;
229-
}
220+
err = matrix_keypad_parse_of_params(dev, &keypad_data->rows,
221+
&keypad_data->cols);
222+
if (err)
223+
return err;
230224

231225
if (of_get_property(np, "linux,input-no-autorepeat", NULL))
232226
keypad_data->no_autorepeat = true;

drivers/input/keyboard/tca8418_keypad.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ static int tca8418_keypad_probe(struct i2c_client *client,
288288
irq_is_gpio = pdata->irq_is_gpio;
289289
} else {
290290
struct device_node *np = dev->of_node;
291-
of_property_read_u32(np, "keypad,num-rows", &rows);
292-
of_property_read_u32(np, "keypad,num-columns", &cols);
291+
int err;
292+
293+
err = matrix_keypad_parse_of_params(dev, &rows, &cols);
294+
if (err)
295+
return err;
293296
rep = of_property_read_bool(np, "keypad,autorepeat");
294297
}
295298

drivers/input/matrix-keymap.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ static bool matrix_keypad_map_key(struct input_dev *input_dev,
5050
}
5151

5252
#ifdef CONFIG_OF
53+
int matrix_keypad_parse_of_params(struct device *dev,
54+
unsigned int *rows, unsigned int *cols)
55+
{
56+
struct device_node *np = dev->of_node;
57+
58+
if (!np) {
59+
dev_err(dev, "missing DT data");
60+
return -EINVAL;
61+
}
62+
of_property_read_u32(np, "keypad,num-rows", rows);
63+
of_property_read_u32(np, "keypad,num-columns", cols);
64+
if (!*rows || !*cols) {
65+
dev_err(dev, "number of keypad rows/columns not specified\n");
66+
return -EINVAL;
67+
}
68+
69+
return 0;
70+
}
71+
5372
static int matrix_keypad_parse_of_keymap(const char *propname,
5473
unsigned int rows, unsigned int cols,
5574
struct input_dev *input_dev)

include/linux/input/matrix_keypad.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,23 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
8181
unsigned short *keymap,
8282
struct input_dev *input_dev);
8383

84+
#ifdef CONFIG_OF
85+
/**
86+
* matrix_keypad_parse_of_params() - Read parameters from matrix-keypad node
87+
*
88+
* @dev: Device containing of_node
89+
* @rows: Returns number of matrix rows
90+
* @cols: Returns number of matrix columns
91+
* @return 0 if OK, <0 on error
92+
*/
93+
int matrix_keypad_parse_of_params(struct device *dev,
94+
unsigned int *rows, unsigned int *cols);
95+
#else
96+
static inline int matrix_keypad_parse_of_params(struct device *dev,
97+
unsigned int *rows, unsigned int *cols)
98+
{
99+
return -ENOSYS;
100+
}
101+
#endif /* CONFIG_OF */
102+
84103
#endif /* _MATRIX_KEYPAD_H */

0 commit comments

Comments
 (0)