summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfram Sang <wsa@the-dreams.de>2016-04-03 20:44:45 +0200
committerWolfram Sang <wsa@the-dreams.de>2016-04-11 18:54:59 +0200
commita16d6ebca6efb73f6402f36e5aebf84f61721856 (patch)
tree149558debefac59bc26ea8576972d804f4354ab1
parente28b124564e648d933337a0708dae1323c518af7 (diff)
downloadop-kernel-dev-a16d6ebca6efb73f6402f36e5aebf84f61721856.zip
op-kernel-dev-a16d6ebca6efb73f6402f36e5aebf84f61721856.tar.gz
i2c: introduce helper function to get 8 bit address from a message
Drivers do this in various ways, let's use one standard way of doing it. Note: I2C_M_RD is bit 0, so the code could be simplified. To be extremly robust and to advertise good coding practices, I still use the ternary operator and let the compilers do the optimizing job. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--include/linux/i2c.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 200cf13b..c30833b 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -654,6 +654,11 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
return adap->nr;
}
+static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
+{
+ return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0);
+}
+
/**
* module_i2c_driver() - Helper macro for registering a modular I2C driver
* @__i2c_driver: i2c_driver struct
OpenPOWER on IntegriCloud