Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b2643d7 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare
Browse files

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: default avatarJean Delvare <khali@linux-fr.org>
parent ba7fbb72
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ And then read the data

  or

  count = i2c_smbus_read_i2c_block_data(fd, 0x84, buffer);
  count = i2c_smbus_read_i2c_block_data(fd, 0x84, 16, buffer);

The block read should read 16 bytes.
0x84 is the block read command.
+1 −1
Original line number Diff line number Diff line
@@ -571,7 +571,7 @@ SMBus communication
                                        u8 command, u8 length,
                                        u8 *values);
  extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
                                           u8 command, u8 *values);
                                           u8 command, u8 length, u8 *values);

These ones were removed in Linux 2.6.10 because they had no users, but could
be added back later if needed:
+1 −2
Original line number Diff line number Diff line
@@ -121,8 +121,7 @@ static s32 i2c_powermac_smbus_xfer( struct i2c_adapter* adap,
		if (rc)
			goto bail;
		rc = pmac_i2c_xfer(bus, addrdir, 1, command,
				   read ? data->block : &data->block[1],
				   data->block[0]);
				   &data->block[1], data->block[0]);
		break;

        default:
+1 −1
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
		if (!(vt596_features & FEATURE_I2CBLOCK))
			goto exit_unsupported;
		if (read_write == I2C_SMBUS_READ)
			outb_p(I2C_SMBUS_BLOCK_MAX, SMBHSTDAT0);
			outb_p(data->block[0], SMBHSTDAT0);
		/* Fall through */
	case I2C_SMBUS_BLOCK_DATA:
		outb_p(command, SMBHSTCMD);
+0 −2
Original line number Diff line number Diff line
@@ -310,8 +310,6 @@ static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
		break;

	case I2C_SMBUS_I2C_BLOCK_DATA:
		if (rw == I2C_SMBUS_READ)
			data->block[0] = I2C_SMBUS_BLOCK_MAX; /* For now */
		len = data->block[0];
		if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
			return -EINVAL;
Loading