aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/atmel_mxt_ts.c
diff options
context:
space:
mode:
authorNick Dyer <nick.dyer@itdev.co.uk>2014-07-23 14:25:55 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-07-23 16:25:09 -0400
commitdd24dcf566d0787297953bcaa3a7739586535a33 (patch)
tree4ffb506517e32e25a040bc00892b85ecc5ea725f /drivers/input/touchscreen/atmel_mxt_ts.c
parentba4e9a61ad54c438d4c7b655e94e31f23a6fe13f (diff)
Input: atmel_mxt_ts - initialise IRQ before probing
The maXTouch chips use the CHG line to generate status events in bootloader mode, and during configuration download, before there is enough information to configure the input device. Therefore set up the interrupt handler earlier. However, this introduces states where parts of the interrupt processing must not run. Use data->object_table as a way to tell whether the chip information is valid, and data->input_dev as a way to tell whether it is valid to generate input report. 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/atmel_mxt_ts.c')
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c101
1 files changed, 62 insertions, 39 deletions
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 6e0b4a2120d3..02c374d52967 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -764,6 +764,12 @@ static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
764 764
765 if (status & MXT_T6_STATUS_RESET) 765 if (status & MXT_T6_STATUS_RESET)
766 complete(&data->reset_completion); 766 complete(&data->reset_completion);
767 } else if (!data->input_dev) {
768 /*
769 * do not report events if input device
770 * is not yet registered
771 */
772 mxt_dump_message(dev, &message);
767 } else if (mxt_is_T9_message(data, &message)) { 773 } else if (mxt_is_T9_message(data, &message)) {
768 int id = reportid - data->T9_reportid_min; 774 int id = reportid - data->T9_reportid_min;
769 mxt_input_touchevent(data, &message, id); 775 mxt_input_touchevent(data, &message, id);
@@ -792,6 +798,9 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
792 return IRQ_HANDLED; 798 return IRQ_HANDLED;
793 } 799 }
794 800
801 if (!data->object_table)
802 return IRQ_HANDLED;
803
795 return mxt_process_messages_until_invalid(data); 804 return mxt_process_messages_until_invalid(data);
796} 805}
797 806
@@ -942,6 +951,19 @@ static int mxt_make_highchg(struct mxt_data *data)
942 return 0; 951 return 0;
943} 952}
944 953
954static int mxt_acquire_irq(struct mxt_data *data)
955{
956 int error;
957
958 enable_irq(data->irq);
959
960 error = mxt_make_highchg(data);
961 if (error)
962 return error;
963
964 return 0;
965}
966
945static int mxt_get_info(struct mxt_data *data) 967static int mxt_get_info(struct mxt_data *data)
946{ 968{
947 struct i2c_client *client = data->client; 969 struct i2c_client *client = data->client;
@@ -960,20 +982,29 @@ static int mxt_get_object_table(struct mxt_data *data)
960{ 982{
961 struct i2c_client *client = data->client; 983 struct i2c_client *client = data->client;
962 size_t table_size; 984 size_t table_size;
985 struct mxt_object *object_table;
963 int error; 986 int error;
964 int i; 987 int i;
965 u8 reportid; 988 u8 reportid;
966 989
967 table_size = data->info.object_num * sizeof(struct mxt_object); 990 table_size = data->info.object_num * sizeof(struct mxt_object);
991 object_table = kzalloc(table_size, GFP_KERNEL);
992 if (!object_table) {
993 dev_err(&data->client->dev, "Failed to allocate memory\n");
994 return -ENOMEM;
995 }
996
968 error = __mxt_read_reg(client, MXT_OBJECT_START, table_size, 997 error = __mxt_read_reg(client, MXT_OBJECT_START, table_size,
969 data->object_table); 998 object_table);
970 if (error) 999 if (error) {
1000 kfree(object_table);
971 return error; 1001 return error;
1002 }
972 1003
973 /* Valid Report IDs start counting from 1 */ 1004 /* Valid Report IDs start counting from 1 */
974 reportid = 1; 1005 reportid = 1;
975 for (i = 0; i < data->info.object_num; i++) { 1006 for (i = 0; i < data->info.object_num; i++) {
976 struct mxt_object *object = data->object_table + i; 1007 struct mxt_object *object = object_table + i;
977 u8 min_id, max_id; 1008 u8 min_id, max_id;
978 1009
979 le16_to_cpus(&object->start_address); 1010 le16_to_cpus(&object->start_address);
@@ -1009,6 +1040,8 @@ static int mxt_get_object_table(struct mxt_data *data)
1009 } 1040 }
1010 } 1041 }
1011 1042
1043 data->object_table = object_table;
1044
1012 return 0; 1045 return 0;
1013} 1046}
1014 1047
@@ -1080,21 +1113,17 @@ static int mxt_initialize(struct mxt_data *data)
1080 if (error) 1113 if (error)
1081 return error; 1114 return error;
1082 1115
1083 data->object_table = kcalloc(info->object_num,
1084 sizeof(struct mxt_object),
1085 GFP_KERNEL);
1086 if (!data->object_table) {
1087 dev_err(&client->dev, "Failed to allocate memory\n");
1088 return -ENOMEM;
1089 }
1090
1091 /* Get object table information */ 1116 /* Get object table information */
1092 error = mxt_get_object_table(data); 1117 error = mxt_get_object_table(data);
1093 if (error) { 1118 if (error) {
1094 dev_err(&client->dev, "Error %d reading object table\n", error); 1119 dev_err(&client->dev, "Error %d reading object table\n", error);
1095 goto err_free_object_table; 1120 return error;
1096 } 1121 }
1097 1122
1123 mxt_acquire_irq(data);
1124 if (error)
1125 goto err_free_object_table;
1126
1098 /* Check register init values */ 1127 /* Check register init values */
1099 error = mxt_check_reg_init(data); 1128 error = mxt_check_reg_init(data);
1100 if (error) { 1129 if (error) {
@@ -1345,11 +1374,7 @@ static ssize_t mxt_update_fw_store(struct device *dev,
1345 1374
1346 mxt_free_object_table(data); 1375 mxt_free_object_table(data);
1347 1376
1348 mxt_initialize(data); 1377 error = mxt_initialize(data);
1349
1350 enable_irq(data->irq);
1351
1352 error = mxt_make_highchg(data);
1353 if (error) 1378 if (error)
1354 return error; 1379 return error;
1355 } 1380 }
@@ -1446,9 +1471,26 @@ static int mxt_probe(struct i2c_client *client,
1446 init_completion(&data->reset_completion); 1471 init_completion(&data->reset_completion);
1447 init_completion(&data->crc_completion); 1472 init_completion(&data->crc_completion);
1448 1473
1474 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
1475 pdata->irqflags | IRQF_ONESHOT,
1476 client->name, data);
1477 if (error) {
1478 dev_err(&client->dev, "Failed to register interrupt\n");
1479 goto err_free_mem;
1480 }
1481
1482 disable_irq(client->irq);
1483
1484 error = input_register_device(input_dev);
1485 if (error) {
1486 dev_err(&client->dev, "Error %d registering input device\n",
1487 error);
1488 goto err_free_irq;
1489 }
1490
1449 error = mxt_initialize(data); 1491 error = mxt_initialize(data);
1450 if (error) 1492 if (error)
1451 goto err_free_mem; 1493 goto err_unregister_device;
1452 1494
1453 __set_bit(EV_ABS, input_dev->evbit); 1495 __set_bit(EV_ABS, input_dev->evbit);
1454 __set_bit(EV_KEY, input_dev->evbit); 1496 __set_bit(EV_KEY, input_dev->evbit);
@@ -1499,25 +1541,6 @@ static int mxt_probe(struct i2c_client *client,
1499 input_set_drvdata(input_dev, data); 1541 input_set_drvdata(input_dev, data);
1500 i2c_set_clientdata(client, data); 1542 i2c_set_clientdata(client, data);
1501 1543
1502 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
1503 pdata->irqflags | IRQF_ONESHOT,
1504 client->name, data);
1505 if (error) {
1506 dev_err(&client->dev, "Failed to register interrupt\n");
1507 goto err_free_object;
1508 }
1509
1510 error = mxt_make_highchg(data);
1511 if (error)
1512 goto err_free_irq;
1513
1514 error = input_register_device(input_dev);
1515 if (error) {
1516 dev_err(&client->dev, "Error %d registering input device\n",
1517 error);
1518 goto err_free_irq;
1519 }
1520
1521 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); 1544 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
1522 if (error) { 1545 if (error) {
1523 dev_err(&client->dev, "Failure %d creating sysfs group\n", 1546 dev_err(&client->dev, "Failure %d creating sysfs group\n",
@@ -1530,10 +1553,10 @@ static int mxt_probe(struct i2c_client *client,
1530err_unregister_device: 1553err_unregister_device:
1531 input_unregister_device(input_dev); 1554 input_unregister_device(input_dev);
1532 input_dev = NULL; 1555 input_dev = NULL;
1533err_free_irq:
1534 free_irq(client->irq, data);
1535err_free_object: 1556err_free_object:
1536 kfree(data->object_table); 1557 kfree(data->object_table);
1558err_free_irq:
1559 free_irq(client->irq, data);
1537err_free_mem: 1560err_free_mem:
1538 input_free_device(input_dev); 1561 input_free_device(input_dev);
1539 kfree(data); 1562 kfree(data);