summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2015-12-06 23:52:39 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2015-12-08 08:38:31 +0100
commitba624ae97eea80540f8fa41a812ac732325e380d (patch)
tree7feffa5062b932fc388d05e394b981ed3b2d8c79 /include
parent2ae9bbba0742d79376eb26252b212913d9181bd8 (diff)
downloadbarebox-ba624ae97eea80540f8fa41a812ac732325e380d.tar.gz
barebox-ba624ae97eea80540f8fa41a812ac732325e380d.tar.xz
i2c: Port two utility functions from Linux kernel
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/i2c/i2c.h15
1 files changed, 15 insertions, 0 deletions
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);