Skip to content

Commit 06be672

Browse files
TaliPerrywsakernel
authored andcommitted
i2c: npcm7xx: Fix timeout calculation
timeout_usec value calculation was wrong, the calculated value was in msec instead of usec. Fixes: 56a1485 ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Tali Perry <[email protected]> Reviewed-by: Avi Fishman <[email protected]> Reviewed-by: Joel Stanley <[email protected]> Reviewed-by: Alex Qiu <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent f4d51df commit 06be672

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/i2c/busses/i2c-npcm7xx.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,8 +2093,12 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
20932093
}
20942094
}
20952095

2096-
/* Adaptive TimeOut: astimated time in usec + 100% margin */
2097-
timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
2096+
/*
2097+
* Adaptive TimeOut: estimated time in usec + 100% margin:
2098+
* 2: double the timeout for clock stretching case
2099+
* 9: bits per transaction (including the ack/nack)
2100+
*/
2101+
timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite);
20982102
timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
20992103
if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
21002104
dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);

0 commit comments

Comments
 (0)