aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-dev.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-07-12 08:12:29 -0400
committerJean Delvare <khali@hyperion.delvare>2007-07-12 08:12:29 -0400
commit4b2643d7d9bdcd776749e17f73c168ddf02e93cb (patch)
tree1642900ea1c196cc27d120f0af4de44fff30633e /drivers/i2c/i2c-dev.c
parentba7fbb723f50ab2607989a282af655fb0fab0492 (diff)
i2c: Fix the i2c_smbus_read_i2c_block_data() prototype
Let the drivers specify how many bytes they want to read with i2c_smbus_read_i2c_block_data(). So far, the block count was hard-coded to I2C_SMBUS_BLOCK_MAX (32), which did not make much sense. Many driver authors complained about this before, and I believe it's about time to fix it. Right now, authors have to do technically stupid things, such as individual byte reads or full-fledged I2C messaging, to work around the problem. We do not want to encourage that. I even found that some bus drivers (e.g. i2c-amd8111) already implemented I2C block read the "right" way, that is, they didn't follow the old, broken standard. The fact that it was never noticed before just shows how little i2c_smbus_read_i2c_block_data() was used, which isn't that surprising given how broken its prototype was so far. There are some obvious compatiblity considerations: * This changes the i2c_smbus_read_i2c_block_data() prototype. Users outside the kernel tree will notice at compilation time, and will have to update their code. * User-space has access to i2c_smbus_xfer() directly using i2c-dev, so the changed expectations would affect tools such as i2cdump. In order to preserve binary compatibility, we give I2C_SMBUS_I2C_BLOCK_DATA a new numeric value, and define I2C_SMBUS_I2C_BLOCK_BROKEN with the old numeric value. When i2c-dev receives a transaction with the old value, it can convert it to the new format on the fly. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c/i2c-dev.c')
-rw-r--r--drivers/i2c/i2c-dev.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index e7a709710592..64eee9551b22 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -283,6 +283,7 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
283 (data_arg.size != I2C_SMBUS_WORD_DATA) && 283 (data_arg.size != I2C_SMBUS_WORD_DATA) &&
284 (data_arg.size != I2C_SMBUS_PROC_CALL) && 284 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
285 (data_arg.size != I2C_SMBUS_BLOCK_DATA) && 285 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
286 (data_arg.size != I2C_SMBUS_I2C_BLOCK_BROKEN) &&
286 (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) && 287 (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
287 (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) { 288 (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
288 dev_dbg(&client->adapter->dev, 289 dev_dbg(&client->adapter->dev,
@@ -329,10 +330,18 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
329 330
330 if ((data_arg.size == I2C_SMBUS_PROC_CALL) || 331 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
331 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 332 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
333 (data_arg.size == I2C_SMBUS_I2C_BLOCK_DATA) ||
332 (data_arg.read_write == I2C_SMBUS_WRITE)) { 334 (data_arg.read_write == I2C_SMBUS_WRITE)) {
333 if (copy_from_user(&temp, data_arg.data, datasize)) 335 if (copy_from_user(&temp, data_arg.data, datasize))
334 return -EFAULT; 336 return -EFAULT;
335 } 337 }
338 if (data_arg.size == I2C_SMBUS_I2C_BLOCK_BROKEN) {
339 /* Convert old I2C block commands to the new
340 convention. This preserves binary compatibility. */
341 data_arg.size = I2C_SMBUS_I2C_BLOCK_DATA;
342 if (data_arg.read_write == I2C_SMBUS_READ)
343 temp.block[0] = I2C_SMBUS_BLOCK_MAX;
344 }
336 res = i2c_smbus_xfer(client->adapter,client->addr,client->flags, 345 res = i2c_smbus_xfer(client->adapter,client->addr,client->flags,
337 data_arg.read_write, 346 data_arg.read_write,
338 data_arg.command,data_arg.size,&temp); 347 data_arg.command,data_arg.size,&temp);