brute-forced more changes from MontaVista's tree. SCSI partition table read still...
[linux-2.4.git] / drivers / i2c / i2c-core.c
1 /* i2c-core.c - a device driver for the iic-bus interface                    */
2 /* ------------------------------------------------------------------------- */
3 /*   Copyright (C) 1995-99 Simon G. Vogl
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
18 /* ------------------------------------------------------------------------- */
19
20 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
21    All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */
22
23 /* $Id: i2c-core.c,v 1.64 2001/08/13 01:35:56 mds Exp $ */
24
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/slab.h>
29 #include <linux/proc_fs.h>
30 #include <linux/config.h>
31
32 #include <linux/i2c.h>
33
34 /* ----- compatibility stuff ----------------------------------------------- */
35
36 #include <linux/init.h>
37
38 #include <asm/uaccess.h>
39
40 /* ----- global defines ---------------------------------------------------- */
41
42 /* exclusive access to the bus */
43 #define I2C_LOCK(adap) down(&adap->lock)
44 #define I2C_UNLOCK(adap) up(&adap->lock) 
45
46 #define ADAP_LOCK()     down(&adap_lock)
47 #define ADAP_UNLOCK()   up(&adap_lock)
48
49 #define DRV_LOCK()      down(&driver_lock)
50 #define DRV_UNLOCK()    up(&driver_lock)
51
52 #define DEB(x) if (i2c_debug>=1) x;
53 #define DEB2(x) if (i2c_debug>=2) x;
54
55 /* ----- global variables -------------------------------------------------- */
56
57 /**** lock for writing to global variables: the adapter & driver list */
58 struct semaphore adap_lock;
59 struct semaphore driver_lock;
60
61 /**** adapter list */
62 static struct i2c_adapter *adapters[I2C_ADAP_MAX];
63 static int adap_count;
64
65 /**** drivers list */
66 static struct i2c_driver *drivers[I2C_DRIVER_MAX];
67 static int driver_count;
68
69 /**** debug level */
70 static int i2c_debug=1;
71
72 /* ---------------------------------------------------
73  * /proc entry declarations
74  *----------------------------------------------------
75  */
76
77 #ifdef CONFIG_PROC_FS
78
79 static int i2cproc_init(void);
80 static int i2cproc_cleanup(void);
81
82 static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, 
83                                 loff_t *ppos);
84 static int read_bus_i2c(char *buf, char **start, off_t offset, int len,
85                            int *eof , void *private);
86
87 /* To implement the dynamic /proc/bus/i2c-? files, we need our own 
88    implementation of the read hook */
89 static struct file_operations i2cproc_operations = {
90         .read           = i2cproc_bus_read,
91 };
92
93 static int i2cproc_initialized = 0;
94
95 #else /* undef CONFIG_PROC_FS */
96
97 #define i2cproc_init() 0
98 #define i2cproc_cleanup() 0
99
100 #endif /* CONFIG_PROC_FS */
101
102
103 /* ---------------------------------------------------
104  * registering functions 
105  * --------------------------------------------------- 
106  */
107
108 /* -----
109  * i2c_add_adapter is called from within the algorithm layer,
110  * when a new hw adapter registers. A new device is register to be
111  * available for clients.
112  */
113 int i2c_add_adapter(struct i2c_adapter *adap)
114 {
115         int i,j,res;
116
117         ADAP_LOCK();
118         for (i = 0; i < I2C_ADAP_MAX; i++)
119                 if (NULL == adapters[i])
120                         break;
121         if (I2C_ADAP_MAX == i) {
122                 printk(KERN_WARNING 
123                        " i2c-core.o: register_adapter(%s) - enlarge I2C_ADAP_MAX.\n",
124                         adap->name);
125                 res = -ENOMEM;
126                 goto ERROR0;
127         }
128
129         adapters[i] = adap;
130         adap_count++;
131         ADAP_UNLOCK();
132         
133         /* init data types */
134         init_MUTEX(&adap->lock);
135
136 #ifdef CONFIG_PROC_FS
137
138         if (i2cproc_initialized) {
139                 char name[8];
140                 struct proc_dir_entry *proc_entry;
141
142                 sprintf(name,"i2c-%d", i);
143
144                 proc_entry = create_proc_entry(name,0,proc_bus);
145                 if (! proc_entry) {
146                         printk("i2c-core.o: Could not create /proc/bus/%s\n",
147                                name);
148                         res = -ENOENT;
149                         goto ERROR1;
150                 }
151
152                 proc_entry->proc_fops = &i2cproc_operations;
153                 proc_entry->owner = THIS_MODULE;
154                 adap->inode = proc_entry->low_ino;
155         }
156
157 #endif /* def CONFIG_PROC_FS */
158
159         /* inform drivers of new adapters */
160         DRV_LOCK();     
161         for (j=0;j<I2C_DRIVER_MAX;j++)
162                 if (drivers[j]!=NULL && 
163                     (drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY)))
164                         /* We ignore the return code; if it fails, too bad */
165                         drivers[j]->attach_adapter(adap);
166         DRV_UNLOCK();
167         
168         DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
169                    adap->name,i));
170
171         return 0;       
172
173
174 ERROR1:
175         ADAP_LOCK();
176         adapters[i] = NULL;
177         adap_count--;
178 ERROR0:
179         ADAP_UNLOCK();
180         return res;
181 }
182
183
184 int i2c_del_adapter(struct i2c_adapter *adap)
185 {
186         int i,j,res;
187
188         ADAP_LOCK();
189
190         for (i = 0; i < I2C_ADAP_MAX; i++)
191                 if (adap == adapters[i])
192                         break;
193         if (I2C_ADAP_MAX == i) {
194                 printk(KERN_WARNING "i2c-core.o: unregister_adapter adap [%s] not found.\n",
195                         adap->name);
196                 res = -ENODEV;
197                 goto ERROR0;
198         }
199
200         /* DUMMY drivers do not register their clients, so we have to
201          * use a trick here: we call driver->attach_adapter to
202          * *detach* it! Of course, each dummy driver should know about
203          * this or hell will break loose...
204          */
205         DRV_LOCK();
206         for (j = 0; j < I2C_DRIVER_MAX; j++) 
207                 if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY))
208                         if ((res = drivers[j]->attach_adapter(adap))) {
209                                 printk(KERN_WARNING "i2c-core.o: can't detach adapter %s "
210                                        "while detaching driver %s: driver not "
211                                        "detached!\n", adap->name, drivers[j]->name);
212                                 goto ERROR1;    
213                         }
214         DRV_UNLOCK();
215
216
217         /* detach any active clients. This must be done first, because
218          * it can fail; in which case we give up. */
219         for (j=0;j<I2C_CLIENT_MAX;j++) {
220                 struct i2c_client *client = adap->clients[j];
221                 if (client!=NULL)
222                     /* detaching devices is unconditional of the set notify
223                      * flag, as _all_ clients that reside on the adapter
224                      * must be deleted, as this would cause invalid states.
225                      */
226                         if ((res=client->driver->detach_client(client))) {
227                                 printk(KERN_ERR "i2c-core.o: adapter %s not "
228                                         "unregistered, because client at "
229                                         "address %02x can't be detached\n",
230                                         adap->name, client->addr);
231                                 goto ERROR0;
232                         }
233         }
234
235 #ifdef CONFIG_PROC_FS
236         if (i2cproc_initialized) {
237                 char name[8];
238                 sprintf(name,"i2c-%d", i);
239                 remove_proc_entry(name,proc_bus);
240         }
241 #endif /* def CONFIG_PROC_FS */
242
243         adapters[i] = NULL;
244         adap_count--;
245         
246         ADAP_UNLOCK();  
247         DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
248         return 0;
249
250 ERROR0:
251         ADAP_UNLOCK();
252         return res;
253 ERROR1:
254         DRV_UNLOCK();
255         return res;
256 }
257
258
259 /* -----
260  * What follows is the "upwards" interface: commands for talking to clients,
261  * which implement the functions to access the physical information of the
262  * chips.
263  */
264
265 int i2c_add_driver(struct i2c_driver *driver)
266 {
267         int i;
268         DRV_LOCK();
269         for (i = 0; i < I2C_DRIVER_MAX; i++)
270                 if (NULL == drivers[i])
271                         break;
272         if (I2C_DRIVER_MAX == i) {
273                 printk(KERN_WARNING 
274                        " i2c-core.o: register_driver(%s) "
275                        "- enlarge I2C_DRIVER_MAX.\n",
276                         driver->name);
277                 DRV_UNLOCK();
278                 return -ENOMEM;
279         }
280
281         drivers[i] = driver;
282         driver_count++;
283         
284         DRV_UNLOCK();   /* driver was successfully added */
285         
286         DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
287         
288         ADAP_LOCK();
289
290         /* now look for instances of driver on our adapters
291          */
292         if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
293                 for (i=0;i<I2C_ADAP_MAX;i++)
294                         if (adapters[i]!=NULL)
295                                 /* Ignore errors */
296                                 driver->attach_adapter(adapters[i]);
297         }
298         ADAP_UNLOCK();
299         return 0;
300 }
301
302 int i2c_del_driver(struct i2c_driver *driver)
303 {
304         int i,j,k,res;
305
306         DRV_LOCK();
307         for (i = 0; i < I2C_DRIVER_MAX; i++)
308                 if (driver == drivers[i])
309                         break;
310         if (I2C_DRIVER_MAX == i) {
311                 printk(KERN_WARNING " i2c-core.o: unregister_driver: "
312                                     "[%s] not found\n",
313                         driver->name);
314                 DRV_UNLOCK();
315                 return -ENODEV;
316         }
317         /* Have a look at each adapter, if clients of this driver are still
318          * attached. If so, detach them to be able to kill the driver 
319          * afterwards.
320          */
321         DEB2(printk(KERN_DEBUG "i2c-core.o: unregister_driver - looking for clients.\n"));
322         /* removing clients does not depend on the notify flag, else 
323          * invalid operation might (will!) result, when using stale client
324          * pointers.
325          */
326         ADAP_LOCK(); /* should be moved inside the if statement... */
327         for (k=0;k<I2C_ADAP_MAX;k++) {
328                 struct i2c_adapter *adap = adapters[k];
329                 if (adap == NULL) /* skip empty entries. */
330                         continue;
331                 DEB2(printk(KERN_DEBUG "i2c-core.o: examining adapter %s:\n",
332                             adap->name));
333                 if (driver->flags & I2C_DF_DUMMY) {
334                 /* DUMMY drivers do not register their clients, so we have to
335                  * use a trick here: we call driver->attach_adapter to
336                  * *detach* it! Of course, each dummy driver should know about
337                  * this or hell will break loose...  
338                  */
339                         if ((res = driver->attach_adapter(adap))) {
340                                 printk(KERN_WARNING "i2c-core.o: while unregistering "
341                                        "dummy driver %s, adapter %s could "
342                                        "not be detached properly; driver "
343                                        "not unloaded!\n", driver->name,
344                                        adap->name);
345                                 ADAP_UNLOCK();
346                                 return res;
347                         }
348                 } else {
349                         for (j=0;j<I2C_CLIENT_MAX;j++) { 
350                                 struct i2c_client *client = adap->clients[j];
351                                 if (client != NULL && 
352                                     client->driver == driver) {
353                                         DEB2(printk(KERN_DEBUG "i2c-core.o: "
354                                                     "detaching client %s:\n",
355                                                     client->name));
356                                         if ((res = driver->
357                                                         detach_client(client)))
358                                         {
359                                                 printk(KERN_ERR "i2c-core.o: while "
360                                                        "unregistering driver "
361                                                        "`%s', the client at "
362                                                        "address %02x of "
363                                                        "adapter `%s' could not "
364                                                        "be detached; driver "
365                                                        "not unloaded!\n",
366                                                        driver->name,
367                                                        client->addr,
368                                                        adap->name);
369                                                 ADAP_UNLOCK();
370                                                 return res;
371                                         }
372                                 }
373                         }
374                 }
375         }
376         ADAP_UNLOCK();
377         drivers[i] = NULL;
378         driver_count--;
379         DRV_UNLOCK();
380         
381         DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
382         return 0;
383 }
384
385 int i2c_check_addr (struct i2c_adapter *adapter, int addr)
386 {
387         int i;
388         for (i = 0; i < I2C_CLIENT_MAX ; i++) 
389                 if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
390                         return -EBUSY;
391         return 0;
392 }
393
394 int i2c_attach_client(struct i2c_client *client)
395 {
396         struct i2c_adapter *adapter = client->adapter;
397         int i;
398
399         if (i2c_check_addr(client->adapter,client->addr))
400                 return -EBUSY;
401
402         for (i = 0; i < I2C_CLIENT_MAX; i++)
403                 if (NULL == adapter->clients[i])
404                         break;
405         if (I2C_CLIENT_MAX == i) {
406                 printk(KERN_WARNING 
407                        " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
408                         client->name);
409                 return -ENOMEM;
410         }
411
412         adapter->clients[i] = client;
413         adapter->client_count++;
414         
415         if (adapter->client_register) 
416                 if (adapter->client_register(client)) 
417                         printk(KERN_DEBUG "i2c-core.o: warning: client_register seems "
418                                "to have failed for client %02x at adapter %s\n",
419                                client->addr,adapter->name);
420         DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
421                 client->name, adapter->name,i));
422
423         if(client->flags & I2C_CLIENT_ALLOW_USE)
424                 client->usage_count = 0;
425         
426         return 0;
427 }
428
429
430 int i2c_detach_client(struct i2c_client *client)
431 {
432         struct i2c_adapter *adapter = client->adapter;
433         int i,res;
434
435         for (i = 0; i < I2C_CLIENT_MAX; i++)
436                 if (client == adapter->clients[i])
437                         break;
438         if (I2C_CLIENT_MAX == i) {
439                 printk(KERN_WARNING " i2c-core.o: unregister_client "
440                                     "[%s] not found\n",
441                         client->name);
442                 return -ENODEV;
443         }
444         
445         if( (client->flags & I2C_CLIENT_ALLOW_USE) && 
446             (client->usage_count>0))
447                 return -EBUSY;
448         
449         if (adapter->client_unregister != NULL) 
450                 if ((res = adapter->client_unregister(client))) {
451                         printk(KERN_ERR "i2c-core.o: client_unregister [%s] failed, "
452                                "client not detached\n", client->name);
453                         return res;
454                 }
455
456         adapter->clients[i] = NULL;
457         adapter->client_count--;
458
459         DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name));
460         return 0;
461 }
462
463 void i2c_inc_use_client(struct i2c_client *client)
464 {
465         if (client->driver->inc_use != NULL)
466                 client->driver->inc_use(client);
467         if (client->adapter->inc_use != NULL)
468                 client->adapter->inc_use(client->adapter);
469 }
470
471 void i2c_dec_use_client(struct i2c_client *client)
472 {
473         if (client->driver->dec_use != NULL)
474                 client->driver->dec_use(client);
475         if (client->adapter->dec_use != NULL)
476                 client->adapter->dec_use(client->adapter);
477 }
478
479 struct i2c_client *i2c_get_client(int driver_id, int adapter_id, 
480                                         struct i2c_client *prev)
481 {
482         int i,j;
483         
484         /* Will iterate through the list of clients in each adapter of adapters-list
485            in search for a client that matches the search criteria. driver_id or 
486            adapter_id are ignored if set to 0. If both are ignored this returns 
487            first client found. */
488         
489         i = j = 0;  
490         
491         /* set starting point */ 
492         if(prev)
493         {
494                 if(!(prev->adapter))
495                         return (struct i2c_client *) -EINVAL;
496                 
497                 for(j=0; j < I2C_ADAP_MAX; j++)
498                         if(prev->adapter == adapters[j])
499                                 break;
500                 
501                 /* invalid starting point? */
502                 if (I2C_ADAP_MAX == j) {
503                         printk(KERN_WARNING " i2c-core.o: get_client adapter for client:[%s] not found\n",
504                                 prev->name);
505                         return (struct i2c_client *) -ENODEV;
506                 }       
507                 
508                 for(i=0; i < I2C_CLIENT_MAX; i++)
509                         if(prev == adapters[j]->clients[i])
510                                 break;
511                 
512                 /* invalid starting point? */
513                 if (I2C_CLIENT_MAX == i) {
514                         printk(KERN_WARNING " i2c-core.o: get_client client:[%s] not found\n",
515                                 prev->name);
516                         return (struct i2c_client *) -ENODEV;
517                 }       
518                 
519                 i++; /* start from one after prev */
520         }
521         
522         for(; j < I2C_ADAP_MAX; j++)
523         {
524                 if(!adapters[j])
525                         continue;
526                         
527                 if(adapter_id && (adapters[j]->id != adapter_id))
528                         continue;
529                 
530                 for(; i < I2C_CLIENT_MAX; i++)
531                 {
532                         if(!adapters[j]->clients[i])
533                                 continue;
534                                 
535                         if(driver_id && (adapters[j]->clients[i]->driver->id != driver_id))
536                                 continue;
537                         if(adapters[j]->clients[i]->flags & I2C_CLIENT_ALLOW_USE)       
538                                 return adapters[j]->clients[i];
539                 }
540                 i = 0;
541         }
542
543         return 0;
544 }
545
546 int i2c_use_client(struct i2c_client *client)
547 {
548         if (client->flags & I2C_CLIENT_ALLOW_USE) {
549                 if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
550                         client->usage_count++;
551                 else if (client->usage_count > 0)
552                         return -EBUSY;
553                 else
554                         client->usage_count++;
555         }
556
557         i2c_inc_use_client(client);
558
559         return 0;
560 }
561
562 int i2c_release_client(struct i2c_client *client)
563 {
564         if(client->flags & I2C_CLIENT_ALLOW_USE) {
565                 if(client->usage_count>0)
566                         client->usage_count--;
567                 else
568                 {
569                         printk(KERN_WARNING " i2c-core.o: dec_use_client used one too many times\n");
570                         return -EPERM;
571                 }
572         }
573         
574         i2c_dec_use_client(client);
575         
576         return 0;
577 }
578
579 /* ----------------------------------------------------
580  * The /proc functions
581  * ----------------------------------------------------
582  */
583
584 #ifdef CONFIG_PROC_FS
585
586 /* This function generates the output for /proc/bus/i2c */
587 int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, 
588                  void *private)
589 {
590         int i;
591         int nr = 0;
592         /* Note that it is safe to write a `little' beyond len. Yes, really. */
593         for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++)
594                 if (adapters[i]) {
595                         nr += sprintf(buf+nr, "i2c-%d\t", i);
596                         if (adapters[i]->algo->smbus_xfer) {
597                                 if (adapters[i]->algo->master_xfer)
598                                         nr += sprintf(buf+nr,"smbus/i2c");
599                                 else
600                                         nr += sprintf(buf+nr,"smbus    ");
601                         } else if (adapters[i]->algo->master_xfer)
602                                 nr += sprintf(buf+nr,"i2c       ");
603                         else
604                                 nr += sprintf(buf+nr,"dummy     ");
605                         nr += sprintf(buf+nr,"\t%-32s\t%-32s\n",
606                                       adapters[i]->name,
607                                       adapters[i]->algo->name);
608                 }
609         return nr;
610 }
611
612 /* This function generates the output for /proc/bus/i2c-? */
613 ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, 
614                          loff_t *ppos)
615 {
616         struct inode * inode = file->f_dentry->d_inode;
617         char *kbuf;
618         struct i2c_client *client;
619         int i,j,k,order_nr,len=0;
620         size_t len_total;
621         int order[I2C_CLIENT_MAX];
622
623         if (count > 4000)
624                 return -EINVAL; 
625         len_total = file->f_pos + count;
626         /* Too bad if this gets longer (unlikely) */
627         if (len_total > 4000)
628                 len_total = 4000;
629         for (i = 0; i < I2C_ADAP_MAX; i++)
630                 if (adapters[i]->inode == inode->i_ino) {
631                 /* We need a bit of slack in the kernel buffer; this makes the
632                    sprintf safe. */
633                         if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
634                                 return -ENOMEM;
635                         /* Order will hold the indexes of the clients
636                            sorted by address */
637                         order_nr=0;
638                         for (j = 0; j < I2C_CLIENT_MAX; j++) {
639                                 if ((client = adapters[i]->clients[j]) && 
640                                     (client->driver->id != I2C_DRIVERID_I2CDEV))  {
641                                         for(k = order_nr; 
642                                             (k > 0) && 
643                                             adapters[i]->clients[order[k-1]]->
644                                                      addr > client->addr; 
645                                             k--)
646                                                 order[k] = order[k-1];
647                                         order[k] = j;
648                                         order_nr++;
649                                 }
650                         }
651
652
653                         for (j = 0; (j < order_nr) && (len < len_total); j++) {
654                                 client = adapters[i]->clients[order[j]];
655                                 len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
656                                               client->addr,
657                                               client->name,
658                                               client->driver->name);
659                         }
660                         len = len - file->f_pos;
661                         if (len > count)
662                                 len = count;
663                         if (len < 0) 
664                                 len = 0;
665                         if (copy_to_user (buf,kbuf+file->f_pos, len)) {
666                                 kfree(kbuf);
667                                 return -EFAULT;
668                         }
669                         file->f_pos += len;
670                         kfree(kbuf);
671                         return len;
672                 }
673         return -ENOENT;
674 }
675
676 int i2cproc_init(void)
677 {
678
679         struct proc_dir_entry *proc_bus_i2c;
680
681         i2cproc_initialized = 0;
682
683         if (! proc_bus) {
684                 printk("i2c-core.o: /proc/bus/ does not exist");
685                 i2cproc_cleanup();
686                 return -ENOENT;
687         } 
688         proc_bus_i2c = create_proc_entry("i2c",0,proc_bus);
689         if (!proc_bus_i2c) {
690                 printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c");
691                 i2cproc_cleanup();
692                 return -ENOENT;
693         }
694         proc_bus_i2c->read_proc = &read_bus_i2c;
695         proc_bus_i2c->owner = THIS_MODULE;
696         i2cproc_initialized += 2;
697         return 0;
698 }
699
700 int i2cproc_cleanup(void)
701 {
702
703         if (i2cproc_initialized >= 1) {
704                 remove_proc_entry("i2c",proc_bus);
705                 i2cproc_initialized -= 2;
706         }
707         return 0;
708 }
709
710 #endif /* def CONFIG_PROC_FS */
711
712 /* ----------------------------------------------------
713  * the functional interface to the i2c busses.
714  * ----------------------------------------------------
715  */
716
717 int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs,int num)
718 {
719         int ret;
720
721         if (adap->algo->master_xfer) {
722                 DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n",
723                             adap->name,num));
724
725                 I2C_LOCK(adap);
726                 ret = adap->algo->master_xfer(adap,msgs,num);
727                 I2C_UNLOCK(adap);
728
729                 return ret;
730         } else {
731                 printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
732                        adap->id);
733                 return -ENOSYS;
734         }
735 }
736
737 int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
738 {
739         int ret;
740         struct i2c_adapter *adap=client->adapter;
741         struct i2c_msg msg;
742
743         if (client->adapter->algo->master_xfer) {
744                 msg.addr   = client->addr;
745                 msg.flags = client->flags & I2C_M_TEN;
746                 msg.len = count;
747                 msg.buf = (char *)buf;
748         
749                 DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n",
750                         count,client->adapter->name));
751         
752                 I2C_LOCK(adap);
753                 ret = adap->algo->master_xfer(adap,&msg,1);
754                 I2C_UNLOCK(adap);
755
756                 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
757                  * transmitted, else error code.
758                  */
759                 return (ret == 1 )? count : ret;
760         } else {
761                 printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
762                        client->adapter->id);
763                 return -ENOSYS;
764         }
765 }
766
767 int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
768 {
769         struct i2c_adapter *adap=client->adapter;
770         struct i2c_msg msg;
771         int ret;
772         if (client->adapter->algo->master_xfer) {
773                 msg.addr   = client->addr;
774                 msg.flags = client->flags & I2C_M_TEN;
775                 msg.flags |= I2C_M_RD;
776                 msg.len = count;
777                 msg.buf = buf;
778
779                 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n",
780                         count,client->adapter->name));
781         
782                 I2C_LOCK(adap);
783                 ret = adap->algo->master_xfer(adap,&msg,1);
784                 I2C_UNLOCK(adap);
785         
786                 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
787                         ret, count, client->addr));
788         
789                 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
790                 * transmitted, else error code.
791                 */
792                 return (ret == 1 )? count : ret;
793         } else {
794                 printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
795                        client->adapter->id);
796                 return -ENOSYS;
797         }
798 }
799
800
801 int i2c_control(struct i2c_client *client,
802         unsigned int cmd, unsigned long arg)
803 {
804         int ret = 0;
805         struct i2c_adapter *adap = client->adapter;
806
807         DEB2(printk(KERN_DEBUG "i2c-core.o: i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg));
808         switch ( cmd ) {
809                 case I2C_RETRIES:
810                         adap->retries = arg;
811                         break;
812                 case I2C_TIMEOUT:
813                         adap->timeout = arg;
814                         break;
815                 default:
816                         if (adap->algo->algo_control!=NULL)
817                                 ret = adap->algo->algo_control(adap,cmd,arg);
818         }
819         return ret;
820 }
821
822 /* ----------------------------------------------------
823  * the i2c address scanning function
824  * Will not work for 10-bit addresses!
825  * ----------------------------------------------------
826  */
827 int i2c_probe(struct i2c_adapter *adapter,
828                    struct i2c_client_address_data *address_data,
829                    i2c_client_found_addr_proc *found_proc)
830 {
831         int addr,i,found,err;
832         int adap_id = i2c_adapter_id(adapter);
833
834         /* Forget it if we can't probe using SMBUS_QUICK */
835         if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK))
836                 return -1;
837
838         for (addr = 0x00; addr <= 0x7f; addr++) {
839
840                 /* Skip if already in use */
841                 if (i2c_check_addr(adapter,addr))
842                         continue;
843
844                 /* If it is in one of the force entries, we don't do any detection
845                    at all */
846                 found = 0;
847
848                 for (i = 0; !found && (address_data->force[i] != I2C_CLIENT_END); i += 2) {
849                         if (((adap_id == address_data->force[i]) || 
850                              (address_data->force[i] == ANY_I2C_BUS)) &&
851                              (addr == address_data->force[i+1])) {
852                                 DEB2(printk(KERN_DEBUG "i2c-core.o: found force parameter for adapter %d, addr %04x\n",
853                                             adap_id,addr));
854                                 if ((err = found_proc(adapter,addr,0,0)))
855                                         return err;
856                                 found = 1;
857                         }
858                 }
859                 if (found) 
860                         continue;
861
862                 /* If this address is in one of the ignores, we can forget about
863                    it right now */
864                 for (i = 0;
865                      !found && (address_data->ignore[i] != I2C_CLIENT_END);
866                      i += 2) {
867                         if (((adap_id == address_data->ignore[i]) || 
868                             ((address_data->ignore[i] == ANY_I2C_BUS))) &&
869                             (addr == address_data->ignore[i+1])) {
870                                 DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore parameter for adapter %d, "
871                                      "addr %04x\n", adap_id ,addr));
872                                 found = 1;
873                         }
874                 }
875                 for (i = 0;
876                      !found && (address_data->ignore_range[i] != I2C_CLIENT_END);
877                      i += 3) {
878                         if (((adap_id == address_data->ignore_range[i]) ||
879                             ((address_data->ignore_range[i]==ANY_I2C_BUS))) &&
880                             (addr >= address_data->ignore_range[i+1]) &&
881                             (addr <= address_data->ignore_range[i+2])) {
882                                 DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore_range parameter for adapter %d, "
883                                             "addr %04x\n", adap_id,addr));
884                                 found = 1;
885                         }
886                 }
887                 if (found) 
888                         continue;
889
890                 /* Now, we will do a detection, but only if it is in the normal or 
891                    probe entries */  
892                 for (i = 0;
893                      !found && (address_data->normal_i2c[i] != I2C_CLIENT_END);
894                      i += 1) {
895                         if (addr == address_data->normal_i2c[i]) {
896                                 found = 1;
897                                 DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c entry for adapter %d, "
898                                             "addr %02x\n", adap_id, addr));
899                         }
900                 }
901
902                 for (i = 0;
903                      !found && (address_data->normal_i2c_range[i] != I2C_CLIENT_END);
904                      i += 2) {
905                         if ((addr >= address_data->normal_i2c_range[i]) &&
906                             (addr <= address_data->normal_i2c_range[i+1])) {
907                                 found = 1;
908                                 DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c_range entry for adapter %d, "
909                                             "addr %04x\n", adap_id,addr));
910                         }
911                 }
912
913                 for (i = 0;
914                      !found && (address_data->probe[i] != I2C_CLIENT_END);
915                      i += 2) {
916                         if (((adap_id == address_data->probe[i]) ||
917                             ((address_data->probe[i] == ANY_I2C_BUS))) &&
918                             (addr == address_data->probe[i+1])) {
919                                 found = 1;
920                                 DEB2(printk(KERN_DEBUG "i2c-core.o: found probe parameter for adapter %d, "
921                                             "addr %04x\n", adap_id,addr));
922                         }
923                 }
924                 for (i = 0;
925                      !found && (address_data->probe_range[i] != I2C_CLIENT_END);
926                      i += 3) {
927                         if (((adap_id == address_data->probe_range[i]) ||
928                            (address_data->probe_range[i] == ANY_I2C_BUS)) &&
929                            (addr >= address_data->probe_range[i+1]) &&
930                            (addr <= address_data->probe_range[i+2])) {
931                                 found = 1;
932                                 DEB2(printk(KERN_DEBUG "i2c-core.o: found probe_range parameter for adapter %d, "
933                                             "addr %04x\n", adap_id,addr));
934                         }
935                 }
936                 if (!found) 
937                         continue;
938
939                 /* OK, so we really should examine this address. First check
940                    whether there is some client here at all! */
941                 if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0)
942                         if ((err = found_proc(adapter,addr,0,-1)))
943                                 return err;
944         }
945         return 0;
946 }
947
948 /*
949  * return id number for a specific adapter
950  */
951 int i2c_adapter_id(struct i2c_adapter *adap)
952 {
953         int i;
954         for (i = 0; i < I2C_ADAP_MAX; i++)
955                 if (adap == adapters[i])
956                         return i;
957         return -1;
958 }
959
960 /* The SMBus parts */
961
962 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
963 {
964         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
965                               value,0,I2C_SMBUS_QUICK,NULL);
966 }
967
968 extern s32 i2c_smbus_read_byte(struct i2c_client * client)
969 {
970         union i2c_smbus_data data;
971         if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
972                            I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data))
973                 return -1;
974         else
975                 return data.byte;
976 }
977
978 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
979 {
980         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
981                               I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
982 }
983
984 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command)
985 {
986         union i2c_smbus_data data;
987         if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
988                            I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data))
989                 return -1;
990         else
991                 return data.byte;
992 }
993
994 extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, u8 command,
995                                      u8 value)
996 {
997         union i2c_smbus_data data;
998         data.byte = value;
999         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
1000                               I2C_SMBUS_WRITE,command,
1001                               I2C_SMBUS_BYTE_DATA,&data);
1002 }
1003
1004 extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command)
1005 {
1006         union i2c_smbus_data data;
1007         if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
1008                            I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data))
1009                 return -1;
1010         else
1011                 return data.word;
1012 }
1013
1014 extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
1015                                      u8 command, u16 value)
1016 {
1017         union i2c_smbus_data data;
1018         data.word = value;
1019         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
1020                               I2C_SMBUS_WRITE,command,
1021                               I2C_SMBUS_WORD_DATA,&data);
1022 }
1023
1024 extern s32 i2c_smbus_process_call(struct i2c_client * client,
1025                                   u8 command, u16 value)
1026 {
1027         union i2c_smbus_data data;
1028         data.word = value;
1029         if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
1030                            I2C_SMBUS_WRITE,command,
1031                            I2C_SMBUS_PROC_CALL, &data))
1032                 return -1;
1033         else
1034                 return data.word;
1035 }
1036
1037 /* Returns the number of read bytes */
1038 extern s32 i2c_smbus_read_block_data(struct i2c_client * client,
1039                                      u8 command, u8 *values)
1040 {
1041         union i2c_smbus_data data;
1042         int i;
1043         if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
1044                            I2C_SMBUS_READ,command,
1045                            I2C_SMBUS_BLOCK_DATA,&data))
1046                 return -1;
1047         else {
1048                 for (i = 1; i <= data.block[0]; i++)
1049                         values[i-1] = data.block[i];
1050                 return data.block[0];
1051         }
1052 }
1053
1054 extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
1055                                       u8 command, u8 length, u8 *values)
1056 {
1057         union i2c_smbus_data data;
1058         int i;
1059         if (length > I2C_SMBUS_BLOCK_MAX)
1060                 length = I2C_SMBUS_BLOCK_MAX;
1061         for (i = 1; i <= length; i++)
1062                 data.block[i] = values[i-1];
1063         data.block[0] = length;
1064         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
1065                               I2C_SMBUS_WRITE,command,
1066                               I2C_SMBUS_BLOCK_DATA,&data);
1067 }
1068
1069 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
1070                                           u8 command, u8 length, u8 *values)
1071 {
1072         union i2c_smbus_data data;
1073         int i;
1074         if (length > I2C_SMBUS_I2C_BLOCK_MAX)
1075                 length = I2C_SMBUS_I2C_BLOCK_MAX;
1076         for (i = 1; i <= length; i++)
1077                 data.block[i] = values[i-1];
1078         data.block[0] = length;
1079         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
1080                               I2C_SMBUS_WRITE,command,
1081                               I2C_SMBUS_I2C_BLOCK_DATA,&data);
1082 }
1083
1084 /* Simulate a SMBus command using the i2c protocol 
1085    No checking of parameters is done!  */
1086 static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, 
1087                                    unsigned short flags,
1088                                    char read_write, u8 command, int size, 
1089                                    union i2c_smbus_data * data)
1090 {
1091         /* So we need to generate a series of msgs. In the case of writing, we
1092           need to use only one message; when reading, we need two. We initialize
1093           most things with sane defaults, to keep the code below somewhat
1094           simpler. */
1095         unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+2];
1096         unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
1097         int num = read_write == I2C_SMBUS_READ?2:1;
1098         struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, 
1099                                   { addr, flags | I2C_M_RD, 0, msgbuf1 }
1100                                 };
1101         int i;
1102
1103         msgbuf0[0] = command;
1104         switch(size) {
1105         case I2C_SMBUS_QUICK:
1106                 msg[0].len = 0;
1107                 /* Special case: The read/write field is used as data */
1108                 msg[0].flags = flags | (read_write==I2C_SMBUS_READ)?I2C_M_RD:0;
1109                 num = 1;
1110                 break;
1111         case I2C_SMBUS_BYTE:
1112                 if (read_write == I2C_SMBUS_READ) {
1113                         /* Special case: only a read! */
1114                         msg[0].flags = I2C_M_RD | flags;
1115                         num = 1;
1116                 }
1117                 break;
1118         case I2C_SMBUS_BYTE_DATA:
1119                 if (read_write == I2C_SMBUS_READ)
1120                         msg[1].len = 1;
1121                 else {
1122                         msg[0].len = 2;
1123                         msgbuf0[1] = data->byte;
1124                 }
1125                 break;
1126         case I2C_SMBUS_WORD_DATA:
1127                 if (read_write == I2C_SMBUS_READ)
1128                         msg[1].len = 2;
1129                 else {
1130                         msg[0].len=3;
1131                         msgbuf0[1] = data->word & 0xff;
1132                         msgbuf0[2] = data->word >> 8;
1133                 }
1134                 break;
1135         case I2C_SMBUS_PROC_CALL:
1136                 num = 2; /* Special case */
1137                 msg[0].len = 3;
1138                 msg[1].len = 2;
1139                 msgbuf0[1] = data->word & 0xff;
1140                 msgbuf0[2] = data->word >> 8;
1141                 break;
1142         case I2C_SMBUS_BLOCK_DATA:
1143                 if (read_write == I2C_SMBUS_READ) {
1144                         printk(KERN_ERR "i2c-core.o: Block read not supported "
1145                                "under I2C emulation!\n");
1146                         return -1;
1147                 } else {
1148                         msg[0].len = data->block[0] + 2;
1149                         if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
1150                                 printk(KERN_ERR "i2c-core.o: smbus_access called with "
1151                                        "invalid block write size (%d)\n",
1152                                        data->block[0]);
1153                                 return -1;
1154                         }
1155                         for (i = 1; i <= msg[0].len; i++)
1156                                 msgbuf0[i] = data->block[i-1];
1157                 }
1158                 break;
1159         default:
1160                 printk(KERN_ERR "i2c-core.o: smbus_access called with invalid size (%d)\n",
1161                        size);
1162                 return -1;
1163         }
1164
1165         if (i2c_transfer(adapter, msg, num) < 0)
1166                 return -1;
1167
1168         if (read_write == I2C_SMBUS_READ)
1169                 switch(size) {
1170                         case I2C_SMBUS_BYTE:
1171                                 data->byte = msgbuf0[0];
1172                                 break;
1173                         case I2C_SMBUS_BYTE_DATA:
1174                                 data->byte = msgbuf1[0];
1175                                 break;
1176                         case I2C_SMBUS_WORD_DATA: 
1177                         case I2C_SMBUS_PROC_CALL:
1178                                 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
1179                                 break;
1180                 }
1181         return 0;
1182 }
1183
1184
1185 s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1186                    char read_write, u8 command, int size, 
1187                    union i2c_smbus_data * data)
1188 {
1189         s32 res;
1190
1191         flags = flags & I2C_M_TEN;
1192
1193         if (adapter->algo->smbus_xfer) {
1194                 I2C_LOCK(adapter);
1195                 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
1196                                                 command,size,data);
1197                 I2C_UNLOCK(adapter);
1198         } else
1199                 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
1200                                               command,size,data);
1201
1202         return res;
1203 }
1204
1205
1206 /* You should always define `functionality'; the 'else' is just for
1207    backward compatibility. */ 
1208 u32 i2c_get_functionality (struct i2c_adapter *adap)
1209 {
1210         if (adap->algo->functionality)
1211                 return adap->algo->functionality(adap);
1212         else
1213                 return 0xffffffff;
1214 }
1215
1216 int i2c_check_functionality (struct i2c_adapter *adap, u32 func)
1217 {
1218         u32 adap_func = i2c_get_functionality (adap);
1219         return (func & adap_func) == func;
1220 }
1221
1222
1223 static int __init i2c_init(void)
1224 {
1225         printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE);
1226         memset(adapters,0,sizeof(adapters));
1227         memset(drivers,0,sizeof(drivers));
1228         adap_count=0;
1229         driver_count=0;
1230
1231         init_MUTEX(&adap_lock);
1232         init_MUTEX(&driver_lock);
1233         
1234         i2cproc_init();
1235         
1236         return 0;
1237 }
1238
1239 #ifndef MODULE
1240 #ifdef CONFIG_I2C_CHARDEV
1241         extern int i2c_dev_init(void);
1242 #endif
1243 #ifdef CONFIG_I2C_ALGOBIT
1244         extern int i2c_algo_bit_init(void);
1245 #endif
1246 #ifdef CONFIG_I2C_PHILIPSPAR
1247         extern int i2c_bitlp_init(void);
1248 #endif
1249 #ifdef CONFIG_I2C_ELV
1250         extern int i2c_bitelv_init(void);
1251 #endif
1252 #ifdef CONFIG_I2C_VELLEMAN
1253         extern int i2c_bitvelle_init(void);
1254 #endif
1255 #ifdef CONFIG_I2C_BITVIA
1256         extern int i2c_bitvia_init(void);
1257 #endif
1258
1259 #ifdef CONFIG_I2C_ALGOPCF
1260         extern int i2c_algo_pcf_init(void);     
1261 #endif
1262 #ifdef CONFIG_I2C_ELEKTOR
1263         extern int i2c_pcfisa_init(void);
1264 #endif
1265
1266 #ifdef CONFIG_I2C_ALGO8XX
1267         extern int i2c_algo_8xx_init(void);
1268 #endif
1269 #ifdef CONFIG_I2C_RPXLITE
1270         extern int i2c_rpx_init(void);
1271 #endif
1272
1273 #ifdef CONFIG_I2C_ALGO_SIBYTE
1274         extern int i2c_algo_sibyte_init(void);
1275         extern int i2c_sibyte_init(void);
1276 #endif
1277 #ifdef CONFIG_I2C_MAX1617
1278         extern int i2c_max1617_init(void);
1279 #endif
1280
1281 #ifdef CONFIG_I2C_PROC
1282         extern int sensors_init(void);
1283 #endif
1284
1285 /* This is needed for automatic patch generation: sensors code starts here */
1286 /* This is needed for automatic patch generation: sensors code ends here   */
1287
1288 int __init i2c_init_all(void)
1289 {
1290         /* --------------------- global ----- */
1291         i2c_init();
1292
1293 #ifdef CONFIG_I2C_CHARDEV
1294         i2c_dev_init();
1295 #endif
1296         /* --------------------- bit -------- */
1297 #ifdef CONFIG_I2C_ALGOBIT
1298         i2c_algo_bit_init();
1299 #endif
1300 #ifdef CONFIG_I2C_PHILIPSPAR
1301         i2c_bitlp_init();
1302 #endif
1303 #ifdef CONFIG_I2C_ELV
1304         i2c_bitelv_init();
1305 #endif
1306 #ifdef CONFIG_I2C_VELLEMAN
1307         i2c_bitvelle_init();
1308 #endif
1309
1310         /* --------------------- pcf -------- */
1311 #ifdef CONFIG_I2C_ALGOPCF
1312         i2c_algo_pcf_init();    
1313 #endif
1314 #ifdef CONFIG_I2C_ELEKTOR
1315         i2c_pcfisa_init();
1316 #endif
1317
1318         /* --------------------- 8xx -------- */
1319 #ifdef CONFIG_I2C_ALGO8XX
1320         i2c_algo_8xx_init();
1321 #endif
1322 #ifdef CONFIG_I2C_RPXLITE
1323         i2c_rpx_init();
1324 #endif
1325
1326         /* --------------------- SiByte -------- */
1327 #ifdef CONFIG_I2C_ALGO_SIBYTE
1328         i2c_algo_sibyte_init();
1329         i2c_sibyte_init();
1330 #endif
1331 #ifdef CONFIG_I2C_MAX1617
1332         i2c_max1617_init();
1333 #endif
1334
1335         /* -------------- proc interface ---- */
1336 #ifdef CONFIG_I2C_PROC
1337         sensors_init();
1338 #endif
1339 /* This is needed for automatic patch generation: sensors code starts here */
1340 /* This is needed for automatic patch generation: sensors code ends here */
1341
1342         return 0;
1343 }
1344
1345 #endif
1346
1347
1348
1349 EXPORT_SYMBOL(i2c_add_adapter);
1350 EXPORT_SYMBOL(i2c_del_adapter);
1351 EXPORT_SYMBOL(i2c_add_driver);
1352 EXPORT_SYMBOL(i2c_del_driver);
1353 EXPORT_SYMBOL(i2c_attach_client);
1354 EXPORT_SYMBOL(i2c_detach_client);
1355 EXPORT_SYMBOL(i2c_inc_use_client);
1356 EXPORT_SYMBOL(i2c_dec_use_client);
1357 EXPORT_SYMBOL(i2c_get_client);
1358 EXPORT_SYMBOL(i2c_use_client);
1359 EXPORT_SYMBOL(i2c_release_client);
1360 EXPORT_SYMBOL(i2c_check_addr);
1361
1362
1363 EXPORT_SYMBOL(i2c_master_send);
1364 EXPORT_SYMBOL(i2c_master_recv);
1365 EXPORT_SYMBOL(i2c_control);
1366 EXPORT_SYMBOL(i2c_transfer);
1367 EXPORT_SYMBOL(i2c_adapter_id);
1368 EXPORT_SYMBOL(i2c_probe);
1369
1370 EXPORT_SYMBOL(i2c_smbus_xfer);
1371 EXPORT_SYMBOL(i2c_smbus_write_quick);
1372 EXPORT_SYMBOL(i2c_smbus_read_byte);
1373 EXPORT_SYMBOL(i2c_smbus_write_byte);
1374 EXPORT_SYMBOL(i2c_smbus_read_byte_data);
1375 EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1376 EXPORT_SYMBOL(i2c_smbus_read_word_data);
1377 EXPORT_SYMBOL(i2c_smbus_write_word_data);
1378 EXPORT_SYMBOL(i2c_smbus_process_call);
1379 EXPORT_SYMBOL(i2c_smbus_read_block_data);
1380 EXPORT_SYMBOL(i2c_smbus_write_block_data);
1381
1382 EXPORT_SYMBOL(i2c_get_functionality);
1383 EXPORT_SYMBOL(i2c_check_functionality);
1384
1385 #ifdef MODULE
1386 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
1387 MODULE_DESCRIPTION("I2C-Bus main module");
1388 MODULE_LICENSE("GPL");
1389
1390 MODULE_PARM(i2c_debug, "i");
1391 MODULE_PARM_DESC(i2c_debug,"debug level");
1392
1393 int init_module(void) 
1394 {
1395         return i2c_init();
1396 }
1397
1398 void cleanup_module(void) 
1399 {
1400         i2cproc_cleanup();
1401 }
1402 #endif