aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen
diff options
context:
space:
mode:
authorNick Dyer <nick.dyer@itdev.co.uk>2014-07-23 15:46:55 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-07-23 17:42:12 -0400
commit5f3f9bc2b1f3a09e732dfb5faad9cd3f42bd0328 (patch)
tree4fdbfc8738b12e0566996d7550b27907f3e5b30d /drivers/input/touchscreen
parent8efaa5e5a95170fa126798c7a48f0747fdb29862 (diff)
Input: atmel_mxt_ts - add support for dynamic message size
The T5 object may have various sizes depending on the objects used on the particular maXTouch chip and firmware version, therefore it can't be hardcoded in the driver. Allocate a buffer on probe instead. Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk> Acked-by: Benson Leung <bleung@chromium.org> Acked-by: Yufeng Shen <miletus@chromium.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c120
1 files changed, 68 insertions, 52 deletions
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 869065c2df83..215ffe1595e3 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -80,6 +80,9 @@
80#define MXT_SPT_MESSAGECOUNT_T44 44 80#define MXT_SPT_MESSAGECOUNT_T44 44
81#define MXT_SPT_CTECONFIG_T46 46 81#define MXT_SPT_CTECONFIG_T46 46
82 82
83/* MXT_GEN_MESSAGE_T5 object */
84#define MXT_RPTID_NOMSG 0xff
85
83/* MXT_GEN_COMMAND_T6 field */ 86/* MXT_GEN_COMMAND_T6 field */
84#define MXT_COMMAND_RESET 0 87#define MXT_COMMAND_RESET 0
85#define MXT_COMMAND_BACKUPNV 1 88#define MXT_COMMAND_BACKUPNV 1
@@ -223,11 +226,6 @@ struct mxt_object {
223 u8 num_report_ids; 226 u8 num_report_ids;
224} __packed; 227} __packed;
225 228
226struct mxt_message {
227 u8 reportid;
228 u8 message[7];
229};
230
231/* Each client has this additional data */ 229/* Each client has this additional data */
232struct mxt_data { 230struct mxt_data {
233 struct i2c_client *client; 231 struct i2c_client *client;
@@ -244,8 +242,10 @@ struct mxt_data {
244 u32 config_crc; 242 u32 config_crc;
245 u32 info_crc; 243 u32 info_crc;
246 u8 bootloader_addr; 244 u8 bootloader_addr;
245 u8 *msg_buf;
247 246
248 /* Cached parameters from object table */ 247 /* Cached parameters from object table */
248 u8 T5_msg_size;
249 u8 T6_reportid; 249 u8 T6_reportid;
250 u16 T6_address; 250 u16 T6_address;
251 u16 T7_address; 251 u16 T7_address;
@@ -306,11 +306,10 @@ static bool mxt_object_readable(unsigned int type)
306 } 306 }
307} 307}
308 308
309static void mxt_dump_message(struct device *dev, 309static void mxt_dump_message(struct mxt_data *data, u8 *message)
310 struct mxt_message *message)
311{ 310{
312 dev_dbg(dev, "reportid: %u\tmessage: %*ph\n", 311 dev_dbg(&data->client->dev, "message: %*ph\n",
313 message->reportid, 7, message->message); 312 data->T5_msg_size, message);
314} 313}
315 314
316static int mxt_wait_for_completion(struct mxt_data *data, 315static int mxt_wait_for_completion(struct mxt_data *data,
@@ -624,8 +623,7 @@ mxt_get_object(struct mxt_data *data, u8 type)
624 return NULL; 623 return NULL;
625} 624}
626 625
627static int mxt_read_message(struct mxt_data *data, 626static int mxt_read_message(struct mxt_data *data, u8 *message)
628 struct mxt_message *message)
629{ 627{
630 struct mxt_object *object; 628 struct mxt_object *object;
631 u16 reg; 629 u16 reg;
@@ -636,7 +634,7 @@ static int mxt_read_message(struct mxt_data *data,
636 634
637 reg = object->start_address; 635 reg = object->start_address;
638 return __mxt_read_reg(data->client, reg, 636 return __mxt_read_reg(data->client, reg,
639 sizeof(struct mxt_message), message); 637 data->T5_msg_size, message);
640} 638}
641 639
642static int mxt_write_object(struct mxt_data *data, 640static int mxt_write_object(struct mxt_data *data,
@@ -653,7 +651,7 @@ static int mxt_write_object(struct mxt_data *data,
653 return mxt_write_reg(data->client, reg + offset, val); 651 return mxt_write_reg(data->client, reg + offset, val);
654} 652}
655 653
656static void mxt_input_button(struct mxt_data *data, struct mxt_message *message) 654static void mxt_input_button(struct mxt_data *data, u8 *message)
657{ 655{
658 struct input_dev *input = data->input_dev; 656 struct input_dev *input = data->input_dev;
659 const struct mxt_platform_data *pdata = data->pdata; 657 const struct mxt_platform_data *pdata = data->pdata;
@@ -664,7 +662,7 @@ static void mxt_input_button(struct mxt_data *data, struct mxt_message *message)
664 for (i = 0; i < pdata->t19_num_keys; i++) { 662 for (i = 0; i < pdata->t19_num_keys; i++) {
665 if (pdata->t19_keymap[i] == KEY_RESERVED) 663 if (pdata->t19_keymap[i] == KEY_RESERVED)
666 continue; 664 continue;
667 button = !(message->message[0] & (1 << i)); 665 button = !(message[1] & (1 << i));
668 input_report_key(input, pdata->t19_keymap[i], button); 666 input_report_key(input, pdata->t19_keymap[i], button);
669 } 667 }
670} 668}
@@ -676,19 +674,21 @@ static void mxt_input_sync(struct mxt_data *data)
676 input_sync(data->input_dev); 674 input_sync(data->input_dev);
677} 675}
678 676
679static void mxt_input_touchevent(struct mxt_data *data, 677static void mxt_input_touchevent(struct mxt_data *data, u8 *message)
680 struct mxt_message *message, int id)
681{ 678{
682 struct device *dev = &data->client->dev; 679 struct device *dev = &data->client->dev;
683 u8 status = message->message[0];
684 struct input_dev *input_dev = data->input_dev; 680 struct input_dev *input_dev = data->input_dev;
681 int id;
682 u8 status;
685 int x; 683 int x;
686 int y; 684 int y;
687 int area; 685 int area;
688 int amplitude; 686 int amplitude;
689 687
690 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); 688 id = message[0] - data->T9_reportid_min;
691 y = (message->message[2] << 4) | ((message->message[3] & 0xf)); 689 status = message[1];
690 x = (message[2] << 4) | ((message[4] >> 4) & 0xf);
691 y = (message[3] << 4) | ((message[4] & 0xf));
692 692
693 /* Handle 10/12 bit switching */ 693 /* Handle 10/12 bit switching */
694 if (data->max_x < 1024) 694 if (data->max_x < 1024)
@@ -696,8 +696,8 @@ static void mxt_input_touchevent(struct mxt_data *data,
696 if (data->max_y < 1024) 696 if (data->max_y < 1024)
697 y >>= 2; 697 y >>= 2;
698 698
699 area = message->message[4]; 699 area = message[5];
700 amplitude = message->message[5]; 700 amplitude = message[6];
701 701
702 dev_dbg(dev, 702 dev_dbg(dev,
703 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n", 703 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
@@ -743,28 +743,28 @@ static u16 mxt_extract_T6_csum(const u8 *csum)
743 return csum[0] | (csum[1] << 8) | (csum[2] << 16); 743 return csum[0] | (csum[1] << 8) | (csum[2] << 16);
744} 744}
745 745
746static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg) 746static bool mxt_is_T9_message(struct mxt_data *data, u8 *msg)
747{ 747{
748 u8 id = msg->reportid; 748 u8 id = msg[0];
749 return (id >= data->T9_reportid_min && id <= data->T9_reportid_max); 749 return (id >= data->T9_reportid_min && id <= data->T9_reportid_max);
750} 750}
751 751
752static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data) 752static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
753{ 753{
754 struct mxt_message message; 754 u8 *message = &data->msg_buf[0];
755 const u8 *payload = &message.message[0]; 755 const u8 *payload = &data->msg_buf[1];
756 struct device *dev = &data->client->dev; 756 struct device *dev = &data->client->dev;
757 u8 reportid; 757 u8 reportid;
758 bool update_input = false; 758 bool update_input = false;
759 u32 crc; 759 u32 crc;
760 760
761 do { 761 do {
762 if (mxt_read_message(data, &message)) { 762 if (mxt_read_message(data, message)) {
763 dev_err(dev, "Failed to read message\n"); 763 dev_err(dev, "Failed to read message\n");
764 return IRQ_NONE; 764 return IRQ_NONE;
765 } 765 }
766 766
767 reportid = message.reportid; 767 reportid = message[0];
768 768
769 if (reportid == data->T6_reportid) { 769 if (reportid == data->T6_reportid) {
770 u8 status = payload[0]; 770 u8 status = payload[0];
@@ -785,18 +785,17 @@ static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
785 * do not report events if input device 785 * do not report events if input device
786 * is not yet registered 786 * is not yet registered
787 */ 787 */
788 mxt_dump_message(dev, &message); 788 mxt_dump_message(data, message);
789 } else if (mxt_is_T9_message(data, &message)) { 789 } else if (mxt_is_T9_message(data, message)) {
790 int id = reportid - data->T9_reportid_min; 790 mxt_input_touchevent(data, message);
791 mxt_input_touchevent(data, &message, id);
792 update_input = true; 791 update_input = true;
793 } else if (message.reportid == data->T19_reportid) { 792 } else if (reportid == data->T19_reportid) {
794 mxt_input_button(data, &message); 793 mxt_input_button(data, message);
795 update_input = true; 794 update_input = true;
796 } else { 795 } else {
797 mxt_dump_message(dev, &message); 796 mxt_dump_message(data, message);
798 } 797 }
799 } while (reportid != 0xff); 798 } while (reportid != MXT_RPTID_NOMSG);
800 799
801 if (update_input) 800 if (update_input)
802 mxt_input_sync(data); 801 mxt_input_sync(data);
@@ -1193,16 +1192,15 @@ release:
1193static int mxt_make_highchg(struct mxt_data *data) 1192static int mxt_make_highchg(struct mxt_data *data)
1194{ 1193{
1195 struct device *dev = &data->client->dev; 1194 struct device *dev = &data->client->dev;
1196 struct mxt_message message;
1197 int count = 10; 1195 int count = 10;
1198 int error; 1196 int error;
1199 1197
1200 /* Read dummy message to make high CHG pin */ 1198 /* Read dummy message to make high CHG pin */
1201 do { 1199 do {
1202 error = mxt_read_message(data, &message); 1200 error = mxt_read_message(data, data->msg_buf);
1203 if (error) 1201 if (error)
1204 return error; 1202 return error;
1205 } while (message.reportid != 0xff && --count); 1203 } while (data->msg_buf[0] != MXT_RPTID_NOMSG && --count);
1206 1204
1207 if (!count) { 1205 if (!count) {
1208 dev_err(dev, "CHG pin isn't cleared\n"); 1206 dev_err(dev, "CHG pin isn't cleared\n");
@@ -1239,6 +1237,23 @@ static int mxt_get_info(struct mxt_data *data)
1239 return 0; 1237 return 0;
1240} 1238}
1241 1239
1240static void mxt_free_object_table(struct mxt_data *data)
1241{
1242 input_unregister_device(data->input_dev);
1243 data->input_dev = NULL;
1244
1245 kfree(data->object_table);
1246 data->object_table = NULL;
1247 kfree(data->msg_buf);
1248 data->msg_buf = NULL;
1249 data->T5_msg_size = 0;
1250 data->T6_reportid = 0;
1251 data->T7_address = 0;
1252 data->T9_reportid_min = 0;
1253 data->T9_reportid_max = 0;
1254 data->T19_reportid = 0;
1255}
1256
1242static int mxt_get_object_table(struct mxt_data *data) 1257static int mxt_get_object_table(struct mxt_data *data)
1243{ 1258{
1244 struct i2c_client *client = data->client; 1259 struct i2c_client *client = data->client;
@@ -1289,6 +1304,9 @@ static int mxt_get_object_table(struct mxt_data *data)
1289 min_id, max_id); 1304 min_id, max_id);
1290 1305
1291 switch (object->type) { 1306 switch (object->type) {
1307 case MXT_GEN_MESSAGE_T5:
1308 /* CRC not enabled, therefore don't read last byte */
1309 data->T5_msg_size = mxt_obj_size(object) - 1;
1292 case MXT_GEN_COMMAND_T6: 1310 case MXT_GEN_COMMAND_T6:
1293 data->T6_reportid = min_id; 1311 data->T6_reportid = min_id;
1294 data->T6_address = object->start_address; 1312 data->T6_address = object->start_address;
@@ -1312,22 +1330,20 @@ static int mxt_get_object_table(struct mxt_data *data)
1312 data->mem_size = end_address + 1; 1330 data->mem_size = end_address + 1;
1313 } 1331 }
1314 1332
1333 data->msg_buf = kzalloc(data->T5_msg_size, GFP_KERNEL);
1334 if (!data->msg_buf) {
1335 dev_err(&client->dev, "Failed to allocate message buffer\n");
1336 error = -ENOMEM;
1337 goto free_object_table;
1338 }
1339
1315 data->object_table = object_table; 1340 data->object_table = object_table;
1316 1341
1317 return 0; 1342 return 0;
1318}
1319 1343
1320static void mxt_free_object_table(struct mxt_data *data) 1344free_object_table:
1321{ 1345 mxt_free_object_table(data);
1322 input_unregister_device(data->input_dev); 1346 return error;
1323 data->input_dev = NULL;
1324
1325 kfree(data->object_table);
1326 data->object_table = NULL;
1327 data->T6_reportid = 0;
1328 data->T9_reportid_min = 0;
1329 data->T9_reportid_max = 0;
1330 data->T19_reportid = 0;
1331} 1347}
1332 1348
1333static int mxt_read_t9_resolution(struct mxt_data *data) 1349static int mxt_read_t9_resolution(struct mxt_data *data)
@@ -1963,7 +1979,7 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
1963 return 0; 1979 return 0;
1964 1980
1965err_free_object: 1981err_free_object:
1966 kfree(data->object_table); 1982 mxt_free_object_table(data);
1967err_free_irq: 1983err_free_irq:
1968 free_irq(client->irq, data); 1984 free_irq(client->irq, data);
1969err_free_mem: 1985err_free_mem:
@@ -1978,7 +1994,7 @@ static int mxt_remove(struct i2c_client *client)
1978 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); 1994 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
1979 free_irq(data->irq, data); 1995 free_irq(data->irq, data);
1980 input_unregister_device(data->input_dev); 1996 input_unregister_device(data->input_dev);
1981 kfree(data->object_table); 1997 mxt_free_object_table(data);
1982 kfree(data); 1998 kfree(data);
1983 1999
1984 return 0; 2000 return 0;