diff options
| author | Tomasz Figa <t.figa@samsung.com> | 2012-10-11 04:03:50 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-10-11 04:29:36 -0400 |
| commit | ad5396ee32afbdabb6188ffba67778080ea795b8 (patch) | |
| tree | 3b804f68084673f4e85373a9724805e37379621e /drivers/input/touchscreen | |
| parent | dae6ba4ab797ed411fbde60ef5b5f6fbf13f0090 (diff) | |
Input: mms114 - add device tree bindings
Add device tree bindings for mms114 touchscreen.
[Dmitry Torokhov: added #ifdef CONFIG_OF guards]
Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen')
| -rw-r--r-- | drivers/input/touchscreen/mms114.c | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index 560cf09d1c5a..3426d2e11a36 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> | 11 | #include <linux/init.h> |
| 12 | #include <linux/delay.h> | 12 | #include <linux/delay.h> |
| 13 | #include <linux/of.h> | ||
| 13 | #include <linux/i2c.h> | 14 | #include <linux/i2c.h> |
| 14 | #include <linux/i2c/mms114.h> | 15 | #include <linux/i2c/mms114.h> |
| 15 | #include <linux/input/mt.h> | 16 | #include <linux/input/mt.h> |
| @@ -360,14 +361,63 @@ static void mms114_input_close(struct input_dev *dev) | |||
| 360 | mms114_stop(data); | 361 | mms114_stop(data); |
| 361 | } | 362 | } |
| 362 | 363 | ||
| 364 | #ifdef CONFIG_OF | ||
| 365 | static struct mms114_platform_data * __devinit mms114_parse_dt(struct device *dev) | ||
| 366 | { | ||
| 367 | struct mms114_platform_data *pdata; | ||
| 368 | struct device_node *np = dev->of_node; | ||
| 369 | |||
| 370 | if (!np) | ||
| 371 | return NULL; | ||
| 372 | |||
| 373 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
| 374 | if (!pdata) { | ||
| 375 | dev_err(dev, "failed to allocate platform data\n"); | ||
| 376 | return NULL; | ||
| 377 | } | ||
| 378 | |||
| 379 | if (of_property_read_u32(np, "x-size", &pdata->x_size)) { | ||
| 380 | dev_err(dev, "failed to get x-size property\n"); | ||
| 381 | return NULL; | ||
| 382 | }; | ||
| 383 | |||
| 384 | if (of_property_read_u32(np, "y-size", &pdata->y_size)) { | ||
| 385 | dev_err(dev, "failed to get y-size property\n"); | ||
| 386 | return NULL; | ||
| 387 | }; | ||
| 388 | |||
| 389 | of_property_read_u32(np, "contact-threshold", | ||
| 390 | &pdata->contact_threshold); | ||
| 391 | of_property_read_u32(np, "moving-threshold", | ||
| 392 | &pdata->moving_threshold); | ||
| 393 | |||
| 394 | if (of_find_property(np, "x-invert", NULL)) | ||
| 395 | pdata->x_invert = true; | ||
| 396 | if (of_find_property(np, "y-invert", NULL)) | ||
| 397 | pdata->y_invert = true; | ||
| 398 | |||
| 399 | return pdata; | ||
| 400 | } | ||
| 401 | #else | ||
| 402 | static inline struct mms114_platform_data *mms114_parse_dt(struct device *dev) | ||
| 403 | { | ||
| 404 | return NULL; | ||
| 405 | } | ||
| 406 | #endif | ||
| 407 | |||
| 363 | static int __devinit mms114_probe(struct i2c_client *client, | 408 | static int __devinit mms114_probe(struct i2c_client *client, |
| 364 | const struct i2c_device_id *id) | 409 | const struct i2c_device_id *id) |
| 365 | { | 410 | { |
| 411 | const struct mms114_platform_data *pdata; | ||
| 366 | struct mms114_data *data; | 412 | struct mms114_data *data; |
| 367 | struct input_dev *input_dev; | 413 | struct input_dev *input_dev; |
| 368 | int error; | 414 | int error; |
| 369 | 415 | ||
| 370 | if (!client->dev.platform_data) { | 416 | pdata = dev_get_platdata(&client->dev); |
| 417 | if (!pdata) | ||
| 418 | pdata = mms114_parse_dt(&client->dev); | ||
| 419 | |||
| 420 | if (!pdata) { | ||
| 371 | dev_err(&client->dev, "Need platform data\n"); | 421 | dev_err(&client->dev, "Need platform data\n"); |
| 372 | return -EINVAL; | 422 | return -EINVAL; |
| 373 | } | 423 | } |
| @@ -389,7 +439,7 @@ static int __devinit mms114_probe(struct i2c_client *client, | |||
| 389 | 439 | ||
| 390 | data->client = client; | 440 | data->client = client; |
| 391 | data->input_dev = input_dev; | 441 | data->input_dev = input_dev; |
| 392 | data->pdata = client->dev.platform_data; | 442 | data->pdata = pdata; |
| 393 | 443 | ||
| 394 | input_dev->name = "MELPAS MMS114 Touchscreen"; | 444 | input_dev->name = "MELPAS MMS114 Touchscreen"; |
| 395 | input_dev->id.bustype = BUS_I2C; | 445 | input_dev->id.bustype = BUS_I2C; |
| @@ -525,11 +575,19 @@ static const struct i2c_device_id mms114_id[] = { | |||
| 525 | }; | 575 | }; |
| 526 | MODULE_DEVICE_TABLE(i2c, mms114_id); | 576 | MODULE_DEVICE_TABLE(i2c, mms114_id); |
| 527 | 577 | ||
| 578 | #ifdef CONFIG_OF | ||
| 579 | static struct of_device_id __devinitdata mms114_dt_match[] = { | ||
| 580 | { .compatible = "melfas,mms114" }, | ||
| 581 | { } | ||
| 582 | }; | ||
| 583 | #endif | ||
| 584 | |||
| 528 | static struct i2c_driver mms114_driver = { | 585 | static struct i2c_driver mms114_driver = { |
| 529 | .driver = { | 586 | .driver = { |
| 530 | .name = "mms114", | 587 | .name = "mms114", |
| 531 | .owner = THIS_MODULE, | 588 | .owner = THIS_MODULE, |
| 532 | .pm = &mms114_pm_ops, | 589 | .pm = &mms114_pm_ops, |
| 590 | .of_match_table = of_match_ptr(mms114_dt_match), | ||
| 533 | }, | 591 | }, |
| 534 | .probe = mms114_probe, | 592 | .probe = mms114_probe, |
| 535 | .remove = __devexit_p(mms114_remove), | 593 | .remove = __devexit_p(mms114_remove), |
