Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <sjg@chromium.org>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Tested-by: Sourav Poddar <sourav.poddar@ti.com> (v2)
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Simon Glass and committed by
Samuel Ortiz
43840415 a17d94f0

+54 -18
+6 -5
drivers/input/keyboard/lpc32xx-keys.c
··· 144 144 { 145 145 struct device_node *np = dev->of_node; 146 146 u32 rows = 0, columns = 0; 147 + int err; 147 148 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"); 153 154 return -EINVAL; 154 155 } 155 156
+5 -11
drivers/input/keyboard/omap4-keypad.c
··· 215 215 struct omap4_keypad *keypad_data) 216 216 { 217 217 struct device_node *np = dev->of_node; 218 + int err; 218 219 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; 230 224 231 225 if (of_get_property(np, "linux,input-no-autorepeat", NULL)) 232 226 keypad_data->no_autorepeat = true;
+5 -2
drivers/input/keyboard/tca8418_keypad.c
··· 288 288 irq_is_gpio = pdata->irq_is_gpio; 289 289 } else { 290 290 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; 293 296 rep = of_property_read_bool(np, "keypad,autorepeat"); 294 297 } 295 298
+19
drivers/input/matrix-keymap.c
··· 50 50 } 51 51 52 52 #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 + 53 72 static int matrix_keypad_parse_of_keymap(const char *propname, 54 73 unsigned int rows, unsigned int cols, 55 74 struct input_dev *input_dev)
+19
include/linux/input/matrix_keypad.h
··· 81 81 unsigned short *keymap, 82 82 struct input_dev *input_dev); 83 83 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 + 84 103 #endif /* _MATRIX_KEYPAD_H */