aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2014-07-23 15:23:23 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-07-23 17:41:06 -0400
commit78188be3e5dd59cc2f67bf4cf573e579da186d39 (patch)
tree4e4b4d26bf39d886310d38685022e50487fccc39 /drivers/input
parentb735fbe064a0a64d848e3002f41b7e5f657d5665 (diff)
Input: atmel_mxt_ts - implement device tree support
Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c68
1 files changed, 63 insertions, 5 deletions
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 31113c372f59..4317273c2138 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -22,6 +22,7 @@
22#include <linux/i2c/atmel_mxt_ts.h> 22#include <linux/i2c/atmel_mxt_ts.h>
23#include <linux/input/mt.h> 23#include <linux/input/mt.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/of.h>
25#include <linux/slab.h> 26#include <linux/slab.h>
26 27
27/* Version */ 28/* Version */
@@ -1527,15 +1528,65 @@ static void mxt_input_close(struct input_dev *dev)
1527 mxt_stop(data); 1528 mxt_stop(data);
1528} 1529}
1529 1530
1530static int mxt_probe(struct i2c_client *client, 1531#ifdef CONFIG_OF
1531 const struct i2c_device_id *id) 1532static struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
1533{
1534 struct mxt_platform_data *pdata;
1535 u32 *keymap;
1536 u32 keycode;
1537 int proplen, i, ret;
1538
1539 if (!client->dev.of_node)
1540 return ERR_PTR(-ENODEV);
1541
1542 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
1543 if (!pdata)
1544 return ERR_PTR(-ENOMEM);
1545
1546 if (of_find_property(client->dev.of_node, "linux,gpio-keymap",
1547 &proplen)) {
1548 pdata->t19_num_keys = proplen / sizeof(u32);
1549
1550 keymap = devm_kzalloc(&client->dev,
1551 pdata->t19_num_keys * sizeof(keymap[0]),
1552 GFP_KERNEL);
1553 if (!keymap)
1554 return ERR_PTR(-ENOMEM);
1555
1556 for (i = 0; i < pdata->t19_num_keys; i++) {
1557 ret = of_property_read_u32_index(client->dev.of_node,
1558 "linux,gpio-keymap", i, &keycode);
1559 if (ret)
1560 keycode = KEY_RESERVED;
1561
1562 keymap[i] = keycode;
1563 }
1564
1565 pdata->t19_keymap = keymap;
1566 }
1567
1568 return pdata;
1569}
1570#else
1571static struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
1572{
1573 dev_dbg(&client->dev, "No platform data specified\n");
1574 return ERR_PTR(-EINVAL);
1575}
1576#endif
1577
1578static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
1532{ 1579{
1533 struct mxt_data *data; 1580 struct mxt_data *data;
1534 const struct mxt_platform_data *pdata = dev_get_platdata(&client->dev); 1581 const struct mxt_platform_data *pdata;
1535 int error; 1582 int error;
1536 1583
1537 if (!pdata) 1584 pdata = dev_get_platdata(&client->dev);
1538 return -EINVAL; 1585 if (!pdata) {
1586 pdata = mxt_parse_dt(client);
1587 if (IS_ERR(pdata))
1588 return PTR_ERR(pdata);
1589 }
1539 1590
1540 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); 1591 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
1541 if (!data) { 1592 if (!data) {
@@ -1638,6 +1689,12 @@ static int mxt_resume(struct device *dev)
1638 1689
1639static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume); 1690static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
1640 1691
1692static const struct of_device_id mxt_of_match[] = {
1693 { .compatible = "atmel,maxtouch", },
1694 {},
1695};
1696MODULE_DEVICE_TABLE(of, mxt_of_match);
1697
1641static const struct i2c_device_id mxt_id[] = { 1698static const struct i2c_device_id mxt_id[] = {
1642 { "qt602240_ts", 0 }, 1699 { "qt602240_ts", 0 },
1643 { "atmel_mxt_ts", 0 }, 1700 { "atmel_mxt_ts", 0 },
@@ -1651,6 +1708,7 @@ static struct i2c_driver mxt_driver = {
1651 .driver = { 1708 .driver = {
1652 .name = "atmel_mxt_ts", 1709 .name = "atmel_mxt_ts",
1653 .owner = THIS_MODULE, 1710 .owner = THIS_MODULE,
1711 .of_match_table = of_match_ptr(mxt_of_match),
1654 .pm = &mxt_pm_ops, 1712 .pm = &mxt_pm_ops,
1655 }, 1713 },
1656 .probe = mxt_probe, 1714 .probe = mxt_probe,