i2c: designware: Get right data length
Subsystems (3)
PATCH 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 right data length.
--- drivers/i2c/busses/i2c-designware-master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-master.c +1 -1
@@ -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 &0xff ) <=I2C_SMBUS_BLOCK_MAX && tmp >0 ) { len =i2c_dw_recv_len (dev, tmp); } *buf++ = tmp;
Signature · 1 line
2.19.1.6.gb485710b
Andy Shevchenko
reviewerQuoted 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 right data length.
Thanks for the report and fix!
My comments below.
Quoted 10 lines
Signed-off-by Liguang Zhang <[email protected]>--- drivers/i2c/busses/i2c-designware-master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/busses/i2c-designware-master.c +0
-0
drivers/i2c/busses/i2c-designware-master.c i2c_dw_read(struct dw_i2c_dev *dev) · line 435
Quoted 5 lines
drivers/i2c/busses/i2c-designware-master.c +1
-1@@ -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 &0xff ) <=I2C_SMBUS_BLOCK_MAX && tmp >0 ) {
Can we rather describe this as
#define DW_IC_DATA_CMD_DAT GENMASK(7, 0)
in *.h file and...
(tmp & DW_IC_DATA_CMD_DAT) <= I2C_SMBUS_BLOCK_MAX && tmp > 0) {...here?
Quoted 6 lines
drivers/i2c/busses/i2c-designware-master.c +0
-0len =i2c_dw_recv_len (dev, tmp); } *buf++ = tmp;Signature · 1 line
2.19.1.6.gb485710b
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 8 lines · Andy Shevchenko
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 right data length.
Thanks for the report and fix!
My comments below.
Thanks for your comments. I will optimize my code follow your comments and send v2 revision.
Regards,
Liguang
Quoted 31 lines
Quoted 11 lines
Signed-off-by Liguang Zhang <[email protected]>--- drivers/i2c/busses/i2c-designware-master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/busses/i2c-designware-master.c +0
-0drivers/i2c/busses/i2c-designware-master.c i2c_dw_read(struct dw_i2c_dev *dev) · line 435
Quoted 5 lines
drivers/i2c/busses/i2c-designware-master.c +1
-1@@ -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 &0xff ) <=I2C_SMBUS_BLOCK_MAX && tmp >0 ) {Can we rather describe this as
#define
DW_IC_DATA_CMD_DATGENMASK(7, 0)in *.h file and...
(tmp & DW_IC_DATA_CMD_DAT) <= I2C_SMBUS_BLOCK_MAX && tmp > 0) {...here?
Quoted 6 lines
drivers/i2c/busses/i2c-designware-master.c +0
-0len =i2c_dw_recv_len (dev, tmp); } *buf++ = tmp;Signature · 1 line
2.19.1.6.gb485710b