Skip to contentSkip to conversation

Input: ili210x - Probe even if no resolution information

PATCH Applied Marek Vasut 2 participants 8 messages Feb 17, 2023 – May 7, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Input: ili210x - Probe even if no resolution information

Probe the touch controller driver even if resolution information is not available. This can happen e.g. in case the touch controller suffered a failed firmware update and is stuck in bootloader mode.

---
Cc: Dmitry Torokhov <[email protected]>
Cc: Joe Hung <[email protected]>
Cc: Luca Hsu <[email protected]>
---
V2: Add dev_warn() in case resolution is invalid

---
 drivers/input/touchscreen/ili210x.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
drivers/input/touchscreen/ili210x.c +19 -9
index 4897fafa4204d..d64b6d77d2e08 100644
@@ -370,22 +370,33 @@ static int ili251x_firmware_update_resolution(struct device *dev)
 
 	/* The firmware update blob might have changed the resolution. */
 	error = priv->chip->read_reg(client, REG_PANEL_INFO, &rs, sizeof(rs));
-	if (error)
-		return error;
+	if (!error) {
+		resx = le16_to_cpup((__le16 *)rs);
+		resy = le16_to_cpup((__le16 *)(rs + 2));
 
-	resx = le16_to_cpup((__le16 *)rs);
-	resy = le16_to_cpup((__le16 *)(rs + 2));
+		/* The value reported by the firmware is invalid. */
+		if (!resx || resx == 0xffff || !resy || resy == 0xffff)
+			error = -EINVAL;
+	}
 
-	/* The value reported by the firmware is invalid. */
-	if (!resx || resx == 0xffff || !resy || resy == 0xffff)
-		return -EINVAL;
+	/*
+	 * In case of error, the firmware might be stuck in bootloader mode,
+	 * e.g. after a failed firmware update. Set maximum resolution, but
+	 * do not fail to probe, so the user can re-trigger the firmware
+	 * update and recover the touch controller.
+	 */
+	if (error) {
+		dev_warn(dev, "Invalid resolution reported by controller.\n");
+		resx = 16384;
+		resy = 16384;
+	}
 
 	input_abs_set_max(priv->input, ABS_X, resx - 1);
 	input_abs_set_max(priv->input, ABS_Y, resy - 1);
 	input_abs_set_max(priv->input, ABS_MT_POSITION_X, resx - 1);
 	input_abs_set_max(priv->input, ABS_MT_POSITION_Y, resy - 1);
 
-	return 0;
+	return error;
 }
 
 static ssize_t ili251x_firmware_update_firmware_version(struct device *dev)
@@ -980,7 +991,6 @@ static int ili210x_i2c_probe(struct i2c_client *client)
 	if (error) {
 		dev_err(dev, "Unable to cache firmware information, err: %d\n",
 			error);
-		return error;
 	}
 	touchscreen_parse_properties(input, true, &priv->prop);
 
Signature · 1 line
2.39.1
maintainer
#1 lore raw

Hi Marek,

Quoted 48 lines · Marek Vasut

Probe the touch controller driver even if resolution information is not available. This can happen e.g. in case the touch controller suffered a failed firmware update and is stuck in bootloader mode.

---
Cc: Dmitry Torokhov <[email protected]>
Cc: Joe Hung <[email protected]>
Cc: Luca Hsu <[email protected]>
---
V2: Add dev_warn() in case resolution is invalid

---
 drivers/input/touchscreen/ili210x.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
drivers/input/touchscreen/ili210x.c +16 -7
index 4897fafa4204d..d64b6d77d2e08 100644
@@ -370,22 +370,33 @@ static int ili251x_firmware_update_resolution(struct device *dev)
 
 	/* The firmware update blob might have changed the resolution. */
 	error = priv->chip->read_reg(client, REG_PANEL_INFO, &rs, sizeof(rs));
-	if (error)
-		return error;
+	if (!error) {
+		resx = le16_to_cpup((__le16 *)rs);
+		resy = le16_to_cpup((__le16 *)(rs + 2));
 
-	resx = le16_to_cpup((__le16 *)rs);
-	resy = le16_to_cpup((__le16 *)(rs + 2));
+		/* The value reported by the firmware is invalid. */
+		if (!resx || resx == 0xffff || !resy || resy == 0xffff)
+			error = -EINVAL;
+	}
 
-	/* The value reported by the firmware is invalid. */
-	if (!resx || resx == 0xffff || !resy || resy == 0xffff)
-		return -EINVAL;
+	/*
+	 * In case of error, the firmware might be stuck in bootloader mode,
+	 * e.g. after a failed firmware update. Set maximum resolution, but
+	 * do not fail to probe, so the user can re-trigger the firmware
+	 * update and recover the touch controller.
+	 */
+	if (error) {
+		dev_warn(dev, "Invalid resolution reported by controller.\n");
+		resx = 16384;

drivers/input/touchscreen/ili210x.c static int ili251x_firmware_update_resolution(struct device *dev) · line 399

Quoted 10 lines
drivers/input/touchscreen/ili210x.c +3 -1
+		resy = 16384;
+	}
 
 	input_abs_set_max(priv->input, ABS_X, resx - 1);
 	input_abs_set_max(priv->input, ABS_Y, resy - 1);
 	input_abs_set_max(priv->input, ABS_MT_POSITION_X, resx - 1);
 	input_abs_set_max(priv->input, ABS_MT_POSITION_Y, resy - 1);
 
-	return 0;
+	return error;

I think this will make ili251x_firmware_update_cached_state() continue failing when it reports invalid coordinates. Was this intended?

Quoted 14 lines
drivers/input/touchscreen/ili210x.c +0 -1
 }
 
 static ssize_t ili251x_firmware_update_firmware_version(struct device *dev)
@@ -980,7 +991,6 @@ static int ili210x_i2c_probe(struct i2c_client *client)
 	if (error) {
 		dev_err(dev, "Unable to cache firmware information, err: %d\n",
 			error);
-		return error;
 	}
 	touchscreen_parse_properties(input, true, &priv->prop);
 
Signature · 1 line
2.39.1

Thanks.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 59 lines · Dmitry Torokhov

Hi Marek,

Quoted 56 lines · Marek Vasut

Probe the touch controller driver even if resolution information is not available. This can happen e.g. in case the touch controller suffered a failed firmware update and is stuck in bootloader mode.

---
Cc: Dmitry Torokhov <[email protected]>
Cc: Joe Hung <[email protected]>
Cc: Luca Hsu <[email protected]>
---
V2: Add dev_warn() in case resolution is invalid

---
  drivers/input/touchscreen/ili210x.c | 28 +++++++++++++++++++---------
  1 file changed, 19 insertions(+), 9 deletions(-)
drivers/input/touchscreen/ili210x.c +18 -7
index 4897fafa4204d..d64b6d77d2e08 100644
@@ -370,22 +370,33 @@ static int ili251x_firmware_update_resolution(struct device *dev)
 
  	/* The firmware update blob might have changed the resolution. */
  	error = priv->chip->read_reg(client, REG_PANEL_INFO, &rs, sizeof(rs));
-	if (error)
-		return error;
+	if (!error) {
+		resx = le16_to_cpup((__le16 *)rs);
+		resy = le16_to_cpup((__le16 *)(rs + 2));
 
-	resx = le16_to_cpup((__le16 *)rs);
-	resy = le16_to_cpup((__le16 *)(rs + 2));
+		/* The value reported by the firmware is invalid. */
+		if (!resx || resx == 0xffff || !resy || resy == 0xffff)
+			error = -EINVAL;
+	}
 
-	/* The value reported by the firmware is invalid. */
-	if (!resx || resx == 0xffff || !resy || resy == 0xffff)
-		return -EINVAL;
+	/*
+	 * In case of error, the firmware might be stuck in bootloader mode,
+	 * e.g. after a failed firmware update. Set maximum resolution, but
+	 * do not fail to probe, so the user can re-trigger the firmware
+	 * update and recover the touch controller.
+	 */
+	if (error) {
+		dev_warn(dev, "Invalid resolution reported by controller.\n");
+		resx = 16384;
+		resy = 16384;
+	}
 
  	input_abs_set_max(priv->input, ABS_X, resx - 1);
  	input_abs_set_max(priv->input, ABS_Y, resy - 1);
  	input_abs_set_max(priv->input, ABS_MT_POSITION_X, resx - 1);
  	input_abs_set_max(priv->input, ABS_MT_POSITION_Y, resy - 1);
 
Quoted 5 lines

drivers/input/touchscreen/ili210x.c static int ili251x_firmware_update_resolution(struct device *dev) · line 399

Quoted 2 lines
drivers/input/touchscreen/ili210x.c +1 -1
-	return 0;
+	return error;

I think this will make ili251x_firmware_update_cached_state() continue failing when it reports invalid coordinates. Was this intended?

This is actually correct, ili251x_firmware_update_cached_state() will fail, but ili210x_i2c_probe() won't stop there anymore, see the second hunk of this patch. The driver will instantiate the controller, so user can load correct firmware into it and recover the hardware.

maintainer
#3 lore raw
Quoted 61 lines · Marek Vasut
Quoted 51 lines · Dmitry Torokhov

Hi Marek,

Quoted 48 lines · Marek Vasut

Probe the touch controller driver even if resolution information is not available. This can happen e.g. in case the touch controller suffered a failed firmware update and is stuck in bootloader mode.

---
Cc: Dmitry Torokhov <[email protected]>
Cc: Joe Hung <[email protected]>
Cc: Luca Hsu <[email protected]>
---
V2: Add dev_warn() in case resolution is invalid

---
  drivers/input/touchscreen/ili210x.c | 28 +++++++++++++++++++---------
  1 file changed, 19 insertions(+), 9 deletions(-)
drivers/input/touchscreen/ili210x.c +18 -7
index 4897fafa4204d..d64b6d77d2e08 100644
@@ -370,22 +370,33 @@ static int ili251x_firmware_update_resolution(struct device *dev)
  	/* The firmware update blob might have changed the resolution. */
  	error = priv->chip->read_reg(client, REG_PANEL_INFO, &rs, sizeof(rs));
-	if (error)
-		return error;
+	if (!error) {
+		resx = le16_to_cpup((__le16 *)rs);
+		resy = le16_to_cpup((__le16 *)(rs + 2));
-	resx = le16_to_cpup((__le16 *)rs);
-	resy = le16_to_cpup((__le16 *)(rs + 2));
+		/* The value reported by the firmware is invalid. */
+		if (!resx || resx == 0xffff || !resy || resy == 0xffff)
+			error = -EINVAL;
+	}
-	/* The value reported by the firmware is invalid. */
-	if (!resx || resx == 0xffff || !resy || resy == 0xffff)
-		return -EINVAL;
+	/*
+	 * In case of error, the firmware might be stuck in bootloader mode,
+	 * e.g. after a failed firmware update. Set maximum resolution, but
+	 * do not fail to probe, so the user can re-trigger the firmware
+	 * update and recover the touch controller.
+	 */
+	if (error) {
+		dev_warn(dev, "Invalid resolution reported by controller.\n");
+		resx = 16384;
+		resy = 16384;
+	}
  	input_abs_set_max(priv->input, ABS_X, resx - 1);
Quoted 8 lines

drivers/input/touchscreen/ili210x.c static int ili251x_firmware_update_resolution(struct device *dev) · line 399

Quoted 5 lines
drivers/input/touchscreen/ili210x.c +1 -1
  	input_abs_set_max(priv->input, ABS_Y, resy - 1);
  	input_abs_set_max(priv->input, ABS_MT_POSITION_X, resx - 1);
  	input_abs_set_max(priv->input, ABS_MT_POSITION_Y, resy - 1);
-	return 0;
+	return error;

I think this will make ili251x_firmware_update_cached_state() continue failing when it reports invalid coordinates. Was this intended?

Quoted 4 lines

This is actually correct, ili251x_firmware_update_cached_state() will fail, but ili210x_i2c_probe() won't stop there anymore, see the second hunk of this patch. The driver will instantiate the controller, so user can load correct firmware into it and recover the hardware.

I was concerned about call from ili210x_firmware_update_store() which will continue returning error.

Thanks.

Signature · 1 line
Dmitry
#4 lore raw
Quoted 62 lines · Dmitry Torokhov
Quoted 61 lines · Marek Vasut
Quoted 59 lines · Dmitry Torokhov

Hi Marek,

Quoted 43 lines · Marek Vasut

Probe the touch controller driver even if resolution information is not available. This can happen e.g. in case the touch controller suffered a failed firmware update and is stuck in bootloader mode.

---
Cc: Dmitry Torokhov <[email protected]>
Cc: Joe Hung <[email protected]>
Cc: Luca Hsu <[email protected]>
---
V2: Add dev_warn() in case resolution is invalid

---
   drivers/input/touchscreen/ili210x.c | 28 +++++++++++++++++++---------
   1 file changed, 19 insertions(+), 9 deletions(-)
drivers/input/touchscreen/ili210x.c +14 -7
index 4897fafa4204d..d64b6d77d2e08 100644
@@ -370,22 +370,33 @@ static int ili251x_firmware_update_resolution(struct device *dev)
   	/* The firmware update blob might have changed the resolution. */
   	error = priv->chip->read_reg(client, REG_PANEL_INFO, &rs, sizeof(rs));
-	if (error)
-		return error;
+	if (!error) {
+		resx = le16_to_cpup((__le16 *)rs);
+		resy = le16_to_cpup((__le16 *)(rs + 2));
-	resx = le16_to_cpup((__le16 *)rs);
-	resy = le16_to_cpup((__le16 *)(rs + 2));
+		/* The value reported by the firmware is invalid. */
+		if (!resx || resx == 0xffff || !resy || resy == 0xffff)
+			error = -EINVAL;
+	}
-	/* The value reported by the firmware is invalid. */
-	if (!resx || resx == 0xffff || !resy || resy == 0xffff)
-		return -EINVAL;
+	/*
+	 * In case of error, the firmware might be stuck in bootloader mode,
+	 * e.g. after a failed firmware update. Set maximum resolution, but
+	 * do not fail to probe, so the user can re-trigger the firmware
+	 * update and recover the touch controller.
+	 */
+	if (error) {

drivers/input/touchscreen/ili210x.c static int ili251x_firmware_update_resolution(struct device *dev) · line 394

Quoted 10 lines
drivers/input/touchscreen/ili210x.c +5 -1
+		dev_warn(dev, "Invalid resolution reported by controller.\n");
+		resx = 16384;
+		resy = 16384;
+	}
   	input_abs_set_max(priv->input, ABS_X, resx - 1);
   	input_abs_set_max(priv->input, ABS_Y, resy - 1);
   	input_abs_set_max(priv->input, ABS_MT_POSITION_X, resx - 1);
   	input_abs_set_max(priv->input, ABS_MT_POSITION_Y, resy - 1);
-	return 0;
+	return error;

I think this will make ili251x_firmware_update_cached_state() continue failing when it reports invalid coordinates. Was this intended?

Quoted 7 lines
Quoted 4 lines

This is actually correct, ili251x_firmware_update_cached_state() will fail, but ili210x_i2c_probe() won't stop there anymore, see the second hunk of this patch. The driver will instantiate the controller, so user can load correct firmware into it and recover the hardware.

I was concerned about call from ili210x_firmware_update_store() which will continue returning error.

It hopefully won't, because at that point the controller would be running new and working firmware, which would report the correct values. If the firmware is broken, then yes, it would fail.

#5 lore raw
Quoted 73 lines · Marek Vasut
Quoted 72 lines · Dmitry Torokhov
Quoted 70 lines · Marek Vasut
Quoted 56 lines · Dmitry Torokhov

Hi Marek,

Quoted 53 lines · Marek Vasut

Probe the touch controller driver even if resolution information is not available. This can happen e.g. in case the touch controller suffered a failed firmware update and is stuck in bootloader mode.

---
Cc: Dmitry Torokhov <[email protected]>
Cc: Joe Hung <[email protected]>
Cc: Luca Hsu <[email protected]>
---
V2: Add dev_warn() in case resolution is invalid
---
   drivers/input/touchscreen/ili210x.c | 28
+++++++++++++++++++---------

   1 file changed, 19 insertions(+), 9 deletions(-)
drivers/input/touchscreen/ili210x.c +10 -7
index 4897fafa4204d..d64b6d77d2e08 100644
@@ -370,22 +370,33 @@ static int 
 ili251x_firmware_update_resolution(struct device *dev)
        /* The firmware update blob might have changed the resolution. */
        error = priv->chip->read_reg(client, REG_PANEL_INFO, &rs, sizeof(rs));
-    if (error)
-        return error;
+    if (!error) {
+        resx = le16_to_cpup((__le16 *)rs);
+        resy = le16_to_cpup((__le16 *)(rs + 2));
-    resx = le16_to_cpup((__le16 *)rs);
-    resy = le16_to_cpup((__le16 *)(rs + 2));
+        /* The value reported by the firmware is invalid. */
+        if (!resx || resx == 0xffff || !resy || resy == 0xffff)
+            error = -EINVAL;
+    }
-    /* The value reported by the firmware is invalid. */
-    if (!resx || resx == 0xffff || !resy || resy == 0xffff)
-        return -EINVAL;
+    /*
+     * In case of error, the firmware might be stuck in bootloader 
 mode,
+     * e.g. after a failed firmware update. Set maximum 

resolution, but
+     * do not fail to probe, so the user can re-trigger the firmware +     * update and recover the touch controller.
+     */
+    if (error) {
+        dev_warn(dev, "Invalid resolution reported by controller.\n");
+        resx = 16384;
+        resy = 16384;
+    }
       input_abs_set_max(priv->input, ABS_X, resx - 1);

Quoted 8 lines
Quoted 5 lines

       input_abs_set_max(priv->input, ABS_Y, resy - 1); input_abs_set_max(priv->input, ABS_MT_POSITION_X, resx - 1); input_abs_set_max(priv->input, ABS_MT_POSITION_Y, resy - 1); -    return 0;
+    return error;

I think this will make ili251x_firmware_update_cached_state() continue failing when it reports invalid coordinates. Was this intended?

This is actually correct, ili251x_firmware_update_cached_state() will fail, but ili210x_i2c_probe() won't stop there anymore, see the second hunk of this patch. The driver will instantiate the controller, so user can load correct firmware into it and recover the hardware.

Quoted 4 lines
Quoted 2 lines

I was concerned about call from ili210x_firmware_update_store() which will continue returning error.

It hopefully won't, because at that point the controller would be running new and working firmware, which would report the correct values. If the firmware is broken, then yes, it would fail.

Hi,

any news on this ?

I still have to track this downstream to recover those devices from broken firmware update, it would be really useful to have this also upstream.

maintainer Applied
#6 lore raw
In reply to Marek Vasut
Quoted 5 lines · Marek Vasut

Probe the touch controller driver even if resolution information is not available. This can happen e.g. in case the touch controller suffered a failed firmware update and is stuck in bootloader mode.

Applied, thank you.

Signature · 1 line
Dmitry
#7 lore raw
Quoted 8 lines · Dmitry Torokhov
Quoted 5 lines · Marek Vasut

Probe the touch controller driver even if resolution information is not available. This can happen e.g. in case the touch controller suffered a failed firmware update and is stuck in bootloader mode.

Applied, thank you.

Much appreciated, thanks !