| | 49 | static int check_funcs(int file, int i2cbus, int size, int pec) |
| | 50 | { |
| | 51 | unsigned long funcs; |
| | 52 | |
| | 53 | /* check adapter functionality */ |
| | 54 | if (ioctl(file, I2C_FUNCS, &funcs) < 0) { |
| | 55 | fprintf(stderr, "Error: Could not get the adapter " |
| | 56 | "functionality matrix: %s\n", strerror(errno)); |
| | 57 | return -1; |
| | 58 | } |
| | 59 | |
| | 60 | switch(size) { |
| | 61 | case I2C_SMBUS_BYTE: |
| | 62 | if (!((funcs & I2C_FUNC_SMBUS_BYTE) == I2C_FUNC_SMBUS_BYTE)) { |
| | 63 | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| | 64 | "not have byte capability\n", i2cbus); |
| | 65 | return -1; |
| | 66 | } |
| | 67 | break; |
| | 68 | |
| | 69 | case I2C_SMBUS_BYTE_DATA: |
| | 70 | if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) { |
| | 71 | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| | 72 | "not have byte read capability\n", i2cbus); |
| | 73 | return -1; |
| | 74 | } |
| | 75 | break; |
| | 76 | |
| | 77 | case I2C_SMBUS_WORD_DATA: |
| | 78 | if (!(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) { |
| | 79 | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| | 80 | "not have word read capability\n", i2cbus); |
| | 81 | return -1; |
| | 82 | } |
| | 83 | break; |
| | 84 | |
| | 85 | case I2C_SMBUS_BLOCK_DATA: |
| | 86 | if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { |
| | 87 | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| | 88 | "not have smbus block read capability\n", |
| | 89 | i2cbus); |
| | 90 | return -1; |
| | 91 | } |
| | 92 | break; |
| | 93 | |
| | 94 | case I2C_SMBUS_I2C_BLOCK_DATA: |
| | 95 | if (!(funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { |
| | 96 | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| | 97 | "not have i2c block read capability\n", |
| | 98 | i2cbus); |
| | 99 | return -1; |
| | 100 | } |
| | 101 | break; |
| | 102 | } |
| | 103 | |
| | 104 | if (pec |
| | 105 | && !(funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C))) { |
| | 106 | fprintf(stderr, "Warning: Adapter for i2c bus %d does " |
| | 107 | "not seem to support PEC\n", i2cbus); |
| | 108 | } |
| | 109 | |
| | 110 | return 0; |
| | 111 | } |
| | 112 | |
| 203 | | if (file < 0) { |
| 204 | | exit(1); |
| 205 | | } |
| 206 | | |
| 207 | | /* check adapter functionality */ |
| 208 | | if (ioctl(file, I2C_FUNCS, &funcs) < 0) { |
| 209 | | fprintf(stderr, "Error: Could not get the adapter " |
| 210 | | "functionality matrix: %s\n", strerror(errno)); |
| 211 | | exit(1); |
| 212 | | } |
| 213 | | |
| 214 | | switch(size) { |
| 215 | | case I2C_SMBUS_BYTE: |
| 216 | | if (!((funcs & I2C_FUNC_SMBUS_BYTE) == I2C_FUNC_SMBUS_BYTE)) { |
| 217 | | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| 218 | | "not have byte capability\n", i2cbus); |
| 219 | | exit(1); |
| 220 | | } |
| 221 | | break; |
| 222 | | |
| 223 | | case I2C_SMBUS_BYTE_DATA: |
| 224 | | if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) { |
| 225 | | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| 226 | | "not have byte read capability\n", i2cbus); |
| 227 | | exit(1); |
| 228 | | } |
| 229 | | break; |
| 230 | | |
| 231 | | case I2C_SMBUS_WORD_DATA: |
| 232 | | if (!(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) { |
| 233 | | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| 234 | | "not have word read capability\n", i2cbus); |
| 235 | | exit(1); |
| 236 | | } |
| 237 | | break; |
| 238 | | |
| 239 | | case I2C_SMBUS_BLOCK_DATA: |
| 240 | | if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { |
| 241 | | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| 242 | | "not have smbus block read capability\n", |
| 243 | | i2cbus); |
| 244 | | exit(1); |
| 245 | | } |
| 246 | | break; |
| 247 | | |
| 248 | | case I2C_SMBUS_I2C_BLOCK_DATA: |
| 249 | | if (!(funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { |
| 250 | | fprintf(stderr, "Error: Adapter for i2c bus %d does " |
| 251 | | "not have i2c block read capability\n", |
| 252 | | i2cbus); |
| 253 | | exit(1); |
| 254 | | } |
| 255 | | break; |
| 256 | | } |
| 257 | | |
| 258 | | if (set_slave_addr(file, address, force) < 0) |
| | 266 | if (file < 0 |
| | 267 | || check_funcs(file, i2cbus, size, pec) |
| | 268 | || set_slave_addr(file, address, force)) |