[PATCH v13 2/8] i2c: mux: add idle_state property to i2c_mux_core

Marcus Folkesson marcus.folkesson at gmail.com
Thu Oct 15 04:01:49 PDT 2026


Muxes treat their channels differently when idle.
Let the mux core have this information to make it available for
internal use.

Possible idle states are:
 - I2C_MUX_IDLE_AS_IS: Leave channels as is when idle
 - I2C_MUX_IDLE_DISCONNECT: Disconnect channel (set HiZ when idle)
 - I2C_MUX_IDLE_UNKNOWN: Unknown idle state
 - <n>: Enable channel n (starting from 0) when idle"

Default value is set to I2C_MUX_IDLE_UNKNOWN.

Reviewed-by: Andy Shevchenko <andriy.shevchenko at intel.com>
Signed-off-by: Marcus Folkesson <marcus.folkesson at gmail.com>
---
 drivers/i2c/i2c-mux.c   |  1 +
 include/linux/i2c-mux.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 53428098ddc7..94cc019b222f 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -248,6 +248,7 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
 	muxc->select = select;
 	muxc->deselect = deselect;
 	muxc->max_adapters = max_adapters;
+	muxc->idle_state = I2C_MUX_IDLE_UNKNOWN;
 
 	return muxc;
 }
diff --git a/include/linux/i2c-mux.h b/include/linux/i2c-mux.h
index 1784ac7afb11..17690f4f0dbe 100644
--- a/include/linux/i2c-mux.h
+++ b/include/linux/i2c-mux.h
@@ -14,6 +14,11 @@
 #ifdef __KERNEL__
 
 #include <linux/bitops.h>
+#include <linux/i2c.h>
+
+#define I2C_MUX_IDLE_AS_IS      (-1)
+#define I2C_MUX_IDLE_DISCONNECT (-2)
+#define I2C_MUX_IDLE_UNKNOWN	(-3)
 
 struct i2c_mux_core {
 	struct i2c_adapter *parent;
@@ -22,6 +27,18 @@ struct i2c_mux_core {
 	unsigned int arbitrator:1;
 	unsigned int gate:1;
 
+	/*
+	 * The mux state used by the driver when idle.
+	 * Possible idle states are:
+	 *  - I2C_MUX_IDLE_AS_IS: Leave channels as is when idle
+	 *  - I2C_MUX_IDLE_DISCONNECT: Disconnect channel (set HiZ when idle)
+	 *  - I2C_MUX_IDLE_UNKNOWN: Unknown idle state
+	 *  - <n>: Enable channel n (starting from 0) when idle"
+	 *
+	 * Default value is set to I2C_MUX_IDLE_UNKNOWN.
+	 */
+	int idle_state;
+
 	void *priv;
 
 	int (*select)(struct i2c_mux_core *, u32 chan_id);
@@ -38,6 +55,46 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
 				   int (*select)(struct i2c_mux_core *, u32),
 				   int (*deselect)(struct i2c_mux_core *, u32));
 
+static inline int i2c_mux_set_idle_state(struct i2c_mux_core *muxc, int state)
+{
+	switch (state) {
+	case I2C_MUX_IDLE_AS_IS:
+	case I2C_MUX_IDLE_UNKNOWN:
+		for (int i = 0; i < muxc->num_adapters; i++) {
+			/*
+			 * idle_state is incompatible with channels that have a
+			 * different clock frequency than the parent adapter.
+			 */
+			if (muxc->adapter[i]->clock_Hz != muxc->parent->clock_Hz)
+				return -EINVAL;
+		}
+		break;
+
+	case I2C_MUX_IDLE_DISCONNECT:
+		break;
+
+	default:
+		if (state < 0 || state >= muxc->num_adapters)
+			return -EINVAL;
+
+		/*
+		 * idle_state cannot select a channel with a different clock
+		 * frequency than the parent adapter.
+		 */
+		if (muxc->adapter[state]->clock_Hz != muxc->parent->clock_Hz)
+			return -EINVAL;
+		break;
+	}
+
+	muxc->idle_state = state;
+	return 0;
+}
+
+static inline int i2c_mux_idle_state(struct i2c_mux_core *muxc)
+{
+	return muxc->idle_state;
+}
+
 /* flags for i2c_mux_alloc */
 #define I2C_MUX_LOCKED     BIT(0)
 #define I2C_MUX_ARBITRATOR BIT(1)

-- 
2.55.0




More information about the linux-arm-kernel mailing list