diff options
author | Wolfram Sang <w.sang@pengutronix.de> | 2008-04-22 16:16:46 -0400 |
---|---|---|
committer | Jean Delvare <khali@hyperion.delvare> | 2008-04-22 16:16:46 -0400 |
commit | c01b0831057381c7f6e0bfb3634bac8c5f7fb256 (patch) | |
tree | 43fb4c2d626df0c32f3196c81062592ab60ccd12 /drivers/i2c/busses | |
parent | 3d4382913f9a86f0d9ff47740feb427415fe7234 (diff) |
i2c-algo-pca: Extend for future drivers
The separation between algorithm and adapter was unsharp at places. This was
partly hidden by the fact, that the ISA-driver allowed just one instance and
had all private data in static variables. This patch makes neccessary
preparations to add a platform driver on top of the algorithm, while still
supporting ISA. Note: Due to lack of hardware, the ISA-driver could not be
tested except that it builds.
Concerning the core struct i2c_algo_pca_data:
- A private data field was added, all hardware dependant data may go here.
Similar to other algorithms, now a pointer to this data is passed to the
adapter's functions. In order to make as less changes as possible to the
ISA-driver, it leaves the private data empty and still only uses its static
variables.
- A "reset_chip" function pointer was added; such a functionality must come
from the adapter, not the algorithm.
- use a variable "i2c_clock" instead of a function pointer "get_clock",
allowing for write access to a default in case a wrong value was supplied.
In the algorithm-file:
- move "i2c-pca-algo.h" into "linux/i2c-algo-pca.h"
- now using per_instance timeout values (i2c_adap->timeout)
- error messages specify the device, not only the driver name
- restructure initialization to easily support "i2c_add_numbered_adapter"
- drop "retries" and "own" (i2c address) as they were unused
(The state-machine for I2C-communication was not touched.)
In the ISA-driver:
- adapt to new algorithm
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r-- | drivers/i2c/busses/i2c-pca-isa.c | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c index 93ed3251893d..a119784bae10 100644 --- a/drivers/i2c/busses/i2c-pca-isa.c +++ b/drivers/i2c/busses/i2c-pca-isa.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * i2c-pca-isa.c driver for PCA9564 on ISA boards | 2 | * i2c-pca-isa.c driver for PCA9564 on ISA boards |
3 | * Copyright (C) 2004 Arcom Control Systems | 3 | * Copyright (C) 2004 Arcom Control Systems |
4 | * Copyright (C) 2008 Pengutronix | ||
4 | * | 5 | * |
5 | * This program is free software; you can redistribute it and/or modify | 6 | * 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 | * it under the terms of the GNU General Public License as published by |
@@ -22,11 +23,9 @@ | |||
22 | #include <linux/module.h> | 23 | #include <linux/module.h> |
23 | #include <linux/moduleparam.h> | 24 | #include <linux/moduleparam.h> |
24 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
25 | #include <linux/slab.h> | ||
26 | #include <linux/init.h> | 26 | #include <linux/init.h> |
27 | #include <linux/interrupt.h> | 27 | #include <linux/interrupt.h> |
28 | #include <linux/wait.h> | 28 | #include <linux/wait.h> |
29 | |||
30 | #include <linux/isa.h> | 29 | #include <linux/isa.h> |
31 | #include <linux/i2c.h> | 30 | #include <linux/i2c.h> |
32 | #include <linux/i2c-algo-pca.h> | 31 | #include <linux/i2c-algo-pca.h> |
@@ -34,13 +33,9 @@ | |||
34 | #include <asm/io.h> | 33 | #include <asm/io.h> |
35 | #include <asm/irq.h> | 34 | #include <asm/irq.h> |
36 | 35 | ||
37 | #include "../algos/i2c-algo-pca.h" | 36 | #define DRIVER "i2c-pca-isa" |
38 | |||
39 | #define IO_SIZE 4 | 37 | #define IO_SIZE 4 |
40 | 38 | ||
41 | #undef DEBUG_IO | ||
42 | //#define DEBUG_IO | ||
43 | |||
44 | static unsigned long base = 0x330; | 39 | static unsigned long base = 0x330; |
45 | static int irq = 10; | 40 | static int irq = 10; |
46 | 41 | ||
@@ -48,22 +43,9 @@ static int irq = 10; | |||
48 | * in the actual clock rate */ | 43 | * in the actual clock rate */ |
49 | static int clock = I2C_PCA_CON_59kHz; | 44 | static int clock = I2C_PCA_CON_59kHz; |
50 | 45 | ||
51 | static int own = 0x55; | ||
52 | |||
53 | static wait_queue_head_t pca_wait; | 46 | static wait_queue_head_t pca_wait; |
54 | 47 | ||
55 | static int pca_isa_getown(struct i2c_algo_pca_data *adap) | 48 | static void pca_isa_writebyte(void *pd, int reg, int val) |
56 | { | ||
57 | return (own); | ||
58 | } | ||
59 | |||
60 | static int pca_isa_getclock(struct i2c_algo_pca_data *adap) | ||
61 | { | ||
62 | return (clock); | ||
63 | } | ||
64 | |||
65 | static void | ||
66 | pca_isa_writebyte(struct i2c_algo_pca_data *adap, int reg, int val) | ||
67 | { | 49 | { |
68 | #ifdef DEBUG_IO | 50 | #ifdef DEBUG_IO |
69 | static char *names[] = { "T/O", "DAT", "ADR", "CON" }; | 51 | static char *names[] = { "T/O", "DAT", "ADR", "CON" }; |
@@ -72,8 +54,7 @@ pca_isa_writebyte(struct i2c_algo_pca_data *adap, int reg, int val) | |||
72 | outb(val, base+reg); | 54 | outb(val, base+reg); |
73 | } | 55 | } |
74 | 56 | ||
75 | static int | 57 | static int pca_isa_readbyte(void *pd, int reg) |
76 | pca_isa_readbyte(struct i2c_algo_pca_data *adap, int reg) | ||
77 | { | 58 | { |
78 | int res = inb(base+reg); | 59 | int res = inb(base+reg); |
79 | #ifdef DEBUG_IO | 60 | #ifdef DEBUG_IO |
@@ -85,31 +66,37 @@ pca_isa_readbyte(struct i2c_algo_pca_data *adap, int reg) | |||
85 | return res; | 66 | return res; |
86 | } | 67 | } |
87 | 68 | ||
88 | static int pca_isa_waitforinterrupt(struct i2c_algo_pca_data *adap) | 69 | static int pca_isa_waitforcompletion(void *pd) |
89 | { | 70 | { |
90 | int ret = 0; | 71 | int ret = 0; |
91 | 72 | ||
92 | if (irq > -1) { | 73 | if (irq > -1) { |
93 | ret = wait_event_interruptible(pca_wait, | 74 | ret = wait_event_interruptible(pca_wait, |
94 | pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI); | 75 | pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI); |
95 | } else { | 76 | } else { |
96 | while ((pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) | 77 | while ((pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) |
97 | udelay(100); | 78 | udelay(100); |
98 | } | 79 | } |
99 | return ret; | 80 | return ret; |
100 | } | 81 | } |
101 | 82 | ||
83 | static void pca_isa_resetchip(void *pd) | ||
84 | { | ||
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"); | ||
87 | } | ||
88 | |||
102 | static irqreturn_t pca_handler(int this_irq, void *dev_id) { | 89 | static irqreturn_t pca_handler(int this_irq, void *dev_id) { |
103 | wake_up_interruptible(&pca_wait); | 90 | wake_up_interruptible(&pca_wait); |
104 | return IRQ_HANDLED; | 91 | return IRQ_HANDLED; |
105 | } | 92 | } |
106 | 93 | ||
107 | static struct i2c_algo_pca_data pca_isa_data = { | 94 | static struct i2c_algo_pca_data pca_isa_data = { |
108 | .get_own = pca_isa_getown, | 95 | /* .data intentionally left NULL, not needed with ISA */ |
109 | .get_clock = pca_isa_getclock, | ||
110 | .write_byte = pca_isa_writebyte, | 96 | .write_byte = pca_isa_writebyte, |
111 | .read_byte = pca_isa_readbyte, | 97 | .read_byte = pca_isa_readbyte, |
112 | .wait_for_interrupt = pca_isa_waitforinterrupt, | 98 | .wait_for_completion = pca_isa_waitforcompletion, |
99 | .reset_chip = pca_isa_resetchip, | ||
113 | }; | 100 | }; |
114 | 101 | ||
115 | static struct i2c_adapter pca_isa_ops = { | 102 | static struct i2c_adapter pca_isa_ops = { |
@@ -117,6 +104,7 @@ static struct i2c_adapter pca_isa_ops = { | |||
117 | .id = I2C_HW_A_ISA, | 104 | .id = I2C_HW_A_ISA, |
118 | .algo_data = &pca_isa_data, | 105 | .algo_data = &pca_isa_data, |
119 | .name = "PCA9564 ISA Adapter", | 106 | .name = "PCA9564 ISA Adapter", |
107 | .timeout = 100, | ||
120 | }; | 108 | }; |
121 | 109 | ||
122 | static int __devinit pca_isa_probe(struct device *dev, unsigned int id) | 110 | static int __devinit pca_isa_probe(struct device *dev, unsigned int id) |
@@ -144,6 +132,7 @@ static int __devinit pca_isa_probe(struct device *dev, unsigned int id) | |||
144 | } | 132 | } |
145 | } | 133 | } |
146 | 134 | ||
135 | pca_isa_data.i2c_clock = clock; | ||
147 | if (i2c_pca_add_bus(&pca_isa_ops) < 0) { | 136 | if (i2c_pca_add_bus(&pca_isa_ops) < 0) { |
148 | dev_err(dev, "Failed to add i2c bus\n"); | 137 | dev_err(dev, "Failed to add i2c bus\n"); |
149 | goto out_irq; | 138 | goto out_irq; |
@@ -178,7 +167,7 @@ static struct isa_driver pca_isa_driver = { | |||
178 | .remove = __devexit_p(pca_isa_remove), | 167 | .remove = __devexit_p(pca_isa_remove), |
179 | .driver = { | 168 | .driver = { |
180 | .owner = THIS_MODULE, | 169 | .owner = THIS_MODULE, |
181 | .name = "i2c-pca-isa", | 170 | .name = DRIVER, |
182 | } | 171 | } |
183 | }; | 172 | }; |
184 | 173 | ||
@@ -204,7 +193,5 @@ MODULE_PARM_DESC(irq, "IRQ"); | |||
204 | module_param(clock, int, 0); | 193 | module_param(clock, int, 0); |
205 | MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet"); | 194 | MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet"); |
206 | 195 | ||
207 | module_param(own, int, 0); /* the driver can't do slave mode, so there's no real point in this */ | ||
208 | |||
209 | module_init(pca_isa_init); | 196 | module_init(pca_isa_init); |
210 | module_exit(pca_isa_exit); | 197 | module_exit(pca_isa_exit); |