Skip to content

Commit 1f840c4

Browse files
robhancocksedgregkh
authored andcommitted
i2c: xiic: Try re-initialization on bus busy timeout
commit 1d4a1ad upstream. In the event that the I2C bus was powered down when the I2C controller driver loads, or some spurious pulses occur on the I2C bus, it's possible that the controller detects a spurious I2C "start" condition. In this situation it may continue to report the bus is busy indefinitely and block the controller from working. The "single-master" DT flag can be specified to disable bus busy checks entirely, but this may not be safe to use in situations where other I2C masters may potentially exist. In the event that the controller reports "bus busy" for too long when starting a transaction, we can try reinitializing the controller to see if the busy condition clears. This allows recovering from this scenario. Fixes: e1d5b65 ("i2c: Add support for Xilinx XPS IIC Bus Interface") Signed-off-by: Robert Hancock <robert.hancock@calian.com> Cc: <stable@vger.kernel.org> # v2.6.34+ Reviewed-by: Manikanta Guntupalli <manikanta.guntupalli@amd.com> Acked-by: Michal Simek <michal.simek@amd.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ba6e639 commit 1f840c4

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

drivers/i2c/busses/i2c-xiic.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -844,23 +844,11 @@ static int xiic_bus_busy(struct xiic_i2c *i2c)
844844
return (sr & XIIC_SR_BUS_BUSY_MASK) ? -EBUSY : 0;
845845
}
846846

847-
static int xiic_busy(struct xiic_i2c *i2c)
847+
static int xiic_wait_not_busy(struct xiic_i2c *i2c)
848848
{
849849
int tries = 3;
850850
int err;
851851

852-
if (i2c->tx_msg || i2c->rx_msg)
853-
return -EBUSY;
854-
855-
/* In single master mode bus can only be busy, when in use by this
856-
* driver. If the register indicates bus being busy for some reason we
857-
* should ignore it, since bus will never be released and i2c will be
858-
* stuck forever.
859-
*/
860-
if (i2c->singlemaster) {
861-
return 0;
862-
}
863-
864852
/* for instance if previous transfer was terminated due to TX error
865853
* it might be that the bus is on it's way to become available
866854
* give it at most 3 ms to wake
@@ -1104,13 +1092,36 @@ static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num)
11041092

11051093
mutex_lock(&i2c->lock);
11061094

1107-
ret = xiic_busy(i2c);
1108-
if (ret) {
1095+
if (i2c->tx_msg || i2c->rx_msg) {
11091096
dev_err(i2c->adap.dev.parent,
11101097
"cannot start a transfer while busy\n");
1098+
ret = -EBUSY;
11111099
goto out;
11121100
}
11131101

1102+
/* In single master mode bus can only be busy, when in use by this
1103+
* driver. If the register indicates bus being busy for some reason we
1104+
* should ignore it, since bus will never be released and i2c will be
1105+
* stuck forever.
1106+
*/
1107+
if (!i2c->singlemaster) {
1108+
ret = xiic_wait_not_busy(i2c);
1109+
if (ret) {
1110+
/* If the bus is stuck in a busy state, such as due to spurious low
1111+
* pulses on the bus causing a false start condition to be detected,
1112+
* then try to recover by re-initializing the controller and check
1113+
* again if the bus is still busy.
1114+
*/
1115+
dev_warn(i2c->adap.dev.parent, "I2C bus busy timeout, reinitializing\n");
1116+
ret = xiic_reinit(i2c);
1117+
if (ret)
1118+
goto out;
1119+
ret = xiic_wait_not_busy(i2c);
1120+
if (ret)
1121+
goto out;
1122+
}
1123+
}
1124+
11141125
i2c->tx_msg = msgs;
11151126
i2c->rx_msg = NULL;
11161127
i2c->nmsgs = num;

0 commit comments

Comments
 (0)