aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
authorWolfram Sang <w.sang@pengutronix.de>2009-03-28 16:34:45 -0400
committerJean Delvare <khali@linux-fr.org>2009-03-28 16:34:45 -0400
commit2378bc09b91b0702fac7823828a614fd8016a29f (patch)
tree26539b17077028baba2741cf0e78fc01225a7d36 /drivers/i2c/busses
parent8e99ada8deaa9033600cd2c7d0a9366b0e99ab68 (diff)
i2c-algo-pca: Use timeout for checking the state machine
We now timeout also if the state machine does not change within the given time. For that, the driver-specific completion-functions are extended to return true or false depending on the timeout. This then gets checked in the algorithm. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c18
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c20
2 files changed, 23 insertions, 15 deletions
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index b9403fdfb6d8..0ed68e2ccd22 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -23,6 +23,7 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/jiffies.h>
26#include <linux/init.h> 27#include <linux/init.h>
27#include <linux/interrupt.h> 28#include <linux/interrupt.h>
28#include <linux/wait.h> 29#include <linux/wait.h>
@@ -43,6 +44,7 @@ static int irq = -1;
43 * in the actual clock rate */ 44 * in the actual clock rate */
44static int clock = 59000; 45static int clock = 59000;
45 46
47static struct i2c_adapter pca_isa_ops;
46static wait_queue_head_t pca_wait; 48static wait_queue_head_t pca_wait;
47 49
48static void pca_isa_writebyte(void *pd, int reg, int val) 50static void pca_isa_writebyte(void *pd, int reg, int val)
@@ -69,16 +71,22 @@ static int pca_isa_readbyte(void *pd, int reg)
69 71
70static int pca_isa_waitforcompletion(void *pd) 72static int pca_isa_waitforcompletion(void *pd)
71{ 73{
72 int ret = 0; 74 long ret = ~0;
75 unsigned long timeout;
73 76
74 if (irq > -1) { 77 if (irq > -1) {
75 ret = wait_event_interruptible(pca_wait, 78 ret = wait_event_interruptible_timeout(pca_wait,
76 pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI); 79 pca_isa_readbyte(pd, I2C_PCA_CON)
80 & I2C_PCA_CON_SI, pca_isa_ops.timeout);
77 } else { 81 } else {
78 while ((pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) 82 /* Do polling */
83 timeout = jiffies + pca_isa_ops.timeout;
84 while (((pca_isa_readbyte(pd, I2C_PCA_CON)
85 & I2C_PCA_CON_SI) == 0)
86 && (ret = time_before(jiffies, timeout)))
79 udelay(100); 87 udelay(100);
80 } 88 }
81 return ret; 89 return ret > 0;
82} 90}
83 91
84static void pca_isa_resetchip(void *pd) 92static void pca_isa_resetchip(void *pd)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 51d179bbddf9..df5e593a1d76 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/jiffies.h>
18#include <linux/errno.h> 19#include <linux/errno.h>
19#include <linux/i2c.h> 20#include <linux/i2c.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
@@ -81,24 +82,23 @@ static void i2c_pca_pf_writebyte32(void *pd, int reg, int val)
81static int i2c_pca_pf_waitforcompletion(void *pd) 82static int i2c_pca_pf_waitforcompletion(void *pd)
82{ 83{
83 struct i2c_pca_pf_data *i2c = pd; 84 struct i2c_pca_pf_data *i2c = pd;
84 int ret = 0; 85 long ret = ~0;
86 unsigned long timeout;
85 87
86 if (i2c->irq) { 88 if (i2c->irq) {
87 ret = wait_event_interruptible(i2c->wait, 89 ret = wait_event_interruptible_timeout(i2c->wait,
88 i2c->algo_data.read_byte(i2c, I2C_PCA_CON) 90 i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
89 & I2C_PCA_CON_SI); 91 & I2C_PCA_CON_SI, i2c->adap.timeout);
90 } else { 92 } else {
91 /* 93 /* Do polling */
92 * Do polling... 94 timeout = jiffies + i2c->adap.timeout;
93 * XXX: Could get stuck in extreme cases! 95 while (((i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
94 * Maybe add timeout, but using irqs is preferred anyhow.
95 */
96 while ((i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
97 & I2C_PCA_CON_SI) == 0) 96 & I2C_PCA_CON_SI) == 0)
97 && (ret = time_before(jiffies, timeout)))
98 udelay(100); 98 udelay(100);
99 } 99 }
100 100
101 return ret; 101 return ret > 0;
102} 102}
103 103
104static void i2c_pca_pf_dummyreset(void *pd) 104static void i2c_pca_pf_dummyreset(void *pd)