diff options
author | Jean Delvare <jdelvare@suse.de> | 2012-09-07 14:00:57 +0000 |
---|---|---|
committer | Jean Delvare <jdelvare@suse.de> | 2012-09-07 14:00:57 +0000 |
commit | fe0364cb218014777c6c73dbf4f6e5c93bd1f4e3 (patch) | |
tree | 0d63342e39e9b27aaa4f254b8ed560121472adc1 | |
parent | 186311fb8b683686fb4eb53c78f4b8fc3b0dc987 (diff) | |
download | i2c-tools-fe0364cb218014777c6c73dbf4f6e5c93bd1f4e3.tar.gz |
If either SMBus Quick Write or SMBus Receive Byte command is missing,
still proceed and do a best-effort detection.
git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@6064 7894878c-1315-0410-8ee3-d5d059ff63e0
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | tools/i2cdetect.c | 56 |
2 files changed, 42 insertions, 15 deletions
@@ -6,6 +6,7 @@ SVN HEAD decode-dimms: Decode module configuration type of DDR2 SDRAM Decode bus width extension of DDR3 SDRAM Don't choke when no EEPROM is found + i2cdetect: Do a best effort detection if functionality is missing i2c-dev.h: Minimize differences with kernel flavor Move SMBus helper functions to include/i2c/smbus.h i2c-stub-from-dump: Be more tolerant on input dump format diff --git a/tools/i2cdetect.c b/tools/i2cdetect.c index 73f2ba3..8041749 100644 --- a/tools/i2cdetect.c +++ b/tools/i2cdetect.c @@ -47,10 +47,11 @@ static void help(void) " If provided, FIRST and LAST limit the probing range.\n"); } -static int scan_i2c_bus(int file, int mode, int first, int last) +static int scan_i2c_bus(int file, int mode, unsigned long funcs, + int first, int last) { int i, j; - int res; + int cmd, res; printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); @@ -59,8 +60,26 @@ static int scan_i2c_bus(int file, int mode, int first, int last) for(j = 0; j < 16; j++) { fflush(stdout); + /* Select detection command for this address */ + switch (mode) { + default: + cmd = mode; + break; + case MODE_AUTO: + if ((i+j >= 0x30 && i+j <= 0x37) + || (i+j >= 0x50 && i+j <= 0x5F)) + cmd = MODE_READ; + else + cmd = MODE_QUICK; + break; + } + /* Skip unwanted addresses */ - if (i+j < first || i+j > last) { + if (i+j < first || i+j > last + || (cmd == MODE_READ && + !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) + || (cmd == MODE_QUICK && + !(funcs & I2C_FUNC_SMBUS_QUICK))) { printf(" "); continue; } @@ -79,8 +98,8 @@ static int scan_i2c_bus(int file, int mode, int first, int last) } /* Probe this address */ - switch (mode) { - case MODE_QUICK: + switch (cmd) { + default: /* MODE_QUICK */ /* This is known to corrupt the Atmel AT24RF08 EEPROM */ res = i2c_smbus_write_quick(file, @@ -91,13 +110,6 @@ static int scan_i2c_bus(int file, int mode, int first, int last) write-only chips (mainly clock chips) */ res = i2c_smbus_read_byte(file); break; - default: - if ((i+j >= 0x30 && i+j <= 0x37) - || (i+j >= 0x50 && i+j <= 0x5F)) - res = i2c_smbus_read_byte(file); - else - res = i2c_smbus_write_quick(file, - I2C_SMBUS_WRITE); } if (res < 0) @@ -318,18 +330,32 @@ int main(int argc, char *argv[]) exit(0); } - if (mode != MODE_READ && !(funcs & I2C_FUNC_SMBUS_QUICK)) { + if (!(funcs & (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_READ_BYTE))) { + fprintf(stderr, + "Error: Bus doesn't support detection commands\n"); + close(file); + exit(1); + } + if (mode == MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_QUICK)) { fprintf(stderr, "Error: Can't use SMBus Quick Write command " "on this bus\n"); close(file); exit(1); } - if (mode != MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) { + if (mode == MODE_READ && !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) { fprintf(stderr, "Error: Can't use SMBus Read Byte command " "on this bus\n"); close(file); exit(1); } + if (mode == MODE_AUTO) { + if (!(funcs & I2C_FUNC_SMBUS_QUICK)) + fprintf(stderr, "Warning: Can't use SMBus Quick Write " + "command, will skip some addresses\n"); + if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE)) + fprintf(stderr, "Warning: Can't use SMBus Read Byte " + "command, will skip some addresses\n"); + } if (!yes) { char s[2]; @@ -352,7 +378,7 @@ int main(int argc, char *argv[]) } } - res = scan_i2c_bus(file, mode, first, last); + res = scan_i2c_bus(file, mode, funcs, first, last); close(file); |