diff mbox series

[v3,4/4] input: cyttsp5: add startup retry

Message ID 20250110-nekocwd-upstreaming-cyttsp5-v3-4-b33659c8effc@gmail.com (mailing list archive)
State New
Headers show
Series Input: cyttsp5 - improve error handling and remove regmap | expand

Commit Message

Vasiliy Doylov via B4 Relay Jan. 9, 2025, 9:37 p.m. UTC
From: "Vasiliy Doylov (NekoCWD)" <nekodevelopper@gmail.com>

Some firmware/configuration variants fails to start with first attempt.
Vendors drivers tries to start multiple times.

Co-developed-by: James Hilliard <james.hilliard1@gmail.com>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Signed-off-by: Vasiliy Doylov (NekoCWD) <nekodevelopper@gmail.com>
---
 drivers/input/touchscreen/cyttsp5.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/cyttsp5.c b/drivers/input/touchscreen/cyttsp5.c
index 4860ce751c913c605d5f72dad66d1eba9825a900..c8771f44b8e35fcdbf278034f25b0be2bb392869 100644
--- a/drivers/input/touchscreen/cyttsp5.c
+++ b/drivers/input/touchscreen/cyttsp5.c
@@ -29,6 +29,7 @@ 
 #define CY_PIP_1P7_EMPTY_BUF			0xFF00
 #define CYTTSP5_PREALLOCATED_CMD_BUFFER		32
 #define CY_BITS_PER_BTN				1
+#define CY_CORE_STARTUP_RETRY_COUNT		10
 #define CY_NUM_BTN_EVENT_ID			GENMASK(CY_BITS_PER_BTN - 1, 0)
 
 #define MAX_AREA				255
@@ -824,8 +825,10 @@  static int cyttsp5_fill_all_touch(struct cyttsp5 *ts)
 
 static int cyttsp5_startup(struct cyttsp5 *ts)
 {
+	int retry = CY_CORE_STARTUP_RETRY_COUNT;
 	int error;
 
+reset:
 	error = cyttsp5_deassert_int(ts);
 	if (error) {
 		dev_err(ts->dev, "Error on deassert int r=%d\n", error);
@@ -834,6 +837,8 @@  static int cyttsp5_startup(struct cyttsp5 *ts)
 	error = cyttsp5_get_hid_descriptor(ts, &ts->hid_desc);
 	if (error < 0) {
 		dev_err(ts->dev, "Error on getting HID descriptor r=%d\n", error);
+		if (retry--)
+			goto reset;
 		return error;
 	}
 
@@ -845,17 +850,23 @@  static int cyttsp5_startup(struct cyttsp5 *ts)
 		error = cyttsp5_hid_output_bl_launch_app(ts);
 		if (error < 0) {
 			dev_err(ts->dev, "Error on launch app r=%d\n", error);
+			if (retry--)
+				goto reset;
 			return error;
 		}
 
 		error = cyttsp5_get_hid_descriptor(ts, &ts->hid_desc);
 		if (error < 0) {
 			dev_err(ts->dev, "Error on getting HID descriptor r=%d\n", error);
+			if (retry--)
+				goto reset;
 			return error;
 		}
 
 		if (ts->hid_desc.packet_id == HID_BL_REPORT_ID) {
 			dev_err(ts->dev, "Error on launch app still in bootloader\n");
+			if (retry--)
+				goto reset;
 			return -EPROTO;
 		}
 	}
@@ -863,12 +874,16 @@  static int cyttsp5_startup(struct cyttsp5 *ts)
 	error = cyttsp5_fill_all_touch(ts);
 	if (error < 0) {
 		dev_err(ts->dev, "Error on report descriptor r=%d\n", error);
+		if (retry--)
+			goto reset;
 		return error;
 	}
 
 	error = cyttsp5_hid_output_get_sysinfo(ts);
 	if (error) {
 		dev_err(ts->dev, "Error on getting sysinfo r=%d\n", error);
+		if (retry--)
+			goto reset;
 		return error;
 	}