diff options
author | Jonathan Cameron <jic23@cam.ac.uk> | 2011-10-30 13:47:25 +0100 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-10-30 13:47:25 +0100 |
commit | 06a67848c6681a73e621e47c056490d51a07289f (patch) | |
tree | df6e3df869b7b1a1f40f09b9b3a6f8b8a2ad12d6 /include/linux/i2c.h | |
parent | 4403988afc0a92b8faf59b46f51d25fafaf0e63d (diff) | |
download | blackbird-op-linux-06a67848c6681a73e621e47c056490d51a07289f.tar.gz blackbird-op-linux-06a67848c6681a73e621e47c056490d51a07289f.zip |
i2c: Functions for byte-swapped smbus_write/read_word_data
Reimplemented at least 17 times discounting error mangling cases
where it could be used.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r-- | include/linux/i2c.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index a6c652ef516d..38a21c3edd2c 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -34,6 +34,7 @@ #include <linux/sched.h> /* for completion */ #include <linux/mutex.h> #include <linux/of.h> /* for struct device_node */ +#include <linux/swab.h> /* for swab16 */ extern struct bus_type i2c_bus_type; extern struct device_type i2c_adapter_type; @@ -88,6 +89,22 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command); extern s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command, u16 value); + +static inline s32 +i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command) +{ + s32 value = i2c_smbus_read_word_data(client, command); + + return (value < 0) ? value : swab16(value); +} + +static inline s32 +i2c_smbus_write_word_swapped(const struct i2c_client *client, + u8 command, u16 value) +{ + return i2c_smbus_write_word_data(client, command, swab16(value)); +} + /* Returns the number of read bytes */ extern s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command, u8 *values); |