Skip to content

Commit 0836c80

Browse files
Alexander SteinWolfram Sang
authored andcommitted
i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time
If you insert several i2c transfers, the driver might start the next one while the STOP bit of the previous transfer is still on the bus, marking the bus as busy. pch_i2c_wait_for_bus_idle does an msleep(20) delaying the next transfer by >=20ms. Reduce wait time by actively waiting 5 us once, then using usleep_range. Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com> Acked-by: Tomoya MORINAGA <tomoya.rohm@gmail.com> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
1 parent c62c3ca commit 0836c80

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

‎drivers/i2c/busses/i2c-eg20t.c‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,30 +271,36 @@ static inline bool ktime_lt(const ktime_t cmp1, const ktime_t cmp2)
271271
/**
272272
* pch_i2c_wait_for_bus_idle() - check the status of bus.
273273
* @adap: Pointer to struct i2c_algo_pch_data.
274-
* @timeout: waiting time counter (us).
274+
* @timeout: waiting time counter (ms).
275275
*/
276276
static s32 pch_i2c_wait_for_bus_idle(struct i2c_algo_pch_data *adap,
277277
s32 timeout)
278278
{
279279
void __iomem *p = adap->pch_base_address;
280-
ktime_t ns_val;
280+
int schedule = 0;
281+
unsigned long end = jiffies + msecs_to_jiffies(timeout);
282+
283+
while (ioread32(p + PCH_I2CSR) & I2CMBB_BIT) {
284+
if (time_after(jiffies, end)) {
285+
pch_dbg(adap, "I2CSR = %x\n", ioread32(p + PCH_I2CSR));
286+
pch_err(adap, "%s: Timeout Error.return%d\n",
287+
__func__, -ETIME);
288+
pch_i2c_init(adap);
281289

282-
if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
283-
return 0;
290+
return -ETIME;
291+
}
284292

285-
/* MAX timeout value is timeout*1000*1000nsec */
286-
ns_val = ktime_add_ns(ktime_get(), timeout*1000*1000);
287-
do {
288-
msleep(20);
289-
if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
290-
return 0;
291-
} while (ktime_lt(ktime_get(), ns_val));
293+
if (!schedule)
294+
/* Retry after some usecs */
295+
udelay(5);
296+
else
297+
/* Wait a bit more without consuming CPU */
298+
usleep_range(20, 1000);
292299

293-
pch_dbg(adap, "I2CSR = %x\n", ioread32(p + PCH_I2CSR));
294-
pch_err(adap, "%s: Timeout Error.return%d\n", __func__, -ETIME);
295-
pch_i2c_init(adap);
300+
schedule = 1;
301+
}
296302

297-
return -ETIME;
303+
return 0;
298304
}
299305

300306
/**

0 commit comments

Comments
 (0)