Skip to contentSkip to conversation

i2c: stm32f7: fix clearing the control register

PATCH Superseded Jorge Ramirez-Ortiz 2 participants 3 messages Aug 15, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 i2c: stm32f7: fix clearing the control register

Bits should be set to 0, not 1.

---
 drivers/i2c/stm32f7_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/stm32f7_i2c.c +1 -1
index bf2a6c9b4b..3a727e68ac 100644
@@ -413,7 +413,7 @@ static int stm32_i2c_check_end_of_message(struct stm32_i2c_priv *i2c_priv)
 		setbits_le32(&regs->icr, STM32_I2C_ICR_STOPCF);
 
 		/* Clear control register 2 */
-		setbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
+		clrbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
 	}
 
 	return ret;
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 i2c: stm32f7: do not set the STOP condition on error

Sending the stop condition without waiting for TC has been found to lock the bus.

Tested accessing the the NXP SE05X I2C device.

---
 drivers/i2c/stm32f7_i2c.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/i2c/stm32f7_i2c.c +5 -3
index 3a727e68ac..14827e5cec 100644
@@ -485,9 +485,11 @@ 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(&regs->cr2, mask);
+	if (!ret) {
+		/* End of transfer, send stop condition */
+		mask = STM32_I2C_CR2_STOP;
+		setbits_le32(&regs->cr2, mask);
+	}
 
 	return stm32_i2c_check_end_of_message(i2c_priv);
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] i2c: stm32f7: do not set the STOP condition on error

Jorge,

Quoted 5 lines · Jorge Ramirez-Ortiz

Sending the stop condition without waiting for TC has been found to lock the bus.

Tested accessing the the NXP SE05X I2C device.

"the the" seems like a typo.

With this,

Quoted 27 lines
---
 drivers/i2c/stm32f7_i2c.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/i2c/stm32f7_i2c.c +5 -4
index 3a727e68ac..14827e5cec 100644
@@ -485,9 +485,11 @@ 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(&regs->cr2, mask);
+       if (!ret) {
+               /* End of transfer, send stop condition */
+               mask = STM32_I2C_CR2_STOP;
+               setbits_le32(&regs->cr2, mask);
+       }
 
        return stm32_i2c_check_end_of_message(i2c_priv);
 }
--

2.34.1

Signature · 5 lines
Best regards
Oleksandr

Oleksandr Suvorov
[email protected]