[PATCH v7 11/11] i2c: cgbc: Fetch the status of a write transfer

From: Thomas Richard (congatec GmbH)

Date: Fri Nov 27 2026 - 12:58:50 EST


From: Markus Haberlander <markus.haberlander@xxxxxxxxxxxxxxx>

A write transfer sends the I2C command to the board controller and
returns without reading the controller's I2C status, while a read polls
the status until the controller is no longer busy. The status of a write
is therefore never fetched:

- the write reports success before the bus transfer has finished, and
an error such as a NAK is only reported by the next transfer;
- the controller keeps the status of the last write pending. On a
conga-PA7 (BIOS PA70R026, board controller CGBCP032), a board reset
with a write status pending does not power the board up again: after
a reboot that follows a write on the general purpose bus, the board
stays off until it is power cycled.

Read the status after a write as well, as the read path does: poll until
the controller is no longer busy, return the error it reports, and treat
any state other than idle as an error.

Tested on a conga-PA7 with v6.18.64 and "i2c: cgbc: Propagate hardware
errors when polling read status": without this patch, a write to an
absent address returns success, the next read fails, and a reboot after
a write does not come back. With it, the write itself fails, the next
transfer succeeds, and 14 reboots, each right after an acknowledged or a
NAKed write, all came back.

The patch and this changelog were drafted with the help of Claude
Opus 5.5 and reviewed and tested by me.

Fixes: 6894f640b8f3 ("i2c: Congatec Board Controller i2c bus driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Markus Haberlander <markus.haberlander@xxxxxxxxxxxxxxx>
Reviewed-by: Thomas Richard (congatec GmbH) <thomas.richard@xxxxxxxxxxx>
Tested-by: Thomas Richard (congatec GmbH) <thomas.richard@xxxxxxxxxxx>
[Thomas: Use USEC_PER_SEC]
Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@xxxxxxxxxxx>
---
drivers/i2c/busses/i2c-cgbc.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c
index 5105b920e919..852fcb9e21fa 100644
--- a/drivers/i2c/busses/i2c-cgbc.c
+++ b/drivers/i2c/busses/i2c-cgbc.c
@@ -255,6 +255,22 @@ static int cgbc_i2c_xfer_msg(struct i2c_adapter *adap)
ret = cgbc_command(cgbc, &cmd, cmd_len, NULL, 0, NULL);
if (ret)
goto err;
+
+ ret = read_poll_timeout(cgbc_i2c_get_status, status,
+ status != CGBC_I2C_STAT_BUSY, 0,
+ USEC_PER_SEC, false, adap);
+ if (ret)
+ goto err;
+
+ if (status < 0) {
+ ret = status;
+ goto err;
+ }
+
+ if (status != CGBC_I2C_STAT_IDL) {
+ ret = -EIO;
+ goto err;
+ }
} else if (i2c->state == CGBC_I2C_STATE_READ) {
xfer.write = 0;
xfer.read = len;

--
2.53.0