linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: nick.dyer@itdev.co.uk
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Yufeng Shen <miletus@google.com>,
	Daniel Kurtz <djkurtz@chromium.org>,
	Henrik Rydberg <rydberg@euromail.se>,
	Joonyoung Shim <jy0922.shim@samsung.com>,
	Alan Bowens <Alan.Bowens@atmel.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Meerwald <pmeerw@pmeerw.net>,
	Benson Leung <bleung@chromium.org>,
	Olof Johansson <olofj@chromium.org>, Sekhar Nori <nsekhar@ti.com>,
	Nick Dyer <nick.dyer@itdev.co.uk>
Subject: [PATCH 11/15] Input: atmel_mxt_ts - recover from bootloader on probe
Date: Thu,  3 Jul 2014 16:01:33 +0100	[thread overview]
Message-ID: <1404399697-26484-12-git-send-email-nick.dyer@itdev.co.uk> (raw)
In-Reply-To: <1404399697-26484-1-git-send-email-nick.dyer@itdev.co.uk>

From: Nick Dyer <nick.dyer@itdev.co.uk>

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 while 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.

There is an additional complexity: we have to try two possible bootloader
addresses because the mapping is not one-to-one and we don't know the exact
model yet.

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Yufeng Shen <miletus@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c | 67 ++++++++++++++++++++++++--------
 1 file changed, 50 insertions(+), 17 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 5fe3285..8bcf21c 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -383,7 +383,7 @@ static int mxt_bootloader_write(struct mxt_data *data,
 	return ret;
 }
 
-static int mxt_lookup_bootloader_address(struct mxt_data *data)
+static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry)
 {
 	u8 appmode = data->client->addr;
 	u8 bootloader;
@@ -392,7 +392,7 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data)
 	case 0x4a:
 	case 0x4b:
 		/* Chips after 1664S use different scheme */
-		if (data->info.family_id >= 0xa2) {
+		if (retry || data->info.family_id >= 0xa2) {
 			bootloader = appmode - 0x24;
 			break;
 		}
@@ -414,14 +414,14 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data)
 	return 0;
 }
 
-static int mxt_probe_bootloader(struct mxt_data *data)
+static int mxt_probe_bootloader(struct mxt_data *data, bool retry)
 {
 	struct device *dev = &data->client->dev;
 	int ret;
 	u8 val;
 	bool crc_failure;
 
-	ret = mxt_lookup_bootloader_address(data);
+	ret = mxt_lookup_bootloader_address(data, retry);
 	if (ret)
 		return ret;
 
@@ -522,13 +522,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)
@@ -1525,15 +1530,40 @@ static int mxt_initialize(struct mxt_data *data)
 {
 	struct i2c_client *client = data->client;
 	int error;
+	bool alt_bootloader_addr = false;
+	bool retry = false;
 
+retry_info:
 	error = mxt_get_info(data);
 	if (error) {
-		error = mxt_probe_bootloader(data);
-		if (error)
-			return error;
+retry_bootloader:
+		error = mxt_probe_bootloader(data, alt_bootloader_addr);
+		if (error) {
+			if (alt_bootloader_addr) {
+				/* Chip is not in appmode or bootloader mode */
+				return error;
+			}
 
-		data->in_bootloader = true;
-		return 0;
+			dev_info(&client->dev, "Trying alternate bootloader address\n");
+			alt_bootloader_addr = true;
+			goto retry_bootloader;
+		} else {
+			if (retry) {
+				dev_err(&client->dev, "Could not recover from bootloader mode\n");
+				/*
+				 * We can reflash from this state, so do not
+				 * abort init
+				 */
+				data->in_bootloader = true;
+				return 0;
+			}
+
+			/* Attempt to exit bootloader into app mode */
+			mxt_send_bootloader_cmd(data, false);
+			msleep(MXT_FW_RESET_TIME);
+			retry = true;
+			goto retry_info;
+		}
 	}
 
 	/* Get object table information */
@@ -1714,10 +1744,6 @@ static int mxt_load_fw(struct device *dev, const char *fn)
 	if (ret)
 		goto release_firmware;
 
-	ret = mxt_lookup_bootloader_address(data);
-	if (ret)
-		goto release_firmware;
-
 	if (!data->in_bootloader) {
 		/* Change to the bootloader mode */
 		data->in_bootloader = true;
@@ -1728,6 +1754,13 @@ static int mxt_load_fw(struct device *dev, const char *fn)
 			goto release_firmware;
 
 		msleep(MXT_RESET_TIME);
+
+		/* Do not need to scan since we know family ID */
+		ret = mxt_lookup_bootloader_address(data, 0);
+		if (ret)
+			goto release_firmware;
+	} else {
+		enable_irq(data->irq);
 	}
 
 	mxt_free_object_table(data);
@@ -1743,7 +1776,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)
 			goto disable_irq;
 	}
-- 
2.0.1


  parent reply	other threads:[~2014-07-03 15:13 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-03 15:01 [PATCH 00/15] atmel_mxt_ts - device tree, bootloader, etc nick.dyer
2014-07-03 15:01 ` [PATCH 01/15] Input: atmel_mxt_ts - initialise IRQ before probing nick.dyer
2014-07-03 15:01 ` [PATCH 02/15] Input: atmel_mxt_ts - move input device init into separate function nick.dyer
2014-07-03 15:01 ` [PATCH 03/15] Input: atmel_mxt_ts - set pointer emulation on touchpads nick.dyer
2014-07-03 15:01 ` [PATCH 04/15] Input: atmel_mxt_ts - implement device tree support nick.dyer
2014-07-22 20:37   ` Stephen Warren
2014-07-23 15:13     ` Nick Dyer
2014-07-23 21:36   ` Stephen Warren
2014-07-24 15:10     ` Nick Dyer
2014-07-24 16:04       ` Stephen Warren
2014-07-03 15:01 ` [PATCH 05/15] Input: atmel_mxt_ts - download device config using firmware loader nick.dyer
2014-07-03 15:01 ` [PATCH 06/15] Input: atmel_mxt_ts - calculate and check CRC in config file nick.dyer
2014-07-03 15:01 ` [PATCH 07/15] Input: atmel_mxt_ts - use deep sleep mode when stopped nick.dyer
2014-07-03 15:01 ` [PATCH 08/15] Input: atmel_mxt_ts - handle APP_CRC_FAIL on startup nick.dyer
2014-07-03 15:01 ` [PATCH 09/15] Input: atmel_mxt_ts - handle bootloader previously unlocked nick.dyer
2014-07-03 15:01 ` [PATCH 10/15] Input: atmel_mxt_ts - add bootloader addresses for new chips nick.dyer
2014-07-03 15:01 ` nick.dyer [this message]
2014-07-03 15:01 ` [PATCH 12/15] Input: atmel_mxt_ts - add support for dynamic message size nick.dyer
2014-07-03 15:01 ` [PATCH 13/15] Input: atmel_mxt_ts - decode T6 status messages nick.dyer
2014-07-03 15:01 ` [PATCH 14/15] Input: atmel_mxt_ts - split message handler into separate functions nick.dyer
2014-07-03 15:01 ` [PATCH 15/15] Input: atmel_mxt_ts - implement T44 message handling nick.dyer
2014-07-07 11:21 ` [PATCH 00/15] atmel_mxt_ts - device tree, bootloader, etc Sekhar Nori
2014-07-07 11:38   ` Nick Dyer
2014-07-08 12:28     ` Sekhar Nori
2014-07-22 20:34 ` Stephen Warren
2014-07-23 15:30   ` Nick Dyer
2014-07-23 17:22     ` Stephen Warren
2014-07-23 20:29       ` Dmitry Torokhov
2014-07-23 21:39         ` Stephen Warren
2014-07-24 13:47       ` Nick Dyer
2014-07-24 21:19         ` Stephen Warren
2014-07-25 14:10           ` Nick Dyer
2014-07-25 20:06             ` Stephen Warren
2014-07-28 17:28               ` Dmitry Torokhov
2014-07-28 20:20               ` Yufeng Shen
2014-07-28 21:23                 ` Stephen Warren
2014-07-28 23:42                   ` Stephen Warren
2014-07-29  0:10                     ` Yufeng Shen
2014-07-29 16:16                       ` Stephen Warren
2014-07-29 17:06                         ` Nick Dyer
2014-07-29 19:26                           ` Stephen Warren
2014-09-02 15:45                             ` Stephen Warren
2014-07-29 16:43                       ` Nick Dyer
2014-07-29 16:26                     ` Nick Dyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404399697-26484-12-git-send-email-nick.dyer@itdev.co.uk \
    --to=nick.dyer@itdev.co.uk \
    --cc=Alan.Bowens@atmel.com \
    --cc=bleung@chromium.org \
    --cc=djkurtz@chromium.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jy0922.shim@samsung.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miletus@google.com \
    --cc=nsekhar@ti.com \
    --cc=olofj@chromium.org \
    --cc=pmeerw@pmeerw.net \
    --cc=rydberg@euromail.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).