2 * i2c-pca-isa.c driver for PCA9564 on ISA boards
3 * Copyright (C) 2004 Arcom Control Systems
4 * Copyright (C) 2008 Pengutronix
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/wait.h>
29 #include <linux/isa.h>
30 #include <linux/i2c.h>
31 #include <linux/i2c-algo-pca.h>
36 #define DRIVER "i2c-pca-isa"
39 static unsigned long base
;
42 /* Data sheet recommends 59kHz for 100kHz operation due to variation
43 * in the actual clock rate */
44 static int clock
= I2C_PCA_CON_59kHz
;
46 static wait_queue_head_t pca_wait
;
48 static void pca_isa_writebyte(void *pd
, int reg
, int val
)
51 static char *names
[] = { "T/O", "DAT", "ADR", "CON" };
52 printk("*** write %s at %#lx <= %#04x\n", names
[reg
], base
+reg
, val
);
57 static int pca_isa_readbyte(void *pd
, int reg
)
59 int res
= inb(base
+reg
);
62 static char *names
[] = { "STA", "DAT", "ADR", "CON" };
63 printk("*** read %s => %#04x\n", names
[reg
], res
);
69 static int pca_isa_waitforcompletion(void *pd
)
74 ret
= wait_event_interruptible(pca_wait
,
75 pca_isa_readbyte(pd
, I2C_PCA_CON
) & I2C_PCA_CON_SI
);
77 while ((pca_isa_readbyte(pd
, I2C_PCA_CON
) & I2C_PCA_CON_SI
) == 0)
83 static void pca_isa_resetchip(void *pd
)
85 /* apparently only an external reset will do it. not a lot can be done */
86 printk(KERN_WARNING DRIVER
": Haven't figured out how to do a reset yet\n");
89 static irqreturn_t
pca_handler(int this_irq
, void *dev_id
) {
90 wake_up_interruptible(&pca_wait
);
94 static struct i2c_algo_pca_data pca_isa_data
= {
95 /* .data intentionally left NULL, not needed with ISA */
96 .write_byte
= pca_isa_writebyte
,
97 .read_byte
= pca_isa_readbyte
,
98 .wait_for_completion
= pca_isa_waitforcompletion
,
99 .reset_chip
= pca_isa_resetchip
,
102 static struct i2c_adapter pca_isa_ops
= {
103 .owner
= THIS_MODULE
,
105 .algo_data
= &pca_isa_data
,
106 .name
= "PCA9564 ISA Adapter",
110 static int __devinit
pca_isa_match(struct device
*dev
, unsigned int id
)
112 int match
= base
!= 0;
116 dev_warn(dev
, "Using polling mode (specify irq)\n");
118 dev_err(dev
, "Please specify I/O base\n");
123 static int __devinit
pca_isa_probe(struct device
*dev
, unsigned int id
)
125 init_waitqueue_head(&pca_wait
);
127 dev_info(dev
, "i/o base %#08lx. irq %d\n", base
, irq
);
130 if (check_legacy_ioport(base
)) {
131 dev_err(dev
, "I/O address %#08lx is not available\n", base
);
136 if (!request_region(base
, IO_SIZE
, "i2c-pca-isa")) {
137 dev_err(dev
, "I/O address %#08lx is in use\n", base
);
142 if (request_irq(irq
, pca_handler
, 0, "i2c-pca-isa", &pca_isa_ops
) < 0) {
143 dev_err(dev
, "Request irq%d failed\n", irq
);
148 pca_isa_data
.i2c_clock
= clock
;
149 if (i2c_pca_add_bus(&pca_isa_ops
) < 0) {
150 dev_err(dev
, "Failed to add i2c bus\n");
158 free_irq(irq
, &pca_isa_ops
);
160 release_region(base
, IO_SIZE
);
165 static int __devexit
pca_isa_remove(struct device
*dev
, unsigned int id
)
167 i2c_del_adapter(&pca_isa_ops
);
171 free_irq(irq
, &pca_isa_ops
);
173 release_region(base
, IO_SIZE
);
178 static struct isa_driver pca_isa_driver
= {
179 .match
= pca_isa_match
,
180 .probe
= pca_isa_probe
,
181 .remove
= __devexit_p(pca_isa_remove
),
183 .owner
= THIS_MODULE
,
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_init(pca_isa_init
);
211 module_exit(pca_isa_exit
);