diff mbox

[06/10] Input: atmel_mxt_ts - destroy state before fw update and restore after

Message ID 1359706312-24642-7-git-send-email-djkurtz@chromium.org (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Kurtz Feb. 1, 2013, 8:11 a.m. UTC
After firmware update, the device may have a completely different object
table which corresponds to an input device with different properties.
So, destroy the old state before firmware update, and completely
reinitialize the driver afterward.

Two benefits of this:
 1) Since there is no input device during fw update, no need to worry
about device open/close events.
 2) If firmware update fails, the device and driver will still be in
bootloader mode and an improperly configured input device will not exist.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Dmitry Torokhov Feb. 13, 2013, 9:47 p.m. UTC | #1
On Fri, Feb 01, 2013 at 04:11:48PM +0800, Daniel Kurtz wrote:
> After firmware update, the device may have a completely different object
> table which corresponds to an input device with different properties.
> So, destroy the old state before firmware update, and completely
> reinitialize the driver afterward.
> 
> Two benefits of this:
>  1) Since there is no input device during fw update, no need to worry
> about device open/close events.
>  2) If firmware update fails, the device and driver will still be in
> bootloader mode and an improperly configured input device will not exist.
> 
> Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
> ---
>  drivers/input/touchscreen/atmel_mxt_ts.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> index 76a25d3..c74f5a5 100644
> --- a/drivers/input/touchscreen/atmel_mxt_ts.c
> +++ b/drivers/input/touchscreen/atmel_mxt_ts.c
> @@ -1001,6 +1001,13 @@ static int mxt_load_fw(struct device *dev, const char *fn)
>  		client->addr = MXT_BOOT_HIGH;
>  
>  bootloader_ready:
> +	/* Free any driver state. It will get reinitialized after fw update. */
> +	mxt_free_object_table(data);
> +	if (data->input_dev) {
> +		input_unregister_device(data->input_dev);
> +		data->input_dev = NULL;
> +	}
> +
>  	ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
>  	if (ret)
>  		goto out;
> @@ -1068,9 +1075,8 @@ static ssize_t mxt_update_fw_store(struct device *dev,
>  		/* Wait for reset */
>  		msleep(MXT_FWRESET_TIME);
>  
> -		mxt_free_object_table(data);
> -
>  		mxt_initialize(data);
> +		mxt_input_dev_create(data);

What if it fails?

>  	}
>  
>  	enable_irq(data->irq);
> -- 
> 1.8.1
>
diff mbox

Patch

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 76a25d3..c74f5a5 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1001,6 +1001,13 @@  static int mxt_load_fw(struct device *dev, const char *fn)
 		client->addr = MXT_BOOT_HIGH;
 
 bootloader_ready:
+	/* Free any driver state. It will get reinitialized after fw update. */
+	mxt_free_object_table(data);
+	if (data->input_dev) {
+		input_unregister_device(data->input_dev);
+		data->input_dev = NULL;
+	}
+
 	ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
 	if (ret)
 		goto out;
@@ -1068,9 +1075,8 @@  static ssize_t mxt_update_fw_store(struct device *dev,
 		/* Wait for reset */
 		msleep(MXT_FWRESET_TIME);
 
-		mxt_free_object_table(data);
-
 		mxt_initialize(data);
+		mxt_input_dev_create(data);
 	}
 
 	enable_irq(data->irq);