Changeset 3316

Show
Ignore:
Timestamp:
07/18/99 13:35:19 (14 years ago)
Author:
frodo
Message:

First part of Kyösti Mälkki's patches

* All i2c_bus_handle stuff has been removed
* i2c_probe is made somewhat more efficient and readable

Location:
i2c/trunk/kernel
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • i2c/trunk/kernel/i2c-core.c

    r3315 r3316  
    487487        int i; 
    488488        struct i2c_msg msg; 
    489         struct i2c_msg *pmsg = &msg; 
    490489        msg.flags=client->flags & (I2C_M_TENMASK | I2C_M_TEN ); 
    491490        msg.buf = NULL; 
     
    493492        I2C_LOCK(client->adapter); 
    494493        for (i = low_addr; i <= hi_addr; i++) { 
    495                 client->addr=i; 
     494                msg.addr=i; 
    496495                /* TODO: implement a control statement in the algo layer  
    497496                 * that does address lookup only. 
    498497                 */ 
    499498                if (1 == client->adapter-> 
    500                     algo->master_xfer(client->adapter,pmsg,1)) 
     499                    algo->master_xfer(client->adapter,&msg,1)) 
    501500                        break; 
    502501        } 
    503502        I2C_UNLOCK(client->adapter); 
    504         return (i <= hi_addr) ? i : -1; 
     503        return (i <= hi_addr) ? (client->addr=i) : -1; 
    505504} 
    506505 
     
    515514                        return i; 
    516515        return -1; 
    517 } 
    518  
    519 /*  
    520  * query functions for other modules 
    521  */ 
    522  
    523  
    524 /* this function returns the handle for the first i2c_bus available, or 
    525    -1 if no bus is present at all */ 
    526 i2c_bus_handle i2c_get_first_adapter(void) 
    527 { 
    528         int i = 0; 
    529          
    530         for (i = 0; i < I2C_ADAP_MAX; i++) 
    531                 if ( NULL != adapters[(int)i] ) 
    532                         return (i2c_bus_handle)i; 
    533                          
    534         return -1; 
    535 } 
    536  
    537 /* this function returns the handle for the next i2c_bus available, or 
    538    NULL if there is not any other */ 
    539 i2c_bus_handle i2c_get_next_adapter(i2c_bus_handle i) 
    540 { 
    541         int j = (int)i; 
    542  
    543         j++; 
    544  
    545         for(; j < I2C_ADAP_MAX; j++) 
    546                 if ( NULL != adapters[j] ) 
    547                         break; 
    548  
    549         if ( I2C_ADAP_MAX >= j) 
    550                 return -1; 
    551  
    552         return j; 
    553 } 
    554  
    555 /* this function returns the type of the i2c_bus 'i' */ 
    556 int i2c_get_adapter_type(i2c_bus_handle i) 
    557 { 
    558         if ( i < 0 || i >= I2C_ADAP_MAX ) 
    559                 return -1; 
    560  
    561         if ( NULL == adapters[(int)i] ) 
    562                 return -1; 
    563  
    564         return adapters[(int)i]->id; 
    565 } 
    566  
    567 /* */ 
    568 void* i2c_get_adapter_data(i2c_bus_handle i) 
    569 { 
    570         if ( i < 0 || i >= I2C_ADAP_MAX ) 
    571                 return NULL; 
    572  
    573         if ( NULL == adapters[(int)i] ) 
    574                 return NULL; 
    575  
    576         return adapters[(int)i]->data; 
    577 }        
    578  
    579 /* this function returns the number of available clients on the i2c_bus 'i'  
    580    or -1 if the bus-handle is invalid */ 
    581 int i2c_get_client_count(i2c_bus_handle i) 
    582 { 
    583         if ( i < 0 || i >= I2C_ADAP_MAX ) 
    584                 return -1; 
    585  
    586         if ( NULL == adapters[(int)i] ) 
    587                 return -1; 
    588  
    589         return adapters[(int)i]->client_count; 
    590 } 
    591  
    592 /* this function returns the type (client->id) for the client 'c' 
    593    on i2c_bus 'i'. the function returns -1 if the i2c_bus-nr, -2 if the client is invalid  
    594     
    595    this function is useful for checking for specific devices on an i2c-bus. simply loop 
    596    through all available clients and see if they fit your needs */ 
    597 int i2c_get_client_type(i2c_bus_handle i, int c) 
    598 { 
    599         if ( i < 0 || i >= I2C_ADAP_MAX ) 
    600                 return -1; 
    601  
    602         if ( NULL == adapters[(int)i] ) 
    603                 return -1; 
    604  
    605         if ( NULL == adapters[(int)i]->clients[c] ) 
    606                 return -2; 
    607          
    608         return adapters[(int)i]->clients[c]->id; 
    609  
    610 } 
    611  
    612 /* this function sends the command 'cmd' to the client 'c' specified by its id on 
    613    the i2c_bus 'i' supplying the argument 'arg'. 
    614    it returns the return code of the specific function or -2 if the i2c_client could 
    615    not be found on that bus */ 
    616 int i2c_client_command(i2c_bus_handle i, int c, unsigned int cmd, void *arg) 
    617 { 
    618         int j = 0; 
    619          
    620         if ( i < 0 || i >= I2C_ADAP_MAX ) 
    621                 return -1; 
    622  
    623         if ( NULL == adapters[(int)i] ) 
    624                 return -1; 
    625  
    626         for (j = 0; j < adapters[(int)i]->client_count; j++) { 
    627                 if( c == adapters[(int)i]->clients[j]->id ) 
    628                         return adapters[(int)i]->clients[j]->driver->command(adapters[(int)i]->clients[j],cmd,arg); 
    629                 } 
    630  
    631         DEB2(printk("i2c_client_command: didn't find that device!\n")); 
    632  
    633         printk("i2c_client_command: didn't find that device!\n"); 
    634          
    635         return -2; 
    636 } 
    637  
    638 /* this function tells the client 'c' on the i2c_bus 'i' that it is used by another module */ 
    639 int i2c_inc_client_use(i2c_bus_handle i, int c) 
    640 { 
    641         int j = 0; 
    642          
    643         if ( i < 0 || i >= I2C_ADAP_MAX ) 
    644                 return -1; 
    645  
    646         if ( NULL == adapters[(int)i] ) 
    647                 return -1; 
    648                  
    649         for (j = 0; j < adapters[(int)i]->client_count; j++) { 
    650                 if( c == adapters[(int)i]->clients[j]->id ) 
    651                         if ( NULL != adapters[(int)i]->clients[j]->driver->inc_use ){ 
    652                                 adapters[(int)i]->clients[j]->driver->inc_use(adapters[(int)i]->clients[j]); 
    653                                 return 0; 
    654                         } 
    655         } 
    656  
    657         printk("i2c_inc_client_use: didn't find that device!\n"); 
    658          
    659         return -2; 
    660 } 
    661  
    662 /* this function tells the client 'c' on the i2c_bus 'i' that it is no longer uesd by a module */ 
    663 int i2c_dec_client_use(i2c_bus_handle i, int c) 
    664 { 
    665         int j = 0; 
    666          
    667         if ( i < 0 || i >= I2C_ADAP_MAX ) 
    668                 return -1; 
    669  
    670         if ( NULL == adapters[(int)i] ) 
    671                 return -1; 
    672  
    673         for (j = 0; j < adapters[(int)i]->client_count; j++) { 
    674                 if( c == adapters[(int)i]->clients[j]->id ) 
    675                         if ( NULL != adapters[(int)i]->clients[j]->driver->dec_use ) { 
    676                                 adapters[(int)i]->clients[j]->driver->dec_use(adapters[(int)i]->clients[j]); 
    677                                 return 0; 
    678                         } 
    679         }        
    680  
    681         printk("i2c_dec_use_client: didn't find that device!\n"); 
    682         return -2; 
    683516} 
    684517 
     
    785618EXPORT_SYMBOL(i2c_transfer); 
    786619 
    787 EXPORT_SYMBOL(i2c_get_first_adapter); 
    788 EXPORT_SYMBOL(i2c_get_next_adapter); 
    789 EXPORT_SYMBOL(i2c_get_adapter_type); 
    790 EXPORT_SYMBOL(i2c_get_adapter_data); 
    791 EXPORT_SYMBOL(i2c_get_client_count); 
    792 EXPORT_SYMBOL(i2c_get_client_type); 
    793 EXPORT_SYMBOL(i2c_client_command); 
    794 EXPORT_SYMBOL(i2c_inc_client_use); 
    795 EXPORT_SYMBOL(i2c_dec_client_use); 
    796  
    797  
    798620int init_module(void)  
    799621{ 
  • i2c/trunk/kernel/i2c.h

    r3315 r3316  
    244244 
    245245 
    246 /* we need some kind of handle to identify an i2c-bus. just imagine 
    247  * someone has two cards of the same kind in his computer -- how do 
    248  * you want to distinguish the different i2c adapters ?  
    249  */ 
    250 typedef int i2c_bus_handle; 
    251  
    252 /* return id number of first/next adapter.  
    253  * returned value is <0 if out of bounds. 
    254  */ 
    255 extern i2c_bus_handle i2c_get_adapter_first(void); 
    256 extern i2c_bus_handle i2c_get_adapter_next(i2c_bus_handle i); 
    257  
    258 extern int   i2c_get_adapter_type(i2c_bus_handle i); 
    259 extern void* i2c_get_adapter_data(i2c_bus_handle i); 
    260  
    261 extern int i2c_get_client_count(i2c_bus_handle i); 
    262 extern int i2c_get_client_type (i2c_bus_handle i, int c); 
    263  
    264 extern int i2c_client_command(i2c_bus_handle i, int c, unsigned int cmd, void *arg); 
    265  
    266 extern int i2c_inc_client_use(i2c_bus_handle i, int c); 
    267 extern int i2c_dec_client_use(i2c_bus_handle i, int c); 
    268  
    269246/* 
    270247 * A utility function used in the attach-phase of drivers. Returns at the first address