Input: matrix-keypad - switch to using generic device properties
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 11 Nov 2016 20:43:12 +0000 (12:43 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 31 Jan 2017 19:31:48 +0000 (11:31 -0800)
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>
12 files changed:
drivers/input/keyboard/bcm-keypad.c
drivers/input/keyboard/cros_ec_keyb.c
drivers/input/keyboard/lpc32xx-keys.c
drivers/input/keyboard/omap4-keypad.c
drivers/input/keyboard/pmic8xxx-keypad.c
drivers/input/keyboard/pxa27x_keypad.c
drivers/input/keyboard/st-keyscan.c
drivers/input/keyboard/stmpe-keypad.c
drivers/input/keyboard/tca8418_keypad.c
drivers/input/keyboard/twl4030_keypad.c
drivers/input/matrix-keymap.c
include/linux/input/matrix_keypad.h

index 2b4e63d81e6d9ffaaab54ce0c8c3a2a8b9087d8a..e1cf63ee148f5e67ddd45fde5c9fa41200faf6c6 100644 (file)
@@ -213,7 +213,7 @@ static int bcm_kp_matrix_key_parse_dt(struct bcm_kp *kp)
        /* Initialize the KPCR Keypad Configuration Register */
        kp->kpcr = KPCR_STATUSFILTERENABLE | KPCR_COLFILTERENABLE;
 
-       error = matrix_keypad_parse_of_params(dev, &kp->n_rows, &kp->n_cols);
+       error = matrix_keypad_parse_properties(dev, &kp->n_rows, &kp->n_cols);
        if (error) {
                dev_err(dev, "failed to parse kp params\n");
                return error;
index 87d071ae21da0e04e86dda1f5baae97fccd19d22..780977dcf92d244850960c594a5d41b7eef93bf6 100644 (file)
@@ -229,7 +229,8 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
        ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL);
        if (!ckdev)
                return -ENOMEM;
-       err = matrix_keypad_parse_of_params(dev, &ckdev->rows, &ckdev->cols);
+
+       err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols);
        if (err)
                return err;
 
index 632523d4f5dc11b21e1591ccd79f841dbb640194..1dd57ac0e7a27158cf996b5e4b0a9e4027ae4a1e 100644 (file)
@@ -145,7 +145,7 @@ static int lpc32xx_parse_dt(struct device *dev,
        u32 rows = 0, columns = 0;
        int err;
 
-       err = matrix_keypad_parse_of_params(dev, &rows, &columns);
+       err = matrix_keypad_parse_properties(dev, &rows, &columns);
        if (err)
                return err;
        if (rows != columns) {
index 9ecb16701b133e3188fda0a1bbbfaa98e409b3d0..ebc67ba41fe24a0bbadb952916c07b8df917cc66 100644 (file)
@@ -223,8 +223,8 @@ static int omap4_keypad_parse_dt(struct device *dev,
        struct device_node *np = dev->of_node;
        int err;
 
-       err = matrix_keypad_parse_of_params(dev, &keypad_data->rows,
-                                           &keypad_data->cols);
+       err = matrix_keypad_parse_properties(dev, &keypad_data->rows,
+                                            &keypad_data->cols);
        if (err)
                return err;
 
index 5c68e3f096bc83fce073f6ff7dfafe65fe7e8f56..97c5424f49b95df566a2fd84a5ad3ffdeb4cc75f 100644 (file)
@@ -515,7 +515,7 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev)
        int rc;
        unsigned int ctrl_val;
 
-       rc = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols);
+       rc = matrix_keypad_parse_properties(&pdev->dev, &rows, &cols);
        if (rc)
                return rc;
 
index e24443376e756fe6290cfba7e5dbb0aa5f336b9f..3841fa30db3343c2a7a4d464ea4d5ad77335830a 100644 (file)
@@ -126,7 +126,7 @@ static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad,
        u32 rows, cols;
        int error;
 
-       error = matrix_keypad_parse_of_params(dev, &rows, &cols);
+       error = matrix_keypad_parse_properties(dev, &rows, &cols);
        if (error)
                return error;
 
index de7be4f03d9193884d248d506b6f75a306dbc17a..babcfb165e4f0060c854ee524582b3ec436e8978 100644 (file)
@@ -106,8 +106,8 @@ static int keypad_matrix_key_parse_dt(struct st_keyscan *keypad_data)
        struct device_node *np = dev->of_node;
        int error;
 
-       error = matrix_keypad_parse_of_params(dev, &keypad_data->n_rows,
-                                             &keypad_data->n_cols);
+       error = matrix_keypad_parse_properties(dev, &keypad_data->n_rows,
+                                              &keypad_data->n_cols);
        if (error) {
                dev_err(dev, "failed to parse keypad params\n");
                return error;
index fe6e3f22eed76157c42a1d9b873b01e34f38b5f2..8c6c0b9109c75e22bfdc290d4ecfacb88d911ca9 100644 (file)
@@ -354,7 +354,7 @@ static int stmpe_keypad_probe(struct platform_device *pdev)
        input->id.bustype = BUS_I2C;
        input->dev.parent = &pdev->dev;
 
-       error = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols);
+       error = matrix_keypad_parse_properties(&pdev->dev, &rows, &cols);
        if (error)
                return error;
 
index 9f6308fac0b46b1b63148ae361ece213de405b2b..ccff9d1b7135a59d6347318345ff395bfa2e48fd 100644 (file)
@@ -295,7 +295,7 @@ static int tca8418_keypad_probe(struct i2c_client *client,
                struct device_node *np = dev->of_node;
                int err;
 
-               err = matrix_keypad_parse_of_params(dev, &rows, &cols);
+               err = matrix_keypad_parse_properties(dev, &rows, &cols);
                if (err)
                        return err;
                rep = of_property_read_bool(np, "keypad,autorepeat");
index 29396ca69416ea3c80e8697b8ae62dc634d0607f..39e72b3219d8a4ddb0ed358d561a2e2f0abf4285 100644 (file)
@@ -374,8 +374,8 @@ static int twl4030_kp_probe(struct platform_device *pdev)
                kp->autorepeat = pdata->rep;
                keymap_data = pdata->keymap_data;
        } else {
-               error = matrix_keypad_parse_of_params(&pdev->dev, &kp->n_rows,
-                                                     &kp->n_cols);
+               error = matrix_keypad_parse_properties(&pdev->dev, &kp->n_rows,
+                                                      &kp->n_cols);
                if (error)
                        return error;
 
index 08b61f506db616d6a463ae96347dad62bc26517f..8ccefc15c7a4dfcfb03295a681f52620ebf47d4c 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
  */
 
 #include <linux/device.h>
+#include <linux/export.h>
 #include <linux/gfp.h>
-#include <linux/kernel.h>
-#include <linux/types.h>
 #include <linux/input.h>
-#include <linux/of.h>
-#include <linux/export.h>
-#include <linux/module.h>
 #include <linux/input/matrix_keypad.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/property.h>
+#include <linux/slab.h>
+#include <linux/types.h>
 
 static bool matrix_keypad_map_key(struct input_dev *input_dev,
                                  unsigned int rows, unsigned int cols,
@@ -49,18 +49,22 @@ static bool matrix_keypad_map_key(struct input_dev *input_dev,
        return true;
 }
 
-#ifdef CONFIG_OF
-int matrix_keypad_parse_of_params(struct device *dev,
-                                 unsigned int *rows, unsigned int *cols)
+/**
+ * matrix_keypad_parse_properties() - Read properties of matrix keypad
+ *
+ * @dev: Device containing properties
+ * @rows: Returns number of matrix rows
+ * @cols: Returns number of matrix columns
+ * @return 0 if OK, <0 on error
+ */
+int matrix_keypad_parse_properties(struct device *dev,
+                                  unsigned int *rows, unsigned int *cols)
 {
-       struct device_node *np = dev->of_node;
+       *rows = *cols = 0;
+
+       device_property_read_u32(dev, "keypad,num-rows", rows);
+       device_property_read_u32(dev, "keypad,num-columns", cols);
 
-       if (!np) {
-               dev_err(dev, "missing DT data");
-               return -EINVAL;
-       }
-       of_property_read_u32(np, "keypad,num-rows", rows);
-       of_property_read_u32(np, "keypad,num-columns", cols);
        if (!*rows || !*cols) {
                dev_err(dev, "number of keypad rows/columns not specified\n");
                return -EINVAL;
@@ -68,62 +72,61 @@ int matrix_keypad_parse_of_params(struct device *dev,
 
        return 0;
 }
-EXPORT_SYMBOL_GPL(matrix_keypad_parse_of_params);
+EXPORT_SYMBOL_GPL(matrix_keypad_parse_properties);
 
-static int matrix_keypad_parse_of_keymap(const char *propname,
-                                        unsigned int rows, unsigned int cols,
-                                        struct input_dev *input_dev)
+static int matrix_keypad_parse_keymap(const char *propname,
+                                     unsigned int rows, unsigned int cols,
+                                     struct input_dev *input_dev)
 {
        struct device *dev = input_dev->dev.parent;
-       struct device_node *np = dev->of_node;
        unsigned int row_shift = get_count_order(cols);
        unsigned int max_keys = rows << row_shift;
-       unsigned int proplen, i, size;
-       const __be32 *prop;
-
-       if (!np)
-               return -ENOENT;
+       u32 *keys;
+       int i;
+       int size;
+       int retval;
 
        if (!propname)
                propname = "linux,keymap";
 
-       prop = of_get_property(np, propname, &proplen);
-       if (!prop) {
-               dev_err(dev, "OF: %s property not defined in %s\n",
-                       propname, np->full_name);
-               return -ENOENT;
+       size = device_property_read_u32_array(dev, propname, NULL, 0);
+       if (size <= 0) {
+               dev_err(dev, "missing or malformed property %s: %d\n",
+                       propname, size);
+               return size < 0 ? size : -EINVAL;
        }
 
-       if (proplen % sizeof(u32)) {
-               dev_err(dev, "OF: Malformed keycode property %s in %s\n",
-                       propname, np->full_name);
+       if (size > max_keys) {
+               dev_err(dev, "%s size overflow (%d vs max %u)\n",
+                       propname, size, max_keys);
                return -EINVAL;
        }
 
-       size = proplen / sizeof(u32);
-       if (size > max_keys) {
-               dev_err(dev, "OF: %s size overflow\n", propname);
-               return -EINVAL;
+       keys = kmalloc_array(size, sizeof(u32), GFP_KERNEL);
+       if (!keys)
+               return -ENOMEM;
+
+       retval = device_property_read_u32_array(dev, propname, keys, size);
+       if (retval) {
+               dev_err(dev, "failed to read %s property: %d\n",
+                       propname, retval);
+               goto out;
        }
 
        for (i = 0; i < size; i++) {
-               unsigned int key = be32_to_cpup(prop + i);
-
                if (!matrix_keypad_map_key(input_dev, rows, cols,
-                                          row_shift, key))
-                       return -EINVAL;
+                                          row_shift, keys[i])) {
+                       retval = -EINVAL;
+                       goto out;
+               }
        }
 
-       return 0;
-}
-#else
-static int matrix_keypad_parse_of_keymap(const char *propname,
-                                        unsigned int rows, unsigned int cols,
-                                        struct input_dev *input_dev)
-{
-       return -ENOSYS;
+       retval = 0;
+
+out:
+       kfree(keys);
+       return retval;
 }
-#endif
 
 /**
  * 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,
                                return -EINVAL;
                }
        } else {
-               error = matrix_keypad_parse_of_keymap(keymap_name, rows, cols,
-                                                     input_dev);
+               error = matrix_keypad_parse_keymap(keymap_name, rows, cols,
+                                                  input_dev);
                if (error)
                        return error;
        }
index 27e06acc509adf25e6ec4463e683efaae78befa5..37b04a0fdea4e004a63c053bfb3c90d5de3612f1 100644 (file)
@@ -80,24 +80,9 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
                               unsigned int rows, unsigned int cols,
                               unsigned short *keymap,
                               struct input_dev *input_dev);
+int matrix_keypad_parse_properties(struct device *dev,
+                                  unsigned int *rows, unsigned int *cols);
 
-#ifdef CONFIG_OF
-/**
- * matrix_keypad_parse_of_params() - Read parameters from matrix-keypad node
- *
- * @dev: Device containing of_node
- * @rows: Returns number of matrix rows
- * @cols: Returns number of matrix columns
- * @return 0 if OK, <0 on error
- */
-int matrix_keypad_parse_of_params(struct device *dev,
-                                 unsigned int *rows, unsigned int *cols);
-#else
-static inline int matrix_keypad_parse_of_params(struct device *dev,
-                                 unsigned int *rows, unsigned int *cols)
-{
-       return -ENOSYS;
-}
-#endif /* CONFIG_OF */
+#define matrix_keypad_parse_of_params matrix_keypad_parse_properties
 
 #endif /* _MATRIX_KEYPAD_H */