Skip to content

Commit 8e99ada

Browse files
Wolfram SangJean Delvare
authored andcommitted
i2c-algo-pca: Rework waiting for a free bus
Waiting for a free bus now accepts the timeout value in jiffies and does proper checking using time_before. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Jean Delvare <khali@linux-fr.org>
1 parent eff9ec9 commit 8e99ada

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎arch/sh/boards/board-sh7785lcr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static struct resource i2c_resources[] = {
229229
static struct i2c_pca9564_pf_platform_data i2c_platform_data = {
230230
.gpio = 0,
231231
.i2c_clock_speed = I2C_PCA_CON_330kHz,
232-
.timeout = 100,
232+
.timeout = HZ,
233233
};
234234

235235
static struct platform_device i2c_device = {

‎drivers/i2c/algos/i2c-algo-pca.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/module.h>
2323
#include <linux/moduleparam.h>
2424
#include <linux/delay.h>
25+
#include <linux/jiffies.h>
2526
#include <linux/init.h>
2627
#include <linux/errno.h>
2728
#include <linux/i2c.h>
@@ -186,14 +187,16 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
186187
int numbytes = 0;
187188
int state;
188189
int ret;
189-
int timeout = i2c_adap->timeout;
190+
unsigned long timeout = jiffies + i2c_adap->timeout;
190191

191-
while ((state = pca_status(adap)) != 0xf8 && timeout--) {
192-
msleep(10);
193-
}
194-
if (state != 0xf8) {
195-
dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state);
196-
return -EAGAIN;
192+
while (pca_status(adap) != 0xf8) {
193+
if (time_before(jiffies, timeout)) {
194+
msleep(10);
195+
} else {
196+
dev_dbg(&i2c_adap->dev, "bus is not idle. status is "
197+
"%#04x\n", state);
198+
return -EAGAIN;
199+
}
197200
}
198201

199202
DEB1("{{{ XFER %d messages\n", num);

‎drivers/i2c/busses/i2c-pca-isa.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static struct i2c_adapter pca_isa_ops = {
104104
.owner = THIS_MODULE,
105105
.algo_data = &pca_isa_data,
106106
.name = "PCA9564/PCA9665 ISA Adapter",
107-
.timeout = 100,
107+
.timeout = HZ,
108108
};
109109

110110
static int __devinit pca_isa_match(struct device *dev, unsigned int id)

‎include/linux/i2c-pca-platform.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct i2c_pca9564_pf_platform_data {
66
* not supplied (negative value), but it
77
* cannot exit some error conditions then */
88
int i2c_clock_speed; /* values are defined in linux/i2c-algo-pca.h */
9-
int timeout; /* timeout = this value * 10us */
9+
int timeout; /* timeout in jiffies */
1010
};
1111

1212
#endif /* I2C_PCA9564_PLATFORM_H */

0 commit comments

Comments
 (0)