diff options
Diffstat (limited to 'drivers/i2c')
40 files changed, 2537 insertions, 545 deletions
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index 11935f66fcd8..96867347bcbf 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig | |||
@@ -2,10 +2,9 @@ | |||
2 | # I2C subsystem configuration | 2 | # I2C subsystem configuration |
3 | # | 3 | # |
4 | 4 | ||
5 | menu "I2C support" | 5 | menuconfig I2C |
6 | |||
7 | config I2C | ||
8 | tristate "I2C support" | 6 | tristate "I2C support" |
7 | depends on HAS_IOMEM | ||
9 | ---help--- | 8 | ---help--- |
10 | I2C (pronounce: I-square-C) is a slow serial bus protocol used in | 9 | I2C (pronounce: I-square-C) is a slow serial bus protocol used in |
11 | many micro controller applications and developed by Philips. SMBus, | 10 | many micro controller applications and developed by Philips. SMBus, |
@@ -22,9 +21,14 @@ config I2C | |||
22 | This I2C support can also be built as a module. If so, the module | 21 | This I2C support can also be built as a module. If so, the module |
23 | will be called i2c-core. | 22 | will be called i2c-core. |
24 | 23 | ||
24 | if I2C | ||
25 | |||
26 | config I2C_BOARDINFO | ||
27 | boolean | ||
28 | default y | ||
29 | |||
25 | config I2C_CHARDEV | 30 | config I2C_CHARDEV |
26 | tristate "I2C device interface" | 31 | tristate "I2C device interface" |
27 | depends on I2C | ||
28 | help | 32 | help |
29 | Say Y here to use i2c-* device files, usually found in the /dev | 33 | Say Y here to use i2c-* device files, usually found in the /dev |
30 | directory on your system. They make it possible to have user-space | 34 | directory on your system. They make it possible to have user-space |
@@ -40,7 +44,6 @@ source drivers/i2c/chips/Kconfig | |||
40 | 44 | ||
41 | config I2C_DEBUG_CORE | 45 | config I2C_DEBUG_CORE |
42 | bool "I2C Core debugging messages" | 46 | bool "I2C Core debugging messages" |
43 | depends on I2C | ||
44 | help | 47 | help |
45 | Say Y here if you want the I2C core to produce a bunch of debug | 48 | Say Y here if you want the I2C core to produce a bunch of debug |
46 | messages to the system log. Select this if you are having a | 49 | messages to the system log. Select this if you are having a |
@@ -48,7 +51,6 @@ config I2C_DEBUG_CORE | |||
48 | 51 | ||
49 | config I2C_DEBUG_ALGO | 52 | config I2C_DEBUG_ALGO |
50 | bool "I2C Algorithm debugging messages" | 53 | bool "I2C Algorithm debugging messages" |
51 | depends on I2C | ||
52 | help | 54 | help |
53 | Say Y here if you want the I2C algorithm drivers to produce a bunch | 55 | Say Y here if you want the I2C algorithm drivers to produce a bunch |
54 | of debug messages to the system log. Select this if you are having | 56 | of debug messages to the system log. Select this if you are having |
@@ -57,7 +59,6 @@ config I2C_DEBUG_ALGO | |||
57 | 59 | ||
58 | config I2C_DEBUG_BUS | 60 | config I2C_DEBUG_BUS |
59 | bool "I2C Bus debugging messages" | 61 | bool "I2C Bus debugging messages" |
60 | depends on I2C | ||
61 | help | 62 | help |
62 | Say Y here if you want the I2C bus drivers to produce a bunch of | 63 | Say Y here if you want the I2C bus drivers to produce a bunch of |
63 | debug messages to the system log. Select this if you are having | 64 | debug messages to the system log. Select this if you are having |
@@ -66,12 +67,10 @@ config I2C_DEBUG_BUS | |||
66 | 67 | ||
67 | config I2C_DEBUG_CHIP | 68 | config I2C_DEBUG_CHIP |
68 | bool "I2C Chip debugging messages" | 69 | bool "I2C Chip debugging messages" |
69 | depends on I2C | ||
70 | help | 70 | help |
71 | Say Y here if you want the I2C chip drivers to produce a bunch of | 71 | Say Y here if you want the I2C chip drivers to produce a bunch of |
72 | debug messages to the system log. Select this if you are having | 72 | debug messages to the system log. Select this if you are having |
73 | a problem with I2C support and want to see more of what is going | 73 | a problem with I2C support and want to see more of what is going |
74 | on. | 74 | on. |
75 | 75 | ||
76 | endmenu | 76 | endif # I2C |
77 | |||
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index 71c5a854ac5d..ba26e6cbe74e 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile | |||
@@ -2,6 +2,7 @@ | |||
2 | # Makefile for the i2c core. | 2 | # Makefile for the i2c core. |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o | ||
5 | obj-$(CONFIG_I2C) += i2c-core.o | 6 | obj-$(CONFIG_I2C) += i2c-core.o |
6 | obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o | 7 | obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o |
7 | obj-y += busses/ chips/ algos/ | 8 | obj-y += busses/ chips/ algos/ |
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig index af0203409dd1..58899078810b 100644 --- a/drivers/i2c/algos/Kconfig +++ b/drivers/i2c/algos/Kconfig | |||
@@ -3,11 +3,9 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | menu "I2C Algorithms" | 5 | menu "I2C Algorithms" |
6 | depends on I2C | ||
7 | 6 | ||
8 | config I2C_ALGOBIT | 7 | config I2C_ALGOBIT |
9 | tristate "I2C bit-banging interfaces" | 8 | tristate "I2C bit-banging interfaces" |
10 | depends on I2C | ||
11 | help | 9 | help |
12 | This allows you to use a range of I2C adapters called bit-banging | 10 | This allows you to use a range of I2C adapters called bit-banging |
13 | adapters. Say Y if you own an I2C adapter belonging to this class | 11 | adapters. Say Y if you own an I2C adapter belonging to this class |
@@ -18,7 +16,6 @@ config I2C_ALGOBIT | |||
18 | 16 | ||
19 | config I2C_ALGOPCF | 17 | config I2C_ALGOPCF |
20 | tristate "I2C PCF 8584 interfaces" | 18 | tristate "I2C PCF 8584 interfaces" |
21 | depends on I2C | ||
22 | help | 19 | help |
23 | This allows you to use a range of I2C adapters called PCF adapters. | 20 | This allows you to use a range of I2C adapters called PCF adapters. |
24 | Say Y if you own an I2C adapter belonging to this class and then say | 21 | Say Y if you own an I2C adapter belonging to this class and then say |
@@ -29,7 +26,6 @@ config I2C_ALGOPCF | |||
29 | 26 | ||
30 | config I2C_ALGOPCA | 27 | config I2C_ALGOPCA |
31 | tristate "I2C PCA 9564 interfaces" | 28 | tristate "I2C PCA 9564 interfaces" |
32 | depends on I2C | ||
33 | help | 29 | help |
34 | This allows you to use a range of I2C adapters called PCA adapters. | 30 | This allows you to use a range of I2C adapters called PCA adapters. |
35 | Say Y if you own an I2C adapter belonging to this class and then say | 31 | Say Y if you own an I2C adapter belonging to this class and then say |
@@ -40,11 +36,11 @@ config I2C_ALGOPCA | |||
40 | 36 | ||
41 | config I2C_ALGO8XX | 37 | config I2C_ALGO8XX |
42 | tristate "MPC8xx CPM I2C interface" | 38 | tristate "MPC8xx CPM I2C interface" |
43 | depends on 8xx && I2C | 39 | depends on 8xx |
44 | 40 | ||
45 | config I2C_ALGO_SGI | 41 | config I2C_ALGO_SGI |
46 | tristate "I2C SGI interfaces" | 42 | tristate "I2C SGI interfaces" |
47 | depends on I2C && (SGI_IP22 || SGI_IP32 || X86_VISWS) | 43 | depends on SGI_IP22 || SGI_IP32 || X86_VISWS |
48 | help | 44 | help |
49 | Supports the SGI interfaces like the ones found on SGI Indy VINO | 45 | Supports the SGI interfaces like the ones found on SGI Indy VINO |
50 | or SGI O2 MACE. | 46 | or SGI O2 MACE. |
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index 95aa5395a5be..8a5f5825bb72 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c | |||
@@ -33,19 +33,30 @@ | |||
33 | 33 | ||
34 | 34 | ||
35 | /* ----- global defines ----------------------------------------------- */ | 35 | /* ----- global defines ----------------------------------------------- */ |
36 | #define DEB(x) if (i2c_debug>=1) x; | ||
37 | #define DEB2(x) if (i2c_debug>=2) x; | ||
38 | #define DEBSTAT(x) if (i2c_debug>=3) x; /* print several statistical values*/ | ||
39 | #define DEBPROTO(x) if (i2c_debug>=9) { x; } | ||
40 | /* debug the protocol by showing transferred bits */ | ||
41 | 36 | ||
37 | #ifdef DEBUG | ||
38 | #define bit_dbg(level, dev, format, args...) \ | ||
39 | do { \ | ||
40 | if (i2c_debug >= level) \ | ||
41 | dev_dbg(dev, format, ##args); \ | ||
42 | } while (0) | ||
43 | #else | ||
44 | #define bit_dbg(level, dev, format, args...) \ | ||
45 | do {} while (0) | ||
46 | #endif /* DEBUG */ | ||
42 | 47 | ||
43 | /* ----- global variables --------------------------------------------- */ | 48 | /* ----- global variables --------------------------------------------- */ |
44 | 49 | ||
45 | /* module parameters: | ||
46 | */ | ||
47 | static int i2c_debug; | ||
48 | static int bit_test; /* see if the line-setting functions work */ | 50 | static int bit_test; /* see if the line-setting functions work */ |
51 | module_param(bit_test, bool, 0); | ||
52 | MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); | ||
53 | |||
54 | #ifdef DEBUG | ||
55 | static int i2c_debug = 1; | ||
56 | module_param(i2c_debug, int, S_IRUGO | S_IWUSR); | ||
57 | MODULE_PARM_DESC(i2c_debug, | ||
58 | "debug level - 0 off; 1 normal; 2 verbose; 3 very verbose"); | ||
59 | #endif | ||
49 | 60 | ||
50 | /* --- setting states on the bus with the right timing: --------------- */ | 61 | /* --- setting states on the bus with the right timing: --------------- */ |
51 | 62 | ||
@@ -57,19 +68,19 @@ static int bit_test; /* see if the line-setting functions work */ | |||
57 | static inline void sdalo(struct i2c_algo_bit_data *adap) | 68 | static inline void sdalo(struct i2c_algo_bit_data *adap) |
58 | { | 69 | { |
59 | setsda(adap,0); | 70 | setsda(adap,0); |
60 | udelay(adap->udelay); | 71 | udelay((adap->udelay + 1) / 2); |
61 | } | 72 | } |
62 | 73 | ||
63 | static inline void sdahi(struct i2c_algo_bit_data *adap) | 74 | static inline void sdahi(struct i2c_algo_bit_data *adap) |
64 | { | 75 | { |
65 | setsda(adap,1); | 76 | setsda(adap,1); |
66 | udelay(adap->udelay); | 77 | udelay((adap->udelay + 1) / 2); |
67 | } | 78 | } |
68 | 79 | ||
69 | static inline void scllo(struct i2c_algo_bit_data *adap) | 80 | static inline void scllo(struct i2c_algo_bit_data *adap) |
70 | { | 81 | { |
71 | setscl(adap,0); | 82 | setscl(adap,0); |
72 | udelay(adap->udelay); | 83 | udelay(adap->udelay / 2); |
73 | } | 84 | } |
74 | 85 | ||
75 | /* | 86 | /* |
@@ -98,7 +109,11 @@ static int sclhi(struct i2c_algo_bit_data *adap) | |||
98 | } | 109 | } |
99 | cond_resched(); | 110 | cond_resched(); |
100 | } | 111 | } |
101 | DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); | 112 | #ifdef DEBUG |
113 | if (jiffies != start && i2c_debug >= 3) | ||
114 | pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go " | ||
115 | "high\n", jiffies - start); | ||
116 | #endif | ||
102 | 117 | ||
103 | done: | 118 | done: |
104 | udelay(adap->udelay); | 119 | udelay(adap->udelay); |
@@ -110,30 +125,29 @@ done: | |||
110 | static void i2c_start(struct i2c_algo_bit_data *adap) | 125 | static void i2c_start(struct i2c_algo_bit_data *adap) |
111 | { | 126 | { |
112 | /* assert: scl, sda are high */ | 127 | /* assert: scl, sda are high */ |
113 | DEBPROTO(printk("S ")); | 128 | setsda(adap, 0); |
114 | sdalo(adap); | 129 | udelay(adap->udelay); |
115 | scllo(adap); | 130 | scllo(adap); |
116 | } | 131 | } |
117 | 132 | ||
118 | static void i2c_repstart(struct i2c_algo_bit_data *adap) | 133 | static void i2c_repstart(struct i2c_algo_bit_data *adap) |
119 | { | 134 | { |
120 | /* scl, sda may not be high */ | 135 | /* assert: scl is low */ |
121 | DEBPROTO(printk(" Sr ")); | 136 | sdahi(adap); |
122 | setsda(adap,1); | ||
123 | sclhi(adap); | 137 | sclhi(adap); |
124 | 138 | setsda(adap, 0); | |
125 | sdalo(adap); | 139 | udelay(adap->udelay); |
126 | scllo(adap); | 140 | scllo(adap); |
127 | } | 141 | } |
128 | 142 | ||
129 | 143 | ||
130 | static void i2c_stop(struct i2c_algo_bit_data *adap) | 144 | static void i2c_stop(struct i2c_algo_bit_data *adap) |
131 | { | 145 | { |
132 | DEBPROTO(printk("P\n")); | ||
133 | /* assert: scl is low */ | 146 | /* assert: scl is low */ |
134 | sdalo(adap); | 147 | sdalo(adap); |
135 | sclhi(adap); | 148 | sclhi(adap); |
136 | sdahi(adap); | 149 | setsda(adap, 1); |
150 | udelay(adap->udelay); | ||
137 | } | 151 | } |
138 | 152 | ||
139 | 153 | ||
@@ -145,7 +159,7 @@ static void i2c_stop(struct i2c_algo_bit_data *adap) | |||
145 | * 0 if the device did not ack | 159 | * 0 if the device did not ack |
146 | * -ETIMEDOUT if an error occurred (while raising the scl line) | 160 | * -ETIMEDOUT if an error occurred (while raising the scl line) |
147 | */ | 161 | */ |
148 | static int i2c_outb(struct i2c_adapter *i2c_adap, char c) | 162 | static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c) |
149 | { | 163 | { |
150 | int i; | 164 | int i; |
151 | int sb; | 165 | int sb; |
@@ -154,34 +168,32 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, char c) | |||
154 | 168 | ||
155 | /* assert: scl is low */ | 169 | /* assert: scl is low */ |
156 | for ( i=7 ; i>=0 ; i-- ) { | 170 | for ( i=7 ; i>=0 ; i-- ) { |
157 | sb = c & ( 1 << i ); | 171 | sb = (c >> i) & 1; |
158 | setsda(adap,sb); | 172 | setsda(adap,sb); |
159 | udelay(adap->udelay); | 173 | udelay((adap->udelay + 1) / 2); |
160 | DEBPROTO(printk(KERN_DEBUG "%d",sb!=0)); | ||
161 | if (sclhi(adap)<0) { /* timed out */ | 174 | if (sclhi(adap)<0) { /* timed out */ |
162 | sdahi(adap); /* we don't want to block the net */ | 175 | bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " |
163 | DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i)); | 176 | "timeout at bit #%d\n", (int)c, i); |
164 | return -ETIMEDOUT; | 177 | return -ETIMEDOUT; |
165 | }; | 178 | }; |
166 | /* do arbitration here: | 179 | /* do arbitration here: |
167 | * if ( sb && ! getsda(adap) ) -> ouch! Get out of here. | 180 | * if ( sb && ! getsda(adap) ) -> ouch! Get out of here. |
168 | */ | 181 | */ |
169 | setscl(adap, 0 ); | 182 | scllo(adap); |
170 | udelay(adap->udelay); | ||
171 | } | 183 | } |
172 | sdahi(adap); | 184 | sdahi(adap); |
173 | if (sclhi(adap)<0){ /* timeout */ | 185 | if (sclhi(adap)<0){ /* timeout */ |
174 | DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff)); | 186 | bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " |
175 | return -ETIMEDOUT; | 187 | "timeout at ack\n", (int)c); |
188 | return -ETIMEDOUT; | ||
176 | }; | 189 | }; |
177 | /* read ack: SDA should be pulled down by slave */ | 190 | /* read ack: SDA should be pulled down by slave */ |
178 | ack=getsda(adap); /* ack: sda is pulled low ->success. */ | 191 | ack = !getsda(adap); /* ack: sda is pulled low -> success */ |
179 | DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack)); | 192 | bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c, |
193 | ack ? "A" : "NA"); | ||
180 | 194 | ||
181 | DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) ); | ||
182 | DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") ); | ||
183 | scllo(adap); | 195 | scllo(adap); |
184 | return 0==ack; /* return 1 if device acked */ | 196 | return ack; |
185 | /* assert: scl is low (sda undef) */ | 197 | /* assert: scl is low (sda undef) */ |
186 | } | 198 | } |
187 | 199 | ||
@@ -198,19 +210,18 @@ static int i2c_inb(struct i2c_adapter *i2c_adap) | |||
198 | sdahi(adap); | 210 | sdahi(adap); |
199 | for (i=0;i<8;i++) { | 211 | for (i=0;i<8;i++) { |
200 | if (sclhi(adap)<0) { /* timeout */ | 212 | if (sclhi(adap)<0) { /* timeout */ |
201 | DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i)); | 213 | bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit " |
214 | "#%d\n", 7 - i); | ||
202 | return -ETIMEDOUT; | 215 | return -ETIMEDOUT; |
203 | }; | 216 | }; |
204 | indata *= 2; | 217 | indata *= 2; |
205 | if ( getsda(adap) ) | 218 | if ( getsda(adap) ) |
206 | indata |= 0x01; | 219 | indata |= 0x01; |
207 | scllo(adap); | 220 | setscl(adap, 0); |
221 | udelay(i == 7 ? adap->udelay / 2 : adap->udelay); | ||
208 | } | 222 | } |
209 | /* assert: scl is low */ | 223 | /* assert: scl is low */ |
210 | DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff)); | 224 | return indata; |
211 | |||
212 | DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff)); | ||
213 | return (int) (indata & 0xff); | ||
214 | } | 225 | } |
215 | 226 | ||
216 | /* | 227 | /* |
@@ -221,73 +232,67 @@ static int test_bus(struct i2c_algo_bit_data *adap, char* name) { | |||
221 | int scl,sda; | 232 | int scl,sda; |
222 | 233 | ||
223 | if (adap->getscl==NULL) | 234 | if (adap->getscl==NULL) |
224 | printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, " | 235 | pr_info("%s: Testing SDA only, SCL is not readable\n", name); |
225 | "SCL is not readable.\n"); | ||
226 | 236 | ||
227 | sda=getsda(adap); | 237 | sda=getsda(adap); |
228 | scl=(adap->getscl==NULL?1:getscl(adap)); | 238 | scl=(adap->getscl==NULL?1:getscl(adap)); |
229 | printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda); | ||
230 | if (!scl || !sda ) { | 239 | if (!scl || !sda ) { |
231 | printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name); | 240 | printk(KERN_WARNING "%s: bus seems to be busy\n", name); |
232 | goto bailout; | 241 | goto bailout; |
233 | } | 242 | } |
234 | 243 | ||
235 | sdalo(adap); | 244 | sdalo(adap); |
236 | sda=getsda(adap); | 245 | sda=getsda(adap); |
237 | scl=(adap->getscl==NULL?1:getscl(adap)); | 246 | scl=(adap->getscl==NULL?1:getscl(adap)); |
238 | printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda); | ||
239 | if ( 0 != sda ) { | 247 | if ( 0 != sda ) { |
240 | printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n"); | 248 | printk(KERN_WARNING "%s: SDA stuck high!\n", name); |
241 | goto bailout; | 249 | goto bailout; |
242 | } | 250 | } |
243 | if ( 0 == scl ) { | 251 | if ( 0 == scl ) { |
244 | printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low " | 252 | printk(KERN_WARNING "%s: SCL unexpected low " |
245 | "while pulling SDA low!\n"); | 253 | "while pulling SDA low!\n", name); |
246 | goto bailout; | 254 | goto bailout; |
247 | } | 255 | } |
248 | 256 | ||
249 | sdahi(adap); | 257 | sdahi(adap); |
250 | sda=getsda(adap); | 258 | sda=getsda(adap); |
251 | scl=(adap->getscl==NULL?1:getscl(adap)); | 259 | scl=(adap->getscl==NULL?1:getscl(adap)); |
252 | printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda); | ||
253 | if ( 0 == sda ) { | 260 | if ( 0 == sda ) { |
254 | printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n"); | 261 | printk(KERN_WARNING "%s: SDA stuck low!\n", name); |
255 | goto bailout; | 262 | goto bailout; |
256 | } | 263 | } |
257 | if ( 0 == scl ) { | 264 | if ( 0 == scl ) { |
258 | printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low " | 265 | printk(KERN_WARNING "%s: SCL unexpected low " |
259 | "while pulling SDA high!\n"); | 266 | "while pulling SDA high!\n", name); |
260 | goto bailout; | 267 | goto bailout; |
261 | } | 268 | } |
262 | 269 | ||
263 | scllo(adap); | 270 | scllo(adap); |
264 | sda=getsda(adap); | 271 | sda=getsda(adap); |
265 | scl=(adap->getscl==NULL?0:getscl(adap)); | 272 | scl=(adap->getscl==NULL?0:getscl(adap)); |
266 | printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda); | ||
267 | if ( 0 != scl ) { | 273 | if ( 0 != scl ) { |
268 | printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n"); | 274 | printk(KERN_WARNING "%s: SCL stuck high!\n", name); |
269 | goto bailout; | 275 | goto bailout; |
270 | } | 276 | } |
271 | if ( 0 == sda ) { | 277 | if ( 0 == sda ) { |
272 | printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low " | 278 | printk(KERN_WARNING "%s: SDA unexpected low " |
273 | "while pulling SCL low!\n"); | 279 | "while pulling SCL low!\n", name); |
274 | goto bailout; | 280 | goto bailout; |
275 | } | 281 | } |
276 | 282 | ||
277 | sclhi(adap); | 283 | sclhi(adap); |
278 | sda=getsda(adap); | 284 | sda=getsda(adap); |
279 | scl=(adap->getscl==NULL?1:getscl(adap)); | 285 | scl=(adap->getscl==NULL?1:getscl(adap)); |
280 | printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda); | ||
281 | if ( 0 == scl ) { | 286 | if ( 0 == scl ) { |
282 | printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n"); | 287 | printk(KERN_WARNING "%s: SCL stuck low!\n", name); |
283 | goto bailout; | 288 | goto bailout; |
284 | } | 289 | } |
285 | if ( 0 == sda ) { | 290 | if ( 0 == sda ) { |
286 | printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low " | 291 | printk(KERN_WARNING "%s: SDA unexpected low " |
287 | "while pulling SCL high!\n"); | 292 | "while pulling SCL high!\n", name); |
288 | goto bailout; | 293 | goto bailout; |
289 | } | 294 | } |
290 | printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name); | 295 | pr_info("%s: Test OK\n", name); |
291 | return 0; | 296 | return 0; |
292 | bailout: | 297 | bailout: |
293 | sdahi(adap); | 298 | sdahi(adap); |
@@ -312,44 +317,39 @@ static int try_address(struct i2c_adapter *i2c_adap, | |||
312 | int i,ret = -1; | 317 | int i,ret = -1; |
313 | for (i=0;i<=retries;i++) { | 318 | for (i=0;i<=retries;i++) { |
314 | ret = i2c_outb(i2c_adap,addr); | 319 | ret = i2c_outb(i2c_adap,addr); |
315 | if (ret==1) | 320 | if (ret == 1 || i == retries) |
316 | break; /* success! */ | ||
317 | i2c_stop(adap); | ||
318 | udelay(5/*adap->udelay*/); | ||
319 | if (i==retries) /* no success */ | ||
320 | break; | 321 | break; |
321 | i2c_start(adap); | 322 | bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); |
323 | i2c_stop(adap); | ||
322 | udelay(adap->udelay); | 324 | udelay(adap->udelay); |
325 | yield(); | ||
326 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); | ||
327 | i2c_start(adap); | ||
323 | } | 328 | } |
324 | DEB2(if (i) | 329 | if (i && ret) |
325 | printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n", | 330 | bit_dbg(1, &i2c_adap->dev, "Used %d tries to %s client at " |
326 | i+1, addr & 1 ? "read" : "write", addr>>1, | 331 | "0x%02x: %s\n", i + 1, |
327 | ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" ) | 332 | addr & 1 ? "read from" : "write to", addr >> 1, |
328 | ); | 333 | ret == 1 ? "success" : "failed, timeout?"); |
329 | return ret; | 334 | return ret; |
330 | } | 335 | } |
331 | 336 | ||
332 | static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | 337 | static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) |
333 | { | 338 | { |
334 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | 339 | const unsigned char *temp = msg->buf; |
335 | char c; | ||
336 | const char *temp = msg->buf; | ||
337 | int count = msg->len; | 340 | int count = msg->len; |
338 | unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; | 341 | unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; |
339 | int retval; | 342 | int retval; |
340 | int wrcount=0; | 343 | int wrcount=0; |
341 | 344 | ||
342 | while (count > 0) { | 345 | while (count > 0) { |
343 | c = *temp; | 346 | retval = i2c_outb(i2c_adap, *temp); |
344 | DEB2(dev_dbg(&i2c_adap->dev, "sendbytes: writing %2.2X\n", c&0xff)); | ||
345 | retval = i2c_outb(i2c_adap,c); | ||
346 | if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */ | 347 | if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */ |
347 | count--; | 348 | count--; |
348 | temp++; | 349 | temp++; |
349 | wrcount++; | 350 | wrcount++; |
350 | } else { /* arbitration or no acknowledge */ | 351 | } else { /* arbitration or no acknowledge */ |
351 | dev_err(&i2c_adap->dev, "sendbytes: error - bailout.\n"); | 352 | dev_err(&i2c_adap->dev, "sendbytes: error - bailout.\n"); |
352 | i2c_stop(adap); | ||
353 | return (retval<0)? retval : -EFAULT; | 353 | return (retval<0)? retval : -EFAULT; |
354 | /* got a better one ?? */ | 354 | /* got a better one ?? */ |
355 | } | 355 | } |
@@ -362,7 +362,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
362 | int inval; | 362 | int inval; |
363 | int rdcount=0; /* counts bytes read */ | 363 | int rdcount=0; /* counts bytes read */ |
364 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | 364 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; |
365 | char *temp = msg->buf; | 365 | unsigned char *temp = msg->buf; |
366 | int count = msg->len; | 366 | int count = msg->len; |
367 | 367 | ||
368 | while (count > 0) { | 368 | while (count > 0) { |
@@ -371,30 +371,44 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
371 | *temp = inval; | 371 | *temp = inval; |
372 | rdcount++; | 372 | rdcount++; |
373 | } else { /* read timed out */ | 373 | } else { /* read timed out */ |
374 | printk(KERN_ERR "i2c-algo-bit.o: readbytes: i2c_inb timed out.\n"); | ||
375 | break; | 374 | break; |
376 | } | 375 | } |
377 | 376 | ||
378 | temp++; | 377 | temp++; |
379 | count--; | 378 | count--; |
380 | 379 | ||
381 | if (msg->flags & I2C_M_NO_RD_ACK) | 380 | if (msg->flags & I2C_M_NO_RD_ACK) { |
381 | bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x\n", | ||
382 | inval); | ||
382 | continue; | 383 | continue; |
383 | |||
384 | if ( count > 0 ) { /* send ack */ | ||
385 | sdalo(adap); | ||
386 | DEBPROTO(printk(" Am ")); | ||
387 | } else { | ||
388 | sdahi(adap); /* neg. ack on last byte */ | ||
389 | DEBPROTO(printk(" NAm ")); | ||
390 | } | 384 | } |
385 | |||
386 | /* assert: sda is high */ | ||
387 | if (count) /* send ack */ | ||
388 | setsda(adap, 0); | ||
389 | udelay((adap->udelay + 1) / 2); | ||
390 | bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x %s\n", inval, | ||
391 | count ? "A" : "NA"); | ||
391 | if (sclhi(adap)<0) { /* timeout */ | 392 | if (sclhi(adap)<0) { /* timeout */ |
392 | sdahi(adap); | 393 | dev_err(&i2c_adap->dev, "readbytes: timeout at ack\n"); |
393 | printk(KERN_ERR "i2c-algo-bit.o: readbytes: Timeout at ack\n"); | ||
394 | return -ETIMEDOUT; | 394 | return -ETIMEDOUT; |
395 | }; | 395 | }; |
396 | scllo(adap); | 396 | scllo(adap); |
397 | sdahi(adap); | 397 | |
398 | /* Some SMBus transactions require that we receive the | ||
399 | transaction length as the first read byte. */ | ||
400 | if (rdcount == 1 && (msg->flags & I2C_M_RECV_LEN)) { | ||
401 | if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) { | ||
402 | dev_err(&i2c_adap->dev, "readbytes: invalid " | ||
403 | "block length (%d)\n", inval); | ||
404 | return -EREMOTEIO; | ||
405 | } | ||
406 | /* The original count value accounts for the extra | ||
407 | bytes, that is, either 1 for a regular transaction, | ||
408 | or 2 for a PEC transaction. */ | ||
409 | count += inval; | ||
410 | msg->len += inval; | ||
411 | } | ||
398 | } | 412 | } |
399 | return rdcount; | 413 | return rdcount; |
400 | } | 414 | } |
@@ -421,27 +435,31 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
421 | if ( (flags & I2C_M_TEN) ) { | 435 | if ( (flags & I2C_M_TEN) ) { |
422 | /* a ten bit address */ | 436 | /* a ten bit address */ |
423 | addr = 0xf0 | (( msg->addr >> 7) & 0x03); | 437 | addr = 0xf0 | (( msg->addr >> 7) & 0x03); |
424 | DEB2(printk(KERN_DEBUG "addr0: %d\n",addr)); | 438 | bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); |
425 | /* try extended address code...*/ | 439 | /* try extended address code...*/ |
426 | ret = try_address(i2c_adap, addr, retries); | 440 | ret = try_address(i2c_adap, addr, retries); |
427 | if ((ret != 1) && !nak_ok) { | 441 | if ((ret != 1) && !nak_ok) { |
428 | printk(KERN_ERR "died at extended address code.\n"); | 442 | dev_err(&i2c_adap->dev, |
443 | "died at extended address code\n"); | ||
429 | return -EREMOTEIO; | 444 | return -EREMOTEIO; |
430 | } | 445 | } |
431 | /* the remaining 8 bit address */ | 446 | /* the remaining 8 bit address */ |
432 | ret = i2c_outb(i2c_adap,msg->addr & 0x7f); | 447 | ret = i2c_outb(i2c_adap,msg->addr & 0x7f); |
433 | if ((ret != 1) && !nak_ok) { | 448 | if ((ret != 1) && !nak_ok) { |
434 | /* the chip did not ack / xmission error occurred */ | 449 | /* the chip did not ack / xmission error occurred */ |
435 | printk(KERN_ERR "died at 2nd address code.\n"); | 450 | dev_err(&i2c_adap->dev, "died at 2nd address code\n"); |
436 | return -EREMOTEIO; | 451 | return -EREMOTEIO; |
437 | } | 452 | } |
438 | if ( flags & I2C_M_RD ) { | 453 | if ( flags & I2C_M_RD ) { |
454 | bit_dbg(3, &i2c_adap->dev, "emitting repeated " | ||
455 | "start condition\n"); | ||
439 | i2c_repstart(adap); | 456 | i2c_repstart(adap); |
440 | /* okay, now switch into reading mode */ | 457 | /* okay, now switch into reading mode */ |
441 | addr |= 0x01; | 458 | addr |= 0x01; |
442 | ret = try_address(i2c_adap, addr, retries); | 459 | ret = try_address(i2c_adap, addr, retries); |
443 | if ((ret!=1) && !nak_ok) { | 460 | if ((ret!=1) && !nak_ok) { |
444 | printk(KERN_ERR "died at extended address code.\n"); | 461 | dev_err(&i2c_adap->dev, |
462 | "died at repeated address code\n"); | ||
445 | return -EREMOTEIO; | 463 | return -EREMOTEIO; |
446 | } | 464 | } |
447 | } | 465 | } |
@@ -468,44 +486,62 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
468 | int i,ret; | 486 | int i,ret; |
469 | unsigned short nak_ok; | 487 | unsigned short nak_ok; |
470 | 488 | ||
489 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); | ||
471 | i2c_start(adap); | 490 | i2c_start(adap); |
472 | for (i=0;i<num;i++) { | 491 | for (i=0;i<num;i++) { |
473 | pmsg = &msgs[i]; | 492 | pmsg = &msgs[i]; |
474 | nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; | 493 | nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; |
475 | if (!(pmsg->flags & I2C_M_NOSTART)) { | 494 | if (!(pmsg->flags & I2C_M_NOSTART)) { |
476 | if (i) { | 495 | if (i) { |
496 | bit_dbg(3, &i2c_adap->dev, "emitting " | ||
497 | "repeated start condition\n"); | ||
477 | i2c_repstart(adap); | 498 | i2c_repstart(adap); |
478 | } | 499 | } |
479 | ret = bit_doAddress(i2c_adap, pmsg); | 500 | ret = bit_doAddress(i2c_adap, pmsg); |
480 | if ((ret != 0) && !nak_ok) { | 501 | if ((ret != 0) && !nak_ok) { |
481 | DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n" | 502 | bit_dbg(1, &i2c_adap->dev, "NAK from " |
482 | ,msgs[i].addr,i)); | 503 | "device addr 0x%02x msg #%d\n", |
483 | return (ret<0) ? ret : -EREMOTEIO; | 504 | msgs[i].addr, i); |
505 | goto bailout; | ||
484 | } | 506 | } |
485 | } | 507 | } |
486 | if (pmsg->flags & I2C_M_RD ) { | 508 | if (pmsg->flags & I2C_M_RD ) { |
487 | /* read bytes into buffer*/ | 509 | /* read bytes into buffer*/ |
488 | ret = readbytes(i2c_adap, pmsg); | 510 | ret = readbytes(i2c_adap, pmsg); |
489 | DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret)); | 511 | if (ret >= 1) |
490 | if (ret < pmsg->len ) { | 512 | bit_dbg(2, &i2c_adap->dev, "read %d byte%s\n", |
491 | return (ret<0)? ret : -EREMOTEIO; | 513 | ret, ret == 1 ? "" : "s"); |
514 | if (ret < pmsg->len) { | ||
515 | if (ret >= 0) | ||
516 | ret = -EREMOTEIO; | ||
517 | goto bailout; | ||
492 | } | 518 | } |
493 | } else { | 519 | } else { |
494 | /* write bytes from buffer */ | 520 | /* write bytes from buffer */ |
495 | ret = sendbytes(i2c_adap, pmsg); | 521 | ret = sendbytes(i2c_adap, pmsg); |
496 | DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret)); | 522 | if (ret >= 1) |
497 | if (ret < pmsg->len ) { | 523 | bit_dbg(2, &i2c_adap->dev, "wrote %d byte%s\n", |
498 | return (ret<0) ? ret : -EREMOTEIO; | 524 | ret, ret == 1 ? "" : "s"); |
525 | if (ret < pmsg->len) { | ||
526 | if (ret >= 0) | ||
527 | ret = -EREMOTEIO; | ||
528 | goto bailout; | ||
499 | } | 529 | } |
500 | } | 530 | } |
501 | } | 531 | } |
532 | ret = i; | ||
533 | |||
534 | bailout: | ||
535 | bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); | ||
502 | i2c_stop(adap); | 536 | i2c_stop(adap); |
503 | return num; | 537 | return ret; |
504 | } | 538 | } |
505 | 539 | ||
506 | static u32 bit_func(struct i2c_adapter *adap) | 540 | static u32 bit_func(struct i2c_adapter *adap) |
507 | { | 541 | { |
508 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | | 542 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | |
543 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | | ||
544 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | | ||
509 | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; | 545 | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; |
510 | } | 546 | } |
511 | 547 | ||
@@ -520,7 +556,7 @@ static const struct i2c_algorithm i2c_bit_algo = { | |||
520 | /* | 556 | /* |
521 | * registering functions to load algorithms at runtime | 557 | * registering functions to load algorithms at runtime |
522 | */ | 558 | */ |
523 | int i2c_bit_add_bus(struct i2c_adapter *adap) | 559 | static int i2c_bit_prepare_bus(struct i2c_adapter *adap) |
524 | { | 560 | { |
525 | struct i2c_algo_bit_data *bit_adap = adap->algo_data; | 561 | struct i2c_algo_bit_data *bit_adap = adap->algo_data; |
526 | 562 | ||
@@ -530,25 +566,39 @@ int i2c_bit_add_bus(struct i2c_adapter *adap) | |||
530 | return -ENODEV; | 566 | return -ENODEV; |
531 | } | 567 | } |
532 | 568 | ||
533 | DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); | ||
534 | |||
535 | /* register new adapter to i2c module... */ | 569 | /* register new adapter to i2c module... */ |
536 | adap->algo = &i2c_bit_algo; | 570 | adap->algo = &i2c_bit_algo; |
537 | 571 | ||
538 | adap->timeout = 100; /* default values, should */ | 572 | adap->timeout = 100; /* default values, should */ |
539 | adap->retries = 3; /* be replaced by defines */ | 573 | adap->retries = 3; /* be replaced by defines */ |
540 | 574 | ||
575 | return 0; | ||
576 | } | ||
577 | |||
578 | int i2c_bit_add_bus(struct i2c_adapter *adap) | ||
579 | { | ||
580 | int err; | ||
581 | |||
582 | err = i2c_bit_prepare_bus(adap); | ||
583 | if (err) | ||
584 | return err; | ||
585 | |||
541 | return i2c_add_adapter(adap); | 586 | return i2c_add_adapter(adap); |
542 | } | 587 | } |
543 | EXPORT_SYMBOL(i2c_bit_add_bus); | 588 | EXPORT_SYMBOL(i2c_bit_add_bus); |
544 | 589 | ||
590 | int i2c_bit_add_numbered_bus(struct i2c_adapter *adap) | ||
591 | { | ||
592 | int err; | ||
593 | |||
594 | err = i2c_bit_prepare_bus(adap); | ||
595 | if (err) | ||
596 | return err; | ||
597 | |||
598 | return i2c_add_numbered_adapter(adap); | ||
599 | } | ||
600 | EXPORT_SYMBOL(i2c_bit_add_numbered_bus); | ||
601 | |||
545 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); | 602 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); |
546 | MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); | 603 | MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); |
547 | MODULE_LICENSE("GPL"); | 604 | MODULE_LICENSE("GPL"); |
548 | |||
549 | module_param(bit_test, bool, 0); | ||
550 | module_param(i2c_debug, int, S_IRUGO | S_IWUSR); | ||
551 | |||
552 | MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); | ||
553 | MODULE_PARM_DESC(i2c_debug, | ||
554 | "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol"); | ||
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c index ac2d5053078a..6eaf145e1ada 100644 --- a/drivers/i2c/algos/i2c-algo-sgi.c +++ b/drivers/i2c/algos/i2c-algo-sgi.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * i2c-algo-sgi.c: i2c driver algorithms for SGI adapters. | 2 | * i2c-algo-sgi.c: i2c driver algorithm used by the VINO (SGI Indy) and |
3 | * | 3 | * MACE (SGI O2) chips. |
4 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | 5 | * This file is subject to the terms and conditions of the GNU General Public |
5 | * License version 2 as published by the Free Software Foundation. | 6 | * License version 2 as published by the Free Software Foundation. |
6 | * | 7 | * |
@@ -162,8 +163,8 @@ static const struct i2c_algorithm sgi_algo = { | |||
162 | .functionality = sgi_func, | 163 | .functionality = sgi_func, |
163 | }; | 164 | }; |
164 | 165 | ||
165 | /* | 166 | /* |
166 | * registering functions to load algorithms at runtime | 167 | * registering functions to load algorithms at runtime |
167 | */ | 168 | */ |
168 | int i2c_sgi_add_bus(struct i2c_adapter *adap) | 169 | int i2c_sgi_add_bus(struct i2c_adapter *adap) |
169 | { | 170 | { |
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index ece31d2c6c64..838dc1c19d61 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -3,11 +3,10 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | menu "I2C Hardware Bus support" | 5 | menu "I2C Hardware Bus support" |
6 | depends on I2C | ||
7 | 6 | ||
8 | config I2C_ALI1535 | 7 | config I2C_ALI1535 |
9 | tristate "ALI 1535" | 8 | tristate "ALI 1535" |
10 | depends on I2C && PCI | 9 | depends on PCI |
11 | help | 10 | help |
12 | If you say yes to this option, support will be included for the SMB | 11 | If you say yes to this option, support will be included for the SMB |
13 | Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB | 12 | Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB |
@@ -19,7 +18,7 @@ config I2C_ALI1535 | |||
19 | 18 | ||
20 | config I2C_ALI1563 | 19 | config I2C_ALI1563 |
21 | tristate "ALI 1563" | 20 | tristate "ALI 1563" |
22 | depends on I2C && PCI && EXPERIMENTAL | 21 | depends on PCI && EXPERIMENTAL |
23 | help | 22 | help |
24 | If you say yes to this option, support will be included for the SMB | 23 | If you say yes to this option, support will be included for the SMB |
25 | Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB | 24 | Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB |
@@ -31,7 +30,7 @@ config I2C_ALI1563 | |||
31 | 30 | ||
32 | config I2C_ALI15X3 | 31 | config I2C_ALI15X3 |
33 | tristate "ALI 15x3" | 32 | tristate "ALI 15x3" |
34 | depends on I2C && PCI | 33 | depends on PCI |
35 | help | 34 | help |
36 | If you say yes to this option, support will be included for the | 35 | If you say yes to this option, support will be included for the |
37 | Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces. | 36 | Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces. |
@@ -41,7 +40,7 @@ config I2C_ALI15X3 | |||
41 | 40 | ||
42 | config I2C_AMD756 | 41 | config I2C_AMD756 |
43 | tristate "AMD 756/766/768/8111 and nVidia nForce" | 42 | tristate "AMD 756/766/768/8111 and nVidia nForce" |
44 | depends on I2C && PCI | 43 | depends on PCI |
45 | help | 44 | help |
46 | If you say yes to this option, support will be included for the AMD | 45 | If you say yes to this option, support will be included for the AMD |
47 | 756/766/768 mainboard I2C interfaces. The driver also includes | 46 | 756/766/768 mainboard I2C interfaces. The driver also includes |
@@ -66,7 +65,7 @@ config I2C_AMD756_S4882 | |||
66 | 65 | ||
67 | config I2C_AMD8111 | 66 | config I2C_AMD8111 |
68 | tristate "AMD 8111" | 67 | tristate "AMD 8111" |
69 | depends on I2C && PCI | 68 | depends on PCI |
70 | help | 69 | help |
71 | If you say yes to this option, support will be included for the | 70 | If you say yes to this option, support will be included for the |
72 | second (SMBus 2.0) AMD 8111 mainboard I2C interface. | 71 | second (SMBus 2.0) AMD 8111 mainboard I2C interface. |
@@ -76,14 +75,14 @@ config I2C_AMD8111 | |||
76 | 75 | ||
77 | config I2C_AT91 | 76 | config I2C_AT91 |
78 | tristate "Atmel AT91 I2C Two-Wire interface (TWI)" | 77 | tristate "Atmel AT91 I2C Two-Wire interface (TWI)" |
79 | depends on I2C && ARCH_AT91 && EXPERIMENTAL | 78 | depends on ARCH_AT91 && EXPERIMENTAL |
80 | help | 79 | help |
81 | This supports the use of the I2C interface on Atmel AT91 | 80 | This supports the use of the I2C interface on Atmel AT91 |
82 | processors. | 81 | processors. |
83 | 82 | ||
84 | config I2C_AU1550 | 83 | config I2C_AU1550 |
85 | tristate "Au1550/Au1200 SMBus interface" | 84 | tristate "Au1550/Au1200 SMBus interface" |
86 | depends on I2C && (SOC_AU1550 || SOC_AU1200) | 85 | depends on SOC_AU1550 || SOC_AU1200 |
87 | help | 86 | help |
88 | If you say yes to this option, support will be included for the | 87 | If you say yes to this option, support will be included for the |
89 | Au1550 and Au1200 SMBus interface. | 88 | Au1550 and Au1200 SMBus interface. |
@@ -91,9 +90,25 @@ config I2C_AU1550 | |||
91 | This driver can also be built as a module. If so, the module | 90 | This driver can also be built as a module. If so, the module |
92 | will be called i2c-au1550. | 91 | will be called i2c-au1550. |
93 | 92 | ||
93 | config I2C_BLACKFIN_TWI | ||
94 | tristate "Blackfin TWI I2C support" | ||
95 | depends on BF534 || BF536 || BF537 | ||
96 | help | ||
97 | This is the TWI I2C device driver for Blackfin 534/536/537. | ||
98 | This driver can also be built as a module. If so, the module | ||
99 | will be called i2c-bfin-twi. | ||
100 | |||
101 | config I2C_BLACKFIN_TWI_CLK_KHZ | ||
102 | int "Blackfin TWI I2C clock (kHz)" | ||
103 | depends on I2C_BLACKFIN_TWI | ||
104 | range 10 400 | ||
105 | default 50 | ||
106 | help | ||
107 | The unit of the TWI clock is kHz. | ||
108 | |||
94 | config I2C_ELEKTOR | 109 | config I2C_ELEKTOR |
95 | tristate "Elektor ISA card" | 110 | tristate "Elektor ISA card" |
96 | depends on I2C && ISA && BROKEN_ON_SMP | 111 | depends on ISA && BROKEN_ON_SMP |
97 | select I2C_ALGOPCF | 112 | select I2C_ALGOPCF |
98 | help | 113 | help |
99 | This supports the PCF8584 ISA bus I2C adapter. Say Y if you own | 114 | This supports the PCF8584 ISA bus I2C adapter. Say Y if you own |
@@ -102,9 +117,17 @@ config I2C_ELEKTOR | |||
102 | This support is also available as a module. If so, the module | 117 | This support is also available as a module. If so, the module |
103 | will be called i2c-elektor. | 118 | will be called i2c-elektor. |
104 | 119 | ||
120 | config I2C_GPIO | ||
121 | tristate "GPIO-based bitbanging I2C" | ||
122 | depends on GENERIC_GPIO | ||
123 | select I2C_ALGOBIT | ||
124 | help | ||
125 | This is a very simple bitbanging I2C driver utilizing the | ||
126 | arch-neutral GPIO API to control the SCL and SDA lines. | ||
127 | |||
105 | config I2C_HYDRA | 128 | config I2C_HYDRA |
106 | tristate "CHRP Apple Hydra Mac I/O I2C interface" | 129 | tristate "CHRP Apple Hydra Mac I/O I2C interface" |
107 | depends on I2C && PCI && PPC_CHRP && EXPERIMENTAL | 130 | depends on PCI && PPC_CHRP && EXPERIMENTAL |
108 | select I2C_ALGOBIT | 131 | select I2C_ALGOBIT |
109 | help | 132 | help |
110 | This supports the use of the I2C interface in the Apple Hydra Mac | 133 | This supports the use of the I2C interface in the Apple Hydra Mac |
@@ -116,7 +139,7 @@ config I2C_HYDRA | |||
116 | 139 | ||
117 | config I2C_I801 | 140 | config I2C_I801 |
118 | tristate "Intel 82801 (ICH)" | 141 | tristate "Intel 82801 (ICH)" |
119 | depends on I2C && PCI | 142 | depends on PCI |
120 | help | 143 | help |
121 | If you say yes to this option, support will be included for the Intel | 144 | If you say yes to this option, support will be included for the Intel |
122 | 801 family of mainboard I2C interfaces. Specifically, the following | 145 | 801 family of mainboard I2C interfaces. Specifically, the following |
@@ -139,7 +162,7 @@ config I2C_I801 | |||
139 | 162 | ||
140 | config I2C_I810 | 163 | config I2C_I810 |
141 | tristate "Intel 810/815" | 164 | tristate "Intel 810/815" |
142 | depends on I2C && PCI | 165 | depends on PCI |
143 | select I2C_ALGOBIT | 166 | select I2C_ALGOBIT |
144 | help | 167 | help |
145 | If you say yes to this option, support will be included for the Intel | 168 | If you say yes to this option, support will be included for the Intel |
@@ -156,7 +179,7 @@ config I2C_I810 | |||
156 | 179 | ||
157 | config I2C_PXA | 180 | config I2C_PXA |
158 | tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)" | 181 | tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)" |
159 | depends on I2C && EXPERIMENTAL && ARCH_PXA | 182 | depends on EXPERIMENTAL && ARCH_PXA |
160 | help | 183 | help |
161 | If you have devices in the PXA I2C bus, say yes to this option. | 184 | If you have devices in the PXA I2C bus, say yes to this option. |
162 | This driver can also be built as a module. If so, the module | 185 | This driver can also be built as a module. If so, the module |
@@ -172,7 +195,7 @@ config I2C_PXA_SLAVE | |||
172 | 195 | ||
173 | config I2C_PIIX4 | 196 | config I2C_PIIX4 |
174 | tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)" | 197 | tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)" |
175 | depends on I2C && PCI | 198 | depends on PCI |
176 | help | 199 | help |
177 | If you say yes to this option, support will be included for the Intel | 200 | If you say yes to this option, support will be included for the Intel |
178 | PIIX4 family of mainboard I2C interfaces. Specifically, the following | 201 | PIIX4 family of mainboard I2C interfaces. Specifically, the following |
@@ -195,7 +218,7 @@ config I2C_PIIX4 | |||
195 | 218 | ||
196 | config I2C_IBM_IIC | 219 | config I2C_IBM_IIC |
197 | tristate "IBM PPC 4xx on-chip I2C interface" | 220 | tristate "IBM PPC 4xx on-chip I2C interface" |
198 | depends on IBM_OCP && I2C | 221 | depends on IBM_OCP |
199 | help | 222 | help |
200 | Say Y here if you want to use IIC peripheral found on | 223 | Say Y here if you want to use IIC peripheral found on |
201 | embedded IBM PPC 4xx based systems. | 224 | embedded IBM PPC 4xx based systems. |
@@ -205,7 +228,7 @@ config I2C_IBM_IIC | |||
205 | 228 | ||
206 | config I2C_IOP3XX | 229 | config I2C_IOP3XX |
207 | tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" | 230 | tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" |
208 | depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX) && I2C | 231 | depends on ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX |
209 | help | 232 | help |
210 | Say Y here if you want to use the IIC bus controller on | 233 | Say Y here if you want to use the IIC bus controller on |
211 | the Intel IOPx3xx I/O Processors or IXP4xx Network Processors. | 234 | the Intel IOPx3xx I/O Processors or IXP4xx Network Processors. |
@@ -215,11 +238,10 @@ config I2C_IOP3XX | |||
215 | 238 | ||
216 | config I2C_ISA | 239 | config I2C_ISA |
217 | tristate | 240 | tristate |
218 | depends on I2C | ||
219 | 241 | ||
220 | config I2C_IXP4XX | 242 | config I2C_IXP4XX |
221 | tristate "IXP4xx GPIO-Based I2C Interface" | 243 | tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)" |
222 | depends on I2C && ARCH_IXP4XX | 244 | depends on ARCH_IXP4XX |
223 | select I2C_ALGOBIT | 245 | select I2C_ALGOBIT |
224 | help | 246 | help |
225 | Say Y here if you have an Intel IXP4xx(420,421,422,425) based | 247 | Say Y here if you have an Intel IXP4xx(420,421,422,425) based |
@@ -228,9 +250,12 @@ config I2C_IXP4XX | |||
228 | This support is also available as a module. If so, the module | 250 | This support is also available as a module. If so, the module |
229 | will be called i2c-ixp4xx. | 251 | will be called i2c-ixp4xx. |
230 | 252 | ||
253 | This driver is deprecated and will be dropped soon. Use i2c-gpio | ||
254 | instead. | ||
255 | |||
231 | config I2C_IXP2000 | 256 | config I2C_IXP2000 |
232 | tristate "IXP2000 GPIO-Based I2C Interface" | 257 | tristate "IXP2000 GPIO-Based I2C Interface (DEPRECATED)" |
233 | depends on I2C && ARCH_IXP2000 | 258 | depends on ARCH_IXP2000 |
234 | select I2C_ALGOBIT | 259 | select I2C_ALGOBIT |
235 | help | 260 | help |
236 | Say Y here if you have an Intel IXP2000(2400, 2800, 2850) based | 261 | Say Y here if you have an Intel IXP2000(2400, 2800, 2850) based |
@@ -239,9 +264,12 @@ config I2C_IXP2000 | |||
239 | This support is also available as a module. If so, the module | 264 | This support is also available as a module. If so, the module |
240 | will be called i2c-ixp2000. | 265 | will be called i2c-ixp2000. |
241 | 266 | ||
267 | This driver is deprecated and will be dropped soon. Use i2c-gpio | ||
268 | instead. | ||
269 | |||
242 | config I2C_POWERMAC | 270 | config I2C_POWERMAC |
243 | tristate "Powermac I2C interface" | 271 | tristate "Powermac I2C interface" |
244 | depends on I2C && PPC_PMAC | 272 | depends on PPC_PMAC |
245 | default y | 273 | default y |
246 | help | 274 | help |
247 | This exposes the various PowerMac i2c interfaces to the linux i2c | 275 | This exposes the various PowerMac i2c interfaces to the linux i2c |
@@ -253,7 +281,7 @@ config I2C_POWERMAC | |||
253 | 281 | ||
254 | config I2C_MPC | 282 | config I2C_MPC |
255 | tristate "MPC107/824x/85xx/52xx/86xx" | 283 | tristate "MPC107/824x/85xx/52xx/86xx" |
256 | depends on I2C && PPC32 | 284 | depends on PPC32 |
257 | help | 285 | help |
258 | If you say yes to this option, support will be included for the | 286 | If you say yes to this option, support will be included for the |
259 | built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and | 287 | built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and |
@@ -265,7 +293,7 @@ config I2C_MPC | |||
265 | 293 | ||
266 | config I2C_NFORCE2 | 294 | config I2C_NFORCE2 |
267 | tristate "Nvidia nForce2, nForce3 and nForce4" | 295 | tristate "Nvidia nForce2, nForce3 and nForce4" |
268 | depends on I2C && PCI | 296 | depends on PCI |
269 | help | 297 | help |
270 | If you say yes to this option, support will be included for the Nvidia | 298 | If you say yes to this option, support will be included for the Nvidia |
271 | nForce2, nForce3 and nForce4 families of mainboard I2C interfaces. | 299 | nForce2, nForce3 and nForce4 families of mainboard I2C interfaces. |
@@ -275,7 +303,7 @@ config I2C_NFORCE2 | |||
275 | 303 | ||
276 | config I2C_OCORES | 304 | config I2C_OCORES |
277 | tristate "OpenCores I2C Controller" | 305 | tristate "OpenCores I2C Controller" |
278 | depends on I2C && EXPERIMENTAL | 306 | depends on EXPERIMENTAL |
279 | help | 307 | help |
280 | If you say yes to this option, support will be included for the | 308 | If you say yes to this option, support will be included for the |
281 | OpenCores I2C controller. For details see | 309 | OpenCores I2C controller. For details see |
@@ -286,7 +314,7 @@ config I2C_OCORES | |||
286 | 314 | ||
287 | config I2C_OMAP | 315 | config I2C_OMAP |
288 | tristate "OMAP I2C adapter" | 316 | tristate "OMAP I2C adapter" |
289 | depends on I2C && ARCH_OMAP | 317 | depends on ARCH_OMAP |
290 | default y if MACH_OMAP_H3 || MACH_OMAP_OSK | 318 | default y if MACH_OMAP_H3 || MACH_OMAP_OSK |
291 | help | 319 | help |
292 | If you say yes to this option, support will be included for the | 320 | If you say yes to this option, support will be included for the |
@@ -296,7 +324,7 @@ config I2C_OMAP | |||
296 | 324 | ||
297 | config I2C_PARPORT | 325 | config I2C_PARPORT |
298 | tristate "Parallel port adapter" | 326 | tristate "Parallel port adapter" |
299 | depends on I2C && PARPORT | 327 | depends on PARPORT |
300 | select I2C_ALGOBIT | 328 | select I2C_ALGOBIT |
301 | help | 329 | help |
302 | This supports parallel port I2C adapters such as the ones made by | 330 | This supports parallel port I2C adapters such as the ones made by |
@@ -320,7 +348,6 @@ config I2C_PARPORT | |||
320 | 348 | ||
321 | config I2C_PARPORT_LIGHT | 349 | config I2C_PARPORT_LIGHT |
322 | tristate "Parallel port adapter (light)" | 350 | tristate "Parallel port adapter (light)" |
323 | depends on I2C | ||
324 | select I2C_ALGOBIT | 351 | select I2C_ALGOBIT |
325 | help | 352 | help |
326 | This supports parallel port I2C adapters such as the ones made by | 353 | This supports parallel port I2C adapters such as the ones made by |
@@ -344,13 +371,13 @@ config I2C_PARPORT_LIGHT | |||
344 | 371 | ||
345 | config I2C_PASEMI | 372 | config I2C_PASEMI |
346 | tristate "PA Semi SMBus interface" | 373 | tristate "PA Semi SMBus interface" |
347 | depends on PPC_PASEMI && I2C && PCI | 374 | depends on PPC_PASEMI && PCI |
348 | help | 375 | help |
349 | Supports the PA Semi PWRficient on-chip SMBus interfaces. | 376 | Supports the PA Semi PWRficient on-chip SMBus interfaces. |
350 | 377 | ||
351 | config I2C_PROSAVAGE | 378 | config I2C_PROSAVAGE |
352 | tristate "S3/VIA (Pro)Savage" | 379 | tristate "S3/VIA (Pro)Savage" |
353 | depends on I2C && PCI | 380 | depends on PCI |
354 | select I2C_ALGOBIT | 381 | select I2C_ALGOBIT |
355 | help | 382 | help |
356 | If you say yes to this option, support will be included for the | 383 | If you say yes to this option, support will be included for the |
@@ -365,19 +392,19 @@ config I2C_PROSAVAGE | |||
365 | 392 | ||
366 | config I2C_RPXLITE | 393 | config I2C_RPXLITE |
367 | tristate "Embedded Planet RPX Lite/Classic support" | 394 | tristate "Embedded Planet RPX Lite/Classic support" |
368 | depends on (RPXLITE || RPXCLASSIC) && I2C | 395 | depends on RPXLITE || RPXCLASSIC |
369 | select I2C_ALGO8XX | 396 | select I2C_ALGO8XX |
370 | 397 | ||
371 | config I2C_S3C2410 | 398 | config I2C_S3C2410 |
372 | tristate "S3C2410 I2C Driver" | 399 | tristate "S3C2410 I2C Driver" |
373 | depends on I2C && ARCH_S3C2410 | 400 | depends on ARCH_S3C2410 |
374 | help | 401 | help |
375 | Say Y here to include support for I2C controller in the | 402 | Say Y here to include support for I2C controller in the |
376 | Samsung S3C2410 based System-on-Chip devices. | 403 | Samsung S3C2410 based System-on-Chip devices. |
377 | 404 | ||
378 | config I2C_SAVAGE4 | 405 | config I2C_SAVAGE4 |
379 | tristate "S3 Savage 4" | 406 | tristate "S3 Savage 4" |
380 | depends on I2C && PCI && EXPERIMENTAL | 407 | depends on PCI && EXPERIMENTAL |
381 | select I2C_ALGOBIT | 408 | select I2C_ALGOBIT |
382 | help | 409 | help |
383 | If you say yes to this option, support will be included for the | 410 | If you say yes to this option, support will be included for the |
@@ -388,13 +415,25 @@ config I2C_SAVAGE4 | |||
388 | 415 | ||
389 | config I2C_SIBYTE | 416 | config I2C_SIBYTE |
390 | tristate "SiByte SMBus interface" | 417 | tristate "SiByte SMBus interface" |
391 | depends on SIBYTE_SB1xxx_SOC && I2C | 418 | depends on SIBYTE_SB1xxx_SOC |
392 | help | 419 | help |
393 | Supports the SiByte SOC on-chip I2C interfaces (2 channels). | 420 | Supports the SiByte SOC on-chip I2C interfaces (2 channels). |
394 | 421 | ||
422 | config I2C_SIMTEC | ||
423 | tristate "Simtec Generic I2C interface" | ||
424 | select I2C_ALGOBIT | ||
425 | help | ||
426 | If you say yes to this option, support will be inclyded for | ||
427 | the Simtec Generic I2C interface. This driver is for the | ||
428 | simple I2C bus used on newer Simtec products for general | ||
429 | I2C, such as DDC on the Simtec BBD2016A. | ||
430 | |||
431 | This driver can also be build as a module. If so, the module | ||
432 | will be called i2c-simtec. | ||
433 | |||
395 | config SCx200_I2C | 434 | config SCx200_I2C |
396 | tristate "NatSemi SCx200 I2C using GPIO pins" | 435 | tristate "NatSemi SCx200 I2C using GPIO pins (DEPRECATED)" |
397 | depends on SCx200_GPIO && I2C | 436 | depends on SCx200_GPIO |
398 | select I2C_ALGOBIT | 437 | select I2C_ALGOBIT |
399 | help | 438 | help |
400 | Enable the use of two GPIO pins of a SCx200 processor as an I2C bus. | 439 | Enable the use of two GPIO pins of a SCx200 processor as an I2C bus. |
@@ -404,6 +443,9 @@ config SCx200_I2C | |||
404 | This support is also available as a module. If so, the module | 443 | This support is also available as a module. If so, the module |
405 | will be called scx200_i2c. | 444 | will be called scx200_i2c. |
406 | 445 | ||
446 | This driver is deprecated and will be dropped soon. Use i2c-gpio | ||
447 | (or scx200_acb) instead. | ||
448 | |||
407 | config SCx200_I2C_SCL | 449 | config SCx200_I2C_SCL |
408 | int "GPIO pin used for SCL" | 450 | int "GPIO pin used for SCL" |
409 | depends on SCx200_I2C | 451 | depends on SCx200_I2C |
@@ -422,7 +464,7 @@ config SCx200_I2C_SDA | |||
422 | 464 | ||
423 | config SCx200_ACB | 465 | config SCx200_ACB |
424 | tristate "Geode ACCESS.bus support" | 466 | tristate "Geode ACCESS.bus support" |
425 | depends on X86_32 && I2C && PCI | 467 | depends on X86_32 && PCI |
426 | help | 468 | help |
427 | Enable the use of the ACCESS.bus controllers on the Geode SCx200 and | 469 | Enable the use of the ACCESS.bus controllers on the Geode SCx200 and |
428 | SC1100 processors and the CS5535 and CS5536 Geode companion devices. | 470 | SC1100 processors and the CS5535 and CS5536 Geode companion devices. |
@@ -434,7 +476,7 @@ config SCx200_ACB | |||
434 | 476 | ||
435 | config I2C_SIS5595 | 477 | config I2C_SIS5595 |
436 | tristate "SiS 5595" | 478 | tristate "SiS 5595" |
437 | depends on I2C && PCI | 479 | depends on PCI |
438 | help | 480 | help |
439 | If you say yes to this option, support will be included for the | 481 | If you say yes to this option, support will be included for the |
440 | SiS5595 SMBus (a subset of I2C) interface. | 482 | SiS5595 SMBus (a subset of I2C) interface. |
@@ -444,7 +486,7 @@ config I2C_SIS5595 | |||
444 | 486 | ||
445 | config I2C_SIS630 | 487 | config I2C_SIS630 |
446 | tristate "SiS 630/730" | 488 | tristate "SiS 630/730" |
447 | depends on I2C && PCI | 489 | depends on PCI |
448 | help | 490 | help |
449 | If you say yes to this option, support will be included for the | 491 | If you say yes to this option, support will be included for the |
450 | SiS630 and SiS730 SMBus (a subset of I2C) interface. | 492 | SiS630 and SiS730 SMBus (a subset of I2C) interface. |
@@ -454,7 +496,7 @@ config I2C_SIS630 | |||
454 | 496 | ||
455 | config I2C_SIS96X | 497 | config I2C_SIS96X |
456 | tristate "SiS 96x" | 498 | tristate "SiS 96x" |
457 | depends on I2C && PCI | 499 | depends on PCI |
458 | help | 500 | help |
459 | If you say yes to this option, support will be included for the SiS | 501 | If you say yes to this option, support will be included for the SiS |
460 | 96x SMBus (a subset of I2C) interfaces. Specifically, the following | 502 | 96x SMBus (a subset of I2C) interfaces. Specifically, the following |
@@ -472,7 +514,7 @@ config I2C_SIS96X | |||
472 | 514 | ||
473 | config I2C_STUB | 515 | config I2C_STUB |
474 | tristate "I2C/SMBus Test Stub" | 516 | tristate "I2C/SMBus Test Stub" |
475 | depends on I2C && EXPERIMENTAL && 'm' | 517 | depends on EXPERIMENTAL && m |
476 | default 'n' | 518 | default 'n' |
477 | help | 519 | help |
478 | This module may be useful to developers of SMBus client drivers, | 520 | This module may be useful to developers of SMBus client drivers, |
@@ -483,9 +525,20 @@ config I2C_STUB | |||
483 | 525 | ||
484 | If you don't know what to do here, definitely say N. | 526 | If you don't know what to do here, definitely say N. |
485 | 527 | ||
528 | config I2C_TINY_USB | ||
529 | tristate "I2C-Tiny-USB" | ||
530 | depends on USB | ||
531 | help | ||
532 | If you say yes to this option, support will be included for the | ||
533 | i2c-tiny-usb, a simple do-it-yourself USB to I2C interface. See | ||
534 | http://www.harbaum.org/till/i2c_tiny_usb for hardware details. | ||
535 | |||
536 | This driver can also be built as a module. If so, the module | ||
537 | will be called i2c-tiny-usb. | ||
538 | |||
486 | config I2C_VERSATILE | 539 | config I2C_VERSATILE |
487 | tristate "ARM Versatile/Realview I2C bus support" | 540 | tristate "ARM Versatile/Realview I2C bus support" |
488 | depends on I2C && (ARCH_VERSATILE || ARCH_REALVIEW) | 541 | depends on ARCH_VERSATILE || ARCH_REALVIEW |
489 | select I2C_ALGOBIT | 542 | select I2C_ALGOBIT |
490 | help | 543 | help |
491 | Say yes if you want to support the I2C serial bus on ARMs Versatile | 544 | Say yes if you want to support the I2C serial bus on ARMs Versatile |
@@ -496,7 +549,7 @@ config I2C_VERSATILE | |||
496 | 549 | ||
497 | config I2C_ACORN | 550 | config I2C_ACORN |
498 | bool "Acorn IOC/IOMD I2C bus support" | 551 | bool "Acorn IOC/IOMD I2C bus support" |
499 | depends on I2C && ARCH_ACORN | 552 | depends on ARCH_ACORN |
500 | default y | 553 | default y |
501 | select I2C_ALGOBIT | 554 | select I2C_ALGOBIT |
502 | help | 555 | help |
@@ -506,7 +559,7 @@ config I2C_ACORN | |||
506 | 559 | ||
507 | config I2C_VIA | 560 | config I2C_VIA |
508 | tristate "VIA 82C586B" | 561 | tristate "VIA 82C586B" |
509 | depends on I2C && PCI && EXPERIMENTAL | 562 | depends on PCI && EXPERIMENTAL |
510 | select I2C_ALGOBIT | 563 | select I2C_ALGOBIT |
511 | help | 564 | help |
512 | If you say yes to this option, support will be included for the VIA | 565 | If you say yes to this option, support will be included for the VIA |
@@ -517,7 +570,7 @@ config I2C_VIA | |||
517 | 570 | ||
518 | config I2C_VIAPRO | 571 | config I2C_VIAPRO |
519 | tristate "VIA VT82C596/82C686/82xx and CX700" | 572 | tristate "VIA VT82C596/82C686/82xx and CX700" |
520 | depends on I2C && PCI | 573 | depends on PCI |
521 | help | 574 | help |
522 | If you say yes to this option, support will be included for the VIA | 575 | If you say yes to this option, support will be included for the VIA |
523 | VT82C596 and later SMBus interface. Specifically, the following | 576 | VT82C596 and later SMBus interface. Specifically, the following |
@@ -536,7 +589,7 @@ config I2C_VIAPRO | |||
536 | 589 | ||
537 | config I2C_VOODOO3 | 590 | config I2C_VOODOO3 |
538 | tristate "Voodoo 3" | 591 | tristate "Voodoo 3" |
539 | depends on I2C && PCI | 592 | depends on PCI |
540 | select I2C_ALGOBIT | 593 | select I2C_ALGOBIT |
541 | help | 594 | help |
542 | If you say yes to this option, support will be included for the | 595 | If you say yes to this option, support will be included for the |
@@ -547,7 +600,7 @@ config I2C_VOODOO3 | |||
547 | 600 | ||
548 | config I2C_PCA_ISA | 601 | config I2C_PCA_ISA |
549 | tristate "PCA9564 on an ISA bus" | 602 | tristate "PCA9564 on an ISA bus" |
550 | depends on I2C | 603 | depends on ISA |
551 | select I2C_ALGOPCA | 604 | select I2C_ALGOPCA |
552 | default n | 605 | default n |
553 | help | 606 | help |
@@ -564,7 +617,7 @@ config I2C_PCA_ISA | |||
564 | 617 | ||
565 | config I2C_MV64XXX | 618 | config I2C_MV64XXX |
566 | tristate "Marvell mv64xxx I2C Controller" | 619 | tristate "Marvell mv64xxx I2C Controller" |
567 | depends on I2C && MV64X60 && EXPERIMENTAL | 620 | depends on MV64X60 && EXPERIMENTAL |
568 | help | 621 | help |
569 | If you say yes to this option, support will be included for the | 622 | If you say yes to this option, support will be included for the |
570 | built-in I2C interface on the Marvell 64xxx line of host bridges. | 623 | built-in I2C interface on the Marvell 64xxx line of host bridges. |
@@ -574,7 +627,7 @@ config I2C_MV64XXX | |||
574 | 627 | ||
575 | config I2C_PNX | 628 | config I2C_PNX |
576 | tristate "I2C bus support for Philips PNX targets" | 629 | tristate "I2C bus support for Philips PNX targets" |
577 | depends on ARCH_PNX4008 && I2C | 630 | depends on ARCH_PNX4008 |
578 | help | 631 | help |
579 | This driver supports the Philips IP3204 I2C IP block master and/or | 632 | This driver supports the Philips IP3204 I2C IP block master and/or |
580 | slave controller | 633 | slave controller |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 290b54018354..14d1432f698b 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
@@ -10,7 +10,9 @@ obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o | |||
10 | obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o | 10 | obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o |
11 | obj-$(CONFIG_I2C_AT91) += i2c-at91.o | 11 | obj-$(CONFIG_I2C_AT91) += i2c-at91.o |
12 | obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o | 12 | obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o |
13 | obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o | ||
13 | obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o | 14 | obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o |
15 | obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o | ||
14 | obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o | 16 | obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o |
15 | obj-$(CONFIG_I2C_I801) += i2c-i801.o | 17 | obj-$(CONFIG_I2C_I801) += i2c-i801.o |
16 | obj-$(CONFIG_I2C_I810) += i2c-i810.o | 18 | obj-$(CONFIG_I2C_I810) += i2c-i810.o |
@@ -37,10 +39,12 @@ obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o | |||
37 | obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o | 39 | obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o |
38 | obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o | 40 | obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o |
39 | obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o | 41 | obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o |
42 | obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o | ||
40 | obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o | 43 | obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o |
41 | obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o | 44 | obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o |
42 | obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o | 45 | obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o |
43 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o | 46 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o |
47 | obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o | ||
44 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o | 48 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o |
45 | obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o | 49 | obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o |
46 | obj-$(CONFIG_I2C_VIA) += i2c-via.o | 50 | obj-$(CONFIG_I2C_VIA) += i2c-via.o |
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c index 1e277ba5a9f3..f14372ac2fc5 100644 --- a/drivers/i2c/busses/i2c-ali1535.c +++ b/drivers/i2c/busses/i2c-ali1535.c | |||
@@ -497,7 +497,7 @@ static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_ | |||
497 | /* set up the sysfs linkage to our parent device */ | 497 | /* set up the sysfs linkage to our parent device */ |
498 | ali1535_adapter.dev.parent = &dev->dev; | 498 | ali1535_adapter.dev.parent = &dev->dev; |
499 | 499 | ||
500 | snprintf(ali1535_adapter.name, I2C_NAME_SIZE, | 500 | snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name), |
501 | "SMBus ALI1535 adapter at %04x", ali1535_smba); | 501 | "SMBus ALI1535 adapter at %04x", ali1535_smba); |
502 | return i2c_add_adapter(&ali1535_adapter); | 502 | return i2c_add_adapter(&ali1535_adapter); |
503 | } | 503 | } |
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c index e47fe01bf42a..93bf87d70961 100644 --- a/drivers/i2c/busses/i2c-ali15x3.c +++ b/drivers/i2c/busses/i2c-ali15x3.c | |||
@@ -492,7 +492,7 @@ static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_ | |||
492 | /* set up the sysfs linkage to our parent device */ | 492 | /* set up the sysfs linkage to our parent device */ |
493 | ali15x3_adapter.dev.parent = &dev->dev; | 493 | ali15x3_adapter.dev.parent = &dev->dev; |
494 | 494 | ||
495 | snprintf(ali15x3_adapter.name, I2C_NAME_SIZE, | 495 | snprintf(ali15x3_adapter.name, sizeof(ali15x3_adapter.name), |
496 | "SMBus ALI15X3 adapter at %04x", ali15x3_smba); | 496 | "SMBus ALI15X3 adapter at %04x", ali15x3_smba); |
497 | return i2c_add_adapter(&ali15x3_adapter); | 497 | return i2c_add_adapter(&ali15x3_adapter); |
498 | } | 498 | } |
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c index 0c70f8293341..c9fca7b49267 100644 --- a/drivers/i2c/busses/i2c-amd8111.c +++ b/drivers/i2c/busses/i2c-amd8111.c | |||
@@ -365,7 +365,7 @@ static int __devinit amd8111_probe(struct pci_dev *dev, | |||
365 | } | 365 | } |
366 | 366 | ||
367 | smbus->adapter.owner = THIS_MODULE; | 367 | smbus->adapter.owner = THIS_MODULE; |
368 | snprintf(smbus->adapter.name, I2C_NAME_SIZE, | 368 | snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), |
369 | "SMBus2 AMD8111 adapter at %04x", smbus->base); | 369 | "SMBus2 AMD8111 adapter at %04x", smbus->base); |
370 | smbus->adapter.id = I2C_HW_SMBUS_AMD8111; | 370 | smbus->adapter.id = I2C_HW_SMBUS_AMD8111; |
371 | smbus->adapter.class = I2C_CLASS_HWMON; | 371 | smbus->adapter.class = I2C_CLASS_HWMON; |
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index 67f91bdda089..9c8b6d5eaec9 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c | |||
@@ -16,8 +16,8 @@ | |||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/version.h> | 17 | #include <linux/version.h> |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/err.h> | ||
19 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
20 | #include <linux/pci.h> | ||
21 | #include <linux/types.h> | 21 | #include <linux/types.h> |
22 | #include <linux/delay.h> | 22 | #include <linux/delay.h> |
23 | #include <linux/i2c.h> | 23 | #include <linux/i2c.h> |
@@ -227,13 +227,14 @@ static int __devinit at91_i2c_probe(struct platform_device *pdev) | |||
227 | adapter->algo = &at91_algorithm; | 227 | adapter->algo = &at91_algorithm; |
228 | adapter->class = I2C_CLASS_HWMON; | 228 | adapter->class = I2C_CLASS_HWMON; |
229 | adapter->dev.parent = &pdev->dev; | 229 | adapter->dev.parent = &pdev->dev; |
230 | /* adapter->id == 0 ... only one TWI controller for now */ | ||
230 | 231 | ||
231 | platform_set_drvdata(pdev, adapter); | 232 | platform_set_drvdata(pdev, adapter); |
232 | 233 | ||
233 | clk_enable(twi_clk); /* enable peripheral clock */ | 234 | clk_enable(twi_clk); /* enable peripheral clock */ |
234 | at91_twi_hwinit(); /* initialize TWI controller */ | 235 | at91_twi_hwinit(); /* initialize TWI controller */ |
235 | 236 | ||
236 | rc = i2c_add_adapter(adapter); | 237 | rc = i2c_add_numbered_adapter(adapter); |
237 | if (rc) { | 238 | if (rc) { |
238 | dev_err(&pdev->dev, "Adapter %s registration failed\n", | 239 | dev_err(&pdev->dev, "Adapter %s registration failed\n", |
239 | adapter->name); | 240 | adapter->name); |
@@ -296,6 +297,9 @@ static int at91_i2c_resume(struct platform_device *pdev) | |||
296 | #define at91_i2c_resume NULL | 297 | #define at91_i2c_resume NULL |
297 | #endif | 298 | #endif |
298 | 299 | ||
300 | /* work with "modprobe at91_i2c" from hotplugging or coldplugging */ | ||
301 | MODULE_ALIAS("at91_i2c"); | ||
302 | |||
299 | static struct platform_driver at91_i2c_driver = { | 303 | static struct platform_driver at91_i2c_driver = { |
300 | .probe = at91_i2c_probe, | 304 | .probe = at91_i2c_probe, |
301 | .remove = __devexit_p(at91_i2c_remove), | 305 | .remove = __devexit_p(at91_i2c_remove), |
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c new file mode 100644 index 000000000000..6311039dfe60 --- /dev/null +++ b/drivers/i2c/busses/i2c-bfin-twi.c | |||
@@ -0,0 +1,644 @@ | |||
1 | /* | ||
2 | * drivers/i2c/busses/i2c-bfin-twi.c | ||
3 | * | ||
4 | * Description: Driver for Blackfin Two Wire Interface | ||
5 | * | ||
6 | * Author: sonicz <sonic.zhang@analog.com> | ||
7 | * | ||
8 | * Copyright (c) 2005-2007 Analog Devices, Inc. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | #include <linux/module.h> | ||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/i2c.h> | ||
29 | #include <linux/mm.h> | ||
30 | #include <linux/timer.h> | ||
31 | #include <linux/spinlock.h> | ||
32 | #include <linux/completion.h> | ||
33 | #include <linux/interrupt.h> | ||
34 | #include <linux/platform_device.h> | ||
35 | |||
36 | #include <asm/blackfin.h> | ||
37 | #include <asm/irq.h> | ||
38 | |||
39 | #define POLL_TIMEOUT (2 * HZ) | ||
40 | |||
41 | /* SMBus mode*/ | ||
42 | #define TWI_I2C_MODE_STANDARD 0x01 | ||
43 | #define TWI_I2C_MODE_STANDARDSUB 0x02 | ||
44 | #define TWI_I2C_MODE_COMBINED 0x04 | ||
45 | |||
46 | struct bfin_twi_iface { | ||
47 | struct mutex twi_lock; | ||
48 | int irq; | ||
49 | spinlock_t lock; | ||
50 | char read_write; | ||
51 | u8 command; | ||
52 | u8 *transPtr; | ||
53 | int readNum; | ||
54 | int writeNum; | ||
55 | int cur_mode; | ||
56 | int manual_stop; | ||
57 | int result; | ||
58 | int timeout_count; | ||
59 | struct timer_list timeout_timer; | ||
60 | struct i2c_adapter adap; | ||
61 | struct completion complete; | ||
62 | }; | ||
63 | |||
64 | static struct bfin_twi_iface twi_iface; | ||
65 | |||
66 | static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) | ||
67 | { | ||
68 | unsigned short twi_int_status = bfin_read_TWI_INT_STAT(); | ||
69 | unsigned short mast_stat = bfin_read_TWI_MASTER_STAT(); | ||
70 | |||
71 | if (twi_int_status & XMTSERV) { | ||
72 | /* Transmit next data */ | ||
73 | if (iface->writeNum > 0) { | ||
74 | bfin_write_TWI_XMT_DATA8(*(iface->transPtr++)); | ||
75 | iface->writeNum--; | ||
76 | } | ||
77 | /* start receive immediately after complete sending in | ||
78 | * combine mode. | ||
79 | */ | ||
80 | else if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { | ||
81 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | ||
82 | | MDIR | RSTART); | ||
83 | } else if (iface->manual_stop) | ||
84 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | ||
85 | | STOP); | ||
86 | SSYNC(); | ||
87 | /* Clear status */ | ||
88 | bfin_write_TWI_INT_STAT(XMTSERV); | ||
89 | SSYNC(); | ||
90 | } | ||
91 | if (twi_int_status & RCVSERV) { | ||
92 | if (iface->readNum > 0) { | ||
93 | /* Receive next data */ | ||
94 | *(iface->transPtr) = bfin_read_TWI_RCV_DATA8(); | ||
95 | if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { | ||
96 | /* Change combine mode into sub mode after | ||
97 | * read first data. | ||
98 | */ | ||
99 | iface->cur_mode = TWI_I2C_MODE_STANDARDSUB; | ||
100 | /* Get read number from first byte in block | ||
101 | * combine mode. | ||
102 | */ | ||
103 | if (iface->readNum == 1 && iface->manual_stop) | ||
104 | iface->readNum = *iface->transPtr + 1; | ||
105 | } | ||
106 | iface->transPtr++; | ||
107 | iface->readNum--; | ||
108 | } else if (iface->manual_stop) { | ||
109 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | ||
110 | | STOP); | ||
111 | SSYNC(); | ||
112 | } | ||
113 | /* Clear interrupt source */ | ||
114 | bfin_write_TWI_INT_STAT(RCVSERV); | ||
115 | SSYNC(); | ||
116 | } | ||
117 | if (twi_int_status & MERR) { | ||
118 | bfin_write_TWI_INT_STAT(MERR); | ||
119 | bfin_write_TWI_INT_MASK(0); | ||
120 | bfin_write_TWI_MASTER_STAT(0x3e); | ||
121 | bfin_write_TWI_MASTER_CTL(0); | ||
122 | SSYNC(); | ||
123 | iface->result = -1; | ||
124 | /* if both err and complete int stats are set, return proper | ||
125 | * results. | ||
126 | */ | ||
127 | if (twi_int_status & MCOMP) { | ||
128 | bfin_write_TWI_INT_STAT(MCOMP); | ||
129 | bfin_write_TWI_INT_MASK(0); | ||
130 | bfin_write_TWI_MASTER_CTL(0); | ||
131 | SSYNC(); | ||
132 | /* If it is a quick transfer, only address bug no data, | ||
133 | * not an err, return 1. | ||
134 | */ | ||
135 | if (iface->writeNum == 0 && (mast_stat & BUFRDERR)) | ||
136 | iface->result = 1; | ||
137 | /* If address not acknowledged return -1, | ||
138 | * else return 0. | ||
139 | */ | ||
140 | else if (!(mast_stat & ANAK)) | ||
141 | iface->result = 0; | ||
142 | } | ||
143 | complete(&iface->complete); | ||
144 | return; | ||
145 | } | ||
146 | if (twi_int_status & MCOMP) { | ||
147 | bfin_write_TWI_INT_STAT(MCOMP); | ||
148 | SSYNC(); | ||
149 | if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { | ||
150 | if (iface->readNum == 0) { | ||
151 | /* set the read number to 1 and ask for manual | ||
152 | * stop in block combine mode | ||
153 | */ | ||
154 | iface->readNum = 1; | ||
155 | iface->manual_stop = 1; | ||
156 | bfin_write_TWI_MASTER_CTL( | ||
157 | bfin_read_TWI_MASTER_CTL() | ||
158 | | (0xff << 6)); | ||
159 | } else { | ||
160 | /* set the readd number in other | ||
161 | * combine mode. | ||
162 | */ | ||
163 | bfin_write_TWI_MASTER_CTL( | ||
164 | (bfin_read_TWI_MASTER_CTL() & | ||
165 | (~(0xff << 6))) | | ||
166 | ( iface->readNum << 6)); | ||
167 | } | ||
168 | /* remove restart bit and enable master receive */ | ||
169 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() & | ||
170 | ~RSTART); | ||
171 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | | ||
172 | MEN | MDIR); | ||
173 | SSYNC(); | ||
174 | } else { | ||
175 | iface->result = 1; | ||
176 | bfin_write_TWI_INT_MASK(0); | ||
177 | bfin_write_TWI_MASTER_CTL(0); | ||
178 | SSYNC(); | ||
179 | complete(&iface->complete); | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | |||
184 | /* Interrupt handler */ | ||
185 | static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id) | ||
186 | { | ||
187 | struct bfin_twi_iface *iface = dev_id; | ||
188 | unsigned long flags; | ||
189 | |||
190 | spin_lock_irqsave(&iface->lock, flags); | ||
191 | del_timer(&iface->timeout_timer); | ||
192 | bfin_twi_handle_interrupt(iface); | ||
193 | spin_unlock_irqrestore(&iface->lock, flags); | ||
194 | return IRQ_HANDLED; | ||
195 | } | ||
196 | |||
197 | static void bfin_twi_timeout(unsigned long data) | ||
198 | { | ||
199 | struct bfin_twi_iface *iface = (struct bfin_twi_iface *)data; | ||
200 | unsigned long flags; | ||
201 | |||
202 | spin_lock_irqsave(&iface->lock, flags); | ||
203 | bfin_twi_handle_interrupt(iface); | ||
204 | if (iface->result == 0) { | ||
205 | iface->timeout_count--; | ||
206 | if (iface->timeout_count > 0) { | ||
207 | iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; | ||
208 | add_timer(&iface->timeout_timer); | ||
209 | } else { | ||
210 | iface->result = -1; | ||
211 | complete(&iface->complete); | ||
212 | } | ||
213 | } | ||
214 | spin_unlock_irqrestore(&iface->lock, flags); | ||
215 | } | ||
216 | |||
217 | /* | ||
218 | * Generic i2c master transfer entrypoint | ||
219 | */ | ||
220 | static int bfin_twi_master_xfer(struct i2c_adapter *adap, | ||
221 | struct i2c_msg *msgs, int num) | ||
222 | { | ||
223 | struct bfin_twi_iface *iface = adap->algo_data; | ||
224 | struct i2c_msg *pmsg; | ||
225 | int i, ret; | ||
226 | int rc = 0; | ||
227 | |||
228 | if (!(bfin_read_TWI_CONTROL() & TWI_ENA)) | ||
229 | return -ENXIO; | ||
230 | |||
231 | mutex_lock(&iface->twi_lock); | ||
232 | |||
233 | while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) { | ||
234 | mutex_unlock(&iface->twi_lock); | ||
235 | yield(); | ||
236 | mutex_lock(&iface->twi_lock); | ||
237 | } | ||
238 | |||
239 | ret = 0; | ||
240 | for (i = 0; rc >= 0 && i < num; i++) { | ||
241 | pmsg = &msgs[i]; | ||
242 | if (pmsg->flags & I2C_M_TEN) { | ||
243 | dev_err(&(adap->dev), "i2c-bfin-twi: 10 bits addr " | ||
244 | "not supported !\n"); | ||
245 | rc = -EINVAL; | ||
246 | break; | ||
247 | } | ||
248 | |||
249 | iface->cur_mode = TWI_I2C_MODE_STANDARD; | ||
250 | iface->manual_stop = 0; | ||
251 | iface->transPtr = pmsg->buf; | ||
252 | iface->writeNum = iface->readNum = pmsg->len; | ||
253 | iface->result = 0; | ||
254 | iface->timeout_count = 10; | ||
255 | /* Set Transmit device address */ | ||
256 | bfin_write_TWI_MASTER_ADDR(pmsg->addr); | ||
257 | |||
258 | /* FIFO Initiation. Data in FIFO should be | ||
259 | * discarded before start a new operation. | ||
260 | */ | ||
261 | bfin_write_TWI_FIFO_CTL(0x3); | ||
262 | SSYNC(); | ||
263 | bfin_write_TWI_FIFO_CTL(0); | ||
264 | SSYNC(); | ||
265 | |||
266 | if (pmsg->flags & I2C_M_RD) | ||
267 | iface->read_write = I2C_SMBUS_READ; | ||
268 | else { | ||
269 | iface->read_write = I2C_SMBUS_WRITE; | ||
270 | /* Transmit first data */ | ||
271 | if (iface->writeNum > 0) { | ||
272 | bfin_write_TWI_XMT_DATA8(*(iface->transPtr++)); | ||
273 | iface->writeNum--; | ||
274 | SSYNC(); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /* clear int stat */ | ||
279 | bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV); | ||
280 | |||
281 | /* Interrupt mask . Enable XMT, RCV interrupt */ | ||
282 | bfin_write_TWI_INT_MASK(MCOMP | MERR | | ||
283 | ((iface->read_write == I2C_SMBUS_READ)? | ||
284 | RCVSERV : XMTSERV)); | ||
285 | SSYNC(); | ||
286 | |||
287 | if (pmsg->len > 0 && pmsg->len <= 255) | ||
288 | bfin_write_TWI_MASTER_CTL(pmsg->len << 6); | ||
289 | else if (pmsg->len > 255) { | ||
290 | bfin_write_TWI_MASTER_CTL(0xff << 6); | ||
291 | iface->manual_stop = 1; | ||
292 | } else | ||
293 | break; | ||
294 | |||
295 | iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; | ||
296 | add_timer(&iface->timeout_timer); | ||
297 | |||
298 | /* Master enable */ | ||
299 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN | | ||
300 | ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | | ||
301 | ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0)); | ||
302 | SSYNC(); | ||
303 | |||
304 | wait_for_completion(&iface->complete); | ||
305 | |||
306 | rc = iface->result; | ||
307 | if (rc == 1) | ||
308 | ret++; | ||
309 | else if (rc == -1) | ||
310 | break; | ||
311 | } | ||
312 | |||
313 | /* Release mutex */ | ||
314 | mutex_unlock(&iface->twi_lock); | ||
315 | |||
316 | return ret; | ||
317 | } | ||
318 | |||
319 | /* | ||
320 | * SMBus type transfer entrypoint | ||
321 | */ | ||
322 | |||
323 | int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, | ||
324 | unsigned short flags, char read_write, | ||
325 | u8 command, int size, union i2c_smbus_data *data) | ||
326 | { | ||
327 | struct bfin_twi_iface *iface = adap->algo_data; | ||
328 | int rc = 0; | ||
329 | |||
330 | if (!(bfin_read_TWI_CONTROL() & TWI_ENA)) | ||
331 | return -ENXIO; | ||
332 | |||
333 | mutex_lock(&iface->twi_lock); | ||
334 | |||
335 | while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) { | ||
336 | mutex_unlock(&iface->twi_lock); | ||
337 | yield(); | ||
338 | mutex_lock(&iface->twi_lock); | ||
339 | } | ||
340 | |||
341 | iface->writeNum = 0; | ||
342 | iface->readNum = 0; | ||
343 | |||
344 | /* Prepare datas & select mode */ | ||
345 | switch (size) { | ||
346 | case I2C_SMBUS_QUICK: | ||
347 | iface->transPtr = NULL; | ||
348 | iface->cur_mode = TWI_I2C_MODE_STANDARD; | ||
349 | break; | ||
350 | case I2C_SMBUS_BYTE: | ||
351 | if (data == NULL) | ||
352 | iface->transPtr = NULL; | ||
353 | else { | ||
354 | if (read_write == I2C_SMBUS_READ) | ||
355 | iface->readNum = 1; | ||
356 | else | ||
357 | iface->writeNum = 1; | ||
358 | iface->transPtr = &data->byte; | ||
359 | } | ||
360 | iface->cur_mode = TWI_I2C_MODE_STANDARD; | ||
361 | break; | ||
362 | case I2C_SMBUS_BYTE_DATA: | ||
363 | if (read_write == I2C_SMBUS_READ) { | ||
364 | iface->readNum = 1; | ||
365 | iface->cur_mode = TWI_I2C_MODE_COMBINED; | ||
366 | } else { | ||
367 | iface->writeNum = 1; | ||
368 | iface->cur_mode = TWI_I2C_MODE_STANDARDSUB; | ||
369 | } | ||
370 | iface->transPtr = &data->byte; | ||
371 | break; | ||
372 | case I2C_SMBUS_WORD_DATA: | ||
373 | if (read_write == I2C_SMBUS_READ) { | ||
374 | iface->readNum = 2; | ||
375 | iface->cur_mode = TWI_I2C_MODE_COMBINED; | ||
376 | } else { | ||
377 | iface->writeNum = 2; | ||
378 | iface->cur_mode = TWI_I2C_MODE_STANDARDSUB; | ||
379 | } | ||
380 | iface->transPtr = (u8 *)&data->word; | ||
381 | break; | ||
382 | case I2C_SMBUS_PROC_CALL: | ||
383 | iface->writeNum = 2; | ||
384 | iface->readNum = 2; | ||
385 | iface->cur_mode = TWI_I2C_MODE_COMBINED; | ||
386 | iface->transPtr = (u8 *)&data->word; | ||
387 | break; | ||
388 | case I2C_SMBUS_BLOCK_DATA: | ||
389 | if (read_write == I2C_SMBUS_READ) { | ||
390 | iface->readNum = 0; | ||
391 | iface->cur_mode = TWI_I2C_MODE_COMBINED; | ||
392 | } else { | ||
393 | iface->writeNum = data->block[0] + 1; | ||
394 | iface->cur_mode = TWI_I2C_MODE_STANDARDSUB; | ||
395 | } | ||
396 | iface->transPtr = data->block; | ||
397 | break; | ||
398 | default: | ||
399 | return -1; | ||
400 | } | ||
401 | |||
402 | iface->result = 0; | ||
403 | iface->manual_stop = 0; | ||
404 | iface->read_write = read_write; | ||
405 | iface->command = command; | ||
406 | iface->timeout_count = 10; | ||
407 | |||
408 | /* FIFO Initiation. Data in FIFO should be discarded before | ||
409 | * start a new operation. | ||
410 | */ | ||
411 | bfin_write_TWI_FIFO_CTL(0x3); | ||
412 | SSYNC(); | ||
413 | bfin_write_TWI_FIFO_CTL(0); | ||
414 | |||
415 | /* clear int stat */ | ||
416 | bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV); | ||
417 | |||
418 | /* Set Transmit device address */ | ||
419 | bfin_write_TWI_MASTER_ADDR(addr); | ||
420 | SSYNC(); | ||
421 | |||
422 | iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; | ||
423 | add_timer(&iface->timeout_timer); | ||
424 | |||
425 | switch (iface->cur_mode) { | ||
426 | case TWI_I2C_MODE_STANDARDSUB: | ||
427 | bfin_write_TWI_XMT_DATA8(iface->command); | ||
428 | bfin_write_TWI_INT_MASK(MCOMP | MERR | | ||
429 | ((iface->read_write == I2C_SMBUS_READ) ? | ||
430 | RCVSERV : XMTSERV)); | ||
431 | SSYNC(); | ||
432 | |||
433 | if (iface->writeNum + 1 <= 255) | ||
434 | bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6); | ||
435 | else { | ||
436 | bfin_write_TWI_MASTER_CTL(0xff << 6); | ||
437 | iface->manual_stop = 1; | ||
438 | } | ||
439 | /* Master enable */ | ||
440 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN | | ||
441 | ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0)); | ||
442 | break; | ||
443 | case TWI_I2C_MODE_COMBINED: | ||
444 | bfin_write_TWI_XMT_DATA8(iface->command); | ||
445 | bfin_write_TWI_INT_MASK(MCOMP | MERR | RCVSERV | XMTSERV); | ||
446 | SSYNC(); | ||
447 | |||
448 | if (iface->writeNum > 0) | ||
449 | bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6); | ||
450 | else | ||
451 | bfin_write_TWI_MASTER_CTL(0x1 << 6); | ||
452 | /* Master enable */ | ||
453 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN | | ||
454 | ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0)); | ||
455 | break; | ||
456 | default: | ||
457 | bfin_write_TWI_MASTER_CTL(0); | ||
458 | if (size != I2C_SMBUS_QUICK) { | ||
459 | /* Don't access xmit data register when this is a | ||
460 | * read operation. | ||
461 | */ | ||
462 | if (iface->read_write != I2C_SMBUS_READ) { | ||
463 | if (iface->writeNum > 0) { | ||
464 | bfin_write_TWI_XMT_DATA8(*(iface->transPtr++)); | ||
465 | if (iface->writeNum <= 255) | ||
466 | bfin_write_TWI_MASTER_CTL(iface->writeNum << 6); | ||
467 | else { | ||
468 | bfin_write_TWI_MASTER_CTL(0xff << 6); | ||
469 | iface->manual_stop = 1; | ||
470 | } | ||
471 | iface->writeNum--; | ||
472 | } else { | ||
473 | bfin_write_TWI_XMT_DATA8(iface->command); | ||
474 | bfin_write_TWI_MASTER_CTL(1 << 6); | ||
475 | } | ||
476 | } else { | ||
477 | if (iface->readNum > 0 && iface->readNum <= 255) | ||
478 | bfin_write_TWI_MASTER_CTL(iface->readNum << 6); | ||
479 | else if (iface->readNum > 255) { | ||
480 | bfin_write_TWI_MASTER_CTL(0xff << 6); | ||
481 | iface->manual_stop = 1; | ||
482 | } else { | ||
483 | del_timer(&iface->timeout_timer); | ||
484 | break; | ||
485 | } | ||
486 | } | ||
487 | } | ||
488 | bfin_write_TWI_INT_MASK(MCOMP | MERR | | ||
489 | ((iface->read_write == I2C_SMBUS_READ) ? | ||
490 | RCVSERV : XMTSERV)); | ||
491 | SSYNC(); | ||
492 | |||
493 | /* Master enable */ | ||
494 | bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN | | ||
495 | ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | | ||
496 | ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); | ||
497 | break; | ||
498 | } | ||
499 | SSYNC(); | ||
500 | |||
501 | wait_for_completion(&iface->complete); | ||
502 | |||
503 | rc = (iface->result >= 0) ? 0 : -1; | ||
504 | |||
505 | /* Release mutex */ | ||
506 | mutex_unlock(&iface->twi_lock); | ||
507 | |||
508 | return rc; | ||
509 | } | ||
510 | |||
511 | /* | ||
512 | * Return what the adapter supports | ||
513 | */ | ||
514 | static u32 bfin_twi_functionality(struct i2c_adapter *adap) | ||
515 | { | ||
516 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | ||
517 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | | ||
518 | I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL | | ||
519 | I2C_FUNC_I2C; | ||
520 | } | ||
521 | |||
522 | |||
523 | static struct i2c_algorithm bfin_twi_algorithm = { | ||
524 | .master_xfer = bfin_twi_master_xfer, | ||
525 | .smbus_xfer = bfin_twi_smbus_xfer, | ||
526 | .functionality = bfin_twi_functionality, | ||
527 | }; | ||
528 | |||
529 | |||
530 | static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state) | ||
531 | { | ||
532 | /* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/ | ||
533 | |||
534 | /* Disable TWI */ | ||
535 | bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() & ~TWI_ENA); | ||
536 | SSYNC(); | ||
537 | |||
538 | return 0; | ||
539 | } | ||
540 | |||
541 | static int i2c_bfin_twi_resume(struct platform_device *dev) | ||
542 | { | ||
543 | /* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/ | ||
544 | |||
545 | /* Enable TWI */ | ||
546 | bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA); | ||
547 | SSYNC(); | ||
548 | |||
549 | return 0; | ||
550 | } | ||
551 | |||
552 | static int i2c_bfin_twi_probe(struct platform_device *dev) | ||
553 | { | ||
554 | struct bfin_twi_iface *iface = &twi_iface; | ||
555 | struct i2c_adapter *p_adap; | ||
556 | int rc; | ||
557 | |||
558 | mutex_init(&(iface->twi_lock)); | ||
559 | spin_lock_init(&(iface->lock)); | ||
560 | init_completion(&(iface->complete)); | ||
561 | iface->irq = IRQ_TWI; | ||
562 | |||
563 | init_timer(&(iface->timeout_timer)); | ||
564 | iface->timeout_timer.function = bfin_twi_timeout; | ||
565 | iface->timeout_timer.data = (unsigned long)iface; | ||
566 | |||
567 | p_adap = &iface->adap; | ||
568 | p_adap->id = I2C_HW_BLACKFIN; | ||
569 | strlcpy(p_adap->name, dev->name, sizeof(p_adap->name)); | ||
570 | p_adap->algo = &bfin_twi_algorithm; | ||
571 | p_adap->algo_data = iface; | ||
572 | p_adap->class = I2C_CLASS_ALL; | ||
573 | p_adap->dev.parent = &dev->dev; | ||
574 | |||
575 | rc = request_irq(iface->irq, bfin_twi_interrupt_entry, | ||
576 | IRQF_DISABLED, dev->name, iface); | ||
577 | if (rc) { | ||
578 | dev_err(&(p_adap->dev), "i2c-bfin-twi: can't get IRQ %d !\n", | ||
579 | iface->irq); | ||
580 | return -ENODEV; | ||
581 | } | ||
582 | |||
583 | /* Set TWI internal clock as 10MHz */ | ||
584 | bfin_write_TWI_CONTROL(((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F); | ||
585 | |||
586 | /* Set Twi interface clock as specified */ | ||
587 | bfin_write_TWI_CLKDIV((( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ ) | ||
588 | << 8) | (( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ ) | ||
589 | & 0xFF)); | ||
590 | |||
591 | /* Enable TWI */ | ||
592 | bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA); | ||
593 | SSYNC(); | ||
594 | |||
595 | rc = i2c_add_adapter(p_adap); | ||
596 | if (rc < 0) | ||
597 | free_irq(iface->irq, iface); | ||
598 | else | ||
599 | platform_set_drvdata(dev, iface); | ||
600 | |||
601 | return rc; | ||
602 | } | ||
603 | |||
604 | static int i2c_bfin_twi_remove(struct platform_device *pdev) | ||
605 | { | ||
606 | struct bfin_twi_iface *iface = platform_get_drvdata(pdev); | ||
607 | |||
608 | platform_set_drvdata(pdev, NULL); | ||
609 | |||
610 | i2c_del_adapter(&(iface->adap)); | ||
611 | free_irq(iface->irq, iface); | ||
612 | |||
613 | return 0; | ||
614 | } | ||
615 | |||
616 | static struct platform_driver i2c_bfin_twi_driver = { | ||
617 | .probe = i2c_bfin_twi_probe, | ||
618 | .remove = i2c_bfin_twi_remove, | ||
619 | .suspend = i2c_bfin_twi_suspend, | ||
620 | .resume = i2c_bfin_twi_resume, | ||
621 | .driver = { | ||
622 | .name = "i2c-bfin-twi", | ||
623 | .owner = THIS_MODULE, | ||
624 | }, | ||
625 | }; | ||
626 | |||
627 | static int __init i2c_bfin_twi_init(void) | ||
628 | { | ||
629 | pr_info("I2C: Blackfin I2C TWI driver\n"); | ||
630 | |||
631 | return platform_driver_register(&i2c_bfin_twi_driver); | ||
632 | } | ||
633 | |||
634 | static void __exit i2c_bfin_twi_exit(void) | ||
635 | { | ||
636 | platform_driver_unregister(&i2c_bfin_twi_driver); | ||
637 | } | ||
638 | |||
639 | MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>"); | ||
640 | MODULE_DESCRIPTION("I2C-Bus adapter routines for Blackfin TWI"); | ||
641 | MODULE_LICENSE("GPL"); | ||
642 | |||
643 | module_init(i2c_bfin_twi_init); | ||
644 | module_exit(i2c_bfin_twi_exit); | ||
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c index 834967464814..804f0a551c05 100644 --- a/drivers/i2c/busses/i2c-elektor.c +++ b/drivers/i2c/busses/i2c-elektor.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/pci.h> | 35 | #include <linux/pci.h> |
36 | #include <linux/wait.h> | 36 | #include <linux/wait.h> |
37 | 37 | ||
38 | #include <linux/isa.h> | ||
38 | #include <linux/i2c.h> | 39 | #include <linux/i2c.h> |
39 | #include <linux/i2c-algo-pcf.h> | 40 | #include <linux/i2c-algo-pcf.h> |
40 | 41 | ||
@@ -207,7 +208,7 @@ static struct i2c_adapter pcf_isa_ops = { | |||
207 | .name = "i2c-elektor", | 208 | .name = "i2c-elektor", |
208 | }; | 209 | }; |
209 | 210 | ||
210 | static int __init i2c_pcfisa_init(void) | 211 | static int __devinit elektor_match(struct device *dev, unsigned int id) |
211 | { | 212 | { |
212 | #ifdef __alpha__ | 213 | #ifdef __alpha__ |
213 | /* check to see we have memory mapped PCF8584 connected to the | 214 | /* check to see we have memory mapped PCF8584 connected to the |
@@ -222,9 +223,8 @@ static int __init i2c_pcfisa_init(void) | |||
222 | /* yeap, we've found cypress, let's check config */ | 223 | /* yeap, we've found cypress, let's check config */ |
223 | if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { | 224 | if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { |
224 | 225 | ||
225 | pr_debug("%s: found cy82c693, config " | 226 | dev_dbg(dev, "found cy82c693, config " |
226 | "register 0x47 = 0x%02x\n", | 227 | "register 0x47 = 0x%02x\n", config); |
227 | pcf_isa_ops.name, config); | ||
228 | 228 | ||
229 | /* UP2000 board has this register set to 0xe1, | 229 | /* UP2000 board has this register set to 0xe1, |
230 | but the most significant bit as seems can be | 230 | but the most significant bit as seems can be |
@@ -244,9 +244,9 @@ static int __init i2c_pcfisa_init(void) | |||
244 | 8.25 MHz (PCI/4) clock | 244 | 8.25 MHz (PCI/4) clock |
245 | (this can be read from cypress) */ | 245 | (this can be read from cypress) */ |
246 | clock = I2C_PCF_CLK | I2C_PCF_TRNS90; | 246 | clock = I2C_PCF_CLK | I2C_PCF_TRNS90; |
247 | pr_info("%s: found API UP2000 like " | 247 | dev_info(dev, "found API UP2000 like " |
248 | "board, will probe PCF8584 " | 248 | "board, will probe PCF8584 " |
249 | "later\n", pcf_isa_ops.name); | 249 | "later\n"); |
250 | } | 250 | } |
251 | } | 251 | } |
252 | pci_dev_put(cy693_dev); | 252 | pci_dev_put(cy693_dev); |
@@ -256,22 +256,27 @@ static int __init i2c_pcfisa_init(void) | |||
256 | 256 | ||
257 | /* sanity checks for mmapped I/O */ | 257 | /* sanity checks for mmapped I/O */ |
258 | if (mmapped && base < 0xc8000) { | 258 | if (mmapped && base < 0xc8000) { |
259 | printk(KERN_ERR "%s: incorrect base address (%#x) specified " | 259 | dev_err(dev, "incorrect base address (%#x) specified " |
260 | "for mmapped I/O\n", pcf_isa_ops.name, base); | 260 | "for mmapped I/O\n", base); |
261 | return -ENODEV; | 261 | return 0; |
262 | } | 262 | } |
263 | 263 | ||
264 | if (base == 0) { | 264 | if (base == 0) { |
265 | base = DEFAULT_BASE; | 265 | base = DEFAULT_BASE; |
266 | } | 266 | } |
267 | return 1; | ||
268 | } | ||
267 | 269 | ||
270 | static int __devinit elektor_probe(struct device *dev, unsigned int id) | ||
271 | { | ||
268 | init_waitqueue_head(&pcf_wait); | 272 | init_waitqueue_head(&pcf_wait); |
269 | if (pcf_isa_init()) | 273 | if (pcf_isa_init()) |
270 | return -ENODEV; | 274 | return -ENODEV; |
275 | pcf_isa_ops.dev.parent = dev; | ||
271 | if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) | 276 | if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) |
272 | goto fail; | 277 | goto fail; |
273 | 278 | ||
274 | dev_info(&pcf_isa_ops.dev, "found device at %#x\n", base); | 279 | dev_info(dev, "found device at %#x\n", base); |
275 | 280 | ||
276 | return 0; | 281 | return 0; |
277 | 282 | ||
@@ -291,7 +296,7 @@ static int __init i2c_pcfisa_init(void) | |||
291 | return -ENODEV; | 296 | return -ENODEV; |
292 | } | 297 | } |
293 | 298 | ||
294 | static void i2c_pcfisa_exit(void) | 299 | static int __devexit elektor_remove(struct device *dev, unsigned int id) |
295 | { | 300 | { |
296 | i2c_del_adapter(&pcf_isa_ops); | 301 | i2c_del_adapter(&pcf_isa_ops); |
297 | 302 | ||
@@ -307,6 +312,28 @@ static void i2c_pcfisa_exit(void) | |||
307 | iounmap(base_iomem); | 312 | iounmap(base_iomem); |
308 | release_mem_region(base, 2); | 313 | release_mem_region(base, 2); |
309 | } | 314 | } |
315 | |||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | static struct isa_driver i2c_elektor_driver = { | ||
320 | .match = elektor_match, | ||
321 | .probe = elektor_probe, | ||
322 | .remove = __devexit_p(elektor_remove), | ||
323 | .driver = { | ||
324 | .owner = THIS_MODULE, | ||
325 | .name = "i2c-elektor", | ||
326 | }, | ||
327 | }; | ||
328 | |||
329 | static int __init i2c_pcfisa_init(void) | ||
330 | { | ||
331 | return isa_register_driver(&i2c_elektor_driver, 1); | ||
332 | } | ||
333 | |||
334 | static void __exit i2c_pcfisa_exit(void) | ||
335 | { | ||
336 | isa_unregister_driver(&i2c_elektor_driver); | ||
310 | } | 337 | } |
311 | 338 | ||
312 | MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); | 339 | MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); |
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c new file mode 100644 index 000000000000..a7dd54654a9a --- /dev/null +++ b/drivers/i2c/busses/i2c-gpio.c | |||
@@ -0,0 +1,215 @@ | |||
1 | /* | ||
2 | * Bitbanging I2C bus driver using the GPIO API | ||
3 | * | ||
4 | * Copyright (C) 2007 Atmel Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #include <linux/i2c.h> | ||
11 | #include <linux/i2c-algo-bit.h> | ||
12 | #include <linux/i2c-gpio.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | |||
17 | #include <asm/gpio.h> | ||
18 | |||
19 | /* Toggle SDA by changing the direction of the pin */ | ||
20 | static void i2c_gpio_setsda_dir(void *data, int state) | ||
21 | { | ||
22 | struct i2c_gpio_platform_data *pdata = data; | ||
23 | |||
24 | if (state) | ||
25 | gpio_direction_input(pdata->sda_pin); | ||
26 | else | ||
27 | gpio_direction_output(pdata->sda_pin, 0); | ||
28 | } | ||
29 | |||
30 | /* | ||
31 | * Toggle SDA by changing the output value of the pin. This is only | ||
32 | * valid for pins configured as open drain (i.e. setting the value | ||
33 | * high effectively turns off the output driver.) | ||
34 | */ | ||
35 | static void i2c_gpio_setsda_val(void *data, int state) | ||
36 | { | ||
37 | struct i2c_gpio_platform_data *pdata = data; | ||
38 | |||
39 | gpio_set_value(pdata->sda_pin, state); | ||
40 | } | ||
41 | |||
42 | /* Toggle SCL by changing the direction of the pin. */ | ||
43 | static void i2c_gpio_setscl_dir(void *data, int state) | ||
44 | { | ||
45 | struct i2c_gpio_platform_data *pdata = data; | ||
46 | |||
47 | if (state) | ||
48 | gpio_direction_input(pdata->scl_pin); | ||
49 | else | ||
50 | gpio_direction_output(pdata->scl_pin, 0); | ||
51 | } | ||
52 | |||
53 | /* | ||
54 | * Toggle SCL by changing the output value of the pin. This is used | ||
55 | * for pins that are configured as open drain and for output-only | ||
56 | * pins. The latter case will break the i2c protocol, but it will | ||
57 | * often work in practice. | ||
58 | */ | ||
59 | static void i2c_gpio_setscl_val(void *data, int state) | ||
60 | { | ||
61 | struct i2c_gpio_platform_data *pdata = data; | ||
62 | |||
63 | gpio_set_value(pdata->scl_pin, state); | ||
64 | } | ||
65 | |||
66 | int i2c_gpio_getsda(void *data) | ||
67 | { | ||
68 | struct i2c_gpio_platform_data *pdata = data; | ||
69 | |||
70 | return gpio_get_value(pdata->sda_pin); | ||
71 | } | ||
72 | |||
73 | int i2c_gpio_getscl(void *data) | ||
74 | { | ||
75 | struct i2c_gpio_platform_data *pdata = data; | ||
76 | |||
77 | return gpio_get_value(pdata->scl_pin); | ||
78 | } | ||
79 | |||
80 | static int __init i2c_gpio_probe(struct platform_device *pdev) | ||
81 | { | ||
82 | struct i2c_gpio_platform_data *pdata; | ||
83 | struct i2c_algo_bit_data *bit_data; | ||
84 | struct i2c_adapter *adap; | ||
85 | int ret; | ||
86 | |||
87 | pdata = pdev->dev.platform_data; | ||
88 | if (!pdata) | ||
89 | return -ENXIO; | ||
90 | |||
91 | ret = -ENOMEM; | ||
92 | adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL); | ||
93 | if (!adap) | ||
94 | goto err_alloc_adap; | ||
95 | bit_data = kzalloc(sizeof(struct i2c_algo_bit_data), GFP_KERNEL); | ||
96 | if (!bit_data) | ||
97 | goto err_alloc_bit_data; | ||
98 | |||
99 | ret = gpio_request(pdata->sda_pin, "sda"); | ||
100 | if (ret) | ||
101 | goto err_request_sda; | ||
102 | ret = gpio_request(pdata->scl_pin, "scl"); | ||
103 | if (ret) | ||
104 | goto err_request_scl; | ||
105 | |||
106 | if (pdata->sda_is_open_drain) { | ||
107 | gpio_direction_output(pdata->sda_pin, 1); | ||
108 | bit_data->setsda = i2c_gpio_setsda_val; | ||
109 | } else { | ||
110 | gpio_direction_input(pdata->sda_pin); | ||
111 | bit_data->setsda = i2c_gpio_setsda_dir; | ||
112 | } | ||
113 | |||
114 | if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { | ||
115 | gpio_direction_output(pdata->scl_pin, 1); | ||
116 | bit_data->setscl = i2c_gpio_setscl_val; | ||
117 | } else { | ||
118 | gpio_direction_input(pdata->scl_pin); | ||
119 | bit_data->setscl = i2c_gpio_setscl_dir; | ||
120 | } | ||
121 | |||
122 | if (!pdata->scl_is_output_only) | ||
123 | bit_data->getscl = i2c_gpio_getscl; | ||
124 | bit_data->getsda = i2c_gpio_getsda; | ||
125 | |||
126 | if (pdata->udelay) | ||
127 | bit_data->udelay = pdata->udelay; | ||
128 | else if (pdata->scl_is_output_only) | ||
129 | bit_data->udelay = 50; /* 10 kHz */ | ||
130 | else | ||
131 | bit_data->udelay = 5; /* 100 kHz */ | ||
132 | |||
133 | if (pdata->timeout) | ||
134 | bit_data->timeout = pdata->timeout; | ||
135 | else | ||
136 | bit_data->timeout = HZ / 10; /* 100 ms */ | ||
137 | |||
138 | bit_data->data = pdata; | ||
139 | |||
140 | adap->owner = THIS_MODULE; | ||
141 | snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); | ||
142 | adap->algo_data = bit_data; | ||
143 | adap->dev.parent = &pdev->dev; | ||
144 | |||
145 | ret = i2c_bit_add_bus(adap); | ||
146 | if (ret) | ||
147 | goto err_add_bus; | ||
148 | |||
149 | platform_set_drvdata(pdev, adap); | ||
150 | |||
151 | dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", | ||
152 | pdata->sda_pin, pdata->scl_pin, | ||
153 | pdata->scl_is_output_only | ||
154 | ? ", no clock stretching" : ""); | ||
155 | |||
156 | return 0; | ||
157 | |||
158 | err_add_bus: | ||
159 | gpio_free(pdata->scl_pin); | ||
160 | err_request_scl: | ||
161 | gpio_free(pdata->sda_pin); | ||
162 | err_request_sda: | ||
163 | kfree(bit_data); | ||
164 | err_alloc_bit_data: | ||
165 | kfree(adap); | ||
166 | err_alloc_adap: | ||
167 | return ret; | ||
168 | } | ||
169 | |||
170 | static int __exit i2c_gpio_remove(struct platform_device *pdev) | ||
171 | { | ||
172 | struct i2c_gpio_platform_data *pdata; | ||
173 | struct i2c_adapter *adap; | ||
174 | |||
175 | adap = platform_get_drvdata(pdev); | ||
176 | pdata = pdev->dev.platform_data; | ||
177 | |||
178 | i2c_del_adapter(adap); | ||
179 | gpio_free(pdata->scl_pin); | ||
180 | gpio_free(pdata->sda_pin); | ||
181 | kfree(adap->algo_data); | ||
182 | kfree(adap); | ||
183 | |||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static struct platform_driver i2c_gpio_driver = { | ||
188 | .driver = { | ||
189 | .name = "i2c-gpio", | ||
190 | .owner = THIS_MODULE, | ||
191 | }, | ||
192 | .remove = __exit_p(i2c_gpio_remove), | ||
193 | }; | ||
194 | |||
195 | static int __init i2c_gpio_init(void) | ||
196 | { | ||
197 | int ret; | ||
198 | |||
199 | ret = platform_driver_probe(&i2c_gpio_driver, i2c_gpio_probe); | ||
200 | if (ret) | ||
201 | printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret); | ||
202 | |||
203 | return ret; | ||
204 | } | ||
205 | module_init(i2c_gpio_init); | ||
206 | |||
207 | static void __exit i2c_gpio_exit(void) | ||
208 | { | ||
209 | platform_driver_unregister(&i2c_gpio_driver); | ||
210 | } | ||
211 | module_exit(i2c_gpio_exit); | ||
212 | |||
213 | MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>"); | ||
214 | MODULE_DESCRIPTION("Platform-independent bitbanging I2C driver"); | ||
215 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index a320e7d82c1f..611b57192c96 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c | |||
@@ -527,7 +527,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id | |||
527 | /* set up the sysfs linkage to our parent device */ | 527 | /* set up the sysfs linkage to our parent device */ |
528 | i801_adapter.dev.parent = &dev->dev; | 528 | i801_adapter.dev.parent = &dev->dev; |
529 | 529 | ||
530 | snprintf(i801_adapter.name, I2C_NAME_SIZE, | 530 | snprintf(i801_adapter.name, sizeof(i801_adapter.name), |
531 | "SMBus I801 adapter at %04lx", i801_smba); | 531 | "SMBus I801 adapter at %04lx", i801_smba); |
532 | err = i2c_add_adapter(&i801_adapter); | 532 | err = i2c_add_adapter(&i801_adapter); |
533 | if (err) { | 533 | if (err) { |
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c index 5f33bc9c1e02..b0e1370075de 100644 --- a/drivers/i2c/busses/i2c-isa.c +++ b/drivers/i2c/busses/i2c-isa.c | |||
@@ -41,6 +41,10 @@ | |||
41 | #include <linux/platform_device.h> | 41 | #include <linux/platform_device.h> |
42 | #include <linux/completion.h> | 42 | #include <linux/completion.h> |
43 | 43 | ||
44 | /* Exported by i2c-core for i2c-isa only */ | ||
45 | extern void i2c_adapter_dev_release(struct device *dev); | ||
46 | extern struct class i2c_adapter_class; | ||
47 | |||
44 | static u32 isa_func(struct i2c_adapter *adapter); | 48 | static u32 isa_func(struct i2c_adapter *adapter); |
45 | 49 | ||
46 | /* This is the actual algorithm we define */ | 50 | /* This is the actual algorithm we define */ |
@@ -64,16 +68,6 @@ static u32 isa_func(struct i2c_adapter *adapter) | |||
64 | } | 68 | } |
65 | 69 | ||
66 | 70 | ||
67 | /* Copied from i2c-core */ | ||
68 | static ssize_t show_adapter_name(struct device *dev, | ||
69 | struct device_attribute *attr, char *buf) | ||
70 | { | ||
71 | struct i2c_adapter *adap = dev_to_i2c_adapter(dev); | ||
72 | return sprintf(buf, "%s\n", adap->name); | ||
73 | } | ||
74 | static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); | ||
75 | |||
76 | |||
77 | /* We implement an interface which resembles i2c_{add,del}_driver, | 71 | /* We implement an interface which resembles i2c_{add,del}_driver, |
78 | but for i2c-isa drivers. We don't have to remember and handle lists | 72 | but for i2c-isa drivers. We don't have to remember and handle lists |
79 | of drivers and adapters so this is much more simple, of course. */ | 73 | of drivers and adapters so this is much more simple, of course. */ |
@@ -139,41 +133,18 @@ static int __init i2c_isa_init(void) | |||
139 | isa_adapter.nr = ANY_I2C_ISA_BUS; | 133 | isa_adapter.nr = ANY_I2C_ISA_BUS; |
140 | isa_adapter.dev.parent = &platform_bus; | 134 | isa_adapter.dev.parent = &platform_bus; |
141 | sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); | 135 | sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); |
142 | isa_adapter.dev.driver = &i2c_adapter_driver; | ||
143 | isa_adapter.dev.release = &i2c_adapter_dev_release; | 136 | isa_adapter.dev.release = &i2c_adapter_dev_release; |
137 | isa_adapter.dev.class = &i2c_adapter_class; | ||
144 | err = device_register(&isa_adapter.dev); | 138 | err = device_register(&isa_adapter.dev); |
145 | if (err) { | 139 | if (err) { |
146 | printk(KERN_ERR "i2c-isa: Failed to register device\n"); | 140 | printk(KERN_ERR "i2c-isa: Failed to register device\n"); |
147 | goto exit; | 141 | goto exit; |
148 | } | 142 | } |
149 | err = device_create_file(&isa_adapter.dev, &dev_attr_name); | ||
150 | if (err) { | ||
151 | printk(KERN_ERR "i2c-isa: Failed to create name file\n"); | ||
152 | goto exit_unregister; | ||
153 | } | ||
154 | |||
155 | /* Add this adapter to the i2c_adapter class */ | ||
156 | memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device)); | ||
157 | isa_adapter.class_dev.dev = &isa_adapter.dev; | ||
158 | isa_adapter.class_dev.class = &i2c_adapter_class; | ||
159 | strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id, | ||
160 | BUS_ID_SIZE); | ||
161 | err = class_device_register(&isa_adapter.class_dev); | ||
162 | if (err) { | ||
163 | printk(KERN_ERR "i2c-isa: Failed to register class device\n"); | ||
164 | goto exit_remove_name; | ||
165 | } | ||
166 | 143 | ||
167 | dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); | 144 | dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); |
168 | 145 | ||
169 | return 0; | 146 | return 0; |
170 | 147 | ||
171 | exit_remove_name: | ||
172 | device_remove_file(&isa_adapter.dev, &dev_attr_name); | ||
173 | exit_unregister: | ||
174 | init_completion(&isa_adapter.dev_released); /* Needed? */ | ||
175 | device_unregister(&isa_adapter.dev); | ||
176 | wait_for_completion(&isa_adapter.dev_released); | ||
177 | exit: | 148 | exit: |
178 | return err; | 149 | return err; |
179 | } | 150 | } |
@@ -201,15 +172,11 @@ static void __exit i2c_isa_exit(void) | |||
201 | /* Clean up the sysfs representation */ | 172 | /* Clean up the sysfs representation */ |
202 | dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); | 173 | dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); |
203 | init_completion(&isa_adapter.dev_released); | 174 | init_completion(&isa_adapter.dev_released); |
204 | init_completion(&isa_adapter.class_dev_released); | ||
205 | class_device_unregister(&isa_adapter.class_dev); | ||
206 | device_remove_file(&isa_adapter.dev, &dev_attr_name); | ||
207 | device_unregister(&isa_adapter.dev); | 175 | device_unregister(&isa_adapter.dev); |
208 | 176 | ||
209 | /* Wait for sysfs to drop all references */ | 177 | /* Wait for sysfs to drop all references */ |
210 | dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); | 178 | dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); |
211 | wait_for_completion(&isa_adapter.dev_released); | 179 | wait_for_completion(&isa_adapter.dev_released); |
212 | wait_for_completion(&isa_adapter.class_dev_released); | ||
213 | 180 | ||
214 | dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); | 181 | dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); |
215 | } | 182 | } |
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c index efa3ecc5522a..6352121a2827 100644 --- a/drivers/i2c/busses/i2c-ixp2000.c +++ b/drivers/i2c/busses/i2c-ixp2000.c | |||
@@ -118,7 +118,7 @@ static int ixp2000_i2c_probe(struct platform_device *plat_dev) | |||
118 | 118 | ||
119 | drv_data->adapter.id = I2C_HW_B_IXP2000, | 119 | drv_data->adapter.id = I2C_HW_B_IXP2000, |
120 | strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, | 120 | strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, |
121 | I2C_NAME_SIZE); | 121 | sizeof(drv_data->adapter.name)); |
122 | drv_data->adapter.algo_data = &drv_data->algo_data, | 122 | drv_data->adapter.algo_data = &drv_data->algo_data, |
123 | 123 | ||
124 | drv_data->adapter.dev.parent = &plat_dev->dev; | 124 | drv_data->adapter.dev.parent = &plat_dev->dev; |
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c index 08e89b83984a..069ed7f3b395 100644 --- a/drivers/i2c/busses/i2c-ixp4xx.c +++ b/drivers/i2c/busses/i2c-ixp4xx.c | |||
@@ -127,7 +127,7 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev) | |||
127 | drv_data->adapter.id = I2C_HW_B_IXP4XX; | 127 | drv_data->adapter.id = I2C_HW_B_IXP4XX; |
128 | drv_data->adapter.class = I2C_CLASS_HWMON; | 128 | drv_data->adapter.class = I2C_CLASS_HWMON; |
129 | strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, | 129 | strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, |
130 | I2C_NAME_SIZE); | 130 | sizeof(drv_data->adapter.name)); |
131 | drv_data->adapter.algo_data = &drv_data->algo_data; | 131 | drv_data->adapter.algo_data = &drv_data->algo_data; |
132 | 132 | ||
133 | drv_data->adapter.dev.parent = &plat_dev->dev; | 133 | drv_data->adapter.dev.parent = &plat_dev->dev; |
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index ee65aa1be13a..c6b6898592b1 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c | |||
@@ -17,7 +17,6 @@ | |||
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/sched.h> | 18 | #include <linux/sched.h> |
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/pci.h> | ||
21 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
22 | 21 | ||
23 | #include <asm/io.h> | 22 | #include <asm/io.h> |
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index a3283b907eb8..a55b3335d1be 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c | |||
@@ -508,7 +508,7 @@ mv64xxx_i2c_probe(struct platform_device *pd) | |||
508 | } | 508 | } |
509 | 509 | ||
510 | strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter", | 510 | strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter", |
511 | I2C_NAME_SIZE); | 511 | sizeof(drv_data->adapter.name)); |
512 | 512 | ||
513 | init_waitqueue_head(&drv_data->waitq); | 513 | init_waitqueue_head(&drv_data->waitq); |
514 | spin_lock_init(&drv_data->lock); | 514 | spin_lock_init(&drv_data->lock); |
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c index 1514ec5b77f8..3cd0d63e7b50 100644 --- a/drivers/i2c/busses/i2c-nforce2.c +++ b/drivers/i2c/busses/i2c-nforce2.c | |||
@@ -33,6 +33,8 @@ | |||
33 | nForce4 MCP-04 0034 | 33 | nForce4 MCP-04 0034 |
34 | nForce4 MCP51 0264 | 34 | nForce4 MCP51 0264 |
35 | nForce4 MCP55 0368 | 35 | nForce4 MCP55 0368 |
36 | nForce MCP61 03EB | ||
37 | nForce MCP65 0446 | ||
36 | 38 | ||
37 | This driver supports the 2 SMBuses that are included in the MCP of the | 39 | This driver supports the 2 SMBuses that are included in the MCP of the |
38 | nForce2/3/4/5xx chipsets. | 40 | nForce2/3/4/5xx chipsets. |
@@ -200,6 +202,8 @@ static struct pci_device_id nforce2_ids[] = { | |||
200 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) }, | 202 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) }, |
201 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) }, | 203 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) }, |
202 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) }, | 204 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) }, |
205 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS) }, | ||
206 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS) }, | ||
203 | { 0 } | 207 | { 0 } |
204 | }; | 208 | }; |
205 | 209 | ||
@@ -240,7 +244,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar, | |||
240 | smbus->adapter.algo = &smbus_algorithm; | 244 | smbus->adapter.algo = &smbus_algorithm; |
241 | smbus->adapter.algo_data = smbus; | 245 | smbus->adapter.algo_data = smbus; |
242 | smbus->adapter.dev.parent = &dev->dev; | 246 | smbus->adapter.dev.parent = &dev->dev; |
243 | snprintf(smbus->adapter.name, I2C_NAME_SIZE, | 247 | snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), |
244 | "SMBus nForce2 adapter at %04x", smbus->base); | 248 | "SMBus nForce2 adapter at %04x", smbus->base); |
245 | 249 | ||
246 | error = i2c_add_adapter(&smbus->adapter); | 250 | error = i2c_add_adapter(&smbus->adapter); |
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index bcd8367cede1..e471e3bfdc1e 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
@@ -605,7 +605,8 @@ omap_i2c_probe(struct platform_device *pdev) | |||
605 | adap->dev.parent = &pdev->dev; | 605 | adap->dev.parent = &pdev->dev; |
606 | 606 | ||
607 | /* i2c device drivers may be active on return from add_adapter() */ | 607 | /* i2c device drivers may be active on return from add_adapter() */ |
608 | r = i2c_add_adapter(adap); | 608 | adap->nr = pdev->id; |
609 | r = i2c_add_numbered_adapter(adap); | ||
609 | if (r) { | 610 | if (r) { |
610 | dev_err(dev->dev, "failure adding adapter\n"); | 611 | dev_err(dev->dev, "failure adding adapter\n"); |
611 | goto err_free_irq; | 612 | goto err_free_irq; |
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c index 4bc42810b9aa..49a95e2887bc 100644 --- a/drivers/i2c/busses/i2c-parport-light.c +++ b/drivers/i2c/busses/i2c-parport-light.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* ------------------------------------------------------------------------ * | 1 | /* ------------------------------------------------------------------------ * |
2 | * i2c-parport.c I2C bus over parallel port * | 2 | * i2c-parport-light.c I2C bus over parallel port * |
3 | * ------------------------------------------------------------------------ * | 3 | * ------------------------------------------------------------------------ * |
4 | Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> | 4 | Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org> |
5 | 5 | ||
6 | Based on older i2c-velleman.c driver | 6 | Based on older i2c-velleman.c driver |
7 | Copyright (C) 1995-2000 Simon G. Vogl | 7 | Copyright (C) 1995-2000 Simon G. Vogl |
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
30 | #include <linux/platform_device.h> | ||
30 | #include <linux/ioport.h> | 31 | #include <linux/ioport.h> |
31 | #include <linux/i2c.h> | 32 | #include <linux/i2c.h> |
32 | #include <linux/i2c-algo-bit.h> | 33 | #include <linux/i2c-algo-bit.h> |
@@ -34,6 +35,9 @@ | |||
34 | #include "i2c-parport.h" | 35 | #include "i2c-parport.h" |
35 | 36 | ||
36 | #define DEFAULT_BASE 0x378 | 37 | #define DEFAULT_BASE 0x378 |
38 | #define DRVNAME "i2c-parport-light" | ||
39 | |||
40 | static struct platform_device *pdev; | ||
37 | 41 | ||
38 | static u16 base; | 42 | static u16 base; |
39 | module_param(base, ushort, 0); | 43 | module_param(base, ushort, 0); |
@@ -106,7 +110,7 @@ static struct i2c_algo_bit_data parport_algo_data = { | |||
106 | .timeout = HZ, | 110 | .timeout = HZ, |
107 | }; | 111 | }; |
108 | 112 | ||
109 | /* ----- I2c structure ---------------------------------------------------- */ | 113 | /* ----- Driver registration ---------------------------------------------- */ |
110 | 114 | ||
111 | static struct i2c_adapter parport_adapter = { | 115 | static struct i2c_adapter parport_adapter = { |
112 | .owner = THIS_MODULE, | 116 | .owner = THIS_MODULE, |
@@ -116,55 +120,141 @@ static struct i2c_adapter parport_adapter = { | |||
116 | .name = "Parallel port adapter (light)", | 120 | .name = "Parallel port adapter (light)", |
117 | }; | 121 | }; |
118 | 122 | ||
119 | /* ----- Module loading, unloading and information ------------------------ */ | 123 | static int __devinit i2c_parport_probe(struct platform_device *pdev) |
124 | { | ||
125 | int err; | ||
126 | struct resource *res; | ||
127 | |||
128 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
129 | if (!request_region(res->start, res->end - res->start + 1, DRVNAME)) | ||
130 | return -EBUSY; | ||
131 | |||
132 | /* Reset hardware to a sane state (SCL and SDA high) */ | ||
133 | parport_setsda(NULL, 1); | ||
134 | parport_setscl(NULL, 1); | ||
135 | /* Other init if needed (power on...) */ | ||
136 | if (adapter_parm[type].init.val) | ||
137 | line_set(1, &adapter_parm[type].init); | ||
138 | |||
139 | parport_adapter.dev.parent = &pdev->dev; | ||
140 | err = i2c_bit_add_bus(&parport_adapter); | ||
141 | if (err) { | ||
142 | dev_err(&pdev->dev, "Unable to register with I2C\n"); | ||
143 | goto exit_region; | ||
144 | } | ||
145 | return 0; | ||
146 | |||
147 | exit_region: | ||
148 | release_region(res->start, res->end - res->start + 1); | ||
149 | return err; | ||
150 | } | ||
151 | |||
152 | static int __devexit i2c_parport_remove(struct platform_device *pdev) | ||
153 | { | ||
154 | struct resource *res; | ||
155 | |||
156 | i2c_del_adapter(&parport_adapter); | ||
157 | |||
158 | /* Un-init if needed (power off...) */ | ||
159 | if (adapter_parm[type].init.val) | ||
160 | line_set(0, &adapter_parm[type].init); | ||
161 | |||
162 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
163 | release_region(res->start, res->end - res->start + 1); | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | static struct platform_driver i2c_parport_driver = { | ||
168 | .driver = { | ||
169 | .owner = THIS_MODULE, | ||
170 | .name = DRVNAME, | ||
171 | }, | ||
172 | .probe = i2c_parport_probe, | ||
173 | .remove = __devexit_p(i2c_parport_remove), | ||
174 | }; | ||
175 | |||
176 | static int __init i2c_parport_device_add(u16 address) | ||
177 | { | ||
178 | struct resource res = { | ||
179 | .start = address, | ||
180 | .end = address + 2, | ||
181 | .name = DRVNAME, | ||
182 | .flags = IORESOURCE_IO, | ||
183 | }; | ||
184 | int err; | ||
185 | |||
186 | pdev = platform_device_alloc(DRVNAME, -1); | ||
187 | if (!pdev) { | ||
188 | err = -ENOMEM; | ||
189 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); | ||
190 | goto exit; | ||
191 | } | ||
192 | |||
193 | err = platform_device_add_resources(pdev, &res, 1); | ||
194 | if (err) { | ||
195 | printk(KERN_ERR DRVNAME ": Device resource addition failed " | ||
196 | "(%d)\n", err); | ||
197 | goto exit_device_put; | ||
198 | } | ||
199 | |||
200 | err = platform_device_add(pdev); | ||
201 | if (err) { | ||
202 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", | ||
203 | err); | ||
204 | goto exit_device_put; | ||
205 | } | ||
206 | |||
207 | return 0; | ||
208 | |||
209 | exit_device_put: | ||
210 | platform_device_put(pdev); | ||
211 | exit: | ||
212 | return err; | ||
213 | } | ||
120 | 214 | ||
121 | static int __init i2c_parport_init(void) | 215 | static int __init i2c_parport_init(void) |
122 | { | 216 | { |
217 | int err; | ||
218 | |||
123 | if (type < 0) { | 219 | if (type < 0) { |
124 | printk(KERN_WARNING "i2c-parport: adapter type unspecified\n"); | 220 | printk(KERN_ERR DRVNAME ": adapter type unspecified\n"); |
125 | return -ENODEV; | 221 | return -ENODEV; |
126 | } | 222 | } |
127 | 223 | ||
128 | if (type >= ARRAY_SIZE(adapter_parm)) { | 224 | if (type >= ARRAY_SIZE(adapter_parm)) { |
129 | printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type); | 225 | printk(KERN_ERR DRVNAME ": invalid type (%d)\n", type); |
130 | return -ENODEV; | 226 | return -ENODEV; |
131 | } | 227 | } |
132 | 228 | ||
133 | if (base == 0) { | 229 | if (base == 0) { |
134 | printk(KERN_INFO "i2c-parport: using default base 0x%x\n", DEFAULT_BASE); | 230 | pr_info(DRVNAME ": using default base 0x%x\n", DEFAULT_BASE); |
135 | base = DEFAULT_BASE; | 231 | base = DEFAULT_BASE; |
136 | } | 232 | } |
137 | 233 | ||
138 | if (!request_region(base, 3, "i2c-parport")) | ||
139 | return -ENODEV; | ||
140 | |||
141 | if (!adapter_parm[type].getscl.val) | 234 | if (!adapter_parm[type].getscl.val) |
142 | parport_algo_data.getscl = NULL; | 235 | parport_algo_data.getscl = NULL; |
143 | 236 | ||
144 | /* Reset hardware to a sane state (SCL and SDA high) */ | 237 | /* Sets global pdev as a side effect */ |
145 | parport_setsda(NULL, 1); | 238 | err = i2c_parport_device_add(base); |
146 | parport_setscl(NULL, 1); | 239 | if (err) |
147 | /* Other init if needed (power on...) */ | 240 | goto exit; |
148 | if (adapter_parm[type].init.val) | ||
149 | line_set(1, &adapter_parm[type].init); | ||
150 | 241 | ||
151 | if (i2c_bit_add_bus(&parport_adapter) < 0) { | 242 | err = platform_driver_register(&i2c_parport_driver); |
152 | printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); | 243 | if (err) |
153 | release_region(base, 3); | 244 | goto exit_device; |
154 | return -ENODEV; | ||
155 | } | ||
156 | 245 | ||
157 | return 0; | 246 | return 0; |
247 | |||
248 | exit_device: | ||
249 | platform_device_unregister(pdev); | ||
250 | exit: | ||
251 | return err; | ||
158 | } | 252 | } |
159 | 253 | ||
160 | static void __exit i2c_parport_exit(void) | 254 | static void __exit i2c_parport_exit(void) |
161 | { | 255 | { |
162 | /* Un-init if needed (power off...) */ | 256 | platform_driver_unregister(&i2c_parport_driver); |
163 | if (adapter_parm[type].init.val) | 257 | platform_device_unregister(pdev); |
164 | line_set(0, &adapter_parm[type].init); | ||
165 | |||
166 | i2c_del_adapter(&parport_adapter); | ||
167 | release_region(base, 3); | ||
168 | } | 258 | } |
169 | 259 | ||
170 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | 260 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c index 66696a40c7b5..039a07fde908 100644 --- a/drivers/i2c/busses/i2c-parport.c +++ b/drivers/i2c/busses/i2c-parport.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* ------------------------------------------------------------------------ * | 1 | /* ------------------------------------------------------------------------ * |
2 | * i2c-parport.c I2C bus over parallel port * | 2 | * i2c-parport.c I2C bus over parallel port * |
3 | * ------------------------------------------------------------------------ * | 3 | * ------------------------------------------------------------------------ * |
4 | Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> | 4 | Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org> |
5 | 5 | ||
6 | Based on older i2c-philips-par.c driver | 6 | Based on older i2c-philips-par.c driver |
7 | Copyright (C) 1995-2000 Simon G. Vogl | 7 | Copyright (C) 1995-2000 Simon G. Vogl |
@@ -137,19 +137,12 @@ static struct i2c_algo_bit_data parport_algo_data = { | |||
137 | .setscl = parport_setscl, | 137 | .setscl = parport_setscl, |
138 | .getsda = parport_getsda, | 138 | .getsda = parport_getsda, |
139 | .getscl = parport_getscl, | 139 | .getscl = parport_getscl, |
140 | .udelay = 60, | 140 | .udelay = 10, /* ~50 kbps */ |
141 | .timeout = HZ, | 141 | .timeout = HZ, |
142 | }; | 142 | }; |
143 | 143 | ||
144 | /* ----- I2c and parallel port call-back functions and structures --------- */ | 144 | /* ----- I2c and parallel port call-back functions and structures --------- */ |
145 | 145 | ||
146 | static struct i2c_adapter parport_adapter = { | ||
147 | .owner = THIS_MODULE, | ||
148 | .class = I2C_CLASS_HWMON, | ||
149 | .id = I2C_HW_B_LP, | ||
150 | .name = "Parallel port adapter", | ||
151 | }; | ||
152 | |||
153 | static void i2c_parport_attach (struct parport *port) | 146 | static void i2c_parport_attach (struct parport *port) |
154 | { | 147 | { |
155 | struct i2c_par *adapter; | 148 | struct i2c_par *adapter; |
@@ -169,12 +162,20 @@ static void i2c_parport_attach (struct parport *port) | |||
169 | } | 162 | } |
170 | 163 | ||
171 | /* Fill the rest of the structure */ | 164 | /* Fill the rest of the structure */ |
172 | adapter->adapter = parport_adapter; | 165 | adapter->adapter.owner = THIS_MODULE; |
166 | adapter->adapter.class = I2C_CLASS_HWMON; | ||
167 | adapter->adapter.id = I2C_HW_B_LP; | ||
168 | strlcpy(adapter->adapter.name, "Parallel port adapter", | ||
169 | sizeof(adapter->adapter.name)); | ||
173 | adapter->algo_data = parport_algo_data; | 170 | adapter->algo_data = parport_algo_data; |
174 | if (!adapter_parm[type].getscl.val) | 171 | /* Slow down if we can't sense SCL */ |
172 | if (!adapter_parm[type].getscl.val) { | ||
175 | adapter->algo_data.getscl = NULL; | 173 | adapter->algo_data.getscl = NULL; |
174 | adapter->algo_data.udelay = 50; /* ~10 kbps */ | ||
175 | } | ||
176 | adapter->algo_data.data = port; | 176 | adapter->algo_data.data = port; |
177 | adapter->adapter.algo_data = &adapter->algo_data; | 177 | adapter->adapter.algo_data = &adapter->algo_data; |
178 | adapter->adapter.dev.parent = port->physport->dev; | ||
178 | 179 | ||
179 | if (parport_claim_or_block(adapter->pdev) < 0) { | 180 | if (parport_claim_or_block(adapter->pdev) < 0) { |
180 | printk(KERN_ERR "i2c-parport: Could not claim parallel port\n"); | 181 | printk(KERN_ERR "i2c-parport: Could not claim parallel port\n"); |
@@ -214,11 +215,12 @@ static void i2c_parport_detach (struct parport *port) | |||
214 | for (prev = NULL, adapter = adapter_list; adapter; | 215 | for (prev = NULL, adapter = adapter_list; adapter; |
215 | prev = adapter, adapter = adapter->next) { | 216 | prev = adapter, adapter = adapter->next) { |
216 | if (adapter->pdev->port == port) { | 217 | if (adapter->pdev->port == port) { |
218 | i2c_del_adapter(&adapter->adapter); | ||
219 | |||
217 | /* Un-init if needed (power off...) */ | 220 | /* Un-init if needed (power off...) */ |
218 | if (adapter_parm[type].init.val) | 221 | if (adapter_parm[type].init.val) |
219 | line_set(port, 0, &adapter_parm[type].init); | 222 | line_set(port, 0, &adapter_parm[type].init); |
220 | 223 | ||
221 | i2c_del_adapter(&adapter->adapter); | ||
222 | parport_unregister_device(adapter->pdev); | 224 | parport_unregister_device(adapter->pdev); |
223 | if (prev) | 225 | if (prev) |
224 | prev->next = adapter->next; | 226 | prev->next = adapter->next; |
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c index bf89eeef74e9..58e32714afb5 100644 --- a/drivers/i2c/busses/i2c-pasemi.c +++ b/drivers/i2c/busses/i2c-pasemi.c | |||
@@ -358,7 +358,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev, | |||
358 | } | 358 | } |
359 | 359 | ||
360 | smbus->adapter.owner = THIS_MODULE; | 360 | smbus->adapter.owner = THIS_MODULE; |
361 | snprintf(smbus->adapter.name, I2C_NAME_SIZE, | 361 | snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), |
362 | "PA Semi SMBus adapter at 0x%lx", smbus->base); | 362 | "PA Semi SMBus adapter at 0x%lx", smbus->base); |
363 | smbus->adapter.class = I2C_CLASS_HWMON; | 363 | smbus->adapter.class = I2C_CLASS_HWMON; |
364 | smbus->adapter.algo = &smbus_algorithm; | 364 | smbus->adapter.algo = &smbus_algorithm; |
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c index cc6536a19eca..5161aaf9341b 100644 --- a/drivers/i2c/busses/i2c-pca-isa.c +++ b/drivers/i2c/busses/i2c-pca-isa.c | |||
@@ -25,9 +25,9 @@ | |||
25 | #include <linux/slab.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/pci.h> | ||
29 | #include <linux/wait.h> | 28 | #include <linux/wait.h> |
30 | 29 | ||
30 | #include <linux/isa.h> | ||
31 | #include <linux/i2c.h> | 31 | #include <linux/i2c.h> |
32 | #include <linux/i2c-algo-pca.h> | 32 | #include <linux/i2c-algo-pca.h> |
33 | 33 | ||
@@ -119,27 +119,26 @@ static struct i2c_adapter pca_isa_ops = { | |||
119 | .name = "PCA9564 ISA Adapter", | 119 | .name = "PCA9564 ISA Adapter", |
120 | }; | 120 | }; |
121 | 121 | ||
122 | static int __init pca_isa_init(void) | 122 | static int __devinit pca_isa_probe(struct device *dev, unsigned int id) |
123 | { | 123 | { |
124 | |||
125 | init_waitqueue_head(&pca_wait); | 124 | init_waitqueue_head(&pca_wait); |
126 | 125 | ||
127 | printk(KERN_INFO "i2c-pca-isa: i/o base %#08lx. irq %d\n", base, irq); | 126 | dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq); |
128 | 127 | ||
129 | if (!request_region(base, IO_SIZE, "i2c-pca-isa")) { | 128 | if (!request_region(base, IO_SIZE, "i2c-pca-isa")) { |
130 | printk(KERN_ERR "i2c-pca-isa: I/O address %#08lx is in use.\n", base); | 129 | dev_err(dev, "I/O address %#08lx is in use\n", base); |
131 | goto out; | 130 | goto out; |
132 | } | 131 | } |
133 | 132 | ||
134 | if (irq > -1) { | 133 | if (irq > -1) { |
135 | if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) { | 134 | if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) { |
136 | printk(KERN_ERR "i2c-pca-isa: Request irq%d failed\n", irq); | 135 | dev_err(dev, "Request irq%d failed\n", irq); |
137 | goto out_region; | 136 | goto out_region; |
138 | } | 137 | } |
139 | } | 138 | } |
140 | 139 | ||
141 | if (i2c_pca_add_bus(&pca_isa_ops) < 0) { | 140 | if (i2c_pca_add_bus(&pca_isa_ops) < 0) { |
142 | printk(KERN_ERR "i2c-pca-isa: Failed to add i2c bus\n"); | 141 | dev_err(dev, "Failed to add i2c bus\n"); |
143 | goto out_irq; | 142 | goto out_irq; |
144 | } | 143 | } |
145 | 144 | ||
@@ -154,7 +153,7 @@ static int __init pca_isa_init(void) | |||
154 | return -ENODEV; | 153 | return -ENODEV; |
155 | } | 154 | } |
156 | 155 | ||
157 | static void pca_isa_exit(void) | 156 | static int __devexit pca_isa_remove(struct device *dev, unsigned int id) |
158 | { | 157 | { |
159 | i2c_del_adapter(&pca_isa_ops); | 158 | i2c_del_adapter(&pca_isa_ops); |
160 | 159 | ||
@@ -163,6 +162,27 @@ static void pca_isa_exit(void) | |||
163 | free_irq(irq, &pca_isa_ops); | 162 | free_irq(irq, &pca_isa_ops); |
164 | } | 163 | } |
165 | release_region(base, IO_SIZE); | 164 | release_region(base, IO_SIZE); |
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static struct isa_driver pca_isa_driver = { | ||
170 | .probe = pca_isa_probe, | ||
171 | .remove = __devexit_p(pca_isa_remove), | ||
172 | .driver = { | ||
173 | .owner = THIS_MODULE, | ||
174 | .name = "i2c-pca-isa", | ||
175 | } | ||
176 | }; | ||
177 | |||
178 | static int __init pca_isa_init(void) | ||
179 | { | ||
180 | return isa_register_driver(&pca_isa_driver, 1); | ||
181 | } | ||
182 | |||
183 | static void __exit pca_isa_exit(void) | ||
184 | { | ||
185 | isa_unregister_driver(&pca_isa_driver); | ||
166 | } | 186 | } |
167 | 187 | ||
168 | MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); | 188 | MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); |
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c index 21b180904085..5a52bf5e3fb0 100644 --- a/drivers/i2c/busses/i2c-piix4.c +++ b/drivers/i2c/busses/i2c-piix4.c | |||
@@ -428,7 +428,7 @@ static int __devinit piix4_probe(struct pci_dev *dev, | |||
428 | /* set up the sysfs linkage to our parent device */ | 428 | /* set up the sysfs linkage to our parent device */ |
429 | piix4_adapter.dev.parent = &dev->dev; | 429 | piix4_adapter.dev.parent = &dev->dev; |
430 | 430 | ||
431 | snprintf(piix4_adapter.name, I2C_NAME_SIZE, | 431 | snprintf(piix4_adapter.name, sizeof(piix4_adapter.name), |
432 | "SMBus PIIX4 adapter at %04x", piix4_smba); | 432 | "SMBus PIIX4 adapter at %04x", piix4_smba); |
433 | 433 | ||
434 | if ((retval = i2c_add_adapter(&piix4_adapter))) { | 434 | if ((retval = i2c_add_adapter(&piix4_adapter))) { |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 14e83d0aac8c..8a0a99b93641 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
@@ -539,6 +539,18 @@ static inline void i2c_pxa_start_message(struct pxa_i2c *i2c) | |||
539 | writel(icr | ICR_START | ICR_TB, _ICR(i2c)); | 539 | writel(icr | ICR_START | ICR_TB, _ICR(i2c)); |
540 | } | 540 | } |
541 | 541 | ||
542 | static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c) | ||
543 | { | ||
544 | u32 icr; | ||
545 | |||
546 | /* | ||
547 | * Clear the STOP and ACK flags | ||
548 | */ | ||
549 | icr = readl(_ICR(i2c)); | ||
550 | icr &= ~(ICR_STOP | ICR_ACKNAK); | ||
551 | writel(icr, _ICR(i2c)); | ||
552 | } | ||
553 | |||
542 | /* | 554 | /* |
543 | * We are protected by the adapter bus mutex. | 555 | * We are protected by the adapter bus mutex. |
544 | */ | 556 | */ |
@@ -581,6 +593,7 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num) | |||
581 | * The rest of the processing occurs in the interrupt handler. | 593 | * The rest of the processing occurs in the interrupt handler. |
582 | */ | 594 | */ |
583 | timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); | 595 | timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); |
596 | i2c_pxa_stop_message(i2c); | ||
584 | 597 | ||
585 | /* | 598 | /* |
586 | * We place the return code in i2c->msg_idx. | 599 | * We place the return code in i2c->msg_idx. |
@@ -825,7 +838,7 @@ static const struct i2c_algorithm i2c_pxa_algorithm = { | |||
825 | }; | 838 | }; |
826 | 839 | ||
827 | static struct pxa_i2c i2c_pxa = { | 840 | static struct pxa_i2c i2c_pxa = { |
828 | .lock = SPIN_LOCK_UNLOCKED, | 841 | .lock = __SPIN_LOCK_UNLOCKED(i2c_pxa.lock), |
829 | .adap = { | 842 | .adap = { |
830 | .owner = THIS_MODULE, | 843 | .owner = THIS_MODULE, |
831 | .algo = &i2c_pxa_algorithm, | 844 | .algo = &i2c_pxa_algorithm, |
@@ -839,9 +852,7 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
839 | { | 852 | { |
840 | struct pxa_i2c *i2c = &i2c_pxa; | 853 | struct pxa_i2c *i2c = &i2c_pxa; |
841 | struct resource *res; | 854 | struct resource *res; |
842 | #ifdef CONFIG_I2C_PXA_SLAVE | ||
843 | struct i2c_pxa_platform_data *plat = dev->dev.platform_data; | 855 | struct i2c_pxa_platform_data *plat = dev->dev.platform_data; |
844 | #endif | ||
845 | int ret; | 856 | int ret; |
846 | int irq; | 857 | int irq; |
847 | 858 | ||
@@ -889,14 +900,14 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
889 | pxa_gpio_mode(GPIO117_I2CSCL_MD); | 900 | pxa_gpio_mode(GPIO117_I2CSCL_MD); |
890 | pxa_gpio_mode(GPIO118_I2CSDA_MD); | 901 | pxa_gpio_mode(GPIO118_I2CSDA_MD); |
891 | #endif | 902 | #endif |
892 | pxa_set_cken(CKEN14_I2C, 1); | 903 | pxa_set_cken(CKEN_I2C, 1); |
893 | break; | 904 | break; |
894 | #ifdef CONFIG_PXA27x | 905 | #ifdef CONFIG_PXA27x |
895 | case 1: | 906 | case 1: |
896 | local_irq_disable(); | 907 | local_irq_disable(); |
897 | PCFR |= PCFR_PI2CEN; | 908 | PCFR |= PCFR_PI2CEN; |
898 | local_irq_enable(); | 909 | local_irq_enable(); |
899 | pxa_set_cken(CKEN15_PWRI2C, 1); | 910 | pxa_set_cken(CKEN_PWRI2C, 1); |
900 | #endif | 911 | #endif |
901 | } | 912 | } |
902 | 913 | ||
@@ -911,6 +922,10 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
911 | i2c->adap.algo_data = i2c; | 922 | i2c->adap.algo_data = i2c; |
912 | i2c->adap.dev.parent = &dev->dev; | 923 | i2c->adap.dev.parent = &dev->dev; |
913 | 924 | ||
925 | if (plat) { | ||
926 | i2c->adap.class = plat->class; | ||
927 | } | ||
928 | |||
914 | ret = i2c_add_adapter(&i2c->adap); | 929 | ret = i2c_add_adapter(&i2c->adap); |
915 | if (ret < 0) { | 930 | if (ret < 0) { |
916 | printk(KERN_INFO "I2C: Failed to add bus\n"); | 931 | printk(KERN_INFO "I2C: Failed to add bus\n"); |
@@ -933,11 +948,11 @@ eadapt: | |||
933 | ereqirq: | 948 | ereqirq: |
934 | switch (dev->id) { | 949 | switch (dev->id) { |
935 | case 0: | 950 | case 0: |
936 | pxa_set_cken(CKEN14_I2C, 0); | 951 | pxa_set_cken(CKEN_I2C, 0); |
937 | break; | 952 | break; |
938 | #ifdef CONFIG_PXA27x | 953 | #ifdef CONFIG_PXA27x |
939 | case 1: | 954 | case 1: |
940 | pxa_set_cken(CKEN15_PWRI2C, 0); | 955 | pxa_set_cken(CKEN_PWRI2C, 0); |
941 | local_irq_disable(); | 956 | local_irq_disable(); |
942 | PCFR &= ~PCFR_PI2CEN; | 957 | PCFR &= ~PCFR_PI2CEN; |
943 | local_irq_enable(); | 958 | local_irq_enable(); |
@@ -960,11 +975,11 @@ static int i2c_pxa_remove(struct platform_device *dev) | |||
960 | free_irq(i2c->irq, i2c); | 975 | free_irq(i2c->irq, i2c); |
961 | switch (dev->id) { | 976 | switch (dev->id) { |
962 | case 0: | 977 | case 0: |
963 | pxa_set_cken(CKEN14_I2C, 0); | 978 | pxa_set_cken(CKEN_I2C, 0); |
964 | break; | 979 | break; |
965 | #ifdef CONFIG_PXA27x | 980 | #ifdef CONFIG_PXA27x |
966 | case 1: | 981 | case 1: |
967 | pxa_set_cken(CKEN15_PWRI2C, 0); | 982 | pxa_set_cken(CKEN_PWRI2C, 0); |
968 | local_irq_disable(); | 983 | local_irq_disable(); |
969 | PCFR &= ~PCFR_PI2CEN; | 984 | PCFR &= ~PCFR_PI2CEN; |
970 | local_irq_enable(); | 985 | local_irq_enable(); |
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 556f244aae76..e68a96f589fd 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c | |||
@@ -61,6 +61,8 @@ struct s3c24xx_i2c { | |||
61 | unsigned int msg_idx; | 61 | unsigned int msg_idx; |
62 | unsigned int msg_ptr; | 62 | unsigned int msg_ptr; |
63 | 63 | ||
64 | unsigned int tx_setup; | ||
65 | |||
64 | enum s3c24xx_i2c_state state; | 66 | enum s3c24xx_i2c_state state; |
65 | 67 | ||
66 | void __iomem *regs; | 68 | void __iomem *regs; |
@@ -199,8 +201,11 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, | |||
199 | dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); | 201 | dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); |
200 | writeb(addr, i2c->regs + S3C2410_IICDS); | 202 | writeb(addr, i2c->regs + S3C2410_IICDS); |
201 | 203 | ||
202 | // delay a bit and reset iiccon before setting start (per samsung) | 204 | /* delay here to ensure the data byte has gotten onto the bus |
203 | udelay(1); | 205 | * before the transaction is started */ |
206 | |||
207 | ndelay(i2c->tx_setup); | ||
208 | |||
204 | dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); | 209 | dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); |
205 | writel(iiccon, i2c->regs + S3C2410_IICCON); | 210 | writel(iiccon, i2c->regs + S3C2410_IICCON); |
206 | 211 | ||
@@ -322,7 +327,15 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
322 | if (!is_msgend(i2c)) { | 327 | if (!is_msgend(i2c)) { |
323 | byte = i2c->msg->buf[i2c->msg_ptr++]; | 328 | byte = i2c->msg->buf[i2c->msg_ptr++]; |
324 | writeb(byte, i2c->regs + S3C2410_IICDS); | 329 | writeb(byte, i2c->regs + S3C2410_IICDS); |
325 | 330 | ||
331 | /* delay after writing the byte to allow the | ||
332 | * data setup time on the bus, as writing the | ||
333 | * data to the register causes the first bit | ||
334 | * to appear on SDA, and SCL will change as | ||
335 | * soon as the interrupt is acknowledged */ | ||
336 | |||
337 | ndelay(i2c->tx_setup); | ||
338 | |||
326 | } else if (!is_lastmsg(i2c)) { | 339 | } else if (!is_lastmsg(i2c)) { |
327 | /* we need to go to the next i2c message */ | 340 | /* we need to go to the next i2c message */ |
328 | 341 | ||
@@ -570,9 +583,10 @@ static const struct i2c_algorithm s3c24xx_i2c_algorithm = { | |||
570 | }; | 583 | }; |
571 | 584 | ||
572 | static struct s3c24xx_i2c s3c24xx_i2c = { | 585 | static struct s3c24xx_i2c s3c24xx_i2c = { |
573 | .lock = SPIN_LOCK_UNLOCKED, | 586 | .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_i2c.lock), |
574 | .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait), | 587 | .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait), |
575 | .adap = { | 588 | .tx_setup = 50, |
589 | .adap = { | ||
576 | .name = "s3c2410-i2c", | 590 | .name = "s3c2410-i2c", |
577 | .owner = THIS_MODULE, | 591 | .owner = THIS_MODULE, |
578 | .algo = &s3c24xx_i2c_algorithm, | 592 | .algo = &s3c24xx_i2c_algorithm, |
@@ -731,26 +745,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) | |||
731 | return 0; | 745 | return 0; |
732 | } | 746 | } |
733 | 747 | ||
734 | static void s3c24xx_i2c_free(struct s3c24xx_i2c *i2c) | ||
735 | { | ||
736 | if (i2c->clk != NULL && !IS_ERR(i2c->clk)) { | ||
737 | clk_disable(i2c->clk); | ||
738 | clk_put(i2c->clk); | ||
739 | i2c->clk = NULL; | ||
740 | } | ||
741 | |||
742 | if (i2c->regs != NULL) { | ||
743 | iounmap(i2c->regs); | ||
744 | i2c->regs = NULL; | ||
745 | } | ||
746 | |||
747 | if (i2c->ioarea != NULL) { | ||
748 | release_resource(i2c->ioarea); | ||
749 | kfree(i2c->ioarea); | ||
750 | i2c->ioarea = NULL; | ||
751 | } | ||
752 | } | ||
753 | |||
754 | /* s3c24xx_i2c_probe | 748 | /* s3c24xx_i2c_probe |
755 | * | 749 | * |
756 | * called by the bus driver when a suitable device is found | 750 | * called by the bus driver when a suitable device is found |
@@ -769,7 +763,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
769 | if (IS_ERR(i2c->clk)) { | 763 | if (IS_ERR(i2c->clk)) { |
770 | dev_err(&pdev->dev, "cannot get clock\n"); | 764 | dev_err(&pdev->dev, "cannot get clock\n"); |
771 | ret = -ENOENT; | 765 | ret = -ENOENT; |
772 | goto out; | 766 | goto err_noclk; |
773 | } | 767 | } |
774 | 768 | ||
775 | dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); | 769 | dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); |
@@ -782,7 +776,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
782 | if (res == NULL) { | 776 | if (res == NULL) { |
783 | dev_err(&pdev->dev, "cannot find IO resource\n"); | 777 | dev_err(&pdev->dev, "cannot find IO resource\n"); |
784 | ret = -ENOENT; | 778 | ret = -ENOENT; |
785 | goto out; | 779 | goto err_clk; |
786 | } | 780 | } |
787 | 781 | ||
788 | i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1, | 782 | i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1, |
@@ -791,7 +785,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
791 | if (i2c->ioarea == NULL) { | 785 | if (i2c->ioarea == NULL) { |
792 | dev_err(&pdev->dev, "cannot request IO\n"); | 786 | dev_err(&pdev->dev, "cannot request IO\n"); |
793 | ret = -ENXIO; | 787 | ret = -ENXIO; |
794 | goto out; | 788 | goto err_clk; |
795 | } | 789 | } |
796 | 790 | ||
797 | i2c->regs = ioremap(res->start, (res->end-res->start)+1); | 791 | i2c->regs = ioremap(res->start, (res->end-res->start)+1); |
@@ -799,7 +793,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
799 | if (i2c->regs == NULL) { | 793 | if (i2c->regs == NULL) { |
800 | dev_err(&pdev->dev, "cannot map IO\n"); | 794 | dev_err(&pdev->dev, "cannot map IO\n"); |
801 | ret = -ENXIO; | 795 | ret = -ENXIO; |
802 | goto out; | 796 | goto err_ioarea; |
803 | } | 797 | } |
804 | 798 | ||
805 | dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res); | 799 | dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res); |
@@ -813,7 +807,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
813 | 807 | ||
814 | ret = s3c24xx_i2c_init(i2c); | 808 | ret = s3c24xx_i2c_init(i2c); |
815 | if (ret != 0) | 809 | if (ret != 0) |
816 | goto out; | 810 | goto err_iomap; |
817 | 811 | ||
818 | /* find the IRQ for this unit (note, this relies on the init call to | 812 | /* find the IRQ for this unit (note, this relies on the init call to |
819 | * ensure no current IRQs pending | 813 | * ensure no current IRQs pending |
@@ -823,7 +817,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
823 | if (res == NULL) { | 817 | if (res == NULL) { |
824 | dev_err(&pdev->dev, "cannot find IRQ\n"); | 818 | dev_err(&pdev->dev, "cannot find IRQ\n"); |
825 | ret = -ENOENT; | 819 | ret = -ENOENT; |
826 | goto out; | 820 | goto err_iomap; |
827 | } | 821 | } |
828 | 822 | ||
829 | ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, | 823 | ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, |
@@ -831,7 +825,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
831 | 825 | ||
832 | if (ret != 0) { | 826 | if (ret != 0) { |
833 | dev_err(&pdev->dev, "cannot claim IRQ\n"); | 827 | dev_err(&pdev->dev, "cannot claim IRQ\n"); |
834 | goto out; | 828 | goto err_iomap; |
835 | } | 829 | } |
836 | 830 | ||
837 | i2c->irq = res; | 831 | i2c->irq = res; |
@@ -841,17 +835,29 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
841 | ret = i2c_add_adapter(&i2c->adap); | 835 | ret = i2c_add_adapter(&i2c->adap); |
842 | if (ret < 0) { | 836 | if (ret < 0) { |
843 | dev_err(&pdev->dev, "failed to add bus to i2c core\n"); | 837 | dev_err(&pdev->dev, "failed to add bus to i2c core\n"); |
844 | goto out; | 838 | goto err_irq; |
845 | } | 839 | } |
846 | 840 | ||
847 | platform_set_drvdata(pdev, i2c); | 841 | platform_set_drvdata(pdev, i2c); |
848 | 842 | ||
849 | dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id); | 843 | dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id); |
844 | return 0; | ||
850 | 845 | ||
851 | out: | 846 | err_irq: |
852 | if (ret < 0) | 847 | free_irq(i2c->irq->start, i2c); |
853 | s3c24xx_i2c_free(i2c); | 848 | |
849 | err_iomap: | ||
850 | iounmap(i2c->regs); | ||
854 | 851 | ||
852 | err_ioarea: | ||
853 | release_resource(i2c->ioarea); | ||
854 | kfree(i2c->ioarea); | ||
855 | |||
856 | err_clk: | ||
857 | clk_disable(i2c->clk); | ||
858 | clk_put(i2c->clk); | ||
859 | |||
860 | err_noclk: | ||
855 | return ret; | 861 | return ret; |
856 | } | 862 | } |
857 | 863 | ||
@@ -863,11 +869,17 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
863 | static int s3c24xx_i2c_remove(struct platform_device *pdev) | 869 | static int s3c24xx_i2c_remove(struct platform_device *pdev) |
864 | { | 870 | { |
865 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); | 871 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); |
866 | 872 | ||
867 | if (i2c != NULL) { | 873 | i2c_del_adapter(&i2c->adap); |
868 | s3c24xx_i2c_free(i2c); | 874 | free_irq(i2c->irq->start, i2c); |
869 | platform_set_drvdata(pdev, NULL); | 875 | |
870 | } | 876 | clk_disable(i2c->clk); |
877 | clk_put(i2c->clk); | ||
878 | |||
879 | iounmap(i2c->regs); | ||
880 | |||
881 | release_resource(i2c->ioarea); | ||
882 | kfree(i2c->ioarea); | ||
871 | 883 | ||
872 | return 0; | 884 | return 0; |
873 | } | 885 | } |
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c new file mode 100644 index 000000000000..10af8d31e12a --- /dev/null +++ b/drivers/i2c/busses/i2c-simtec.c | |||
@@ -0,0 +1,186 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2005 Simtec Electronics | ||
3 | * Ben Dooks <ben@simtec.co.uk> | ||
4 | * | ||
5 | * Simtec Generic I2C Controller | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License | ||
10 | * | ||
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. | ||
15 | * | ||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | |||
27 | #include <linux/i2c.h> | ||
28 | #include <linux/i2c-algo-bit.h> | ||
29 | |||
30 | #include <asm/io.h> | ||
31 | |||
32 | struct simtec_i2c_data { | ||
33 | struct resource *ioarea; | ||
34 | void __iomem *reg; | ||
35 | struct i2c_adapter adap; | ||
36 | struct i2c_algo_bit_data bit; | ||
37 | }; | ||
38 | |||
39 | #define CMD_SET_SDA (1<<2) | ||
40 | #define CMD_SET_SCL (1<<3) | ||
41 | |||
42 | #define STATE_SDA (1<<0) | ||
43 | #define STATE_SCL (1<<1) | ||
44 | |||
45 | /* i2c bit-bus functions */ | ||
46 | |||
47 | static void simtec_i2c_setsda(void *pw, int state) | ||
48 | { | ||
49 | struct simtec_i2c_data *pd = pw; | ||
50 | writeb(CMD_SET_SDA | (state ? STATE_SDA : 0), pd->reg); | ||
51 | } | ||
52 | |||
53 | static void simtec_i2c_setscl(void *pw, int state) | ||
54 | { | ||
55 | struct simtec_i2c_data *pd = pw; | ||
56 | writeb(CMD_SET_SCL | (state ? STATE_SCL : 0), pd->reg); | ||
57 | } | ||
58 | |||
59 | static int simtec_i2c_getsda(void *pw) | ||
60 | { | ||
61 | struct simtec_i2c_data *pd = pw; | ||
62 | return readb(pd->reg) & STATE_SDA ? 1 : 0; | ||
63 | } | ||
64 | |||
65 | static int simtec_i2c_getscl(void *pw) | ||
66 | { | ||
67 | struct simtec_i2c_data *pd = pw; | ||
68 | return readb(pd->reg) & STATE_SCL ? 1 : 0; | ||
69 | } | ||
70 | |||
71 | /* device registration */ | ||
72 | |||
73 | static int simtec_i2c_probe(struct platform_device *dev) | ||
74 | { | ||
75 | struct simtec_i2c_data *pd; | ||
76 | struct resource *res; | ||
77 | int size; | ||
78 | int ret; | ||
79 | |||
80 | pd = kzalloc(sizeof(struct simtec_i2c_data), GFP_KERNEL); | ||
81 | if (pd == NULL) { | ||
82 | dev_err(&dev->dev, "cannot allocate private data\n"); | ||
83 | return -ENOMEM; | ||
84 | } | ||
85 | |||
86 | platform_set_drvdata(dev, pd); | ||
87 | |||
88 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
89 | if (res == NULL) { | ||
90 | dev_err(&dev->dev, "cannot find IO resource\n"); | ||
91 | ret = -ENOENT; | ||
92 | goto err; | ||
93 | } | ||
94 | |||
95 | size = (res->end-res->start)+1; | ||
96 | |||
97 | pd->ioarea = request_mem_region(res->start, size, dev->name); | ||
98 | if (pd->ioarea == NULL) { | ||
99 | dev_err(&dev->dev, "cannot request IO\n"); | ||
100 | ret = -ENXIO; | ||
101 | goto err; | ||
102 | } | ||
103 | |||
104 | pd->reg = ioremap(res->start, size); | ||
105 | if (pd->reg == NULL) { | ||
106 | dev_err(&dev->dev, "cannot map IO\n"); | ||
107 | ret = -ENXIO; | ||
108 | goto err_res; | ||
109 | } | ||
110 | |||
111 | /* setup the private data */ | ||
112 | |||
113 | pd->adap.owner = THIS_MODULE; | ||
114 | pd->adap.algo_data = &pd->bit; | ||
115 | pd->adap.dev.parent = &dev->dev; | ||
116 | |||
117 | strlcpy(pd->adap.name, "Simtec I2C", sizeof(pd->adap.name)); | ||
118 | |||
119 | pd->bit.data = pd; | ||
120 | pd->bit.setsda = simtec_i2c_setsda; | ||
121 | pd->bit.setscl = simtec_i2c_setscl; | ||
122 | pd->bit.getsda = simtec_i2c_getsda; | ||
123 | pd->bit.getscl = simtec_i2c_getscl; | ||
124 | pd->bit.timeout = HZ; | ||
125 | pd->bit.udelay = 20; | ||
126 | |||
127 | ret = i2c_bit_add_bus(&pd->adap); | ||
128 | if (ret) | ||
129 | goto err_all; | ||
130 | |||
131 | return 0; | ||
132 | |||
133 | err_all: | ||
134 | iounmap(pd->reg); | ||
135 | |||
136 | err_res: | ||
137 | release_resource(pd->ioarea); | ||
138 | kfree(pd->ioarea); | ||
139 | |||
140 | err: | ||
141 | kfree(pd); | ||
142 | return ret; | ||
143 | } | ||
144 | |||
145 | static int simtec_i2c_remove(struct platform_device *dev) | ||
146 | { | ||
147 | struct simtec_i2c_data *pd = platform_get_drvdata(dev); | ||
148 | |||
149 | i2c_del_adapter(&pd->adap); | ||
150 | |||
151 | iounmap(pd->reg); | ||
152 | release_resource(pd->ioarea); | ||
153 | kfree(pd->ioarea); | ||
154 | kfree(pd); | ||
155 | |||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | |||
160 | /* device driver */ | ||
161 | |||
162 | static struct platform_driver simtec_i2c_driver = { | ||
163 | .driver = { | ||
164 | .name = "simtec-i2c", | ||
165 | .owner = THIS_MODULE, | ||
166 | }, | ||
167 | .probe = simtec_i2c_probe, | ||
168 | .remove = simtec_i2c_remove, | ||
169 | }; | ||
170 | |||
171 | static int __init i2c_adap_simtec_init(void) | ||
172 | { | ||
173 | return platform_driver_register(&simtec_i2c_driver); | ||
174 | } | ||
175 | |||
176 | static void __exit i2c_adap_simtec_exit(void) | ||
177 | { | ||
178 | platform_driver_unregister(&simtec_i2c_driver); | ||
179 | } | ||
180 | |||
181 | module_init(i2c_adap_simtec_init); | ||
182 | module_exit(i2c_adap_simtec_exit); | ||
183 | |||
184 | MODULE_DESCRIPTION("Simtec Generic I2C Bus driver"); | ||
185 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); | ||
186 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c index 4157b0cd604c..dc235bb8e24d 100644 --- a/drivers/i2c/busses/i2c-sis96x.c +++ b/drivers/i2c/busses/i2c-sis96x.c | |||
@@ -300,7 +300,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev, | |||
300 | /* set up the sysfs linkage to our parent device */ | 300 | /* set up the sysfs linkage to our parent device */ |
301 | sis96x_adapter.dev.parent = &dev->dev; | 301 | sis96x_adapter.dev.parent = &dev->dev; |
302 | 302 | ||
303 | snprintf(sis96x_adapter.name, I2C_NAME_SIZE, | 303 | snprintf(sis96x_adapter.name, sizeof(sis96x_adapter.name), |
304 | "SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base); | 304 | "SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base); |
305 | 305 | ||
306 | if ((retval = i2c_add_adapter(&sis96x_adapter))) { | 306 | if ((retval = i2c_add_adapter(&sis96x_adapter))) { |
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c new file mode 100644 index 000000000000..907999049d50 --- /dev/null +++ b/drivers/i2c/busses/i2c-tiny-usb.c | |||
@@ -0,0 +1,277 @@ | |||
1 | /* | ||
2 | * driver for the i2c-tiny-usb adapter - 1.0 | ||
3 | * http://www.harbaum.org/till/i2c_tiny_usb | ||
4 | * | ||
5 | * Copyright (C) 2006-2007 Till Harbaum (Till@Harbaum.org) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License as | ||
9 | * published by the Free Software Foundation, version 2. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/errno.h> | ||
15 | #include <linux/module.h> | ||
16 | |||
17 | /* include interfaces to usb layer */ | ||
18 | #include <linux/usb.h> | ||
19 | |||
20 | /* include interface to i2c layer */ | ||
21 | #include <linux/i2c.h> | ||
22 | |||
23 | /* commands via USB, must match command ids in the firmware */ | ||
24 | #define CMD_ECHO 0 | ||
25 | #define CMD_GET_FUNC 1 | ||
26 | #define CMD_SET_DELAY 2 | ||
27 | #define CMD_GET_STATUS 3 | ||
28 | |||
29 | #define CMD_I2C_IO 4 | ||
30 | #define CMD_I2C_IO_BEGIN (1<<0) | ||
31 | #define CMD_I2C_IO_END (1<<1) | ||
32 | |||
33 | /* i2c bit delay, default is 10us -> 100kHz */ | ||
34 | static int delay = 10; | ||
35 | module_param(delay, int, 0); | ||
36 | MODULE_PARM_DESC(delay, "bit delay in microseconds, " | ||
37 | "e.g. 10 for 100kHz (default is 100kHz)"); | ||
38 | |||
39 | static int usb_read(struct i2c_adapter *adapter, int cmd, | ||
40 | int value, int index, void *data, int len); | ||
41 | |||
42 | static int usb_write(struct i2c_adapter *adapter, int cmd, | ||
43 | int value, int index, void *data, int len); | ||
44 | |||
45 | /* ----- begin of i2c layer ---------------------------------------------- */ | ||
46 | |||
47 | #define STATUS_IDLE 0 | ||
48 | #define STATUS_ADDRESS_ACK 1 | ||
49 | #define STATUS_ADDRESS_NAK 2 | ||
50 | |||
51 | static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num) | ||
52 | { | ||
53 | unsigned char status; | ||
54 | struct i2c_msg *pmsg; | ||
55 | int i; | ||
56 | |||
57 | dev_dbg(&adapter->dev, "master xfer %d messages:\n", num); | ||
58 | |||
59 | for (i = 0 ; i < num ; i++) { | ||
60 | int cmd = CMD_I2C_IO; | ||
61 | |||
62 | if (i == 0) | ||
63 | cmd |= CMD_I2C_IO_BEGIN; | ||
64 | |||
65 | if (i == num-1) | ||
66 | cmd |= CMD_I2C_IO_END; | ||
67 | |||
68 | pmsg = &msgs[i]; | ||
69 | |||
70 | dev_dbg(&adapter->dev, | ||
71 | " %d: %s (flags %d) %d bytes to 0x%02x\n", | ||
72 | i, pmsg->flags & I2C_M_RD ? "read" : "write", | ||
73 | pmsg->flags, pmsg->len, pmsg->addr); | ||
74 | |||
75 | /* and directly send the message */ | ||
76 | if (pmsg->flags & I2C_M_RD) { | ||
77 | /* read data */ | ||
78 | if (usb_read(adapter, cmd, | ||
79 | pmsg->flags, pmsg->addr, | ||
80 | pmsg->buf, pmsg->len) != pmsg->len) { | ||
81 | dev_err(&adapter->dev, | ||
82 | "failure reading data\n"); | ||
83 | return -EREMOTEIO; | ||
84 | } | ||
85 | } else { | ||
86 | /* write data */ | ||
87 | if (usb_write(adapter, cmd, | ||
88 | pmsg->flags, pmsg->addr, | ||
89 | pmsg->buf, pmsg->len) != pmsg->len) { | ||
90 | dev_err(&adapter->dev, | ||
91 | "failure writing data\n"); | ||
92 | return -EREMOTEIO; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | /* read status */ | ||
97 | if (usb_read(adapter, CMD_GET_STATUS, 0, 0, &status, 1) != 1) { | ||
98 | dev_err(&adapter->dev, "failure reading status\n"); | ||
99 | return -EREMOTEIO; | ||
100 | } | ||
101 | |||
102 | dev_dbg(&adapter->dev, " status = %d\n", status); | ||
103 | if (status == STATUS_ADDRESS_NAK) | ||
104 | return -EREMOTEIO; | ||
105 | } | ||
106 | |||
107 | return i; | ||
108 | } | ||
109 | |||
110 | static u32 usb_func(struct i2c_adapter *adapter) | ||
111 | { | ||
112 | u32 func; | ||
113 | |||
114 | /* get functionality from adapter */ | ||
115 | if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) != | ||
116 | sizeof(func)) { | ||
117 | dev_err(&adapter->dev, "failure reading functionality\n"); | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | return func; | ||
122 | } | ||
123 | |||
124 | /* This is the actual algorithm we define */ | ||
125 | static const struct i2c_algorithm usb_algorithm = { | ||
126 | .master_xfer = usb_xfer, | ||
127 | .functionality = usb_func, | ||
128 | }; | ||
129 | |||
130 | /* ----- end of i2c layer ------------------------------------------------ */ | ||
131 | |||
132 | /* ----- begin of usb layer ---------------------------------------------- */ | ||
133 | |||
134 | /* The usb i2c interface uses a vid/pid pair donated by */ | ||
135 | /* Future Technology Devices International Ltd. */ | ||
136 | static struct usb_device_id i2c_tiny_usb_table [] = { | ||
137 | { USB_DEVICE(0x0403, 0xc631) }, | ||
138 | { } /* Terminating entry */ | ||
139 | }; | ||
140 | |||
141 | MODULE_DEVICE_TABLE(usb, i2c_tiny_usb_table); | ||
142 | |||
143 | /* Structure to hold all of our device specific stuff */ | ||
144 | struct i2c_tiny_usb { | ||
145 | struct usb_device *usb_dev; /* the usb device for this device */ | ||
146 | struct usb_interface *interface; /* the interface for this device */ | ||
147 | struct i2c_adapter adapter; /* i2c related things */ | ||
148 | }; | ||
149 | |||
150 | static int usb_read(struct i2c_adapter *adapter, int cmd, | ||
151 | int value, int index, void *data, int len) | ||
152 | { | ||
153 | struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data; | ||
154 | |||
155 | /* do control transfer */ | ||
156 | return usb_control_msg(dev->usb_dev, usb_rcvctrlpipe(dev->usb_dev, 0), | ||
157 | cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | | ||
158 | USB_DIR_IN, value, index, data, len, 2000); | ||
159 | } | ||
160 | |||
161 | static int usb_write(struct i2c_adapter *adapter, int cmd, | ||
162 | int value, int index, void *data, int len) | ||
163 | { | ||
164 | struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data; | ||
165 | |||
166 | /* do control transfer */ | ||
167 | return usb_control_msg(dev->usb_dev, usb_sndctrlpipe(dev->usb_dev, 0), | ||
168 | cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE, | ||
169 | value, index, data, len, 2000); | ||
170 | } | ||
171 | |||
172 | static void i2c_tiny_usb_free(struct i2c_tiny_usb *dev) | ||
173 | { | ||
174 | usb_put_dev(dev->usb_dev); | ||
175 | kfree(dev); | ||
176 | } | ||
177 | |||
178 | static int i2c_tiny_usb_probe(struct usb_interface *interface, | ||
179 | const struct usb_device_id *id) | ||
180 | { | ||
181 | struct i2c_tiny_usb *dev; | ||
182 | int retval = -ENOMEM; | ||
183 | u16 version; | ||
184 | |||
185 | dev_dbg(&interface->dev, "probing usb device\n"); | ||
186 | |||
187 | /* allocate memory for our device state and initialize it */ | ||
188 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
189 | if (dev == NULL) { | ||
190 | dev_err(&interface->dev, "Out of memory\n"); | ||
191 | goto error; | ||
192 | } | ||
193 | |||
194 | dev->usb_dev = usb_get_dev(interface_to_usbdev(interface)); | ||
195 | dev->interface = interface; | ||
196 | |||
197 | /* save our data pointer in this interface device */ | ||
198 | usb_set_intfdata(interface, dev); | ||
199 | |||
200 | version = le16_to_cpu(dev->usb_dev->descriptor.bcdDevice); | ||
201 | dev_info(&interface->dev, | ||
202 | "version %x.%02x found at bus %03d address %03d\n", | ||
203 | version >> 8, version & 0xff, | ||
204 | dev->usb_dev->bus->busnum, dev->usb_dev->devnum); | ||
205 | |||
206 | /* setup i2c adapter description */ | ||
207 | dev->adapter.owner = THIS_MODULE; | ||
208 | dev->adapter.class = I2C_CLASS_HWMON; | ||
209 | dev->adapter.algo = &usb_algorithm; | ||
210 | dev->adapter.algo_data = dev; | ||
211 | snprintf(dev->adapter.name, I2C_NAME_SIZE, | ||
212 | "i2c-tiny-usb at bus %03d device %03d", | ||
213 | dev->usb_dev->bus->busnum, dev->usb_dev->devnum); | ||
214 | |||
215 | if (usb_write(&dev->adapter, CMD_SET_DELAY, | ||
216 | cpu_to_le16(delay), 0, NULL, 0) != 0) { | ||
217 | dev_err(&dev->adapter.dev, | ||
218 | "failure setting delay to %dus\n", delay); | ||
219 | retval = -EIO; | ||
220 | goto error; | ||
221 | } | ||
222 | |||
223 | dev->adapter.dev.parent = &dev->interface->dev; | ||
224 | |||
225 | /* and finally attach to i2c layer */ | ||
226 | i2c_add_adapter(&dev->adapter); | ||
227 | |||
228 | /* inform user about successful attachment to i2c layer */ | ||
229 | dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n"); | ||
230 | |||
231 | return 0; | ||
232 | |||
233 | error: | ||
234 | if (dev) | ||
235 | i2c_tiny_usb_free(dev); | ||
236 | |||
237 | return retval; | ||
238 | } | ||
239 | |||
240 | static void i2c_tiny_usb_disconnect(struct usb_interface *interface) | ||
241 | { | ||
242 | struct i2c_tiny_usb *dev = usb_get_intfdata(interface); | ||
243 | |||
244 | i2c_del_adapter(&dev->adapter); | ||
245 | usb_set_intfdata(interface, NULL); | ||
246 | i2c_tiny_usb_free(dev); | ||
247 | |||
248 | dev_dbg(&interface->dev, "disconnected\n"); | ||
249 | } | ||
250 | |||
251 | static struct usb_driver i2c_tiny_usb_driver = { | ||
252 | .name = "i2c-tiny-usb", | ||
253 | .probe = i2c_tiny_usb_probe, | ||
254 | .disconnect = i2c_tiny_usb_disconnect, | ||
255 | .id_table = i2c_tiny_usb_table, | ||
256 | }; | ||
257 | |||
258 | static int __init usb_i2c_tiny_usb_init(void) | ||
259 | { | ||
260 | /* register this driver with the USB subsystem */ | ||
261 | return usb_register(&i2c_tiny_usb_driver); | ||
262 | } | ||
263 | |||
264 | static void __exit usb_i2c_tiny_usb_exit(void) | ||
265 | { | ||
266 | /* deregister this driver with the USB subsystem */ | ||
267 | usb_deregister(&i2c_tiny_usb_driver); | ||
268 | } | ||
269 | |||
270 | module_init(usb_i2c_tiny_usb_init); | ||
271 | module_exit(usb_i2c_tiny_usb_exit); | ||
272 | |||
273 | /* ----- end of usb layer ------------------------------------------------ */ | ||
274 | |||
275 | MODULE_AUTHOR("Till Harbaum <Till@Harbaum.org>"); | ||
276 | MODULE_DESCRIPTION("i2c-tiny-usb driver v1.0"); | ||
277 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c index 03c5fc868548..7a2bc06304fc 100644 --- a/drivers/i2c/busses/i2c-viapro.c +++ b/drivers/i2c/busses/i2c-viapro.c | |||
@@ -404,7 +404,7 @@ found: | |||
404 | } | 404 | } |
405 | 405 | ||
406 | vt596_adapter.dev.parent = &pdev->dev; | 406 | vt596_adapter.dev.parent = &pdev->dev; |
407 | snprintf(vt596_adapter.name, I2C_NAME_SIZE, | 407 | snprintf(vt596_adapter.name, sizeof(vt596_adapter.name), |
408 | "SMBus Via Pro adapter at %04x", vt596_smba); | 408 | "SMBus Via Pro adapter at %04x", vt596_smba); |
409 | 409 | ||
410 | vt596_pdev = pci_dev_get(pdev); | 410 | vt596_pdev = pci_dev_get(pdev); |
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c index 0b082c5a0195..0d6bd4f7b7fa 100644 --- a/drivers/i2c/busses/scx200_acb.c +++ b/drivers/i2c/busses/scx200_acb.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
30 | #include <linux/i2c.h> | 30 | #include <linux/i2c.h> |
31 | #include <linux/smp_lock.h> | ||
32 | #include <linux/pci.h> | 31 | #include <linux/pci.h> |
33 | #include <linux/delay.h> | 32 | #include <linux/delay.h> |
34 | #include <linux/mutex.h> | 33 | #include <linux/mutex.h> |
@@ -441,7 +440,7 @@ static __init struct scx200_acb_iface *scx200_create_iface(const char *text, | |||
441 | 440 | ||
442 | adapter = &iface->adapter; | 441 | adapter = &iface->adapter; |
443 | i2c_set_adapdata(adapter, iface); | 442 | i2c_set_adapdata(adapter, iface); |
444 | snprintf(adapter->name, I2C_NAME_SIZE, "%s ACB%d", text, index); | 443 | snprintf(adapter->name, sizeof(adapter->name), "%s ACB%d", text, index); |
445 | adapter->owner = THIS_MODULE; | 444 | adapter->owner = THIS_MODULE; |
446 | adapter->id = I2C_HW_SMBUS_SCX200; | 445 | adapter->id = I2C_HW_SMBUS_SCX200; |
447 | adapter->algo = &scx200_acb_algorithm; | 446 | adapter->algo = &scx200_acb_algorithm; |
@@ -599,6 +598,7 @@ static __init int scx200_scan_pci(void) | |||
599 | else { | 598 | else { |
600 | int i; | 599 | int i; |
601 | 600 | ||
601 | pci_dev_put(pdev); | ||
602 | for (i = 0; i < MAX_DEVICES; ++i) { | 602 | for (i = 0; i < MAX_DEVICES; ++i) { |
603 | if (base[i] == 0) | 603 | if (base[i] == 0) |
604 | continue; | 604 | continue; |
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig index 87ee3ce58618..ea085a006ead 100644 --- a/drivers/i2c/chips/Kconfig +++ b/drivers/i2c/chips/Kconfig | |||
@@ -3,11 +3,10 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | menu "Miscellaneous I2C Chip support" | 5 | menu "Miscellaneous I2C Chip support" |
6 | depends on I2C | ||
7 | 6 | ||
8 | config SENSORS_DS1337 | 7 | config SENSORS_DS1337 |
9 | tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock" | 8 | tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock" |
10 | depends on I2C && EXPERIMENTAL | 9 | depends on EXPERIMENTAL |
11 | help | 10 | help |
12 | If you say yes here you get support for Dallas Semiconductor | 11 | If you say yes here you get support for Dallas Semiconductor |
13 | DS1337 and DS1339 real-time clock chips. | 12 | DS1337 and DS1339 real-time clock chips. |
@@ -17,7 +16,7 @@ config SENSORS_DS1337 | |||
17 | 16 | ||
18 | config SENSORS_DS1374 | 17 | config SENSORS_DS1374 |
19 | tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock" | 18 | tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock" |
20 | depends on I2C && EXPERIMENTAL | 19 | depends on EXPERIMENTAL |
21 | help | 20 | help |
22 | If you say yes here you get support for Dallas Semiconductor | 21 | If you say yes here you get support for Dallas Semiconductor |
23 | DS1374 real-time clock chips. | 22 | DS1374 real-time clock chips. |
@@ -27,7 +26,7 @@ config SENSORS_DS1374 | |||
27 | 26 | ||
28 | config SENSORS_EEPROM | 27 | config SENSORS_EEPROM |
29 | tristate "EEPROM reader" | 28 | tristate "EEPROM reader" |
30 | depends on I2C && EXPERIMENTAL | 29 | depends on EXPERIMENTAL |
31 | help | 30 | help |
32 | If you say yes here you get read-only access to the EEPROM data | 31 | If you say yes here you get read-only access to the EEPROM data |
33 | available on modern memory DIMMs and Sony Vaio laptops. Such | 32 | available on modern memory DIMMs and Sony Vaio laptops. Such |
@@ -38,7 +37,7 @@ config SENSORS_EEPROM | |||
38 | 37 | ||
39 | config SENSORS_PCF8574 | 38 | config SENSORS_PCF8574 |
40 | tristate "Philips PCF8574 and PCF8574A" | 39 | tristate "Philips PCF8574 and PCF8574A" |
41 | depends on I2C && EXPERIMENTAL | 40 | depends on EXPERIMENTAL |
42 | default n | 41 | default n |
43 | help | 42 | help |
44 | If you say yes here you get support for Philips PCF8574 and | 43 | If you say yes here you get support for Philips PCF8574 and |
@@ -52,7 +51,7 @@ config SENSORS_PCF8574 | |||
52 | 51 | ||
53 | config SENSORS_PCA9539 | 52 | config SENSORS_PCA9539 |
54 | tristate "Philips PCA9539 16-bit I/O port" | 53 | tristate "Philips PCA9539 16-bit I/O port" |
55 | depends on I2C && EXPERIMENTAL | 54 | depends on EXPERIMENTAL |
56 | help | 55 | help |
57 | If you say yes here you get support for the Philips PCA9539 | 56 | If you say yes here you get support for the Philips PCA9539 |
58 | 16-bit I/O port. | 57 | 16-bit I/O port. |
@@ -62,7 +61,7 @@ config SENSORS_PCA9539 | |||
62 | 61 | ||
63 | config SENSORS_PCF8591 | 62 | config SENSORS_PCF8591 |
64 | tristate "Philips PCF8591" | 63 | tristate "Philips PCF8591" |
65 | depends on I2C && EXPERIMENTAL | 64 | depends on EXPERIMENTAL |
66 | default n | 65 | default n |
67 | help | 66 | help |
68 | If you say yes here you get support for Philips PCF8591 chips. | 67 | If you say yes here you get support for Philips PCF8591 chips. |
@@ -75,7 +74,7 @@ config SENSORS_PCF8591 | |||
75 | 74 | ||
76 | config ISP1301_OMAP | 75 | config ISP1301_OMAP |
77 | tristate "Philips ISP1301 with OMAP OTG" | 76 | tristate "Philips ISP1301 with OMAP OTG" |
78 | depends on I2C && ARCH_OMAP_OTG | 77 | depends on ARCH_OMAP_OTG |
79 | help | 78 | help |
80 | If you say yes here you get support for the Philips ISP1301 | 79 | If you say yes here you get support for the Philips ISP1301 |
81 | USB-On-The-Go transceiver working with the OMAP OTG controller. | 80 | USB-On-The-Go transceiver working with the OMAP OTG controller. |
@@ -90,7 +89,7 @@ config ISP1301_OMAP | |||
90 | # and having mostly OMAP-specific board support | 89 | # and having mostly OMAP-specific board support |
91 | config TPS65010 | 90 | config TPS65010 |
92 | tristate "TPS6501x Power Management chips" | 91 | tristate "TPS6501x Power Management chips" |
93 | depends on I2C && ARCH_OMAP | 92 | depends on ARCH_OMAP |
94 | default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK | 93 | default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK |
95 | help | 94 | help |
96 | If you say yes here you get support for the TPS6501x series of | 95 | If you say yes here you get support for the TPS6501x series of |
@@ -103,7 +102,7 @@ config TPS65010 | |||
103 | 102 | ||
104 | config SENSORS_M41T00 | 103 | config SENSORS_M41T00 |
105 | tristate "ST M41T00 RTC chip" | 104 | tristate "ST M41T00 RTC chip" |
106 | depends on I2C && PPC32 | 105 | depends on PPC32 |
107 | help | 106 | help |
108 | If you say yes here you get support for the ST M41T00 RTC chip. | 107 | If you say yes here you get support for the ST M41T00 RTC chip. |
109 | 108 | ||
@@ -112,7 +111,7 @@ config SENSORS_M41T00 | |||
112 | 111 | ||
113 | config SENSORS_MAX6875 | 112 | config SENSORS_MAX6875 |
114 | tristate "Maxim MAX6875 Power supply supervisor" | 113 | tristate "Maxim MAX6875 Power supply supervisor" |
115 | depends on I2C && EXPERIMENTAL | 114 | depends on EXPERIMENTAL |
116 | help | 115 | help |
117 | If you say yes here you get support for the Maxim MAX6875 | 116 | If you say yes here you get support for the Maxim MAX6875 |
118 | EEPROM-programmable, quad power-supply sequencer/supervisor. | 117 | EEPROM-programmable, quad power-supply sequencer/supervisor. |
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c index 214fbb1423c5..3c3f2ebf3fc9 100644 --- a/drivers/i2c/chips/tps65010.c +++ b/drivers/i2c/chips/tps65010.c | |||
@@ -351,8 +351,10 @@ static void tps65010_interrupt(struct tps65010 *tps) | |||
351 | #if 0 | 351 | #if 0 |
352 | /* REVISIT: this might need its own workqueue | 352 | /* REVISIT: this might need its own workqueue |
353 | * plus tweaks including deadlock avoidance ... | 353 | * plus tweaks including deadlock avoidance ... |
354 | * also needs to get error handling and probably | ||
355 | * an #ifdef CONFIG_SOFTWARE_SUSPEND | ||
354 | */ | 356 | */ |
355 | software_suspend(); | 357 | hibernate(); |
356 | #endif | 358 | #endif |
357 | poll = 1; | 359 | poll = 1; |
358 | } | 360 | } |
diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c new file mode 100644 index 000000000000..ffb35f09df03 --- /dev/null +++ b/drivers/i2c/i2c-boardinfo.c | |||
@@ -0,0 +1,90 @@ | |||
1 | /* | ||
2 | * i2c-boardinfo.h - collect pre-declarations of I2C devices | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/i2c.h> | ||
21 | |||
22 | #include "i2c-core.h" | ||
23 | |||
24 | |||
25 | /* These symbols are exported ONLY FOR the i2c core. | ||
26 | * No other users will be supported. | ||
27 | */ | ||
28 | DEFINE_MUTEX(__i2c_board_lock); | ||
29 | EXPORT_SYMBOL_GPL(__i2c_board_lock); | ||
30 | |||
31 | LIST_HEAD(__i2c_board_list); | ||
32 | EXPORT_SYMBOL_GPL(__i2c_board_list); | ||
33 | |||
34 | int __i2c_first_dynamic_bus_num; | ||
35 | EXPORT_SYMBOL_GPL(__i2c_first_dynamic_bus_num); | ||
36 | |||
37 | |||
38 | /** | ||
39 | * i2c_register_board_info - statically declare I2C devices | ||
40 | * @busnum: identifies the bus to which these devices belong | ||
41 | * @info: vector of i2c device descriptors | ||
42 | * @len: how many descriptors in the vector; may be zero to reserve | ||
43 | * the specified bus number. | ||
44 | * | ||
45 | * Systems using the Linux I2C driver stack can declare tables of board info | ||
46 | * while they initialize. This should be done in board-specific init code | ||
47 | * near arch_initcall() time, or equivalent, before any I2C adapter driver is | ||
48 | * registered. For example, mainboard init code could define several devices, | ||
49 | * as could the init code for each daughtercard in a board stack. | ||
50 | * | ||
51 | * The I2C devices will be created later, after the adapter for the relevant | ||
52 | * bus has been registered. After that moment, standard driver model tools | ||
53 | * are used to bind "new style" I2C drivers to the devices. The bus number | ||
54 | * for any device declared using this routine is not available for dynamic | ||
55 | * allocation. | ||
56 | * | ||
57 | * The board info passed can safely be __initdata, but be careful of embedded | ||
58 | * pointers (for platform_data, functions, etc) since that won't be copied. | ||
59 | */ | ||
60 | int __init | ||
61 | i2c_register_board_info(int busnum, | ||
62 | struct i2c_board_info const *info, unsigned len) | ||
63 | { | ||
64 | int status; | ||
65 | |||
66 | mutex_lock(&__i2c_board_lock); | ||
67 | |||
68 | /* dynamic bus numbers will be assigned after the last static one */ | ||
69 | if (busnum >= __i2c_first_dynamic_bus_num) | ||
70 | __i2c_first_dynamic_bus_num = busnum + 1; | ||
71 | |||
72 | for (status = 0; len; len--, info++) { | ||
73 | struct i2c_devinfo *devinfo; | ||
74 | |||
75 | devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL); | ||
76 | if (!devinfo) { | ||
77 | pr_debug("i2c-core: can't register boardinfo!\n"); | ||
78 | status = -ENOMEM; | ||
79 | break; | ||
80 | } | ||
81 | |||
82 | devinfo->busnum = busnum; | ||
83 | devinfo->board_info = *info; | ||
84 | list_add_tail(&devinfo->list, &__i2c_board_list); | ||
85 | } | ||
86 | |||
87 | mutex_unlock(&__i2c_board_lock); | ||
88 | |||
89 | return status; | ||
90 | } | ||
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 21fe1406c8b4..64f8e56d300e 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -35,29 +35,92 @@ | |||
35 | #include <linux/completion.h> | 35 | #include <linux/completion.h> |
36 | #include <asm/uaccess.h> | 36 | #include <asm/uaccess.h> |
37 | 37 | ||
38 | #include "i2c-core.h" | ||
39 | |||
38 | 40 | ||
39 | static LIST_HEAD(adapters); | 41 | static LIST_HEAD(adapters); |
40 | static LIST_HEAD(drivers); | 42 | static LIST_HEAD(drivers); |
41 | static DEFINE_MUTEX(core_lists); | 43 | static DEFINE_MUTEX(core_lists); |
42 | static DEFINE_IDR(i2c_adapter_idr); | 44 | static DEFINE_IDR(i2c_adapter_idr); |
43 | 45 | ||
46 | #define is_newstyle_driver(d) ((d)->probe || (d)->remove) | ||
44 | 47 | ||
45 | /* ------------------------------------------------------------------------- */ | 48 | /* ------------------------------------------------------------------------- */ |
46 | 49 | ||
47 | /* match always succeeds, as we want the probe() to tell if we really accept this match */ | ||
48 | static int i2c_device_match(struct device *dev, struct device_driver *drv) | 50 | static int i2c_device_match(struct device *dev, struct device_driver *drv) |
49 | { | 51 | { |
50 | return 1; | 52 | struct i2c_client *client = to_i2c_client(dev); |
53 | struct i2c_driver *driver = to_i2c_driver(drv); | ||
54 | |||
55 | /* make legacy i2c drivers bypass driver model probing entirely; | ||
56 | * such drivers scan each i2c adapter/bus themselves. | ||
57 | */ | ||
58 | if (!is_newstyle_driver(driver)) | ||
59 | return 0; | ||
60 | |||
61 | /* new style drivers use the same kind of driver matching policy | ||
62 | * as platform devices or SPI: compare device and driver IDs. | ||
63 | */ | ||
64 | return strcmp(client->driver_name, drv->name) == 0; | ||
65 | } | ||
66 | |||
67 | #ifdef CONFIG_HOTPLUG | ||
68 | |||
69 | /* uevent helps with hotplug: modprobe -q $(MODALIAS) */ | ||
70 | static int i2c_device_uevent(struct device *dev, char **envp, int num_envp, | ||
71 | char *buffer, int buffer_size) | ||
72 | { | ||
73 | struct i2c_client *client = to_i2c_client(dev); | ||
74 | int i = 0, length = 0; | ||
75 | |||
76 | /* by definition, legacy drivers can't hotplug */ | ||
77 | if (dev->driver || !client->driver_name) | ||
78 | return 0; | ||
79 | |||
80 | if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length, | ||
81 | "MODALIAS=%s", client->driver_name)) | ||
82 | return -ENOMEM; | ||
83 | envp[i] = NULL; | ||
84 | dev_dbg(dev, "uevent\n"); | ||
85 | return 0; | ||
51 | } | 86 | } |
52 | 87 | ||
88 | #else | ||
89 | #define i2c_device_uevent NULL | ||
90 | #endif /* CONFIG_HOTPLUG */ | ||
91 | |||
53 | static int i2c_device_probe(struct device *dev) | 92 | static int i2c_device_probe(struct device *dev) |
54 | { | 93 | { |
55 | return -ENODEV; | 94 | struct i2c_client *client = to_i2c_client(dev); |
95 | struct i2c_driver *driver = to_i2c_driver(dev->driver); | ||
96 | |||
97 | if (!driver->probe) | ||
98 | return -ENODEV; | ||
99 | client->driver = driver; | ||
100 | dev_dbg(dev, "probe\n"); | ||
101 | return driver->probe(client); | ||
56 | } | 102 | } |
57 | 103 | ||
58 | static int i2c_device_remove(struct device *dev) | 104 | static int i2c_device_remove(struct device *dev) |
59 | { | 105 | { |
60 | return 0; | 106 | struct i2c_client *client = to_i2c_client(dev); |
107 | struct i2c_driver *driver; | ||
108 | int status; | ||
109 | |||
110 | if (!dev->driver) | ||
111 | return 0; | ||
112 | |||
113 | driver = to_i2c_driver(dev->driver); | ||
114 | if (driver->remove) { | ||
115 | dev_dbg(dev, "remove\n"); | ||
116 | status = driver->remove(client); | ||
117 | } else { | ||
118 | dev->driver = NULL; | ||
119 | status = 0; | ||
120 | } | ||
121 | if (status == 0) | ||
122 | client->driver = NULL; | ||
123 | return status; | ||
61 | } | 124 | } |
62 | 125 | ||
63 | static void i2c_device_shutdown(struct device *dev) | 126 | static void i2c_device_shutdown(struct device *dev) |
@@ -95,122 +158,184 @@ static int i2c_device_resume(struct device * dev) | |||
95 | return driver->resume(to_i2c_client(dev)); | 158 | return driver->resume(to_i2c_client(dev)); |
96 | } | 159 | } |
97 | 160 | ||
161 | static void i2c_client_release(struct device *dev) | ||
162 | { | ||
163 | struct i2c_client *client = to_i2c_client(dev); | ||
164 | complete(&client->released); | ||
165 | } | ||
166 | |||
167 | static void i2c_client_dev_release(struct device *dev) | ||
168 | { | ||
169 | kfree(to_i2c_client(dev)); | ||
170 | } | ||
171 | |||
172 | static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf) | ||
173 | { | ||
174 | struct i2c_client *client = to_i2c_client(dev); | ||
175 | return sprintf(buf, "%s\n", client->name); | ||
176 | } | ||
177 | |||
178 | static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf) | ||
179 | { | ||
180 | struct i2c_client *client = to_i2c_client(dev); | ||
181 | return client->driver_name | ||
182 | ? sprintf(buf, "%s\n", client->driver_name) | ||
183 | : 0; | ||
184 | } | ||
185 | |||
186 | static struct device_attribute i2c_dev_attrs[] = { | ||
187 | __ATTR(name, S_IRUGO, show_client_name, NULL), | ||
188 | /* modalias helps coldplug: modprobe $(cat .../modalias) */ | ||
189 | __ATTR(modalias, S_IRUGO, show_modalias, NULL), | ||
190 | { }, | ||
191 | }; | ||
192 | |||
98 | struct bus_type i2c_bus_type = { | 193 | struct bus_type i2c_bus_type = { |
99 | .name = "i2c", | 194 | .name = "i2c", |
195 | .dev_attrs = i2c_dev_attrs, | ||
100 | .match = i2c_device_match, | 196 | .match = i2c_device_match, |
197 | .uevent = i2c_device_uevent, | ||
101 | .probe = i2c_device_probe, | 198 | .probe = i2c_device_probe, |
102 | .remove = i2c_device_remove, | 199 | .remove = i2c_device_remove, |
103 | .shutdown = i2c_device_shutdown, | 200 | .shutdown = i2c_device_shutdown, |
104 | .suspend = i2c_device_suspend, | 201 | .suspend = i2c_device_suspend, |
105 | .resume = i2c_device_resume, | 202 | .resume = i2c_device_resume, |
106 | }; | 203 | }; |
204 | EXPORT_SYMBOL_GPL(i2c_bus_type); | ||
107 | 205 | ||
108 | /* ------------------------------------------------------------------------- */ | 206 | /** |
207 | * i2c_new_device - instantiate an i2c device for use with a new style driver | ||
208 | * @adap: the adapter managing the device | ||
209 | * @info: describes one I2C device; bus_num is ignored | ||
210 | * | ||
211 | * Create a device to work with a new style i2c driver, where binding is | ||
212 | * handled through driver model probe()/remove() methods. This call is not | ||
213 | * appropriate for use by mainboad initialization logic, which usually runs | ||
214 | * during an arch_initcall() long before any i2c_adapter could exist. | ||
215 | * | ||
216 | * This returns the new i2c client, which may be saved for later use with | ||
217 | * i2c_unregister_device(); or NULL to indicate an error. | ||
218 | */ | ||
219 | struct i2c_client * | ||
220 | i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) | ||
221 | { | ||
222 | struct i2c_client *client; | ||
223 | int status; | ||
109 | 224 | ||
110 | void i2c_adapter_dev_release(struct device *dev) | 225 | client = kzalloc(sizeof *client, GFP_KERNEL); |
226 | if (!client) | ||
227 | return NULL; | ||
228 | |||
229 | client->adapter = adap; | ||
230 | |||
231 | client->dev.platform_data = info->platform_data; | ||
232 | client->flags = info->flags; | ||
233 | client->addr = info->addr; | ||
234 | client->irq = info->irq; | ||
235 | |||
236 | strlcpy(client->driver_name, info->driver_name, | ||
237 | sizeof(client->driver_name)); | ||
238 | strlcpy(client->name, info->type, sizeof(client->name)); | ||
239 | |||
240 | /* a new style driver may be bound to this device when we | ||
241 | * return from this function, or any later moment (e.g. maybe | ||
242 | * hotplugging will load the driver module). and the device | ||
243 | * refcount model is the standard driver model one. | ||
244 | */ | ||
245 | status = i2c_attach_client(client); | ||
246 | if (status < 0) { | ||
247 | kfree(client); | ||
248 | client = NULL; | ||
249 | } | ||
250 | return client; | ||
251 | } | ||
252 | EXPORT_SYMBOL_GPL(i2c_new_device); | ||
253 | |||
254 | |||
255 | /** | ||
256 | * i2c_unregister_device - reverse effect of i2c_new_device() | ||
257 | * @client: value returned from i2c_new_device() | ||
258 | */ | ||
259 | void i2c_unregister_device(struct i2c_client *client) | ||
111 | { | 260 | { |
112 | struct i2c_adapter *adap = dev_to_i2c_adapter(dev); | 261 | struct i2c_adapter *adapter = client->adapter; |
113 | complete(&adap->dev_released); | 262 | struct i2c_driver *driver = client->driver; |
263 | |||
264 | if (driver && !is_newstyle_driver(driver)) { | ||
265 | dev_err(&client->dev, "can't unregister devices " | ||
266 | "with legacy drivers\n"); | ||
267 | WARN_ON(1); | ||
268 | return; | ||
269 | } | ||
270 | |||
271 | mutex_lock(&adapter->clist_lock); | ||
272 | list_del(&client->list); | ||
273 | mutex_unlock(&adapter->clist_lock); | ||
274 | |||
275 | device_unregister(&client->dev); | ||
114 | } | 276 | } |
277 | EXPORT_SYMBOL_GPL(i2c_unregister_device); | ||
115 | 278 | ||
116 | struct device_driver i2c_adapter_driver = { | ||
117 | .owner = THIS_MODULE, | ||
118 | .name = "i2c_adapter", | ||
119 | .bus = &i2c_bus_type, | ||
120 | }; | ||
121 | 279 | ||
122 | /* ------------------------------------------------------------------------- */ | 280 | /* ------------------------------------------------------------------------- */ |
123 | 281 | ||
124 | /* I2C bus adapters -- one roots each I2C or SMBUS segment */ | 282 | /* I2C bus adapters -- one roots each I2C or SMBUS segment */ |
125 | 283 | ||
126 | static void i2c_adapter_class_dev_release(struct class_device *dev) | 284 | void i2c_adapter_dev_release(struct device *dev) |
127 | { | 285 | { |
128 | struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev); | 286 | struct i2c_adapter *adap = to_i2c_adapter(dev); |
129 | complete(&adap->class_dev_released); | 287 | complete(&adap->dev_released); |
130 | } | 288 | } |
289 | EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); /* exported to i2c-isa */ | ||
131 | 290 | ||
132 | static ssize_t i2c_adapter_show_name(struct class_device *cdev, char *buf) | 291 | static ssize_t |
292 | show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) | ||
133 | { | 293 | { |
134 | struct i2c_adapter *adap = class_dev_to_i2c_adapter(cdev); | 294 | struct i2c_adapter *adap = to_i2c_adapter(dev); |
135 | return sprintf(buf, "%s\n", adap->name); | 295 | return sprintf(buf, "%s\n", adap->name); |
136 | } | 296 | } |
137 | 297 | ||
138 | static struct class_device_attribute i2c_adapter_attrs[] = { | 298 | static struct device_attribute i2c_adapter_attrs[] = { |
139 | __ATTR(name, S_IRUGO, i2c_adapter_show_name, NULL), | 299 | __ATTR(name, S_IRUGO, show_adapter_name, NULL), |
140 | { }, | 300 | { }, |
141 | }; | 301 | }; |
142 | 302 | ||
143 | struct class i2c_adapter_class = { | 303 | struct class i2c_adapter_class = { |
144 | .owner = THIS_MODULE, | 304 | .owner = THIS_MODULE, |
145 | .name = "i2c-adapter", | 305 | .name = "i2c-adapter", |
146 | .class_dev_attrs = i2c_adapter_attrs, | 306 | .dev_attrs = i2c_adapter_attrs, |
147 | .release = &i2c_adapter_class_dev_release, | ||
148 | }; | 307 | }; |
308 | EXPORT_SYMBOL_GPL(i2c_adapter_class); /* exported to i2c-isa */ | ||
149 | 309 | ||
150 | static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) | 310 | static void i2c_scan_static_board_info(struct i2c_adapter *adapter) |
151 | { | ||
152 | struct i2c_adapter *adap = dev_to_i2c_adapter(dev); | ||
153 | return sprintf(buf, "%s\n", adap->name); | ||
154 | } | ||
155 | static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); | ||
156 | |||
157 | |||
158 | static void i2c_client_release(struct device *dev) | ||
159 | { | ||
160 | struct i2c_client *client = to_i2c_client(dev); | ||
161 | complete(&client->released); | ||
162 | } | ||
163 | |||
164 | static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf) | ||
165 | { | 311 | { |
166 | struct i2c_client *client = to_i2c_client(dev); | 312 | struct i2c_devinfo *devinfo; |
167 | return sprintf(buf, "%s\n", client->name); | 313 | |
314 | mutex_lock(&__i2c_board_lock); | ||
315 | list_for_each_entry(devinfo, &__i2c_board_list, list) { | ||
316 | if (devinfo->busnum == adapter->nr | ||
317 | && !i2c_new_device(adapter, | ||
318 | &devinfo->board_info)) | ||
319 | printk(KERN_ERR "i2c-core: can't create i2c%d-%04x\n", | ||
320 | i2c_adapter_id(adapter), | ||
321 | devinfo->board_info.addr); | ||
322 | } | ||
323 | mutex_unlock(&__i2c_board_lock); | ||
168 | } | 324 | } |
169 | 325 | ||
170 | /* | 326 | static int i2c_register_adapter(struct i2c_adapter *adap) |
171 | * We can't use the DEVICE_ATTR() macro here, as we used the same name for | ||
172 | * an i2c adapter attribute (above). | ||
173 | */ | ||
174 | static struct device_attribute dev_attr_client_name = | ||
175 | __ATTR(name, S_IRUGO, &show_client_name, NULL); | ||
176 | |||
177 | |||
178 | /* --------------------------------------------------- | ||
179 | * registering functions | ||
180 | * --------------------------------------------------- | ||
181 | */ | ||
182 | |||
183 | /* ----- | ||
184 | * i2c_add_adapter is called from within the algorithm layer, | ||
185 | * when a new hw adapter registers. A new device is register to be | ||
186 | * available for clients. | ||
187 | */ | ||
188 | int i2c_add_adapter(struct i2c_adapter *adap) | ||
189 | { | 327 | { |
190 | int id, res = 0; | 328 | int res = 0; |
191 | struct list_head *item; | 329 | struct list_head *item; |
192 | struct i2c_driver *driver; | 330 | struct i2c_driver *driver; |
193 | 331 | ||
194 | mutex_lock(&core_lists); | ||
195 | |||
196 | if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) { | ||
197 | res = -ENOMEM; | ||
198 | goto out_unlock; | ||
199 | } | ||
200 | |||
201 | res = idr_get_new(&i2c_adapter_idr, adap, &id); | ||
202 | if (res < 0) { | ||
203 | if (res == -EAGAIN) | ||
204 | res = -ENOMEM; | ||
205 | goto out_unlock; | ||
206 | } | ||
207 | |||
208 | adap->nr = id & MAX_ID_MASK; | ||
209 | mutex_init(&adap->bus_lock); | 332 | mutex_init(&adap->bus_lock); |
210 | mutex_init(&adap->clist_lock); | 333 | mutex_init(&adap->clist_lock); |
211 | list_add_tail(&adap->list,&adapters); | ||
212 | INIT_LIST_HEAD(&adap->clients); | 334 | INIT_LIST_HEAD(&adap->clients); |
213 | 335 | ||
336 | mutex_lock(&core_lists); | ||
337 | list_add_tail(&adap->list, &adapters); | ||
338 | |||
214 | /* Add the adapter to the driver core. | 339 | /* Add the adapter to the driver core. |
215 | * If the parent pointer is not set up, | 340 | * If the parent pointer is not set up, |
216 | * we add this adapter to the host bus. | 341 | * we add this adapter to the host bus. |
@@ -221,27 +346,19 @@ int i2c_add_adapter(struct i2c_adapter *adap) | |||
221 | "physical device\n", adap->name); | 346 | "physical device\n", adap->name); |
222 | } | 347 | } |
223 | sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); | 348 | sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); |
224 | adap->dev.driver = &i2c_adapter_driver; | ||
225 | adap->dev.release = &i2c_adapter_dev_release; | 349 | adap->dev.release = &i2c_adapter_dev_release; |
350 | adap->dev.class = &i2c_adapter_class; | ||
226 | res = device_register(&adap->dev); | 351 | res = device_register(&adap->dev); |
227 | if (res) | 352 | if (res) |
228 | goto out_list; | 353 | goto out_list; |
229 | res = device_create_file(&adap->dev, &dev_attr_name); | ||
230 | if (res) | ||
231 | goto out_unregister; | ||
232 | |||
233 | /* Add this adapter to the i2c_adapter class */ | ||
234 | memset(&adap->class_dev, 0x00, sizeof(struct class_device)); | ||
235 | adap->class_dev.dev = &adap->dev; | ||
236 | adap->class_dev.class = &i2c_adapter_class; | ||
237 | strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); | ||
238 | res = class_device_register(&adap->class_dev); | ||
239 | if (res) | ||
240 | goto out_remove_name; | ||
241 | 354 | ||
242 | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); | 355 | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); |
243 | 356 | ||
244 | /* inform drivers of new adapters */ | 357 | /* create pre-declared device nodes for new-style drivers */ |
358 | if (adap->nr < __i2c_first_dynamic_bus_num) | ||
359 | i2c_scan_static_board_info(adap); | ||
360 | |||
361 | /* let legacy drivers scan this bus for matching devices */ | ||
245 | list_for_each(item,&drivers) { | 362 | list_for_each(item,&drivers) { |
246 | driver = list_entry(item, struct i2c_driver, list); | 363 | driver = list_entry(item, struct i2c_driver, list); |
247 | if (driver->attach_adapter) | 364 | if (driver->attach_adapter) |
@@ -253,18 +370,98 @@ out_unlock: | |||
253 | mutex_unlock(&core_lists); | 370 | mutex_unlock(&core_lists); |
254 | return res; | 371 | return res; |
255 | 372 | ||
256 | out_remove_name: | ||
257 | device_remove_file(&adap->dev, &dev_attr_name); | ||
258 | out_unregister: | ||
259 | init_completion(&adap->dev_released); /* Needed? */ | ||
260 | device_unregister(&adap->dev); | ||
261 | wait_for_completion(&adap->dev_released); | ||
262 | out_list: | 373 | out_list: |
263 | list_del(&adap->list); | 374 | list_del(&adap->list); |
264 | idr_remove(&i2c_adapter_idr, adap->nr); | 375 | idr_remove(&i2c_adapter_idr, adap->nr); |
265 | goto out_unlock; | 376 | goto out_unlock; |
266 | } | 377 | } |
267 | 378 | ||
379 | /** | ||
380 | * i2c_add_adapter - declare i2c adapter, use dynamic bus number | ||
381 | * @adapter: the adapter to add | ||
382 | * | ||
383 | * This routine is used to declare an I2C adapter when its bus number | ||
384 | * doesn't matter. Examples: for I2C adapters dynamically added by | ||
385 | * USB links or PCI plugin cards. | ||
386 | * | ||
387 | * When this returns zero, a new bus number was allocated and stored | ||
388 | * in adap->nr, and the specified adapter became available for clients. | ||
389 | * Otherwise, a negative errno value is returned. | ||
390 | */ | ||
391 | int i2c_add_adapter(struct i2c_adapter *adapter) | ||
392 | { | ||
393 | int id, res = 0; | ||
394 | |||
395 | retry: | ||
396 | if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) | ||
397 | return -ENOMEM; | ||
398 | |||
399 | mutex_lock(&core_lists); | ||
400 | /* "above" here means "above or equal to", sigh */ | ||
401 | res = idr_get_new_above(&i2c_adapter_idr, adapter, | ||
402 | __i2c_first_dynamic_bus_num, &id); | ||
403 | mutex_unlock(&core_lists); | ||
404 | |||
405 | if (res < 0) { | ||
406 | if (res == -EAGAIN) | ||
407 | goto retry; | ||
408 | return res; | ||
409 | } | ||
410 | |||
411 | adapter->nr = id; | ||
412 | return i2c_register_adapter(adapter); | ||
413 | } | ||
414 | EXPORT_SYMBOL(i2c_add_adapter); | ||
415 | |||
416 | /** | ||
417 | * i2c_add_numbered_adapter - declare i2c adapter, use static bus number | ||
418 | * @adap: the adapter to register (with adap->nr initialized) | ||
419 | * | ||
420 | * This routine is used to declare an I2C adapter when its bus number | ||
421 | * matters. Example: for I2C adapters from system-on-chip CPUs, or | ||
422 | * otherwise built in to the system's mainboard, and where i2c_board_info | ||
423 | * is used to properly configure I2C devices. | ||
424 | * | ||
425 | * If no devices have pre-been declared for this bus, then be sure to | ||
426 | * register the adapter before any dynamically allocated ones. Otherwise | ||
427 | * the required bus ID may not be available. | ||
428 | * | ||
429 | * When this returns zero, the specified adapter became available for | ||
430 | * clients using the bus number provided in adap->nr. Also, the table | ||
431 | * of I2C devices pre-declared using i2c_register_board_info() is scanned, | ||
432 | * and the appropriate driver model device nodes are created. Otherwise, a | ||
433 | * negative errno value is returned. | ||
434 | */ | ||
435 | int i2c_add_numbered_adapter(struct i2c_adapter *adap) | ||
436 | { | ||
437 | int id; | ||
438 | int status; | ||
439 | |||
440 | if (adap->nr & ~MAX_ID_MASK) | ||
441 | return -EINVAL; | ||
442 | |||
443 | retry: | ||
444 | if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) | ||
445 | return -ENOMEM; | ||
446 | |||
447 | mutex_lock(&core_lists); | ||
448 | /* "above" here means "above or equal to", sigh; | ||
449 | * we need the "equal to" result to force the result | ||
450 | */ | ||
451 | status = idr_get_new_above(&i2c_adapter_idr, adap, adap->nr, &id); | ||
452 | if (status == 0 && id != adap->nr) { | ||
453 | status = -EBUSY; | ||
454 | idr_remove(&i2c_adapter_idr, id); | ||
455 | } | ||
456 | mutex_unlock(&core_lists); | ||
457 | if (status == -EAGAIN) | ||
458 | goto retry; | ||
459 | |||
460 | if (status == 0) | ||
461 | status = i2c_register_adapter(adap); | ||
462 | return status; | ||
463 | } | ||
464 | EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); | ||
268 | 465 | ||
269 | int i2c_del_adapter(struct i2c_adapter *adap) | 466 | int i2c_del_adapter(struct i2c_adapter *adap) |
270 | { | 467 | { |
@@ -302,9 +499,19 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
302 | /* detach any active clients. This must be done first, because | 499 | /* detach any active clients. This must be done first, because |
303 | * it can fail; in which case we give up. */ | 500 | * it can fail; in which case we give up. */ |
304 | list_for_each_safe(item, _n, &adap->clients) { | 501 | list_for_each_safe(item, _n, &adap->clients) { |
502 | struct i2c_driver *driver; | ||
503 | |||
305 | client = list_entry(item, struct i2c_client, list); | 504 | client = list_entry(item, struct i2c_client, list); |
505 | driver = client->driver; | ||
506 | |||
507 | /* new style, follow standard driver model */ | ||
508 | if (!driver || is_newstyle_driver(driver)) { | ||
509 | i2c_unregister_device(client); | ||
510 | continue; | ||
511 | } | ||
306 | 512 | ||
307 | if ((res=client->driver->detach_client(client))) { | 513 | /* legacy drivers create and remove clients themselves */ |
514 | if ((res = driver->detach_client(client))) { | ||
308 | dev_err(&adap->dev, "detach_client failed for client " | 515 | dev_err(&adap->dev, "detach_client failed for client " |
309 | "[%s] at address 0x%02x\n", client->name, | 516 | "[%s] at address 0x%02x\n", client->name, |
310 | client->addr); | 517 | client->addr); |
@@ -314,17 +521,13 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
314 | 521 | ||
315 | /* clean up the sysfs representation */ | 522 | /* clean up the sysfs representation */ |
316 | init_completion(&adap->dev_released); | 523 | init_completion(&adap->dev_released); |
317 | init_completion(&adap->class_dev_released); | ||
318 | class_device_unregister(&adap->class_dev); | ||
319 | device_remove_file(&adap->dev, &dev_attr_name); | ||
320 | device_unregister(&adap->dev); | 524 | device_unregister(&adap->dev); |
321 | list_del(&adap->list); | 525 | list_del(&adap->list); |
322 | 526 | ||
323 | /* wait for sysfs to drop all references */ | 527 | /* wait for sysfs to drop all references */ |
324 | wait_for_completion(&adap->dev_released); | 528 | wait_for_completion(&adap->dev_released); |
325 | wait_for_completion(&adap->class_dev_released); | ||
326 | 529 | ||
327 | /* free dynamically allocated bus id */ | 530 | /* free bus id */ |
328 | idr_remove(&i2c_adapter_idr, adap->nr); | 531 | idr_remove(&i2c_adapter_idr, adap->nr); |
329 | 532 | ||
330 | dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); | 533 | dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); |
@@ -333,24 +536,42 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
333 | mutex_unlock(&core_lists); | 536 | mutex_unlock(&core_lists); |
334 | return res; | 537 | return res; |
335 | } | 538 | } |
539 | EXPORT_SYMBOL(i2c_del_adapter); | ||
540 | |||
336 | 541 | ||
542 | /* ------------------------------------------------------------------------- */ | ||
337 | 543 | ||
338 | /* ----- | 544 | /* |
339 | * What follows is the "upwards" interface: commands for talking to clients, | 545 | * An i2c_driver is used with one or more i2c_client (device) nodes to access |
340 | * which implement the functions to access the physical information of the | 546 | * i2c slave chips, on a bus instance associated with some i2c_adapter. There |
341 | * chips. | 547 | * are two models for binding the driver to its device: "new style" drivers |
548 | * follow the standard Linux driver model and just respond to probe() calls | ||
549 | * issued if the driver core sees they match(); "legacy" drivers create device | ||
550 | * nodes themselves. | ||
342 | */ | 551 | */ |
343 | 552 | ||
344 | int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | 553 | int i2c_register_driver(struct module *owner, struct i2c_driver *driver) |
345 | { | 554 | { |
346 | struct list_head *item; | ||
347 | struct i2c_adapter *adapter; | ||
348 | int res; | 555 | int res; |
349 | 556 | ||
557 | /* new style driver methods can't mix with legacy ones */ | ||
558 | if (is_newstyle_driver(driver)) { | ||
559 | if (driver->attach_adapter || driver->detach_adapter | ||
560 | || driver->detach_client) { | ||
561 | printk(KERN_WARNING | ||
562 | "i2c-core: driver [%s] is confused\n", | ||
563 | driver->driver.name); | ||
564 | return -EINVAL; | ||
565 | } | ||
566 | } | ||
567 | |||
350 | /* add the driver to the list of i2c drivers in the driver core */ | 568 | /* add the driver to the list of i2c drivers in the driver core */ |
351 | driver->driver.owner = owner; | 569 | driver->driver.owner = owner; |
352 | driver->driver.bus = &i2c_bus_type; | 570 | driver->driver.bus = &i2c_bus_type; |
353 | 571 | ||
572 | /* for new style drivers, when registration returns the driver core | ||
573 | * will have called probe() for all matching-but-unbound devices. | ||
574 | */ | ||
354 | res = driver_register(&driver->driver); | 575 | res = driver_register(&driver->driver); |
355 | if (res) | 576 | if (res) |
356 | return res; | 577 | return res; |
@@ -360,10 +581,11 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
360 | list_add_tail(&driver->list,&drivers); | 581 | list_add_tail(&driver->list,&drivers); |
361 | pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); | 582 | pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); |
362 | 583 | ||
363 | /* now look for instances of driver on our adapters */ | 584 | /* legacy drivers scan i2c busses directly */ |
364 | if (driver->attach_adapter) { | 585 | if (driver->attach_adapter) { |
365 | list_for_each(item,&adapters) { | 586 | struct i2c_adapter *adapter; |
366 | adapter = list_entry(item, struct i2c_adapter, list); | 587 | |
588 | list_for_each_entry(adapter, &adapters, list) { | ||
367 | driver->attach_adapter(adapter); | 589 | driver->attach_adapter(adapter); |
368 | } | 590 | } |
369 | } | 591 | } |
@@ -373,16 +595,22 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
373 | } | 595 | } |
374 | EXPORT_SYMBOL(i2c_register_driver); | 596 | EXPORT_SYMBOL(i2c_register_driver); |
375 | 597 | ||
376 | int i2c_del_driver(struct i2c_driver *driver) | 598 | /** |
599 | * i2c_del_driver - unregister I2C driver | ||
600 | * @driver: the driver being unregistered | ||
601 | */ | ||
602 | void i2c_del_driver(struct i2c_driver *driver) | ||
377 | { | 603 | { |
378 | struct list_head *item1, *item2, *_n; | 604 | struct list_head *item1, *item2, *_n; |
379 | struct i2c_client *client; | 605 | struct i2c_client *client; |
380 | struct i2c_adapter *adap; | 606 | struct i2c_adapter *adap; |
381 | 607 | ||
382 | int res = 0; | ||
383 | |||
384 | mutex_lock(&core_lists); | 608 | mutex_lock(&core_lists); |
385 | 609 | ||
610 | /* new-style driver? */ | ||
611 | if (is_newstyle_driver(driver)) | ||
612 | goto unregister; | ||
613 | |||
386 | /* Have a look at each adapter, if clients of this driver are still | 614 | /* Have a look at each adapter, if clients of this driver are still |
387 | * attached. If so, detach them to be able to kill the driver | 615 | * attached. If so, detach them to be able to kill the driver |
388 | * afterwards. | 616 | * afterwards. |
@@ -390,11 +618,10 @@ int i2c_del_driver(struct i2c_driver *driver) | |||
390 | list_for_each(item1,&adapters) { | 618 | list_for_each(item1,&adapters) { |
391 | adap = list_entry(item1, struct i2c_adapter, list); | 619 | adap = list_entry(item1, struct i2c_adapter, list); |
392 | if (driver->detach_adapter) { | 620 | if (driver->detach_adapter) { |
393 | if ((res = driver->detach_adapter(adap))) { | 621 | if (driver->detach_adapter(adap)) { |
394 | dev_err(&adap->dev, "detach_adapter failed " | 622 | dev_err(&adap->dev, "detach_adapter failed " |
395 | "for driver [%s]\n", | 623 | "for driver [%s]\n", |
396 | driver->driver.name); | 624 | driver->driver.name); |
397 | goto out_unlock; | ||
398 | } | 625 | } |
399 | } else { | 626 | } else { |
400 | list_for_each_safe(item2, _n, &adap->clients) { | 627 | list_for_each_safe(item2, _n, &adap->clients) { |
@@ -404,25 +631,26 @@ int i2c_del_driver(struct i2c_driver *driver) | |||
404 | dev_dbg(&adap->dev, "detaching client [%s] " | 631 | dev_dbg(&adap->dev, "detaching client [%s] " |
405 | "at 0x%02x\n", client->name, | 632 | "at 0x%02x\n", client->name, |
406 | client->addr); | 633 | client->addr); |
407 | if ((res = driver->detach_client(client))) { | 634 | if (driver->detach_client(client)) { |
408 | dev_err(&adap->dev, "detach_client " | 635 | dev_err(&adap->dev, "detach_client " |
409 | "failed for client [%s] at " | 636 | "failed for client [%s] at " |
410 | "0x%02x\n", client->name, | 637 | "0x%02x\n", client->name, |
411 | client->addr); | 638 | client->addr); |
412 | goto out_unlock; | ||
413 | } | 639 | } |
414 | } | 640 | } |
415 | } | 641 | } |
416 | } | 642 | } |
417 | 643 | ||
644 | unregister: | ||
418 | driver_unregister(&driver->driver); | 645 | driver_unregister(&driver->driver); |
419 | list_del(&driver->list); | 646 | list_del(&driver->list); |
420 | pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); | 647 | pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); |
421 | 648 | ||
422 | out_unlock: | ||
423 | mutex_unlock(&core_lists); | 649 | mutex_unlock(&core_lists); |
424 | return 0; | ||
425 | } | 650 | } |
651 | EXPORT_SYMBOL(i2c_del_driver); | ||
652 | |||
653 | /* ------------------------------------------------------------------------- */ | ||
426 | 654 | ||
427 | static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr) | 655 | static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr) |
428 | { | 656 | { |
@@ -447,6 +675,7 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr) | |||
447 | 675 | ||
448 | return rval; | 676 | return rval; |
449 | } | 677 | } |
678 | EXPORT_SYMBOL(i2c_check_addr); | ||
450 | 679 | ||
451 | int i2c_attach_client(struct i2c_client *client) | 680 | int i2c_attach_client(struct i2c_client *client) |
452 | { | 681 | { |
@@ -463,9 +692,15 @@ int i2c_attach_client(struct i2c_client *client) | |||
463 | client->usage_count = 0; | 692 | client->usage_count = 0; |
464 | 693 | ||
465 | client->dev.parent = &client->adapter->dev; | 694 | client->dev.parent = &client->adapter->dev; |
466 | client->dev.driver = &client->driver->driver; | ||
467 | client->dev.bus = &i2c_bus_type; | 695 | client->dev.bus = &i2c_bus_type; |
468 | client->dev.release = &i2c_client_release; | 696 | |
697 | if (client->driver) | ||
698 | client->dev.driver = &client->driver->driver; | ||
699 | |||
700 | if (client->driver && !is_newstyle_driver(client->driver)) | ||
701 | client->dev.release = i2c_client_release; | ||
702 | else | ||
703 | client->dev.release = i2c_client_dev_release; | ||
469 | 704 | ||
470 | snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), | 705 | snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), |
471 | "%d-%04x", i2c_adapter_id(adapter), client->addr); | 706 | "%d-%04x", i2c_adapter_id(adapter), client->addr); |
@@ -474,9 +709,6 @@ int i2c_attach_client(struct i2c_client *client) | |||
474 | res = device_register(&client->dev); | 709 | res = device_register(&client->dev); |
475 | if (res) | 710 | if (res) |
476 | goto out_list; | 711 | goto out_list; |
477 | res = device_create_file(&client->dev, &dev_attr_client_name); | ||
478 | if (res) | ||
479 | goto out_unregister; | ||
480 | mutex_unlock(&adapter->clist_lock); | 712 | mutex_unlock(&adapter->clist_lock); |
481 | 713 | ||
482 | if (adapter->client_register) { | 714 | if (adapter->client_register) { |
@@ -489,10 +721,6 @@ int i2c_attach_client(struct i2c_client *client) | |||
489 | 721 | ||
490 | return 0; | 722 | return 0; |
491 | 723 | ||
492 | out_unregister: | ||
493 | init_completion(&client->released); /* Needed? */ | ||
494 | device_unregister(&client->dev); | ||
495 | wait_for_completion(&client->released); | ||
496 | out_list: | 724 | out_list: |
497 | list_del(&client->list); | 725 | list_del(&client->list); |
498 | dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " | 726 | dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " |
@@ -501,7 +729,7 @@ out_unlock: | |||
501 | mutex_unlock(&adapter->clist_lock); | 729 | mutex_unlock(&adapter->clist_lock); |
502 | return res; | 730 | return res; |
503 | } | 731 | } |
504 | 732 | EXPORT_SYMBOL(i2c_attach_client); | |
505 | 733 | ||
506 | int i2c_detach_client(struct i2c_client *client) | 734 | int i2c_detach_client(struct i2c_client *client) |
507 | { | 735 | { |
@@ -527,7 +755,6 @@ int i2c_detach_client(struct i2c_client *client) | |||
527 | mutex_lock(&adapter->clist_lock); | 755 | mutex_lock(&adapter->clist_lock); |
528 | list_del(&client->list); | 756 | list_del(&client->list); |
529 | init_completion(&client->released); | 757 | init_completion(&client->released); |
530 | device_remove_file(&client->dev, &dev_attr_client_name); | ||
531 | device_unregister(&client->dev); | 758 | device_unregister(&client->dev); |
532 | mutex_unlock(&adapter->clist_lock); | 759 | mutex_unlock(&adapter->clist_lock); |
533 | wait_for_completion(&client->released); | 760 | wait_for_completion(&client->released); |
@@ -535,6 +762,7 @@ int i2c_detach_client(struct i2c_client *client) | |||
535 | out: | 762 | out: |
536 | return res; | 763 | return res; |
537 | } | 764 | } |
765 | EXPORT_SYMBOL(i2c_detach_client); | ||
538 | 766 | ||
539 | static int i2c_inc_use_client(struct i2c_client *client) | 767 | static int i2c_inc_use_client(struct i2c_client *client) |
540 | { | 768 | { |
@@ -567,6 +795,7 @@ int i2c_use_client(struct i2c_client *client) | |||
567 | 795 | ||
568 | return 0; | 796 | return 0; |
569 | } | 797 | } |
798 | EXPORT_SYMBOL(i2c_use_client); | ||
570 | 799 | ||
571 | int i2c_release_client(struct i2c_client *client) | 800 | int i2c_release_client(struct i2c_client *client) |
572 | { | 801 | { |
@@ -581,6 +810,7 @@ int i2c_release_client(struct i2c_client *client) | |||
581 | 810 | ||
582 | return 0; | 811 | return 0; |
583 | } | 812 | } |
813 | EXPORT_SYMBOL(i2c_release_client); | ||
584 | 814 | ||
585 | void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg) | 815 | void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg) |
586 | { | 816 | { |
@@ -601,6 +831,7 @@ void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg) | |||
601 | } | 831 | } |
602 | mutex_unlock(&adap->clist_lock); | 832 | mutex_unlock(&adap->clist_lock); |
603 | } | 833 | } |
834 | EXPORT_SYMBOL(i2c_clients_command); | ||
604 | 835 | ||
605 | static int __init i2c_init(void) | 836 | static int __init i2c_init(void) |
606 | { | 837 | { |
@@ -609,16 +840,12 @@ static int __init i2c_init(void) | |||
609 | retval = bus_register(&i2c_bus_type); | 840 | retval = bus_register(&i2c_bus_type); |
610 | if (retval) | 841 | if (retval) |
611 | return retval; | 842 | return retval; |
612 | retval = driver_register(&i2c_adapter_driver); | ||
613 | if (retval) | ||
614 | return retval; | ||
615 | return class_register(&i2c_adapter_class); | 843 | return class_register(&i2c_adapter_class); |
616 | } | 844 | } |
617 | 845 | ||
618 | static void __exit i2c_exit(void) | 846 | static void __exit i2c_exit(void) |
619 | { | 847 | { |
620 | class_unregister(&i2c_adapter_class); | 848 | class_unregister(&i2c_adapter_class); |
621 | driver_unregister(&i2c_adapter_driver); | ||
622 | bus_unregister(&i2c_bus_type); | 849 | bus_unregister(&i2c_bus_type); |
623 | } | 850 | } |
624 | 851 | ||
@@ -638,8 +865,9 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num) | |||
638 | #ifdef DEBUG | 865 | #ifdef DEBUG |
639 | for (ret = 0; ret < num; ret++) { | 866 | for (ret = 0; ret < num; ret++) { |
640 | dev_dbg(&adap->dev, "master_xfer[%d] %c, addr=0x%02x, " | 867 | dev_dbg(&adap->dev, "master_xfer[%d] %c, addr=0x%02x, " |
641 | "len=%d\n", ret, msgs[ret].flags & I2C_M_RD ? | 868 | "len=%d%s\n", ret, (msgs[ret].flags & I2C_M_RD) |
642 | 'R' : 'W', msgs[ret].addr, msgs[ret].len); | 869 | ? 'R' : 'W', msgs[ret].addr, msgs[ret].len, |
870 | (msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : ""); | ||
643 | } | 871 | } |
644 | #endif | 872 | #endif |
645 | 873 | ||
@@ -653,6 +881,7 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num) | |||
653 | return -ENOSYS; | 881 | return -ENOSYS; |
654 | } | 882 | } |
655 | } | 883 | } |
884 | EXPORT_SYMBOL(i2c_transfer); | ||
656 | 885 | ||
657 | int i2c_master_send(struct i2c_client *client,const char *buf ,int count) | 886 | int i2c_master_send(struct i2c_client *client,const char *buf ,int count) |
658 | { | 887 | { |
@@ -671,6 +900,7 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count) | |||
671 | transmitted, else error code. */ | 900 | transmitted, else error code. */ |
672 | return (ret == 1) ? count : ret; | 901 | return (ret == 1) ? count : ret; |
673 | } | 902 | } |
903 | EXPORT_SYMBOL(i2c_master_send); | ||
674 | 904 | ||
675 | int i2c_master_recv(struct i2c_client *client, char *buf ,int count) | 905 | int i2c_master_recv(struct i2c_client *client, char *buf ,int count) |
676 | { | 906 | { |
@@ -690,7 +920,7 @@ int i2c_master_recv(struct i2c_client *client, char *buf ,int count) | |||
690 | transmitted, else error code. */ | 920 | transmitted, else error code. */ |
691 | return (ret == 1) ? count : ret; | 921 | return (ret == 1) ? count : ret; |
692 | } | 922 | } |
693 | 923 | EXPORT_SYMBOL(i2c_master_recv); | |
694 | 924 | ||
695 | int i2c_control(struct i2c_client *client, | 925 | int i2c_control(struct i2c_client *client, |
696 | unsigned int cmd, unsigned long arg) | 926 | unsigned int cmd, unsigned long arg) |
@@ -712,6 +942,7 @@ int i2c_control(struct i2c_client *client, | |||
712 | } | 942 | } |
713 | return ret; | 943 | return ret; |
714 | } | 944 | } |
945 | EXPORT_SYMBOL(i2c_control); | ||
715 | 946 | ||
716 | /* ---------------------------------------------------- | 947 | /* ---------------------------------------------------- |
717 | * the i2c address scanning function | 948 | * the i2c address scanning function |
@@ -853,6 +1084,70 @@ int i2c_probe(struct i2c_adapter *adapter, | |||
853 | 1084 | ||
854 | return 0; | 1085 | return 0; |
855 | } | 1086 | } |
1087 | EXPORT_SYMBOL(i2c_probe); | ||
1088 | |||
1089 | struct i2c_client * | ||
1090 | i2c_new_probed_device(struct i2c_adapter *adap, | ||
1091 | struct i2c_board_info *info, | ||
1092 | unsigned short const *addr_list) | ||
1093 | { | ||
1094 | int i; | ||
1095 | |||
1096 | /* Stop here if the bus doesn't support probing */ | ||
1097 | if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) { | ||
1098 | dev_err(&adap->dev, "Probing not supported\n"); | ||
1099 | return NULL; | ||
1100 | } | ||
1101 | |||
1102 | mutex_lock(&adap->clist_lock); | ||
1103 | for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { | ||
1104 | /* Check address validity */ | ||
1105 | if (addr_list[i] < 0x03 || addr_list[i] > 0x77) { | ||
1106 | dev_warn(&adap->dev, "Invalid 7-bit address " | ||
1107 | "0x%02x\n", addr_list[i]); | ||
1108 | continue; | ||
1109 | } | ||
1110 | |||
1111 | /* Check address availability */ | ||
1112 | if (__i2c_check_addr(adap, addr_list[i])) { | ||
1113 | dev_dbg(&adap->dev, "Address 0x%02x already in " | ||
1114 | "use, not probing\n", addr_list[i]); | ||
1115 | continue; | ||
1116 | } | ||
1117 | |||
1118 | /* Test address responsiveness | ||
1119 | The default probe method is a quick write, but it is known | ||
1120 | to corrupt the 24RF08 EEPROMs due to a state machine bug, | ||
1121 | and could also irreversibly write-protect some EEPROMs, so | ||
1122 | for address ranges 0x30-0x37 and 0x50-0x5f, we use a byte | ||
1123 | read instead. Also, some bus drivers don't implement | ||
1124 | quick write, so we fallback to a byte read it that case | ||
1125 | too. */ | ||
1126 | if ((addr_list[i] & ~0x07) == 0x30 | ||
1127 | || (addr_list[i] & ~0x0f) == 0x50 | ||
1128 | || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) { | ||
1129 | if (i2c_smbus_xfer(adap, addr_list[i], 0, | ||
1130 | I2C_SMBUS_READ, 0, | ||
1131 | I2C_SMBUS_BYTE, NULL) >= 0) | ||
1132 | break; | ||
1133 | } else { | ||
1134 | if (i2c_smbus_xfer(adap, addr_list[i], 0, | ||
1135 | I2C_SMBUS_WRITE, 0, | ||
1136 | I2C_SMBUS_QUICK, NULL) >= 0) | ||
1137 | break; | ||
1138 | } | ||
1139 | } | ||
1140 | mutex_unlock(&adap->clist_lock); | ||
1141 | |||
1142 | if (addr_list[i] == I2C_CLIENT_END) { | ||
1143 | dev_dbg(&adap->dev, "Probing failed, no device found\n"); | ||
1144 | return NULL; | ||
1145 | } | ||
1146 | |||
1147 | info->addr = addr_list[i]; | ||
1148 | return i2c_new_device(adap, info); | ||
1149 | } | ||
1150 | EXPORT_SYMBOL_GPL(i2c_new_probed_device); | ||
856 | 1151 | ||
857 | struct i2c_adapter* i2c_get_adapter(int id) | 1152 | struct i2c_adapter* i2c_get_adapter(int id) |
858 | { | 1153 | { |
@@ -866,11 +1161,13 @@ struct i2c_adapter* i2c_get_adapter(int id) | |||
866 | mutex_unlock(&core_lists); | 1161 | mutex_unlock(&core_lists); |
867 | return adapter; | 1162 | return adapter; |
868 | } | 1163 | } |
1164 | EXPORT_SYMBOL(i2c_get_adapter); | ||
869 | 1165 | ||
870 | void i2c_put_adapter(struct i2c_adapter *adap) | 1166 | void i2c_put_adapter(struct i2c_adapter *adap) |
871 | { | 1167 | { |
872 | module_put(adap->owner); | 1168 | module_put(adap->owner); |
873 | } | 1169 | } |
1170 | EXPORT_SYMBOL(i2c_put_adapter); | ||
874 | 1171 | ||
875 | /* The SMBus parts */ | 1172 | /* The SMBus parts */ |
876 | 1173 | ||
@@ -939,6 +1236,7 @@ s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value) | |||
939 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1236 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, |
940 | value,0,I2C_SMBUS_QUICK,NULL); | 1237 | value,0,I2C_SMBUS_QUICK,NULL); |
941 | } | 1238 | } |
1239 | EXPORT_SYMBOL(i2c_smbus_write_quick); | ||
942 | 1240 | ||
943 | s32 i2c_smbus_read_byte(struct i2c_client *client) | 1241 | s32 i2c_smbus_read_byte(struct i2c_client *client) |
944 | { | 1242 | { |
@@ -949,12 +1247,14 @@ s32 i2c_smbus_read_byte(struct i2c_client *client) | |||
949 | else | 1247 | else |
950 | return data.byte; | 1248 | return data.byte; |
951 | } | 1249 | } |
1250 | EXPORT_SYMBOL(i2c_smbus_read_byte); | ||
952 | 1251 | ||
953 | s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) | 1252 | s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) |
954 | { | 1253 | { |
955 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1254 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, |
956 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); | 1255 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); |
957 | } | 1256 | } |
1257 | EXPORT_SYMBOL(i2c_smbus_write_byte); | ||
958 | 1258 | ||
959 | s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) | 1259 | s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) |
960 | { | 1260 | { |
@@ -965,6 +1265,7 @@ s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) | |||
965 | else | 1265 | else |
966 | return data.byte; | 1266 | return data.byte; |
967 | } | 1267 | } |
1268 | EXPORT_SYMBOL(i2c_smbus_read_byte_data); | ||
968 | 1269 | ||
969 | s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) | 1270 | s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) |
970 | { | 1271 | { |
@@ -974,6 +1275,7 @@ s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) | |||
974 | I2C_SMBUS_WRITE,command, | 1275 | I2C_SMBUS_WRITE,command, |
975 | I2C_SMBUS_BYTE_DATA,&data); | 1276 | I2C_SMBUS_BYTE_DATA,&data); |
976 | } | 1277 | } |
1278 | EXPORT_SYMBOL(i2c_smbus_write_byte_data); | ||
977 | 1279 | ||
978 | s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) | 1280 | s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) |
979 | { | 1281 | { |
@@ -984,6 +1286,7 @@ s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) | |||
984 | else | 1286 | else |
985 | return data.word; | 1287 | return data.word; |
986 | } | 1288 | } |
1289 | EXPORT_SYMBOL(i2c_smbus_read_word_data); | ||
987 | 1290 | ||
988 | s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) | 1291 | s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) |
989 | { | 1292 | { |
@@ -993,6 +1296,23 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) | |||
993 | I2C_SMBUS_WRITE,command, | 1296 | I2C_SMBUS_WRITE,command, |
994 | I2C_SMBUS_WORD_DATA,&data); | 1297 | I2C_SMBUS_WORD_DATA,&data); |
995 | } | 1298 | } |
1299 | EXPORT_SYMBOL(i2c_smbus_write_word_data); | ||
1300 | |||
1301 | /* Returns the number of read bytes */ | ||
1302 | s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, | ||
1303 | u8 *values) | ||
1304 | { | ||
1305 | union i2c_smbus_data data; | ||
1306 | |||
1307 | if (i2c_smbus_xfer(client->adapter, client->addr, client->flags, | ||
1308 | I2C_SMBUS_READ, command, | ||
1309 | I2C_SMBUS_BLOCK_DATA, &data)) | ||
1310 | return -1; | ||
1311 | |||
1312 | memcpy(values, &data.block[1], data.block[0]); | ||
1313 | return data.block[0]; | ||
1314 | } | ||
1315 | EXPORT_SYMBOL(i2c_smbus_read_block_data); | ||
996 | 1316 | ||
997 | s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, | 1317 | s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, |
998 | u8 length, const u8 *values) | 1318 | u8 length, const u8 *values) |
@@ -1007,6 +1327,7 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, | |||
1007 | I2C_SMBUS_WRITE,command, | 1327 | I2C_SMBUS_WRITE,command, |
1008 | I2C_SMBUS_BLOCK_DATA,&data); | 1328 | I2C_SMBUS_BLOCK_DATA,&data); |
1009 | } | 1329 | } |
1330 | EXPORT_SYMBOL(i2c_smbus_write_block_data); | ||
1010 | 1331 | ||
1011 | /* Returns the number of read bytes */ | 1332 | /* Returns the number of read bytes */ |
1012 | s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values) | 1333 | s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values) |
@@ -1021,6 +1342,7 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *val | |||
1021 | memcpy(values, &data.block[1], data.block[0]); | 1342 | memcpy(values, &data.block[1], data.block[0]); |
1022 | return data.block[0]; | 1343 | return data.block[0]; |
1023 | } | 1344 | } |
1345 | EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); | ||
1024 | 1346 | ||
1025 | s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, | 1347 | s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, |
1026 | u8 length, const u8 *values) | 1348 | u8 length, const u8 *values) |
@@ -1035,6 +1357,7 @@ s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, | |||
1035 | I2C_SMBUS_WRITE, command, | 1357 | I2C_SMBUS_WRITE, command, |
1036 | I2C_SMBUS_I2C_BLOCK_DATA, &data); | 1358 | I2C_SMBUS_I2C_BLOCK_DATA, &data); |
1037 | } | 1359 | } |
1360 | EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data); | ||
1038 | 1361 | ||
1039 | /* Simulate a SMBus command using the i2c protocol | 1362 | /* Simulate a SMBus command using the i2c protocol |
1040 | No checking of parameters is done! */ | 1363 | No checking of parameters is done! */ |
@@ -1098,9 +1421,9 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1098 | break; | 1421 | break; |
1099 | case I2C_SMBUS_BLOCK_DATA: | 1422 | case I2C_SMBUS_BLOCK_DATA: |
1100 | if (read_write == I2C_SMBUS_READ) { | 1423 | if (read_write == I2C_SMBUS_READ) { |
1101 | dev_err(&adapter->dev, "Block read not supported " | 1424 | msg[1].flags |= I2C_M_RECV_LEN; |
1102 | "under I2C emulation!\n"); | 1425 | msg[1].len = 1; /* block length will be added by |
1103 | return -1; | 1426 | the underlying bus driver */ |
1104 | } else { | 1427 | } else { |
1105 | msg[0].len = data->block[0] + 2; | 1428 | msg[0].len = data->block[0] + 2; |
1106 | if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { | 1429 | if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { |
@@ -1114,9 +1437,21 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1114 | } | 1437 | } |
1115 | break; | 1438 | break; |
1116 | case I2C_SMBUS_BLOCK_PROC_CALL: | 1439 | case I2C_SMBUS_BLOCK_PROC_CALL: |
1117 | dev_dbg(&adapter->dev, "Block process call not supported " | 1440 | num = 2; /* Another special case */ |
1118 | "under I2C emulation!\n"); | 1441 | read_write = I2C_SMBUS_READ; |
1119 | return -1; | 1442 | if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { |
1443 | dev_err(&adapter->dev, "%s called with invalid " | ||
1444 | "block proc call size (%d)\n", __FUNCTION__, | ||
1445 | data->block[0]); | ||
1446 | return -1; | ||
1447 | } | ||
1448 | msg[0].len = data->block[0] + 2; | ||
1449 | for (i = 1; i < msg[0].len; i++) | ||
1450 | msgbuf0[i] = data->block[i-1]; | ||
1451 | msg[1].flags |= I2C_M_RECV_LEN; | ||
1452 | msg[1].len = 1; /* block length will be added by | ||
1453 | the underlying bus driver */ | ||
1454 | break; | ||
1120 | case I2C_SMBUS_I2C_BLOCK_DATA: | 1455 | case I2C_SMBUS_I2C_BLOCK_DATA: |
1121 | if (read_write == I2C_SMBUS_READ) { | 1456 | if (read_write == I2C_SMBUS_READ) { |
1122 | msg[1].len = I2C_SMBUS_BLOCK_MAX; | 1457 | msg[1].len = I2C_SMBUS_BLOCK_MAX; |
@@ -1180,6 +1515,11 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1180 | for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) | 1515 | for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) |
1181 | data->block[i+1] = msgbuf1[i]; | 1516 | data->block[i+1] = msgbuf1[i]; |
1182 | break; | 1517 | break; |
1518 | case I2C_SMBUS_BLOCK_DATA: | ||
1519 | case I2C_SMBUS_BLOCK_PROC_CALL: | ||
1520 | for (i = 0; i < msgbuf1[0] + 1; i++) | ||
1521 | data->block[i] = msgbuf1[i]; | ||
1522 | break; | ||
1183 | } | 1523 | } |
1184 | return 0; | 1524 | return 0; |
1185 | } | 1525 | } |
@@ -1204,43 +1544,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, | |||
1204 | 1544 | ||
1205 | return res; | 1545 | return res; |
1206 | } | 1546 | } |
1207 | |||
1208 | |||
1209 | /* Next four are needed by i2c-isa */ | ||
1210 | EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); | ||
1211 | EXPORT_SYMBOL_GPL(i2c_adapter_driver); | ||
1212 | EXPORT_SYMBOL_GPL(i2c_adapter_class); | ||
1213 | EXPORT_SYMBOL_GPL(i2c_bus_type); | ||
1214 | |||
1215 | EXPORT_SYMBOL(i2c_add_adapter); | ||
1216 | EXPORT_SYMBOL(i2c_del_adapter); | ||
1217 | EXPORT_SYMBOL(i2c_del_driver); | ||
1218 | EXPORT_SYMBOL(i2c_attach_client); | ||
1219 | EXPORT_SYMBOL(i2c_detach_client); | ||
1220 | EXPORT_SYMBOL(i2c_use_client); | ||
1221 | EXPORT_SYMBOL(i2c_release_client); | ||
1222 | EXPORT_SYMBOL(i2c_clients_command); | ||
1223 | EXPORT_SYMBOL(i2c_check_addr); | ||
1224 | |||
1225 | EXPORT_SYMBOL(i2c_master_send); | ||
1226 | EXPORT_SYMBOL(i2c_master_recv); | ||
1227 | EXPORT_SYMBOL(i2c_control); | ||
1228 | EXPORT_SYMBOL(i2c_transfer); | ||
1229 | EXPORT_SYMBOL(i2c_get_adapter); | ||
1230 | EXPORT_SYMBOL(i2c_put_adapter); | ||
1231 | EXPORT_SYMBOL(i2c_probe); | ||
1232 | |||
1233 | EXPORT_SYMBOL(i2c_smbus_xfer); | 1547 | EXPORT_SYMBOL(i2c_smbus_xfer); |
1234 | EXPORT_SYMBOL(i2c_smbus_write_quick); | ||
1235 | EXPORT_SYMBOL(i2c_smbus_read_byte); | ||
1236 | EXPORT_SYMBOL(i2c_smbus_write_byte); | ||
1237 | EXPORT_SYMBOL(i2c_smbus_read_byte_data); | ||
1238 | EXPORT_SYMBOL(i2c_smbus_write_byte_data); | ||
1239 | EXPORT_SYMBOL(i2c_smbus_read_word_data); | ||
1240 | EXPORT_SYMBOL(i2c_smbus_write_word_data); | ||
1241 | EXPORT_SYMBOL(i2c_smbus_write_block_data); | ||
1242 | EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); | ||
1243 | EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data); | ||
1244 | 1548 | ||
1245 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); | 1549 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); |
1246 | MODULE_DESCRIPTION("I2C-Bus main module"); | 1550 | MODULE_DESCRIPTION("I2C-Bus main module"); |
diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h new file mode 100644 index 000000000000..cd5bff874855 --- /dev/null +++ b/drivers/i2c/i2c-core.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * i2c-core.h - interfaces internal to the I2C framework | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | struct i2c_devinfo { | ||
20 | struct list_head list; | ||
21 | int busnum; | ||
22 | struct i2c_board_info board_info; | ||
23 | }; | ||
24 | |||
25 | /* board_lock protects board_list and first_dynamic_bus_num. | ||
26 | * only i2c core components are allowed to use these symbols. | ||
27 | */ | ||
28 | extern struct mutex __i2c_board_lock; | ||
29 | extern struct list_head __i2c_board_list; | ||
30 | extern int __i2c_first_dynamic_bus_num; | ||
31 | |||
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index cb4fa9bef8cd..e7a709710592 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/fs.h> | 31 | #include <linux/fs.h> |
32 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
33 | #include <linux/smp_lock.h> | ||
34 | #include <linux/init.h> | 33 | #include <linux/init.h> |
35 | #include <linux/list.h> | 34 | #include <linux/list.h> |
36 | #include <linux/i2c.h> | 35 | #include <linux/i2c.h> |