aboutsummaryrefslogtreecommitdiff
path: root/miscutils/i2c_tools.c
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartekgola@gmail.com>2015-10-27 17:15:00 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-11-01 20:55:09 +0100
commit99f025a4999ee9d44db17d8abfbde7813bf99de1 (patch)
tree12f4bdfe0e76a7a048a19369b9959a5a061dba68 /miscutils/i2c_tools.c
parent1062391365981a09069f96509937b7f1181b7484 (diff)
downloadbusybox-w32-99f025a4999ee9d44db17d8abfbde7813bf99de1.tar.gz
busybox-w32-99f025a4999ee9d44db17d8abfbde7813bf99de1.tar.bz2
busybox-w32-99f025a4999ee9d44db17d8abfbde7813bf99de1.zip
i2cdetect: fix address skipping in auto mode
If the bus doesn't support SMBus Quick Write or Receive Byte commands and we're running in auto mode all addresses will be skipped resulting in an empty table being printed. This is caused by not restoring the auto mode after it's been changed for certain address ranges - we need an additional variable to hold the temporary state. Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/i2c_tools.c')
-rw-r--r--miscutils/i2c_tools.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
index d77e6bacf..c5baaa78e 100644
--- a/miscutils/i2c_tools.c
+++ b/miscutils/i2c_tools.c
@@ -1200,7 +1200,7 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv)
1200 opt_F = (1 << 4), opt_l = (1 << 5); 1200 opt_F = (1 << 4), opt_l = (1 << 5);
1201 const char *const optstr = "yaqrFl"; 1201 const char *const optstr = "yaqrFl";
1202 1202
1203 int fd, bus_num, i, j, mode = I2CDETECT_MODE_AUTO, status; 1203 int fd, bus_num, i, j, mode = I2CDETECT_MODE_AUTO, status, cmd;
1204 unsigned first = 0x03, last = 0x77, opts; 1204 unsigned first = 0x03, last = 0x77, opts;
1205 unsigned long funcs; 1205 unsigned long funcs;
1206 1206
@@ -1273,19 +1273,20 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv)
1273 for(j = 0; j < 16; j++) { 1273 for(j = 0; j < 16; j++) {
1274 fflush_all(); 1274 fflush_all();
1275 1275
1276 cmd = mode;
1276 if (mode == I2CDETECT_MODE_AUTO) { 1277 if (mode == I2CDETECT_MODE_AUTO) {
1277 if ((i+j >= 0x30 && i+j <= 0x37) || 1278 if ((i+j >= 0x30 && i+j <= 0x37) ||
1278 (i+j >= 0x50 && i+j <= 0x5F)) 1279 (i+j >= 0x50 && i+j <= 0x5F))
1279 mode = I2CDETECT_MODE_READ; 1280 cmd = I2CDETECT_MODE_READ;
1280 else 1281 else
1281 mode = I2CDETECT_MODE_QUICK; 1282 cmd = I2CDETECT_MODE_QUICK;
1282 } 1283 }
1283 1284
1284 /* Skip unwanted addresses. */ 1285 /* Skip unwanted addresses. */
1285 if (i+j < first 1286 if (i+j < first
1286 || i+j > last 1287 || i+j > last
1287 || (mode == I2CDETECT_MODE_READ && !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) 1288 || (cmd == I2CDETECT_MODE_READ && !(funcs & I2C_FUNC_SMBUS_READ_BYTE))
1288 || (mode == I2CDETECT_MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_QUICK))) 1289 || (cmd == I2CDETECT_MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_QUICK)))
1289 { 1290 {
1290 printf(" "); 1291 printf(" ");
1291 continue; 1292 continue;
@@ -1302,7 +1303,7 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv)
1302 "can't set address to 0x%02x", i + j); 1303 "can't set address to 0x%02x", i + j);
1303 } 1304 }
1304 1305
1305 switch (mode) { 1306 switch (cmd) {
1306 case I2CDETECT_MODE_READ: 1307 case I2CDETECT_MODE_READ:
1307 /* 1308 /*
1308 * This is known to lock SMBus on various 1309 * This is known to lock SMBus on various