Skip to content

Commit 0c21d02

Browse files
Alain Volmatwsakernel
authored andcommitted
i2c: stm32f7: flush TX FIFO upon transfer errors
While handling an error during transfer (ex: NACK), it could happen that the driver has already written data into TXDR before the transfer get stopped. This commit add TXDR Flush after end of transfer in case of error to avoid sending a wrong data on any other slave upon next transfer. Fixes: aeb068c ("i2c: i2c-stm32f7: add driver") Signed-off-by: Alain Volmat <[email protected]> Reviewed-by: Pierre-Yves MORDRET <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent b127646 commit 0c21d02

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

drivers/i2c/busses/i2c-stm32f7.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,16 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
16961696
time_left = wait_for_completion_timeout(&i2c_dev->complete,
16971697
i2c_dev->adap.timeout);
16981698
ret = f7_msg->result;
1699+
if (ret) {
1700+
/*
1701+
* It is possible that some unsent data have already been
1702+
* written into TXDR. To avoid sending old data in a
1703+
* further transfer, flush TXDR in case of any error
1704+
*/
1705+
writel_relaxed(STM32F7_I2C_ISR_TXE,
1706+
i2c_dev->base + STM32F7_I2C_ISR);
1707+
goto pm_free;
1708+
}
16991709

17001710
if (!time_left) {
17011711
dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n",
@@ -1744,8 +1754,16 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
17441754
timeout = wait_for_completion_timeout(&i2c_dev->complete,
17451755
i2c_dev->adap.timeout);
17461756
ret = f7_msg->result;
1747-
if (ret)
1757+
if (ret) {
1758+
/*
1759+
* It is possible that some unsent data have already been
1760+
* written into TXDR. To avoid sending old data in a
1761+
* further transfer, flush TXDR in case of any error
1762+
*/
1763+
writel_relaxed(STM32F7_I2C_ISR_TXE,
1764+
i2c_dev->base + STM32F7_I2C_ISR);
17481765
goto pm_free;
1766+
}
17491767

17501768
if (!timeout) {
17511769
dev_dbg(dev, "Access to slave 0x%x timed out\n", f7_msg->addr);

0 commit comments

Comments
 (0)