Changeset 3391
- Timestamp:
- 09/27/99 18:00:17 (9 years ago)
- Files:
-
- i2c/trunk/doc/writing-clients (modified) (7 diffs)
- i2c/trunk/kernel/i2c-core.c (modified) (16 diffs)
- i2c/trunk/kernel/i2c-dev.c (modified) (2 diffs)
- i2c/trunk/kernel/i2c.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
i2c/trunk/doc/writing-clients
r3390 r3391 138 138 { 139 139 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); 141 141 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); 143 143 } 144 144 … … 148 148 return -1; 149 149 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); 151 151 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); 153 153 } 154 154 … … 166 166 return res; 167 167 } else 168 return i2c_smbus_read_byte_data(client ->adapter,client->addr,reg);168 return i2c_smbus_read_byte_data(client,reg); 169 169 } 170 170 … … 388 388 389 389 /* 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)) 393 394 goto ERROR0; 394 395 … … 457 458 new_client->adapter = adapter; 458 459 new_client->driver = &foo_driver; 460 new_client->flags = 0; 459 461 460 462 /* Now, we do the remaining detection. If no `force' parameter is used. */ … … 706 708 ------------------- 707 709 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, 709 712 char read_write, u8 command, int size, 710 713 union i2c_smbus_data * data); … … 713 716 in terms of it. Never use this function directly! 714 717 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, 735 734 u8 *values); 736 735 i2c/trunk/kernel/i2c-core.c
r3388 r3391 832 832 /* ---------------------------------------------------- 833 833 * the i2c address scanning function 834 * Will not work for 10-bit addresses! 834 835 * ---------------------------------------------------- 835 836 */ … … 840 841 int addr,i,found,err; 841 842 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; 842 847 843 848 for (addr = 0x00; … … 857 862 DEB2(printk("i2c-core.o: found force parameter for adapter %d, addr %04x\n", 858 863 adap_id,addr)); 859 if ((err = found_proc(adapter,addr,0 )))864 if ((err = found_proc(adapter,addr,0,0))) 860 865 return err; 861 866 found = 1; … … 944 949 /* OK, so we really should examine this address. First check 945 950 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))) 948 953 return err; 949 954 } … … 965 970 /* The SMBus parts */ 966 971 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)972 extern 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 978 extern s32 i2c_smbus_read_byte(struct i2c_client * client) 974 979 { 975 980 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)) 978 983 return -1; 979 984 else … … 981 986 } 982 987 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) 988 extern 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 994 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command) 992 995 { 993 996 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)) 996 999 return -1; 997 1000 else … … 999 1002 } 1000 1003 1001 extern s32 i2c_smbus_write_byte_data(struct i2c_ adapter * adapter,1002 u8 addr,u8 command, u8 value)1004 extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, 1005 u8 command, u8 value) 1003 1006 { 1004 1007 union i2c_smbus_data data; 1005 1008 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, 1007 1011 I2C_SMBUS_BYTE_DATA,&data); 1008 1012 } 1009 1013 1010 extern s32 i2c_smbus_read_word_data(struct i2c_adapter * adapter, 1011 u8 addr, u8 command) 1014 extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command) 1012 1015 { 1013 1016 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)) 1016 1019 return -1; 1017 1020 else … … 1019 1022 } 1020 1023 1021 extern s32 i2c_smbus_write_word_data(struct i2c_ adapter * adapter,1022 u8 addr,u8 command, u16 value)1024 extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 1025 u8 command, u16 value) 1023 1026 { 1024 1027 union i2c_smbus_data data; 1025 1028 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, 1027 1031 I2C_SMBUS_WORD_DATA,&data); 1028 1032 } 1029 1033 1030 extern s32 i2c_smbus_process_call(struct i2c_ adapter * adapter,1031 u8 addr,u8 command, u16 value)1034 extern s32 i2c_smbus_process_call(struct i2c_client * client, 1035 u8 command, u16 value) 1032 1036 { 1033 1037 union i2c_smbus_data data; 1034 1038 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, 1036 1041 I2C_SMBUS_PROC_CALL, &data)) 1037 1042 return -1; … … 1041 1046 1042 1047 /* 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)1048 extern s32 i2c_smbus_read_block_data(struct i2c_client * client, 1049 u8 command, u8 *values) 1045 1050 { 1046 1051 union i2c_smbus_data data; 1047 1052 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, 1049 1055 I2C_SMBUS_BLOCK_DATA,&data)) 1050 1056 return -1; … … 1056 1062 } 1057 1063 1058 extern s32 i2c_smbus_write_block_data(struct i2c_adapter * adapter, 1059 u8 addr, u8 command, u8 length, 1060 u8 *values) 1064 extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 1065 u8 command, u8 length, u8 *values) 1061 1066 { 1062 1067 union i2c_smbus_data data; … … 1067 1072 data.block[i] = values[i-1]; 1068 1073 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, 1070 1076 I2C_SMBUS_BLOCK_DATA,&data); 1071 1077 } … … 1074 1080 No checking of parameters is done! */ 1075 1081 static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u8 addr, 1082 unsigned short flags, 1076 1083 char read_write, u8 command, int size, 1077 1084 union i2c_smbus_data * data) … … 1084 1091 unsigned char msgbuf1[33]; 1085 1092 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 } 1088 1095 }; 1089 1096 int i; … … 1094 1101 msg[0].len = 0; 1095 1102 /* 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; 1097 1104 num = 1; 1098 1105 break; … … 1100 1107 if (read_write == I2C_SMBUS_READ) { 1101 1108 /* Special case: only a read! */ 1102 msg[0].flags = I2C_M_RD ;1109 msg[0].flags = I2C_M_RD | flags; 1103 1110 num = 1; 1104 1111 } … … 1171 1178 1172 1179 1173 s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u8 addr, char read_write, 1174 u8 command, int size, union i2c_smbus_data * data) 1180 s32 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) 1175 1183 { 1176 1184 s32 res; 1185 flags = flags & I2C_M_TEN; 1177 1186 if (adapter->algo->smbus_xfer) { 1178 1187 I2C_LOCK(adapter); 1179 res = adapter->algo->smbus_xfer(adapter,addr, read_write,1188 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write, 1180 1189 command,size,data); 1181 1190 I2C_UNLOCK(adapter); 1182 1191 } 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); 1185 1194 return res; 1186 1195 } i2c/trunk/kernel/i2c-dev.c
r3372 r3391 330 330 (data_arg.read_write == I2C_SMBUS_WRITE))) 331 331 /* 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, 333 333 data_arg.read_write, data_arg.command, 334 334 data_arg.size, NULL); … … 365 365 (data_arg.read_write == I2C_SMBUS_WRITE)) 366 366 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, 368 369 data_arg.command,data_arg.size,&temp); 369 370 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || i2c/trunk/kernel/i2c.h
r3389 r3391 98 98 #define I2C_M_TENMASK 0x06 99 99 #define I2C_M_RD 0x01 100 #if 0 100 101 #define I2C_M_PROBE 0x20 102 #endif 101 103 short len; /* msg length */ 102 104 char *buf; /* pointer to msg data */ … … 110 112 smbus adapter to call this function. */ 111 113 extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u8 addr, 114 unsigned short flags, 112 115 char read_write, u8 command, int size, 113 116 union i2c_smbus_data * data); … … 116 119 conventions of smbus_access. */ 117 120 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); 121 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); 122 extern s32 i2c_smbus_read_byte(struct i2c_client * client); 123 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value); 124 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command); 125 extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, 126 u8 command, u8 value); 127 extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); 128 extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 129 u8 command, u16 value); 130 extern s32 i2c_smbus_process_call(struct i2c_client * client, 131 u8 command, u16 value); 133 132 /* Returns the number of read bytes */ 134 extern s32 i2c_smbus_read_block_data(struct i2c_ adapter * adapter,135 u8 addr, u8command, u8 *values);136 extern s32 i2c_smbus_write_block_data(struct i2c_ adapter * adapter,137 u8 addr, u8command, u8 length,133 extern s32 i2c_smbus_read_block_data(struct i2c_client * client, 134 u8 command, u8 *values); 135 extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 136 u8 command, u8 length, 138 137 u8 *values); 139 138 … … 223 222 int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg msgs[], 224 223 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, 226 226 u8 command, int size, union i2c_smbus_data * data); 227 227 … … 337 337 */ 338 338 typedef int i2c_client_found_addr_proc (struct i2c_adapter *adapter, 339 int addr, int kind);339 int addr, unsigned short flags,int kind); 340 340 341 341 extern int i2c_probe(struct i2c_adapter *adapter,
