Skip to content

Commit 288b204

Browse files
TaliPerrywsakernel
authored andcommitted
i2c: npcm: Fix timeout calculation
Use adap.timeout for timeout calculation instead of hard-coded value of 35ms. Fixes: 56a1485 ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Tali Perry <[email protected]> Signed-off-by: Tyrone Ting <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 94acda5 commit 288b204

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/i2c/busses/i2c-npcm7xx.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
20472047
u16 nwrite, nread;
20482048
u8 *write_data, *read_data;
20492049
u8 slave_addr;
2050-
int timeout;
2050+
unsigned long timeout;
20512051
int ret = 0;
20522052
bool read_block = false;
20532053
bool read_PEC = false;
@@ -2099,13 +2099,13 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
20992099
* 9: bits per transaction (including the ack/nack)
21002100
*/
21012101
timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite);
2102-
timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
2102+
timeout = max_t(unsigned long, bus->adap.timeout, usecs_to_jiffies(timeout_usec));
21032103
if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
21042104
dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);
21052105
return -EINVAL;
21062106
}
21072107

2108-
time_left = jiffies + msecs_to_jiffies(DEFAULT_STALL_COUNT) + 1;
2108+
time_left = jiffies + timeout + 1;
21092109
do {
21102110
/*
21112111
* we must clear slave address immediately when the bus is not
@@ -2268,7 +2268,7 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev)
22682268
adap = &bus->adap;
22692269
adap->owner = THIS_MODULE;
22702270
adap->retries = 3;
2271-
adap->timeout = HZ;
2271+
adap->timeout = msecs_to_jiffies(35);
22722272
adap->algo = &npcm_i2c_algo;
22732273
adap->quirks = &npcm_i2c_quirks;
22742274
adap->algo_data = bus;

0 commit comments

Comments
 (0)