diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-12-06 11:06:28 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-12-06 11:06:28 -0500 |
commit | 4710317891e4824ce1510a6b5066abbd3e917750 (patch) | |
tree | 497e78c7b78485ade6d5cb84206a62903f1919a9 /drivers/i2c | |
parent | 69b0089a6750a0435570df3ba8456c77b352af55 (diff) |
i2c-stub: Implement I2C block support
This is required to test some drivers, for example at24.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/i2c-stub.c | 28 |
1 files changed, 26 insertions, 2 deletions
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, | |||
130 | static u32 stub_func(struct i2c_adapter *adapter) | 153 | static 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 | ||
136 | static const struct i2c_algorithm smbus_algorithm = { | 160 | static const struct i2c_algorithm smbus_algorithm = { |