diff options
author | Ron Yorston <rmy@pobox.com> | 2015-11-06 16:38:39 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2015-11-06 16:38:39 +0000 |
commit | d6c9296168ad0a770967714515ffa1fca5e60145 (patch) | |
tree | d72556385814a18a0ac039ee0b43ef6f561c317f /miscutils | |
parent | b60a9b30ba420808c4c9f540dcf92b11ee87a87b (diff) | |
parent | 196e400441652946b9c7ad7bc2d78c73885f2359 (diff) | |
download | busybox-w32-d6c9296168ad0a770967714515ffa1fca5e60145.tar.gz busybox-w32-d6c9296168ad0a770967714515ffa1fca5e60145.tar.bz2 busybox-w32-d6c9296168ad0a770967714515ffa1fca5e60145.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/i2c_tools.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index d77e6bacf..aa1c7c5cc 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c | |||
@@ -723,16 +723,18 @@ static int read_block_data(int buf_fd, int mode, int *block) | |||
723 | uint8_t cblock[I2C_SMBUS_BLOCK_MAX + I2CDUMP_NUM_REGS]; | 723 | uint8_t cblock[I2C_SMBUS_BLOCK_MAX + I2CDUMP_NUM_REGS]; |
724 | int res, blen = 0, tmp, i; | 724 | int res, blen = 0, tmp, i; |
725 | 725 | ||
726 | if (mode == I2C_SMBUS_BLOCK_DATA || mode == I2C_SMBUS_I2C_BLOCK_DATA) { | 726 | if (mode == I2C_SMBUS_BLOCK_DATA) { |
727 | res = i2c_smbus_read_block_data(buf_fd, 0, cblock); | 727 | blen = i2c_smbus_read_block_data(buf_fd, 0, cblock); |
728 | blen = res; | 728 | if (blen <= 0) |
729 | goto fail; | ||
729 | } else { | 730 | } else { |
730 | for (res = 0; res < I2CDUMP_NUM_REGS; res += tmp) { | 731 | for (res = 0; res < I2CDUMP_NUM_REGS; res += tmp) { |
731 | tmp = i2c_smbus_read_i2c_block_data( | 732 | tmp = i2c_smbus_read_i2c_block_data( |
732 | buf_fd, res, I2C_SMBUS_BLOCK_MAX, | 733 | buf_fd, res, I2C_SMBUS_BLOCK_MAX, |
733 | cblock + res); | 734 | cblock + res); |
734 | if (tmp < 0) { | 735 | if (tmp <= 0) { |
735 | bb_error_msg_and_die("block read failed"); | 736 | blen = tmp; |
737 | goto fail; | ||
736 | } | 738 | } |
737 | } | 739 | } |
738 | 740 | ||
@@ -748,6 +750,9 @@ static int read_block_data(int buf_fd, int mode, int *block) | |||
748 | } | 750 | } |
749 | 751 | ||
750 | return blen; | 752 | return blen; |
753 | |||
754 | fail: | ||
755 | bb_error_msg_and_die("block read failed: %d", blen); | ||
751 | } | 756 | } |
752 | 757 | ||
753 | /* Dump all but word data. */ | 758 | /* Dump all but word data. */ |
@@ -904,7 +909,7 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv) | |||
904 | unsigned first = 0x00, last = 0xff, opts; | 909 | unsigned first = 0x00, last = 0xff, opts; |
905 | int *block = (int *)bb_common_bufsiz1; | 910 | int *block = (int *)bb_common_bufsiz1; |
906 | char *opt_r_str, *dash; | 911 | char *opt_r_str, *dash; |
907 | int fd, res, blen; | 912 | int fd, res; |
908 | 913 | ||
909 | opt_complementary = "-2:?3"; /* from 2 to 3 args */ | 914 | opt_complementary = "-2:?3"; /* from 2 to 3 args */ |
910 | opts = getopt32(argv, optstr, &opt_r_str); | 915 | opts = getopt32(argv, optstr, &opt_r_str); |
@@ -971,7 +976,10 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv) | |||
971 | 976 | ||
972 | /* All but word data. */ | 977 | /* All but word data. */ |
973 | if (mode != I2C_SMBUS_WORD_DATA || even) { | 978 | if (mode != I2C_SMBUS_WORD_DATA || even) { |
974 | blen = read_block_data(fd, mode, block); | 979 | int blen = 0; |
980 | |||
981 | if (mode == I2C_SMBUS_BLOCK_DATA || mode == I2C_SMBUS_I2C_BLOCK_DATA) | ||
982 | blen = read_block_data(fd, mode, block); | ||
975 | 983 | ||
976 | if (mode == I2C_SMBUS_BYTE) { | 984 | if (mode == I2C_SMBUS_BYTE) { |
977 | res = i2c_smbus_write_byte(fd, first); | 985 | res = i2c_smbus_write_byte(fd, first); |
@@ -1200,7 +1208,7 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv) | |||
1200 | opt_F = (1 << 4), opt_l = (1 << 5); | 1208 | opt_F = (1 << 4), opt_l = (1 << 5); |
1201 | const char *const optstr = "yaqrFl"; | 1209 | const char *const optstr = "yaqrFl"; |
1202 | 1210 | ||
1203 | int fd, bus_num, i, j, mode = I2CDETECT_MODE_AUTO, status; | 1211 | int fd, bus_num, i, j, mode = I2CDETECT_MODE_AUTO, status, cmd; |
1204 | unsigned first = 0x03, last = 0x77, opts; | 1212 | unsigned first = 0x03, last = 0x77, opts; |
1205 | unsigned long funcs; | 1213 | unsigned long funcs; |
1206 | 1214 | ||
@@ -1270,22 +1278,23 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv) | |||
1270 | puts(" 0 1 2 3 4 5 6 7 8 9 a b c d e f"); | 1278 | puts(" 0 1 2 3 4 5 6 7 8 9 a b c d e f"); |
1271 | for (i = 0; i < 128; i += 16) { | 1279 | for (i = 0; i < 128; i += 16) { |
1272 | printf("%02x: ", i); | 1280 | printf("%02x: ", i); |
1273 | for(j = 0; j < 16; j++) { | 1281 | for (j = 0; j < 16; j++) { |
1274 | fflush_all(); | 1282 | fflush_all(); |
1275 | 1283 | ||
1284 | cmd = mode; | ||
1276 | if (mode == I2CDETECT_MODE_AUTO) { | 1285 | if (mode == I2CDETECT_MODE_AUTO) { |
1277 | if ((i+j >= 0x30 && i+j <= 0x37) || | 1286 | if ((i+j >= 0x30 && i+j <= 0x37) || |
1278 | (i+j >= 0x50 && i+j <= 0x5F)) | 1287 | (i+j >= 0x50 && i+j <= 0x5F)) |
1279 | mode = I2CDETECT_MODE_READ; | 1288 | cmd = I2CDETECT_MODE_READ; |
1280 | else | 1289 | else |
1281 | mode = I2CDETECT_MODE_QUICK; | 1290 | cmd = I2CDETECT_MODE_QUICK; |
1282 | } | 1291 | } |
1283 | 1292 | ||
1284 | /* Skip unwanted addresses. */ | 1293 | /* Skip unwanted addresses. */ |
1285 | if (i+j < first | 1294 | if (i+j < first |
1286 | || i+j > last | 1295 | || i+j > last |
1287 | || (mode == I2CDETECT_MODE_READ && !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) | 1296 | || (cmd == I2CDETECT_MODE_READ && !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) |
1288 | || (mode == I2CDETECT_MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_QUICK))) | 1297 | || (cmd == I2CDETECT_MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_QUICK))) |
1289 | { | 1298 | { |
1290 | printf(" "); | 1299 | printf(" "); |
1291 | continue; | 1300 | continue; |
@@ -1302,7 +1311,7 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv) | |||
1302 | "can't set address to 0x%02x", i + j); | 1311 | "can't set address to 0x%02x", i + j); |
1303 | } | 1312 | } |
1304 | 1313 | ||
1305 | switch (mode) { | 1314 | switch (cmd) { |
1306 | case I2CDETECT_MODE_READ: | 1315 | case I2CDETECT_MODE_READ: |
1307 | /* | 1316 | /* |
1308 | * This is known to lock SMBus on various | 1317 | * This is known to lock SMBus on various |