PCI: Cleanup the includes of <linux/pci.h>
[deliverable/linux.git] / drivers / i2c / busses / i2c-pca-isa.c
CommitLineData
1da177e4
LT
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
1da177e4
LT
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>
1da177e4
LT
28#include <linux/wait.h>
29
30#include <linux/i2c.h>
31#include <linux/i2c-algo-pca.h>
32
33#include <asm/io.h>
34#include <asm/irq.h>
35
36#include "../algos/i2c-algo-pca.h"
37
38#define IO_SIZE 4
39
40#undef DEBUG_IO
41//#define DEBUG_IO
42
43static unsigned long base = 0x330;
44static int irq = 10;
45
46/* Data sheet recommends 59kHz for 100kHz operation due to variation
47 * in the actual clock rate */
48static int clock = I2C_PCA_CON_59kHz;
49
50static int own = 0x55;
51
52static wait_queue_head_t pca_wait;
53
54static int pca_isa_getown(struct i2c_algo_pca_data *adap)
55{
56 return (own);
57}
58
59static int pca_isa_getclock(struct i2c_algo_pca_data *adap)
60{
61 return (clock);
62}
63
64static void
65pca_isa_writebyte(struct i2c_algo_pca_data *adap, int reg, int val)
66{
67#ifdef DEBUG_IO
68 static char *names[] = { "T/O", "DAT", "ADR", "CON" };
69 printk("*** write %s at %#lx <= %#04x\n", names[reg], base+reg, val);
70#endif
71 outb(val, base+reg);
72}
73
74static int
75pca_isa_readbyte(struct i2c_algo_pca_data *adap, int reg)
76{
77 int res = inb(base+reg);
78#ifdef DEBUG_IO
79 {
80 static char *names[] = { "STA", "DAT", "ADR", "CON" };
81 printk("*** read %s => %#04x\n", names[reg], res);
82 }
83#endif
84 return res;
85}
86
87static int pca_isa_waitforinterrupt(struct i2c_algo_pca_data *adap)
88{
89 int ret = 0;
90
91 if (irq > -1) {
92 ret = wait_event_interruptible(pca_wait,
93 pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI);
94 } else {
95 while ((pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0)
96 udelay(100);
97 }
98 return ret;
99}
100
7d12e780 101static irqreturn_t pca_handler(int this_irq, void *dev_id) {
1da177e4
LT
102 wake_up_interruptible(&pca_wait);
103 return IRQ_HANDLED;
104}
105
106static struct i2c_algo_pca_data pca_isa_data = {
107 .get_own = pca_isa_getown,
108 .get_clock = pca_isa_getclock,
109 .write_byte = pca_isa_writebyte,
110 .read_byte = pca_isa_readbyte,
111 .wait_for_interrupt = pca_isa_waitforinterrupt,
112};
113
114static struct i2c_adapter pca_isa_ops = {
115 .owner = THIS_MODULE,
116 .id = I2C_HW_A_ISA,
117 .algo_data = &pca_isa_data,
118 .name = "PCA9564 ISA Adapter",
119};
120
121static int __init pca_isa_init(void)
122{
123
124 init_waitqueue_head(&pca_wait);
125
126 printk(KERN_INFO "i2c-pca-isa: i/o base %#08lx. irq %d\n", base, irq);
127
128 if (!request_region(base, IO_SIZE, "i2c-pca-isa")) {
129 printk(KERN_ERR "i2c-pca-isa: I/O address %#08lx is in use.\n", base);
130 goto out;
131 }
132
133 if (irq > -1) {
134 if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) {
135 printk(KERN_ERR "i2c-pca-isa: Request irq%d failed\n", irq);
136 goto out_region;
137 }
138 }
139
140 if (i2c_pca_add_bus(&pca_isa_ops) < 0) {
141 printk(KERN_ERR "i2c-pca-isa: Failed to add i2c bus\n");
142 goto out_irq;
143 }
144
145 return 0;
146
147 out_irq:
148 if (irq > -1)
149 free_irq(irq, &pca_isa_ops);
150 out_region:
151 release_region(base, IO_SIZE);
152 out:
153 return -ENODEV;
154}
155
156static void pca_isa_exit(void)
157{
3269711b 158 i2c_del_adapter(&pca_isa_ops);
1da177e4
LT
159
160 if (irq > 0) {
161 disable_irq(irq);
162 free_irq(irq, &pca_isa_ops);
163 }
164 release_region(base, IO_SIZE);
165}
166
167MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
168MODULE_DESCRIPTION("ISA base PCA9564 driver");
169MODULE_LICENSE("GPL");
170
171module_param(base, ulong, 0);
172MODULE_PARM_DESC(base, "I/O base address");
173
174module_param(irq, int, 0);
175MODULE_PARM_DESC(irq, "IRQ");
176module_param(clock, int, 0);
177MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet");
178
179module_param(own, int, 0); /* the driver can't do slave mode, so there's no real point in this */
180
181module_init(pca_isa_init);
182module_exit(pca_isa_exit);
This page took 0.215667 seconds and 5 git commands to generate.