diff mbox series

[v1,1/8] i2c: Introduce i2c_10bit_addr_from_msg()

Message ID 20250212163359.2407327-2-andriy.shevchenko@linux.intel.com
State New
Headers show
Series i2c: busses: Introduce and use i2c_10bit_addr_from_msg() | expand

Commit Message

Andy Shevchenko Feb. 12, 2025, 4:32 p.m. UTC
There are already a lot of drivers that have been using
i2c_8bit_addr_from_msg() for 7-bit addresses, now it's time
to have the similar for 10-bit addresses.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/i2c.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 997e80649889..4d281ff5582b 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -952,6 +952,16 @@  static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
 	return (msg->addr << 1) | (msg->flags & I2C_M_RD);
 }
 
+static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
+{
+	/*
+	 * 10-bit address
+	 *   addr_1: 5'b11110 | addr[9:8] | (R/nW)
+	 *   addr_2: addr[7:0]
+	 */
+	return 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7) | (msg->flags & I2C_M_RD);
+}
+
 u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
 void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);