diff options
| author | Roger Quadros <rogerq@ti.com> | 2014-07-28 13:05:39 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-07-28 13:26:18 -0400 |
| commit | a4054596e93048d50502f6c31c853bfeba5acb8e (patch) | |
| tree | da22e91a4188146d8d506143c8a46b5140445cbb /drivers/input/touchscreen | |
| parent | 36874c7e219fa080141d49fd7bb9bbbdad0507c5 (diff) | |
Input: pixcir_i2c_ts - add device tree support
Provide device tree support and binding information. Also provide support
for a new chip "pixcir_tangoc".
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen')
| -rw-r--r-- | drivers/input/touchscreen/pixcir_i2c_ts.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c index eddda520a1a7..fc49c75317d1 100644 --- a/drivers/input/touchscreen/pixcir_i2c_ts.c +++ b/drivers/input/touchscreen/pixcir_i2c_ts.c | |||
| @@ -26,6 +26,9 @@ | |||
| 26 | #include <linux/input/mt.h> | 26 | #include <linux/input/mt.h> |
| 27 | #include <linux/input/pixcir_ts.h> | 27 | #include <linux/input/pixcir_ts.h> |
| 28 | #include <linux/gpio.h> | 28 | #include <linux/gpio.h> |
| 29 | #include <linux/of.h> | ||
| 30 | #include <linux/of_gpio.h> | ||
| 31 | #include <linux/of_device.h> | ||
| 29 | 32 | ||
| 30 | #define PIXCIR_MAX_SLOTS 5 /* Max fingers supported by driver */ | 33 | #define PIXCIR_MAX_SLOTS 5 /* Max fingers supported by driver */ |
| 31 | 34 | ||
| @@ -407,16 +410,69 @@ unlock: | |||
| 407 | static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops, | 410 | static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops, |
| 408 | pixcir_i2c_ts_suspend, pixcir_i2c_ts_resume); | 411 | pixcir_i2c_ts_suspend, pixcir_i2c_ts_resume); |
| 409 | 412 | ||
| 413 | #ifdef CONFIG_OF | ||
| 414 | static const struct of_device_id pixcir_of_match[]; | ||
| 415 | |||
| 416 | static struct pixcir_ts_platform_data *pixcir_parse_dt(struct device *dev) | ||
| 417 | { | ||
| 418 | struct pixcir_ts_platform_data *pdata; | ||
| 419 | struct device_node *np = dev->of_node; | ||
| 420 | const struct of_device_id *match; | ||
| 421 | |||
| 422 | match = of_match_device(of_match_ptr(pixcir_of_match), dev); | ||
| 423 | if (!match) | ||
| 424 | return ERR_PTR(-EINVAL); | ||
| 425 | |||
| 426 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
| 427 | if (!pdata) | ||
| 428 | return ERR_PTR(-ENOMEM); | ||
| 429 | |||
| 430 | pdata->chip = *(const struct pixcir_i2c_chip_data *)match->data; | ||
| 431 | |||
| 432 | pdata->gpio_attb = of_get_named_gpio(np, "attb-gpio", 0); | ||
| 433 | /* gpio_attb validity is checked in probe */ | ||
| 434 | |||
| 435 | if (of_property_read_u32(np, "touchscreen-size-x", &pdata->x_max)) { | ||
| 436 | dev_err(dev, "Failed to get touchscreen-size-x property\n"); | ||
| 437 | return ERR_PTR(-EINVAL); | ||
| 438 | } | ||
| 439 | pdata->x_max -= 1; | ||
| 440 | |||
| 441 | if (of_property_read_u32(np, "touchscreen-size-y", &pdata->y_max)) { | ||
| 442 | dev_err(dev, "Failed to get touchscreen-size-y property\n"); | ||
| 443 | return ERR_PTR(-EINVAL); | ||
| 444 | } | ||
| 445 | pdata->y_max -= 1; | ||
| 446 | |||
| 447 | dev_dbg(dev, "%s: x %d, y %d, gpio %d\n", __func__, | ||
| 448 | pdata->x_max + 1, pdata->y_max + 1, pdata->gpio_attb); | ||
| 449 | |||
| 450 | return pdata; | ||
| 451 | } | ||
| 452 | #else | ||
| 453 | static struct pixcir_ts_platform_data *pixcir_parse_dt(struct device *dev) | ||
| 454 | { | ||
| 455 | return ERR_PTR(-EINVAL); | ||
| 456 | } | ||
| 457 | #endif | ||
| 458 | |||
| 410 | static int pixcir_i2c_ts_probe(struct i2c_client *client, | 459 | static int pixcir_i2c_ts_probe(struct i2c_client *client, |
| 411 | const struct i2c_device_id *id) | 460 | const struct i2c_device_id *id) |
| 412 | { | 461 | { |
| 413 | const struct pixcir_ts_platform_data *pdata = | 462 | const struct pixcir_ts_platform_data *pdata = |
| 414 | dev_get_platdata(&client->dev); | 463 | dev_get_platdata(&client->dev); |
| 415 | struct device *dev = &client->dev; | 464 | struct device *dev = &client->dev; |
| 465 | struct device_node *np = dev->of_node; | ||
| 416 | struct pixcir_i2c_ts_data *tsdata; | 466 | struct pixcir_i2c_ts_data *tsdata; |
| 417 | struct input_dev *input; | 467 | struct input_dev *input; |
| 418 | int error; | 468 | int error; |
| 419 | 469 | ||
| 470 | if (np && !pdata) { | ||
| 471 | pdata = pixcir_parse_dt(dev); | ||
| 472 | if (IS_ERR(pdata)) | ||
| 473 | return PTR_ERR(pdata); | ||
| 474 | } | ||
| 475 | |||
| 420 | if (!pdata) { | 476 | if (!pdata) { |
| 421 | dev_err(&client->dev, "platform data not defined\n"); | 477 | dev_err(&client->dev, "platform data not defined\n"); |
| 422 | return -EINVAL; | 478 | return -EINVAL; |
| @@ -522,15 +578,36 @@ static int pixcir_i2c_ts_remove(struct i2c_client *client) | |||
| 522 | 578 | ||
| 523 | static const struct i2c_device_id pixcir_i2c_ts_id[] = { | 579 | static const struct i2c_device_id pixcir_i2c_ts_id[] = { |
| 524 | { "pixcir_ts", 0 }, | 580 | { "pixcir_ts", 0 }, |
| 581 | { "pixcir_tangoc", 0 }, | ||
| 525 | { } | 582 | { } |
| 526 | }; | 583 | }; |
| 527 | MODULE_DEVICE_TABLE(i2c, pixcir_i2c_ts_id); | 584 | MODULE_DEVICE_TABLE(i2c, pixcir_i2c_ts_id); |
| 528 | 585 | ||
| 586 | #ifdef CONFIG_OF | ||
| 587 | static const struct pixcir_i2c_chip_data pixcir_ts_data = { | ||
| 588 | .max_fingers = 2, | ||
| 589 | /* no hw id support */ | ||
| 590 | }; | ||
| 591 | |||
| 592 | static const struct pixcir_i2c_chip_data pixcir_tangoc_data = { | ||
| 593 | .max_fingers = 5, | ||
| 594 | .has_hw_ids = true, | ||
| 595 | }; | ||
| 596 | |||
| 597 | static const struct of_device_id pixcir_of_match[] = { | ||
| 598 | { .compatible = "pixcir,pixcir_ts", .data = &pixcir_ts_data }, | ||
| 599 | { .compatible = "pixcir,pixcir_tangoc", .data = &pixcir_tangoc_data }, | ||
| 600 | { } | ||
| 601 | }; | ||
| 602 | MODULE_DEVICE_TABLE(of, pixcir_of_match); | ||
| 603 | #endif | ||
| 604 | |||
| 529 | static struct i2c_driver pixcir_i2c_ts_driver = { | 605 | static struct i2c_driver pixcir_i2c_ts_driver = { |
| 530 | .driver = { | 606 | .driver = { |
| 531 | .owner = THIS_MODULE, | 607 | .owner = THIS_MODULE, |
| 532 | .name = "pixcir_ts", | 608 | .name = "pixcir_ts", |
| 533 | .pm = &pixcir_dev_pm_ops, | 609 | .pm = &pixcir_dev_pm_ops, |
| 610 | .of_match_table = of_match_ptr(pixcir_of_match), | ||
| 534 | }, | 611 | }, |
| 535 | .probe = pixcir_i2c_ts_probe, | 612 | .probe = pixcir_i2c_ts_probe, |
| 536 | .remove = pixcir_i2c_ts_remove, | 613 | .remove = pixcir_i2c_ts_remove, |
