Skip to contentSkip to conversation

i2c: designware: Get right data length

PATCH Applied Liguang Zhang 3 participants 3 messages Feb 25, 2021 – Feb 26, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: designware: Get right data length

IC_DATA_CMD[11] indicates the first data byte received after the address phase for receive transfer in Master receiver or Slave receiver mode, this bit was set in some transfer flow. IC_DATA_CMD[7:0] contains the data to be transmitted or received on the I2C bus, so we should use the lower 8 bits to get the real data length.

---
 drivers/i2c/busses/i2c-designware-core.h   | 2 ++
 drivers/i2c/busses/i2c-designware-master.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-core.h +2 -0
index 85307cfa7109..5392b82f68a4 100644
@@ -38,6 +38,8 @@
 #define DW_IC_CON_TX_EMPTY_CTRL			BIT(8)
 #define DW_IC_CON_RX_FIFO_FULL_HLD_CTRL		BIT(9)
 
+#define DW_IC_DATA_CMD_DAT			GENMASK(7, 0)
+
 /*
  * Registers offset
  */
drivers/i2c/busses/i2c-designware-master.c +1 -1
index d6425ad6e6a3..dd27b9dbe931 100644
@@ -432,7 +432,7 @@ i2c_dw_read(struct dw_i2c_dev *dev)
 			regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
 			/* Ensure length byte is a valid value */
 			if (flags & I2C_M_RECV_LEN &&
-			    tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) {
+			    (tmp & DW_IC_DATA_CMD_DAT) <= I2C_SMBUS_BLOCK_MAX && tmp > 0) {
 				len = i2c_dw_recv_len(dev, tmp);
 			}
 			*buf++ = tmp;
Signature · 1 line
2.19.1.6.gb485710b
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Liguang Zhang

IC_DATA_CMD[11] indicates the first data byte received after the address phase for receive transfer in Master receiver or Slave receiver mode, this bit was set in some transfer flow. IC_DATA_CMD[7:0] contains the data to be transmitted or received on the I2C bus, so we should use the lower 8 bits to get the real data length.

Quoted 35 lines
---
 drivers/i2c/busses/i2c-designware-core.h   | 2 ++
 drivers/i2c/busses/i2c-designware-master.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-core.h +2 -0
index 85307cfa7109..5392b82f68a4 100644
@@ -38,6 +38,8 @@
 #define DW_IC_CON_TX_EMPTY_CTRL			BIT(8)
 #define DW_IC_CON_RX_FIFO_FULL_HLD_CTRL		BIT(9)
 
+#define DW_IC_DATA_CMD_DAT			GENMASK(7, 0)
+
 /*
  * Registers offset
  */
drivers/i2c/busses/i2c-designware-master.c +1 -1
index d6425ad6e6a3..dd27b9dbe931 100644
@@ -432,7 +432,7 @@ i2c_dw_read(struct dw_i2c_dev *dev)
 			regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
 			/* Ensure length byte is a valid value */
 			if (flags & I2C_M_RECV_LEN &&
-			    tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) {
+			    (tmp & DW_IC_DATA_CMD_DAT) <= I2C_SMBUS_BLOCK_MAX && tmp > 0) {
 				len = i2c_dw_recv_len(dev, tmp);
 			}
 			*buf++ = tmp;
Signature · 1 line
2.19.1.6.gb485710b
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Applied
#2 lore raw
In reply to Liguang Zhang
Quoted 7 lines · Liguang Zhang

IC_DATA_CMD[11] indicates the first data byte received after the address phase for receive transfer in Master receiver or Slave receiver mode, this bit was set in some transfer flow. IC_DATA_CMD[7:0] contains the data to be transmitted or received on the I2C bus, so we should use the lower 8 bits to get the real data length.

Applied to for-current, thanks!