aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/zforce_ts.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/touchscreen/zforce_ts.c')
-rw-r--r--drivers/input/touchscreen/zforce_ts.c95
1 files changed, 77 insertions, 18 deletions
diff --git a/drivers/input/touchscreen/zforce_ts.c b/drivers/input/touchscreen/zforce_ts.c
index 2175f3419002..01d30cedde46 100644
--- a/drivers/input/touchscreen/zforce_ts.c
+++ b/drivers/input/touchscreen/zforce_ts.c
@@ -29,10 +29,13 @@
29#include <linux/sysfs.h> 29#include <linux/sysfs.h>
30#include <linux/input/mt.h> 30#include <linux/input/mt.h>
31#include <linux/platform_data/zforce_ts.h> 31#include <linux/platform_data/zforce_ts.h>
32#include <linux/of.h>
33#include <linux/of_gpio.h>
32 34
33#define WAIT_TIMEOUT msecs_to_jiffies(1000) 35#define WAIT_TIMEOUT msecs_to_jiffies(1000)
34 36
35#define FRAME_START 0xee 37#define FRAME_START 0xee
38#define FRAME_MAXSIZE 257
36 39
37/* Offsets of the different parts of the payload the controller sends */ 40/* Offsets of the different parts of the payload the controller sends */
38#define PAYLOAD_HEADER 0 41#define PAYLOAD_HEADER 0
@@ -64,7 +67,7 @@
64#define RESPONSE_STATUS 0X1e 67#define RESPONSE_STATUS 0X1e
65 68
66/* 69/*
67 * Notifications are send by the touch controller without 70 * Notifications are sent by the touch controller without
68 * being requested by the driver and include for example 71 * being requested by the driver and include for example
69 * touch indications 72 * touch indications
70 */ 73 */
@@ -103,8 +106,8 @@ struct zforce_point {
103 * @suspended device suspended 106 * @suspended device suspended
104 * @access_mutex serialize i2c-access, to keep multipart reads together 107 * @access_mutex serialize i2c-access, to keep multipart reads together
105 * @command_done completion to wait for the command result 108 * @command_done completion to wait for the command result
106 * @command_mutex serialize commands send to the ic 109 * @command_mutex serialize commands sent to the ic
107 * @command_waiting the id of the command that that is currently waiting 110 * @command_waiting the id of the command that is currently waiting
108 * for a result 111 * for a result
109 * @command_result returned result of the command 112 * @command_result returned result of the command
110 */ 113 */
@@ -235,7 +238,8 @@ static int zforce_scan_frequency(struct zforce_ts *ts, u16 idle, u16 finger,
235 (finger & 0xff), ((finger >> 8) & 0xff), 238 (finger & 0xff), ((finger >> 8) & 0xff),
236 (stylus & 0xff), ((stylus >> 8) & 0xff) }; 239 (stylus & 0xff), ((stylus >> 8) & 0xff) };
237 240
238 dev_dbg(&client->dev, "set scan frequency to (idle: %d, finger: %d, stylus: %d)\n", 241 dev_dbg(&client->dev,
242 "set scan frequency to (idle: %d, finger: %d, stylus: %d)\n",
239 idle, finger, stylus); 243 idle, finger, stylus);
240 244
241 return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf)); 245 return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
@@ -255,7 +259,7 @@ static int zforce_setconfig(struct zforce_ts *ts, char b1)
255static int zforce_start(struct zforce_ts *ts) 259static int zforce_start(struct zforce_ts *ts)
256{ 260{
257 struct i2c_client *client = ts->client; 261 struct i2c_client *client = ts->client;
258 const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev); 262 const struct zforce_ts_platdata *pdata = ts->pdata;
259 int ret; 263 int ret;
260 264
261 dev_dbg(&client->dev, "starting device\n"); 265 dev_dbg(&client->dev, "starting device\n");
@@ -326,13 +330,14 @@ static int zforce_stop(struct zforce_ts *ts)
326static int zforce_touch_event(struct zforce_ts *ts, u8 *payload) 330static int zforce_touch_event(struct zforce_ts *ts, u8 *payload)
327{ 331{
328 struct i2c_client *client = ts->client; 332 struct i2c_client *client = ts->client;
329 const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev); 333 const struct zforce_ts_platdata *pdata = ts->pdata;
330 struct zforce_point point; 334 struct zforce_point point;
331 int count, i, num = 0; 335 int count, i, num = 0;
332 336
333 count = payload[0]; 337 count = payload[0];
334 if (count > ZFORCE_REPORT_POINTS) { 338 if (count > ZFORCE_REPORT_POINTS) {
335 dev_warn(&client->dev, "to many coordinates %d, expected max %d\n", 339 dev_warn(&client->dev,
340 "too many coordinates %d, expected max %d\n",
336 count, ZFORCE_REPORT_POINTS); 341 count, ZFORCE_REPORT_POINTS);
337 count = ZFORCE_REPORT_POINTS; 342 count = ZFORCE_REPORT_POINTS;
338 } 343 }
@@ -421,7 +426,7 @@ static int zforce_read_packet(struct zforce_ts *ts, u8 *buf)
421 goto unlock; 426 goto unlock;
422 } 427 }
423 428
424 if (buf[PAYLOAD_LENGTH] <= 0 || buf[PAYLOAD_LENGTH] > 255) { 429 if (buf[PAYLOAD_LENGTH] == 0) {
425 dev_err(&client->dev, "invalid payload length: %d\n", 430 dev_err(&client->dev, "invalid payload length: %d\n",
426 buf[PAYLOAD_LENGTH]); 431 buf[PAYLOAD_LENGTH]);
427 ret = -EIO; 432 ret = -EIO;
@@ -471,9 +476,9 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
471{ 476{
472 struct zforce_ts *ts = dev_id; 477 struct zforce_ts *ts = dev_id;
473 struct i2c_client *client = ts->client; 478 struct i2c_client *client = ts->client;
474 const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev); 479 const struct zforce_ts_platdata *pdata = ts->pdata;
475 int ret; 480 int ret;
476 u8 payload_buffer[512]; 481 u8 payload_buffer[FRAME_MAXSIZE];
477 u8 *payload; 482 u8 *payload;
478 483
479 /* 484 /*
@@ -494,8 +499,8 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
494 while (!gpio_get_value(pdata->gpio_int)) { 499 while (!gpio_get_value(pdata->gpio_int)) {
495 ret = zforce_read_packet(ts, payload_buffer); 500 ret = zforce_read_packet(ts, payload_buffer);
496 if (ret < 0) { 501 if (ret < 0) {
497 dev_err(&client->dev, "could not read packet, ret: %d\n", 502 dev_err(&client->dev,
498 ret); 503 "could not read packet, ret: %d\n", ret);
499 break; 504 break;
500 } 505 }
501 506
@@ -539,7 +544,8 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
539 payload[RESPONSE_DATA + 4]; 544 payload[RESPONSE_DATA + 4];
540 ts->version_rev = (payload[RESPONSE_DATA + 7] << 8) | 545 ts->version_rev = (payload[RESPONSE_DATA + 7] << 8) |
541 payload[RESPONSE_DATA + 6]; 546 payload[RESPONSE_DATA + 6];
542 dev_dbg(&ts->client->dev, "Firmware Version %04x:%04x %04x:%04x\n", 547 dev_dbg(&ts->client->dev,
548 "Firmware Version %04x:%04x %04x:%04x\n",
543 ts->version_major, ts->version_minor, 549 ts->version_major, ts->version_minor,
544 ts->version_build, ts->version_rev); 550 ts->version_build, ts->version_rev);
545 551
@@ -552,7 +558,8 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
552 break; 558 break;
553 559
554 default: 560 default:
555 dev_err(&ts->client->dev, "unrecognized response id: 0x%x\n", 561 dev_err(&ts->client->dev,
562 "unrecognized response id: 0x%x\n",
556 payload[RESPONSE_ID]); 563 payload[RESPONSE_ID]);
557 break; 564 break;
558 } 565 }
@@ -618,7 +625,8 @@ static int zforce_suspend(struct device *dev)
618 625
619 enable_irq_wake(client->irq); 626 enable_irq_wake(client->irq);
620 } else if (input->users) { 627 } else if (input->users) {
621 dev_dbg(&client->dev, "suspend without being a wakeup source\n"); 628 dev_dbg(&client->dev,
629 "suspend without being a wakeup source\n");
622 630
623 ret = zforce_stop(ts); 631 ret = zforce_stop(ts);
624 if (ret) 632 if (ret)
@@ -684,6 +692,45 @@ static void zforce_reset(void *data)
684 gpio_set_value(ts->pdata->gpio_rst, 0); 692 gpio_set_value(ts->pdata->gpio_rst, 0);
685} 693}
686 694
695static struct zforce_ts_platdata *zforce_parse_dt(struct device *dev)
696{
697 struct zforce_ts_platdata *pdata;
698 struct device_node *np = dev->of_node;
699
700 if (!np)
701 return ERR_PTR(-ENOENT);
702
703 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
704 if (!pdata) {
705 dev_err(dev, "failed to allocate platform data\n");
706 return ERR_PTR(-ENOMEM);
707 }
708
709 pdata->gpio_int = of_get_gpio(np, 0);
710 if (!gpio_is_valid(pdata->gpio_int)) {
711 dev_err(dev, "failed to get interrupt gpio\n");
712 return ERR_PTR(-EINVAL);
713 }
714
715 pdata->gpio_rst = of_get_gpio(np, 1);
716 if (!gpio_is_valid(pdata->gpio_rst)) {
717 dev_err(dev, "failed to get reset gpio\n");
718 return ERR_PTR(-EINVAL);
719 }
720
721 if (of_property_read_u32(np, "x-size", &pdata->x_max)) {
722 dev_err(dev, "failed to get x-size property\n");
723 return ERR_PTR(-EINVAL);
724 }
725
726 if (of_property_read_u32(np, "y-size", &pdata->y_max)) {
727 dev_err(dev, "failed to get y-size property\n");
728 return ERR_PTR(-EINVAL);
729 }
730
731 return pdata;
732}
733
687static int zforce_probe(struct i2c_client *client, 734static int zforce_probe(struct i2c_client *client,
688 const struct i2c_device_id *id) 735 const struct i2c_device_id *id)
689{ 736{
@@ -692,8 +739,11 @@ static int zforce_probe(struct i2c_client *client,
692 struct input_dev *input_dev; 739 struct input_dev *input_dev;
693 int ret; 740 int ret;
694 741
695 if (!pdata) 742 if (!pdata) {
696 return -EINVAL; 743 pdata = zforce_parse_dt(&client->dev);
744 if (IS_ERR(pdata))
745 return PTR_ERR(pdata);
746 }
697 747
698 ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL); 748 ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL);
699 if (!ts) 749 if (!ts)
@@ -798,7 +848,7 @@ static int zforce_probe(struct i2c_client *client,
798 return ret; 848 return ret;
799 } 849 }
800 850
801 /* this gets the firmware version among other informations */ 851 /* this gets the firmware version among other information */
802 ret = zforce_command_wait(ts, COMMAND_STATUS); 852 ret = zforce_command_wait(ts, COMMAND_STATUS);
803 if (ret < 0) { 853 if (ret < 0) {
804 dev_err(&client->dev, "couldn't get status, %d\n", ret); 854 dev_err(&client->dev, "couldn't get status, %d\n", ret);
@@ -829,11 +879,20 @@ static struct i2c_device_id zforce_idtable[] = {
829}; 879};
830MODULE_DEVICE_TABLE(i2c, zforce_idtable); 880MODULE_DEVICE_TABLE(i2c, zforce_idtable);
831 881
882#ifdef CONFIG_OF
883static struct of_device_id zforce_dt_idtable[] = {
884 { .compatible = "neonode,zforce" },
885 {},
886};
887MODULE_DEVICE_TABLE(of, zforce_dt_idtable);
888#endif
889
832static struct i2c_driver zforce_driver = { 890static struct i2c_driver zforce_driver = {
833 .driver = { 891 .driver = {
834 .owner = THIS_MODULE, 892 .owner = THIS_MODULE,
835 .name = "zforce-ts", 893 .name = "zforce-ts",
836 .pm = &zforce_pm_ops, 894 .pm = &zforce_pm_ops,
895 .of_match_table = of_match_ptr(zforce_dt_idtable),
837 }, 896 },
838 .probe = zforce_probe, 897 .probe = zforce_probe,
839 .id_table = zforce_idtable, 898 .id_table = zforce_idtable,