[PATCH 30/40] Input: atmel_mxt_ts - recover from bootloader on probe

From: Nick Dyer
Date: Fri Feb 22 2013 - 13:13:23 EST


The MXT device may be in bootloader mode on probe, due to:
1) APP CRC failure, either:
a) flash corruption
b) bad power or other intermittent problem in checking CRC
2) If the device has been reset 10 or more times without accessing comms
3) Warm probe, device was in bootloader mode already

This code attempts to recover from 1(b) and 3.

Signed-off-by: Nick Dyer <nick.dyer@xxxxxxxxxxx>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 33 +++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 96c961e..02fce62 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -519,13 +519,18 @@ recheck:
return 0;
}

-static int mxt_unlock_bootloader(struct mxt_data *data)
+static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock)
{
int ret;
u8 buf[2];

- buf[0] = MXT_UNLOCK_CMD_LSB;
- buf[1] = MXT_UNLOCK_CMD_MSB;
+ if (unlock) {
+ buf[0] = MXT_UNLOCK_CMD_LSB;
+ buf[1] = MXT_UNLOCK_CMD_MSB;
+ } else {
+ buf[0] = 0x01;
+ buf[1] = 0x01;
+ }

ret = mxt_bootloader_write(data, buf, 2);
if (ret) {
@@ -1601,16 +1606,30 @@ static int mxt_initialize(struct mxt_data *data)
struct i2c_client *client = data->client;
struct mxt_info *info = &data->info;
int error;
+ u8 retry_count = 0;

+retry_probe:
error = mxt_get_info(data);
if (error) {
error = mxt_probe_bootloader(data);
-
if (error) {
+ /* Chip is not in appmode or bootloader mode */
return error;
} else {
- data->state = BOOTLOADER;
- return 0;
+ if (++retry_count > 10) {
+ dev_err(&client->dev,
+ "Could not recover device from "
+ "bootloader mode\n");
+ data->state = BOOTLOADER;
+ /* this is not an error state, we can reflash
+ * from here */
+ return 0;
+ }
+
+ /* Attempt to exit bootloader into app mode */
+ mxt_send_bootloader_cmd(data, false);
+ msleep(MXT_FWRESET_TIME);
+ goto retry_probe;
}
}

@@ -1807,7 +1826,7 @@ static int mxt_load_fw(struct device *dev, const char *fn)
dev_info(dev, "Unlocking bootloader\n");

/* Unlock bootloader */
- ret = mxt_unlock_bootloader(data);
+ ret = mxt_send_bootloader_cmd(data, true);
if (ret) {
data->state = FAILED;
goto release_firmware;
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/