aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-pca-isa.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses/i2c-pca-isa.c')
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index 4aa8138cb0a9..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>
@@ -41,15 +42,17 @@ static int irq = -1;
41 42
42/* Data sheet recommends 59kHz for 100kHz operation due to variation 43/* Data sheet recommends 59kHz for 100kHz operation due to variation
43 * in the actual clock rate */ 44 * in the actual clock rate */
44static int clock = I2C_PCA_CON_59kHz; 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)
49{ 51{
50#ifdef DEBUG_IO 52#ifdef DEBUG_IO
51 static char *names[] = { "T/O", "DAT", "ADR", "CON" }; 53 static char *names[] = { "T/O", "DAT", "ADR", "CON" };
52 printk("*** write %s at %#lx <= %#04x\n", names[reg], base+reg, val); 54 printk(KERN_DEBUG "*** write %s at %#lx <= %#04x\n", names[reg],
55 base+reg, val);
53#endif 56#endif
54 outb(val, base+reg); 57 outb(val, base+reg);
55} 58}
@@ -60,7 +63,7 @@ static int pca_isa_readbyte(void *pd, int reg)
60#ifdef DEBUG_IO 63#ifdef DEBUG_IO
61 { 64 {
62 static char *names[] = { "STA", "DAT", "ADR", "CON" }; 65 static char *names[] = { "STA", "DAT", "ADR", "CON" };
63 printk("*** read %s => %#04x\n", names[reg], res); 66 printk(KERN_DEBUG "*** read %s => %#04x\n", names[reg], res);
64 } 67 }
65#endif 68#endif
66 return res; 69 return res;
@@ -68,16 +71,22 @@ static int pca_isa_readbyte(void *pd, int reg)
68 71
69static int pca_isa_waitforcompletion(void *pd) 72static int pca_isa_waitforcompletion(void *pd)
70{ 73{
71 int ret = 0; 74 long ret = ~0;
75 unsigned long timeout;
72 76
73 if (irq > -1) { 77 if (irq > -1) {
74 ret = wait_event_interruptible(pca_wait, 78 ret = wait_event_interruptible_timeout(pca_wait,
75 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);
76 } else { 81 } else {
77 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)))
78 udelay(100); 87 udelay(100);
79 } 88 }
80 return ret; 89 return ret > 0;
81} 90}
82 91
83static void pca_isa_resetchip(void *pd) 92static void pca_isa_resetchip(void *pd)
@@ -102,8 +111,8 @@ static struct i2c_algo_pca_data pca_isa_data = {
102static struct i2c_adapter pca_isa_ops = { 111static struct i2c_adapter pca_isa_ops = {
103 .owner = THIS_MODULE, 112 .owner = THIS_MODULE,
104 .algo_data = &pca_isa_data, 113 .algo_data = &pca_isa_data,
105 .name = "PCA9564 ISA Adapter", 114 .name = "PCA9564/PCA9665 ISA Adapter",
106 .timeout = 100, 115 .timeout = HZ,
107}; 116};
108 117
109static int __devinit pca_isa_match(struct device *dev, unsigned int id) 118static int __devinit pca_isa_match(struct device *dev, unsigned int id)
@@ -195,7 +204,7 @@ static void __exit pca_isa_exit(void)
195} 204}
196 205
197MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); 206MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
198MODULE_DESCRIPTION("ISA base PCA9564 driver"); 207MODULE_DESCRIPTION("ISA base PCA9564/PCA9665 driver");
199MODULE_LICENSE("GPL"); 208MODULE_LICENSE("GPL");
200 209
201module_param(base, ulong, 0); 210module_param(base, ulong, 0);
@@ -204,7 +213,13 @@ MODULE_PARM_DESC(base, "I/O base address");
204module_param(irq, int, 0); 213module_param(irq, int, 0);
205MODULE_PARM_DESC(irq, "IRQ"); 214MODULE_PARM_DESC(irq, "IRQ");
206module_param(clock, int, 0); 215module_param(clock, int, 0);
207MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet"); 216MODULE_PARM_DESC(clock, "Clock rate in hertz.\n\t\t"
217 "For PCA9564: 330000,288000,217000,146000,"
218 "88000,59000,44000,36000\n"
219 "\t\tFor PCA9665:\tStandard: 60300 - 100099\n"
220 "\t\t\t\tFast: 100100 - 400099\n"
221 "\t\t\t\tFast+: 400100 - 10000099\n"
222 "\t\t\t\tTurbo: Up to 1265800");
208 223
209module_init(pca_isa_init); 224module_init(pca_isa_init);
210module_exit(pca_isa_exit); 225module_exit(pca_isa_exit);