summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYauhen Kharuzhy <jekhor@gmail.com>2026-02-17 21:10:27 +0300
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2026-02-18 10:05:16 +0300
commit710a1a8c591e93fa49946b68a4f1e25ae9687ecf (patch)
tree7d3831659940d1120d041de6d69b342babdd3367
parent029edcfc4331f404570affbbd4f7d11f0a7fb13e (diff)
downloadlinux-710a1a8c591e93fa49946b68a4f1e25ae9687ecf.tar.xz
Input: drv260x - handle calibration timeout
If something goes wrong during calibration (for instance, if the 'enable' GPIO was not properly defined), the GO bit may not be cleared after some time, causing the driver to get stuck. To prevent this, add a timeout check to the waiting loop and return an error if it times out. Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com> Link: https://patch.msgid.link/20260215141435.727872-6-jekhor@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--drivers/input/misc/drv260x.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/input/misc/drv260x.c b/drivers/input/misc/drv260x.c
index d73175024abb..b3076aa682c4 100644
--- a/drivers/input/misc/drv260x.c
+++ b/drivers/input/misc/drv260x.c
@@ -166,6 +166,12 @@
#define DRV260X_AUTOCAL_TIME_500MS (2 << 4)
#define DRV260X_AUTOCAL_TIME_1000MS (3 << 4)
+/*
+ * Timeout for waiting for the GO status bit, in seconds. Should be reasonably
+ * large to wait for a auto-calibration cycle completion.
+ */
+#define DRV260X_GO_TIMEOUT_S 5
+
/**
* struct drv260x_data -
* @input_dev: Pointer to the input device
@@ -309,6 +315,7 @@ static int drv260x_init(struct drv260x_data *haptics)
{
int error;
unsigned int cal_buf;
+ unsigned long timeout;
error = regmap_write(haptics->regmap,
DRV260X_RATED_VOLT, haptics->rated_voltage);
@@ -398,6 +405,7 @@ static int drv260x_init(struct drv260x_data *haptics)
return error;
}
+ timeout = jiffies + DRV260X_GO_TIMEOUT_S * HZ;
do {
usleep_range(15000, 15500);
error = regmap_read(haptics->regmap, DRV260X_GO, &cal_buf);
@@ -407,6 +415,11 @@ static int drv260x_init(struct drv260x_data *haptics)
error);
return error;
}
+ if (time_after(jiffies, timeout)) {
+ dev_err(&haptics->client->dev,
+ "Calibration timeout. The device cannot be used.\n");
+ return -ETIMEDOUT;
+ }
} while (cal_buf == DRV260X_GO_BIT);
return 0;