aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2012-07-07 19:18:33 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2012-07-07 19:18:33 -0400
commitf053ea8d841a3a4620fff4a1b2ab1da9d7c53939 (patch)
treef8b6e0fc8c5c07d40db8d3aa3645092ab3d57ec6 /drivers/input
parent3c3416abbe3328c2fae054379894614b0c894069 (diff)
parentc45361a1287a74d327d72d4d2b96f4ac170653d9 (diff)
Pull input changes from Henrik Rydberg, including large update to
atmel_mxt_ts driver by Daniel and MT protocol addition for win8 devices. Conflicts: drivers/input/touchscreen/atmel_mxt_ts.c
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/input-mt.c2
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c463
2 files changed, 242 insertions, 223 deletions
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index f658086fbbe0..70a16c7da8cc 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -135,7 +135,7 @@ EXPORT_SYMBOL(input_mt_report_finger_count);
135 */ 135 */
136void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count) 136void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count)
137{ 137{
138 struct input_mt_slot *oldest = 0; 138 struct input_mt_slot *oldest = NULL;
139 int oldid = dev->trkid; 139 int oldid = dev->trkid;
140 int count = 0; 140 int count = 0;
141 int i; 141 int i;
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 25fd0561a17d..4623cc69fc60 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -36,6 +36,7 @@
36#define MXT_FW_NAME "maxtouch.fw" 36#define MXT_FW_NAME "maxtouch.fw"
37 37
38/* Registers */ 38/* Registers */
39#define MXT_INFO 0x00
39#define MXT_FAMILY_ID 0x00 40#define MXT_FAMILY_ID 0x00
40#define MXT_VARIANT_ID 0x01 41#define MXT_VARIANT_ID 0x01
41#define MXT_VERSION 0x02 42#define MXT_VERSION 0x02
@@ -194,6 +195,7 @@
194#define MXT_BOOT_STATUS_MASK 0x3f 195#define MXT_BOOT_STATUS_MASK 0x3f
195 196
196/* Touch status */ 197/* Touch status */
198#define MXT_UNGRIP (1 << 0)
197#define MXT_SUPPRESS (1 << 1) 199#define MXT_SUPPRESS (1 << 1)
198#define MXT_AMP (1 << 2) 200#define MXT_AMP (1 << 2)
199#define MXT_VECTOR (1 << 3) 201#define MXT_VECTOR (1 << 3)
@@ -210,8 +212,6 @@
210/* Touchscreen absolute values */ 212/* Touchscreen absolute values */
211#define MXT_MAX_AREA 0xff 213#define MXT_MAX_AREA 0xff
212 214
213#define MXT_MAX_FINGER 10
214
215struct mxt_info { 215struct mxt_info {
216 u8 family_id; 216 u8 family_id;
217 u8 variant_id; 217 u8 variant_id;
@@ -225,44 +225,37 @@ struct mxt_info {
225struct mxt_object { 225struct mxt_object {
226 u8 type; 226 u8 type;
227 u16 start_address; 227 u16 start_address;
228 u8 size; 228 u8 size; /* Size of each instance - 1 */
229 u8 instances; 229 u8 instances; /* Number of instances - 1 */
230 u8 num_report_ids; 230 u8 num_report_ids;
231 231} __packed;
232 /* to map object and message */
233 u8 max_reportid;
234};
235 232
236struct mxt_message { 233struct mxt_message {
237 u8 reportid; 234 u8 reportid;
238 u8 message[7]; 235 u8 message[7];
239}; 236};
240 237
241struct mxt_finger {
242 int status;
243 int x;
244 int y;
245 int area;
246 int pressure;
247};
248
249/* Each client has this additional data */ 238/* Each client has this additional data */
250struct mxt_data { 239struct mxt_data {
251 struct i2c_client *client; 240 struct i2c_client *client;
252 struct input_dev *input_dev; 241 struct input_dev *input_dev;
242 char phys[64]; /* device physical location */
253 const struct mxt_platform_data *pdata; 243 const struct mxt_platform_data *pdata;
254 struct mxt_object *object_table; 244 struct mxt_object *object_table;
255 struct mxt_info info; 245 struct mxt_info info;
256 struct mxt_finger finger[MXT_MAX_FINGER];
257 unsigned int irq; 246 unsigned int irq;
258 unsigned int max_x; 247 unsigned int max_x;
259 unsigned int max_y; 248 unsigned int max_y;
249
250 /* Cached parameters from object table */
251 u8 T6_reportid;
252 u8 T9_reportid_min;
253 u8 T9_reportid_max;
260}; 254};
261 255
262static bool mxt_object_readable(unsigned int type) 256static bool mxt_object_readable(unsigned int type)
263{ 257{
264 switch (type) { 258 switch (type) {
265 case MXT_GEN_MESSAGE_T5:
266 case MXT_GEN_COMMAND_T6: 259 case MXT_GEN_COMMAND_T6:
267 case MXT_GEN_POWER_T7: 260 case MXT_GEN_POWER_T7:
268 case MXT_GEN_ACQUIRE_T8: 261 case MXT_GEN_ACQUIRE_T8:
@@ -396,6 +389,7 @@ static int __mxt_read_reg(struct i2c_client *client,
396{ 389{
397 struct i2c_msg xfer[2]; 390 struct i2c_msg xfer[2];
398 u8 buf[2]; 391 u8 buf[2];
392 int ret;
399 393
400 buf[0] = reg & 0xff; 394 buf[0] = reg & 0xff;
401 buf[1] = (reg >> 8) & 0xff; 395 buf[1] = (reg >> 8) & 0xff;
@@ -412,12 +406,17 @@ static int __mxt_read_reg(struct i2c_client *client,
412 xfer[1].len = len; 406 xfer[1].len = len;
413 xfer[1].buf = val; 407 xfer[1].buf = val;
414 408
415 if (i2c_transfer(client->adapter, xfer, 2) != 2) { 409 ret = i2c_transfer(client->adapter, xfer, 2);
416 dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); 410 if (ret == 2) {
417 return -EIO; 411 ret = 0;
412 } else {
413 if (ret >= 0)
414 ret = -EIO;
415 dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
416 __func__, ret);
418 } 417 }
419 418
420 return 0; 419 return ret;
421} 420}
422 421
423static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val) 422static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
@@ -425,27 +424,39 @@ static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
425 return __mxt_read_reg(client, reg, 1, val); 424 return __mxt_read_reg(client, reg, 1, val);
426} 425}
427 426
428static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) 427static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
428 const void *val)
429{ 429{
430 u8 buf[3]; 430 u8 *buf;
431 size_t count;
432 int ret;
433
434 count = len + 2;
435 buf = kmalloc(count, GFP_KERNEL);
436 if (!buf)
437 return -ENOMEM;
431 438
432 buf[0] = reg & 0xff; 439 buf[0] = reg & 0xff;
433 buf[1] = (reg >> 8) & 0xff; 440 buf[1] = (reg >> 8) & 0xff;
434 buf[2] = val; 441 memcpy(&buf[2], val, len);
435 442
436 if (i2c_master_send(client, buf, 3) != 3) { 443 ret = i2c_master_send(client, buf, count);
437 dev_err(&client->dev, "%s: i2c send failed\n", __func__); 444 if (ret == count) {
438 return -EIO; 445 ret = 0;
446 } else {
447 if (ret >= 0)
448 ret = -EIO;
449 dev_err(&client->dev, "%s: i2c send failed (%d)\n",
450 __func__, ret);
439 } 451 }
440 452
441 return 0; 453 kfree(buf);
454 return ret;
442} 455}
443 456
444static int mxt_read_object_table(struct i2c_client *client, 457static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
445 u16 reg, u8 *object_buf)
446{ 458{
447 return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, 459 return __mxt_write_reg(client, reg, 1, &val);
448 object_buf);
449} 460}
450 461
451static struct mxt_object * 462static struct mxt_object *
@@ -479,20 +490,6 @@ static int mxt_read_message(struct mxt_data *data,
479 sizeof(struct mxt_message), message); 490 sizeof(struct mxt_message), message);
480} 491}
481 492
482static int mxt_read_object(struct mxt_data *data,
483 u8 type, u8 offset, u8 *val)
484{
485 struct mxt_object *object;
486 u16 reg;
487
488 object = mxt_get_object(data, type);
489 if (!object)
490 return -EINVAL;
491
492 reg = object->start_address;
493 return __mxt_read_reg(data->client, reg + offset, 1, val);
494}
495
496static int mxt_write_object(struct mxt_data *data, 493static int mxt_write_object(struct mxt_data *data,
497 u8 type, u8 offset, u8 val) 494 u8 type, u8 offset, u8 val)
498{ 495{
@@ -507,75 +504,17 @@ static int mxt_write_object(struct mxt_data *data,
507 return mxt_write_reg(data->client, reg + offset, val); 504 return mxt_write_reg(data->client, reg + offset, val);
508} 505}
509 506
510static void mxt_input_report(struct mxt_data *data, int single_id)
511{
512 struct mxt_finger *finger = data->finger;
513 struct input_dev *input_dev = data->input_dev;
514 int status = finger[single_id].status;
515 int finger_num = 0;
516 int id;
517
518 for (id = 0; id < MXT_MAX_FINGER; id++) {
519 if (!finger[id].status)
520 continue;
521
522 input_mt_slot(input_dev, id);
523 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
524 finger[id].status != MXT_RELEASE);
525
526 if (finger[id].status != MXT_RELEASE) {
527 finger_num++;
528 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
529 finger[id].area);
530 input_report_abs(input_dev, ABS_MT_POSITION_X,
531 finger[id].x);
532 input_report_abs(input_dev, ABS_MT_POSITION_Y,
533 finger[id].y);
534 input_report_abs(input_dev, ABS_MT_PRESSURE,
535 finger[id].pressure);
536 } else {
537 finger[id].status = 0;
538 }
539 }
540
541 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
542
543 if (status != MXT_RELEASE) {
544 input_report_abs(input_dev, ABS_X, finger[single_id].x);
545 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
546 input_report_abs(input_dev,
547 ABS_PRESSURE, finger[single_id].pressure);
548 }
549
550 input_sync(input_dev);
551}
552
553static void mxt_input_touchevent(struct mxt_data *data, 507static void mxt_input_touchevent(struct mxt_data *data,
554 struct mxt_message *message, int id) 508 struct mxt_message *message, int id)
555{ 509{
556 struct mxt_finger *finger = data->finger;
557 struct device *dev = &data->client->dev; 510 struct device *dev = &data->client->dev;
558 u8 status = message->message[0]; 511 u8 status = message->message[0];
512 struct input_dev *input_dev = data->input_dev;
559 int x; 513 int x;
560 int y; 514 int y;
561 int area; 515 int area;
562 int pressure; 516 int pressure;
563 517
564 /* Check the touch is present on the screen */
565 if (!(status & MXT_DETECT)) {
566 if (status & MXT_RELEASE) {
567 dev_dbg(dev, "[%d] released\n", id);
568
569 finger[id].status = MXT_RELEASE;
570 mxt_input_report(data, id);
571 }
572 return;
573 }
574
575 /* Check only AMP detection */
576 if (!(status & (MXT_PRESS | MXT_MOVE)))
577 return;
578
579 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); 518 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
580 y = (message->message[2] << 4) | ((message->message[3] & 0xf)); 519 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
581 if (data->max_x < 1024) 520 if (data->max_x < 1024)
@@ -586,30 +525,50 @@ static void mxt_input_touchevent(struct mxt_data *data,
586 area = message->message[4]; 525 area = message->message[4];
587 pressure = message->message[5]; 526 pressure = message->message[5];
588 527
589 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id, 528 dev_dbg(dev,
590 status & MXT_MOVE ? "moved" : "pressed", 529 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
591 x, y, area); 530 id,
531 (status & MXT_DETECT) ? 'D' : '.',
532 (status & MXT_PRESS) ? 'P' : '.',
533 (status & MXT_RELEASE) ? 'R' : '.',
534 (status & MXT_MOVE) ? 'M' : '.',
535 (status & MXT_VECTOR) ? 'V' : '.',
536 (status & MXT_AMP) ? 'A' : '.',
537 (status & MXT_SUPPRESS) ? 'S' : '.',
538 (status & MXT_UNGRIP) ? 'U' : '.',
539 x, y, area, pressure);
540
541 input_mt_slot(input_dev, id);
542 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
543 status & MXT_DETECT);
544
545 if (status & MXT_DETECT) {
546 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
547 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
548 input_report_abs(input_dev, ABS_MT_PRESSURE, pressure);
549 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
550 }
551}
592 552
593 finger[id].status = status & MXT_MOVE ? 553static unsigned mxt_extract_T6_csum(const u8 *csum)
594 MXT_MOVE : MXT_PRESS; 554{
595 finger[id].x = x; 555 return csum[0] | (csum[1] << 8) | (csum[2] << 16);
596 finger[id].y = y; 556}
597 finger[id].area = area;
598 finger[id].pressure = pressure;
599 557
600 mxt_input_report(data, id); 558static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg)
559{
560 u8 id = msg->reportid;
561 return (id >= data->T9_reportid_min && id <= data->T9_reportid_max);
601} 562}
602 563
603static irqreturn_t mxt_interrupt(int irq, void *dev_id) 564static irqreturn_t mxt_interrupt(int irq, void *dev_id)
604{ 565{
605 struct mxt_data *data = dev_id; 566 struct mxt_data *data = dev_id;
606 struct mxt_message message; 567 struct mxt_message message;
607 struct mxt_object *object; 568 const u8 *payload = &message.message[0];
608 struct device *dev = &data->client->dev; 569 struct device *dev = &data->client->dev;
609 int id;
610 u8 reportid; 570 u8 reportid;
611 u8 max_reportid; 571 bool update_input = false;
612 u8 min_reportid;
613 572
614 do { 573 do {
615 if (mxt_read_message(data, &message)) { 574 if (mxt_read_message(data, &message)) {
@@ -619,21 +578,25 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
619 578
620 reportid = message.reportid; 579 reportid = message.reportid;
621 580
622 /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */ 581 if (reportid == data->T6_reportid) {
623 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); 582 u8 status = payload[0];
624 if (!object) 583 unsigned csum = mxt_extract_T6_csum(&payload[1]);
625 goto end; 584 dev_dbg(dev, "Status: %02x Config Checksum: %06x\n",
626 585 status, csum);
627 max_reportid = object->max_reportid; 586 } else if (mxt_is_T9_message(data, &message)) {
628 min_reportid = max_reportid - object->num_report_ids + 1; 587 int id = reportid - data->T9_reportid_min;
629 id = reportid - min_reportid;
630
631 if (reportid >= min_reportid && reportid <= max_reportid)
632 mxt_input_touchevent(data, &message, id); 588 mxt_input_touchevent(data, &message, id);
633 else 589 update_input = true;
590 } else {
634 mxt_dump_message(dev, &message); 591 mxt_dump_message(dev, &message);
592 }
635 } while (reportid != 0xff); 593 } while (reportid != 0xff);
636 594
595 if (update_input) {
596 input_mt_report_pointer_emulation(data->input_dev, false);
597 input_sync(data->input_dev);
598 }
599
637end: 600end:
638 return IRQ_HANDLED; 601 return IRQ_HANDLED;
639} 602}
@@ -644,7 +607,8 @@ static int mxt_check_reg_init(struct mxt_data *data)
644 struct mxt_object *object; 607 struct mxt_object *object;
645 struct device *dev = &data->client->dev; 608 struct device *dev = &data->client->dev;
646 int index = 0; 609 int index = 0;
647 int i, j, config_offset; 610 int i, size;
611 int ret;
648 612
649 if (!pdata->config) { 613 if (!pdata->config) {
650 dev_dbg(dev, "No cfg data defined, skipping reg init\n"); 614 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
@@ -657,18 +621,17 @@ static int mxt_check_reg_init(struct mxt_data *data)
657 if (!mxt_object_writable(object->type)) 621 if (!mxt_object_writable(object->type))
658 continue; 622 continue;
659 623
660 for (j = 0; 624 size = (object->size + 1) * (object->instances + 1);
661 j < (object->size + 1) * (object->instances + 1); 625 if (index + size > pdata->config_length) {
662 j++) { 626 dev_err(dev, "Not enough config data!\n");
663 config_offset = index + j; 627 return -EINVAL;
664 if (config_offset > pdata->config_length) {
665 dev_err(dev, "Not enough config data!\n");
666 return -EINVAL;
667 }
668 mxt_write_object(data, object->type, j,
669 pdata->config[config_offset]);
670 } 628 }
671 index += (object->size + 1) * (object->instances + 1); 629
630 ret = __mxt_write_reg(data->client, object->start_address,
631 size, &pdata->config[index]);
632 if (ret)
633 return ret;
634 index += size;
672 } 635 }
673 636
674 return 0; 637 return 0;
@@ -749,68 +712,76 @@ static int mxt_get_info(struct mxt_data *data)
749 struct i2c_client *client = data->client; 712 struct i2c_client *client = data->client;
750 struct mxt_info *info = &data->info; 713 struct mxt_info *info = &data->info;
751 int error; 714 int error;
752 u8 val;
753 715
754 error = mxt_read_reg(client, MXT_FAMILY_ID, &val); 716 /* Read 7-byte info block starting at address 0 */
717 error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info);
755 if (error) 718 if (error)
756 return error; 719 return error;
757 info->family_id = val;
758
759 error = mxt_read_reg(client, MXT_VARIANT_ID, &val);
760 if (error)
761 return error;
762 info->variant_id = val;
763
764 error = mxt_read_reg(client, MXT_VERSION, &val);
765 if (error)
766 return error;
767 info->version = val;
768
769 error = mxt_read_reg(client, MXT_BUILD, &val);
770 if (error)
771 return error;
772 info->build = val;
773
774 error = mxt_read_reg(client, MXT_OBJECT_NUM, &val);
775 if (error)
776 return error;
777 info->object_num = val;
778 720
779 return 0; 721 return 0;
780} 722}
781 723
782static int mxt_get_object_table(struct mxt_data *data) 724static int mxt_get_object_table(struct mxt_data *data)
783{ 725{
726 struct i2c_client *client = data->client;
727 size_t table_size;
784 int error; 728 int error;
785 int i; 729 int i;
786 u16 reg; 730 u8 reportid;
787 u8 reportid = 0; 731
788 u8 buf[MXT_OBJECT_SIZE]; 732 table_size = data->info.object_num * sizeof(struct mxt_object);
733 error = __mxt_read_reg(client, MXT_OBJECT_START, table_size,
734 data->object_table);
735 if (error)
736 return error;
789 737
738 /* Valid Report IDs start counting from 1 */
739 reportid = 1;
790 for (i = 0; i < data->info.object_num; i++) { 740 for (i = 0; i < data->info.object_num; i++) {
791 struct mxt_object *object = data->object_table + i; 741 struct mxt_object *object = data->object_table + i;
742 u8 min_id, max_id;
792 743
793 reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; 744 le16_to_cpus(&object->start_address);
794 error = mxt_read_object_table(data->client, reg, buf);
795 if (error)
796 return error;
797
798 object->type = buf[0];
799 object->start_address = (buf[2] << 8) | buf[1];
800 object->size = buf[3];
801 object->instances = buf[4];
802 object->num_report_ids = buf[5];
803 745
804 if (object->num_report_ids) { 746 if (object->num_report_ids) {
747 min_id = reportid;
805 reportid += object->num_report_ids * 748 reportid += object->num_report_ids *
806 (object->instances + 1); 749 (object->instances + 1);
807 object->max_reportid = reportid; 750 max_id = reportid - 1;
751 } else {
752 min_id = 0;
753 max_id = 0;
754 }
755
756 dev_dbg(&data->client->dev,
757 "Type %2d Start %3d Size %3d Instances %2d ReportIDs %3u : %3u\n",
758 object->type, object->start_address, object->size + 1,
759 object->instances + 1, min_id, max_id);
760
761 switch (object->type) {
762 case MXT_GEN_COMMAND_T6:
763 data->T6_reportid = min_id;
764 break;
765 case MXT_TOUCH_MULTI_T9:
766 data->T9_reportid_min = min_id;
767 data->T9_reportid_max = max_id;
768 break;
808 } 769 }
809 } 770 }
810 771
811 return 0; 772 return 0;
812} 773}
813 774
775static void mxt_free_object_table(struct mxt_data *data)
776{
777 kfree(data->object_table);
778 data->object_table = NULL;
779 data->T6_reportid = 0;
780 data->T9_reportid_min = 0;
781 data->T9_reportid_max = 0;
782
783}
784
814static int mxt_initialize(struct mxt_data *data) 785static int mxt_initialize(struct mxt_data *data)
815{ 786{
816 struct i2c_client *client = data->client; 787 struct i2c_client *client = data->client;
@@ -833,12 +804,12 @@ static int mxt_initialize(struct mxt_data *data)
833 /* Get object table information */ 804 /* Get object table information */
834 error = mxt_get_object_table(data); 805 error = mxt_get_object_table(data);
835 if (error) 806 if (error)
836 return error; 807 goto err_free_object_table;
837 808
838 /* Check register init values */ 809 /* Check register init values */
839 error = mxt_check_reg_init(data); 810 error = mxt_check_reg_init(data);
840 if (error) 811 if (error)
841 return error; 812 goto err_free_object_table;
842 813
843 mxt_handle_pdata(data); 814 mxt_handle_pdata(data);
844 815
@@ -856,25 +827,29 @@ static int mxt_initialize(struct mxt_data *data)
856 /* Update matrix size at info struct */ 827 /* Update matrix size at info struct */
857 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); 828 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
858 if (error) 829 if (error)
859 return error; 830 goto err_free_object_table;
860 info->matrix_xsize = val; 831 info->matrix_xsize = val;
861 832
862 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); 833 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
863 if (error) 834 if (error)
864 return error; 835 goto err_free_object_table;
865 info->matrix_ysize = val; 836 info->matrix_ysize = val;
866 837
867 dev_info(&client->dev, 838 dev_info(&client->dev,
868 "Family ID: %d Variant ID: %d Version: %d Build: %d\n", 839 "Family ID: %u Variant ID: %u Major.Minor.Build: %u.%u.%02X\n",
869 info->family_id, info->variant_id, info->version, 840 info->family_id, info->variant_id, info->version >> 4,
870 info->build); 841 info->version & 0xf, info->build);
871 842
872 dev_info(&client->dev, 843 dev_info(&client->dev,
873 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", 844 "Matrix X Size: %u Matrix Y Size: %u Object Num: %u\n",
874 info->matrix_xsize, info->matrix_ysize, 845 info->matrix_xsize, info->matrix_ysize,
875 info->object_num); 846 info->object_num);
876 847
877 return 0; 848 return 0;
849
850err_free_object_table:
851 mxt_free_object_table(data);
852 return error;
878} 853}
879 854
880static void mxt_calc_resolution(struct mxt_data *data) 855static void mxt_calc_resolution(struct mxt_data *data)
@@ -891,6 +866,44 @@ static void mxt_calc_resolution(struct mxt_data *data)
891 } 866 }
892} 867}
893 868
869/* Firmware Version is returned as Major.Minor.Build */
870static ssize_t mxt_fw_version_show(struct device *dev,
871 struct device_attribute *attr, char *buf)
872{
873 struct mxt_data *data = dev_get_drvdata(dev);
874 struct mxt_info *info = &data->info;
875 return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n",
876 info->version >> 4, info->version & 0xf, info->build);
877}
878
879/* Hardware Version is returned as FamilyID.VariantID */
880static ssize_t mxt_hw_version_show(struct device *dev,
881 struct device_attribute *attr, char *buf)
882{
883 struct mxt_data *data = dev_get_drvdata(dev);
884 struct mxt_info *info = &data->info;
885 return scnprintf(buf, PAGE_SIZE, "%u.%u\n",
886 info->family_id, info->variant_id);
887}
888
889static ssize_t mxt_show_instance(char *buf, int count,
890 struct mxt_object *object, int instance,
891 const u8 *val)
892{
893 int i;
894
895 if (object->instances > 0)
896 count += scnprintf(buf + count, PAGE_SIZE - count,
897 "Instance %u\n", instance);
898
899 for (i = 0; i < object->size + 1; i++)
900 count += scnprintf(buf + count, PAGE_SIZE - count,
901 "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
902 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
903
904 return count;
905}
906
894static ssize_t mxt_object_show(struct device *dev, 907static ssize_t mxt_object_show(struct device *dev,
895 struct device_attribute *attr, char *buf) 908 struct device_attribute *attr, char *buf)
896{ 909{
@@ -899,43 +912,38 @@ static ssize_t mxt_object_show(struct device *dev,
899 int count = 0; 912 int count = 0;
900 int i, j; 913 int i, j;
901 int error; 914 int error;
902 u8 val; 915 u8 *obuf;
903 916
917 /* Pre-allocate buffer large enough to hold max sized object. */
918 obuf = kmalloc(256, GFP_KERNEL);
919 if (!obuf)
920 return -ENOMEM;
921
922 error = 0;
904 for (i = 0; i < data->info.object_num; i++) { 923 for (i = 0; i < data->info.object_num; i++) {
905 object = data->object_table + i; 924 object = data->object_table + i;
906 925
907 count += snprintf(buf + count, PAGE_SIZE - count, 926 if (!mxt_object_readable(object->type))
908 "Object[%d] (Type %d)\n",
909 i + 1, object->type);
910 if (count >= PAGE_SIZE)
911 return PAGE_SIZE - 1;
912
913 if (!mxt_object_readable(object->type)) {
914 count += snprintf(buf + count, PAGE_SIZE - count,
915 "\n");
916 if (count >= PAGE_SIZE)
917 return PAGE_SIZE - 1;
918 continue; 927 continue;
919 }
920 928
921 for (j = 0; j < object->size + 1; j++) { 929 count += scnprintf(buf + count, PAGE_SIZE - count,
922 error = mxt_read_object(data, 930 "T%u:\n", object->type);
923 object->type, j, &val); 931
932 for (j = 0; j < object->instances + 1; j++) {
933 u16 size = object->size + 1;
934 u16 addr = object->start_address + j * size;
935
936 error = __mxt_read_reg(data->client, addr, size, obuf);
924 if (error) 937 if (error)
925 return error; 938 goto done;
926 939
927 count += snprintf(buf + count, PAGE_SIZE - count, 940 count = mxt_show_instance(buf, count, object, j, obuf);
928 "\t[%2d]: %02x (%d)\n", j, val, val);
929 if (count >= PAGE_SIZE)
930 return PAGE_SIZE - 1;
931 } 941 }
932
933 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
934 if (count >= PAGE_SIZE)
935 return PAGE_SIZE - 1;
936 } 942 }
937 943
938 return count; 944done:
945 kfree(obuf);
946 return error ?: count;
939} 947}
940 948
941static int mxt_load_fw(struct device *dev, const char *fn) 949static int mxt_load_fw(struct device *dev, const char *fn)
@@ -1028,8 +1036,7 @@ static ssize_t mxt_update_fw_store(struct device *dev,
1028 /* Wait for reset */ 1036 /* Wait for reset */
1029 msleep(MXT_FWRESET_TIME); 1037 msleep(MXT_FWRESET_TIME);
1030 1038
1031 kfree(data->object_table); 1039 mxt_free_object_table(data);
1032 data->object_table = NULL;
1033 1040
1034 mxt_initialize(data); 1041 mxt_initialize(data);
1035 } 1042 }
@@ -1043,10 +1050,14 @@ static ssize_t mxt_update_fw_store(struct device *dev,
1043 return count; 1050 return count;
1044} 1051}
1045 1052
1053static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
1054static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
1046static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); 1055static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
1047static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); 1056static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
1048 1057
1049static struct attribute *mxt_attrs[] = { 1058static struct attribute *mxt_attrs[] = {
1059 &dev_attr_fw_version.attr,
1060 &dev_attr_hw_version.attr,
1050 &dev_attr_object.attr, 1061 &dev_attr_object.attr,
1051 &dev_attr_update_fw.attr, 1062 &dev_attr_update_fw.attr,
1052 NULL 1063 NULL
@@ -1093,6 +1104,7 @@ static int __devinit mxt_probe(struct i2c_client *client,
1093 struct mxt_data *data; 1104 struct mxt_data *data;
1094 struct input_dev *input_dev; 1105 struct input_dev *input_dev;
1095 int error; 1106 int error;
1107 unsigned int num_mt_slots;
1096 1108
1097 if (!pdata) 1109 if (!pdata)
1098 return -EINVAL; 1110 return -EINVAL;
@@ -1106,6 +1118,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
1106 } 1118 }
1107 1119
1108 input_dev->name = "Atmel maXTouch Touchscreen"; 1120 input_dev->name = "Atmel maXTouch Touchscreen";
1121 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1122 client->adapter->nr, client->addr);
1123 input_dev->phys = data->phys;
1124
1109 input_dev->id.bustype = BUS_I2C; 1125 input_dev->id.bustype = BUS_I2C;
1110 input_dev->dev.parent = &client->dev; 1126 input_dev->dev.parent = &client->dev;
1111 input_dev->open = mxt_input_open; 1127 input_dev->open = mxt_input_open;
@@ -1118,6 +1134,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
1118 1134
1119 mxt_calc_resolution(data); 1135 mxt_calc_resolution(data);
1120 1136
1137 error = mxt_initialize(data);
1138 if (error)
1139 goto err_free_mem;
1140
1121 __set_bit(EV_ABS, input_dev->evbit); 1141 __set_bit(EV_ABS, input_dev->evbit);
1122 __set_bit(EV_KEY, input_dev->evbit); 1142 __set_bit(EV_KEY, input_dev->evbit);
1123 __set_bit(BTN_TOUCH, input_dev->keybit); 1143 __set_bit(BTN_TOUCH, input_dev->keybit);
@@ -1131,7 +1151,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
1131 0, 255, 0, 0); 1151 0, 255, 0, 0);
1132 1152
1133 /* For multi touch */ 1153 /* For multi touch */
1134 input_mt_init_slots(input_dev, MXT_MAX_FINGER); 1154 num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
1155 error = input_mt_init_slots(input_dev, num_mt_slots);
1156 if (error)
1157 goto err_free_object;
1135 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 1158 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1136 0, MXT_MAX_AREA, 0, 0); 1159 0, MXT_MAX_AREA, 0, 0);
1137 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 1160 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
@@ -1144,13 +1167,9 @@ static int __devinit mxt_probe(struct i2c_client *client,
1144 input_set_drvdata(input_dev, data); 1167 input_set_drvdata(input_dev, data);
1145 i2c_set_clientdata(client, data); 1168 i2c_set_clientdata(client, data);
1146 1169
1147 error = mxt_initialize(data);
1148 if (error)
1149 goto err_free_object;
1150
1151 error = request_threaded_irq(client->irq, NULL, mxt_interrupt, 1170 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
1152 pdata->irqflags | IRQF_ONESHOT, 1171 pdata->irqflags | IRQF_ONESHOT,
1153 client->dev.driver->name, data); 1172 client->name, data);
1154 if (error) { 1173 if (error) {
1155 dev_err(&client->dev, "Failed to register interrupt\n"); 1174 dev_err(&client->dev, "Failed to register interrupt\n");
1156 goto err_free_object; 1175 goto err_free_object;