Commit aef01aad authored by Dmitry Torokhov's avatar Dmitry Torokhov

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: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent b1fe0cf0
......@@ -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;
......
......@@ -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;
......
......@@ -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) {
......
......@@ -223,7 +223,7 @@ 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,
err = matrix_keypad_parse_properties(dev, &keypad_data->rows,
&keypad_data->cols);
if (err)
return err;
......
......@@ -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;
......
......@@ -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;
......
......@@ -106,7 +106,7 @@ 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,
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");
......
......@@ -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;
......
......@@ -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");
......
......@@ -374,7 +374,7 @@ 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,
error = matrix_keypad_parse_properties(&pdev->dev, &kp->n_rows,
&kp->n_cols);
if (error)
return error;
......
......@@ -14,18 +14,18 @@
* 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,
/**
* 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,
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,7 +195,7 @@ 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,
error = matrix_keypad_parse_keymap(keymap_name, rows, cols,
input_dev);
if (error)
return error;
......
......@@ -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);
#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,
int matrix_keypad_parse_properties(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 */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment