Skip to content

Commit c3f7804

Browse files
ndyerdtor
authored andcommitted
Input: atmel_mxt_ts - implement CRC check for configuration data
The configuration is stored in NVRAM on the maXTouch chip. When the device is reset it reports a CRC of the stored configuration values. Therefore it isn't necessary to send the configuration on each probe - we can check the CRC matches and avoid a timeconsuming backup/reset cycle. 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>
1 parent 7bed680 commit c3f7804

2 files changed

Lines changed: 53 additions & 8 deletions

File tree

‎drivers/input/touchscreen/atmel_mxt_ts.c‎

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
#define MXT_BACKUP_TIME 50 /* msec */
189189
#define MXT_RESET_TIME 200 /* msec */
190190
#define MXT_RESET_TIMEOUT 3000 /* msec */
191+
#define MXT_CRC_TIMEOUT 1000 /* msec */
191192
#define MXT_FW_RESET_TIME 3000 /* msec */
192193
#define MXT_FW_CHG_TIMEOUT 300 /* msec */
193194

@@ -259,6 +260,7 @@ struct mxt_data {
259260
unsigned int max_x;
260261
unsigned int max_y;
261262
bool in_bootloader;
263+
u32 config_crc;
262264

263265
/* Cached parameters from object table */
264266
u8 T6_reportid;
@@ -272,6 +274,9 @@ struct mxt_data {
272274

273275
/* for reset handling */
274276
struct completion reset_completion;
277+
278+
/* for config update handling */
279+
struct completion crc_completion;
275280
};
276281

277282
static size_t mxt_obj_size(const struct mxt_object *obj)
@@ -636,7 +641,7 @@ static void mxt_input_touchevent(struct mxt_data *data,
636641
}
637642
}
638643

639-
static unsigned mxt_extract_T6_csum(const u8 *csum)
644+
static u16 mxt_extract_T6_csum(const u8 *csum)
640645
{
641646
return csum[0] | (csum[1] << 8) | (csum[2] << 16);
642647
}
@@ -654,6 +659,7 @@ static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
654659
struct device *dev = &data->client->dev;
655660
u8 reportid;
656661
bool update_input = false;
662+
u32 crc;
657663

658664
do {
659665
if (mxt_read_message(data, &message)) {
@@ -665,9 +671,15 @@ static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
665671

666672
if (reportid == data->T6_reportid) {
667673
u8 status = payload[0];
668-
unsigned csum = mxt_extract_T6_csum(&payload[1]);
674+
675+
crc = mxt_extract_T6_csum(&payload[1]);
676+
if (crc != data->config_crc) {
677+
data->config_crc = crc;
678+
complete(&data->crc_completion);
679+
}
680+
669681
dev_dbg(dev, "Status: %02x Config Checksum: %06x\n",
670-
status, csum);
682+
status, data->config_crc);
671683

672684
if (status & MXT_T6_STATUS_RESET)
673685
complete(&data->reset_completion);
@@ -757,6 +769,24 @@ static int mxt_soft_reset(struct mxt_data *data)
757769
return 0;
758770
}
759771

772+
static void mxt_update_crc(struct mxt_data *data, u8 cmd, u8 value)
773+
{
774+
/*
775+
* On failure, CRC is set to 0 and config will always be
776+
* downloaded.
777+
*/
778+
data->config_crc = 0;
779+
reinit_completion(&data->crc_completion);
780+
781+
mxt_t6_command(data, cmd, value, true);
782+
783+
/*
784+
* Wait for crc message. On failure, CRC is set to 0 and config will
785+
* always be downloaded.
786+
*/
787+
mxt_wait_for_completion(data, &data->crc_completion, MXT_CRC_TIMEOUT);
788+
}
789+
760790
static int mxt_check_reg_init(struct mxt_data *data)
761791
{
762792
const struct mxt_platform_data *pdata = data->pdata;
@@ -771,6 +801,16 @@ static int mxt_check_reg_init(struct mxt_data *data)
771801
return 0;
772802
}
773803

804+
mxt_update_crc(data, MXT_COMMAND_REPORTALL, 1);
805+
806+
if (data->config_crc == pdata->config_crc) {
807+
dev_info(dev, "Config CRC 0x%06X: OK\n", data->config_crc);
808+
return 0;
809+
}
810+
811+
dev_info(dev, "Config CRC 0x%06X: does not match 0x%06X\n",
812+
data->config_crc, pdata->config_crc);
813+
774814
for (i = 0; i < data->info.object_num; i++) {
775815
object = data->object_table + i;
776816

@@ -790,6 +830,14 @@ static int mxt_check_reg_init(struct mxt_data *data)
790830
index += size;
791831
}
792832

833+
mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE);
834+
835+
ret = mxt_soft_reset(data);
836+
if (ret)
837+
return ret;
838+
839+
dev_info(dev, "Config successfully updated\n");
840+
793841
return 0;
794842
}
795843

@@ -929,11 +977,6 @@ static int mxt_initialize(struct mxt_data *data)
929977
goto err_free_object_table;
930978
}
931979

932-
error = mxt_t6_command(data, MXT_COMMAND_BACKUPNV,
933-
MXT_BACKUP_VALUE, false);
934-
if (!error)
935-
mxt_soft_reset(data);
936-
937980
/* Update matrix size at info struct */
938981
error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
939982
if (error)
@@ -1263,6 +1306,7 @@ static int mxt_probe(struct i2c_client *client,
12631306

12641307
init_completion(&data->bl_completion);
12651308
init_completion(&data->reset_completion);
1309+
init_completion(&data->crc_completion);
12661310

12671311
mxt_calc_resolution(data);
12681312

‎include/linux/i2c/atmel_mxt_ts.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
struct mxt_platform_data {
3030
const u8 *config;
3131
size_t config_length;
32+
u32 config_crc;
3233

3334
unsigned int x_size;
3435
unsigned int y_size;

0 commit comments

Comments
 (0)