Message ID | 20220912084201.1826979-4-alain.volmat@foss.st.com |
---|---|
State | Accepted |
Commit | 3bf699f7a8c650372b8d7e8ff4332a54e3a4fffa |
Delegated to: | Patrick Delaunay |
Headers | show |
Series | i2c: stm32: cleanup & stop handling fix | expand |
Hi Alain On 9/12/22 10:42, Alain Volmat wrote: > Current function stm32_i2c_message_xfer is sending a STOP > whatever the result of the transaction is. This can cause issues > such as making the bus busy since the controller itself is already > sending automatically a STOP when a NACK is generated. > > Thanks to Jorge Ramirez-Ortiz for diagnosing and proposing a first > fix for this. [1] > > [1] https://lore.kernel.org/u-boot/20220815145211.31342-2-jorge@foundries.io/ > > Reported-by: Jorge Ramirez-Ortiz, Foundries <jorge@foundries.io> > Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io> > Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> > --- > drivers/i2c/stm32f7_i2c.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/i2c/stm32f7_i2c.c b/drivers/i2c/stm32f7_i2c.c > index 0ec67b5c12..2db7f44d44 100644 > --- a/drivers/i2c/stm32f7_i2c.c > +++ b/drivers/i2c/stm32f7_i2c.c > @@ -483,9 +483,9 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv, > } > } > > - /* End of transfer, send stop condition */ > - mask = STM32_I2C_CR2_STOP; > - setbits_le32(®s->cr2, mask); > + /* End of transfer, send stop condition if appropriate */ > + if (!ret && !(status & (STM32_I2C_ISR_NACKF | STM32_I2C_ISR_ERRORS))) > + setbits_le32(®s->cr2, STM32_I2C_CR2_STOP); > > return stm32_i2c_check_end_of_message(i2c_priv); > } Applied to u-boot-stm/master, thanks! I also add the missing Reviewed-by when I get the patch from patchwork http://patchwork.ozlabs.org/project/uboot/patch/20220912084201.1826979-4-alain.volmat@foss.st.com/ + Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com> + Reviewed-by: Heiko Schocher <hs@denx.de> + Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com> + Tested-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Regards Patrick
Hi Alain, On 9/12/22 10:42, Alain Volmat wrote: > Current function stm32_i2c_message_xfer is sending a STOP > whatever the result of the transaction is. This can cause issues > such as making the bus busy since the controller itself is already > sending automatically a STOP when a NACK is generated. > > Thanks to Jorge Ramirez-Ortiz for diagnosing and proposing a first > fix for this. [1] > > [1] https://lore.kernel.org/u-boot/20220815145211.31342-2-jorge@foundries.io/ > > Reported-by: Jorge Ramirez-Ortiz, Foundries <jorge@foundries.io> > Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io> > Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> > --- > drivers/i2c/stm32f7_i2c.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/i2c/stm32f7_i2c.c b/drivers/i2c/stm32f7_i2c.c > index 0ec67b5c12..2db7f44d44 100644 > --- a/drivers/i2c/stm32f7_i2c.c > +++ b/drivers/i2c/stm32f7_i2c.c > @@ -483,9 +483,9 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv, > } > } > > - /* End of transfer, send stop condition */ > - mask = STM32_I2C_CR2_STOP; > - setbits_le32(®s->cr2, mask); > + /* End of transfer, send stop condition if appropriate */ > + if (!ret && !(status & (STM32_I2C_ISR_NACKF | STM32_I2C_ISR_ERRORS))) > + setbits_le32(®s->cr2, STM32_I2C_CR2_STOP); > > return stm32_i2c_check_end_of_message(i2c_priv); > } Applied to u-boot-stm/master, thanks! I also add the missing Reviewed-by when I get the patch from patchwork http://patchwork.ozlabs.org/project/uboot/patch/20220912084201.1826979-5-alain.volmat@foss.st.com/ + Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com> + Reviewed-by: Heiko Schocher <hs@denx.de> + Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com> + Tested-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Regards Patrick
diff --git a/drivers/i2c/stm32f7_i2c.c b/drivers/i2c/stm32f7_i2c.c index 0ec67b5c12..2db7f44d44 100644 --- a/drivers/i2c/stm32f7_i2c.c +++ b/drivers/i2c/stm32f7_i2c.c @@ -483,9 +483,9 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv, } } - /* End of transfer, send stop condition */ - mask = STM32_I2C_CR2_STOP; - setbits_le32(®s->cr2, mask); + /* End of transfer, send stop condition if appropriate */ + if (!ret && !(status & (STM32_I2C_ISR_NACKF | STM32_I2C_ISR_ERRORS))) + setbits_le32(®s->cr2, STM32_I2C_CR2_STOP); return stm32_i2c_check_end_of_message(i2c_priv); }