diff options
Diffstat (limited to 'miscutils/i2c_tools.c')
-rw-r--r-- | miscutils/i2c_tools.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index cc8b99a92..48135921d 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c | |||
@@ -273,7 +273,7 @@ static int i2c_bus_lookup(const char *bus_str) | |||
273 | return xstrtou_range(bus_str, 10, 0, 0xfffff); | 273 | return xstrtou_range(bus_str, 10, 0, 0xfffff); |
274 | } | 274 | } |
275 | 275 | ||
276 | #if ENABLE_I2CGET || ENABLE_I2CSET || ENABLE_I2CDUMP || ENABLE_I2CTRANSFER | 276 | #if ENABLE_I2CGET || ENABLE_I2CSET || ENABLE_I2CDUMP |
277 | static int i2c_parse_bus_addr(const char *addr_str) | 277 | static int i2c_parse_bus_addr(const char *addr_str) |
278 | { | 278 | { |
279 | /* Slave address must be in range 0x03 - 0x77. */ | 279 | /* Slave address must be in range 0x03 - 0x77. */ |
@@ -286,14 +286,16 @@ static void i2c_set_pec(int fd, int pec) | |||
286 | itoptr(pec ? 1 : 0), | 286 | itoptr(pec ? 1 : 0), |
287 | "can't set PEC"); | 287 | "can't set PEC"); |
288 | } | 288 | } |
289 | #endif | ||
289 | 290 | ||
291 | #if ENABLE_I2CGET || ENABLE_I2CSET || ENABLE_I2CDUMP || ENABLE_I2CTRANSFER | ||
290 | static void i2c_set_slave_addr(int fd, int addr, int force) | 292 | static void i2c_set_slave_addr(int fd, int addr, int force) |
291 | { | 293 | { |
292 | ioctl_or_perror_and_die(fd, force ? I2C_SLAVE_FORCE : I2C_SLAVE, | 294 | ioctl_or_perror_and_die(fd, force ? I2C_SLAVE_FORCE : I2C_SLAVE, |
293 | itoptr(addr), | 295 | itoptr(addr), |
294 | "can't set address to 0x%02x", addr); | 296 | "can't set address to 0x%02x", addr); |
295 | } | 297 | } |
296 | #endif /* ENABLE_I2CGET || ENABLE_I2CSET || ENABLE_I2CDUMP */ | 298 | #endif |
297 | 299 | ||
298 | #if ENABLE_I2CGET || ENABLE_I2CSET | 300 | #if ENABLE_I2CGET || ENABLE_I2CSET |
299 | static int i2c_parse_data_addr(const char *data_addr) | 301 | static int i2c_parse_data_addr(const char *data_addr) |
@@ -1052,24 +1054,19 @@ struct adap_desc { | |||
1052 | const char *algo; | 1054 | const char *algo; |
1053 | }; | 1055 | }; |
1054 | 1056 | ||
1055 | static const struct adap_desc adap_descs[] = { | 1057 | static const struct adap_desc adap_descs[] ALIGN_PTR = { |
1056 | { .funcs = "dummy", | 1058 | { .funcs = "dummy", .algo = "Dummy bus", }, |
1057 | .algo = "Dummy bus", }, | 1059 | { .funcs = "isa", .algo = "ISA bus", }, |
1058 | { .funcs = "isa", | 1060 | { .funcs = "i2c", .algo = "I2C adapter", }, |
1059 | .algo = "ISA bus", }, | 1061 | { .funcs = "smbus", .algo = "SMBus adapter", }, |
1060 | { .funcs = "i2c", | ||
1061 | .algo = "I2C adapter", }, | ||
1062 | { .funcs = "smbus", | ||
1063 | .algo = "SMBus adapter", }, | ||
1064 | }; | 1062 | }; |
1065 | 1063 | ||
1066 | struct i2c_func | 1064 | struct i2c_func { |
1067 | { | ||
1068 | long value; | 1065 | long value; |
1069 | const char* name; | 1066 | const char* name; |
1070 | }; | 1067 | }; |
1071 | 1068 | ||
1072 | static const struct i2c_func i2c_funcs_tab[] = { | 1069 | static const struct i2c_func i2c_funcs_tab[] ALIGN_PTR = { |
1073 | { .value = I2C_FUNC_I2C, | 1070 | { .value = I2C_FUNC_I2C, |
1074 | .name = "I2C" }, | 1071 | .name = "I2C" }, |
1075 | { .value = I2C_FUNC_SMBUS_QUICK, | 1072 | { .value = I2C_FUNC_SMBUS_QUICK, |
@@ -1152,12 +1149,12 @@ static void NORETURN list_i2c_busses_and_exit(void) | |||
1152 | /* Simple version for ISA chips. */ | 1149 | /* Simple version for ISA chips. */ |
1153 | snprintf(path, NAME_MAX, "%s/%s/name", | 1150 | snprintf(path, NAME_MAX, "%s/%s/name", |
1154 | i2cdev_path, de->d_name); | 1151 | i2cdev_path, de->d_name); |
1155 | fp = fopen(path, "r"); | 1152 | fp = fopen_for_read(path); |
1156 | if (fp == NULL) { | 1153 | if (fp == NULL) { |
1157 | snprintf(path, NAME_MAX, | 1154 | snprintf(path, NAME_MAX, |
1158 | "%s/%s/device/name", | 1155 | "%s/%s/device/name", |
1159 | i2cdev_path, de->d_name); | 1156 | i2cdev_path, de->d_name); |
1160 | fp = fopen(path, "r"); | 1157 | fp = fopen_for_read(path); |
1161 | } | 1158 | } |
1162 | 1159 | ||
1163 | /* Non-ISA chips require the hard-way. */ | 1160 | /* Non-ISA chips require the hard-way. */ |
@@ -1178,7 +1175,7 @@ static void NORETURN list_i2c_busses_and_exit(void) | |||
1178 | "%s/%s/device/%s/name", | 1175 | "%s/%s/device/%s/name", |
1179 | i2cdev_path, de->d_name, | 1176 | i2cdev_path, de->d_name, |
1180 | subde->d_name); | 1177 | subde->d_name); |
1181 | fp = fopen(path, "r"); | 1178 | fp = fopen_for_read(path); |
1182 | break; | 1179 | break; |
1183 | } | 1180 | } |
1184 | } | 1181 | } |