Skip to contentSkip to conversation

i2c: busses: i2c-cadence: fix message length when receive block message

PATCH Superseded Adam Wujek 2 participants 3 messages May 19, 2022 – May 24, 2022

Subsystems (2)
lore
Share & tools
lore

Adam Wujek

author
#0 lore raw

PATCH 1/1 i2c: busses: i2c-cadence: fix message length when receive block message

Needed by hwmon/pmbus_core driver to correctly calculate PEC.
The hwmon/pmbus_core driver relies on bus drivers to update the message length of received block transfers. Only in this type of smbus transfer, in which the length is not known before the transfer is started.

---
 drivers/i2c/busses/i2c-cadence.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/i2c/busses/i2c-cadence.c +5 -0
index 20ac432a37ea..65f1979d4e6f 100644
@@ -830,6 +830,11 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
 		return -ETIMEDOUT;
 	}
 
+	/* Update message len, as i2c/smbus driver (function
+	 * i2c_smbus_xfer_emulated) relies on i2c device drivers to do this */
+	if ((msg->flags & I2C_M_RECV_LEN) && (msg->flags & I2C_M_RD))
+		msg->len = msg->buf[0] + 2; /* add len byte + PEC byte */
+
 	cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
 			  CDNS_I2C_IDR_OFFSET);
 

--
2.17.1

author
#1 lore raw

PATCH v2 1/1 i2c: busses: i2c-cadence: fix message length when receive block message

Needed by hwmon/pmbus_core driver to calculate PEC correctly. The hwmon/pmbus_core driver relies on bus drivers to update the message length of receive block transfers. Only in this type of smbus transfer the length is not known before the transfer is started.

---
Notes:
Changes in v2:
- fix multiline comment

 drivers/i2c/busses/i2c-cadence.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/i2c/busses/i2c-cadence.c +7 -0
index 805c77143a0f..a679eb390ef5 100644
@@ -794,6 +794,13 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
 		return -ETIMEDOUT;
 	}
 
+	/*
+	 * Update message len, as i2c/smbus driver (function
+	 * i2c_smbus_xfer_emulated) relies on i2c device drivers to do this.
+	 */
+	if ((msg->flags & I2C_M_RECV_LEN) && (msg->flags & I2C_M_RD))
+		msg->len = msg->buf[0] + 2; /* add len byte + PEC byte */
+
 	cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
 			  CDNS_I2C_IDR_OFFSET);
 

--
2.17.1

#2 lore raw
Quoted 33 lines · Adam Wujek

Needed by hwmon/pmbus_core driver to calculate PEC correctly. The hwmon/pmbus_core driver relies on bus drivers to update the message length of receive block transfers. Only in this type of smbus transfer the length is not known before the transfer is started.

---
Notes:
Changes in v2:
- fix multiline comment

  drivers/i2c/busses/i2c-cadence.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/i2c/busses/i2c-cadence.c +7 -1
index 805c77143a0f..a679eb390ef5 100644
@@ -794,6 +794,13 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
  		return -ETIMEDOUT;
  	}
 
+	/*
+	 * Update message len, as i2c/smbus driver (function
+	 * i2c_smbus_xfer_emulated) relies on i2c device drivers to do this.
+	 */
+	if ((msg->flags & I2C_M_RECV_LEN) && (msg->flags & I2C_M_RD))
+		msg->len = msg->buf[0] + 2; /* add len byte + PEC byte */
+
  	cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
  			  CDNS_I2C_IDR_OFFSET);
 
--
Quoted 3 lines

2.17.1

Shubhrajyoti: Can you please test it?

Thanks,
Michal