Skip to content

Commit

Permalink
Input: samsung-keypad - favor platform data if present
Browse files Browse the repository at this point in the history
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: Joonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
  • Loading branch information
Dmitry Torokhov committed Dec 7, 2013
1 parent c838cb3 commit 670d207
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions drivers/input/keyboard/samsung-keypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,34 +244,39 @@ static void samsung_keypad_close(struct input_dev *input_dev)
}

#ifdef CONFIG_OF
static struct samsung_keypad_platdata *samsung_keypad_parse_dt(
struct device *dev)
static struct samsung_keypad_platdata *
samsung_keypad_parse_dt(struct device *dev)
{
struct samsung_keypad_platdata *pdata;
struct matrix_keymap_data *keymap_data;
uint32_t *keymap, num_rows = 0, num_cols = 0;
struct device_node *np = dev->of_node, *key_np;
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);
if (!pdata) {
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-columns", &num_cols);
if (!num_rows || !num_cols) {
dev_err(dev, "number of keypad rows/columns not specified\n");
return NULL;
return ERR_PTR(-EINVAL);
}
pdata->rows = num_rows;
pdata->cols = num_cols;

keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
if (!keymap_data) {
dev_err(dev, "could not allocate memory for keymap data\n");
return NULL;
return ERR_PTR(-ENOMEM);
}
pdata->keymap_data = keymap_data;

Expand All @@ -280,7 +285,7 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt(
keymap = devm_kzalloc(dev, sizeof(uint32_t) * key_count, GFP_KERNEL);
if (!keymap) {
dev_err(dev, "could not allocate memory for keymap\n");
return NULL;
return ERR_PTR(-ENOMEM);
}
keymap_data->keymap = keymap;

Expand All @@ -294,16 +299,19 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt(

if (of_get_property(np, "linux,input-no-autorepeat", NULL))
pdata->no_autorepeat = true;

if (of_get_property(np, "linux,input-wakeup", NULL))
pdata->wakeup = true;

return pdata;
}
#else
static
struct samsung_keypad_platdata *samsung_keypad_parse_dt(struct device *dev)
static struct samsung_keypad_platdata *
samsung_keypad_parse_dt(struct device *dev)
{
return NULL;
dev_err(dev, "no platform data defined\n");

return ERR_PTR(-EINVAL);
}
#endif

Expand All @@ -318,13 +326,11 @@ static int samsung_keypad_probe(struct platform_device *pdev)
unsigned int keymap_size;
int error;

if (pdev->dev.of_node)
pdata = samsung_keypad_parse_dt(&pdev->dev);
else
pdata = dev_get_platdata(&pdev->dev);
pdata = dev_get_platdata(&pdev->dev);
if (!pdata) {
dev_err(&pdev->dev, "no platform data defined\n");
return -EINVAL;
pdata = samsung_keypad_parse_dt(&pdev->dev);
if (IS_ERR(pdata))
return PTR_ERR(pdata);
}

keymap_data = pdata->keymap_data;
Expand Down

0 comments on commit 670d207

Please sign in to comment.