Commit 670d2072 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: samsung-keypad - favor platform data if present

We should be able to override firmware-provided parameters with in-kernel
data, if needed. To that effect favor platform data, if present, over
devicetree data.
Acked-by: default avatarJoonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent c838cb3d
...@@ -244,8 +244,8 @@ static void samsung_keypad_close(struct input_dev *input_dev) ...@@ -244,8 +244,8 @@ static void samsung_keypad_close(struct input_dev *input_dev)
} }
#ifdef CONFIG_OF #ifdef CONFIG_OF
static struct samsung_keypad_platdata *samsung_keypad_parse_dt( static struct samsung_keypad_platdata *
struct device *dev) samsung_keypad_parse_dt(struct device *dev)
{ {
struct samsung_keypad_platdata *pdata; struct samsung_keypad_platdata *pdata;
struct matrix_keymap_data *keymap_data; struct matrix_keymap_data *keymap_data;
...@@ -253,17 +253,22 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt( ...@@ -253,17 +253,22 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt(
struct device_node *np = dev->of_node, *key_np; struct device_node *np = dev->of_node, *key_np;
unsigned int key_count; unsigned int key_count;
if (!np) {
dev_err(dev, "missing device tree data\n");
return ERR_PTR(-EINVAL);
}
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) { if (!pdata) {
dev_err(dev, "could not allocate memory for platform data\n"); dev_err(dev, "could not allocate memory for platform data\n");
return NULL; return ERR_PTR(-ENOMEM);
} }
of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows); of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows);
of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols); of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols);
if (!num_rows || !num_cols) { if (!num_rows || !num_cols) {
dev_err(dev, "number of keypad rows/columns not specified\n"); dev_err(dev, "number of keypad rows/columns not specified\n");
return NULL; return ERR_PTR(-EINVAL);
} }
pdata->rows = num_rows; pdata->rows = num_rows;
pdata->cols = num_cols; pdata->cols = num_cols;
...@@ -271,7 +276,7 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt( ...@@ -271,7 +276,7 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt(
keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL); keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
if (!keymap_data) { if (!keymap_data) {
dev_err(dev, "could not allocate memory for keymap data\n"); dev_err(dev, "could not allocate memory for keymap data\n");
return NULL; return ERR_PTR(-ENOMEM);
} }
pdata->keymap_data = keymap_data; pdata->keymap_data = keymap_data;
...@@ -280,7 +285,7 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt( ...@@ -280,7 +285,7 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt(
keymap = devm_kzalloc(dev, sizeof(uint32_t) * key_count, GFP_KERNEL); keymap = devm_kzalloc(dev, sizeof(uint32_t) * key_count, GFP_KERNEL);
if (!keymap) { if (!keymap) {
dev_err(dev, "could not allocate memory for keymap\n"); dev_err(dev, "could not allocate memory for keymap\n");
return NULL; return ERR_PTR(-ENOMEM);
} }
keymap_data->keymap = keymap; keymap_data->keymap = keymap;
...@@ -294,16 +299,19 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt( ...@@ -294,16 +299,19 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt(
if (of_get_property(np, "linux,input-no-autorepeat", NULL)) if (of_get_property(np, "linux,input-no-autorepeat", NULL))
pdata->no_autorepeat = true; pdata->no_autorepeat = true;
if (of_get_property(np, "linux,input-wakeup", NULL)) if (of_get_property(np, "linux,input-wakeup", NULL))
pdata->wakeup = true; pdata->wakeup = true;
return pdata; return pdata;
} }
#else #else
static static struct samsung_keypad_platdata *
struct samsung_keypad_platdata *samsung_keypad_parse_dt(struct device *dev) samsung_keypad_parse_dt(struct device *dev)
{ {
return NULL; dev_err(dev, "no platform data defined\n");
return ERR_PTR(-EINVAL);
} }
#endif #endif
...@@ -318,13 +326,11 @@ static int samsung_keypad_probe(struct platform_device *pdev) ...@@ -318,13 +326,11 @@ static int samsung_keypad_probe(struct platform_device *pdev)
unsigned int keymap_size; unsigned int keymap_size;
int error; int error;
if (pdev->dev.of_node) pdata = dev_get_platdata(&pdev->dev);
pdata = samsung_keypad_parse_dt(&pdev->dev);
else
pdata = dev_get_platdata(&pdev->dev);
if (!pdata) { if (!pdata) {
dev_err(&pdev->dev, "no platform data defined\n"); pdata = samsung_keypad_parse_dt(&pdev->dev);
return -EINVAL; if (IS_ERR(pdata))
return PTR_ERR(pdata);
} }
keymap_data = pdata->keymap_data; keymap_data = pdata->keymap_data;
......
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