2 * i2c-pca-isa.c driver for PCA9564 on ISA boards
3 * Copyright (C) 2004 Arcom Control Systems
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.
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.
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.
20 #include <linux/kernel.h>
21 #include <linux/ioport.h>
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/wait.h>
30 #include <linux/isa.h>
31 #include <linux/i2c.h>
32 #include <linux/i2c-algo-pca.h>
37 #include "../algos/i2c-algo-pca.h"
44 static unsigned long base
= 0x330;
47 /* Data sheet recommends 59kHz for 100kHz operation due to variation
48 * in the actual clock rate */
49 static int clock
= I2C_PCA_CON_59kHz
;
51 static int own
= 0x55;
53 static wait_queue_head_t pca_wait
;
55 static int pca_isa_getown(struct i2c_algo_pca_data
*adap
)
60 static int pca_isa_getclock(struct i2c_algo_pca_data
*adap
)
66 pca_isa_writebyte(struct i2c_algo_pca_data
*adap
, int reg
, int val
)
69 static char *names
[] = { "T/O", "DAT", "ADR", "CON" };
70 printk("*** write %s at %#lx <= %#04x\n", names
[reg
], base
+reg
, val
);
76 pca_isa_readbyte(struct i2c_algo_pca_data
*adap
, int reg
)
78 int res
= inb(base
+reg
);
81 static char *names
[] = { "STA", "DAT", "ADR", "CON" };
82 printk("*** read %s => %#04x\n", names
[reg
], res
);
88 static int pca_isa_waitforinterrupt(struct i2c_algo_pca_data
*adap
)
93 ret
= wait_event_interruptible(pca_wait
,
94 pca_isa_readbyte(adap
, I2C_PCA_CON
) & I2C_PCA_CON_SI
);
96 while ((pca_isa_readbyte(adap
, I2C_PCA_CON
) & I2C_PCA_CON_SI
) == 0)
102 static irqreturn_t
pca_handler(int this_irq
, void *dev_id
) {
103 wake_up_interruptible(&pca_wait
);
107 static struct i2c_algo_pca_data pca_isa_data
= {
108 .get_own
= pca_isa_getown
,
109 .get_clock
= pca_isa_getclock
,
110 .write_byte
= pca_isa_writebyte
,
111 .read_byte
= pca_isa_readbyte
,
112 .wait_for_interrupt
= pca_isa_waitforinterrupt
,
115 static struct i2c_adapter pca_isa_ops
= {
116 .owner
= THIS_MODULE
,
118 .algo_data
= &pca_isa_data
,
119 .name
= "PCA9564 ISA Adapter",
122 static int __devinit
pca_isa_probe(struct device
*dev
, unsigned int id
)
124 init_waitqueue_head(&pca_wait
);
126 dev_info(dev
, "i/o base %#08lx. irq %d\n", base
, irq
);
128 <<<<<<< HEAD
:drivers
/i2c
/busses
/i2c
-pca
-isa
.c
130 #ifdef CONFIG_PPC_MERGE
131 if (check_legacy_ioport(base
)) {
132 dev_err(dev
, "I/O address %#08lx is not available\n", base
);
137 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/i2c
/busses
/i2c
-pca
-isa
.c
138 if (!request_region(base
, IO_SIZE
, "i2c-pca-isa")) {
139 dev_err(dev
, "I/O address %#08lx is in use\n", base
);
144 if (request_irq(irq
, pca_handler
, 0, "i2c-pca-isa", &pca_isa_ops
) < 0) {
145 dev_err(dev
, "Request irq%d failed\n", irq
);
150 if (i2c_pca_add_bus(&pca_isa_ops
) < 0) {
151 dev_err(dev
, "Failed to add i2c bus\n");
159 free_irq(irq
, &pca_isa_ops
);
161 release_region(base
, IO_SIZE
);
166 static int __devexit
pca_isa_remove(struct device
*dev
, unsigned int id
)
168 i2c_del_adapter(&pca_isa_ops
);
172 free_irq(irq
, &pca_isa_ops
);
174 release_region(base
, IO_SIZE
);
179 static struct isa_driver pca_isa_driver
= {
180 .probe
= pca_isa_probe
,
181 .remove
= __devexit_p(pca_isa_remove
),
183 .owner
= THIS_MODULE
,
184 .name
= "i2c-pca-isa",
188 static int __init
pca_isa_init(void)
190 return isa_register_driver(&pca_isa_driver
, 1);
193 static void __exit
pca_isa_exit(void)
195 isa_unregister_driver(&pca_isa_driver
);
198 MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
199 MODULE_DESCRIPTION("ISA base PCA9564 driver");
200 MODULE_LICENSE("GPL");
202 module_param(base
, ulong
, 0);
203 MODULE_PARM_DESC(base
, "I/O base address");
205 module_param(irq
, int, 0);
206 MODULE_PARM_DESC(irq
, "IRQ");
207 module_param(clock
, int, 0);
208 MODULE_PARM_DESC(clock
, "Clock rate as described in table 1 of PCA9564 datasheet");
210 module_param(own
, int, 0); /* the driver can't do slave mode, so there's no real point in this */
212 module_init(pca_isa_init
);
213 module_exit(pca_isa_exit
);