From ba624ae97eea80540f8fa41a812ac732325e380d Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sun, 6 Dec 2015 23:52:39 -0800 Subject: i2c: Port two utility functions from Linux kernel Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- include/i2c/i2c.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h index 33a4791c96..cf784ca1f1 100644 --- a/include/i2c/i2c.h +++ b/include/i2c/i2c.h @@ -194,6 +194,21 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client, 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_i2c_block_data(const struct i2c_client *client, u8 command, u8 length, u8 *values); -- cgit v1.2.3