Changeset 3391

Show
Ignore:
Timestamp:
09/27/99 18:00:17 (15 years ago)
Author:
frodo
Message:

Preparations for better 10-bit address support

WARNING! INTERFACE CHANGE!

All i2c_smbus_* transaction functions now use a client parameter, instead of
adapter and address parameters.

Also, at some other places 'flags' parameter are added.

Location:
i2c/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • i2c/trunk/doc/writing-clients

    r3390 r3391  
    138138  { 
    139139    if (reg < 0x10) /* byte-sized register */ 
    140       return i2c_smbus_read_byte_data(client->adapter,client->addr,reg); 
     140      return i2c_smbus_read_byte_data(client,reg); 
    141141    else /* word-sized register */ 
    142       return i2c_smbus_read_word_data(client->adapter,client->addr,reg); 
     142      return i2c_smbus_read_word_data(client,reg); 
    143143  } 
    144144 
     
    148148      return -1; 
    149149    else if (reg < 0x10) /* byte-sized register */ 
    150       return i2c_smbus_write_byte_data(client->adapter,client->addr,reg,value); 
     150      return i2c_smbus_write_byte_data(client,reg,value); 
    151151    else /* word-sized register */ 
    152       return i2c_smbus_write_word_data(client->adapter,client->addr,reg,value); 
     152      return i2c_smbus_write_word_data(client,reg,value); 
    153153  } 
    154154 
     
    166166      return res; 
    167167    } else 
    168       return i2c_smbus_read_byte_data(client->adapter,client->addr,reg); 
     168      return i2c_smbus_read_byte_data(client,reg); 
    169169  } 
    170170 
     
    388388    
    389389    /* Let's see whether this adapter can support what we need. 
    390        Please substitute the things you need here! */ 
    391     if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA | 
    392                                           I2C_FUNC_SMBUS_WRITE_BYTE)) 
     390       Please substitute the things you need here!  
     391       For `sensors' drivers, add `! is_isa &&' to the if statement */ 
     392    if (i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA | 
     393                                        I2C_FUNC_SMBUS_WRITE_BYTE)) 
    393394       goto ERROR0; 
    394395 
     
    457458    new_client->adapter = adapter; 
    458459    new_client->driver = &foo_driver; 
     460    new_client->flags = 0; 
    459461 
    460462    /* Now, we do the remaining detection. If no `force' parameter is used. */ 
     
    706708------------------- 
    707709 
    708   extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u8 addr, 
     710  extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u8 addr,  
     711                             unsigned short flags, 
    709712                             char read_write, u8 command, int size, 
    710713                             union i2c_smbus_data * data); 
     
    713716  in terms of it. Never use this function directly! 
    714717 
    715   extern s32 i2c_smbus_write_quick(struct i2c_adapter * adapter, u8 addr, 
    716                                    u8 value); 
    717   extern s32 i2c_smbus_read_byte(struct i2c_adapter * adapter,u8 addr); 
    718   extern s32 i2c_smbus_write_byte(struct i2c_adapter * adapter, u8 addr, 
    719                                   u8 value); 
    720   extern s32 i2c_smbus_read_byte_data(struct i2c_adapter * adapter, 
    721                                       u8 addr, u8 command); 
    722   extern s32 i2c_smbus_write_byte_data(struct i2c_adapter * adapter, 
    723                                    u8 addr, u8 command, u8 value); 
    724   extern s32 i2c_smbus_read_word_data(struct i2c_adapter * adapter, 
    725                                       u8 addr, u8 command); 
    726   extern s32 i2c_smbus_write_word_data(struct i2c_adapter * adapter, 
    727                                        u8 addr, u8 command, u16 value); 
    728   extern s32 i2c_smbus_process_call(struct i2c_adapter * adapter, 
    729                                 u8 addr, u8 command, u16 value); 
    730   /* Returns the number of read bytes */ 
    731   extern s32 i2c_smbus_read_block_data(struct i2c_adapter * adapter, 
    732                                        u8 addr, u8 command, u8 *values); 
    733   extern s32 i2c_smbus_write_block_data(struct i2c_adapter * adapter, 
    734                                         u8 addr, u8 command, u8 length, 
     718 
     719  extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); 
     720  extern s32 i2c_smbus_read_byte(struct i2c_client * client); 
     721  extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value); 
     722  extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command); 
     723  extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, 
     724                                       u8 command, u8 value); 
     725  extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); 
     726  extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 
     727                                       u8 command, u16 value); 
     728  extern s32 i2c_smbus_process_call(struct i2c_client * client, 
     729                                    u8 command, u16 value); 
     730  extern s32 i2c_smbus_read_block_data(struct i2c_client * client, 
     731                                       u8 command, u8 *values); 
     732  extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 
     733                                        u8 command, u8 length, 
    735734                                        u8 *values); 
    736735 
  • i2c/trunk/kernel/i2c-core.c

    r3388 r3391  
    832832/* ---------------------------------------------------- 
    833833 * the i2c address scanning function 
     834 * Will not work for 10-bit addresses! 
    834835 * ---------------------------------------------------- 
    835836 */ 
     
    840841  int addr,i,found,err; 
    841842  int adap_id = i2c_adapter_id(adapter); 
     843 
     844  /* Forget it if we can't probe using SMBUS_QUICK */ 
     845  if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK)) 
     846    return -1; 
    842847 
    843848  for (addr = 0x00;  
     
    857862        DEB2(printk("i2c-core.o: found force parameter for adapter %d, addr %04x\n", 
    858863               adap_id,addr)); 
    859         if ((err = found_proc(adapter,addr,0))) 
     864        if ((err = found_proc(adapter,addr,0,0))) 
    860865           return err; 
    861866        found = 1; 
     
    944949    /* OK, so we really should examine this address. First check 
    945950       whether there is some client here at all! */ 
    946     if (i2c_smbus_write_quick(adapter,addr,0) >= 0) 
    947       if ((err = found_proc(adapter,addr,-1))) 
     951    if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL)) 
     952      if ((err = found_proc(adapter,addr,0,-1))) 
    948953        return err; 
    949954  } 
     
    965970/* The SMBus parts */ 
    966971 
    967 extern s32 i2c_smbus_write_quick(struct i2c_adapter * adapter, u8 addr,  
    968                                         u8 value) 
    969 { 
    970         return i2c_smbus_xfer(adapter,addr,value,0,I2C_SMBUS_QUICK,NULL); 
    971 } 
    972  
    973 extern s32 i2c_smbus_read_byte(struct i2c_adapter * adapter,u8 addr) 
     972extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value) 
     973{ 
     974        return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     975                              value,0,I2C_SMBUS_QUICK,NULL); 
     976} 
     977 
     978extern s32 i2c_smbus_read_byte(struct i2c_client * client) 
    974979{ 
    975980        union i2c_smbus_data data; 
    976         if (i2c_smbus_xfer(adapter,addr,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, 
    977                           &data)) 
     981        if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     982                           I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data)) 
    978983                return -1; 
    979984        else 
     
    981986} 
    982987 
    983 extern s32 i2c_smbus_write_byte(struct i2c_adapter * adapter, u8 addr,  
    984                                        u8 value) 
    985 { 
    986         return i2c_smbus_xfer(adapter,addr,I2C_SMBUS_WRITE,value,  
    987                               I2C_SMBUS_BYTE,NULL); 
    988 } 
    989  
    990 extern s32 i2c_smbus_read_byte_data(struct i2c_adapter * adapter, 
    991                                            u8 addr, u8 command) 
     988extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value) 
     989{ 
     990        return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     991                              I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL); 
     992} 
     993 
     994extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command) 
    992995{ 
    993996        union i2c_smbus_data data; 
    994         if (i2c_smbus_xfer(adapter,addr,I2C_SMBUS_READ,command, 
    995                            I2C_SMBUS_BYTE_DATA,&data)) 
     997        if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     998                           I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data)) 
    996999                return -1; 
    9971000        else 
     
    9991002} 
    10001003 
    1001 extern s32 i2c_smbus_write_byte_data(struct i2c_adapter * adapter, 
    1002                                         u8 addr, u8 command, u8 value) 
     1004extern s32 i2c_smbus_write_byte_data(struct i2c_client * client,  
     1005                                     u8 command, u8 value) 
    10031006{ 
    10041007        union i2c_smbus_data data; 
    10051008        data.byte = value; 
    1006         return i2c_smbus_xfer(adapter,addr,I2C_SMBUS_WRITE,command, 
     1009        return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     1010                              I2C_SMBUS_WRITE,command, 
    10071011                              I2C_SMBUS_BYTE_DATA,&data); 
    10081012} 
    10091013 
    1010 extern s32 i2c_smbus_read_word_data(struct i2c_adapter * adapter, 
    1011                                            u8 addr, u8 command) 
     1014extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command) 
    10121015{ 
    10131016        union i2c_smbus_data data; 
    1014         if (i2c_smbus_xfer(adapter,addr,I2C_SMBUS_READ,command, 
    1015                            I2C_SMBUS_WORD_DATA, &data)) 
     1017        if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     1018                           I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data)) 
    10161019                return -1; 
    10171020        else 
     
    10191022} 
    10201023 
    1021 extern s32 i2c_smbus_write_word_data(struct i2c_adapter * adapter, 
    1022                                             u8 addr, u8 command, u16 value) 
     1024extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 
     1025                                     u8 command, u16 value) 
    10231026{ 
    10241027        union i2c_smbus_data data; 
    10251028        data.word = value; 
    1026         return i2c_smbus_xfer(adapter,addr,I2C_SMBUS_WRITE,command, 
     1029        return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     1030                              I2C_SMBUS_WRITE,command, 
    10271031                              I2C_SMBUS_WORD_DATA,&data); 
    10281032} 
    10291033 
    1030 extern s32 i2c_smbus_process_call(struct i2c_adapter * adapter, 
    1031                                      u8 addr, u8 command, u16 value) 
     1034extern s32 i2c_smbus_process_call(struct i2c_client * client, 
     1035                                  u8 command, u16 value) 
    10321036{ 
    10331037        union i2c_smbus_data data; 
    10341038        data.word = value; 
    1035         if (i2c_smbus_xfer(adapter,addr,I2C_SMBUS_WRITE,command, 
     1039        if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     1040                           I2C_SMBUS_WRITE,command, 
    10361041                           I2C_SMBUS_PROC_CALL, &data)) 
    10371042                return -1; 
     
    10411046 
    10421047/* Returns the number of read bytes */ 
    1043 extern s32 i2c_smbus_read_block_data(struct i2c_adapter * adapter, 
    1044                                             u8 addr, u8 command, u8 *values) 
     1048extern s32 i2c_smbus_read_block_data(struct i2c_client * client, 
     1049                                     u8 command, u8 *values) 
    10451050{ 
    10461051        union i2c_smbus_data data; 
    10471052        int i; 
    1048         if (i2c_smbus_xfer(adapter,addr,I2C_SMBUS_READ,command, 
     1053        if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     1054                           I2C_SMBUS_READ,command, 
    10491055                           I2C_SMBUS_BLOCK_DATA,&data)) 
    10501056                return -1; 
     
    10561062} 
    10571063 
    1058 extern s32 i2c_smbus_write_block_data(struct i2c_adapter * adapter, 
    1059                                              u8 addr, u8 command, u8 length, 
    1060                                              u8 *values) 
     1064extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 
     1065                                      u8 command, u8 length, u8 *values) 
    10611066{ 
    10621067        union i2c_smbus_data data; 
     
    10671072                data.block[i] = values[i-1]; 
    10681073        data.block[0] = length; 
    1069         return i2c_smbus_xfer(adapter,addr,I2C_SMBUS_WRITE,command, 
     1074        return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     1075                              I2C_SMBUS_WRITE,command, 
    10701076                              I2C_SMBUS_BLOCK_DATA,&data); 
    10711077} 
     
    10741080   No checking of parameters is done!  */ 
    10751081static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u8 addr,  
     1082                                   unsigned short flags, 
    10761083                                   char read_write, u8 command, int size,  
    10771084                                   union i2c_smbus_data * data) 
     
    10841091        unsigned char msgbuf1[33]; 
    10851092        int num = read_write == I2C_SMBUS_READ?2:1; 
    1086         struct i2c_msg msg[2] = { { addr, 0, 1, msgbuf0 },  
    1087                                   { addr, I2C_M_RD, 0, msgbuf1 } 
     1093        struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },  
     1094                                  { addr, flags | I2C_M_RD, 0, msgbuf1 } 
    10881095                                }; 
    10891096        int i; 
     
    10941101                msg[0].len = 0; 
    10951102                /* Special case: The read/write field is used as data */ 
    1096                 msg[0].flags = (read_write==I2C_SMBUS_READ)?I2C_M_RD:0; 
     1103                msg[0].flags = flags | (read_write==I2C_SMBUS_READ)?I2C_M_RD:0; 
    10971104                num = 1; 
    10981105                break; 
     
    11001107                if (read_write == I2C_SMBUS_READ) { 
    11011108                        /* Special case: only a read! */ 
    1102                         msg[0].flags = I2C_M_RD; 
     1109                        msg[0].flags = I2C_M_RD | flags; 
    11031110                        num = 1; 
    11041111                } 
     
    11711178 
    11721179 
    1173 s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u8 addr, char read_write, 
    1174                    u8 command, int size, union i2c_smbus_data * data) 
     1180s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u8 addr, unsigned short flags, 
     1181                   char read_write, u8 command, int size,  
     1182                   union i2c_smbus_data * data) 
    11751183{ 
    11761184        s32 res; 
     1185        flags = flags & I2C_M_TEN; 
    11771186        if (adapter->algo->smbus_xfer) { 
    11781187                I2C_LOCK(adapter); 
    1179                 res = adapter->algo->smbus_xfer(adapter,addr,read_write, 
     1188                res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write, 
    11801189                                                command,size,data); 
    11811190                I2C_UNLOCK(adapter); 
    11821191        } else 
    1183                 res = i2c_smbus_xfer_emulated(adapter,addr,read_write, 
    1184                                                 command,size,data); 
     1192                res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, 
     1193                                              command,size,data); 
    11851194        return res; 
    11861195} 
  • i2c/trunk/kernel/i2c-dev.c

    r3372 r3391  
    330330           (data_arg.read_write == I2C_SMBUS_WRITE))) 
    331331        /* These are special: we do not use data */ 
    332         return i2c_smbus_xfer(client->adapter, client->addr,  
     332        return i2c_smbus_xfer(client->adapter, client->addr, client->flags, 
    333333                              data_arg.read_write, data_arg.command, 
    334334                              data_arg.size, NULL); 
     
    365365          (data_arg.read_write == I2C_SMBUS_WRITE)) 
    366366        copy_from_user(&temp,data_arg.data,datasize); 
    367       res = i2c_smbus_xfer(client->adapter,client->addr,data_arg.read_write, 
     367      res = i2c_smbus_xfer(client->adapter,client->addr,client->flags, 
     368                           data_arg.read_write, 
    368369                           data_arg.command,data_arg.size,&temp); 
    369370      if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) ||  
  • i2c/trunk/kernel/i2c.h

    r3389 r3391  
    9898#define I2C_M_TENMASK   0x06 
    9999#define I2C_M_RD        0x01 
     100#if 0 
    100101#define I2C_M_PROBE     0x20 
     102#endif 
    101103        short len;              /* msg length                           */ 
    102104        char *buf;              /* pointer to msg data                  */ 
     
    110112   smbus adapter to call this function. */ 
    111113extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u8 addr,  
     114                           unsigned short flags, 
    112115                           char read_write, u8 command, int size, 
    113116                           union i2c_smbus_data * data); 
     
    116119   conventions of smbus_access. */ 
    117120 
    118 extern s32 i2c_smbus_write_quick(struct i2c_adapter * adapter, u8 addr,  
    119                                  u8 value); 
    120 extern s32 i2c_smbus_read_byte(struct i2c_adapter * adapter,u8 addr); 
    121 extern s32 i2c_smbus_write_byte(struct i2c_adapter * adapter, u8 addr,  
    122                                 u8 value); 
    123 extern s32 i2c_smbus_read_byte_data(struct i2c_adapter * adapter, 
    124                                     u8 addr, u8 command); 
    125 extern s32 i2c_smbus_write_byte_data(struct i2c_adapter * adapter, 
    126                                  u8 addr, u8 command, u8 value); 
    127 extern s32 i2c_smbus_read_word_data(struct i2c_adapter * adapter, 
    128                                     u8 addr, u8 command); 
    129 extern s32 i2c_smbus_write_word_data(struct i2c_adapter * adapter, 
    130                                      u8 addr, u8 command, u16 value); 
    131 extern s32 i2c_smbus_process_call(struct i2c_adapter * adapter, 
    132                               u8 addr, u8 command, u16 value); 
     121extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); 
     122extern s32 i2c_smbus_read_byte(struct i2c_client * client); 
     123extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value); 
     124extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command); 
     125extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, 
     126                                     u8 command, u8 value); 
     127extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); 
     128extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 
     129                                     u8 command, u16 value); 
     130extern s32 i2c_smbus_process_call(struct i2c_client * client, 
     131                                  u8 command, u16 value); 
    133132/* Returns the number of read bytes */ 
    134 extern s32 i2c_smbus_read_block_data(struct i2c_adapter * adapter, 
    135                                      u8 addr, u8 command, u8 *values); 
    136 extern s32 i2c_smbus_write_block_data(struct i2c_adapter * adapter, 
    137                                       u8 addr, u8 command, u8 length, 
     133extern s32 i2c_smbus_read_block_data(struct i2c_client * client, 
     134                                     u8 command, u8 *values); 
     135extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 
     136                                      u8 command, u8 length, 
    138137                                      u8 *values); 
    139138 
     
    223222        int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg msgs[],  
    224223                           int num); 
    225         int (*smbus_xfer) (struct i2c_adapter *adap, u8 addr, char read_write, 
     224        int (*smbus_xfer) (struct i2c_adapter *adap, u8 addr,  
     225                           unsigned short flags, char read_write, 
    226226                           u8 command, int size, union i2c_smbus_data * data); 
    227227 
     
    337337 */ 
    338338typedef int i2c_client_found_addr_proc (struct i2c_adapter *adapter, 
    339                                      int addr, int kind); 
     339                                     int addr, unsigned short flags,int kind); 
    340340 
    341341extern int i2c_probe(struct i2c_adapter *adapter,