提交 8e99ada8 编写于 作者: W Wolfram Sang 提交者: Jean Delvare

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: NWolfram Sang <w.sang@pengutronix.de>
Signed-off-by: NJean Delvare <khali@linux-fr.org>
上级 eff9ec95
...@@ -229,7 +229,7 @@ static struct resource i2c_resources[] = { ...@@ -229,7 +229,7 @@ static struct resource i2c_resources[] = {
static struct i2c_pca9564_pf_platform_data i2c_platform_data = { static struct i2c_pca9564_pf_platform_data i2c_platform_data = {
.gpio = 0, .gpio = 0,
.i2c_clock_speed = I2C_PCA_CON_330kHz, .i2c_clock_speed = I2C_PCA_CON_330kHz,
.timeout = 100, .timeout = HZ,
}; };
static struct platform_device i2c_device = { static struct platform_device i2c_device = {
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/i2c.h> #include <linux/i2c.h>
...@@ -186,15 +187,17 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, ...@@ -186,15 +187,17 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
int numbytes = 0; int numbytes = 0;
int state; int state;
int ret; int ret;
int timeout = i2c_adap->timeout; unsigned long timeout = jiffies + i2c_adap->timeout;
while ((state = pca_status(adap)) != 0xf8 && timeout--) { while (pca_status(adap) != 0xf8) {
if (time_before(jiffies, timeout)) {
msleep(10); msleep(10);
} } else {
if (state != 0xf8) { dev_dbg(&i2c_adap->dev, "bus is not idle. status is "
dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state); "%#04x\n", state);
return -EAGAIN; return -EAGAIN;
} }
}
DEB1("{{{ XFER %d messages\n", num); DEB1("{{{ XFER %d messages\n", num);
......
...@@ -104,7 +104,7 @@ static struct i2c_adapter pca_isa_ops = { ...@@ -104,7 +104,7 @@ static struct i2c_adapter pca_isa_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.algo_data = &pca_isa_data, .algo_data = &pca_isa_data,
.name = "PCA9564/PCA9665 ISA Adapter", .name = "PCA9564/PCA9665 ISA Adapter",
.timeout = 100, .timeout = HZ,
}; };
static int __devinit pca_isa_match(struct device *dev, unsigned int id) static int __devinit pca_isa_match(struct device *dev, unsigned int id)
......
...@@ -6,7 +6,7 @@ struct i2c_pca9564_pf_platform_data { ...@@ -6,7 +6,7 @@ struct i2c_pca9564_pf_platform_data {
* not supplied (negative value), but it * not supplied (negative value), but it
* cannot exit some error conditions then */ * cannot exit some error conditions then */
int i2c_clock_speed; /* values are defined in linux/i2c-algo-pca.h */ int i2c_clock_speed; /* values are defined in linux/i2c-algo-pca.h */
int timeout; /* timeout = this value * 10us */ int timeout; /* timeout in jiffies */
}; };
#endif /* I2C_PCA9564_PLATFORM_H */ #endif /* I2C_PCA9564_PLATFORM_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册