diff options
author | Wolfram Sang <w.sang@pengutronix.de> | 2009-03-28 16:34:45 -0400 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-03-28 16:34:45 -0400 |
commit | 8e99ada8deaa9033600cd2c7d0a9366b0e99ab68 (patch) | |
tree | 20784a41011e58f7ba6497d7a3763781b8a3d460 | |
parent | eff9ec95efaaf6b12d230f0ea7d3c295d3bc9d57 (diff) |
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>
-rw-r--r-- | arch/sh/boards/board-sh7785lcr.c | 2 | ||||
-rw-r--r-- | drivers/i2c/algos/i2c-algo-pca.c | 17 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-pca-isa.c | 2 | ||||
-rw-r--r-- | include/linux/i2c-pca-platform.h | 2 |
4 files changed, 13 insertions, 10 deletions
diff --git a/arch/sh/boards/board-sh7785lcr.c b/arch/sh/boards/board-sh7785lcr.c index 94c0296bc35d..6f94f17adc46 100644 --- a/arch/sh/boards/board-sh7785lcr.c +++ b/arch/sh/boards/board-sh7785lcr.c | |||
@@ -229,7 +229,7 @@ static struct resource i2c_resources[] = { | |||
229 | static struct i2c_pca9564_pf_platform_data i2c_platform_data = { | 229 | static struct i2c_pca9564_pf_platform_data i2c_platform_data = { |
230 | .gpio = 0, | 230 | .gpio = 0, |
231 | .i2c_clock_speed = I2C_PCA_CON_330kHz, | 231 | .i2c_clock_speed = I2C_PCA_CON_330kHz, |
232 | .timeout = 100, | 232 | .timeout = HZ, |
233 | }; | 233 | }; |
234 | 234 | ||
235 | static struct platform_device i2c_device = { | 235 | static struct platform_device i2c_device = { |
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c index a8e51bd1a4f5..9e134fad7bda 100644 --- a/drivers/i2c/algos/i2c-algo-pca.c +++ b/drivers/i2c/algos/i2c-algo-pca.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
23 | #include <linux/moduleparam.h> | 23 | #include <linux/moduleparam.h> |
24 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
25 | #include <linux/jiffies.h> | ||
25 | #include <linux/init.h> | 26 | #include <linux/init.h> |
26 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
27 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
@@ -186,14 +187,16 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, | |||
186 | int numbytes = 0; | 187 | int numbytes = 0; |
187 | int state; | 188 | int state; |
188 | int ret; | 189 | int ret; |
189 | int timeout = i2c_adap->timeout; | 190 | unsigned long timeout = jiffies + i2c_adap->timeout; |
190 | 191 | ||
191 | while ((state = pca_status(adap)) != 0xf8 && timeout--) { | 192 | while (pca_status(adap) != 0xf8) { |
192 | msleep(10); | 193 | if (time_before(jiffies, timeout)) { |
193 | } | 194 | msleep(10); |
194 | if (state != 0xf8) { | 195 | } else { |
195 | dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state); | 196 | dev_dbg(&i2c_adap->dev, "bus is not idle. status is " |
196 | return -EAGAIN; | 197 | "%#04x\n", state); |
198 | return -EAGAIN; | ||
199 | } | ||
197 | } | 200 | } |
198 | 201 | ||
199 | DEB1("{{{ XFER %d messages\n", num); | 202 | DEB1("{{{ XFER %d messages\n", num); |
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c index 0cc8017b3f64..b9403fdfb6d8 100644 --- a/drivers/i2c/busses/i2c-pca-isa.c +++ b/drivers/i2c/busses/i2c-pca-isa.c | |||
@@ -104,7 +104,7 @@ static struct i2c_adapter pca_isa_ops = { | |||
104 | .owner = THIS_MODULE, | 104 | .owner = THIS_MODULE, |
105 | .algo_data = &pca_isa_data, | 105 | .algo_data = &pca_isa_data, |
106 | .name = "PCA9564/PCA9665 ISA Adapter", | 106 | .name = "PCA9564/PCA9665 ISA Adapter", |
107 | .timeout = 100, | 107 | .timeout = HZ, |
108 | }; | 108 | }; |
109 | 109 | ||
110 | static int __devinit pca_isa_match(struct device *dev, unsigned int id) | 110 | static int __devinit pca_isa_match(struct device *dev, unsigned int id) |
diff --git a/include/linux/i2c-pca-platform.h b/include/linux/i2c-pca-platform.h index 3d191873f2d1..aba33759dec4 100644 --- a/include/linux/i2c-pca-platform.h +++ b/include/linux/i2c-pca-platform.h | |||
@@ -6,7 +6,7 @@ struct i2c_pca9564_pf_platform_data { | |||
6 | * not supplied (negative value), but it | 6 | * not supplied (negative value), but it |
7 | * cannot exit some error conditions then */ | 7 | * cannot exit some error conditions then */ |
8 | int i2c_clock_speed; /* values are defined in linux/i2c-algo-pca.h */ | 8 | 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 */ |
10 | }; | 10 | }; |
11 | 11 | ||
12 | #endif /* I2C_PCA9564_PLATFORM_H */ | 12 | #endif /* I2C_PCA9564_PLATFORM_H */ |