Commit 47103178 authored by Jean Delvare's avatar Jean Delvare

i2c-stub: Implement I2C block support

This is required to test some drivers, for example at24.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 69b0089a
...@@ -2,9 +2,9 @@ MODULE: i2c-stub ...@@ -2,9 +2,9 @@ MODULE: i2c-stub
DESCRIPTION: DESCRIPTION:
This module is a very simple fake I2C/SMBus driver. It implements four This module is a very simple fake I2C/SMBus driver. It implements five
types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, and types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
(r/w) word data. word data, and (r/w) I2C block data.
You need to provide chip addresses as a module parameter when loading this You need to provide chip addresses as a module parameter when loading this
driver, which will then only react to SMBus commands to these addresses. driver, which will then only react to SMBus commands to these addresses.
......
...@@ -48,7 +48,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, ...@@ -48,7 +48,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
char read_write, u8 command, int size, union i2c_smbus_data * data) char read_write, u8 command, int size, union i2c_smbus_data * data)
{ {
s32 ret; s32 ret;
int i; int i, len;
struct stub_chip *chip = NULL; struct stub_chip *chip = NULL;
/* Search for the right chip */ /* Search for the right chip */
...@@ -118,6 +118,29 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, ...@@ -118,6 +118,29 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
ret = 0; ret = 0;
break; break;
case I2C_SMBUS_I2C_BLOCK_DATA:
len = data->block[0];
if (read_write == I2C_SMBUS_WRITE) {
for (i = 0; i < len; i++) {
chip->words[command + i] &= 0xff00;
chip->words[command + i] |= data->block[1 + i];
}
dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, "
"wrote %d bytes at 0x%02x.\n",
addr, len, command);
} else {
for (i = 0; i < len; i++) {
data->block[1 + i] =
chip->words[command + i] & 0xff;
}
dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, "
"read %d bytes at 0x%02x.\n",
addr, len, command);
}
ret = 0;
break;
default: default:
dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n");
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
...@@ -130,7 +153,8 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, ...@@ -130,7 +153,8 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
static u32 stub_func(struct i2c_adapter *adapter) static u32 stub_func(struct i2c_adapter *adapter)
{ {
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_I2C_BLOCK;
} }
static const struct i2c_algorithm smbus_algorithm = { static const struct i2c_algorithm smbus_algorithm = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment