From b33986c2ac51bf40cc9e914e3eb1efd2d9f93d39 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Mon, 28 May 2007 10:31:56 +0000 Subject: [PATCH] Support and use the new I2C block read with variable length which will be available in Linux kernel 2.6.23. Binary compatibility is guaranteed, source code compatibility isn't, but the incompatibility will be spotted quickly as the prototype of the helper function i2c_smbus_read_i2c_block_data() changed. The only problem would be if a program is calling i2c_smbus_access() directly. Hopefully this should be a rare case. The py-smbus binding code is in this case and will be adjusted soon. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4419 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 2 ++ kernel/include/i2c-dev.h | 15 ++++++++++++--- prog/dump/i2cdump.c | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 2a216324..375d38fb 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ lm_sensors CHANGES file ----------------------- SVN HEAD + File i2c-dev.h: Support I2C block reads with specified length All bus modules and documentation: Delete All chip modules and documentation: Delete Legacy hotplug modules and documentation: Delete @@ -13,6 +14,7 @@ SVN HEAD Add dme1737 support Delete support of non-sensor drivers (ddcmon, eeprom) Man page sensors.conf.5: Update the chip statement section + Program i2cdump: Use the new I2C block read function Program isadump: Detect when address bit 7 is a busy flag Fix Super-I/O exit sequence for Winbond/Fintek chips Program mkpatch: Delete diff --git a/kernel/include/i2c-dev.h b/kernel/include/i2c-dev.h index 5737d5ee..5284cf11 100644 --- a/kernel/include/i2c-dev.h +++ b/kernel/include/i2c-dev.h @@ -106,8 +106,9 @@ union i2c_smbus_data { #define I2C_SMBUS_WORD_DATA 3 #define I2C_SMBUS_PROC_CALL 4 #define I2C_SMBUS_BLOCK_DATA 5 -#define I2C_SMBUS_I2C_BLOCK_DATA 6 +#define I2C_SMBUS_I2C_BLOCK_BROKEN 6 #define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */ +#define I2C_SMBUS_I2C_BLOCK_DATA 8 /* ----- commands for the ioctl like i2c_command call: @@ -271,12 +272,20 @@ static inline __s32 i2c_smbus_write_block_data(int file, __u8 command, } /* Returns the number of read bytes */ +/* Until kernel 2.6.22, the length is hardcoded to 32 bytes. If you + ask for less than 32 bytes, your code will only work with kernels + 2.6.23 and later. */ static inline __s32 i2c_smbus_read_i2c_block_data(int file, __u8 command, - __u8 *values) + __u8 length, __u8 *values) { union i2c_smbus_data data; int i; + + if (length > 32) + length = 32; + data.block[0] = length; if (i2c_smbus_access(file,I2C_SMBUS_READ,command, + length == 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN : I2C_SMBUS_I2C_BLOCK_DATA,&data)) return -1; else { @@ -297,7 +306,7 @@ static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command, data.block[i] = values[i-1]; data.block[0] = length; return i2c_smbus_access(file,I2C_SMBUS_WRITE,command, - I2C_SMBUS_I2C_BLOCK_DATA, &data); + I2C_SMBUS_I2C_BLOCK_BROKEN, &data); } /* Returns the number of read bytes */ diff --git a/prog/dump/i2cdump.c b/prog/dump/i2cdump.c index ddcb65cd..77d53a99 100644 --- a/prog/dump/i2cdump.c +++ b/prog/dump/i2cdump.c @@ -316,7 +316,7 @@ int main(int argc, char *argv[]) } else { for (res = 0; res < 256; res += i) { i = i2c_smbus_read_i2c_block_data(file, - res, cblock + res); + res, 32, cblock + res); if (i <= 0) break; }