diff options
Diffstat (limited to 'drivers/i2c/busses/i2c-pca-isa.c')
-rw-r--r-- | drivers/i2c/busses/i2c-pca-isa.c | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c new file mode 100644 index 000000000000..9c611134db9c --- /dev/null +++ b/drivers/i2c/busses/i2c-pca-isa.c | |||
@@ -0,0 +1,184 @@ | |||
1 | /* | ||
2 | * i2c-pca-isa.c driver for PCA9564 on ISA boards | ||
3 | * Copyright (C) 2004 Arcom Control Systems | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | */ | ||
19 | |||
20 | #include <linux/config.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/ioport.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/moduleparam.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/interrupt.h> | ||
29 | #include <linux/pci.h> | ||
30 | #include <linux/wait.h> | ||
31 | |||
32 | #include <linux/i2c.h> | ||
33 | #include <linux/i2c-algo-pca.h> | ||
34 | |||
35 | #include <asm/io.h> | ||
36 | #include <asm/irq.h> | ||
37 | |||
38 | #include "../algos/i2c-algo-pca.h" | ||
39 | |||
40 | #define IO_SIZE 4 | ||
41 | |||
42 | #undef DEBUG_IO | ||
43 | //#define DEBUG_IO | ||
44 | |||
45 | static unsigned long base = 0x330; | ||
46 | static int irq = 10; | ||
47 | |||
48 | /* Data sheet recommends 59kHz for 100kHz operation due to variation | ||
49 | * in the actual clock rate */ | ||
50 | static int clock = I2C_PCA_CON_59kHz; | ||
51 | |||
52 | static int own = 0x55; | ||
53 | |||
54 | static wait_queue_head_t pca_wait; | ||
55 | |||
56 | static int pca_isa_getown(struct i2c_algo_pca_data *adap) | ||
57 | { | ||
58 | return (own); | ||
59 | } | ||
60 | |||
61 | static int pca_isa_getclock(struct i2c_algo_pca_data *adap) | ||
62 | { | ||
63 | return (clock); | ||
64 | } | ||
65 | |||
66 | static void | ||
67 | pca_isa_writebyte(struct i2c_algo_pca_data *adap, int reg, int val) | ||
68 | { | ||
69 | #ifdef DEBUG_IO | ||
70 | static char *names[] = { "T/O", "DAT", "ADR", "CON" }; | ||
71 | printk("*** write %s at %#lx <= %#04x\n", names[reg], base+reg, val); | ||
72 | #endif | ||
73 | outb(val, base+reg); | ||
74 | } | ||
75 | |||
76 | static int | ||
77 | pca_isa_readbyte(struct i2c_algo_pca_data *adap, int reg) | ||
78 | { | ||
79 | int res = inb(base+reg); | ||
80 | #ifdef DEBUG_IO | ||
81 | { | ||
82 | static char *names[] = { "STA", "DAT", "ADR", "CON" }; | ||
83 | printk("*** read %s => %#04x\n", names[reg], res); | ||
84 | } | ||
85 | #endif | ||
86 | return res; | ||
87 | } | ||
88 | |||
89 | static int pca_isa_waitforinterrupt(struct i2c_algo_pca_data *adap) | ||
90 | { | ||
91 | int ret = 0; | ||
92 | |||
93 | if (irq > -1) { | ||
94 | ret = wait_event_interruptible(pca_wait, | ||
95 | pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI); | ||
96 | } else { | ||
97 | while ((pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) | ||
98 | udelay(100); | ||
99 | } | ||
100 | return ret; | ||
101 | } | ||
102 | |||
103 | static irqreturn_t pca_handler(int this_irq, void *dev_id, struct pt_regs *regs) { | ||
104 | wake_up_interruptible(&pca_wait); | ||
105 | return IRQ_HANDLED; | ||
106 | } | ||
107 | |||
108 | static struct i2c_algo_pca_data pca_isa_data = { | ||
109 | .get_own = pca_isa_getown, | ||
110 | .get_clock = pca_isa_getclock, | ||
111 | .write_byte = pca_isa_writebyte, | ||
112 | .read_byte = pca_isa_readbyte, | ||
113 | .wait_for_interrupt = pca_isa_waitforinterrupt, | ||
114 | }; | ||
115 | |||
116 | static struct i2c_adapter pca_isa_ops = { | ||
117 | .owner = THIS_MODULE, | ||
118 | .id = I2C_HW_A_ISA, | ||
119 | .algo_data = &pca_isa_data, | ||
120 | .name = "PCA9564 ISA Adapter", | ||
121 | }; | ||
122 | |||
123 | static int __init pca_isa_init(void) | ||
124 | { | ||
125 | |||
126 | init_waitqueue_head(&pca_wait); | ||
127 | |||
128 | printk(KERN_INFO "i2c-pca-isa: i/o base %#08lx. irq %d\n", base, irq); | ||
129 | |||
130 | if (!request_region(base, IO_SIZE, "i2c-pca-isa")) { | ||
131 | printk(KERN_ERR "i2c-pca-isa: I/O address %#08lx is in use.\n", base); | ||
132 | goto out; | ||
133 | } | ||
134 | |||
135 | if (irq > -1) { | ||
136 | if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) { | ||
137 | printk(KERN_ERR "i2c-pca-isa: Request irq%d failed\n", irq); | ||
138 | goto out_region; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | if (i2c_pca_add_bus(&pca_isa_ops) < 0) { | ||
143 | printk(KERN_ERR "i2c-pca-isa: Failed to add i2c bus\n"); | ||
144 | goto out_irq; | ||
145 | } | ||
146 | |||
147 | return 0; | ||
148 | |||
149 | out_irq: | ||
150 | if (irq > -1) | ||
151 | free_irq(irq, &pca_isa_ops); | ||
152 | out_region: | ||
153 | release_region(base, IO_SIZE); | ||
154 | out: | ||
155 | return -ENODEV; | ||
156 | } | ||
157 | |||
158 | static void pca_isa_exit(void) | ||
159 | { | ||
160 | i2c_pca_del_bus(&pca_isa_ops); | ||
161 | |||
162 | if (irq > 0) { | ||
163 | disable_irq(irq); | ||
164 | free_irq(irq, &pca_isa_ops); | ||
165 | } | ||
166 | release_region(base, IO_SIZE); | ||
167 | } | ||
168 | |||
169 | MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); | ||
170 | MODULE_DESCRIPTION("ISA base PCA9564 driver"); | ||
171 | MODULE_LICENSE("GPL"); | ||
172 | |||
173 | module_param(base, ulong, 0); | ||
174 | MODULE_PARM_DESC(base, "I/O base address"); | ||
175 | |||
176 | module_param(irq, int, 0); | ||
177 | MODULE_PARM_DESC(irq, "IRQ"); | ||
178 | module_param(clock, int, 0); | ||
179 | MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet"); | ||
180 | |||
181 | module_param(own, int, 0); /* the driver can't do slave mode, so there's no real point in this */ | ||
182 | |||
183 | module_init(pca_isa_init); | ||
184 | module_exit(pca_isa_exit); | ||