aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2016-11-11 15:43:12 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2017-01-31 14:31:48 -0500
commitaef01aad89e457e34a60ff6e8fd69ff6740cf201 (patch)
treea1a02536fd46b11f05e8e804f018b8384068e45a
parentb1fe0cf06f92ff8ebe77959810ec3ff2555ff56c (diff)
Input: matrix-keypad - switch to using generic device properties
Instead of being OF-specific, let's switch to using generic device properties, which will make this code usable on ACPI, device tree and legacy boards that use property sets. As part of the change let's rename matrix_keypad_parse_of_params() to matrix_keypad_parse_properties(). Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--drivers/input/keyboard/bcm-keypad.c2
-rw-r--r--drivers/input/keyboard/cros_ec_keyb.c3
-rw-r--r--drivers/input/keyboard/lpc32xx-keys.c2
-rw-r--r--drivers/input/keyboard/omap4-keypad.c4
-rw-r--r--drivers/input/keyboard/pmic8xxx-keypad.c2
-rw-r--r--drivers/input/keyboard/pxa27x_keypad.c2
-rw-r--r--drivers/input/keyboard/st-keyscan.c4
-rw-r--r--drivers/input/keyboard/stmpe-keypad.c2
-rw-r--r--drivers/input/keyboard/tca8418_keypad.c2
-rw-r--r--drivers/input/keyboard/twl4030_keypad.c4
-rw-r--r--drivers/input/matrix-keymap.c109
-rw-r--r--include/linux/input/matrix_keypad.h21
12 files changed, 73 insertions, 84 deletions
diff --git a/drivers/input/keyboard/bcm-keypad.c b/drivers/input/keyboard/bcm-keypad.c
index 2b4e63d81e6d..e1cf63ee148f 100644
--- a/drivers/input/keyboard/bcm-keypad.c
+++ b/drivers/input/keyboard/bcm-keypad.c
@@ -213,7 +213,7 @@ static int bcm_kp_matrix_key_parse_dt(struct bcm_kp *kp)
213 /* Initialize the KPCR Keypad Configuration Register */ 213 /* Initialize the KPCR Keypad Configuration Register */
214 kp->kpcr = KPCR_STATUSFILTERENABLE | KPCR_COLFILTERENABLE; 214 kp->kpcr = KPCR_STATUSFILTERENABLE | KPCR_COLFILTERENABLE;
215 215
216 error = matrix_keypad_parse_of_params(dev, &kp->n_rows, &kp->n_cols); 216 error = matrix_keypad_parse_properties(dev, &kp->n_rows, &kp->n_cols);
217 if (error) { 217 if (error) {
218 dev_err(dev, "failed to parse kp params\n"); 218 dev_err(dev, "failed to parse kp params\n");
219 return error; 219 return error;
diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
index 87d071ae21da..780977dcf92d 100644
--- a/drivers/input/keyboard/cros_ec_keyb.c
+++ b/drivers/input/keyboard/cros_ec_keyb.c
@@ -229,7 +229,8 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
229 ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL); 229 ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL);
230 if (!ckdev) 230 if (!ckdev)
231 return -ENOMEM; 231 return -ENOMEM;
232 err = matrix_keypad_parse_of_params(dev, &ckdev->rows, &ckdev->cols); 232
233 err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols);
233 if (err) 234 if (err)
234 return err; 235 return err;
235 236
diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c
index 632523d4f5dc..1dd57ac0e7a2 100644
--- a/drivers/input/keyboard/lpc32xx-keys.c
+++ b/drivers/input/keyboard/lpc32xx-keys.c
@@ -145,7 +145,7 @@ static int lpc32xx_parse_dt(struct device *dev,
145 u32 rows = 0, columns = 0; 145 u32 rows = 0, columns = 0;
146 int err; 146 int err;
147 147
148 err = matrix_keypad_parse_of_params(dev, &rows, &columns); 148 err = matrix_keypad_parse_properties(dev, &rows, &columns);
149 if (err) 149 if (err)
150 return err; 150 return err;
151 if (rows != columns) { 151 if (rows != columns) {
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index 9ecb16701b13..ebc67ba41fe2 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -223,8 +223,8 @@ static int omap4_keypad_parse_dt(struct device *dev,
223 struct device_node *np = dev->of_node; 223 struct device_node *np = dev->of_node;
224 int err; 224 int err;
225 225
226 err = matrix_keypad_parse_of_params(dev, &keypad_data->rows, 226 err = matrix_keypad_parse_properties(dev, &keypad_data->rows,
227 &keypad_data->cols); 227 &keypad_data->cols);
228 if (err) 228 if (err)
229 return err; 229 return err;
230 230
diff --git a/drivers/input/keyboard/pmic8xxx-keypad.c b/drivers/input/keyboard/pmic8xxx-keypad.c
index 5c68e3f096bc..97c5424f49b9 100644
--- a/drivers/input/keyboard/pmic8xxx-keypad.c
+++ b/drivers/input/keyboard/pmic8xxx-keypad.c
@@ -515,7 +515,7 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev)
515 int rc; 515 int rc;
516 unsigned int ctrl_val; 516 unsigned int ctrl_val;
517 517
518 rc = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols); 518 rc = matrix_keypad_parse_properties(&pdev->dev, &rows, &cols);
519 if (rc) 519 if (rc)
520 return rc; 520 return rc;
521 521
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index e24443376e75..3841fa30db33 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -126,7 +126,7 @@ static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad,
126 u32 rows, cols; 126 u32 rows, cols;
127 int error; 127 int error;
128 128
129 error = matrix_keypad_parse_of_params(dev, &rows, &cols); 129 error = matrix_keypad_parse_properties(dev, &rows, &cols);
130 if (error) 130 if (error)
131 return error; 131 return error;
132 132
diff --git a/drivers/input/keyboard/st-keyscan.c b/drivers/input/keyboard/st-keyscan.c
index de7be4f03d91..babcfb165e4f 100644
--- a/drivers/input/keyboard/st-keyscan.c
+++ b/drivers/input/keyboard/st-keyscan.c
@@ -106,8 +106,8 @@ static int keypad_matrix_key_parse_dt(struct st_keyscan *keypad_data)
106 struct device_node *np = dev->of_node; 106 struct device_node *np = dev->of_node;
107 int error; 107 int error;
108 108
109 error = matrix_keypad_parse_of_params(dev, &keypad_data->n_rows, 109 error = matrix_keypad_parse_properties(dev, &keypad_data->n_rows,
110 &keypad_data->n_cols); 110 &keypad_data->n_cols);
111 if (error) { 111 if (error) {
112 dev_err(dev, "failed to parse keypad params\n"); 112 dev_err(dev, "failed to parse keypad params\n");
113 return error; 113 return error;
diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c
index fe6e3f22eed7..8c6c0b9109c7 100644
--- a/drivers/input/keyboard/stmpe-keypad.c
+++ b/drivers/input/keyboard/stmpe-keypad.c
@@ -354,7 +354,7 @@ static int stmpe_keypad_probe(struct platform_device *pdev)
354 input->id.bustype = BUS_I2C; 354 input->id.bustype = BUS_I2C;
355 input->dev.parent = &pdev->dev; 355 input->dev.parent = &pdev->dev;
356 356
357 error = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols); 357 error = matrix_keypad_parse_properties(&pdev->dev, &rows, &cols);
358 if (error) 358 if (error)
359 return error; 359 return error;
360 360
diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c
index 9f6308fac0b4..ccff9d1b7135 100644
--- a/drivers/input/keyboard/tca8418_keypad.c
+++ b/drivers/input/keyboard/tca8418_keypad.c
@@ -295,7 +295,7 @@ static int tca8418_keypad_probe(struct i2c_client *client,
295 struct device_node *np = dev->of_node; 295 struct device_node *np = dev->of_node;
296 int err; 296 int err;
297 297
298 err = matrix_keypad_parse_of_params(dev, &rows, &cols); 298 err = matrix_keypad_parse_properties(dev, &rows, &cols);
299 if (err) 299 if (err)
300 return err; 300 return err;
301 rep = of_property_read_bool(np, "keypad,autorepeat"); 301 rep = of_property_read_bool(np, "keypad,autorepeat");
diff --git a/drivers/input/keyboard/twl4030_keypad.c b/drivers/input/keyboard/twl4030_keypad.c
index 29396ca69416..39e72b3219d8 100644
--- a/drivers/input/keyboard/twl4030_keypad.c
+++ b/drivers/input/keyboard/twl4030_keypad.c
@@ -374,8 +374,8 @@ static int twl4030_kp_probe(struct platform_device *pdev)
374 kp->autorepeat = pdata->rep; 374 kp->autorepeat = pdata->rep;
375 keymap_data = pdata->keymap_data; 375 keymap_data = pdata->keymap_data;
376 } else { 376 } else {
377 error = matrix_keypad_parse_of_params(&pdev->dev, &kp->n_rows, 377 error = matrix_keypad_parse_properties(&pdev->dev, &kp->n_rows,
378 &kp->n_cols); 378 &kp->n_cols);
379 if (error) 379 if (error)
380 return error; 380 return error;
381 381
diff --git a/drivers/input/matrix-keymap.c b/drivers/input/matrix-keymap.c
index 08b61f506db6..8ccefc15c7a4 100644
--- a/drivers/input/matrix-keymap.c
+++ b/drivers/input/matrix-keymap.c
@@ -14,18 +14,18 @@
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 *
18 */ 17 */
19 18
20#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/export.h>
21#include <linux/gfp.h> 21#include <linux/gfp.h>
22#include <linux/kernel.h>
23#include <linux/types.h>
24#include <linux/input.h> 22#include <linux/input.h>
25#include <linux/of.h>
26#include <linux/export.h>
27#include <linux/module.h>
28#include <linux/input/matrix_keypad.h> 23#include <linux/input/matrix_keypad.h>
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/property.h>
27#include <linux/slab.h>
28#include <linux/types.h>
29 29
30static bool matrix_keypad_map_key(struct input_dev *input_dev, 30static bool matrix_keypad_map_key(struct input_dev *input_dev,
31 unsigned int rows, unsigned int cols, 31 unsigned int rows, unsigned int cols,
@@ -49,18 +49,22 @@ static bool matrix_keypad_map_key(struct input_dev *input_dev,
49 return true; 49 return true;
50} 50}
51 51
52#ifdef CONFIG_OF 52/**
53int matrix_keypad_parse_of_params(struct device *dev, 53 * matrix_keypad_parse_properties() - Read properties of matrix keypad
54 unsigned int *rows, unsigned int *cols) 54 *
55 * @dev: Device containing properties
56 * @rows: Returns number of matrix rows
57 * @cols: Returns number of matrix columns
58 * @return 0 if OK, <0 on error
59 */
60int matrix_keypad_parse_properties(struct device *dev,
61 unsigned int *rows, unsigned int *cols)
55{ 62{
56 struct device_node *np = dev->of_node; 63 *rows = *cols = 0;
64
65 device_property_read_u32(dev, "keypad,num-rows", rows);
66 device_property_read_u32(dev, "keypad,num-columns", cols);
57 67
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) { 68 if (!*rows || !*cols) {
65 dev_err(dev, "number of keypad rows/columns not specified\n"); 69 dev_err(dev, "number of keypad rows/columns not specified\n");
66 return -EINVAL; 70 return -EINVAL;
@@ -68,62 +72,61 @@ int matrix_keypad_parse_of_params(struct device *dev,
68 72
69 return 0; 73 return 0;
70} 74}
71EXPORT_SYMBOL_GPL(matrix_keypad_parse_of_params); 75EXPORT_SYMBOL_GPL(matrix_keypad_parse_properties);
72 76
73static int matrix_keypad_parse_of_keymap(const char *propname, 77static int matrix_keypad_parse_keymap(const char *propname,
74 unsigned int rows, unsigned int cols, 78 unsigned int rows, unsigned int cols,
75 struct input_dev *input_dev) 79 struct input_dev *input_dev)
76{ 80{
77 struct device *dev = input_dev->dev.parent; 81 struct device *dev = input_dev->dev.parent;
78 struct device_node *np = dev->of_node;
79 unsigned int row_shift = get_count_order(cols); 82 unsigned int row_shift = get_count_order(cols);
80 unsigned int max_keys = rows << row_shift; 83 unsigned int max_keys = rows << row_shift;
81 unsigned int proplen, i, size; 84 u32 *keys;
82 const __be32 *prop; 85 int i;
83 86 int size;
84 if (!np) 87 int retval;
85 return -ENOENT;
86 88
87 if (!propname) 89 if (!propname)
88 propname = "linux,keymap"; 90 propname = "linux,keymap";
89 91
90 prop = of_get_property(np, propname, &proplen); 92 size = device_property_read_u32_array(dev, propname, NULL, 0);
91 if (!prop) { 93 if (size <= 0) {
92 dev_err(dev, "OF: %s property not defined in %s\n", 94 dev_err(dev, "missing or malformed property %s: %d\n",
93 propname, np->full_name); 95 propname, size);
94 return -ENOENT; 96 return size < 0 ? size : -EINVAL;
95 } 97 }
96 98
97 if (proplen % sizeof(u32)) { 99 if (size > max_keys) {
98 dev_err(dev, "OF: Malformed keycode property %s in %s\n", 100 dev_err(dev, "%s size overflow (%d vs max %u)\n",
99 propname, np->full_name); 101 propname, size, max_keys);
100 return -EINVAL; 102 return -EINVAL;
101 } 103 }
102 104
103 size = proplen / sizeof(u32); 105 keys = kmalloc_array(size, sizeof(u32), GFP_KERNEL);
104 if (size > max_keys) { 106 if (!keys)
105 dev_err(dev, "OF: %s size overflow\n", propname); 107 return -ENOMEM;
106 return -EINVAL; 108
109 retval = device_property_read_u32_array(dev, propname, keys, size);
110 if (retval) {
111 dev_err(dev, "failed to read %s property: %d\n",
112 propname, retval);
113 goto out;
107 } 114 }
108 115
109 for (i = 0; i < size; i++) { 116 for (i = 0; i < size; i++) {
110 unsigned int key = be32_to_cpup(prop + i);
111
112 if (!matrix_keypad_map_key(input_dev, rows, cols, 117 if (!matrix_keypad_map_key(input_dev, rows, cols,
113 row_shift, key)) 118 row_shift, keys[i])) {
114 return -EINVAL; 119 retval = -EINVAL;
120 goto out;
121 }
115 } 122 }
116 123
117 return 0; 124 retval = 0;
118} 125
119#else 126out:
120static int matrix_keypad_parse_of_keymap(const char *propname, 127 kfree(keys);
121 unsigned int rows, unsigned int cols, 128 return retval;
122 struct input_dev *input_dev)
123{
124 return -ENOSYS;
125} 129}
126#endif
127 130
128/** 131/**
129 * matrix_keypad_build_keymap - convert platform keymap into matrix keymap 132 * matrix_keypad_build_keymap - convert platform keymap into matrix keymap
@@ -192,8 +195,8 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
192 return -EINVAL; 195 return -EINVAL;
193 } 196 }
194 } else { 197 } else {
195 error = matrix_keypad_parse_of_keymap(keymap_name, rows, cols, 198 error = matrix_keypad_parse_keymap(keymap_name, rows, cols,
196 input_dev); 199 input_dev);
197 if (error) 200 if (error)
198 return error; 201 return error;
199 } 202 }
diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h
index 27e06acc509a..37b04a0fdea4 100644
--- a/include/linux/input/matrix_keypad.h
+++ b/include/linux/input/matrix_keypad.h
@@ -80,24 +80,9 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
80 unsigned int rows, unsigned int cols, 80 unsigned int rows, unsigned int cols,
81 unsigned short *keymap, 81 unsigned short *keymap,
82 struct input_dev *input_dev); 82 struct input_dev *input_dev);
83int matrix_keypad_parse_properties(struct device *dev,
84 unsigned int *rows, unsigned int *cols);
83 85
84#ifdef CONFIG_OF 86#define matrix_keypad_parse_of_params matrix_keypad_parse_properties
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 */
93int matrix_keypad_parse_of_params(struct device *dev,
94 unsigned int *rows, unsigned int *cols);
95#else
96static 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 87
103#endif /* _MATRIX_KEYPAD_H */ 88#endif /* _MATRIX_KEYPAD_H */