diff options
author | David Woodhouse <dwmw2@infradead.org> | 2007-01-17 18:34:51 -0500 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2007-01-17 18:34:51 -0500 |
commit | 9cdf083f981b8d37b3212400a359368661385099 (patch) | |
tree | aa15a6a08ad87e650dea40fb59b3180bef0d345b /drivers/i2c | |
parent | e499e01d234a31d59679b7b1e1cf628d917ba49a (diff) | |
parent | a8b3485287731978899ced11f24628c927890e78 (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers/i2c')
40 files changed, 1401 insertions, 1584 deletions
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig index c034820615bb..af0203409dd1 100644 --- a/drivers/i2c/algos/Kconfig +++ b/drivers/i2c/algos/Kconfig | |||
@@ -38,17 +38,6 @@ config I2C_ALGOPCA | |||
38 | This support is also available as a module. If so, the module | 38 | This support is also available as a module. If so, the module |
39 | will be called i2c-algo-pca. | 39 | will be called i2c-algo-pca. |
40 | 40 | ||
41 | config I2C_ALGOITE | ||
42 | tristate "ITE I2C Algorithm" | ||
43 | depends on MIPS_ITE8172 && I2C | ||
44 | help | ||
45 | This supports the use of the ITE8172 I2C interface found on some MIPS | ||
46 | systems. Say Y if you have one of these. You should also say Y for | ||
47 | the ITE I2C peripheral driver support below. | ||
48 | |||
49 | This support is also available as a module. If so, the module | ||
50 | will be called i2c-algo-ite. | ||
51 | |||
52 | config I2C_ALGO8XX | 41 | config I2C_ALGO8XX |
53 | tristate "MPC8xx CPM I2C interface" | 42 | tristate "MPC8xx CPM I2C interface" |
54 | depends on 8xx && I2C | 43 | depends on 8xx && I2C |
diff --git a/drivers/i2c/algos/Makefile b/drivers/i2c/algos/Makefile index 208be04a3dbd..cac1051bd4f1 100644 --- a/drivers/i2c/algos/Makefile +++ b/drivers/i2c/algos/Makefile | |||
@@ -5,7 +5,6 @@ | |||
5 | obj-$(CONFIG_I2C_ALGOBIT) += i2c-algo-bit.o | 5 | obj-$(CONFIG_I2C_ALGOBIT) += i2c-algo-bit.o |
6 | obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o | 6 | obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o |
7 | obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o | 7 | obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o |
8 | obj-$(CONFIG_I2C_ALGOITE) += i2c-algo-ite.o | ||
9 | obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o | 8 | obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o |
10 | 9 | ||
11 | ifeq ($(CONFIG_I2C_DEBUG_ALGO),y) | 10 | ifeq ($(CONFIG_I2C_DEBUG_ALGO),y) |
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index 21c36bfb5e6b..95aa5395a5be 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c | |||
@@ -540,15 +540,7 @@ int i2c_bit_add_bus(struct i2c_adapter *adap) | |||
540 | 540 | ||
541 | return i2c_add_adapter(adap); | 541 | return i2c_add_adapter(adap); |
542 | } | 542 | } |
543 | |||
544 | |||
545 | int i2c_bit_del_bus(struct i2c_adapter *adap) | ||
546 | { | ||
547 | return i2c_del_adapter(adap); | ||
548 | } | ||
549 | |||
550 | EXPORT_SYMBOL(i2c_bit_add_bus); | 543 | EXPORT_SYMBOL(i2c_bit_add_bus); |
551 | EXPORT_SYMBOL(i2c_bit_del_bus); | ||
552 | 544 | ||
553 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); | 545 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); |
554 | MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); | 546 | MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); |
diff --git a/drivers/i2c/algos/i2c-algo-ite.c b/drivers/i2c/algos/i2c-algo-ite.c deleted file mode 100644 index 70d8eefb5efc..000000000000 --- a/drivers/i2c/algos/i2c-algo-ite.c +++ /dev/null | |||
@@ -1,806 +0,0 @@ | |||
1 | /* | ||
2 | ------------------------------------------------------------------------- | ||
3 | i2c-algo-ite.c i2c driver algorithms for ITE adapters | ||
4 | |||
5 | Hai-Pao Fan, MontaVista Software, Inc. | ||
6 | hpfan@mvista.com or source@mvista.com | ||
7 | |||
8 | Copyright 2000 MontaVista Software Inc. | ||
9 | |||
10 | --------------------------------------------------------------------------- | ||
11 | This file was highly leveraged from i2c-algo-pcf.c, which was created | ||
12 | by Simon G. Vogl and Hans Berglund: | ||
13 | |||
14 | |||
15 | Copyright (C) 1995-1997 Simon G. Vogl | ||
16 | 1998-2000 Hans Berglund | ||
17 | |||
18 | This program is free software; you can redistribute it and/or modify | ||
19 | it under the terms of the GNU General Public License as published by | ||
20 | the Free Software Foundation; either version 2 of the License, or | ||
21 | (at your option) any later version. | ||
22 | |||
23 | This program is distributed in the hope that it will be useful, | ||
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
26 | GNU General Public License for more details. | ||
27 | |||
28 | You should have received a copy of the GNU General Public License | ||
29 | along with this program; if not, write to the Free Software | ||
30 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
31 | /* ------------------------------------------------------------------------- */ | ||
32 | |||
33 | /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and | ||
34 | Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey | ||
35 | <mbailey@littlefeet-inc.com> */ | ||
36 | |||
37 | #include <linux/kernel.h> | ||
38 | #include <linux/module.h> | ||
39 | #include <linux/delay.h> | ||
40 | #include <linux/slab.h> | ||
41 | #include <linux/init.h> | ||
42 | #include <asm/uaccess.h> | ||
43 | #include <linux/ioport.h> | ||
44 | #include <linux/errno.h> | ||
45 | #include <linux/sched.h> | ||
46 | |||
47 | #include <linux/i2c.h> | ||
48 | #include <linux/i2c-algo-ite.h> | ||
49 | #include "i2c-algo-ite.h" | ||
50 | |||
51 | #define PM_DSR IT8172_PCI_IO_BASE + IT_PM_DSR | ||
52 | #define PM_IBSR IT8172_PCI_IO_BASE + IT_PM_DSR + 0x04 | ||
53 | #define GPIO_CCR IT8172_PCI_IO_BASE + IT_GPCCR | ||
54 | |||
55 | #define DEB2(x) if (i2c_debug>=2) x | ||
56 | #define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/ | ||
57 | #define DEF_TIMEOUT 16 | ||
58 | |||
59 | |||
60 | /* module parameters: | ||
61 | */ | ||
62 | static int i2c_debug; | ||
63 | static int iic_test; /* see if the line-setting functions work */ | ||
64 | |||
65 | /* --- setting states on the bus with the right timing: --------------- */ | ||
66 | |||
67 | #define get_clock(adap) adap->getclock(adap->data) | ||
68 | #define iic_outw(adap, reg, val) adap->setiic(adap->data, reg, val) | ||
69 | #define iic_inw(adap, reg) adap->getiic(adap->data, reg) | ||
70 | |||
71 | |||
72 | /* --- other auxiliary functions -------------------------------------- */ | ||
73 | |||
74 | static void iic_start(struct i2c_algo_iic_data *adap) | ||
75 | { | ||
76 | iic_outw(adap,ITE_I2CHCR,ITE_CMD); | ||
77 | } | ||
78 | |||
79 | static void iic_stop(struct i2c_algo_iic_data *adap) | ||
80 | { | ||
81 | iic_outw(adap,ITE_I2CHCR,0); | ||
82 | iic_outw(adap,ITE_I2CHSR,ITE_I2CHSR_TDI); | ||
83 | } | ||
84 | |||
85 | static void iic_reset(struct i2c_algo_iic_data *adap) | ||
86 | { | ||
87 | iic_outw(adap, PM_IBSR, iic_inw(adap, PM_IBSR) | 0x80); | ||
88 | } | ||
89 | |||
90 | |||
91 | static int wait_for_bb(struct i2c_algo_iic_data *adap) | ||
92 | { | ||
93 | int timeout = DEF_TIMEOUT; | ||
94 | short status; | ||
95 | |||
96 | status = iic_inw(adap, ITE_I2CHSR); | ||
97 | #ifndef STUB_I2C | ||
98 | while (timeout-- && (status & ITE_I2CHSR_HB)) { | ||
99 | udelay(1000); /* How much is this? */ | ||
100 | status = iic_inw(adap, ITE_I2CHSR); | ||
101 | } | ||
102 | #endif | ||
103 | if (timeout<=0) { | ||
104 | printk(KERN_ERR "Timeout, host is busy\n"); | ||
105 | iic_reset(adap); | ||
106 | } | ||
107 | return(timeout<=0); | ||
108 | } | ||
109 | |||
110 | /* After we issue a transaction on the IIC bus, this function | ||
111 | * is called. It puts this process to sleep until we get an interrupt from | ||
112 | * from the controller telling us that the transaction we requested in complete. | ||
113 | */ | ||
114 | static int wait_for_pin(struct i2c_algo_iic_data *adap, short *status) { | ||
115 | |||
116 | int timeout = DEF_TIMEOUT; | ||
117 | |||
118 | timeout = wait_for_bb(adap); | ||
119 | if (timeout) { | ||
120 | DEB2(printk("Timeout waiting for host not busy\n");) | ||
121 | return -EIO; | ||
122 | } | ||
123 | timeout = DEF_TIMEOUT; | ||
124 | |||
125 | *status = iic_inw(adap, ITE_I2CHSR); | ||
126 | #ifndef STUB_I2C | ||
127 | while (timeout-- && !(*status & ITE_I2CHSR_TDI)) { | ||
128 | adap->waitforpin(); | ||
129 | *status = iic_inw(adap, ITE_I2CHSR); | ||
130 | } | ||
131 | #endif | ||
132 | if (timeout <= 0) | ||
133 | return(-1); | ||
134 | else | ||
135 | return(0); | ||
136 | } | ||
137 | |||
138 | static int wait_for_fe(struct i2c_algo_iic_data *adap, short *status) | ||
139 | { | ||
140 | int timeout = DEF_TIMEOUT; | ||
141 | |||
142 | *status = iic_inw(adap, ITE_I2CFSR); | ||
143 | #ifndef STUB_I2C | ||
144 | while (timeout-- && (*status & ITE_I2CFSR_FE)) { | ||
145 | udelay(1000); | ||
146 | iic_inw(adap, ITE_I2CFSR); | ||
147 | } | ||
148 | #endif | ||
149 | if (timeout <= 0) | ||
150 | return(-1); | ||
151 | else | ||
152 | return(0); | ||
153 | } | ||
154 | |||
155 | static int iic_init (struct i2c_algo_iic_data *adap) | ||
156 | { | ||
157 | short i; | ||
158 | |||
159 | /* Clear bit 7 to set I2C to normal operation mode */ | ||
160 | i=iic_inw(adap, PM_DSR)& 0xff7f; | ||
161 | iic_outw(adap, PM_DSR, i); | ||
162 | |||
163 | /* set IT_GPCCR port C bit 2&3 as function 2 */ | ||
164 | i = iic_inw(adap, GPIO_CCR) & 0xfc0f; | ||
165 | iic_outw(adap,GPIO_CCR,i); | ||
166 | |||
167 | /* Clear slave address/sub-address */ | ||
168 | iic_outw(adap,ITE_I2CSAR, 0); | ||
169 | iic_outw(adap,ITE_I2CSSAR, 0); | ||
170 | |||
171 | /* Set clock counter register */ | ||
172 | iic_outw(adap,ITE_I2CCKCNT, get_clock(adap)); | ||
173 | |||
174 | /* Set START/reSTART/STOP time registers */ | ||
175 | iic_outw(adap,ITE_I2CSHDR, 0x0a); | ||
176 | iic_outw(adap,ITE_I2CRSUR, 0x0a); | ||
177 | iic_outw(adap,ITE_I2CPSUR, 0x0a); | ||
178 | |||
179 | /* Enable interrupts on completing the current transaction */ | ||
180 | iic_outw(adap,ITE_I2CHCR, ITE_I2CHCR_IE | ITE_I2CHCR_HCE); | ||
181 | |||
182 | /* Clear transfer count */ | ||
183 | iic_outw(adap,ITE_I2CFBCR, 0x0); | ||
184 | |||
185 | DEB2(printk("iic_init: Initialized IIC on ITE 0x%x\n", | ||
186 | iic_inw(adap, ITE_I2CHSR))); | ||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | |||
191 | /* | ||
192 | * Sanity check for the adapter hardware - check the reaction of | ||
193 | * the bus lines only if it seems to be idle. | ||
194 | */ | ||
195 | static int test_bus(struct i2c_algo_iic_data *adap, char *name) { | ||
196 | #if 0 | ||
197 | int scl,sda; | ||
198 | sda=getsda(adap); | ||
199 | if (adap->getscl==NULL) { | ||
200 | printk("test_bus: Warning: Adapter can't read from clock line - skipping test.\n"); | ||
201 | return 0; | ||
202 | } | ||
203 | scl=getscl(adap); | ||
204 | printk("test_bus: Adapter: %s scl: %d sda: %d -- testing...\n", | ||
205 | name,getscl(adap),getsda(adap)); | ||
206 | if (!scl || !sda ) { | ||
207 | printk("test_bus: %s seems to be busy.\n",adap->name); | ||
208 | goto bailout; | ||
209 | } | ||
210 | sdalo(adap); | ||
211 | printk("test_bus:1 scl: %d sda: %d\n", getscl(adap), | ||
212 | getsda(adap)); | ||
213 | if ( 0 != getsda(adap) ) { | ||
214 | printk("test_bus: %s SDA stuck high!\n",name); | ||
215 | sdahi(adap); | ||
216 | goto bailout; | ||
217 | } | ||
218 | if ( 0 == getscl(adap) ) { | ||
219 | printk("test_bus: %s SCL unexpected low while pulling SDA low!\n", | ||
220 | name); | ||
221 | goto bailout; | ||
222 | } | ||
223 | sdahi(adap); | ||
224 | printk("test_bus:2 scl: %d sda: %d\n", getscl(adap), | ||
225 | getsda(adap)); | ||
226 | if ( 0 == getsda(adap) ) { | ||
227 | printk("test_bus: %s SDA stuck low!\n",name); | ||
228 | sdahi(adap); | ||
229 | goto bailout; | ||
230 | } | ||
231 | if ( 0 == getscl(adap) ) { | ||
232 | printk("test_bus: %s SCL unexpected low while SDA high!\n", | ||
233 | adap->name); | ||
234 | goto bailout; | ||
235 | } | ||
236 | scllo(adap); | ||
237 | printk("test_bus:3 scl: %d sda: %d\n", getscl(adap), | ||
238 | getsda(adap)); | ||
239 | if ( 0 != getscl(adap) ) { | ||
240 | |||
241 | sclhi(adap); | ||
242 | goto bailout; | ||
243 | } | ||
244 | if ( 0 == getsda(adap) ) { | ||
245 | printk("test_bus: %s SDA unexpected low while pulling SCL low!\n", | ||
246 | name); | ||
247 | goto bailout; | ||
248 | } | ||
249 | sclhi(adap); | ||
250 | printk("test_bus:4 scl: %d sda: %d\n", getscl(adap), | ||
251 | getsda(adap)); | ||
252 | if ( 0 == getscl(adap) ) { | ||
253 | printk("test_bus: %s SCL stuck low!\n",name); | ||
254 | sclhi(adap); | ||
255 | goto bailout; | ||
256 | } | ||
257 | if ( 0 == getsda(adap) ) { | ||
258 | printk("test_bus: %s SDA unexpected low while SCL high!\n", | ||
259 | name); | ||
260 | goto bailout; | ||
261 | } | ||
262 | printk("test_bus: %s passed test.\n",name); | ||
263 | return 0; | ||
264 | bailout: | ||
265 | sdahi(adap); | ||
266 | sclhi(adap); | ||
267 | return -ENODEV; | ||
268 | #endif | ||
269 | return (0); | ||
270 | } | ||
271 | |||
272 | /* ----- Utility functions | ||
273 | */ | ||
274 | |||
275 | |||
276 | /* Verify the device we want to talk to on the IIC bus really exists. */ | ||
277 | static inline int try_address(struct i2c_algo_iic_data *adap, | ||
278 | unsigned int addr, int retries) | ||
279 | { | ||
280 | int i, ret = -1; | ||
281 | short status; | ||
282 | |||
283 | for (i=0;i<retries;i++) { | ||
284 | iic_outw(adap, ITE_I2CSAR, addr); | ||
285 | iic_start(adap); | ||
286 | if (wait_for_pin(adap, &status) == 0) { | ||
287 | if ((status & ITE_I2CHSR_DNE) == 0) { | ||
288 | iic_stop(adap); | ||
289 | iic_outw(adap, ITE_I2CFCR, ITE_I2CFCR_FLUSH); | ||
290 | ret=1; | ||
291 | break; /* success! */ | ||
292 | } | ||
293 | } | ||
294 | iic_stop(adap); | ||
295 | udelay(adap->udelay); | ||
296 | } | ||
297 | DEB2(if (i) printk("try_address: needed %d retries for 0x%x\n",i, | ||
298 | addr)); | ||
299 | return ret; | ||
300 | } | ||
301 | |||
302 | |||
303 | static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf, | ||
304 | int count) | ||
305 | { | ||
306 | struct i2c_algo_iic_data *adap = i2c_adap->algo_data; | ||
307 | int wrcount=0, timeout; | ||
308 | short status; | ||
309 | int loops, remainder, i, j; | ||
310 | union { | ||
311 | char byte[2]; | ||
312 | unsigned short word; | ||
313 | } tmp; | ||
314 | |||
315 | iic_outw(adap, ITE_I2CSSAR, (unsigned short)buf[wrcount++]); | ||
316 | count--; | ||
317 | if (count == 0) | ||
318 | return -EIO; | ||
319 | |||
320 | loops = count / 32; /* 32-byte FIFO */ | ||
321 | remainder = count % 32; | ||
322 | |||
323 | if(loops) { | ||
324 | for(i=0; i<loops; i++) { | ||
325 | |||
326 | iic_outw(adap, ITE_I2CFBCR, 32); | ||
327 | for(j=0; j<32/2; j++) { | ||
328 | tmp.byte[1] = buf[wrcount++]; | ||
329 | tmp.byte[0] = buf[wrcount++]; | ||
330 | iic_outw(adap, ITE_I2CFDR, tmp.word); | ||
331 | } | ||
332 | |||
333 | /* status FIFO overrun */ | ||
334 | iic_inw(adap, ITE_I2CFSR); | ||
335 | iic_inw(adap, ITE_I2CFBCR); | ||
336 | |||
337 | iic_outw(adap, ITE_I2CHCR, ITE_WRITE); /* Issue WRITE command */ | ||
338 | |||
339 | /* Wait for transmission to complete */ | ||
340 | timeout = wait_for_pin(adap, &status); | ||
341 | if(timeout) { | ||
342 | iic_stop(adap); | ||
343 | printk("iic_sendbytes: %s write timeout.\n", i2c_adap->name); | ||
344 | return -EREMOTEIO; /* got a better one ?? */ | ||
345 | } | ||
346 | if (status & ITE_I2CHSR_DB) { | ||
347 | iic_stop(adap); | ||
348 | printk("iic_sendbytes: %s write error - no ack.\n", i2c_adap->name); | ||
349 | return -EREMOTEIO; /* got a better one ?? */ | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | if(remainder) { | ||
354 | iic_outw(adap, ITE_I2CFBCR, remainder); | ||
355 | for(i=0; i<remainder/2; i++) { | ||
356 | tmp.byte[1] = buf[wrcount++]; | ||
357 | tmp.byte[0] = buf[wrcount++]; | ||
358 | iic_outw(adap, ITE_I2CFDR, tmp.word); | ||
359 | } | ||
360 | |||
361 | /* status FIFO overrun */ | ||
362 | iic_inw(adap, ITE_I2CFSR); | ||
363 | iic_inw(adap, ITE_I2CFBCR); | ||
364 | |||
365 | iic_outw(adap, ITE_I2CHCR, ITE_WRITE); /* Issue WRITE command */ | ||
366 | |||
367 | timeout = wait_for_pin(adap, &status); | ||
368 | if(timeout) { | ||
369 | iic_stop(adap); | ||
370 | printk("iic_sendbytes: %s write timeout.\n", i2c_adap->name); | ||
371 | return -EREMOTEIO; /* got a better one ?? */ | ||
372 | } | ||
373 | #ifndef STUB_I2C | ||
374 | if (status & ITE_I2CHSR_DB) { | ||
375 | iic_stop(adap); | ||
376 | printk("iic_sendbytes: %s write error - no ack.\n", i2c_adap->name); | ||
377 | return -EREMOTEIO; /* got a better one ?? */ | ||
378 | } | ||
379 | #endif | ||
380 | } | ||
381 | iic_stop(adap); | ||
382 | return wrcount; | ||
383 | } | ||
384 | |||
385 | |||
386 | static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count, | ||
387 | int sread) | ||
388 | { | ||
389 | int rdcount=0, i, timeout; | ||
390 | short status; | ||
391 | struct i2c_algo_iic_data *adap = i2c_adap->algo_data; | ||
392 | int loops, remainder, j; | ||
393 | union { | ||
394 | char byte[2]; | ||
395 | unsigned short word; | ||
396 | } tmp; | ||
397 | |||
398 | loops = count / 32; /* 32-byte FIFO */ | ||
399 | remainder = count % 32; | ||
400 | |||
401 | if(loops) { | ||
402 | for(i=0; i<loops; i++) { | ||
403 | iic_outw(adap, ITE_I2CFBCR, 32); | ||
404 | if (sread) | ||
405 | iic_outw(adap, ITE_I2CHCR, ITE_SREAD); | ||
406 | else | ||
407 | iic_outw(adap, ITE_I2CHCR, ITE_READ); /* Issue READ command */ | ||
408 | |||
409 | timeout = wait_for_pin(adap, &status); | ||
410 | if(timeout) { | ||
411 | iic_stop(adap); | ||
412 | printk("iic_readbytes: %s read timeout.\n", i2c_adap->name); | ||
413 | return (-1); | ||
414 | } | ||
415 | #ifndef STUB_I2C | ||
416 | if (status & ITE_I2CHSR_DB) { | ||
417 | iic_stop(adap); | ||
418 | printk("iic_readbytes: %s read error - no ack.\n", i2c_adap->name); | ||
419 | return (-1); | ||
420 | } | ||
421 | #endif | ||
422 | |||
423 | timeout = wait_for_fe(adap, &status); | ||
424 | if(timeout) { | ||
425 | iic_stop(adap); | ||
426 | printk("iic_readbytes: %s FIFO is empty\n", i2c_adap->name); | ||
427 | return (-1); | ||
428 | } | ||
429 | |||
430 | for(j=0; j<32/2; j++) { | ||
431 | tmp.word = iic_inw(adap, ITE_I2CFDR); | ||
432 | buf[rdcount++] = tmp.byte[1]; | ||
433 | buf[rdcount++] = tmp.byte[0]; | ||
434 | } | ||
435 | |||
436 | /* status FIFO underrun */ | ||
437 | iic_inw(adap, ITE_I2CFSR); | ||
438 | |||
439 | } | ||
440 | } | ||
441 | |||
442 | |||
443 | if(remainder) { | ||
444 | remainder=(remainder+1)/2 * 2; | ||
445 | iic_outw(adap, ITE_I2CFBCR, remainder); | ||
446 | if (sread) | ||
447 | iic_outw(adap, ITE_I2CHCR, ITE_SREAD); | ||
448 | else | ||
449 | iic_outw(adap, ITE_I2CHCR, ITE_READ); /* Issue READ command */ | ||
450 | |||
451 | timeout = wait_for_pin(adap, &status); | ||
452 | if(timeout) { | ||
453 | iic_stop(adap); | ||
454 | printk("iic_readbytes: %s read timeout.\n", i2c_adap->name); | ||
455 | return (-1); | ||
456 | } | ||
457 | #ifndef STUB_I2C | ||
458 | if (status & ITE_I2CHSR_DB) { | ||
459 | iic_stop(adap); | ||
460 | printk("iic_readbytes: %s read error - no ack.\n", i2c_adap->name); | ||
461 | return (-1); | ||
462 | } | ||
463 | #endif | ||
464 | timeout = wait_for_fe(adap, &status); | ||
465 | if(timeout) { | ||
466 | iic_stop(adap); | ||
467 | printk("iic_readbytes: %s FIFO is empty\n", i2c_adap->name); | ||
468 | return (-1); | ||
469 | } | ||
470 | |||
471 | for(i=0; i<(remainder+1)/2; i++) { | ||
472 | tmp.word = iic_inw(adap, ITE_I2CFDR); | ||
473 | buf[rdcount++] = tmp.byte[1]; | ||
474 | buf[rdcount++] = tmp.byte[0]; | ||
475 | } | ||
476 | |||
477 | /* status FIFO underrun */ | ||
478 | iic_inw(adap, ITE_I2CFSR); | ||
479 | |||
480 | } | ||
481 | |||
482 | iic_stop(adap); | ||
483 | return rdcount; | ||
484 | } | ||
485 | |||
486 | |||
487 | /* This function implements combined transactions. Combined | ||
488 | * transactions consist of combinations of reading and writing blocks of data. | ||
489 | * Each transfer (i.e. a read or a write) is separated by a repeated start | ||
490 | * condition. | ||
491 | */ | ||
492 | #if 0 | ||
493 | static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) | ||
494 | { | ||
495 | int i; | ||
496 | struct i2c_msg *pmsg; | ||
497 | int ret; | ||
498 | |||
499 | DEB2(printk("Beginning combined transaction\n")); | ||
500 | |||
501 | for(i=0; i<(num-1); i++) { | ||
502 | pmsg = &msgs[i]; | ||
503 | if(pmsg->flags & I2C_M_RD) { | ||
504 | DEB2(printk(" This one is a read\n")); | ||
505 | ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_COMBINED_XFER); | ||
506 | } | ||
507 | else if(!(pmsg->flags & I2C_M_RD)) { | ||
508 | DEB2(printk("This one is a write\n")); | ||
509 | ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_COMBINED_XFER); | ||
510 | } | ||
511 | } | ||
512 | /* Last read or write segment needs to be terminated with a stop */ | ||
513 | pmsg = &msgs[i]; | ||
514 | |||
515 | if(pmsg->flags & I2C_M_RD) { | ||
516 | DEB2(printk("Doing the last read\n")); | ||
517 | ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER); | ||
518 | } | ||
519 | else if(!(pmsg->flags & I2C_M_RD)) { | ||
520 | DEB2(printk("Doing the last write\n")); | ||
521 | ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER); | ||
522 | } | ||
523 | |||
524 | return ret; | ||
525 | } | ||
526 | #endif | ||
527 | |||
528 | |||
529 | /* Whenever we initiate a transaction, the first byte clocked | ||
530 | * onto the bus after the start condition is the address (7 bit) of the | ||
531 | * device we want to talk to. This function manipulates the address specified | ||
532 | * so that it makes sense to the hardware when written to the IIC peripheral. | ||
533 | * | ||
534 | * Note: 10 bit addresses are not supported in this driver, although they are | ||
535 | * supported by the hardware. This functionality needs to be implemented. | ||
536 | */ | ||
537 | static inline int iic_doAddress(struct i2c_algo_iic_data *adap, | ||
538 | struct i2c_msg *msg, int retries) | ||
539 | { | ||
540 | unsigned short flags = msg->flags; | ||
541 | unsigned int addr; | ||
542 | int ret; | ||
543 | |||
544 | /* Ten bit addresses not supported right now */ | ||
545 | if ( (flags & I2C_M_TEN) ) { | ||
546 | #if 0 | ||
547 | addr = 0xf0 | (( msg->addr >> 7) & 0x03); | ||
548 | DEB2(printk("addr0: %d\n",addr)); | ||
549 | ret = try_address(adap, addr, retries); | ||
550 | if (ret!=1) { | ||
551 | printk("iic_doAddress: died at extended address code.\n"); | ||
552 | return -EREMOTEIO; | ||
553 | } | ||
554 | iic_outw(adap,msg->addr & 0x7f); | ||
555 | if (ret != 1) { | ||
556 | printk("iic_doAddress: died at 2nd address code.\n"); | ||
557 | return -EREMOTEIO; | ||
558 | } | ||
559 | if ( flags & I2C_M_RD ) { | ||
560 | i2c_repstart(adap); | ||
561 | addr |= 0x01; | ||
562 | ret = try_address(adap, addr, retries); | ||
563 | if (ret!=1) { | ||
564 | printk("iic_doAddress: died at extended address code.\n"); | ||
565 | return -EREMOTEIO; | ||
566 | } | ||
567 | } | ||
568 | #endif | ||
569 | } else { | ||
570 | |||
571 | addr = ( msg->addr << 1 ); | ||
572 | |||
573 | #if 0 | ||
574 | if (flags & I2C_M_RD ) | ||
575 | addr |= 1; | ||
576 | if (flags & I2C_M_REV_DIR_ADDR ) | ||
577 | addr ^= 1; | ||
578 | #endif | ||
579 | |||
580 | if (iic_inw(adap, ITE_I2CSAR) != addr) { | ||
581 | iic_outw(adap, ITE_I2CSAR, addr); | ||
582 | ret = try_address(adap, addr, retries); | ||
583 | if (ret!=1) { | ||
584 | printk("iic_doAddress: died at address code.\n"); | ||
585 | return -EREMOTEIO; | ||
586 | } | ||
587 | } | ||
588 | |||
589 | } | ||
590 | |||
591 | return 0; | ||
592 | } | ||
593 | |||
594 | |||
595 | /* Description: Prepares the controller for a transaction (clearing status | ||
596 | * registers, data buffers, etc), and then calls either iic_readbytes or | ||
597 | * iic_sendbytes to do the actual transaction. | ||
598 | * | ||
599 | * still to be done: Before we issue a transaction, we should | ||
600 | * verify that the bus is not busy or in some unknown state. | ||
601 | */ | ||
602 | static int iic_xfer(struct i2c_adapter *i2c_adap, | ||
603 | struct i2c_msg *msgs, | ||
604 | int num) | ||
605 | { | ||
606 | struct i2c_algo_iic_data *adap = i2c_adap->algo_data; | ||
607 | struct i2c_msg *pmsg; | ||
608 | int i = 0; | ||
609 | int ret, timeout; | ||
610 | |||
611 | pmsg = &msgs[i]; | ||
612 | |||
613 | if(!pmsg->len) { | ||
614 | DEB2(printk("iic_xfer: read/write length is 0\n");) | ||
615 | return -EIO; | ||
616 | } | ||
617 | if(!(pmsg->flags & I2C_M_RD) && (!(pmsg->len)%2) ) { | ||
618 | DEB2(printk("iic_xfer: write buffer length is not odd\n");) | ||
619 | return -EIO; | ||
620 | } | ||
621 | |||
622 | /* Wait for any pending transfers to complete */ | ||
623 | timeout = wait_for_bb(adap); | ||
624 | if (timeout) { | ||
625 | DEB2(printk("iic_xfer: Timeout waiting for host not busy\n");) | ||
626 | return -EIO; | ||
627 | } | ||
628 | |||
629 | /* Flush FIFO */ | ||
630 | iic_outw(adap, ITE_I2CFCR, ITE_I2CFCR_FLUSH); | ||
631 | |||
632 | /* Load address */ | ||
633 | ret = iic_doAddress(adap, pmsg, i2c_adap->retries); | ||
634 | if (ret) | ||
635 | return -EIO; | ||
636 | |||
637 | #if 0 | ||
638 | /* Combined transaction (read and write) */ | ||
639 | if(num > 1) { | ||
640 | DEB2(printk("iic_xfer: Call combined transaction\n")); | ||
641 | ret = iic_combined_transaction(i2c_adap, msgs, num); | ||
642 | } | ||
643 | #endif | ||
644 | |||
645 | DEB3(printk("iic_xfer: Msg %d, addr=0x%x, flags=0x%x, len=%d\n", | ||
646 | i, msgs[i].addr, msgs[i].flags, msgs[i].len);) | ||
647 | |||
648 | if(pmsg->flags & I2C_M_RD) /* Read */ | ||
649 | ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, 0); | ||
650 | else { /* Write */ | ||
651 | udelay(1000); | ||
652 | ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len); | ||
653 | } | ||
654 | |||
655 | if (ret != pmsg->len) | ||
656 | DEB3(printk("iic_xfer: error or fail on read/write %d bytes.\n",ret)); | ||
657 | else | ||
658 | DEB3(printk("iic_xfer: read/write %d bytes.\n",ret)); | ||
659 | |||
660 | return ret; | ||
661 | } | ||
662 | |||
663 | |||
664 | /* Implements device specific ioctls. Higher level ioctls can | ||
665 | * be found in i2c-core.c and are typical of any i2c controller (specifying | ||
666 | * slave address, timeouts, etc). These ioctls take advantage of any hardware | ||
667 | * features built into the controller for which this algorithm-adapter set | ||
668 | * was written. These ioctls allow you to take control of the data and clock | ||
669 | * lines and set the either high or low, | ||
670 | * similar to a GPIO pin. | ||
671 | */ | ||
672 | static int algo_control(struct i2c_adapter *adapter, | ||
673 | unsigned int cmd, unsigned long arg) | ||
674 | { | ||
675 | |||
676 | struct i2c_algo_iic_data *adap = adapter->algo_data; | ||
677 | struct i2c_iic_msg s_msg; | ||
678 | char *buf; | ||
679 | int ret; | ||
680 | |||
681 | if (cmd == I2C_SREAD) { | ||
682 | if(copy_from_user(&s_msg, (struct i2c_iic_msg *)arg, | ||
683 | sizeof(struct i2c_iic_msg))) | ||
684 | return -EFAULT; | ||
685 | buf = kmalloc(s_msg.len, GFP_KERNEL); | ||
686 | if (buf== NULL) | ||
687 | return -ENOMEM; | ||
688 | |||
689 | /* Flush FIFO */ | ||
690 | iic_outw(adap, ITE_I2CFCR, ITE_I2CFCR_FLUSH); | ||
691 | |||
692 | /* Load address */ | ||
693 | iic_outw(adap, ITE_I2CSAR,s_msg.addr<<1); | ||
694 | iic_outw(adap, ITE_I2CSSAR,s_msg.waddr & 0xff); | ||
695 | |||
696 | ret = iic_readbytes(adapter, buf, s_msg.len, 1); | ||
697 | if (ret>=0) { | ||
698 | if(copy_to_user( s_msg.buf, buf, s_msg.len) ) | ||
699 | ret = -EFAULT; | ||
700 | } | ||
701 | kfree(buf); | ||
702 | } | ||
703 | return 0; | ||
704 | } | ||
705 | |||
706 | |||
707 | static u32 iic_func(struct i2c_adapter *adap) | ||
708 | { | ||
709 | return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | | ||
710 | I2C_FUNC_PROTOCOL_MANGLING; | ||
711 | } | ||
712 | |||
713 | /* -----exported algorithm data: ------------------------------------- */ | ||
714 | |||
715 | static struct i2c_algorithm iic_algo = { | ||
716 | .master_xfer = iic_xfer, | ||
717 | .algo_control = algo_control, /* ioctl */ | ||
718 | .functionality = iic_func, | ||
719 | }; | ||
720 | |||
721 | |||
722 | /* | ||
723 | * registering functions to load algorithms at runtime | ||
724 | */ | ||
725 | int i2c_iic_add_bus(struct i2c_adapter *adap) | ||
726 | { | ||
727 | struct i2c_algo_iic_data *iic_adap = adap->algo_data; | ||
728 | |||
729 | if (iic_test) { | ||
730 | int ret = test_bus(iic_adap, adap->name); | ||
731 | if (ret<0) | ||
732 | return -ENODEV; | ||
733 | } | ||
734 | |||
735 | DEB2(printk("i2c-algo-ite: hw routines for %s registered.\n", | ||
736 | adap->name)); | ||
737 | |||
738 | /* register new adapter to i2c module... */ | ||
739 | adap->algo = &iic_algo; | ||
740 | |||
741 | adap->timeout = 100; /* default values, should */ | ||
742 | adap->retries = 3; /* be replaced by defines */ | ||
743 | adap->flags = 0; | ||
744 | |||
745 | iic_init(iic_adap); | ||
746 | return i2c_add_adapter(adap); | ||
747 | } | ||
748 | |||
749 | |||
750 | int i2c_iic_del_bus(struct i2c_adapter *adap) | ||
751 | { | ||
752 | int res; | ||
753 | if ((res = i2c_del_adapter(adap)) < 0) | ||
754 | return res; | ||
755 | DEB2(printk("i2c-algo-ite: adapter unregistered: %s\n",adap->name)); | ||
756 | |||
757 | return 0; | ||
758 | } | ||
759 | |||
760 | |||
761 | int __init i2c_algo_iic_init (void) | ||
762 | { | ||
763 | printk(KERN_INFO "ITE iic (i2c) algorithm module\n"); | ||
764 | return 0; | ||
765 | } | ||
766 | |||
767 | |||
768 | void i2c_algo_iic_exit(void) | ||
769 | { | ||
770 | return; | ||
771 | } | ||
772 | |||
773 | |||
774 | EXPORT_SYMBOL(i2c_iic_add_bus); | ||
775 | EXPORT_SYMBOL(i2c_iic_del_bus); | ||
776 | |||
777 | /* The MODULE_* macros resolve to nothing if MODULES is not defined | ||
778 | * when this file is compiled. | ||
779 | */ | ||
780 | MODULE_AUTHOR("MontaVista Software <www.mvista.com>"); | ||
781 | MODULE_DESCRIPTION("ITE iic algorithm"); | ||
782 | MODULE_LICENSE("GPL"); | ||
783 | |||
784 | module_param(iic_test, bool, 0); | ||
785 | module_param(i2c_debug, int, S_IRUGO | S_IWUSR); | ||
786 | |||
787 | MODULE_PARM_DESC(iic_test, "Test if the I2C bus is available"); | ||
788 | MODULE_PARM_DESC(i2c_debug, | ||
789 | "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol"); | ||
790 | |||
791 | |||
792 | /* This function resolves to init_module (the function invoked when a module | ||
793 | * is loaded via insmod) when this file is compiled with MODULES defined. | ||
794 | * Otherwise (i.e. if you want this driver statically linked to the kernel), | ||
795 | * a pointer to this function is stored in a table and called | ||
796 | * during the initialization of the kernel (in do_basic_setup in /init/main.c) | ||
797 | * | ||
798 | * All this functionality is complements of the macros defined in linux/init.h | ||
799 | */ | ||
800 | module_init(i2c_algo_iic_init); | ||
801 | |||
802 | |||
803 | /* If MODULES is defined when this file is compiled, then this function will | ||
804 | * resolved to cleanup_module. | ||
805 | */ | ||
806 | module_exit(i2c_algo_iic_exit); | ||
diff --git a/drivers/i2c/algos/i2c-algo-ite.h b/drivers/i2c/algos/i2c-algo-ite.h deleted file mode 100644 index a8ca3c9b546a..000000000000 --- a/drivers/i2c/algos/i2c-algo-ite.h +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
1 | /* | ||
2 | -------------------------------------------------------------------- | ||
3 | i2c-ite.h: Global defines for the I2C controller on board the | ||
4 | ITE MIPS processor. | ||
5 | -------------------------------------------------------------------- | ||
6 | Hai-Pao Fan, MontaVista Software, Inc. | ||
7 | hpfan@mvista.com or source@mvista.com | ||
8 | |||
9 | Copyright 2001 MontaVista Software Inc. | ||
10 | |||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License as published by the | ||
13 | * Free Software Foundation; either version 2 of the License, or (at your | ||
14 | * option) any later version. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | ||
19 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
22 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
23 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | * You should have received a copy of the GNU General Public License along | ||
28 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
29 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
30 | |||
31 | */ | ||
32 | |||
33 | #ifndef I2C_ITE_H | ||
34 | #define I2C_ITE_H 1 | ||
35 | |||
36 | #include <asm/it8172/it8172.h> | ||
37 | |||
38 | /* I2C Registers */ | ||
39 | #define ITE_I2CHCR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x30 | ||
40 | #define ITE_I2CHSR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x34 | ||
41 | #define ITE_I2CSAR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x38 | ||
42 | #define ITE_I2CSSAR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x3c | ||
43 | #define ITE_I2CCKCNT IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x48 | ||
44 | #define ITE_I2CSHDR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x4c | ||
45 | #define ITE_I2CRSUR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x50 | ||
46 | #define ITE_I2CPSUR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x54 | ||
47 | |||
48 | #define ITE_I2CFDR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x70 | ||
49 | #define ITE_I2CFBCR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x74 | ||
50 | #define ITE_I2CFCR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x78 | ||
51 | #define ITE_I2CFSR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x7c | ||
52 | |||
53 | |||
54 | /* Host Control Register ITE_I2CHCR */ | ||
55 | #define ITE_I2CHCR_HCE 0x01 /* Enable I2C Host Controller */ | ||
56 | #define ITE_I2CHCR_IE 0x02 /* Enable the interrupt after completing | ||
57 | the current transaction */ | ||
58 | #define ITE_I2CHCR_CP_W 0x00 /* bit2-4 000 - Write */ | ||
59 | #define ITE_I2CHCR_CP_R 0x08 /* 010 - Current address read */ | ||
60 | #define ITE_I2CHCR_CP_S 0x10 /* 100 - Sequential read */ | ||
61 | #define ITE_I2CHCR_ST 0x20 /* Initiates the I2C host controller to execute | ||
62 | the command and send the data programmed in | ||
63 | all required registers to I2C bus */ | ||
64 | #define ITE_CMD ITE_I2CHCR_HCE | ITE_I2CHCR_IE | ITE_I2CHCR_ST | ||
65 | #define ITE_WRITE ITE_CMD | ITE_I2CHCR_CP_W | ||
66 | #define ITE_READ ITE_CMD | ITE_I2CHCR_CP_R | ||
67 | #define ITE_SREAD ITE_CMD | ITE_I2CHCR_CP_S | ||
68 | |||
69 | /* Host Status Register ITE_I2CHSR */ | ||
70 | #define ITE_I2CHSR_DB 0x01 /* Device is busy, receives NACK response except | ||
71 | in the first and last bytes */ | ||
72 | #define ITE_I2CHSR_DNE 0x02 /* Target address on I2C bus does not exist */ | ||
73 | #define ITE_I2CHSR_TDI 0x04 /* R/W Transaction on I2C bus was completed */ | ||
74 | #define ITE_I2CHSR_HB 0x08 /* Host controller is processing transactions */ | ||
75 | #define ITE_I2CHSR_FER 0x10 /* Error occurs in the FIFO */ | ||
76 | |||
77 | /* Slave Address Register ITE_I2CSAR */ | ||
78 | #define ITE_I2CSAR_SA_MASK 0xfe /* Target I2C device address */ | ||
79 | #define ITE_I2CSAR_ASO 0x0100 /* Output 1/0 to I2CAS port when the | ||
80 | next slave address is addressed */ | ||
81 | |||
82 | /* Slave Sub-address Register ITE_I2CSSAR */ | ||
83 | #define ITE_I2CSSAR_SUBA_MASK 0xff /* Target I2C device sub-address */ | ||
84 | |||
85 | /* Clock Counter Register ITE_I2CCKCNT */ | ||
86 | #define ITE_I2CCKCNT_STOP 0x00 /* stop I2C clock */ | ||
87 | #define ITE_I2CCKCNT_HPCC_MASK 0x7f /* SCL high period counter */ | ||
88 | #define ITE_I2CCKCNT_LPCC_MASK 0x7f00 /* SCL low period counter */ | ||
89 | |||
90 | /* START Hold Time Register ITE_I2CSHDR */ | ||
91 | /* value is counted based on 16 MHz internal clock */ | ||
92 | #define ITE_I2CSHDR_FM 0x0a /* START condition at fast mode */ | ||
93 | #define ITE_I2CSHDR_SM 0x47 /* START contition at standard mode */ | ||
94 | |||
95 | /* (Repeated) START Setup Time Register ITE_I2CRSUR */ | ||
96 | /* value is counted based on 16 MHz internal clock */ | ||
97 | #define ITE_I2CRSUR_FM 0x0a /* repeated START condition at fast mode */ | ||
98 | #define ITE_I2CRSUR_SM 0x50 /* repeated START condition at standard mode */ | ||
99 | |||
100 | /* STOP setup Time Register ITE_I2CPSUR */ | ||
101 | |||
102 | /* FIFO Data Register ITE_I2CFDR */ | ||
103 | #define ITE_I2CFDR_MASK 0xff | ||
104 | |||
105 | /* FIFO Byte Count Register ITE_I2CFBCR */ | ||
106 | #define ITE_I2CFBCR_MASK 0x3f | ||
107 | |||
108 | /* FIFO Control Register ITE_I2CFCR */ | ||
109 | #define ITE_I2CFCR_FLUSH 0x01 /* Flush FIFO and reset the FIFO point | ||
110 | and I2CFSR */ | ||
111 | /* FIFO Status Register ITE_I2CFSR */ | ||
112 | #define ITE_I2CFSR_FO 0x01 /* FIFO is overrun when write */ | ||
113 | #define ITE_I2CFSR_FU 0x02 /* FIFO is underrun when read */ | ||
114 | #define ITE_I2CFSR_FF 0x04 /* FIFO is full when write */ | ||
115 | #define ITE_I2CFSR_FE 0x08 /* FIFO is empty when read */ | ||
116 | |||
117 | #endif /* I2C_ITE_H */ | ||
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c index 9081c9fbcd29..36fdf971f080 100644 --- a/drivers/i2c/algos/i2c-algo-pca.c +++ b/drivers/i2c/algos/i2c-algo-pca.c | |||
@@ -381,14 +381,7 @@ int i2c_pca_add_bus(struct i2c_adapter *adap) | |||
381 | 381 | ||
382 | return rval; | 382 | return rval; |
383 | } | 383 | } |
384 | |||
385 | int i2c_pca_del_bus(struct i2c_adapter *adap) | ||
386 | { | ||
387 | return i2c_del_adapter(adap); | ||
388 | } | ||
389 | |||
390 | EXPORT_SYMBOL(i2c_pca_add_bus); | 384 | EXPORT_SYMBOL(i2c_pca_add_bus); |
391 | EXPORT_SYMBOL(i2c_pca_del_bus); | ||
392 | 385 | ||
393 | MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); | 386 | MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); |
394 | MODULE_DESCRIPTION("I2C-Bus PCA9564 algorithm"); | 387 | MODULE_DESCRIPTION("I2C-Bus PCA9564 algorithm"); |
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c index 3b2003398966..ecb2c2d7d540 100644 --- a/drivers/i2c/algos/i2c-algo-pcf.c +++ b/drivers/i2c/algos/i2c-algo-pcf.c | |||
@@ -486,15 +486,7 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap) | |||
486 | 486 | ||
487 | return rval; | 487 | return rval; |
488 | } | 488 | } |
489 | |||
490 | |||
491 | int i2c_pcf_del_bus(struct i2c_adapter *adap) | ||
492 | { | ||
493 | return i2c_del_adapter(adap); | ||
494 | } | ||
495 | |||
496 | EXPORT_SYMBOL(i2c_pcf_add_bus); | 489 | EXPORT_SYMBOL(i2c_pcf_add_bus); |
497 | EXPORT_SYMBOL(i2c_pcf_del_bus); | ||
498 | 490 | ||
499 | MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); | 491 | MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); |
500 | MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm"); | 492 | MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm"); |
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c index 490d99997fd0..ac2d5053078a 100644 --- a/drivers/i2c/algos/i2c-algo-sgi.c +++ b/drivers/i2c/algos/i2c-algo-sgi.c | |||
@@ -171,15 +171,7 @@ int i2c_sgi_add_bus(struct i2c_adapter *adap) | |||
171 | 171 | ||
172 | return i2c_add_adapter(adap); | 172 | return i2c_add_adapter(adap); |
173 | } | 173 | } |
174 | |||
175 | |||
176 | int i2c_sgi_del_bus(struct i2c_adapter *adap) | ||
177 | { | ||
178 | return i2c_del_adapter(adap); | ||
179 | } | ||
180 | |||
181 | EXPORT_SYMBOL(i2c_sgi_add_bus); | 174 | EXPORT_SYMBOL(i2c_sgi_add_bus); |
182 | EXPORT_SYMBOL(i2c_sgi_del_bus); | ||
183 | 175 | ||
184 | MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>"); | 176 | MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>"); |
185 | MODULE_DESCRIPTION("I2C-Bus SGI algorithm"); | 177 | MODULE_DESCRIPTION("I2C-Bus SGI algorithm"); |
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 510816c16da3..9367c4cfe936 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -74,6 +74,13 @@ config I2C_AMD8111 | |||
74 | This driver can also be built as a module. If so, the module | 74 | This driver can also be built as a module. If so, the module |
75 | will be called i2c-amd8111. | 75 | will be called i2c-amd8111. |
76 | 76 | ||
77 | config I2C_AT91 | ||
78 | tristate "Atmel AT91 I2C Two-Wire interface (TWI)" | ||
79 | depends on I2C && ARCH_AT91 && EXPERIMENTAL | ||
80 | help | ||
81 | This supports the use of the I2C interface on Atmel AT91 | ||
82 | processors. | ||
83 | |||
77 | config I2C_AU1550 | 84 | config I2C_AU1550 |
78 | tristate "Au1550/Au1200 SMBus interface" | 85 | tristate "Au1550/Au1200 SMBus interface" |
79 | depends on I2C && (SOC_AU1550 || SOC_AU1200) | 86 | depends on I2C && (SOC_AU1550 || SOC_AU1200) |
@@ -125,6 +132,7 @@ config I2C_I801 | |||
125 | ICH7 | 132 | ICH7 |
126 | ESB2 | 133 | ESB2 |
127 | ICH8 | 134 | ICH8 |
135 | ICH9 | ||
128 | 136 | ||
129 | This driver can also be built as a module. If so, the module | 137 | This driver can also be built as a module. If so, the module |
130 | will be called i2c-i801. | 138 | will be called i2c-i801. |
@@ -195,11 +203,11 @@ config I2C_IBM_IIC | |||
195 | will be called i2c-ibm_iic. | 203 | will be called i2c-ibm_iic. |
196 | 204 | ||
197 | config I2C_IOP3XX | 205 | config I2C_IOP3XX |
198 | tristate "Intel IOP3xx and IXP4xx on-chip I2C interface" | 206 | tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" |
199 | depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX) && I2C | 207 | depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX) && I2C |
200 | help | 208 | help |
201 | Say Y here if you want to use the IIC bus controller on | 209 | Say Y here if you want to use the IIC bus controller on |
202 | the Intel IOP3xx I/O Processors or IXP4xx Network Processors. | 210 | the Intel IOPx3xx I/O Processors or IXP4xx Network Processors. |
203 | 211 | ||
204 | This driver can also be built as a module. If so, the module | 212 | This driver can also be built as a module. If so, the module |
205 | will be called i2c-iop3xx. | 213 | will be called i2c-iop3xx. |
@@ -208,18 +216,6 @@ config I2C_ISA | |||
208 | tristate | 216 | tristate |
209 | depends on I2C | 217 | depends on I2C |
210 | 218 | ||
211 | config I2C_ITE | ||
212 | tristate "ITE I2C Adapter" | ||
213 | depends on I2C && MIPS_ITE8172 | ||
214 | select I2C_ALGOITE | ||
215 | help | ||
216 | This supports the ITE8172 I2C peripheral found on some MIPS | ||
217 | systems. Say Y if you have one of these. You should also say Y for | ||
218 | the ITE I2C driver algorithm support above. | ||
219 | |||
220 | This support is also available as a module. If so, the module | ||
221 | will be called i2c-ite. | ||
222 | |||
223 | config I2C_IXP4XX | 219 | config I2C_IXP4XX |
224 | tristate "IXP4xx GPIO-Based I2C Interface" | 220 | tristate "IXP4xx GPIO-Based I2C Interface" |
225 | depends on I2C && ARCH_IXP4XX | 221 | depends on I2C && ARCH_IXP4XX |
@@ -480,6 +476,17 @@ config I2C_STUB | |||
480 | 476 | ||
481 | If you don't know what to do here, definitely say N. | 477 | If you don't know what to do here, definitely say N. |
482 | 478 | ||
479 | config I2C_VERSATILE | ||
480 | tristate "ARM Versatile/Realview I2C bus support" | ||
481 | depends on I2C && (ARCH_VERSATILE || ARCH_REALVIEW) | ||
482 | select I2C_ALGOBIT | ||
483 | help | ||
484 | Say yes if you want to support the I2C serial bus on ARMs Versatile | ||
485 | range of platforms. | ||
486 | |||
487 | This driver can also be built as a module. If so, the module | ||
488 | will be called i2c-versatile. | ||
489 | |||
483 | config I2C_VIA | 490 | config I2C_VIA |
484 | tristate "VIA 82C586B" | 491 | tristate "VIA 82C586B" |
485 | depends on I2C && PCI && EXPERIMENTAL | 492 | depends on I2C && PCI && EXPERIMENTAL |
@@ -547,4 +554,14 @@ config I2C_MV64XXX | |||
547 | This driver can also be built as a module. If so, the module | 554 | This driver can also be built as a module. If so, the module |
548 | will be called i2c-mv64xxx. | 555 | will be called i2c-mv64xxx. |
549 | 556 | ||
557 | config I2C_PNX | ||
558 | tristate "I2C bus support for Philips PNX targets" | ||
559 | depends on ARCH_PNX4008 && I2C | ||
560 | help | ||
561 | This driver supports the Philips IP3204 I2C IP block master and/or | ||
562 | slave controller | ||
563 | |||
564 | This driver can also be built as a module. If so, the module | ||
565 | will be called i2c-pnx. | ||
566 | |||
550 | endmenu | 567 | endmenu |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 493c87289b62..37196c1d0794 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
@@ -8,6 +8,7 @@ obj-$(CONFIG_I2C_ALI15X3) += i2c-ali15x3.o | |||
8 | obj-$(CONFIG_I2C_AMD756) += i2c-amd756.o | 8 | obj-$(CONFIG_I2C_AMD756) += i2c-amd756.o |
9 | obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o | 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_AU1550) += i2c-au1550.o | 12 | obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o |
12 | obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o | 13 | obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o |
13 | obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o | 14 | obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o |
@@ -16,7 +17,6 @@ obj-$(CONFIG_I2C_I810) += i2c-i810.o | |||
16 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o | 17 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o |
17 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o | 18 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o |
18 | obj-$(CONFIG_I2C_ISA) += i2c-isa.o | 19 | obj-$(CONFIG_I2C_ISA) += i2c-isa.o |
19 | obj-$(CONFIG_I2C_ITE) += i2c-ite.o | ||
20 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o | 20 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o |
21 | obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o | 21 | obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o |
22 | obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o | 22 | obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o |
@@ -29,6 +29,7 @@ obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o | |||
29 | obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o | 29 | obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o |
30 | obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o | 30 | obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o |
31 | obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o | 31 | obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o |
32 | obj-$(CONFIG_I2C_PNX) += i2c-pnx.o | ||
32 | obj-$(CONFIG_I2C_PROSAVAGE) += i2c-prosavage.o | 33 | obj-$(CONFIG_I2C_PROSAVAGE) += i2c-prosavage.o |
33 | obj-$(CONFIG_I2C_PXA) += i2c-pxa.o | 34 | obj-$(CONFIG_I2C_PXA) += i2c-pxa.o |
34 | obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o | 35 | obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o |
@@ -39,6 +40,7 @@ obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o | |||
39 | obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o | 40 | obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o |
40 | obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o | 41 | obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o |
41 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o | 42 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o |
43 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o | ||
42 | obj-$(CONFIG_I2C_VIA) += i2c-via.o | 44 | obj-$(CONFIG_I2C_VIA) += i2c-via.o |
43 | obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o | 45 | obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o |
44 | obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o | 46 | obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o |
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c index 33fbb47100a3..8e1e3f8e40a4 100644 --- a/drivers/i2c/busses/i2c-ali1563.c +++ b/drivers/i2c/busses/i2c-ali1563.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * i2c-ali1563.c - i2c driver for the ALi 1563 Southbridge | 2 | * i2c-ali1563.c - i2c driver for the ALi 1563 Southbridge |
3 | * | 3 | * |
4 | * Copyright (C) 2004 Patrick Mochel | 4 | * Copyright (C) 2004 Patrick Mochel |
5 | * 2005 Rudolf Marek <r.marek@sh.cvut.cz> | 5 | * 2005 Rudolf Marek <r.marek@assembler.cz> |
6 | * | 6 | * |
7 | * The 1563 southbridge is deceptively similar to the 1533, with a | 7 | * The 1563 southbridge is deceptively similar to the 1533, with a |
8 | * few notable exceptions. One of those happens to be the fact they | 8 | * few notable exceptions. One of those happens to be the fact they |
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c new file mode 100644 index 000000000000..67f91bdda089 --- /dev/null +++ b/drivers/i2c/busses/i2c-at91.c | |||
@@ -0,0 +1,325 @@ | |||
1 | /* | ||
2 | i2c Support for Atmel's AT91 Two-Wire Interface (TWI) | ||
3 | |||
4 | Copyright (C) 2004 Rick Bronson | ||
5 | Converted to 2.6 by Andrew Victor <andrew@sanpeople.com> | ||
6 | |||
7 | Borrowed heavily from original work by: | ||
8 | Copyright (C) 2000 Philip Edelbrock <phil@stimpy.netroedge.com> | ||
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 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/version.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/pci.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/clk.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | |||
28 | #include <asm/io.h> | ||
29 | |||
30 | #include <asm/arch/at91_twi.h> | ||
31 | #include <asm/arch/board.h> | ||
32 | #include <asm/arch/cpu.h> | ||
33 | |||
34 | #define TWI_CLOCK 100000 /* Hz. max 400 Kbits/sec */ | ||
35 | |||
36 | |||
37 | static struct clk *twi_clk; | ||
38 | static void __iomem *twi_base; | ||
39 | |||
40 | #define at91_twi_read(reg) __raw_readl(twi_base + (reg)) | ||
41 | #define at91_twi_write(reg, val) __raw_writel((val), twi_base + (reg)) | ||
42 | |||
43 | |||
44 | /* | ||
45 | * Initialize the TWI hardware registers. | ||
46 | */ | ||
47 | static void __devinit at91_twi_hwinit(void) | ||
48 | { | ||
49 | unsigned long cdiv, ckdiv; | ||
50 | |||
51 | at91_twi_write(AT91_TWI_IDR, 0xffffffff); /* Disable all interrupts */ | ||
52 | at91_twi_write(AT91_TWI_CR, AT91_TWI_SWRST); /* Reset peripheral */ | ||
53 | at91_twi_write(AT91_TWI_CR, AT91_TWI_MSEN); /* Set Master mode */ | ||
54 | |||
55 | /* Calcuate clock dividers */ | ||
56 | cdiv = (clk_get_rate(twi_clk) / (2 * TWI_CLOCK)) - 3; | ||
57 | cdiv = cdiv + 1; /* round up */ | ||
58 | ckdiv = 0; | ||
59 | while (cdiv > 255) { | ||
60 | ckdiv++; | ||
61 | cdiv = cdiv >> 1; | ||
62 | } | ||
63 | |||
64 | if (cpu_is_at91rm9200()) { /* AT91RM9200 Errata #22 */ | ||
65 | if (ckdiv > 5) { | ||
66 | printk(KERN_ERR "AT91 I2C: Invalid TWI_CLOCK value!\n"); | ||
67 | ckdiv = 5; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | at91_twi_write(AT91_TWI_CWGR, (ckdiv << 16) | (cdiv << 8) | cdiv); | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | * Poll the i2c status register until the specified bit is set. | ||
76 | * Returns 0 if timed out (100 msec). | ||
77 | */ | ||
78 | static short at91_poll_status(unsigned long bit) | ||
79 | { | ||
80 | int loop_cntr = 10000; | ||
81 | |||
82 | do { | ||
83 | udelay(10); | ||
84 | } while (!(at91_twi_read(AT91_TWI_SR) & bit) && (--loop_cntr > 0)); | ||
85 | |||
86 | return (loop_cntr > 0); | ||
87 | } | ||
88 | |||
89 | static int xfer_read(struct i2c_adapter *adap, unsigned char *buf, int length) | ||
90 | { | ||
91 | /* Send Start */ | ||
92 | at91_twi_write(AT91_TWI_CR, AT91_TWI_START); | ||
93 | |||
94 | /* Read data */ | ||
95 | while (length--) { | ||
96 | if (!length) /* need to send Stop before reading last byte */ | ||
97 | at91_twi_write(AT91_TWI_CR, AT91_TWI_STOP); | ||
98 | if (!at91_poll_status(AT91_TWI_RXRDY)) { | ||
99 | dev_dbg(&adap->dev, "RXRDY timeout\n"); | ||
100 | return -ETIMEDOUT; | ||
101 | } | ||
102 | *buf++ = (at91_twi_read(AT91_TWI_RHR) & 0xff); | ||
103 | } | ||
104 | |||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | static int xfer_write(struct i2c_adapter *adap, unsigned char *buf, int length) | ||
109 | { | ||
110 | /* Load first byte into transmitter */ | ||
111 | at91_twi_write(AT91_TWI_THR, *buf++); | ||
112 | |||
113 | /* Send Start */ | ||
114 | at91_twi_write(AT91_TWI_CR, AT91_TWI_START); | ||
115 | |||
116 | do { | ||
117 | if (!at91_poll_status(AT91_TWI_TXRDY)) { | ||
118 | dev_dbg(&adap->dev, "TXRDY timeout\n"); | ||
119 | return -ETIMEDOUT; | ||
120 | } | ||
121 | |||
122 | length--; /* byte was transmitted */ | ||
123 | |||
124 | if (length > 0) /* more data to send? */ | ||
125 | at91_twi_write(AT91_TWI_THR, *buf++); | ||
126 | } while (length); | ||
127 | |||
128 | /* Send Stop */ | ||
129 | at91_twi_write(AT91_TWI_CR, AT91_TWI_STOP); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * Generic i2c master transfer entrypoint. | ||
136 | * | ||
137 | * Note: We do not use Atmel's feature of storing the "internal device address". | ||
138 | * Instead the "internal device address" has to be written using a seperate | ||
139 | * i2c message. | ||
140 | * http://lists.arm.linux.org.uk/pipermail/linux-arm-kernel/2004-September/024411.html | ||
141 | */ | ||
142 | static int at91_xfer(struct i2c_adapter *adap, struct i2c_msg *pmsg, int num) | ||
143 | { | ||
144 | int i, ret; | ||
145 | |||
146 | dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num); | ||
147 | |||
148 | for (i = 0; i < num; i++) { | ||
149 | dev_dbg(&adap->dev, " #%d: %sing %d byte%s %s 0x%02x\n", i, | ||
150 | pmsg->flags & I2C_M_RD ? "read" : "writ", | ||
151 | pmsg->len, pmsg->len > 1 ? "s" : "", | ||
152 | pmsg->flags & I2C_M_RD ? "from" : "to", pmsg->addr); | ||
153 | |||
154 | at91_twi_write(AT91_TWI_MMR, (pmsg->addr << 16) | ||
155 | | ((pmsg->flags & I2C_M_RD) ? AT91_TWI_MREAD : 0)); | ||
156 | |||
157 | if (pmsg->len && pmsg->buf) { /* sanity check */ | ||
158 | if (pmsg->flags & I2C_M_RD) | ||
159 | ret = xfer_read(adap, pmsg->buf, pmsg->len); | ||
160 | else | ||
161 | ret = xfer_write(adap, pmsg->buf, pmsg->len); | ||
162 | |||
163 | if (ret) | ||
164 | return ret; | ||
165 | |||
166 | /* Wait until transfer is finished */ | ||
167 | if (!at91_poll_status(AT91_TWI_TXCOMP)) { | ||
168 | dev_dbg(&adap->dev, "TXCOMP timeout\n"); | ||
169 | return -ETIMEDOUT; | ||
170 | } | ||
171 | } | ||
172 | dev_dbg(&adap->dev, "transfer complete\n"); | ||
173 | pmsg++; /* next message */ | ||
174 | } | ||
175 | return i; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * Return list of supported functionality. | ||
180 | */ | ||
181 | static u32 at91_func(struct i2c_adapter *adapter) | ||
182 | { | ||
183 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | ||
184 | } | ||
185 | |||
186 | static struct i2c_algorithm at91_algorithm = { | ||
187 | .master_xfer = at91_xfer, | ||
188 | .functionality = at91_func, | ||
189 | }; | ||
190 | |||
191 | /* | ||
192 | * Main initialization routine. | ||
193 | */ | ||
194 | static int __devinit at91_i2c_probe(struct platform_device *pdev) | ||
195 | { | ||
196 | struct i2c_adapter *adapter; | ||
197 | struct resource *res; | ||
198 | int rc; | ||
199 | |||
200 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
201 | if (!res) | ||
202 | return -ENXIO; | ||
203 | |||
204 | if (!request_mem_region(res->start, res->end - res->start + 1, "at91_i2c")) | ||
205 | return -EBUSY; | ||
206 | |||
207 | twi_base = ioremap(res->start, res->end - res->start + 1); | ||
208 | if (!twi_base) { | ||
209 | rc = -ENOMEM; | ||
210 | goto fail0; | ||
211 | } | ||
212 | |||
213 | twi_clk = clk_get(NULL, "twi_clk"); | ||
214 | if (IS_ERR(twi_clk)) { | ||
215 | dev_err(&pdev->dev, "no clock defined\n"); | ||
216 | rc = -ENODEV; | ||
217 | goto fail1; | ||
218 | } | ||
219 | |||
220 | adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL); | ||
221 | if (adapter == NULL) { | ||
222 | dev_err(&pdev->dev, "can't allocate inteface!\n"); | ||
223 | rc = -ENOMEM; | ||
224 | goto fail2; | ||
225 | } | ||
226 | sprintf(adapter->name, "AT91"); | ||
227 | adapter->algo = &at91_algorithm; | ||
228 | adapter->class = I2C_CLASS_HWMON; | ||
229 | adapter->dev.parent = &pdev->dev; | ||
230 | |||
231 | platform_set_drvdata(pdev, adapter); | ||
232 | |||
233 | clk_enable(twi_clk); /* enable peripheral clock */ | ||
234 | at91_twi_hwinit(); /* initialize TWI controller */ | ||
235 | |||
236 | rc = i2c_add_adapter(adapter); | ||
237 | if (rc) { | ||
238 | dev_err(&pdev->dev, "Adapter %s registration failed\n", | ||
239 | adapter->name); | ||
240 | goto fail3; | ||
241 | } | ||
242 | |||
243 | dev_info(&pdev->dev, "AT91 i2c bus driver.\n"); | ||
244 | return 0; | ||
245 | |||
246 | fail3: | ||
247 | platform_set_drvdata(pdev, NULL); | ||
248 | kfree(adapter); | ||
249 | clk_disable(twi_clk); | ||
250 | fail2: | ||
251 | clk_put(twi_clk); | ||
252 | fail1: | ||
253 | iounmap(twi_base); | ||
254 | fail0: | ||
255 | release_mem_region(res->start, res->end - res->start + 1); | ||
256 | |||
257 | return rc; | ||
258 | } | ||
259 | |||
260 | static int __devexit at91_i2c_remove(struct platform_device *pdev) | ||
261 | { | ||
262 | struct i2c_adapter *adapter = platform_get_drvdata(pdev); | ||
263 | struct resource *res; | ||
264 | int rc; | ||
265 | |||
266 | rc = i2c_del_adapter(adapter); | ||
267 | platform_set_drvdata(pdev, NULL); | ||
268 | |||
269 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
270 | iounmap(twi_base); | ||
271 | release_mem_region(res->start, res->end - res->start + 1); | ||
272 | |||
273 | clk_disable(twi_clk); /* disable peripheral clock */ | ||
274 | clk_put(twi_clk); | ||
275 | |||
276 | return rc; | ||
277 | } | ||
278 | |||
279 | #ifdef CONFIG_PM | ||
280 | |||
281 | /* NOTE: could save a few mA by keeping clock off outside of at91_xfer... */ | ||
282 | |||
283 | static int at91_i2c_suspend(struct platform_device *pdev, pm_message_t mesg) | ||
284 | { | ||
285 | clk_disable(twi_clk); | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int at91_i2c_resume(struct platform_device *pdev) | ||
290 | { | ||
291 | return clk_enable(twi_clk); | ||
292 | } | ||
293 | |||
294 | #else | ||
295 | #define at91_i2c_suspend NULL | ||
296 | #define at91_i2c_resume NULL | ||
297 | #endif | ||
298 | |||
299 | static struct platform_driver at91_i2c_driver = { | ||
300 | .probe = at91_i2c_probe, | ||
301 | .remove = __devexit_p(at91_i2c_remove), | ||
302 | .suspend = at91_i2c_suspend, | ||
303 | .resume = at91_i2c_resume, | ||
304 | .driver = { | ||
305 | .name = "at91_i2c", | ||
306 | .owner = THIS_MODULE, | ||
307 | }, | ||
308 | }; | ||
309 | |||
310 | static int __init at91_i2c_init(void) | ||
311 | { | ||
312 | return platform_driver_register(&at91_i2c_driver); | ||
313 | } | ||
314 | |||
315 | static void __exit at91_i2c_exit(void) | ||
316 | { | ||
317 | platform_driver_unregister(&at91_i2c_driver); | ||
318 | } | ||
319 | |||
320 | module_init(at91_i2c_init); | ||
321 | module_exit(at91_i2c_exit); | ||
322 | |||
323 | MODULE_AUTHOR("Rick Bronson"); | ||
324 | MODULE_DESCRIPTION("I2C (TWI) driver for Atmel AT91"); | ||
325 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c index a591fe685f06..834967464814 100644 --- a/drivers/i2c/busses/i2c-elektor.c +++ b/drivers/i2c/busses/i2c-elektor.c | |||
@@ -293,7 +293,7 @@ static int __init i2c_pcfisa_init(void) | |||
293 | 293 | ||
294 | static void i2c_pcfisa_exit(void) | 294 | static void i2c_pcfisa_exit(void) |
295 | { | 295 | { |
296 | i2c_pcf_del_bus(&pcf_isa_ops); | 296 | i2c_del_adapter(&pcf_isa_ops); |
297 | 297 | ||
298 | if (irq > 0) { | 298 | if (irq > 0) { |
299 | disable_irq(irq); | 299 | disable_irq(irq); |
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c index 457d48a0ab9d..9832f773651d 100644 --- a/drivers/i2c/busses/i2c-hydra.c +++ b/drivers/i2c/busses/i2c-hydra.c | |||
@@ -146,7 +146,7 @@ static int __devinit hydra_probe(struct pci_dev *dev, | |||
146 | static void __devexit hydra_remove(struct pci_dev *dev) | 146 | static void __devexit hydra_remove(struct pci_dev *dev) |
147 | { | 147 | { |
148 | pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */ | 148 | pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */ |
149 | i2c_bit_del_bus(&hydra_adap); | 149 | i2c_del_adapter(&hydra_adap); |
150 | iounmap(hydra_bit_data.data); | 150 | iounmap(hydra_bit_data.data); |
151 | release_mem_region(pci_resource_start(dev, 0)+ | 151 | release_mem_region(pci_resource_start(dev, 0)+ |
152 | offsetof(struct Hydra, CachePD), 4); | 152 | offsetof(struct Hydra, CachePD), 4); |
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index bbb2fbee836f..ae625b854470 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c | |||
@@ -33,6 +33,7 @@ | |||
33 | ICH7 27DA | 33 | ICH7 27DA |
34 | ESB2 269B | 34 | ESB2 269B |
35 | ICH8 283E | 35 | ICH8 283E |
36 | ICH9 2930 | ||
36 | This driver supports several versions of Intel's I/O Controller Hubs (ICH). | 37 | This driver supports several versions of Intel's I/O Controller Hubs (ICH). |
37 | For SMBus support, they are similar to the PIIX4 and are part | 38 | For SMBus support, they are similar to the PIIX4 and are part |
38 | of Intel's '810' and other chipsets. | 39 | of Intel's '810' and other chipsets. |
@@ -457,6 +458,7 @@ static struct pci_device_id i801_ids[] = { | |||
457 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) }, | 458 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) }, |
458 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) }, | 459 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) }, |
459 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) }, | 460 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) }, |
461 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) }, | ||
460 | { 0, } | 462 | { 0, } |
461 | }; | 463 | }; |
462 | 464 | ||
@@ -468,12 +470,20 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id | |||
468 | int err; | 470 | int err; |
469 | 471 | ||
470 | I801_dev = dev; | 472 | I801_dev = dev; |
471 | if ((dev->device == PCI_DEVICE_ID_INTEL_82801DB_3) || | 473 | switch (dev->device) { |
472 | (dev->device == PCI_DEVICE_ID_INTEL_82801EB_3) || | 474 | case PCI_DEVICE_ID_INTEL_82801DB_3: |
473 | (dev->device == PCI_DEVICE_ID_INTEL_ESB_4)) | 475 | case PCI_DEVICE_ID_INTEL_82801EB_3: |
476 | case PCI_DEVICE_ID_INTEL_ESB_4: | ||
477 | case PCI_DEVICE_ID_INTEL_ICH6_16: | ||
478 | case PCI_DEVICE_ID_INTEL_ICH7_17: | ||
479 | case PCI_DEVICE_ID_INTEL_ESB2_17: | ||
480 | case PCI_DEVICE_ID_INTEL_ICH8_5: | ||
481 | case PCI_DEVICE_ID_INTEL_ICH9_6: | ||
474 | isich4 = 1; | 482 | isich4 = 1; |
475 | else | 483 | break; |
484 | default: | ||
476 | isich4 = 0; | 485 | isich4 = 0; |
486 | } | ||
477 | 487 | ||
478 | err = pci_enable_device(dev); | 488 | err = pci_enable_device(dev); |
479 | if (err) { | 489 | if (err) { |
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c index b66fb6bb1870..10c98bc88aa6 100644 --- a/drivers/i2c/busses/i2c-i810.c +++ b/drivers/i2c/busses/i2c-i810.c | |||
@@ -219,14 +219,14 @@ static int __devinit i810_probe(struct pci_dev *dev, const struct pci_device_id | |||
219 | return retval; | 219 | return retval; |
220 | retval = i2c_bit_add_bus(&i810_ddc_adapter); | 220 | retval = i2c_bit_add_bus(&i810_ddc_adapter); |
221 | if (retval) | 221 | if (retval) |
222 | i2c_bit_del_bus(&i810_i2c_adapter); | 222 | i2c_del_adapter(&i810_i2c_adapter); |
223 | return retval; | 223 | return retval; |
224 | } | 224 | } |
225 | 225 | ||
226 | static void __devexit i810_remove(struct pci_dev *dev) | 226 | static void __devexit i810_remove(struct pci_dev *dev) |
227 | { | 227 | { |
228 | i2c_bit_del_bus(&i810_ddc_adapter); | 228 | i2c_del_adapter(&i810_ddc_adapter); |
229 | i2c_bit_del_bus(&i810_i2c_adapter); | 229 | i2c_del_adapter(&i810_i2c_adapter); |
230 | iounmap(ioaddr); | 230 | iounmap(ioaddr); |
231 | } | 231 | } |
232 | 232 | ||
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c index 781a99c1647a..1898e9987021 100644 --- a/drivers/i2c/busses/i2c-ibm_iic.c +++ b/drivers/i2c/busses/i2c-ibm_iic.c | |||
@@ -680,6 +680,12 @@ static int __devinit iic_probe(struct ocp_device *ocp){ | |||
680 | dev->idx = ocp->def->index; | 680 | dev->idx = ocp->def->index; |
681 | ocp_set_drvdata(ocp, dev); | 681 | ocp_set_drvdata(ocp, dev); |
682 | 682 | ||
683 | if (!request_mem_region(ocp->def->paddr, sizeof(struct iic_regs), | ||
684 | "ibm_iic")) { | ||
685 | ret = -EBUSY; | ||
686 | goto fail1; | ||
687 | } | ||
688 | |||
683 | if (!(dev->vaddr = ioremap(ocp->def->paddr, sizeof(struct iic_regs)))){ | 689 | if (!(dev->vaddr = ioremap(ocp->def->paddr, sizeof(struct iic_regs)))){ |
684 | printk(KERN_CRIT "ibm-iic%d: failed to ioremap device registers\n", | 690 | printk(KERN_CRIT "ibm-iic%d: failed to ioremap device registers\n", |
685 | dev->idx); | 691 | dev->idx); |
@@ -750,6 +756,8 @@ fail: | |||
750 | 756 | ||
751 | iounmap(dev->vaddr); | 757 | iounmap(dev->vaddr); |
752 | fail2: | 758 | fail2: |
759 | release_mem_region(ocp->def->paddr, sizeof(struct iic_regs)); | ||
760 | fail1: | ||
753 | ocp_set_drvdata(ocp, NULL); | 761 | ocp_set_drvdata(ocp, NULL); |
754 | kfree(dev); | 762 | kfree(dev); |
755 | return ret; | 763 | return ret; |
@@ -777,6 +785,7 @@ static void __devexit iic_remove(struct ocp_device *ocp) | |||
777 | free_irq(dev->irq, dev); | 785 | free_irq(dev->irq, dev); |
778 | } | 786 | } |
779 | iounmap(dev->vaddr); | 787 | iounmap(dev->vaddr); |
788 | release_mem_region(ocp->def->paddr, sizeof(struct iic_regs)); | ||
780 | kfree(dev); | 789 | kfree(dev); |
781 | } | 790 | } |
782 | } | 791 | } |
diff --git a/drivers/i2c/busses/i2c-ite.c b/drivers/i2c/busses/i2c-ite.c deleted file mode 100644 index f7d71869b3b9..000000000000 --- a/drivers/i2c/busses/i2c-ite.c +++ /dev/null | |||
@@ -1,278 +0,0 @@ | |||
1 | /* | ||
2 | ------------------------------------------------------------------------- | ||
3 | i2c-adap-ite.c i2c-hw access for the IIC peripheral on the ITE MIPS system | ||
4 | ------------------------------------------------------------------------- | ||
5 | Hai-Pao Fan, MontaVista Software, Inc. | ||
6 | hpfan@mvista.com or source@mvista.com | ||
7 | |||
8 | Copyright 2001 MontaVista Software Inc. | ||
9 | |||
10 | ---------------------------------------------------------------------------- | ||
11 | This file was highly leveraged from i2c-elektor.c, which was created | ||
12 | by Simon G. Vogl and Hans Berglund: | ||
13 | |||
14 | |||
15 | Copyright (C) 1995-97 Simon G. Vogl | ||
16 | 1998-99 Hans Berglund | ||
17 | |||
18 | This program is free software; you can redistribute it and/or modify | ||
19 | it under the terms of the GNU General Public License as published by | ||
20 | the Free Software Foundation; either version 2 of the License, or | ||
21 | (at your option) any later version. | ||
22 | |||
23 | This program is distributed in the hope that it will be useful, | ||
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
26 | GNU General Public License for more details. | ||
27 | |||
28 | You should have received a copy of the GNU General Public License | ||
29 | along with this program; if not, write to the Free Software | ||
30 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
31 | /* ------------------------------------------------------------------------- */ | ||
32 | |||
33 | /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even | ||
34 | Frodo Looijaard <frodol@dds.nl> */ | ||
35 | |||
36 | #include <linux/kernel.h> | ||
37 | #include <linux/ioport.h> | ||
38 | #include <linux/module.h> | ||
39 | #include <linux/delay.h> | ||
40 | #include <linux/slab.h> | ||
41 | #include <linux/init.h> | ||
42 | #include <linux/wait.h> | ||
43 | #include <asm/irq.h> | ||
44 | #include <asm/io.h> | ||
45 | |||
46 | #include <linux/i2c.h> | ||
47 | #include <linux/i2c-algo-ite.h> | ||
48 | #include <linux/i2c-adap-ite.h> | ||
49 | #include "../i2c-ite.h" | ||
50 | |||
51 | #define DEFAULT_BASE 0x14014030 | ||
52 | #define ITE_IIC_IO_SIZE 0x40 | ||
53 | #define DEFAULT_IRQ 0 | ||
54 | #define DEFAULT_CLOCK 0x1b0e /* default 16MHz/(27+14) = 400KHz */ | ||
55 | #define DEFAULT_OWN 0x55 | ||
56 | |||
57 | static int base; | ||
58 | static int irq; | ||
59 | static int clock; | ||
60 | static int own; | ||
61 | |||
62 | static struct iic_ite gpi; | ||
63 | static wait_queue_head_t iic_wait; | ||
64 | static int iic_pending; | ||
65 | static spinlock_t lock; | ||
66 | |||
67 | /* ----- local functions ---------------------------------------------- */ | ||
68 | |||
69 | static void iic_ite_setiic(void *data, int ctl, short val) | ||
70 | { | ||
71 | unsigned long j = jiffies + 10; | ||
72 | |||
73 | pr_debug(" Write 0x%02x to 0x%x\n",(unsigned short)val, ctl&0xff); | ||
74 | #ifdef DEBUG | ||
75 | while (time_before(jiffies, j)) | ||
76 | schedule(); | ||
77 | #endif | ||
78 | outw(val,ctl); | ||
79 | } | ||
80 | |||
81 | static short iic_ite_getiic(void *data, int ctl) | ||
82 | { | ||
83 | short val; | ||
84 | |||
85 | val = inw(ctl); | ||
86 | pr_debug("Read 0x%02x from 0x%x\n",(unsigned short)val, ctl&0xff); | ||
87 | return (val); | ||
88 | } | ||
89 | |||
90 | /* Return our slave address. This is the address | ||
91 | * put on the I2C bus when another master on the bus wants to address us | ||
92 | * as a slave | ||
93 | */ | ||
94 | static int iic_ite_getown(void *data) | ||
95 | { | ||
96 | return (gpi.iic_own); | ||
97 | } | ||
98 | |||
99 | |||
100 | static int iic_ite_getclock(void *data) | ||
101 | { | ||
102 | return (gpi.iic_clock); | ||
103 | } | ||
104 | |||
105 | |||
106 | /* Put this process to sleep. We will wake up when the | ||
107 | * IIC controller interrupts. | ||
108 | */ | ||
109 | static void iic_ite_waitforpin(void) { | ||
110 | DEFINE_WAIT(wait); | ||
111 | int timeout = 2; | ||
112 | unsigned long flags; | ||
113 | |||
114 | /* If interrupts are enabled (which they are), then put the process to | ||
115 | * sleep. This process will be awakened by two events -- either the | ||
116 | * the IIC peripheral interrupts or the timeout expires. | ||
117 | * If interrupts are not enabled then delay for a reasonable amount | ||
118 | * of time and return. | ||
119 | */ | ||
120 | if (gpi.iic_irq > 0) { | ||
121 | spin_lock_irqsave(&lock, flags); | ||
122 | if (iic_pending == 0) { | ||
123 | spin_unlock_irqrestore(&lock, flags); | ||
124 | prepare_to_wait(&iic_wait, &wait, TASK_INTERRUPTIBLE); | ||
125 | if (schedule_timeout(timeout*HZ)) { | ||
126 | spin_lock_irqsave(&lock, flags); | ||
127 | if (iic_pending == 1) { | ||
128 | iic_pending = 0; | ||
129 | } | ||
130 | spin_unlock_irqrestore(&lock, flags); | ||
131 | } | ||
132 | finish_wait(&iic_wait, &wait); | ||
133 | } else { | ||
134 | iic_pending = 0; | ||
135 | spin_unlock_irqrestore(&lock, flags); | ||
136 | } | ||
137 | } else { | ||
138 | udelay(100); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | |||
143 | static irqreturn_t iic_ite_handler(int this_irq, void *dev_id) | ||
144 | { | ||
145 | spin_lock(&lock); | ||
146 | iic_pending = 1; | ||
147 | spin_unlock(&lock); | ||
148 | |||
149 | wake_up_interruptible(&iic_wait); | ||
150 | |||
151 | return IRQ_HANDLED; | ||
152 | } | ||
153 | |||
154 | |||
155 | /* Lock the region of memory where I/O registers exist. Request our | ||
156 | * interrupt line and register its associated handler. | ||
157 | */ | ||
158 | static int iic_hw_resrc_init(void) | ||
159 | { | ||
160 | if (!request_region(gpi.iic_base, ITE_IIC_IO_SIZE, "i2c")) | ||
161 | return -ENODEV; | ||
162 | |||
163 | if (gpi.iic_irq <= 0) | ||
164 | return 0; | ||
165 | |||
166 | if (request_irq(gpi.iic_irq, iic_ite_handler, 0, "ITE IIC", 0) < 0) | ||
167 | gpi.iic_irq = 0; | ||
168 | else | ||
169 | enable_irq(gpi.iic_irq); | ||
170 | |||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | |||
175 | static void iic_ite_release(void) | ||
176 | { | ||
177 | if (gpi.iic_irq > 0) { | ||
178 | disable_irq(gpi.iic_irq); | ||
179 | free_irq(gpi.iic_irq, 0); | ||
180 | } | ||
181 | release_region(gpi.iic_base , 2); | ||
182 | } | ||
183 | |||
184 | /* ------------------------------------------------------------------------ | ||
185 | * Encapsulate the above functions in the correct operations structure. | ||
186 | * This is only done when more than one hardware adapter is supported. | ||
187 | */ | ||
188 | static struct i2c_algo_iic_data iic_ite_data = { | ||
189 | NULL, | ||
190 | iic_ite_setiic, | ||
191 | iic_ite_getiic, | ||
192 | iic_ite_getown, | ||
193 | iic_ite_getclock, | ||
194 | iic_ite_waitforpin, | ||
195 | 80, 80, 100, /* waits, timeout */ | ||
196 | }; | ||
197 | |||
198 | static struct i2c_adapter iic_ite_ops = { | ||
199 | .owner = THIS_MODULE, | ||
200 | .id = I2C_HW_I_IIC, | ||
201 | .algo_data = &iic_ite_data, | ||
202 | .name = "ITE IIC adapter", | ||
203 | }; | ||
204 | |||
205 | /* Called when the module is loaded. This function starts the | ||
206 | * cascade of calls up through the hierarchy of i2c modules (i.e. up to the | ||
207 | * algorithm layer and into to the core layer) | ||
208 | */ | ||
209 | static int __init iic_ite_init(void) | ||
210 | { | ||
211 | |||
212 | struct iic_ite *piic = &gpi; | ||
213 | |||
214 | printk(KERN_INFO "Initialize ITE IIC adapter module\n"); | ||
215 | if (base == 0) | ||
216 | piic->iic_base = DEFAULT_BASE; | ||
217 | else | ||
218 | piic->iic_base = base; | ||
219 | |||
220 | if (irq == 0) | ||
221 | piic->iic_irq = DEFAULT_IRQ; | ||
222 | else | ||
223 | piic->iic_irq = irq; | ||
224 | |||
225 | if (clock == 0) | ||
226 | piic->iic_clock = DEFAULT_CLOCK; | ||
227 | else | ||
228 | piic->iic_clock = clock; | ||
229 | |||
230 | if (own == 0) | ||
231 | piic->iic_own = DEFAULT_OWN; | ||
232 | else | ||
233 | piic->iic_own = own; | ||
234 | |||
235 | iic_ite_data.data = (void *)piic; | ||
236 | init_waitqueue_head(&iic_wait); | ||
237 | spin_lock_init(&lock); | ||
238 | if (iic_hw_resrc_init() == 0) { | ||
239 | if (i2c_iic_add_bus(&iic_ite_ops) < 0) | ||
240 | return -ENODEV; | ||
241 | } else { | ||
242 | return -ENODEV; | ||
243 | } | ||
244 | printk(KERN_INFO " found device at %#x irq %d.\n", | ||
245 | piic->iic_base, piic->iic_irq); | ||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | |||
250 | static void iic_ite_exit(void) | ||
251 | { | ||
252 | i2c_iic_del_bus(&iic_ite_ops); | ||
253 | iic_ite_release(); | ||
254 | } | ||
255 | |||
256 | /* If modules is NOT defined when this file is compiled, then the MODULE_* | ||
257 | * macros will resolve to nothing | ||
258 | */ | ||
259 | MODULE_AUTHOR("MontaVista Software <www.mvista.com>"); | ||
260 | MODULE_DESCRIPTION("I2C-Bus adapter routines for ITE IIC bus adapter"); | ||
261 | MODULE_LICENSE("GPL"); | ||
262 | |||
263 | module_param(base, int, 0); | ||
264 | module_param(irq, int, 0); | ||
265 | module_param(clock, int, 0); | ||
266 | module_param(own, int, 0); | ||
267 | |||
268 | |||
269 | /* Called when module is loaded or when kernel is initialized. | ||
270 | * If MODULES is defined when this file is compiled, then this function will | ||
271 | * resolve to init_module (the function called when insmod is invoked for a | ||
272 | * module). Otherwise, this function is called early in the boot, when the | ||
273 | * kernel is intialized. Check out /include/init.h to see how this works. | ||
274 | */ | ||
275 | module_init(iic_ite_init); | ||
276 | |||
277 | /* Resolves to module_cleanup when MODULES is defined. */ | ||
278 | module_exit(iic_ite_exit); | ||
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c index dd3f4cd3aa68..efa3ecc5522a 100644 --- a/drivers/i2c/busses/i2c-ixp2000.c +++ b/drivers/i2c/busses/i2c-ixp2000.c | |||
@@ -90,7 +90,7 @@ static int ixp2000_i2c_remove(struct platform_device *plat_dev) | |||
90 | 90 | ||
91 | platform_set_drvdata(plat_dev, NULL); | 91 | platform_set_drvdata(plat_dev, NULL); |
92 | 92 | ||
93 | i2c_bit_del_bus(&drv_data->adapter); | 93 | i2c_del_adapter(&drv_data->adapter); |
94 | 94 | ||
95 | kfree(drv_data); | 95 | kfree(drv_data); |
96 | 96 | ||
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c index 68fe863f9d54..08e89b83984a 100644 --- a/drivers/i2c/busses/i2c-ixp4xx.c +++ b/drivers/i2c/busses/i2c-ixp4xx.c | |||
@@ -91,7 +91,7 @@ static int ixp4xx_i2c_remove(struct platform_device *plat_dev) | |||
91 | 91 | ||
92 | platform_set_drvdata(plat_dev, NULL); | 92 | platform_set_drvdata(plat_dev, NULL); |
93 | 93 | ||
94 | i2c_bit_del_bus(&drv_data->adapter); | 94 | i2c_del_adapter(&drv_data->adapter); |
95 | 95 | ||
96 | kfree(drv_data); | 96 | kfree(drv_data); |
97 | 97 | ||
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index bbc8e3a7ff55..490173611d6b 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c | |||
@@ -529,6 +529,8 @@ mv64xxx_i2c_probe(struct platform_device *pd) | |||
529 | platform_set_drvdata(pd, drv_data); | 529 | platform_set_drvdata(pd, drv_data); |
530 | i2c_set_adapdata(&drv_data->adapter, drv_data); | 530 | i2c_set_adapdata(&drv_data->adapter, drv_data); |
531 | 531 | ||
532 | mv64xxx_i2c_hw_init(drv_data); | ||
533 | |||
532 | if (request_irq(drv_data->irq, mv64xxx_i2c_intr, 0, | 534 | if (request_irq(drv_data->irq, mv64xxx_i2c_intr, 0, |
533 | MV64XXX_I2C_CTLR_NAME, drv_data)) { | 535 | MV64XXX_I2C_CTLR_NAME, drv_data)) { |
534 | dev_err(&drv_data->adapter.dev, | 536 | dev_err(&drv_data->adapter.dev, |
@@ -542,8 +544,6 @@ mv64xxx_i2c_probe(struct platform_device *pd) | |||
542 | goto exit_free_irq; | 544 | goto exit_free_irq; |
543 | } | 545 | } |
544 | 546 | ||
545 | mv64xxx_i2c_hw_init(drv_data); | ||
546 | |||
547 | return 0; | 547 | return 0; |
548 | 548 | ||
549 | exit_free_irq: | 549 | exit_free_irq: |
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c index e0292e414ab2..ad37c10e7fec 100644 --- a/drivers/i2c/busses/i2c-nforce2.c +++ b/drivers/i2c/busses/i2c-nforce2.c | |||
@@ -35,7 +35,7 @@ | |||
35 | nForce4 MCP55 0368 | 35 | nForce4 MCP55 0368 |
36 | 36 | ||
37 | This driver supports the 2 SMBuses that are included in the MCP of the | 37 | This driver supports the 2 SMBuses that are included in the MCP of the |
38 | nForce2/3/4 chipsets. | 38 | nForce2/3/4/5xx chipsets. |
39 | */ | 39 | */ |
40 | 40 | ||
41 | /* Note: we assume there can only be one nForce2, with two SMBus interfaces */ | 41 | /* Note: we assume there can only be one nForce2, with two SMBus interfaces */ |
@@ -52,8 +52,8 @@ | |||
52 | #include <asm/io.h> | 52 | #include <asm/io.h> |
53 | 53 | ||
54 | MODULE_LICENSE("GPL"); | 54 | MODULE_LICENSE("GPL"); |
55 | MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@arcor.de>"); | 55 | MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@gmx.net>"); |
56 | MODULE_DESCRIPTION("nForce2 SMBus driver"); | 56 | MODULE_DESCRIPTION("nForce2/3/4/5xx SMBus driver"); |
57 | 57 | ||
58 | 58 | ||
59 | struct nforce2_smbus { | 59 | struct nforce2_smbus { |
@@ -80,9 +80,6 @@ struct nforce2_smbus { | |||
80 | #define NVIDIA_SMB_ADDR (smbus->base + 0x02) /* address */ | 80 | #define NVIDIA_SMB_ADDR (smbus->base + 0x02) /* address */ |
81 | #define NVIDIA_SMB_CMD (smbus->base + 0x03) /* command */ | 81 | #define NVIDIA_SMB_CMD (smbus->base + 0x03) /* command */ |
82 | #define NVIDIA_SMB_DATA (smbus->base + 0x04) /* 32 data registers */ | 82 | #define NVIDIA_SMB_DATA (smbus->base + 0x04) /* 32 data registers */ |
83 | #define NVIDIA_SMB_BCNT (smbus->base + 0x24) /* number of data bytes */ | ||
84 | #define NVIDIA_SMB_ALRM_A (smbus->base + 0x25) /* alarm address */ | ||
85 | #define NVIDIA_SMB_ALRM_D (smbus->base + 0x26) /* 2 bytes alarm data */ | ||
86 | 83 | ||
87 | #define NVIDIA_SMB_STS_DONE 0x80 | 84 | #define NVIDIA_SMB_STS_DONE 0x80 |
88 | #define NVIDIA_SMB_STS_ALRM 0x40 | 85 | #define NVIDIA_SMB_STS_ALRM 0x40 |
@@ -95,40 +92,17 @@ struct nforce2_smbus { | |||
95 | #define NVIDIA_SMB_PRTCL_BYTE 0x04 | 92 | #define NVIDIA_SMB_PRTCL_BYTE 0x04 |
96 | #define NVIDIA_SMB_PRTCL_BYTE_DATA 0x06 | 93 | #define NVIDIA_SMB_PRTCL_BYTE_DATA 0x06 |
97 | #define NVIDIA_SMB_PRTCL_WORD_DATA 0x08 | 94 | #define NVIDIA_SMB_PRTCL_WORD_DATA 0x08 |
98 | #define NVIDIA_SMB_PRTCL_BLOCK_DATA 0x0a | ||
99 | #define NVIDIA_SMB_PRTCL_PROC_CALL 0x0c | ||
100 | #define NVIDIA_SMB_PRTCL_BLOCK_PROC_CALL 0x0d | ||
101 | #define NVIDIA_SMB_PRTCL_I2C_BLOCK_DATA 0x4a | ||
102 | #define NVIDIA_SMB_PRTCL_PEC 0x80 | 95 | #define NVIDIA_SMB_PRTCL_PEC 0x80 |
103 | 96 | ||
104 | static struct pci_driver nforce2_driver; | 97 | static struct pci_driver nforce2_driver; |
105 | 98 | ||
106 | static s32 nforce2_access(struct i2c_adapter *adap, u16 addr, | 99 | /* Return -1 on error */ |
107 | unsigned short flags, char read_write, | ||
108 | u8 command, int size, union i2c_smbus_data *data); | ||
109 | static u32 nforce2_func(struct i2c_adapter *adapter); | ||
110 | |||
111 | |||
112 | static const struct i2c_algorithm smbus_algorithm = { | ||
113 | .smbus_xfer = nforce2_access, | ||
114 | .functionality = nforce2_func, | ||
115 | }; | ||
116 | |||
117 | static struct i2c_adapter nforce2_adapter = { | ||
118 | .owner = THIS_MODULE, | ||
119 | .class = I2C_CLASS_HWMON, | ||
120 | .algo = &smbus_algorithm, | ||
121 | }; | ||
122 | |||
123 | /* Return -1 on error. See smbus.h for more information */ | ||
124 | static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, | 100 | static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, |
125 | unsigned short flags, char read_write, | 101 | unsigned short flags, char read_write, |
126 | u8 command, int size, union i2c_smbus_data * data) | 102 | u8 command, int size, union i2c_smbus_data * data) |
127 | { | 103 | { |
128 | struct nforce2_smbus *smbus = adap->algo_data; | 104 | struct nforce2_smbus *smbus = adap->algo_data; |
129 | unsigned char protocol, pec, temp; | 105 | unsigned char protocol, pec, temp; |
130 | unsigned char len = 0; /* to keep the compiler quiet */ | ||
131 | int i; | ||
132 | 106 | ||
133 | protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : | 107 | protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : |
134 | NVIDIA_SMB_PRTCL_WRITE; | 108 | NVIDIA_SMB_PRTCL_WRITE; |
@@ -163,35 +137,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, | |||
163 | protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec; | 137 | protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec; |
164 | break; | 138 | break; |
165 | 139 | ||
166 | case I2C_SMBUS_BLOCK_DATA: | ||
167 | outb_p(command, NVIDIA_SMB_CMD); | ||
168 | if (read_write == I2C_SMBUS_WRITE) { | ||
169 | len = min_t(u8, data->block[0], 32); | ||
170 | outb_p(len, NVIDIA_SMB_BCNT); | ||
171 | for (i = 0; i < len; i++) | ||
172 | outb_p(data->block[i + 1], NVIDIA_SMB_DATA+i); | ||
173 | } | ||
174 | protocol |= NVIDIA_SMB_PRTCL_BLOCK_DATA | pec; | ||
175 | break; | ||
176 | |||
177 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
178 | len = min_t(u8, data->block[0], 32); | ||
179 | outb_p(command, NVIDIA_SMB_CMD); | ||
180 | outb_p(len, NVIDIA_SMB_BCNT); | ||
181 | if (read_write == I2C_SMBUS_WRITE) | ||
182 | for (i = 0; i < len; i++) | ||
183 | outb_p(data->block[i + 1], NVIDIA_SMB_DATA+i); | ||
184 | protocol |= NVIDIA_SMB_PRTCL_I2C_BLOCK_DATA; | ||
185 | break; | ||
186 | |||
187 | case I2C_SMBUS_PROC_CALL: | ||
188 | dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); | ||
189 | return -1; | ||
190 | |||
191 | case I2C_SMBUS_BLOCK_PROC_CALL: | ||
192 | dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n"); | ||
193 | return -1; | ||
194 | |||
195 | default: | 140 | default: |
196 | dev_err(&adap->dev, "Unsupported transaction %d\n", size); | 141 | dev_err(&adap->dev, "Unsupported transaction %d\n", size); |
197 | return -1; | 142 | return -1; |
@@ -227,19 +172,8 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, | |||
227 | break; | 172 | break; |
228 | 173 | ||
229 | case I2C_SMBUS_WORD_DATA: | 174 | case I2C_SMBUS_WORD_DATA: |
230 | /* case I2C_SMBUS_PROC_CALL: not supported */ | ||
231 | data->word = inb_p(NVIDIA_SMB_DATA) | (inb_p(NVIDIA_SMB_DATA+1) << 8); | 175 | data->word = inb_p(NVIDIA_SMB_DATA) | (inb_p(NVIDIA_SMB_DATA+1) << 8); |
232 | break; | 176 | break; |
233 | |||
234 | case I2C_SMBUS_BLOCK_DATA: | ||
235 | /* case I2C_SMBUS_BLOCK_PROC_CALL: not supported */ | ||
236 | len = inb_p(NVIDIA_SMB_BCNT); | ||
237 | len = min_t(u8, len, 32); | ||
238 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
239 | for (i = 0; i < len; i++) | ||
240 | data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i); | ||
241 | data->block[0] = len; | ||
242 | break; | ||
243 | } | 177 | } |
244 | 178 | ||
245 | return 0; | 179 | return 0; |
@@ -250,10 +184,14 @@ static u32 nforce2_func(struct i2c_adapter *adapter) | |||
250 | { | 184 | { |
251 | /* other functionality might be possible, but is not tested */ | 185 | /* other functionality might be possible, but is not tested */ |
252 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | 186 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | |
253 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA /* | | 187 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; |
254 | I2C_FUNC_SMBUS_BLOCK_DATA */; | ||
255 | } | 188 | } |
256 | 189 | ||
190 | static struct i2c_algorithm smbus_algorithm = { | ||
191 | .smbus_xfer = nforce2_access, | ||
192 | .functionality = nforce2_func, | ||
193 | }; | ||
194 | |||
257 | 195 | ||
258 | static struct pci_device_id nforce2_ids[] = { | 196 | static struct pci_device_id nforce2_ids[] = { |
259 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) }, | 197 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) }, |
@@ -267,7 +205,6 @@ static struct pci_device_id nforce2_ids[] = { | |||
267 | { 0 } | 205 | { 0 } |
268 | }; | 206 | }; |
269 | 207 | ||
270 | |||
271 | MODULE_DEVICE_TABLE (pci, nforce2_ids); | 208 | MODULE_DEVICE_TABLE (pci, nforce2_ids); |
272 | 209 | ||
273 | 210 | ||
@@ -291,7 +228,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar, | |||
291 | } | 228 | } |
292 | 229 | ||
293 | smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK; | 230 | smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK; |
294 | smbus->size = 8; | 231 | smbus->size = 64; |
295 | } | 232 | } |
296 | smbus->dev = dev; | 233 | smbus->dev = dev; |
297 | 234 | ||
@@ -300,7 +237,9 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar, | |||
300 | smbus->base, smbus->base+smbus->size-1, name); | 237 | smbus->base, smbus->base+smbus->size-1, name); |
301 | return -1; | 238 | return -1; |
302 | } | 239 | } |
303 | smbus->adapter = nforce2_adapter; | 240 | smbus->adapter.owner = THIS_MODULE; |
241 | smbus->adapter.class = I2C_CLASS_HWMON; | ||
242 | smbus->adapter.algo = &smbus_algorithm; | ||
304 | smbus->adapter.algo_data = smbus; | 243 | smbus->adapter.algo_data = smbus; |
305 | smbus->adapter.dev.parent = &dev->dev; | 244 | smbus->adapter.dev.parent = &dev->dev; |
306 | snprintf(smbus->adapter.name, I2C_NAME_SIZE, | 245 | snprintf(smbus->adapter.name, I2C_NAME_SIZE, |
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index dec04da0455c..bcd8367cede1 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
@@ -231,8 +231,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
231 | * 13 2 1 | 231 | * 13 2 1 |
232 | * 19.2 2 1 | 232 | * 19.2 2 1 |
233 | */ | 233 | */ |
234 | if (fclk_rate > 16000000) | 234 | if (fclk_rate > 12000000) |
235 | psc = (fclk_rate + 8000000) / 12000000; | 235 | psc = fclk_rate / 12000000; |
236 | } | 236 | } |
237 | 237 | ||
238 | /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ | 238 | /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ |
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c index 5eb2bd294fd9..4bc42810b9aa 100644 --- a/drivers/i2c/busses/i2c-parport-light.c +++ b/drivers/i2c/busses/i2c-parport-light.c | |||
@@ -163,7 +163,7 @@ static void __exit i2c_parport_exit(void) | |||
163 | if (adapter_parm[type].init.val) | 163 | if (adapter_parm[type].init.val) |
164 | line_set(0, &adapter_parm[type].init); | 164 | line_set(0, &adapter_parm[type].init); |
165 | 165 | ||
166 | i2c_bit_del_bus(&parport_adapter); | 166 | i2c_del_adapter(&parport_adapter); |
167 | release_region(base, 3); | 167 | release_region(base, 3); |
168 | } | 168 | } |
169 | 169 | ||
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c index 48a829431c7b..66696a40c7b5 100644 --- a/drivers/i2c/busses/i2c-parport.c +++ b/drivers/i2c/busses/i2c-parport.c | |||
@@ -218,7 +218,7 @@ static void i2c_parport_detach (struct parport *port) | |||
218 | if (adapter_parm[type].init.val) | 218 | if (adapter_parm[type].init.val) |
219 | line_set(port, 0, &adapter_parm[type].init); | 219 | line_set(port, 0, &adapter_parm[type].init); |
220 | 220 | ||
221 | i2c_bit_del_bus(&adapter->adapter); | 221 | i2c_del_adapter(&adapter->adapter); |
222 | parport_unregister_device(adapter->pdev); | 222 | parport_unregister_device(adapter->pdev); |
223 | if (prev) | 223 | if (prev) |
224 | prev->next = adapter->next; | 224 | prev->next = adapter->next; |
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c index 407840b6a260..cc6536a19eca 100644 --- a/drivers/i2c/busses/i2c-pca-isa.c +++ b/drivers/i2c/busses/i2c-pca-isa.c | |||
@@ -156,7 +156,7 @@ static int __init pca_isa_init(void) | |||
156 | 156 | ||
157 | static void pca_isa_exit(void) | 157 | static void pca_isa_exit(void) |
158 | { | 158 | { |
159 | i2c_pca_del_bus(&pca_isa_ops); | 159 | i2c_del_adapter(&pca_isa_ops); |
160 | 160 | ||
161 | if (irq > 0) { | 161 | if (irq > 0) { |
162 | disable_irq(irq); | 162 | disable_irq(irq); |
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c new file mode 100644 index 000000000000..17376feb1acc --- /dev/null +++ b/drivers/i2c/busses/i2c-pnx.c | |||
@@ -0,0 +1,703 @@ | |||
1 | /* | ||
2 | * Provides I2C support for Philips PNX010x/PNX4008 boards. | ||
3 | * | ||
4 | * Authors: Dennis Kovalev <dkovalev@ru.mvista.com> | ||
5 | * Vitaly Wool <vwool@ru.mvista.com> | ||
6 | * | ||
7 | * 2004-2006 (c) MontaVista Software, Inc. This file is licensed under | ||
8 | * the terms of the GNU General Public License version 2. This program | ||
9 | * is licensed "as is" without any warranty of any kind, whether express | ||
10 | * or implied. | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/ioport.h> | ||
16 | #include <linux/delay.h> | ||
17 | #include <linux/i2c.h> | ||
18 | #include <linux/timer.h> | ||
19 | #include <linux/completion.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/i2c-pnx.h> | ||
22 | #include <asm/hardware.h> | ||
23 | #include <asm/irq.h> | ||
24 | #include <asm/uaccess.h> | ||
25 | |||
26 | #define I2C_PNX_TIMEOUT 10 /* msec */ | ||
27 | #define I2C_PNX_SPEED_KHZ 100 | ||
28 | #define I2C_PNX_REGION_SIZE 0x100 | ||
29 | #define PNX_DEFAULT_FREQ 13 /* MHz */ | ||
30 | |||
31 | static inline int wait_timeout(long timeout, struct i2c_pnx_algo_data *data) | ||
32 | { | ||
33 | while (timeout > 0 && | ||
34 | (ioread32(I2C_REG_STS(data)) & mstatus_active)) { | ||
35 | mdelay(1); | ||
36 | timeout--; | ||
37 | } | ||
38 | return (timeout <= 0); | ||
39 | } | ||
40 | |||
41 | static inline int wait_reset(long timeout, struct i2c_pnx_algo_data *data) | ||
42 | { | ||
43 | while (timeout > 0 && | ||
44 | (ioread32(I2C_REG_CTL(data)) & mcntrl_reset)) { | ||
45 | mdelay(1); | ||
46 | timeout--; | ||
47 | } | ||
48 | return (timeout <= 0); | ||
49 | } | ||
50 | |||
51 | static inline void i2c_pnx_arm_timer(struct i2c_adapter *adap) | ||
52 | { | ||
53 | struct i2c_pnx_algo_data *data = adap->algo_data; | ||
54 | struct timer_list *timer = &data->mif.timer; | ||
55 | int expires = I2C_PNX_TIMEOUT / (1000 / HZ); | ||
56 | |||
57 | del_timer_sync(timer); | ||
58 | |||
59 | dev_dbg(&adap->dev, "Timer armed at %lu plus %u jiffies.\n", | ||
60 | jiffies, expires); | ||
61 | |||
62 | timer->expires = jiffies + expires; | ||
63 | timer->data = (unsigned long)adap; | ||
64 | |||
65 | add_timer(timer); | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * i2c_pnx_start - start a device | ||
70 | * @slave_addr: slave address | ||
71 | * @adap: pointer to adapter structure | ||
72 | * | ||
73 | * Generate a START signal in the desired mode. | ||
74 | */ | ||
75 | static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap) | ||
76 | { | ||
77 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
78 | |||
79 | dev_dbg(&adap->dev, "%s(): addr 0x%x mode %d\n", __FUNCTION__, | ||
80 | slave_addr, alg_data->mif.mode); | ||
81 | |||
82 | /* Check for 7 bit slave addresses only */ | ||
83 | if (slave_addr & ~0x7f) { | ||
84 | dev_err(&adap->dev, "%s: Invalid slave address %x. " | ||
85 | "Only 7-bit addresses are supported\n", | ||
86 | adap->name, slave_addr); | ||
87 | return -EINVAL; | ||
88 | } | ||
89 | |||
90 | /* First, make sure bus is idle */ | ||
91 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) { | ||
92 | /* Somebody else is monopolizing the bus */ | ||
93 | dev_err(&adap->dev, "%s: Bus busy. Slave addr = %02x, " | ||
94 | "cntrl = %x, stat = %x\n", | ||
95 | adap->name, slave_addr, | ||
96 | ioread32(I2C_REG_CTL(alg_data)), | ||
97 | ioread32(I2C_REG_STS(alg_data))); | ||
98 | return -EBUSY; | ||
99 | } else if (ioread32(I2C_REG_STS(alg_data)) & mstatus_afi) { | ||
100 | /* Sorry, we lost the bus */ | ||
101 | dev_err(&adap->dev, "%s: Arbitration failure. " | ||
102 | "Slave addr = %02x\n", adap->name, slave_addr); | ||
103 | return -EIO; | ||
104 | } | ||
105 | |||
106 | /* | ||
107 | * OK, I2C is enabled and we have the bus. | ||
108 | * Clear the current TDI and AFI status flags. | ||
109 | */ | ||
110 | iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi, | ||
111 | I2C_REG_STS(alg_data)); | ||
112 | |||
113 | dev_dbg(&adap->dev, "%s(): sending %#x\n", __FUNCTION__, | ||
114 | (slave_addr << 1) | start_bit | alg_data->mif.mode); | ||
115 | |||
116 | /* Write the slave address, START bit and R/W bit */ | ||
117 | iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode, | ||
118 | I2C_REG_TX(alg_data)); | ||
119 | |||
120 | dev_dbg(&adap->dev, "%s(): exit\n", __FUNCTION__); | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * i2c_pnx_stop - stop a device | ||
127 | * @adap: pointer to I2C adapter structure | ||
128 | * | ||
129 | * Generate a STOP signal to terminate the master transaction. | ||
130 | */ | ||
131 | static void i2c_pnx_stop(struct i2c_adapter *adap) | ||
132 | { | ||
133 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
134 | /* Only 1 msec max timeout due to interrupt context */ | ||
135 | long timeout = 1000; | ||
136 | |||
137 | dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", | ||
138 | __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); | ||
139 | |||
140 | /* Write a STOP bit to TX FIFO */ | ||
141 | iowrite32(0xff | stop_bit, I2C_REG_TX(alg_data)); | ||
142 | |||
143 | /* Wait until the STOP is seen. */ | ||
144 | while (timeout > 0 && | ||
145 | (ioread32(I2C_REG_STS(alg_data)) & mstatus_active)) { | ||
146 | /* may be called from interrupt context */ | ||
147 | udelay(1); | ||
148 | timeout--; | ||
149 | } | ||
150 | |||
151 | dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", | ||
152 | __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); | ||
153 | } | ||
154 | |||
155 | /** | ||
156 | * i2c_pnx_master_xmit - transmit data to slave | ||
157 | * @adap: pointer to I2C adapter structure | ||
158 | * | ||
159 | * Sends one byte of data to the slave | ||
160 | */ | ||
161 | static int i2c_pnx_master_xmit(struct i2c_adapter *adap) | ||
162 | { | ||
163 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
164 | u32 val; | ||
165 | |||
166 | dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", | ||
167 | __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); | ||
168 | |||
169 | if (alg_data->mif.len > 0) { | ||
170 | /* We still have something to talk about... */ | ||
171 | val = *alg_data->mif.buf++; | ||
172 | |||
173 | if (alg_data->mif.len == 1) { | ||
174 | val |= stop_bit; | ||
175 | if (!alg_data->last) | ||
176 | val |= start_bit; | ||
177 | } | ||
178 | |||
179 | alg_data->mif.len--; | ||
180 | iowrite32(val, I2C_REG_TX(alg_data)); | ||
181 | |||
182 | dev_dbg(&adap->dev, "%s(): xmit %#x [%d]\n", __FUNCTION__, | ||
183 | val, alg_data->mif.len + 1); | ||
184 | |||
185 | if (alg_data->mif.len == 0) { | ||
186 | if (alg_data->last) { | ||
187 | /* Wait until the STOP is seen. */ | ||
188 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) | ||
189 | dev_err(&adap->dev, "The bus is still " | ||
190 | "active after timeout\n"); | ||
191 | } | ||
192 | /* Disable master interrupts */ | ||
193 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) & | ||
194 | ~(mcntrl_afie | mcntrl_naie | mcntrl_drmie), | ||
195 | I2C_REG_CTL(alg_data)); | ||
196 | |||
197 | del_timer_sync(&alg_data->mif.timer); | ||
198 | |||
199 | dev_dbg(&adap->dev, "%s(): Waking up xfer routine.\n", | ||
200 | __FUNCTION__); | ||
201 | |||
202 | complete(&alg_data->mif.complete); | ||
203 | } | ||
204 | } else if (alg_data->mif.len == 0) { | ||
205 | /* zero-sized transfer */ | ||
206 | i2c_pnx_stop(adap); | ||
207 | |||
208 | /* Disable master interrupts. */ | ||
209 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) & | ||
210 | ~(mcntrl_afie | mcntrl_naie | mcntrl_drmie), | ||
211 | I2C_REG_CTL(alg_data)); | ||
212 | |||
213 | /* Stop timer. */ | ||
214 | del_timer_sync(&alg_data->mif.timer); | ||
215 | dev_dbg(&adap->dev, "%s(): Waking up xfer routine after " | ||
216 | "zero-xfer.\n", __FUNCTION__); | ||
217 | |||
218 | complete(&alg_data->mif.complete); | ||
219 | } | ||
220 | |||
221 | dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", | ||
222 | __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); | ||
223 | |||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * i2c_pnx_master_rcv - receive data from slave | ||
229 | * @adap: pointer to I2C adapter structure | ||
230 | * | ||
231 | * Reads one byte data from the slave | ||
232 | */ | ||
233 | static int i2c_pnx_master_rcv(struct i2c_adapter *adap) | ||
234 | { | ||
235 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
236 | unsigned int val = 0; | ||
237 | u32 ctl = 0; | ||
238 | |||
239 | dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", | ||
240 | __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); | ||
241 | |||
242 | /* Check, whether there is already data, | ||
243 | * or we didn't 'ask' for it yet. | ||
244 | */ | ||
245 | if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) { | ||
246 | dev_dbg(&adap->dev, "%s(): Write dummy data to fill " | ||
247 | "Rx-fifo...\n", __FUNCTION__); | ||
248 | |||
249 | if (alg_data->mif.len == 1) { | ||
250 | /* Last byte, do not acknowledge next rcv. */ | ||
251 | val |= stop_bit; | ||
252 | if (!alg_data->last) | ||
253 | val |= start_bit; | ||
254 | |||
255 | /* | ||
256 | * Enable interrupt RFDAIE (data in Rx fifo), | ||
257 | * and disable DRMIE (need data for Tx) | ||
258 | */ | ||
259 | ctl = ioread32(I2C_REG_CTL(alg_data)); | ||
260 | ctl |= mcntrl_rffie | mcntrl_daie; | ||
261 | ctl &= ~mcntrl_drmie; | ||
262 | iowrite32(ctl, I2C_REG_CTL(alg_data)); | ||
263 | } | ||
264 | |||
265 | /* | ||
266 | * Now we'll 'ask' for data: | ||
267 | * For each byte we want to receive, we must | ||
268 | * write a (dummy) byte to the Tx-FIFO. | ||
269 | */ | ||
270 | iowrite32(val, I2C_REG_TX(alg_data)); | ||
271 | |||
272 | return 0; | ||
273 | } | ||
274 | |||
275 | /* Handle data. */ | ||
276 | if (alg_data->mif.len > 0) { | ||
277 | val = ioread32(I2C_REG_RX(alg_data)); | ||
278 | *alg_data->mif.buf++ = (u8) (val & 0xff); | ||
279 | dev_dbg(&adap->dev, "%s(): rcv 0x%x [%d]\n", __FUNCTION__, val, | ||
280 | alg_data->mif.len); | ||
281 | |||
282 | alg_data->mif.len--; | ||
283 | if (alg_data->mif.len == 0) { | ||
284 | if (alg_data->last) | ||
285 | /* Wait until the STOP is seen. */ | ||
286 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) | ||
287 | dev_err(&adap->dev, "The bus is still " | ||
288 | "active after timeout\n"); | ||
289 | |||
290 | /* Disable master interrupts */ | ||
291 | ctl = ioread32(I2C_REG_CTL(alg_data)); | ||
292 | ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie | | ||
293 | mcntrl_drmie | mcntrl_daie); | ||
294 | iowrite32(ctl, I2C_REG_CTL(alg_data)); | ||
295 | |||
296 | /* Kill timer. */ | ||
297 | del_timer_sync(&alg_data->mif.timer); | ||
298 | complete(&alg_data->mif.complete); | ||
299 | } | ||
300 | } | ||
301 | |||
302 | dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", | ||
303 | __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); | ||
304 | |||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) | ||
309 | { | ||
310 | u32 stat, ctl; | ||
311 | struct i2c_adapter *adap = dev_id; | ||
312 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
313 | |||
314 | dev_dbg(&adap->dev, "%s(): mstat = %x mctrl = %x, mode = %d\n", | ||
315 | __FUNCTION__, | ||
316 | ioread32(I2C_REG_STS(alg_data)), | ||
317 | ioread32(I2C_REG_CTL(alg_data)), | ||
318 | alg_data->mif.mode); | ||
319 | stat = ioread32(I2C_REG_STS(alg_data)); | ||
320 | |||
321 | /* let's see what kind of event this is */ | ||
322 | if (stat & mstatus_afi) { | ||
323 | /* We lost arbitration in the midst of a transfer */ | ||
324 | alg_data->mif.ret = -EIO; | ||
325 | |||
326 | /* Disable master interrupts. */ | ||
327 | ctl = ioread32(I2C_REG_CTL(alg_data)); | ||
328 | ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie | | ||
329 | mcntrl_drmie); | ||
330 | iowrite32(ctl, I2C_REG_CTL(alg_data)); | ||
331 | |||
332 | /* Stop timer, to prevent timeout. */ | ||
333 | del_timer_sync(&alg_data->mif.timer); | ||
334 | complete(&alg_data->mif.complete); | ||
335 | } else if (stat & mstatus_nai) { | ||
336 | /* Slave did not acknowledge, generate a STOP */ | ||
337 | dev_dbg(&adap->dev, "%s(): " | ||
338 | "Slave did not acknowledge, generating a STOP.\n", | ||
339 | __FUNCTION__); | ||
340 | i2c_pnx_stop(adap); | ||
341 | |||
342 | /* Disable master interrupts. */ | ||
343 | ctl = ioread32(I2C_REG_CTL(alg_data)); | ||
344 | ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie | | ||
345 | mcntrl_drmie); | ||
346 | iowrite32(ctl, I2C_REG_CTL(alg_data)); | ||
347 | |||
348 | /* Our return value. */ | ||
349 | alg_data->mif.ret = -EIO; | ||
350 | |||
351 | /* Stop timer, to prevent timeout. */ | ||
352 | del_timer_sync(&alg_data->mif.timer); | ||
353 | complete(&alg_data->mif.complete); | ||
354 | } else { | ||
355 | /* | ||
356 | * Two options: | ||
357 | * - Master Tx needs data. | ||
358 | * - There is data in the Rx-fifo | ||
359 | * The latter is only the case if we have requested for data, | ||
360 | * via a dummy write. (See 'i2c_pnx_master_rcv'.) | ||
361 | * We therefore check, as a sanity check, whether that interrupt | ||
362 | * has been enabled. | ||
363 | */ | ||
364 | if ((stat & mstatus_drmi) || !(stat & mstatus_rfe)) { | ||
365 | if (alg_data->mif.mode == I2C_SMBUS_WRITE) { | ||
366 | i2c_pnx_master_xmit(adap); | ||
367 | } else if (alg_data->mif.mode == I2C_SMBUS_READ) { | ||
368 | i2c_pnx_master_rcv(adap); | ||
369 | } | ||
370 | } | ||
371 | } | ||
372 | |||
373 | /* Clear TDI and AFI bits */ | ||
374 | stat = ioread32(I2C_REG_STS(alg_data)); | ||
375 | iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data)); | ||
376 | |||
377 | dev_dbg(&adap->dev, "%s(): exiting, stat = %x ctrl = %x.\n", | ||
378 | __FUNCTION__, ioread32(I2C_REG_STS(alg_data)), | ||
379 | ioread32(I2C_REG_CTL(alg_data))); | ||
380 | |||
381 | return IRQ_HANDLED; | ||
382 | } | ||
383 | |||
384 | static void i2c_pnx_timeout(unsigned long data) | ||
385 | { | ||
386 | struct i2c_adapter *adap = (struct i2c_adapter *)data; | ||
387 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
388 | u32 ctl; | ||
389 | |||
390 | dev_err(&adap->dev, "Master timed out. stat = %04x, cntrl = %04x. " | ||
391 | "Resetting master...\n", | ||
392 | ioread32(I2C_REG_STS(alg_data)), | ||
393 | ioread32(I2C_REG_CTL(alg_data))); | ||
394 | |||
395 | /* Reset master and disable interrupts */ | ||
396 | ctl = ioread32(I2C_REG_CTL(alg_data)); | ||
397 | ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie | mcntrl_drmie); | ||
398 | iowrite32(ctl, I2C_REG_CTL(alg_data)); | ||
399 | |||
400 | ctl |= mcntrl_reset; | ||
401 | iowrite32(ctl, I2C_REG_CTL(alg_data)); | ||
402 | wait_reset(I2C_PNX_TIMEOUT, alg_data); | ||
403 | alg_data->mif.ret = -EIO; | ||
404 | complete(&alg_data->mif.complete); | ||
405 | } | ||
406 | |||
407 | static inline void bus_reset_if_active(struct i2c_adapter *adap) | ||
408 | { | ||
409 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
410 | u32 stat; | ||
411 | |||
412 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_active) { | ||
413 | dev_err(&adap->dev, | ||
414 | "%s: Bus is still active after xfer. Reset it...\n", | ||
415 | adap->name); | ||
416 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, | ||
417 | I2C_REG_CTL(alg_data)); | ||
418 | wait_reset(I2C_PNX_TIMEOUT, alg_data); | ||
419 | } else if (!(stat & mstatus_rfe) || !(stat & mstatus_tfe)) { | ||
420 | /* If there is data in the fifo's after transfer, | ||
421 | * flush fifo's by reset. | ||
422 | */ | ||
423 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, | ||
424 | I2C_REG_CTL(alg_data)); | ||
425 | wait_reset(I2C_PNX_TIMEOUT, alg_data); | ||
426 | } else if (stat & mstatus_nai) { | ||
427 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, | ||
428 | I2C_REG_CTL(alg_data)); | ||
429 | wait_reset(I2C_PNX_TIMEOUT, alg_data); | ||
430 | } | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * i2c_pnx_xfer - generic transfer entry point | ||
435 | * @adap: pointer to I2C adapter structure | ||
436 | * @msgs: array of messages | ||
437 | * @num: number of messages | ||
438 | * | ||
439 | * Initiates the transfer | ||
440 | */ | ||
441 | static int | ||
442 | i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | ||
443 | { | ||
444 | struct i2c_msg *pmsg; | ||
445 | int rc = 0, completed = 0, i; | ||
446 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
447 | u32 stat = ioread32(I2C_REG_STS(alg_data)); | ||
448 | |||
449 | dev_dbg(&adap->dev, "%s(): entering: %d messages, stat = %04x.\n", | ||
450 | __FUNCTION__, num, ioread32(I2C_REG_STS(alg_data))); | ||
451 | |||
452 | bus_reset_if_active(adap); | ||
453 | |||
454 | /* Process transactions in a loop. */ | ||
455 | for (i = 0; rc >= 0 && i < num; i++) { | ||
456 | u8 addr; | ||
457 | |||
458 | pmsg = &msgs[i]; | ||
459 | addr = pmsg->addr; | ||
460 | |||
461 | if (pmsg->flags & I2C_M_TEN) { | ||
462 | dev_err(&adap->dev, | ||
463 | "%s: 10 bits addr not supported!\n", | ||
464 | adap->name); | ||
465 | rc = -EINVAL; | ||
466 | break; | ||
467 | } | ||
468 | |||
469 | alg_data->mif.buf = pmsg->buf; | ||
470 | alg_data->mif.len = pmsg->len; | ||
471 | alg_data->mif.mode = (pmsg->flags & I2C_M_RD) ? | ||
472 | I2C_SMBUS_READ : I2C_SMBUS_WRITE; | ||
473 | alg_data->mif.ret = 0; | ||
474 | alg_data->last = (i == num - 1); | ||
475 | |||
476 | dev_dbg(&adap->dev, "%s(): mode %d, %d bytes\n", __FUNCTION__, | ||
477 | alg_data->mif.mode, | ||
478 | alg_data->mif.len); | ||
479 | |||
480 | i2c_pnx_arm_timer(adap); | ||
481 | |||
482 | /* initialize the completion var */ | ||
483 | init_completion(&alg_data->mif.complete); | ||
484 | |||
485 | /* Enable master interrupt */ | ||
486 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie | | ||
487 | mcntrl_naie | mcntrl_drmie, | ||
488 | I2C_REG_CTL(alg_data)); | ||
489 | |||
490 | /* Put start-code and slave-address on the bus. */ | ||
491 | rc = i2c_pnx_start(addr, adap); | ||
492 | if (rc < 0) | ||
493 | break; | ||
494 | |||
495 | /* Wait for completion */ | ||
496 | wait_for_completion(&alg_data->mif.complete); | ||
497 | |||
498 | if (!(rc = alg_data->mif.ret)) | ||
499 | completed++; | ||
500 | dev_dbg(&adap->dev, "%s(): Complete, return code = %d.\n", | ||
501 | __FUNCTION__, rc); | ||
502 | |||
503 | /* Clear TDI and AFI bits in case they are set. */ | ||
504 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) { | ||
505 | dev_dbg(&adap->dev, | ||
506 | "%s: TDI still set... clearing now.\n", | ||
507 | adap->name); | ||
508 | iowrite32(stat, I2C_REG_STS(alg_data)); | ||
509 | } | ||
510 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_afi) { | ||
511 | dev_dbg(&adap->dev, | ||
512 | "%s: AFI still set... clearing now.\n", | ||
513 | adap->name); | ||
514 | iowrite32(stat, I2C_REG_STS(alg_data)); | ||
515 | } | ||
516 | } | ||
517 | |||
518 | bus_reset_if_active(adap); | ||
519 | |||
520 | /* Cleanup to be sure... */ | ||
521 | alg_data->mif.buf = NULL; | ||
522 | alg_data->mif.len = 0; | ||
523 | |||
524 | dev_dbg(&adap->dev, "%s(): exiting, stat = %x\n", | ||
525 | __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); | ||
526 | |||
527 | if (completed != num) | ||
528 | return ((rc < 0) ? rc : -EREMOTEIO); | ||
529 | |||
530 | return num; | ||
531 | } | ||
532 | |||
533 | static u32 i2c_pnx_func(struct i2c_adapter *adapter) | ||
534 | { | ||
535 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | ||
536 | } | ||
537 | |||
538 | static struct i2c_algorithm pnx_algorithm = { | ||
539 | .master_xfer = i2c_pnx_xfer, | ||
540 | .functionality = i2c_pnx_func, | ||
541 | }; | ||
542 | |||
543 | static int i2c_pnx_controller_suspend(struct platform_device *pdev, | ||
544 | pm_message_t state) | ||
545 | { | ||
546 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | ||
547 | return i2c_pnx->suspend(pdev, state); | ||
548 | } | ||
549 | |||
550 | static int i2c_pnx_controller_resume(struct platform_device *pdev) | ||
551 | { | ||
552 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | ||
553 | return i2c_pnx->resume(pdev); | ||
554 | } | ||
555 | |||
556 | static int __devinit i2c_pnx_probe(struct platform_device *pdev) | ||
557 | { | ||
558 | unsigned long tmp; | ||
559 | int ret = 0; | ||
560 | struct i2c_pnx_algo_data *alg_data; | ||
561 | int freq_mhz; | ||
562 | struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data; | ||
563 | |||
564 | if (!i2c_pnx || !i2c_pnx->adapter) { | ||
565 | dev_err(&pdev->dev, "%s: no platform data supplied\n", | ||
566 | __FUNCTION__); | ||
567 | ret = -EINVAL; | ||
568 | goto out; | ||
569 | } | ||
570 | |||
571 | platform_set_drvdata(pdev, i2c_pnx); | ||
572 | |||
573 | if (i2c_pnx->calculate_input_freq) | ||
574 | freq_mhz = i2c_pnx->calculate_input_freq(pdev); | ||
575 | else { | ||
576 | freq_mhz = PNX_DEFAULT_FREQ; | ||
577 | dev_info(&pdev->dev, "Setting bus frequency to default value: " | ||
578 | "%d MHz", freq_mhz); | ||
579 | } | ||
580 | |||
581 | i2c_pnx->adapter->algo = &pnx_algorithm; | ||
582 | |||
583 | alg_data = i2c_pnx->adapter->algo_data; | ||
584 | init_timer(&alg_data->mif.timer); | ||
585 | alg_data->mif.timer.function = i2c_pnx_timeout; | ||
586 | alg_data->mif.timer.data = (unsigned long)i2c_pnx->adapter; | ||
587 | |||
588 | /* Register I/O resource */ | ||
589 | if (!request_region(alg_data->base, I2C_PNX_REGION_SIZE, pdev->name)) { | ||
590 | dev_err(&pdev->dev, | ||
591 | "I/O region 0x%08x for I2C already in use.\n", | ||
592 | alg_data->base); | ||
593 | ret = -ENODEV; | ||
594 | goto out_drvdata; | ||
595 | } | ||
596 | |||
597 | if (!(alg_data->ioaddr = | ||
598 | (u32)ioremap(alg_data->base, I2C_PNX_REGION_SIZE))) { | ||
599 | dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n"); | ||
600 | ret = -ENOMEM; | ||
601 | goto out_release; | ||
602 | } | ||
603 | |||
604 | i2c_pnx->set_clock_run(pdev); | ||
605 | |||
606 | /* | ||
607 | * Clock Divisor High This value is the number of system clocks | ||
608 | * the serial clock (SCL) will be high. | ||
609 | * For example, if the system clock period is 50 ns and the maximum | ||
610 | * desired serial period is 10000 ns (100 kHz), then CLKHI would be | ||
611 | * set to 0.5*(f_sys/f_i2c)-2=0.5*(20e6/100e3)-2=98. The actual value | ||
612 | * programmed into CLKHI will vary from this slightly due to | ||
613 | * variations in the output pad's rise and fall times as well as | ||
614 | * the deglitching filter length. | ||
615 | */ | ||
616 | |||
617 | tmp = ((freq_mhz * 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2; | ||
618 | iowrite32(tmp, I2C_REG_CKH(alg_data)); | ||
619 | iowrite32(tmp, I2C_REG_CKL(alg_data)); | ||
620 | |||
621 | iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data)); | ||
622 | if (wait_reset(I2C_PNX_TIMEOUT, alg_data)) { | ||
623 | ret = -ENODEV; | ||
624 | goto out_unmap; | ||
625 | } | ||
626 | init_completion(&alg_data->mif.complete); | ||
627 | |||
628 | ret = request_irq(alg_data->irq, i2c_pnx_interrupt, | ||
629 | 0, pdev->name, i2c_pnx->adapter); | ||
630 | if (ret) | ||
631 | goto out_clock; | ||
632 | |||
633 | /* Register this adapter with the I2C subsystem */ | ||
634 | i2c_pnx->adapter->dev.parent = &pdev->dev; | ||
635 | ret = i2c_add_adapter(i2c_pnx->adapter); | ||
636 | if (ret < 0) { | ||
637 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); | ||
638 | goto out_irq; | ||
639 | } | ||
640 | |||
641 | dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", | ||
642 | i2c_pnx->adapter->name, alg_data->base, alg_data->irq); | ||
643 | |||
644 | return 0; | ||
645 | |||
646 | out_irq: | ||
647 | free_irq(alg_data->irq, alg_data); | ||
648 | out_clock: | ||
649 | i2c_pnx->set_clock_stop(pdev); | ||
650 | out_unmap: | ||
651 | iounmap((void *)alg_data->ioaddr); | ||
652 | out_release: | ||
653 | release_region(alg_data->base, I2C_PNX_REGION_SIZE); | ||
654 | out_drvdata: | ||
655 | platform_set_drvdata(pdev, NULL); | ||
656 | out: | ||
657 | return ret; | ||
658 | } | ||
659 | |||
660 | static int __devexit i2c_pnx_remove(struct platform_device *pdev) | ||
661 | { | ||
662 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | ||
663 | struct i2c_adapter *adap = i2c_pnx->adapter; | ||
664 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
665 | |||
666 | free_irq(alg_data->irq, alg_data); | ||
667 | i2c_del_adapter(adap); | ||
668 | i2c_pnx->set_clock_stop(pdev); | ||
669 | iounmap((void *)alg_data->ioaddr); | ||
670 | release_region(alg_data->base, I2C_PNX_REGION_SIZE); | ||
671 | platform_set_drvdata(pdev, NULL); | ||
672 | |||
673 | return 0; | ||
674 | } | ||
675 | |||
676 | static struct platform_driver i2c_pnx_driver = { | ||
677 | .driver = { | ||
678 | .name = "pnx-i2c", | ||
679 | .owner = THIS_MODULE, | ||
680 | }, | ||
681 | .probe = i2c_pnx_probe, | ||
682 | .remove = __devexit_p(i2c_pnx_remove), | ||
683 | .suspend = i2c_pnx_controller_suspend, | ||
684 | .resume = i2c_pnx_controller_resume, | ||
685 | }; | ||
686 | |||
687 | static int __init i2c_adap_pnx_init(void) | ||
688 | { | ||
689 | return platform_driver_register(&i2c_pnx_driver); | ||
690 | } | ||
691 | |||
692 | static void __exit i2c_adap_pnx_exit(void) | ||
693 | { | ||
694 | platform_driver_unregister(&i2c_pnx_driver); | ||
695 | } | ||
696 | |||
697 | MODULE_AUTHOR("Vitaly Wool, Dennis Kovalev <source@mvista.com>"); | ||
698 | MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses"); | ||
699 | MODULE_LICENSE("GPL"); | ||
700 | |||
701 | /* We need to make sure I2C is initialized before USB */ | ||
702 | subsys_initcall(i2c_adap_pnx_init); | ||
703 | module_exit(i2c_adap_pnx_exit); | ||
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c index 7745e21874a8..07c1f1e27df1 100644 --- a/drivers/i2c/busses/i2c-prosavage.c +++ b/drivers/i2c/busses/i2c-prosavage.c | |||
@@ -212,7 +212,7 @@ static void prosavage_remove(struct pci_dev *dev) | |||
212 | if (chip->i2c_bus[i].adap_ok == 0) | 212 | if (chip->i2c_bus[i].adap_ok == 0) |
213 | continue; | 213 | continue; |
214 | 214 | ||
215 | ret = i2c_bit_del_bus(&chip->i2c_bus[i].adap); | 215 | ret = i2c_del_adapter(&chip->i2c_bus[i].adap); |
216 | if (ret) { | 216 | if (ret) { |
217 | dev_err(&dev->dev, "%s not removed\n", | 217 | dev_err(&dev->dev, "%s not removed\n", |
218 | chip->i2c_bus[i].adap.name); | 218 | chip->i2c_bus[i].adap.name); |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index c95a6c154165..c3b1567c852a 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
@@ -358,133 +358,6 @@ static void i2c_pxa_reset(struct pxa_i2c *i2c) | |||
358 | 358 | ||
359 | #ifdef CONFIG_I2C_PXA_SLAVE | 359 | #ifdef CONFIG_I2C_PXA_SLAVE |
360 | /* | 360 | /* |
361 | * I2C EEPROM emulation. | ||
362 | */ | ||
363 | static struct i2c_eeprom_emu eeprom = { | ||
364 | .size = I2C_EEPROM_EMU_SIZE, | ||
365 | .watch = LIST_HEAD_INIT(eeprom.watch), | ||
366 | }; | ||
367 | |||
368 | struct i2c_eeprom_emu *i2c_pxa_get_eeprom(void) | ||
369 | { | ||
370 | return &eeprom; | ||
371 | } | ||
372 | |||
373 | int i2c_eeprom_emu_addwatcher(struct i2c_eeprom_emu *emu, void *data, | ||
374 | unsigned int addr, unsigned int size, | ||
375 | struct i2c_eeprom_emu_watcher *watcher) | ||
376 | { | ||
377 | struct i2c_eeprom_emu_watch *watch; | ||
378 | unsigned long flags; | ||
379 | |||
380 | if (addr + size > emu->size) | ||
381 | return -EINVAL; | ||
382 | |||
383 | watch = kmalloc(sizeof(struct i2c_eeprom_emu_watch), GFP_KERNEL); | ||
384 | if (watch) { | ||
385 | watch->start = addr; | ||
386 | watch->end = addr + size - 1; | ||
387 | watch->ops = watcher; | ||
388 | watch->data = data; | ||
389 | |||
390 | local_irq_save(flags); | ||
391 | list_add(&watch->node, &emu->watch); | ||
392 | local_irq_restore(flags); | ||
393 | } | ||
394 | |||
395 | return watch ? 0 : -ENOMEM; | ||
396 | } | ||
397 | |||
398 | void i2c_eeprom_emu_delwatcher(struct i2c_eeprom_emu *emu, void *data, | ||
399 | struct i2c_eeprom_emu_watcher *watcher) | ||
400 | { | ||
401 | struct i2c_eeprom_emu_watch *watch, *n; | ||
402 | unsigned long flags; | ||
403 | |||
404 | list_for_each_entry_safe(watch, n, &emu->watch, node) { | ||
405 | if (watch->ops == watcher && watch->data == data) { | ||
406 | local_irq_save(flags); | ||
407 | list_del(&watch->node); | ||
408 | local_irq_restore(flags); | ||
409 | kfree(watch); | ||
410 | } | ||
411 | } | ||
412 | } | ||
413 | |||
414 | static void i2c_eeprom_emu_event(void *ptr, i2c_slave_event_t event) | ||
415 | { | ||
416 | struct i2c_eeprom_emu *emu = ptr; | ||
417 | |||
418 | eedbg(3, "i2c_eeprom_emu_event: %d\n", event); | ||
419 | |||
420 | switch (event) { | ||
421 | case I2C_SLAVE_EVENT_START_WRITE: | ||
422 | emu->seen_start = 1; | ||
423 | eedbg(2, "i2c_eeprom: write initiated\n"); | ||
424 | break; | ||
425 | |||
426 | case I2C_SLAVE_EVENT_START_READ: | ||
427 | emu->seen_start = 0; | ||
428 | eedbg(2, "i2c_eeprom: read initiated\n"); | ||
429 | break; | ||
430 | |||
431 | case I2C_SLAVE_EVENT_STOP: | ||
432 | emu->seen_start = 0; | ||
433 | eedbg(2, "i2c_eeprom: received stop\n"); | ||
434 | break; | ||
435 | |||
436 | default: | ||
437 | eedbg(0, "i2c_eeprom: unhandled event\n"); | ||
438 | break; | ||
439 | } | ||
440 | } | ||
441 | |||
442 | static int i2c_eeprom_emu_read(void *ptr) | ||
443 | { | ||
444 | struct i2c_eeprom_emu *emu = ptr; | ||
445 | int ret; | ||
446 | |||
447 | ret = emu->bytes[emu->ptr]; | ||
448 | emu->ptr = (emu->ptr + 1) % emu->size; | ||
449 | |||
450 | return ret; | ||
451 | } | ||
452 | |||
453 | static void i2c_eeprom_emu_write(void *ptr, unsigned int val) | ||
454 | { | ||
455 | struct i2c_eeprom_emu *emu = ptr; | ||
456 | struct i2c_eeprom_emu_watch *watch; | ||
457 | |||
458 | if (emu->seen_start != 0) { | ||
459 | eedbg(2, "i2c_eeprom_emu_write: setting ptr %02x\n", val); | ||
460 | emu->ptr = val; | ||
461 | emu->seen_start = 0; | ||
462 | return; | ||
463 | } | ||
464 | |||
465 | emu->bytes[emu->ptr] = val; | ||
466 | |||
467 | eedbg(1, "i2c_eeprom_emu_write: ptr=0x%02x, val=0x%02x\n", | ||
468 | emu->ptr, val); | ||
469 | |||
470 | list_for_each_entry(watch, &emu->watch, node) { | ||
471 | if (!watch->ops || !watch->ops->write) | ||
472 | continue; | ||
473 | if (watch->start <= emu->ptr && watch->end >= emu->ptr) | ||
474 | watch->ops->write(watch->data, emu->ptr, val); | ||
475 | } | ||
476 | |||
477 | emu->ptr = (emu->ptr + 1) % emu->size; | ||
478 | } | ||
479 | |||
480 | struct i2c_slave_client eeprom_client = { | ||
481 | .data = &eeprom, | ||
482 | .event = i2c_eeprom_emu_event, | ||
483 | .read = i2c_eeprom_emu_read, | ||
484 | .write = i2c_eeprom_emu_write | ||
485 | }; | ||
486 | |||
487 | /* | ||
488 | * PXA I2C Slave mode | 361 | * PXA I2C Slave mode |
489 | */ | 362 | */ |
490 | 363 | ||
@@ -963,11 +836,9 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
963 | i2c->slave_addr = I2C_PXA_SLAVE_ADDR; | 836 | i2c->slave_addr = I2C_PXA_SLAVE_ADDR; |
964 | 837 | ||
965 | #ifdef CONFIG_I2C_PXA_SLAVE | 838 | #ifdef CONFIG_I2C_PXA_SLAVE |
966 | i2c->slave = &eeprom_client; | ||
967 | if (plat) { | 839 | if (plat) { |
968 | i2c->slave_addr = plat->slave_addr; | 840 | i2c->slave_addr = plat->slave_addr; |
969 | if (plat->slave) | 841 | i2c->slave = plat->slave; |
970 | i2c->slave = plat->slave; | ||
971 | } | 842 | } |
972 | #endif | 843 | #endif |
973 | 844 | ||
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c index 209f47ea1750..844b4ff90893 100644 --- a/drivers/i2c/busses/i2c-savage4.c +++ b/drivers/i2c/busses/i2c-savage4.c | |||
@@ -173,7 +173,7 @@ static int __devinit savage4_probe(struct pci_dev *dev, const struct pci_device_ | |||
173 | 173 | ||
174 | static void __devexit savage4_remove(struct pci_dev *dev) | 174 | static void __devexit savage4_remove(struct pci_dev *dev) |
175 | { | 175 | { |
176 | i2c_bit_del_bus(&savage4_i2c_adapter); | 176 | i2c_del_adapter(&savage4_i2c_adapter); |
177 | iounmap(ioaddr); | 177 | iounmap(ioaddr); |
178 | } | 178 | } |
179 | 179 | ||
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c new file mode 100644 index 000000000000..081d9578ce10 --- /dev/null +++ b/drivers/i2c/busses/i2c-versatile.c | |||
@@ -0,0 +1,153 @@ | |||
1 | /* | ||
2 | * i2c-versatile.c | ||
3 | * | ||
4 | * Copyright (C) 2006 ARM Ltd. | ||
5 | * written by Russell King, Deep Blue Solutions Ltd. | ||
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 version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/i2c.h> | ||
14 | #include <linux/i2c-algo-bit.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | |||
18 | #include <asm/io.h> | ||
19 | |||
20 | #define I2C_CONTROL 0x00 | ||
21 | #define I2C_CONTROLS 0x00 | ||
22 | #define I2C_CONTROLC 0x04 | ||
23 | #define SCL (1 << 0) | ||
24 | #define SDA (1 << 1) | ||
25 | |||
26 | struct i2c_versatile { | ||
27 | struct i2c_adapter adap; | ||
28 | struct i2c_algo_bit_data algo; | ||
29 | void __iomem *base; | ||
30 | }; | ||
31 | |||
32 | static void i2c_versatile_setsda(void *data, int state) | ||
33 | { | ||
34 | struct i2c_versatile *i2c = data; | ||
35 | |||
36 | writel(SDA, i2c->base + (state ? I2C_CONTROLS : I2C_CONTROLC)); | ||
37 | } | ||
38 | |||
39 | static void i2c_versatile_setscl(void *data, int state) | ||
40 | { | ||
41 | struct i2c_versatile *i2c = data; | ||
42 | |||
43 | writel(SCL, i2c->base + (state ? I2C_CONTROLS : I2C_CONTROLC)); | ||
44 | } | ||
45 | |||
46 | static int i2c_versatile_getsda(void *data) | ||
47 | { | ||
48 | struct i2c_versatile *i2c = data; | ||
49 | return !!(readl(i2c->base + I2C_CONTROL) & SDA); | ||
50 | } | ||
51 | |||
52 | static int i2c_versatile_getscl(void *data) | ||
53 | { | ||
54 | struct i2c_versatile *i2c = data; | ||
55 | return !!(readl(i2c->base + I2C_CONTROL) & SCL); | ||
56 | } | ||
57 | |||
58 | static struct i2c_algo_bit_data i2c_versatile_algo = { | ||
59 | .setsda = i2c_versatile_setsda, | ||
60 | .setscl = i2c_versatile_setscl, | ||
61 | .getsda = i2c_versatile_getsda, | ||
62 | .getscl = i2c_versatile_getscl, | ||
63 | .udelay = 30, | ||
64 | .timeout = HZ, | ||
65 | }; | ||
66 | |||
67 | static int i2c_versatile_probe(struct platform_device *dev) | ||
68 | { | ||
69 | struct i2c_versatile *i2c; | ||
70 | struct resource *r; | ||
71 | int ret; | ||
72 | |||
73 | r = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
74 | if (!r) { | ||
75 | ret = -EINVAL; | ||
76 | goto err_out; | ||
77 | } | ||
78 | |||
79 | if (!request_mem_region(r->start, r->end - r->start + 1, "versatile-i2c")) { | ||
80 | ret = -EBUSY; | ||
81 | goto err_out; | ||
82 | } | ||
83 | |||
84 | i2c = kzalloc(sizeof(struct i2c_versatile), GFP_KERNEL); | ||
85 | if (!i2c) { | ||
86 | ret = -ENOMEM; | ||
87 | goto err_release; | ||
88 | } | ||
89 | |||
90 | i2c->base = ioremap(r->start, r->end - r->start + 1); | ||
91 | if (!i2c->base) { | ||
92 | ret = -ENOMEM; | ||
93 | goto err_free; | ||
94 | } | ||
95 | |||
96 | writel(SCL | SDA, i2c->base + I2C_CONTROLS); | ||
97 | |||
98 | i2c->adap.owner = THIS_MODULE; | ||
99 | strlcpy(i2c->adap.name, "Versatile I2C adapter", sizeof(i2c->adap.name)); | ||
100 | i2c->adap.algo_data = &i2c->algo; | ||
101 | i2c->adap.dev.parent = &dev->dev; | ||
102 | i2c->algo = i2c_versatile_algo; | ||
103 | i2c->algo.data = i2c; | ||
104 | |||
105 | ret = i2c_bit_add_bus(&i2c->adap); | ||
106 | if (ret >= 0) { | ||
107 | platform_set_drvdata(dev, i2c); | ||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | iounmap(i2c->base); | ||
112 | err_free: | ||
113 | kfree(i2c); | ||
114 | err_release: | ||
115 | release_mem_region(r->start, r->end - r->start + 1); | ||
116 | err_out: | ||
117 | return ret; | ||
118 | } | ||
119 | |||
120 | static int i2c_versatile_remove(struct platform_device *dev) | ||
121 | { | ||
122 | struct i2c_versatile *i2c = platform_get_drvdata(dev); | ||
123 | |||
124 | platform_set_drvdata(dev, NULL); | ||
125 | |||
126 | i2c_del_adapter(&i2c->adap); | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static struct platform_driver i2c_versatile_driver = { | ||
131 | .probe = i2c_versatile_probe, | ||
132 | .remove = i2c_versatile_remove, | ||
133 | .driver = { | ||
134 | .name = "versatile-i2c", | ||
135 | .owner = THIS_MODULE, | ||
136 | }, | ||
137 | }; | ||
138 | |||
139 | static int __init i2c_versatile_init(void) | ||
140 | { | ||
141 | return platform_driver_register(&i2c_versatile_driver); | ||
142 | } | ||
143 | |||
144 | static void __exit i2c_versatile_exit(void) | ||
145 | { | ||
146 | platform_driver_unregister(&i2c_versatile_driver); | ||
147 | } | ||
148 | |||
149 | module_init(i2c_versatile_init); | ||
150 | module_exit(i2c_versatile_exit); | ||
151 | |||
152 | MODULE_DESCRIPTION("ARM Versatile I2C bus driver"); | ||
153 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c index 910e200ad500..15d7e00e47e6 100644 --- a/drivers/i2c/busses/i2c-via.c +++ b/drivers/i2c/busses/i2c-via.c | |||
@@ -151,7 +151,7 @@ static int __devinit vt586b_probe(struct pci_dev *dev, const struct pci_device_i | |||
151 | 151 | ||
152 | static void __devexit vt586b_remove(struct pci_dev *dev) | 152 | static void __devexit vt586b_remove(struct pci_dev *dev) |
153 | { | 153 | { |
154 | i2c_bit_del_bus(&vt586b_adapter); | 154 | i2c_del_adapter(&vt586b_adapter); |
155 | release_region(I2C_DIR, IOSPACE); | 155 | release_region(I2C_DIR, IOSPACE); |
156 | pm_io_base = 0; | 156 | pm_io_base = 0; |
157 | } | 157 | } |
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c index 6c8d25183382..b0377b81744b 100644 --- a/drivers/i2c/busses/i2c-voodoo3.c +++ b/drivers/i2c/busses/i2c-voodoo3.c | |||
@@ -211,14 +211,14 @@ static int __devinit voodoo3_probe(struct pci_dev *dev, const struct pci_device_ | |||
211 | return retval; | 211 | return retval; |
212 | retval = i2c_bit_add_bus(&voodoo3_ddc_adapter); | 212 | retval = i2c_bit_add_bus(&voodoo3_ddc_adapter); |
213 | if (retval) | 213 | if (retval) |
214 | i2c_bit_del_bus(&voodoo3_i2c_adapter); | 214 | i2c_del_adapter(&voodoo3_i2c_adapter); |
215 | return retval; | 215 | return retval; |
216 | } | 216 | } |
217 | 217 | ||
218 | static void __devexit voodoo3_remove(struct pci_dev *dev) | 218 | static void __devexit voodoo3_remove(struct pci_dev *dev) |
219 | { | 219 | { |
220 | i2c_bit_del_bus(&voodoo3_i2c_adapter); | 220 | i2c_del_adapter(&voodoo3_i2c_adapter); |
221 | i2c_bit_del_bus(&voodoo3_ddc_adapter); | 221 | i2c_del_adapter(&voodoo3_ddc_adapter); |
222 | iounmap(ioaddr); | 222 | iounmap(ioaddr); |
223 | } | 223 | } |
224 | 224 | ||
diff --git a/drivers/i2c/busses/scx200_i2c.c b/drivers/i2c/busses/scx200_i2c.c index 8ddbae4fafe6..6cd96e43aa72 100644 --- a/drivers/i2c/busses/scx200_i2c.c +++ b/drivers/i2c/busses/scx200_i2c.c | |||
@@ -116,7 +116,7 @@ static int scx200_i2c_init(void) | |||
116 | 116 | ||
117 | static void scx200_i2c_cleanup(void) | 117 | static void scx200_i2c_cleanup(void) |
118 | { | 118 | { |
119 | i2c_bit_del_bus(&scx200_i2c_ops); | 119 | i2c_del_adapter(&scx200_i2c_ops); |
120 | } | 120 | } |
121 | 121 | ||
122 | module_init(scx200_i2c_init); | 122 | module_init(scx200_i2c_init); |
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c index 93d483b8b770..ec17d6b684a2 100644 --- a/drivers/i2c/chips/ds1337.c +++ b/drivers/i2c/chips/ds1337.c | |||
@@ -347,13 +347,19 @@ static void ds1337_init_client(struct i2c_client *client) | |||
347 | 347 | ||
348 | if ((status & 0x80) || (control & 0x80)) { | 348 | if ((status & 0x80) || (control & 0x80)) { |
349 | /* RTC not running */ | 349 | /* RTC not running */ |
350 | u8 buf[16]; | 350 | u8 buf[1+16]; /* First byte is interpreted as address */ |
351 | struct i2c_msg msg[1]; | 351 | struct i2c_msg msg[1]; |
352 | 352 | ||
353 | dev_dbg(&client->dev, "%s: RTC not running!\n", __FUNCTION__); | 353 | dev_dbg(&client->dev, "%s: RTC not running!\n", __FUNCTION__); |
354 | 354 | ||
355 | /* Initialize all, including STATUS and CONTROL to zero */ | 355 | /* Initialize all, including STATUS and CONTROL to zero */ |
356 | memset(buf, 0, sizeof(buf)); | 356 | memset(buf, 0, sizeof(buf)); |
357 | |||
358 | /* Write valid values in the date/time registers */ | ||
359 | buf[1+DS1337_REG_DAY] = 1; | ||
360 | buf[1+DS1337_REG_DATE] = 1; | ||
361 | buf[1+DS1337_REG_MONTH] = 1; | ||
362 | |||
357 | msg[0].addr = client->addr; | 363 | msg[0].addr = client->addr; |
358 | msg[0].flags = 0; | 364 | msg[0].flags = 0; |
359 | msg[0].len = sizeof(buf); | 365 | msg[0].len = sizeof(buf); |
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c index 4630f1969a09..15edf40828b4 100644 --- a/drivers/i2c/chips/ds1374.c +++ b/drivers/i2c/chips/ds1374.c | |||
@@ -140,12 +140,14 @@ ulong ds1374_get_rtc_time(void) | |||
140 | return t1; | 140 | return t1; |
141 | } | 141 | } |
142 | 142 | ||
143 | static void ds1374_set_work(void *arg) | 143 | static ulong new_time; |
144 | |||
145 | static void ds1374_set_work(struct work_struct *work) | ||
144 | { | 146 | { |
145 | ulong t1, t2; | 147 | ulong t1, t2; |
146 | int limit = 10; /* arbitrary retry limit */ | 148 | int limit = 10; /* arbitrary retry limit */ |
147 | 149 | ||
148 | t1 = *(ulong *) arg; | 150 | t1 = new_time; |
149 | 151 | ||
150 | mutex_lock(&ds1374_mutex); | 152 | mutex_lock(&ds1374_mutex); |
151 | 153 | ||
@@ -167,11 +169,9 @@ static void ds1374_set_work(void *arg) | |||
167 | "can't confirm time set from rtc chip\n"); | 169 | "can't confirm time set from rtc chip\n"); |
168 | } | 170 | } |
169 | 171 | ||
170 | static ulong new_time; | ||
171 | |||
172 | static struct workqueue_struct *ds1374_workqueue; | 172 | static struct workqueue_struct *ds1374_workqueue; |
173 | 173 | ||
174 | static DECLARE_WORK(ds1374_work, ds1374_set_work, &new_time); | 174 | static DECLARE_WORK(ds1374_work, ds1374_set_work); |
175 | 175 | ||
176 | int ds1374_set_rtc_time(ulong nowtime) | 176 | int ds1374_set_rtc_time(ulong nowtime) |
177 | { | 177 | { |
@@ -180,7 +180,7 @@ int ds1374_set_rtc_time(ulong nowtime) | |||
180 | if (in_interrupt()) | 180 | if (in_interrupt()) |
181 | queue_work(ds1374_workqueue, &ds1374_work); | 181 | queue_work(ds1374_workqueue, &ds1374_work); |
182 | else | 182 | else |
183 | ds1374_set_work(&new_time); | 183 | ds1374_set_work(NULL); |
184 | 184 | ||
185 | return 0; | 185 | return 0; |
186 | } | 186 | } |
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c index 2dd0a34d9472..3fcb646e2073 100644 --- a/drivers/i2c/chips/m41t00.c +++ b/drivers/i2c/chips/m41t00.c | |||
@@ -209,14 +209,22 @@ m41t00_set(void *arg) | |||
209 | buf[m41t00_chip->hour] = (buf[m41t00_chip->hour] & ~0x3f) | (hour& 0x3f); | 209 | buf[m41t00_chip->hour] = (buf[m41t00_chip->hour] & ~0x3f) | (hour& 0x3f); |
210 | buf[m41t00_chip->day] = (buf[m41t00_chip->day] & ~0x3f) | (day & 0x3f); | 210 | buf[m41t00_chip->day] = (buf[m41t00_chip->day] & ~0x3f) | (day & 0x3f); |
211 | buf[m41t00_chip->mon] = (buf[m41t00_chip->mon] & ~0x1f) | (mon & 0x1f); | 211 | buf[m41t00_chip->mon] = (buf[m41t00_chip->mon] & ~0x1f) | (mon & 0x1f); |
212 | buf[m41t00_chip->year] = year; | ||
212 | 213 | ||
213 | if (i2c_master_send(save_client, wbuf, 9) < 0) | 214 | if (i2c_master_send(save_client, wbuf, 9) < 0) |
214 | dev_err(&save_client->dev, "m41t00_set: Write error\n"); | 215 | dev_err(&save_client->dev, "m41t00_set: Write error\n"); |
215 | } | 216 | } |
216 | 217 | ||
217 | static ulong new_time; | 218 | static ulong new_time; |
219 | /* well, isn't this API just _lovely_? */ | ||
220 | static void | ||
221 | m41t00_barf(struct work_struct *unusable) | ||
222 | { | ||
223 | m41t00_set(&new_time); | ||
224 | } | ||
225 | |||
218 | static struct workqueue_struct *m41t00_wq; | 226 | static struct workqueue_struct *m41t00_wq; |
219 | static DECLARE_WORK(m41t00_work, m41t00_set, &new_time); | 227 | static DECLARE_WORK(m41t00_work, m41t00_barf); |
220 | 228 | ||
221 | int | 229 | int |
222 | m41t00_set_rtc_time(ulong nowtime) | 230 | m41t00_set_rtc_time(ulong nowtime) |
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c index 60bef94cd25f..4ee56def61f2 100644 --- a/drivers/i2c/chips/tps65010.c +++ b/drivers/i2c/chips/tps65010.c | |||
@@ -82,7 +82,7 @@ struct tps65010 { | |||
82 | struct i2c_client client; | 82 | struct i2c_client client; |
83 | struct mutex lock; | 83 | struct mutex lock; |
84 | int irq; | 84 | int irq; |
85 | struct work_struct work; | 85 | struct delayed_work work; |
86 | struct dentry *file; | 86 | struct dentry *file; |
87 | unsigned charging:1; | 87 | unsigned charging:1; |
88 | unsigned por:1; | 88 | unsigned por:1; |
@@ -328,7 +328,7 @@ static void tps65010_interrupt(struct tps65010 *tps) | |||
328 | { | 328 | { |
329 | u8 tmp = 0, mask, poll; | 329 | u8 tmp = 0, mask, poll; |
330 | 330 | ||
331 | /* IRQs won't trigger irqs for certain events, but we can get | 331 | /* IRQs won't trigger for certain events, but we can get |
332 | * others by polling (normally, with external power applied). | 332 | * others by polling (normally, with external power applied). |
333 | */ | 333 | */ |
334 | poll = 0; | 334 | poll = 0; |
@@ -411,10 +411,11 @@ static void tps65010_interrupt(struct tps65010 *tps) | |||
411 | } | 411 | } |
412 | 412 | ||
413 | /* handle IRQs and polling using keventd for now */ | 413 | /* handle IRQs and polling using keventd for now */ |
414 | static void tps65010_work(void *_tps) | 414 | static void tps65010_work(struct work_struct *work) |
415 | { | 415 | { |
416 | struct tps65010 *tps = _tps; | 416 | struct tps65010 *tps; |
417 | 417 | ||
418 | tps = container_of(work, struct tps65010, work.work); | ||
418 | mutex_lock(&tps->lock); | 419 | mutex_lock(&tps->lock); |
419 | 420 | ||
420 | tps65010_interrupt(tps); | 421 | tps65010_interrupt(tps); |
@@ -452,7 +453,7 @@ static irqreturn_t tps65010_irq(int irq, void *_tps) | |||
452 | 453 | ||
453 | disable_irq_nosync(irq); | 454 | disable_irq_nosync(irq); |
454 | set_bit(FLAG_IRQ_ENABLE, &tps->flags); | 455 | set_bit(FLAG_IRQ_ENABLE, &tps->flags); |
455 | (void) schedule_work(&tps->work); | 456 | (void) schedule_work(&tps->work.work); |
456 | return IRQ_HANDLED; | 457 | return IRQ_HANDLED; |
457 | } | 458 | } |
458 | 459 | ||
@@ -465,13 +466,15 @@ static int __exit tps65010_detach_client(struct i2c_client *client) | |||
465 | struct tps65010 *tps; | 466 | struct tps65010 *tps; |
466 | 467 | ||
467 | tps = container_of(client, struct tps65010, client); | 468 | tps = container_of(client, struct tps65010, client); |
469 | free_irq(tps->irq, tps); | ||
468 | #ifdef CONFIG_ARM | 470 | #ifdef CONFIG_ARM |
469 | if (machine_is_omap_h2()) | 471 | if (machine_is_omap_h2()) |
470 | omap_free_gpio(58); | 472 | omap_free_gpio(58); |
471 | if (machine_is_omap_osk()) | 473 | if (machine_is_omap_osk()) |
472 | omap_free_gpio(OMAP_MPUIO(1)); | 474 | omap_free_gpio(OMAP_MPUIO(1)); |
473 | #endif | 475 | #endif |
474 | free_irq(tps->irq, tps); | 476 | cancel_delayed_work(&tps->work); |
477 | flush_scheduled_work(); | ||
475 | debugfs_remove(tps->file); | 478 | debugfs_remove(tps->file); |
476 | if (i2c_detach_client(client) == 0) | 479 | if (i2c_detach_client(client) == 0) |
477 | kfree(tps); | 480 | kfree(tps); |
@@ -505,7 +508,7 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind) | |||
505 | return 0; | 508 | return 0; |
506 | 509 | ||
507 | mutex_init(&tps->lock); | 510 | mutex_init(&tps->lock); |
508 | INIT_WORK(&tps->work, tps65010_work, tps); | 511 | INIT_DELAYED_WORK(&tps->work, tps65010_work); |
509 | tps->irq = -1; | 512 | tps->irq = -1; |
510 | tps->client.addr = address; | 513 | tps->client.addr = address; |
511 | tps->client.adapter = bus; | 514 | tps->client.adapter = bus; |
@@ -620,7 +623,7 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind) | |||
620 | (void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK3, 0x0f | 623 | (void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK3, 0x0f |
621 | | i2c_smbus_read_byte_data(&tps->client, TPS_MASK3)); | 624 | | i2c_smbus_read_byte_data(&tps->client, TPS_MASK3)); |
622 | 625 | ||
623 | tps65010_work(tps); | 626 | tps65010_work(&tps->work.work); |
624 | 627 | ||
625 | tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, | 628 | tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, |
626 | tps, DEBUG_FOPS); | 629 | tps, DEBUG_FOPS); |
@@ -672,7 +675,7 @@ int tps65010_set_vbus_draw(unsigned mA) | |||
672 | && test_and_set_bit( | 675 | && test_and_set_bit( |
673 | FLAG_VBUS_CHANGED, &the_tps->flags)) { | 676 | FLAG_VBUS_CHANGED, &the_tps->flags)) { |
674 | /* gadget drivers call this in_irq() */ | 677 | /* gadget drivers call this in_irq() */ |
675 | (void) schedule_work(&the_tps->work); | 678 | (void) schedule_work(&the_tps->work.work); |
676 | } | 679 | } |
677 | local_irq_restore(flags); | 680 | local_irq_restore(flags); |
678 | 681 | ||
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 7ca81f42d14b..b05378a3d673 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -95,16 +95,32 @@ struct device_driver i2c_adapter_driver = { | |||
95 | .bus = &i2c_bus_type, | 95 | .bus = &i2c_bus_type, |
96 | }; | 96 | }; |
97 | 97 | ||
98 | /* ------------------------------------------------------------------------- */ | ||
99 | |||
100 | /* I2C bus adapters -- one roots each I2C or SMBUS segment */ | ||
101 | |||
98 | static void i2c_adapter_class_dev_release(struct class_device *dev) | 102 | static void i2c_adapter_class_dev_release(struct class_device *dev) |
99 | { | 103 | { |
100 | struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev); | 104 | struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev); |
101 | complete(&adap->class_dev_released); | 105 | complete(&adap->class_dev_released); |
102 | } | 106 | } |
103 | 107 | ||
108 | static ssize_t i2c_adapter_show_name(struct class_device *cdev, char *buf) | ||
109 | { | ||
110 | struct i2c_adapter *adap = class_dev_to_i2c_adapter(cdev); | ||
111 | return sprintf(buf, "%s\n", adap->name); | ||
112 | } | ||
113 | |||
114 | static struct class_device_attribute i2c_adapter_attrs[] = { | ||
115 | __ATTR(name, S_IRUGO, i2c_adapter_show_name, NULL), | ||
116 | { }, | ||
117 | }; | ||
118 | |||
104 | struct class i2c_adapter_class = { | 119 | struct class i2c_adapter_class = { |
105 | .owner = THIS_MODULE, | 120 | .owner = THIS_MODULE, |
106 | .name = "i2c-adapter", | 121 | .name = "i2c-adapter", |
107 | .release = &i2c_adapter_class_dev_release, | 122 | .class_dev_attrs = i2c_adapter_attrs, |
123 | .release = &i2c_adapter_class_dev_release, | ||
108 | }; | 124 | }; |
109 | 125 | ||
110 | static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) | 126 | static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) |
@@ -127,20 +143,17 @@ static ssize_t show_client_name(struct device *dev, struct device_attribute *att | |||
127 | return sprintf(buf, "%s\n", client->name); | 143 | return sprintf(buf, "%s\n", client->name); |
128 | } | 144 | } |
129 | 145 | ||
130 | /* | 146 | /* |
131 | * We can't use the DEVICE_ATTR() macro here as we want the same filename for a | 147 | * We can't use the DEVICE_ATTR() macro here, as we used the same name for |
132 | * different type of a device. So beware if the DEVICE_ATTR() macro ever | 148 | * an i2c adapter attribute (above). |
133 | * changes, this definition will also have to change. | ||
134 | */ | 149 | */ |
135 | static struct device_attribute dev_attr_client_name = { | 150 | static struct device_attribute dev_attr_client_name = |
136 | .attr = {.name = "name", .mode = S_IRUGO, .owner = THIS_MODULE }, | 151 | __ATTR(name, S_IRUGO, &show_client_name, NULL); |
137 | .show = &show_client_name, | ||
138 | }; | ||
139 | 152 | ||
140 | 153 | ||
141 | /* --------------------------------------------------- | 154 | /* --------------------------------------------------- |
142 | * registering functions | 155 | * registering functions |
143 | * --------------------------------------------------- | 156 | * --------------------------------------------------- |
144 | */ | 157 | */ |
145 | 158 | ||
146 | /* ----- | 159 | /* ----- |
@@ -178,8 +191,12 @@ int i2c_add_adapter(struct i2c_adapter *adap) | |||
178 | * If the parent pointer is not set up, | 191 | * If the parent pointer is not set up, |
179 | * we add this adapter to the host bus. | 192 | * we add this adapter to the host bus. |
180 | */ | 193 | */ |
181 | if (adap->dev.parent == NULL) | 194 | if (adap->dev.parent == NULL) { |
182 | adap->dev.parent = &platform_bus; | 195 | adap->dev.parent = &platform_bus; |
196 | printk(KERN_WARNING "**WARNING** I2C adapter driver [%s] " | ||
197 | "forgot to specify physical device; fix it!\n", | ||
198 | adap->name); | ||
199 | } | ||
183 | sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); | 200 | sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); |
184 | adap->dev.driver = &i2c_adapter_driver; | 201 | adap->dev.driver = &i2c_adapter_driver; |
185 | adap->dev.release = &i2c_adapter_dev_release; | 202 | adap->dev.release = &i2c_adapter_dev_release; |
@@ -314,7 +331,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
314 | res = driver_register(&driver->driver); | 331 | res = driver_register(&driver->driver); |
315 | if (res) | 332 | if (res) |
316 | return res; | 333 | return res; |
317 | 334 | ||
318 | mutex_lock(&core_lists); | 335 | mutex_lock(&core_lists); |
319 | 336 | ||
320 | list_add_tail(&driver->list,&drivers); | 337 | list_add_tail(&driver->list,&drivers); |
@@ -338,13 +355,13 @@ int i2c_del_driver(struct i2c_driver *driver) | |||
338 | struct list_head *item1, *item2, *_n; | 355 | struct list_head *item1, *item2, *_n; |
339 | struct i2c_client *client; | 356 | struct i2c_client *client; |
340 | struct i2c_adapter *adap; | 357 | struct i2c_adapter *adap; |
341 | 358 | ||
342 | int res = 0; | 359 | int res = 0; |
343 | 360 | ||
344 | mutex_lock(&core_lists); | 361 | mutex_lock(&core_lists); |
345 | 362 | ||
346 | /* Have a look at each adapter, if clients of this driver are still | 363 | /* Have a look at each adapter, if clients of this driver are still |
347 | * attached. If so, detach them to be able to kill the driver | 364 | * attached. If so, detach them to be able to kill the driver |
348 | * afterwards. | 365 | * afterwards. |
349 | */ | 366 | */ |
350 | list_for_each(item1,&adapters) { | 367 | list_for_each(item1,&adapters) { |
@@ -419,14 +436,14 @@ int i2c_attach_client(struct i2c_client *client) | |||
419 | goto out_unlock; | 436 | goto out_unlock; |
420 | } | 437 | } |
421 | list_add_tail(&client->list,&adapter->clients); | 438 | list_add_tail(&client->list,&adapter->clients); |
422 | 439 | ||
423 | client->usage_count = 0; | 440 | client->usage_count = 0; |
424 | 441 | ||
425 | client->dev.parent = &client->adapter->dev; | 442 | client->dev.parent = &client->adapter->dev; |
426 | client->dev.driver = &client->driver->driver; | 443 | client->dev.driver = &client->driver->driver; |
427 | client->dev.bus = &i2c_bus_type; | 444 | client->dev.bus = &i2c_bus_type; |
428 | client->dev.release = &i2c_client_release; | 445 | client->dev.release = &i2c_client_release; |
429 | 446 | ||
430 | snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), | 447 | snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), |
431 | "%d-%04x", i2c_adapter_id(adapter), client->addr); | 448 | "%d-%04x", i2c_adapter_id(adapter), client->addr); |
432 | dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", | 449 | dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", |
@@ -467,7 +484,7 @@ int i2c_detach_client(struct i2c_client *client) | |||
467 | { | 484 | { |
468 | struct i2c_adapter *adapter = client->adapter; | 485 | struct i2c_adapter *adapter = client->adapter; |
469 | int res = 0; | 486 | int res = 0; |
470 | 487 | ||
471 | if (client->usage_count > 0) { | 488 | if (client->usage_count > 0) { |
472 | dev_warn(&client->dev, "Client [%s] still busy, " | 489 | dev_warn(&client->dev, "Client [%s] still busy, " |
473 | "can't detach\n", client->name); | 490 | "can't detach\n", client->name); |
@@ -535,10 +552,10 @@ int i2c_release_client(struct i2c_client *client) | |||
535 | __FUNCTION__); | 552 | __FUNCTION__); |
536 | return -EPERM; | 553 | return -EPERM; |
537 | } | 554 | } |
538 | 555 | ||
539 | client->usage_count--; | 556 | client->usage_count--; |
540 | i2c_dec_use_client(client); | 557 | i2c_dec_use_client(client); |
541 | 558 | ||
542 | return 0; | 559 | return 0; |
543 | } | 560 | } |
544 | 561 | ||
@@ -603,7 +620,7 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num) | |||
603 | } | 620 | } |
604 | #endif | 621 | #endif |
605 | 622 | ||
606 | mutex_lock(&adap->bus_lock); | 623 | mutex_lock_nested(&adap->bus_lock, adap->level); |
607 | ret = adap->algo->master_xfer(adap,msgs,num); | 624 | ret = adap->algo->master_xfer(adap,msgs,num); |
608 | mutex_unlock(&adap->bus_lock); | 625 | mutex_unlock(&adap->bus_lock); |
609 | 626 | ||
@@ -624,7 +641,7 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count) | |||
624 | msg.flags = client->flags & I2C_M_TEN; | 641 | msg.flags = client->flags & I2C_M_TEN; |
625 | msg.len = count; | 642 | msg.len = count; |
626 | msg.buf = (char *)buf; | 643 | msg.buf = (char *)buf; |
627 | 644 | ||
628 | ret = i2c_transfer(adap, &msg, 1); | 645 | ret = i2c_transfer(adap, &msg, 1); |
629 | 646 | ||
630 | /* If everything went ok (i.e. 1 msg transmitted), return #bytes | 647 | /* If everything went ok (i.e. 1 msg transmitted), return #bytes |
@@ -757,7 +774,7 @@ int i2c_probe(struct i2c_adapter *adapter, | |||
757 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { | 774 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { |
758 | if (address_data->probe[0] == I2C_CLIENT_END | 775 | if (address_data->probe[0] == I2C_CLIENT_END |
759 | && address_data->normal_i2c[0] == I2C_CLIENT_END) | 776 | && address_data->normal_i2c[0] == I2C_CLIENT_END) |
760 | return 0; | 777 | return 0; |
761 | 778 | ||
762 | dev_warn(&adapter->dev, "SMBus Quick command not supported, " | 779 | dev_warn(&adapter->dev, "SMBus Quick command not supported, " |
763 | "can't probe for chips\n"); | 780 | "can't probe for chips\n"); |
@@ -817,7 +834,7 @@ int i2c_probe(struct i2c_adapter *adapter, | |||
817 | struct i2c_adapter* i2c_get_adapter(int id) | 834 | struct i2c_adapter* i2c_get_adapter(int id) |
818 | { | 835 | { |
819 | struct i2c_adapter *adapter; | 836 | struct i2c_adapter *adapter; |
820 | 837 | ||
821 | mutex_lock(&core_lists); | 838 | mutex_lock(&core_lists); |
822 | adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); | 839 | adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); |
823 | if (adapter && !try_module_get(adapter->owner)) | 840 | if (adapter && !try_module_get(adapter->owner)) |
@@ -834,14 +851,14 @@ void i2c_put_adapter(struct i2c_adapter *adap) | |||
834 | 851 | ||
835 | /* The SMBus parts */ | 852 | /* The SMBus parts */ |
836 | 853 | ||
837 | #define POLY (0x1070U << 3) | 854 | #define POLY (0x1070U << 3) |
838 | static u8 | 855 | static u8 |
839 | crc8(u16 data) | 856 | crc8(u16 data) |
840 | { | 857 | { |
841 | int i; | 858 | int i; |
842 | 859 | ||
843 | for(i = 0; i < 8; i++) { | 860 | for(i = 0; i < 8; i++) { |
844 | if (data & 0x8000) | 861 | if (data & 0x8000) |
845 | data = data ^ POLY; | 862 | data = data ^ POLY; |
846 | data = data << 1; | 863 | data = data << 1; |
847 | } | 864 | } |
@@ -891,13 +908,13 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg) | |||
891 | rpec, cpec); | 908 | rpec, cpec); |
892 | return -1; | 909 | return -1; |
893 | } | 910 | } |
894 | return 0; | 911 | return 0; |
895 | } | 912 | } |
896 | 913 | ||
897 | s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value) | 914 | s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value) |
898 | { | 915 | { |
899 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 916 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, |
900 | value,0,I2C_SMBUS_QUICK,NULL); | 917 | value,0,I2C_SMBUS_QUICK,NULL); |
901 | } | 918 | } |
902 | 919 | ||
903 | s32 i2c_smbus_read_byte(struct i2c_client *client) | 920 | s32 i2c_smbus_read_byte(struct i2c_client *client) |
@@ -996,11 +1013,11 @@ s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, | |||
996 | I2C_SMBUS_I2C_BLOCK_DATA, &data); | 1013 | I2C_SMBUS_I2C_BLOCK_DATA, &data); |
997 | } | 1014 | } |
998 | 1015 | ||
999 | /* Simulate a SMBus command using the i2c protocol | 1016 | /* Simulate a SMBus command using the i2c protocol |
1000 | No checking of parameters is done! */ | 1017 | No checking of parameters is done! */ |
1001 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | 1018 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, |
1002 | unsigned short flags, | 1019 | unsigned short flags, |
1003 | char read_write, u8 command, int size, | 1020 | char read_write, u8 command, int size, |
1004 | union i2c_smbus_data * data) | 1021 | union i2c_smbus_data * data) |
1005 | { | 1022 | { |
1006 | /* So we need to generate a series of msgs. In the case of writing, we | 1023 | /* So we need to generate a series of msgs. In the case of writing, we |
@@ -1010,7 +1027,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1010 | unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; | 1027 | unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; |
1011 | unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; | 1028 | unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; |
1012 | int num = read_write == I2C_SMBUS_READ?2:1; | 1029 | int num = read_write == I2C_SMBUS_READ?2:1; |
1013 | struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, | 1030 | struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, |
1014 | { addr, flags | I2C_M_RD, 0, msgbuf1 } | 1031 | { addr, flags | I2C_M_RD, 0, msgbuf1 } |
1015 | }; | 1032 | }; |
1016 | int i; | 1033 | int i; |
@@ -1103,14 +1120,14 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1103 | if (i) { | 1120 | if (i) { |
1104 | /* Compute PEC if first message is a write */ | 1121 | /* Compute PEC if first message is a write */ |
1105 | if (!(msg[0].flags & I2C_M_RD)) { | 1122 | if (!(msg[0].flags & I2C_M_RD)) { |
1106 | if (num == 1) /* Write only */ | 1123 | if (num == 1) /* Write only */ |
1107 | i2c_smbus_add_pec(&msg[0]); | 1124 | i2c_smbus_add_pec(&msg[0]); |
1108 | else /* Write followed by read */ | 1125 | else /* Write followed by read */ |
1109 | partial_pec = i2c_smbus_msg_pec(0, &msg[0]); | 1126 | partial_pec = i2c_smbus_msg_pec(0, &msg[0]); |
1110 | } | 1127 | } |
1111 | /* Ask for PEC if last message is a read */ | 1128 | /* Ask for PEC if last message is a read */ |
1112 | if (msg[num-1].flags & I2C_M_RD) | 1129 | if (msg[num-1].flags & I2C_M_RD) |
1113 | msg[num-1].len++; | 1130 | msg[num-1].len++; |
1114 | } | 1131 | } |
1115 | 1132 | ||
1116 | if (i2c_transfer(adapter, msg, num) < 0) | 1133 | if (i2c_transfer(adapter, msg, num) < 0) |
@@ -1130,7 +1147,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1130 | case I2C_SMBUS_BYTE_DATA: | 1147 | case I2C_SMBUS_BYTE_DATA: |
1131 | data->byte = msgbuf1[0]; | 1148 | data->byte = msgbuf1[0]; |
1132 | break; | 1149 | break; |
1133 | case I2C_SMBUS_WORD_DATA: | 1150 | case I2C_SMBUS_WORD_DATA: |
1134 | case I2C_SMBUS_PROC_CALL: | 1151 | case I2C_SMBUS_PROC_CALL: |
1135 | data->word = msgbuf1[0] | (msgbuf1[1] << 8); | 1152 | data->word = msgbuf1[0] | (msgbuf1[1] << 8); |
1136 | break; | 1153 | break; |
@@ -1146,7 +1163,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1146 | 1163 | ||
1147 | 1164 | ||
1148 | s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, | 1165 | s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, |
1149 | char read_write, u8 command, int size, | 1166 | char read_write, u8 command, int size, |
1150 | union i2c_smbus_data * data) | 1167 | union i2c_smbus_data * data) |
1151 | { | 1168 | { |
1152 | s32 res; | 1169 | s32 res; |
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 3f869033ed70..ac5bd2a7ca99 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | i2c-dev.c - i2c-bus driver, char device interface | 2 | i2c-dev.c - i2c-bus driver, char device interface |
3 | 3 | ||
4 | Copyright (C) 1995-97 Simon G. Vogl | 4 | Copyright (C) 1995-97 Simon G. Vogl |
5 | Copyright (C) 1998-99 Frodo Looijaard <frodol@dds.nl> | 5 | Copyright (C) 1998-99 Frodo Looijaard <frodol@dds.nl> |
@@ -42,7 +42,7 @@ static struct i2c_driver i2cdev_driver; | |||
42 | struct i2c_dev { | 42 | struct i2c_dev { |
43 | struct list_head list; | 43 | struct list_head list; |
44 | struct i2c_adapter *adap; | 44 | struct i2c_adapter *adap; |
45 | struct class_device *class_dev; | 45 | struct device *dev; |
46 | }; | 46 | }; |
47 | 47 | ||
48 | #define I2C_MINORS 256 | 48 | #define I2C_MINORS 256 |
@@ -90,17 +90,19 @@ static void return_i2c_dev(struct i2c_dev *i2c_dev) | |||
90 | spin_lock(&i2c_dev_list_lock); | 90 | spin_lock(&i2c_dev_list_lock); |
91 | list_del(&i2c_dev->list); | 91 | list_del(&i2c_dev->list); |
92 | spin_unlock(&i2c_dev_list_lock); | 92 | spin_unlock(&i2c_dev_list_lock); |
93 | kfree(i2c_dev); | ||
93 | } | 94 | } |
94 | 95 | ||
95 | static ssize_t show_adapter_name(struct class_device *class_dev, char *buf) | 96 | static ssize_t show_adapter_name(struct device *dev, |
97 | struct device_attribute *attr, char *buf) | ||
96 | { | 98 | { |
97 | struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(class_dev->devt)); | 99 | struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(dev->devt)); |
98 | 100 | ||
99 | if (!i2c_dev) | 101 | if (!i2c_dev) |
100 | return -ENODEV; | 102 | return -ENODEV; |
101 | return sprintf(buf, "%s\n", i2c_dev->adap->name); | 103 | return sprintf(buf, "%s\n", i2c_dev->adap->name); |
102 | } | 104 | } |
103 | static CLASS_DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); | 105 | static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); |
104 | 106 | ||
105 | static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, | 107 | static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, |
106 | loff_t *offset) | 108 | loff_t *offset) |
@@ -118,7 +120,7 @@ static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, | |||
118 | return -ENOMEM; | 120 | return -ENOMEM; |
119 | 121 | ||
120 | pr_debug("i2c-dev: i2c-%d reading %zd bytes.\n", | 122 | pr_debug("i2c-dev: i2c-%d reading %zd bytes.\n", |
121 | iminor(file->f_dentry->d_inode), count); | 123 | iminor(file->f_path.dentry->d_inode), count); |
122 | 124 | ||
123 | ret = i2c_master_recv(client,tmp,count); | 125 | ret = i2c_master_recv(client,tmp,count); |
124 | if (ret >= 0) | 126 | if (ret >= 0) |
@@ -146,7 +148,7 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c | |||
146 | } | 148 | } |
147 | 149 | ||
148 | pr_debug("i2c-dev: i2c-%d writing %zd bytes.\n", | 150 | pr_debug("i2c-dev: i2c-%d writing %zd bytes.\n", |
149 | iminor(file->f_dentry->d_inode), count); | 151 | iminor(file->f_path.dentry->d_inode), count); |
150 | 152 | ||
151 | ret = i2c_master_send(client,tmp,count); | 153 | ret = i2c_master_send(client,tmp,count); |
152 | kfree(tmp); | 154 | kfree(tmp); |
@@ -171,7 +173,7 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file, | |||
171 | switch ( cmd ) { | 173 | switch ( cmd ) { |
172 | case I2C_SLAVE: | 174 | case I2C_SLAVE: |
173 | case I2C_SLAVE_FORCE: | 175 | case I2C_SLAVE_FORCE: |
174 | if ((arg > 0x3ff) || | 176 | if ((arg > 0x3ff) || |
175 | (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) | 177 | (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) |
176 | return -EINVAL; | 178 | return -EINVAL; |
177 | if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) | 179 | if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) |
@@ -192,12 +194,11 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file, | |||
192 | return 0; | 194 | return 0; |
193 | case I2C_FUNCS: | 195 | case I2C_FUNCS: |
194 | funcs = i2c_get_functionality(client->adapter); | 196 | funcs = i2c_get_functionality(client->adapter); |
195 | return (copy_to_user((unsigned long __user *)arg, &funcs, | 197 | return put_user(funcs, (unsigned long __user *)arg); |
196 | sizeof(unsigned long)))?-EFAULT:0; | ||
197 | 198 | ||
198 | case I2C_RDWR: | 199 | case I2C_RDWR: |
199 | if (copy_from_user(&rdwr_arg, | 200 | if (copy_from_user(&rdwr_arg, |
200 | (struct i2c_rdwr_ioctl_data __user *)arg, | 201 | (struct i2c_rdwr_ioctl_data __user *)arg, |
201 | sizeof(rdwr_arg))) | 202 | sizeof(rdwr_arg))) |
202 | return -EFAULT; | 203 | return -EFAULT; |
203 | 204 | ||
@@ -205,9 +206,9 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file, | |||
205 | * be sent at once */ | 206 | * be sent at once */ |
206 | if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) | 207 | if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) |
207 | return -EINVAL; | 208 | return -EINVAL; |
208 | 209 | ||
209 | rdwr_pa = (struct i2c_msg *) | 210 | rdwr_pa = (struct i2c_msg *) |
210 | kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), | 211 | kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), |
211 | GFP_KERNEL); | 212 | GFP_KERNEL); |
212 | 213 | ||
213 | if (rdwr_pa == NULL) return -ENOMEM; | 214 | if (rdwr_pa == NULL) return -ENOMEM; |
@@ -277,9 +278,9 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file, | |||
277 | (struct i2c_smbus_ioctl_data __user *) arg, | 278 | (struct i2c_smbus_ioctl_data __user *) arg, |
278 | sizeof(struct i2c_smbus_ioctl_data))) | 279 | sizeof(struct i2c_smbus_ioctl_data))) |
279 | return -EFAULT; | 280 | return -EFAULT; |
280 | if ((data_arg.size != I2C_SMBUS_BYTE) && | 281 | if ((data_arg.size != I2C_SMBUS_BYTE) && |
281 | (data_arg.size != I2C_SMBUS_QUICK) && | 282 | (data_arg.size != I2C_SMBUS_QUICK) && |
282 | (data_arg.size != I2C_SMBUS_BYTE_DATA) && | 283 | (data_arg.size != I2C_SMBUS_BYTE_DATA) && |
283 | (data_arg.size != I2C_SMBUS_WORD_DATA) && | 284 | (data_arg.size != I2C_SMBUS_WORD_DATA) && |
284 | (data_arg.size != I2C_SMBUS_PROC_CALL) && | 285 | (data_arg.size != I2C_SMBUS_PROC_CALL) && |
285 | (data_arg.size != I2C_SMBUS_BLOCK_DATA) && | 286 | (data_arg.size != I2C_SMBUS_BLOCK_DATA) && |
@@ -290,11 +291,11 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file, | |||
290 | data_arg.size); | 291 | data_arg.size); |
291 | return -EINVAL; | 292 | return -EINVAL; |
292 | } | 293 | } |
293 | /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1, | 294 | /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1, |
294 | so the check is valid if size==I2C_SMBUS_QUICK too. */ | 295 | so the check is valid if size==I2C_SMBUS_QUICK too. */ |
295 | if ((data_arg.read_write != I2C_SMBUS_READ) && | 296 | if ((data_arg.read_write != I2C_SMBUS_READ) && |
296 | (data_arg.read_write != I2C_SMBUS_WRITE)) { | 297 | (data_arg.read_write != I2C_SMBUS_WRITE)) { |
297 | dev_dbg(&client->adapter->dev, | 298 | dev_dbg(&client->adapter->dev, |
298 | "read_write out of range (%x) in ioctl I2C_SMBUS.\n", | 299 | "read_write out of range (%x) in ioctl I2C_SMBUS.\n", |
299 | data_arg.read_write); | 300 | data_arg.read_write); |
300 | return -EINVAL; | 301 | return -EINVAL; |
@@ -303,7 +304,7 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file, | |||
303 | /* Note that command values are always valid! */ | 304 | /* Note that command values are always valid! */ |
304 | 305 | ||
305 | if ((data_arg.size == I2C_SMBUS_QUICK) || | 306 | if ((data_arg.size == I2C_SMBUS_QUICK) || |
306 | ((data_arg.size == I2C_SMBUS_BYTE) && | 307 | ((data_arg.size == I2C_SMBUS_BYTE) && |
307 | (data_arg.read_write == I2C_SMBUS_WRITE))) | 308 | (data_arg.read_write == I2C_SMBUS_WRITE))) |
308 | /* These are special: we do not use data */ | 309 | /* These are special: we do not use data */ |
309 | return i2c_smbus_xfer(client->adapter, client->addr, | 310 | return i2c_smbus_xfer(client->adapter, client->addr, |
@@ -321,14 +322,14 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file, | |||
321 | if ((data_arg.size == I2C_SMBUS_BYTE_DATA) || | 322 | if ((data_arg.size == I2C_SMBUS_BYTE_DATA) || |
322 | (data_arg.size == I2C_SMBUS_BYTE)) | 323 | (data_arg.size == I2C_SMBUS_BYTE)) |
323 | datasize = sizeof(data_arg.data->byte); | 324 | datasize = sizeof(data_arg.data->byte); |
324 | else if ((data_arg.size == I2C_SMBUS_WORD_DATA) || | 325 | else if ((data_arg.size == I2C_SMBUS_WORD_DATA) || |
325 | (data_arg.size == I2C_SMBUS_PROC_CALL)) | 326 | (data_arg.size == I2C_SMBUS_PROC_CALL)) |
326 | datasize = sizeof(data_arg.data->word); | 327 | datasize = sizeof(data_arg.data->word); |
327 | else /* size == smbus block, i2c block, or block proc. call */ | 328 | else /* size == smbus block, i2c block, or block proc. call */ |
328 | datasize = sizeof(data_arg.data->block); | 329 | datasize = sizeof(data_arg.data->block); |
329 | 330 | ||
330 | if ((data_arg.size == I2C_SMBUS_PROC_CALL) || | 331 | if ((data_arg.size == I2C_SMBUS_PROC_CALL) || |
331 | (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || | 332 | (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || |
332 | (data_arg.read_write == I2C_SMBUS_WRITE)) { | 333 | (data_arg.read_write == I2C_SMBUS_WRITE)) { |
333 | if (copy_from_user(&temp, data_arg.data, datasize)) | 334 | if (copy_from_user(&temp, data_arg.data, datasize)) |
334 | return -EFAULT; | 335 | return -EFAULT; |
@@ -336,8 +337,8 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file, | |||
336 | res = i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 337 | res = i2c_smbus_xfer(client->adapter,client->addr,client->flags, |
337 | data_arg.read_write, | 338 | data_arg.read_write, |
338 | data_arg.command,data_arg.size,&temp); | 339 | data_arg.command,data_arg.size,&temp); |
339 | if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || | 340 | if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || |
340 | (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || | 341 | (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || |
341 | (data_arg.read_write == I2C_SMBUS_READ))) { | 342 | (data_arg.read_write == I2C_SMBUS_READ))) { |
342 | if (copy_to_user(data_arg.data, &temp, datasize)) | 343 | if (copy_to_user(data_arg.data, &temp, datasize)) |
343 | return -EFAULT; | 344 | return -EFAULT; |
@@ -413,15 +414,14 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap) | |||
413 | return PTR_ERR(i2c_dev); | 414 | return PTR_ERR(i2c_dev); |
414 | 415 | ||
415 | /* register this i2c device with the driver core */ | 416 | /* register this i2c device with the driver core */ |
416 | i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL, | 417 | i2c_dev->dev = device_create(i2c_dev_class, &adap->dev, |
417 | MKDEV(I2C_MAJOR, adap->nr), | 418 | MKDEV(I2C_MAJOR, adap->nr), |
418 | &adap->dev, "i2c-%d", | 419 | "i2c-%d", adap->nr); |
419 | adap->nr); | 420 | if (IS_ERR(i2c_dev->dev)) { |
420 | if (!i2c_dev->class_dev) { | 421 | res = PTR_ERR(i2c_dev->dev); |
421 | res = -ENODEV; | ||
422 | goto error; | 422 | goto error; |
423 | } | 423 | } |
424 | res = class_device_create_file(i2c_dev->class_dev, &class_device_attr_name); | 424 | res = device_create_file(i2c_dev->dev, &dev_attr_name); |
425 | if (res) | 425 | if (res) |
426 | goto error_destroy; | 426 | goto error_destroy; |
427 | 427 | ||
@@ -429,10 +429,9 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap) | |||
429 | adap->name, adap->nr); | 429 | adap->name, adap->nr); |
430 | return 0; | 430 | return 0; |
431 | error_destroy: | 431 | error_destroy: |
432 | class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); | 432 | device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); |
433 | error: | 433 | error: |
434 | return_i2c_dev(i2c_dev); | 434 | return_i2c_dev(i2c_dev); |
435 | kfree(i2c_dev); | ||
436 | return res; | 435 | return res; |
437 | } | 436 | } |
438 | 437 | ||
@@ -444,10 +443,9 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap) | |||
444 | if (!i2c_dev) /* attach_adapter must have failed */ | 443 | if (!i2c_dev) /* attach_adapter must have failed */ |
445 | return 0; | 444 | return 0; |
446 | 445 | ||
447 | class_device_remove_file(i2c_dev->class_dev, &class_device_attr_name); | 446 | device_remove_file(i2c_dev->dev, &dev_attr_name); |
448 | return_i2c_dev(i2c_dev); | 447 | return_i2c_dev(i2c_dev); |
449 | class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); | 448 | device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); |
450 | kfree(i2c_dev); | ||
451 | 449 | ||
452 | pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); | 450 | pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); |
453 | return 0; | 451 | return 0; |