From d9927a5a5e85818155792a494dc9996ce1e0c5f0 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Fri, 30 Sep 2005 17:16:24 +0000 Subject: [PATCH] Fix a bug in argc check. Only use PEC on the register write, not the readback, as it has proven to cause trouble on some chips. Reads with PEC can be tested using i2cget. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@3109 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/dump/i2cset.c | 58 ++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/prog/dump/i2cset.c b/prog/dump/i2cset.c index d6a477fc..2ace9b3e 100644 --- a/prog/dump/i2cset.c +++ b/prog/dump/i2cset.c @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) exit(0); } - if (argc + flags < 5) + if (argc < flags + 5) help(); i2cbus = strtol(argv[flags+1], &end, 0); @@ -167,18 +167,6 @@ int main(int argc, char *argv[]) exit(1); } - if (pec) { - if (ioctl(file, I2C_PEC, 1) < 0) { - fprintf(stderr, "Error: Could not set PEC: %s\n", - strerror(errno)); - exit(1); - } - if (!(funcs & (I2C_FUNC_SMBUS_HWPEC_CALC | I2C_FUNC_I2C))) { - fprintf(stderr, "Warning: Adapter for i2c bus %d does " - "not seem to actually support PEC\n", i2cbus); - } - } - if (!yes) { char s[2]; int dont = 0; @@ -248,6 +236,18 @@ int main(int argc, char *argv[]) } } + if (pec) { + if (ioctl(file, I2C_PEC, 1) < 0) { + fprintf(stderr, "Error: Could not set PEC: %s\n", + strerror(errno)); + exit(1); + } + if (!(funcs & (I2C_FUNC_SMBUS_HWPEC_CALC | I2C_FUNC_I2C))) { + fprintf(stderr, "Warning: Adapter for i2c bus %d does " + "not seem to actually support PEC\n", i2cbus); + } + } + e1 = 0; if (size == I2C_SMBUS_WORD_DATA) { res = i2c_smbus_write_word_data(file, daddress, value); @@ -259,33 +259,19 @@ int main(int argc, char *argv[]) e1++; } + if (pec) { + if (ioctl(file, I2C_PEC, 0) < 0) { + fprintf(stderr, "Error: Could not clear PEC: %s\n", + strerror(errno)); + close(file); + exit(e1); + } + } + if (size == I2C_SMBUS_WORD_DATA) { res = i2c_smbus_read_word_data(file, daddress); } else { res = i2c_smbus_read_byte_data(file, daddress); - if (res < 0 && pec && (funcs & I2C_FUNC_SMBUS_READ_BYTE)) { - fprintf(stderr, "Warning - read_byte_data with PEC " - "failed, trying read_byte with PEC\n"); - res = i2c_smbus_read_byte(file); - } - } - - if (res < 0 && pec) { - /* Try again without PEC */ - fprintf(stderr, "Warning - readback with PEC failed, " - "trying without\n"); - e1++; - - if (ioctl(file, I2C_PEC, 0) < 0) { - fprintf(stderr, "Error: Could not clear PEC: %s\n", - strerror(errno)); - exit(1); - } - - if (size == I2C_SMBUS_WORD_DATA) - res = i2c_smbus_read_word_data(file, daddress); - else - res = i2c_smbus_read_byte_data(file, daddress); } close(file);