aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/i2c/i2c-stub6
-rw-r--r--drivers/i2c/busses/i2c-stub.c28
2 files changed, 29 insertions, 5 deletions
diff --git a/Documentation/i2c/i2c-stub b/Documentation/i2c/i2c-stub
index 0d8be1c20c16..d9c383b30925 100644
--- a/Documentation/i2c/i2c-stub
+++ b/Documentation/i2c/i2c-stub
@@ -2,9 +2,9 @@ MODULE: i2c-stub
2 2
3DESCRIPTION: 3DESCRIPTION:
4 4
5This module is a very simple fake I2C/SMBus driver. It implements four 5This module is a very simple fake I2C/SMBus driver. It implements five
6types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, and 6types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
7(r/w) word data. 7word data, and (r/w) I2C block data.
8 8
9You need to provide chip addresses as a module parameter when loading this 9You need to provide chip addresses as a module parameter when loading this
10driver, which will then only react to SMBus commands to these addresses. 10driver, which will then only react to SMBus commands to these addresses.
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 1b7b2af94036..52ebeda1a64b 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -48,7 +48,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
48 char read_write, u8 command, int size, union i2c_smbus_data * data) 48 char read_write, u8 command, int size, union i2c_smbus_data * data)
49{ 49{
50 s32 ret; 50 s32 ret;
51 int i; 51 int i, len;
52 struct stub_chip *chip = NULL; 52 struct stub_chip *chip = NULL;
53 53
54 /* Search for the right chip */ 54 /* Search for the right chip */
@@ -118,6 +118,29 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
118 ret = 0; 118 ret = 0;
119 break; 119 break;
120 120
121 case I2C_SMBUS_I2C_BLOCK_DATA:
122 len = data->block[0];
123 if (read_write == I2C_SMBUS_WRITE) {
124 for (i = 0; i < len; i++) {
125 chip->words[command + i] &= 0xff00;
126 chip->words[command + i] |= data->block[1 + i];
127 }
128 dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, "
129 "wrote %d bytes at 0x%02x.\n",
130 addr, len, command);
131 } else {
132 for (i = 0; i < len; i++) {
133 data->block[1 + i] =
134 chip->words[command + i] & 0xff;
135 }
136 dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, "
137 "read %d bytes at 0x%02x.\n",
138 addr, len, command);
139 }
140
141 ret = 0;
142 break;
143
121 default: 144 default:
122 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); 145 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n");
123 ret = -EOPNOTSUPP; 146 ret = -EOPNOTSUPP;
@@ -130,7 +153,8 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
130static u32 stub_func(struct i2c_adapter *adapter) 153static u32 stub_func(struct i2c_adapter *adapter)
131{ 154{
132 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 155 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
133 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; 156 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
157 I2C_FUNC_SMBUS_I2C_BLOCK;
134} 158}
135 159
136static const struct i2c_algorithm smbus_algorithm = { 160static const struct i2c_algorithm smbus_algorithm = {