Skip to contentSkip to conversation

i2c: i2c_cdns: fix write timeout on fifo boundary

PATCH New Michael Auchter 3 participants 4 messages Dec 9, 2019 – Dec 11, 2019 I2C

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: i2c_cdns: fix write timeout on fifo boundary

This fixes an issue that would cause I2C writes to timeout when the number of bytes is a multiple of the FIFO depth (i.e. 16 bytes).

Within the transfer loop, after writing the data register with a new byte to transfer, if the transfer size equals the FIFO depth, the loop pauses until the INTERRUPT_COMP bit asserts to indicate data has been sent. This same check is performed after the loop as well to ensure data has been transferred prior to returning.

In the case where the amount of data to be written is a multiple of the FIFO depth, the transfer loop would wait for the INTERRUPT_COMP bit to assert after writing the final byte, and then wait for this bit to assert once more. However, since the transfer has finished at this point, no new data has been written to the data register, and hence INTERRUPT_COMP will never assert.

Fix this by only waiting for INTERRUPT_COMP in the transfer loop if there's still data to be written.

---
 drivers/i2c/i2c-cdns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-cdns.c +1 -1
index 2c0301ad08..ff3956d8c2 100644
@@ -265,7 +265,7 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 
 	while (len-- && !is_arbitration_lost(regs)) {
 		writel(*(cur_data++), &regs->data);
-		if (readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
+		if (len && readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
 			ret = cdns_i2c_wait(regs, CDNS_I2C_INTERRUPT_COMP |
 					    CDNS_I2C_INTERRUPT_ARBLOST);
 			if (ret & CDNS_I2C_INTERRUPT_ARBLOST)
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/1 i2c: i2c_cdns: fix write timeout on fifo boundary

Quoted 39 lines · Michael Auchter

This fixes an issue that would cause I2C writes to timeout when the number of bytes is a multiple of the FIFO depth (i.e. 16 bytes).

Within the transfer loop, after writing the data register with a new byte to transfer, if the transfer size equals the FIFO depth, the loop pauses until the INTERRUPT_COMP bit asserts to indicate data has been sent. This same check is performed after the loop as well to ensure data has been transferred prior to returning.

In the case where the amount of data to be written is a multiple of the FIFO depth, the transfer loop would wait for the INTERRUPT_COMP bit to assert after writing the final byte, and then wait for this bit to assert once more. However, since the transfer has finished at this point, no new data has been written to the data register, and hence INTERRUPT_COMP will never assert.

Fix this by only waiting for INTERRUPT_COMP in the transfer loop if there's still data to be written.

---
 drivers/i2c/i2c-cdns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-cdns.c +1 -2
index 2c0301ad08..ff3956d8c2 100644
@@ -265,7 +265,7 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 
        while (len-- && !is_arbitration_lost(regs)) {
                writel(*(cur_data++), &regs->data);
-               if (readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
+               if (len && readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
                        ret = cdns_i2c_wait(regs, CDNS_I2C_INTERRUPT_COMP |
                                            CDNS_I2C_INTERRUPT_ARBLOST);
                        if (ret & CDNS_I2C_INTERRUPT_ARBLOST)
--
Quoted 2 lines

2.23.0

#2 lore raw

PATCH 1/1 i2c: i2c_cdns: fix write timeout on fifo boundary

In reply to Michael Auchter

Hello Michael,

Am 09.12.2019 um 19:16 schrieb Michael Auchter:

Quoted 30 lines

This fixes an issue that would cause I2C writes to timeout when the number of bytes is a multiple of the FIFO depth (i.e. 16 bytes).

Within the transfer loop, after writing the data register with a new byte to transfer, if the transfer size equals the FIFO depth, the loop pauses until the INTERRUPT_COMP bit asserts to indicate data has been sent. This same check is performed after the loop as well to ensure data has been transferred prior to returning.

In the case where the amount of data to be written is a multiple of the FIFO depth, the transfer loop would wait for the INTERRUPT_COMP bit to assert after writing the final byte, and then wait for this bit to assert once more. However, since the transfer has finished at this point, no new data has been written to the data register, and hence INTERRUPT_COMP will never assert.

Fix this by only waiting for INTERRUPT_COMP in the transfer loop if there's still data to be written.

---
  drivers/i2c/i2c-cdns.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-cdns.c +0 -0
index 2c0301ad08..ff3956d8c2 100644

drivers/i2c/i2c-cdns.c static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data, · line 271

Quoted 8 lines
drivers/i2c/i2c-cdns.c +1 -1
@@ -265,7 +265,7 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 
  	while (len-- && !is_arbitration_lost(regs)) {
  		writel(*(cur_data++), &regs->data);
-		if (readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
+		if (len && readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
  			ret = cdns_i2c_wait(regs, CDNS_I2C_INTERRUPT_COMP |
  					    CDNS_I2C_INTERRUPT_ARBLOST);
  			if (ret & CDNS_I2C_INTERRUPT_ARBLOST)

Thanks for detecting this!

I soon send a pull request for Tom, if travis build is fine.

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#3 lore raw

PATCH 1/1 i2c: i2c_cdns: fix write timeout on fifo boundary

In reply to Michael Auchter

Hello Michael,

Am 09.12.2019 um 19:16 schrieb Michael Auchter:

Quoted 16 lines

This fixes an issue that would cause I2C writes to timeout when the number of bytes is a multiple of the FIFO depth (i.e. 16 bytes).

Within the transfer loop, after writing the data register with a new byte to transfer, if the transfer size equals the FIFO depth, the loop pauses until the INTERRUPT_COMP bit asserts to indicate data has been sent. This same check is performed after the loop as well to ensure data has been transferred prior to returning.

In the case where the amount of data to be written is a multiple of the FIFO depth, the transfer loop would wait for the INTERRUPT_COMP bit to assert after writing the final byte, and then wait for this bit to assert once more. However, since the transfer has finished at this point, no new data has been written to the data register, and hence INTERRUPT_COMP will never assert.

Quoted 7 lines

Fix this by only waiting for INTERRUPT_COMP in the transfer loop if there's still data to be written.

---
  drivers/i2c/i2c-cdns.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks!

Applied to u-boot-i2c master

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de