[PATCH v2 2/2] i2c: qcom-cci: Retry a timed-out first message after resetting
From: Birk Skyum via B4 Relay
Date: Tue Dec 01 2026 - 12:22:39 EST
From: Birk Skyum <birk.skyum@xxxxx>
With the 1 s runtime autosuspend delay, the CCI controller stays clocked
across any target power cycle shorter than a second, so
cci_resume_runtime() does not run in between and the first transfer
after the target powers back on stalls until cci_run_queue() times out
after 100 ms and resets the controller.
Return -EIO from cci_run_queue() if the recovery cci_reset() itself
fails, and retry the first message of an i2c_transfer() once in
cci_xfer() when it returns -ETIMEDOUT. Restricting the retry to the
first message avoids re-running a partial multi-message transaction
after a controller reset while recovering cleanly from the stuck-master
stall without altering autosuspend timing.
On the Lenovo Yoga Slim 7x (X1E80100) running Linux 7.3 with SCL
stretching enabled and the 1 s autosuspend delay unchanged, restarting
the OV02C10 camera with v4l2-ctl across 120 cycles (20 cycles each
after 0.05, 0.1, 0.2, 0.5, 1, and 2 s pauses) succeeded in 120 of 120
runs (91 hit the initial stall and every retry went through).
Signed-off-by: Birk Skyum <birk.skyum@xxxxx>
---
drivers/i2c/busses/i2c-qcom-cci.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index fff817408..d308798d2 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -403,7 +403,8 @@ static int cci_run_queue(struct cci *cci, u8 master, u8 queue)
CCI_TIMEOUT)) {
dev_err(cci->dev, "master %d queue %d timeout\n",
master, queue);
- cci_reset(cci);
+ if (cci_reset(cci))
+ return -EIO;
return -ETIMEDOUT;
}
@@ -518,6 +519,15 @@ static int cci_i2c_write(struct cci *cci, u16 master,
return cci_run_queue(cci, master, queue);
}
+static int cci_xfer_msg(struct cci *cci, u16 master, struct i2c_msg *msg)
+{
+ if (msg->flags & I2C_M_RD)
+ return cci_i2c_read(cci, master, msg->addr, msg->buf,
+ msg->len);
+
+ return cci_i2c_write(cci, master, msg->addr, msg->buf, msg->len);
+}
+
static int cci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
{
struct cci_master *cci_master = i2c_get_adapdata(adap);
@@ -529,14 +539,14 @@ static int cci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
goto err;
for (i = 0; i < num; i++) {
- if (msgs[i].flags & I2C_M_RD)
- ret = cci_i2c_read(cci, cci_master->master,
- msgs[i].addr, msgs[i].buf,
- msgs[i].len);
- else
- ret = cci_i2c_write(cci, cci_master->master,
- msgs[i].addr, msgs[i].buf,
- msgs[i].len);
+ ret = cci_xfer_msg(cci, cci_master->master, &msgs[i]);
+ /*
+ * A master can stall on the first transfer after a target was
+ * powered down while CCI stayed clocked. cci_run_queue() has
+ * already reset the controller on -ETIMEDOUT, so retry once.
+ */
+ if (ret == -ETIMEDOUT && i == 0)
+ ret = cci_xfer_msg(cci, cci_master->master, &msgs[i]);
if (ret < 0)
break;
--
2.56.0