Skip to content

Commit c896ff2

Browse files
Alain Volmatwsakernel
authored andcommitted
i2c: stm32f7: Fix PEC handling in case of SMBUS transfers
In case of SMBUS byte read with PEC enabled, the whole transfer is split into two commands. A first write command, followed by a read command. The write command does not have any PEC byte and a PEC byte is appended at the end of the read command. (cf Read byte protocol with PEC in SMBUS specification) Within the STM32 I2C controller, handling (either sending or receiving) of the PEC byte is done via the PECBYTE bit in register CR2. Currently, the PECBYTE is set at the beginning of a transfer, which lead to sending a PEC byte at the end of the write command (hence losing the real last byte), and also does not check the PEC byte received during the read command. This patch corrects the function stm32f7_i2c_smbus_xfer_msg in order to only set the PECBYTE during the read command. Fixes: 9e48155 ("i2c: i2c-stm32f7: Add initial SMBus protocols support") Signed-off-by: Alain Volmat <[email protected]> Reviewed-by: Pierre-Yves MORDRET <[email protected]> Acked-by: Andi Shyti <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 3dc0ec4 commit c896ff2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/i2c/busses/i2c-stm32f7.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,9 +1059,10 @@ static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
10591059
/* Configure PEC */
10601060
if ((flags & I2C_CLIENT_PEC) && f7_msg->size != I2C_SMBUS_QUICK) {
10611061
cr1 |= STM32F7_I2C_CR1_PECEN;
1062-
cr2 |= STM32F7_I2C_CR2_PECBYTE;
1063-
if (!f7_msg->read_write)
1062+
if (!f7_msg->read_write) {
1063+
cr2 |= STM32F7_I2C_CR2_PECBYTE;
10641064
f7_msg->count++;
1065+
}
10651066
} else {
10661067
cr1 &= ~STM32F7_I2C_CR1_PECEN;
10671068
cr2 &= ~STM32F7_I2C_CR2_PECBYTE;
@@ -1149,8 +1150,10 @@ static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev)
11491150
f7_msg->stop = true;
11501151

11511152
/* Add one byte for PEC if needed */
1152-
if (cr1 & STM32F7_I2C_CR1_PECEN)
1153+
if (cr1 & STM32F7_I2C_CR1_PECEN) {
1154+
cr2 |= STM32F7_I2C_CR2_PECBYTE;
11531155
f7_msg->count++;
1156+
}
11541157

11551158
/* Set number of bytes to be transferred */
11561159
cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK);

0 commit comments

Comments
 (0)