i2c: stm32f7: Fix zero-length transfers used by i2c probe
PATCH 1/1 i2c: stm32f7: Fix zero-length transfers used by i2c probe
From: Petar Krstov <[email protected]>
Zero-length messages (e.g. i2c probe) skip the data loop entirely, so the driver never waits for the address phase to complete before handling STOP/NACK. Add an explicit wait for TC/NACKF/errors in the zero-length case and initialize status to avoid using it uninitialized.
---
Cc: Heiko Schocher <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- drivers/i2c/stm32f7_i2c.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/i2c/stm32f7_i2c.c +16 -1
@@ -420,7 +420,7 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv, struct i2c_msg *msg, bool stop) {struct stm32_i2c_regs *regs = i2c_priv->regs; -u32 status; +u32 status =0 ;u32 mask = msg->flags &I2C_M_RD ?STM32_I2C_ISR_RXNE :STM32_I2C_ISR_TXIS |STM32_I2C_ISR_NACKF ; int bytes_to_rw = msg->len > STM32_I2C_MAX_LEN ?
@@ -432,6 +432,21 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv,stm32_i2c_message_start (i2c_priv, msg); +/* +* Zero-length message (e.g. i2c probe): no data phase, so wait for +* the address phase to finish (TC on ACK, NACKF on NACK) before +* deciding whether to send a STOP. +*/ +if (!msg->len) { + ret =stm32_i2c_wait_flags (i2c_priv, +STM32_I2C_ISR_TC | +STM32_I2C_ISR_NACKF | +STM32_I2C_ISR_ERRORS , + &status); +if (!ret && !stop && (status &STM32_I2C_ISR_TC )) +return 0 ; + } +while (msg->len) {/* * Wait until TXIS/NACKF/BERR/ARLO flags or
Signature · 1 line
2.56.0
Hello Frieder,
Quoted 18 lines · Frieder Schrempf
From: Petar Krstov <[email protected]>
Zero-length messages (e.g. i2c probe) skip the data loop entirely, so the driver never waits for the address phase to complete before handling STOP/NACK. Add an explicit wait for TC/NACKF/errors in the zero-length case and initialize status to avoid using it uninitialized.
Fixes 3bf699f7a8c6 ("i2c: stm32: do not set the STOP condition on error")Signed-off-by Petar Krstov <[email protected]>Signed-off-by Frieder Schrempf <[email protected]>---
Cc: Heiko Schocher <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]
Quoted 3 lines
--- drivers/i2c/stm32f7_i2c.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
bye,
Heiko
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic