diff options
author | Bartosz Golaszewski <bartekgola@gmail.com> | 2015-06-05 10:27:28 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-06-07 18:05:34 +0200 |
commit | 314742747deecd454ae58dfd68be453115ba226c (patch) | |
tree | 1cec4e02ab66823bd559835f8e9360284882dd49 | |
parent | d291c2fdd5cb8616605c67ecbfb04274fa094242 (diff) | |
download | busybox-w32-314742747deecd454ae58dfd68be453115ba226c.tar.gz busybox-w32-314742747deecd454ae58dfd68be453115ba226c.tar.bz2 busybox-w32-314742747deecd454ae58dfd68be453115ba226c.zip |
i2cdetect: don't die on addresses already in use by drivers
We can't use i2c_set_slave_addr() in i2cdetect, as we have to check for
EBUSY after calling ioctl(I2C_SLAVE) and print 'UU' on busy addresses
instead of bailing-out.
While we're at it: reorder definitions of local vars in i2cdetect_main().
function old new delta
i2cdetect_main 703 744 +41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 41/0) Total: 41 bytes
text data bss dec hex filename
826097 4164 9584 839845 cd0a5 busybox_old
826145 4164 9584 839893 cd0d5 busybox_unstripped
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/i2c_tools.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index 7034dc9a8..d5127ec27 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c | |||
@@ -355,6 +355,13 @@ static void i2c_set_pec(int fd, int pec) | |||
355 | itoptr(pec ? 1 : 0), | 355 | itoptr(pec ? 1 : 0), |
356 | "can't set PEC"); | 356 | "can't set PEC"); |
357 | } | 357 | } |
358 | |||
359 | static void i2c_set_slave_addr(int fd, int addr, int force) | ||
360 | { | ||
361 | ioctl_or_perror_and_die(fd, force ? I2C_SLAVE_FORCE : I2C_SLAVE, | ||
362 | itoptr(addr), | ||
363 | "can't set address to 0x%02x", addr); | ||
364 | } | ||
358 | #endif /* ENABLE_I2CGET || ENABLE_I2CSET || ENABLE_I2CDUMP */ | 365 | #endif /* ENABLE_I2CGET || ENABLE_I2CSET || ENABLE_I2CDUMP */ |
359 | 366 | ||
360 | #if ENABLE_I2CGET || ENABLE_I2CSET | 367 | #if ENABLE_I2CGET || ENABLE_I2CSET |
@@ -390,13 +397,6 @@ static int i2c_dev_open(int i2cbus) | |||
390 | return fd; | 397 | return fd; |
391 | } | 398 | } |
392 | 399 | ||
393 | static void i2c_set_slave_addr(int fd, int addr, int force) | ||
394 | { | ||
395 | ioctl_or_perror_and_die(fd, force ? I2C_SLAVE_FORCE : I2C_SLAVE, | ||
396 | itoptr(addr), | ||
397 | "can't set address to 0x%02x", addr); | ||
398 | } | ||
399 | |||
400 | /* Size reducing helpers for xxx_check_funcs(). */ | 400 | /* Size reducing helpers for xxx_check_funcs(). */ |
401 | static void get_funcs_matrix(int fd, unsigned long *funcs) | 401 | static void get_funcs_matrix(int fd, unsigned long *funcs) |
402 | { | 402 | { |
@@ -1281,11 +1281,9 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv) | |||
1281 | opt_F = (1 << 4), opt_l = (1 << 5); | 1281 | opt_F = (1 << 4), opt_l = (1 << 5); |
1282 | const char *const optstr = "yaqrFl"; | 1282 | const char *const optstr = "yaqrFl"; |
1283 | 1283 | ||
1284 | int fd, bus_num, i, j, mode = DETECT_MODE_AUTO; | 1284 | int fd, bus_num, i, j, mode = DETECT_MODE_AUTO, status; |
1285 | int status; | 1285 | unsigned first = 0x00, last = 0x77, opts; |
1286 | unsigned first = 0x00, last = 0x77; | ||
1287 | unsigned long funcs; | 1286 | unsigned long funcs; |
1288 | unsigned opts; | ||
1289 | 1287 | ||
1290 | opt_complementary = "q--r:r--q:" /* mutually exclusive */ | 1288 | opt_complementary = "q--r:r--q:" /* mutually exclusive */ |
1291 | "?3"; /* up to 3 args */ | 1289 | "?3"; /* up to 3 args */ |
@@ -1370,7 +1368,16 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv) | |||
1370 | continue; | 1368 | continue; |
1371 | } | 1369 | } |
1372 | 1370 | ||
1373 | i2c_set_slave_addr(fd, i + j, 0); | 1371 | status = ioctl(fd, I2C_SLAVE, itoptr(i + j)); |
1372 | if (status < 0) { | ||
1373 | if (errno == EBUSY) { | ||
1374 | printf("UU "); | ||
1375 | continue; | ||
1376 | } | ||
1377 | |||
1378 | bb_perror_msg_and_die( | ||
1379 | "can't set address to 0x%02x", i + j); | ||
1380 | } | ||
1374 | 1381 | ||
1375 | switch (mode) { | 1382 | switch (mode) { |
1376 | case DETECT_MODE_READ: | 1383 | case DETECT_MODE_READ: |