[PATCH RFC v2 3/4] mux: Add support for reading mux enable state from DT

Aswath Govindraju a-govindraju at ti.com
Mon Nov 22 04:56:23 PST 2021


In some cases, we might need to provide the state of the mux to be set for
the operation of a given peripheral. Therefore, pass this information using
the second argument of the mux-controls property.

Signed-off-by: Aswath Govindraju <a-govindraju at ti.com>
---

Notes:
- The function mux_control_get() always return the mux_control for a single
  line. So, control for mutiple lines cannot be represented in the
  mux-controls property.
- For representing multiple lines of control, multiple entries need to be
  used along with mux-names for reading them.
- If a device uses both the states of the mux line then #mux-control-cells
  can be set to 1 and enable_state will not be set in this case.

 drivers/mux/core.c           | 20 ++++++++++++++++++--
 include/linux/mux/consumer.h |  1 +
 include/linux/mux/driver.h   |  1 +
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 22f4709768d1..51140748d2d6 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -294,6 +294,18 @@ unsigned int mux_control_states(struct mux_control *mux)
 }
 EXPORT_SYMBOL_GPL(mux_control_states);
 
+/**
+ * mux_control_enable_state() - Query for the enable state.
+ * @mux: The mux-control to query.
+ *
+ * Return: State to be set in the mux to enable a given device
+ */
+unsigned int mux_control_enable_state(struct mux_control *mux)
+{
+	return mux->enable_state;
+}
+EXPORT_SYMBOL_GPL(mux_control_enable_state);
+
 /*
  * The mux->lock must be down when calling this function.
  */
@@ -481,8 +493,7 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
 	if (!mux_chip)
 		return ERR_PTR(-EPROBE_DEFER);
 
-	if (args.args_count > 1 ||
-	    (!args.args_count && (mux_chip->controllers > 1))) {
+	if (!args.args_count && mux_chip->controllers > 1) {
 		dev_err(dev, "%pOF: wrong #mux-control-cells for %pOF\n",
 			np, args.np);
 		put_device(&mux_chip->dev);
@@ -500,6 +511,11 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
 		return ERR_PTR(-EINVAL);
 	}
 
+	if (args.args_count == 2) {
+		mux_chip->mux[controller].enable_state = args.args[1];
+		mux_chip->mux[controller].idle_state = !args.args[1];
+	}
+
 	return &mux_chip->mux[controller];
 }
 EXPORT_SYMBOL_GPL(mux_control_get);
diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
index 7a09b040ac39..cb861eab8aad 100644
--- a/include/linux/mux/consumer.h
+++ b/include/linux/mux/consumer.h
@@ -16,6 +16,7 @@ struct device;
 struct mux_control;
 
 unsigned int mux_control_states(struct mux_control *mux);
+unsigned int mux_control_enable_state(struct mux_control *mux);
 int __must_check mux_control_select_delay(struct mux_control *mux,
 					  unsigned int state,
 					  unsigned int delay_us);
diff --git a/include/linux/mux/driver.h b/include/linux/mux/driver.h
index 18824064f8c0..7db378dabdb2 100644
--- a/include/linux/mux/driver.h
+++ b/include/linux/mux/driver.h
@@ -48,6 +48,7 @@ struct mux_control {
 	int cached_state;
 
 	unsigned int states;
+	unsigned int enable_state;
 	int idle_state;
 
 	ktime_t last_change;
-- 
2.17.1




More information about the linux-phy mailing list