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