All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] MUX: Add support for mux-states
@ 2021-12-02 12:40 Aswath Govindraju
  2021-12-02 12:40 ` [PATCH v2 1/2] dt-bindings: mux: Document mux-states property Aswath Govindraju
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Aswath Govindraju @ 2021-12-02 12:40 UTC (permalink / raw)
  Cc: linux-kernel, devicetree, Rob Herring, Peter Rosin,
	Marc Kleine-Budde, Vignesh Raghavendra, Kishon Vijay Abraham I,
	Aswath Govindraju

The following series of patches add support for reading mux
state from the device tree.

changes since v1:
- Made grammer corrections and added more information
  on the usage for mux-states and mux-controls

Aswath Govindraju (2):
  dt-bindings: mux: Document mux-states property
  mux: Add support for reading mux state from consumer DT node

 .../devicetree/bindings/mux/gpio-mux.yaml     |  11 +-
 .../devicetree/bindings/mux/mux-consumer.yaml |  21 ++
 .../bindings/mux/mux-controller.yaml          |  26 ++-
 drivers/mux/core.c                            | 219 ++++++++++++++++--
 include/linux/mux/consumer.h                  |  19 +-
 5 files changed, 271 insertions(+), 25 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/2] dt-bindings: mux: Document mux-states property
  2021-12-02 12:40 [PATCH v2 0/2] MUX: Add support for mux-states Aswath Govindraju
@ 2021-12-02 12:40 ` Aswath Govindraju
  2021-12-06 20:55   ` Rob Herring
  2021-12-02 12:40 ` [PATCH v2 2/2] mux: Add support for reading mux state from consumer DT node Aswath Govindraju
  2021-12-17  5:57 ` [PATCH v2 0/2] MUX: Add support for mux-states Peter Rosin
  2 siblings, 1 reply; 10+ messages in thread
From: Aswath Govindraju @ 2021-12-02 12:40 UTC (permalink / raw)
  Cc: linux-kernel, devicetree, Rob Herring, Peter Rosin,
	Marc Kleine-Budde, Vignesh Raghavendra, Kishon Vijay Abraham I,
	Aswath Govindraju

In some cases, it is required to provide the state to which the mux
controller has to be set to, from the consumer device tree node. Document
the property mux-states that can be used for adding this support.

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

Note:
- on running dt_binding_check with "DT_CHECKER_FLAGS=-m" the following
  error was seen,

 LINT    Documentation/devicetree/bindings
  CHKDT   Documentation/devicetree/bindings/processed-schema-examples.json
  SCHEMA  Documentation/devicetree/bindings/processed-schema-examples.json
  DTC     Documentation/devicetree/bindings/mux/mux-controller.example.dt.yaml
  CHECK   Documentation/devicetree/bindings/mux/mux-controller.example.dt.yaml
/home/gsaswath/presil/ks3-linux-integrated/linux/Documentation/devicetree/bindings/
mux/mux-controller.example.dt.yaml: can-phy4: 'mux-states' does not match any of 
the regexes: 'pinctrl-[0-9]+'
	From schema: /home/gsaswath/presil/ks3-linux-integrated/linux/
Documentation/devicetree/bindings/phy/ti,tcan104x-can.yaml

"mux-states" is a new property that is being added and the patch adding this
property to TCAN104x can transceiver bindings will be sent as a follow up
of this series.

 .../devicetree/bindings/mux/gpio-mux.yaml     | 11 ++++++--
 .../devicetree/bindings/mux/mux-consumer.yaml | 21 +++++++++++++++
 .../bindings/mux/mux-controller.yaml          | 26 ++++++++++++++++++-
 3 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/mux/gpio-mux.yaml b/Documentation/devicetree/bindings/mux/gpio-mux.yaml
index 0a7c8d64981a..ee4de9fbaf4d 100644
--- a/Documentation/devicetree/bindings/mux/gpio-mux.yaml
+++ b/Documentation/devicetree/bindings/mux/gpio-mux.yaml
@@ -26,7 +26,10 @@ properties:
       List of gpios used to control the multiplexer, least significant bit first.
 
   '#mux-control-cells':
-    const: 0
+    enum: [ 0, 1 ]
+
+  '#mux-state-cells':
+    enum: [ 1, 2 ]
 
   idle-state:
     default: -1
@@ -34,7 +37,11 @@ properties:
 required:
   - compatible
   - mux-gpios
-  - "#mux-control-cells"
+anyOf:
+  - required:
+      - "#mux-control-cells"
+  - required:
+      - "#mux-state-cells"
 
 additionalProperties: false
 
diff --git a/Documentation/devicetree/bindings/mux/mux-consumer.yaml b/Documentation/devicetree/bindings/mux/mux-consumer.yaml
index 7af93298ab5c..d3d854967359 100644
--- a/Documentation/devicetree/bindings/mux/mux-consumer.yaml
+++ b/Documentation/devicetree/bindings/mux/mux-consumer.yaml
@@ -25,6 +25,17 @@ description: |
   strings to label each of the mux controllers listed in the "mux-controls"
   property.
 
+  If it is required to provide the state that the mux controller needs to
+  be set to, the property "mux-states" must be used. An optional property
+  "mux-state-names" can be used to provide a list of strings, to label
+  each of the multiplixer states listed in the "mux-states" property.
+
+  Properties "mux-controls" and "mux-states" can be used depending on how
+  the consumers want to control the mux controller. If the consumer needs
+  needs to set multiple states in a mux controller, then property
+  "mux-controls" can be used. If the consumer needs to set the mux
+  controller to a given state then property "mux-states" can be used.
+
   mux-ctrl-specifier typically encodes the chip-relative mux controller number.
   If the mux controller chip only provides a single mux controller, the
   mux-ctrl-specifier can typically be left out.
@@ -35,12 +46,22 @@ properties:
   mux-controls:
     $ref: /schemas/types.yaml#/definitions/phandle-array
 
+  mux-states:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+
   mux-control-names:
     description:
       Devices that use more than a single mux controller can use the
       "mux-control-names" property to map the name of the requested mux
       controller to an index into the list given by the "mux-controls" property.
 
+  mux-state-names:
+    description:
+      Devices that use more than a single multiplexer state can use the
+      "mux-state-names" property to map the name of the requested mux
+      controller to an index into the list given by the "mux-states"
+      property.
+
 additionalProperties: true
 
 ...
diff --git a/Documentation/devicetree/bindings/mux/mux-controller.yaml b/Documentation/devicetree/bindings/mux/mux-controller.yaml
index 736a84c3b6a5..c855fbad3884 100644
--- a/Documentation/devicetree/bindings/mux/mux-controller.yaml
+++ b/Documentation/devicetree/bindings/mux/mux-controller.yaml
@@ -25,7 +25,9 @@ description: |
   --------------------
 
   Mux controller nodes must specify the number of cells used for the
-  specifier using the '#mux-control-cells' property.
+  specifier using the '#mux-control-cells' or '#mux-state-cells' property.
+  The value of '#mux-state-cells' will always be one greater than the value
+  of '#mux-control-cells'.
 
   Optionally, mux controller nodes can also specify the state the mux should
   have when it is idle. The idle-state property is used for this. If the
@@ -67,6 +69,8 @@ select:
           pattern: '^mux-controller'
     - required:
         - '#mux-control-cells'
+    - required:
+        - '#mux-state-cells'
 
 properties:
   $nodename:
@@ -75,6 +79,9 @@ properties:
   '#mux-control-cells':
     enum: [ 0, 1 ]
 
+  '#mux-state-cells':
+    enum: [ 1, 2 ]
+
   idle-state:
     $ref: /schemas/types.yaml#/definitions/int32
     minimum: -2
@@ -179,4 +186,21 @@ examples:
             };
         };
     };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    mux1: mux-controller {
+        compatible = "gpio-mux";
+        #mux-state-cells = <1>;
+        mux-gpios = <&exp_som 2 GPIO_ACTIVE_HIGH>;
+    };
+
+    transceiver4: can-phy4 {
+        compatible = "ti,tcan1042";
+        #phy-cells = <0>;
+        max-bitrate = <5000000>;
+        standby-gpios = <&exp_som 7 GPIO_ACTIVE_HIGH>;
+        mux-states = <&mux1 1>;
+    };
 ...
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/2] mux: Add support for reading mux state from consumer DT node
  2021-12-02 12:40 [PATCH v2 0/2] MUX: Add support for mux-states Aswath Govindraju
  2021-12-02 12:40 ` [PATCH v2 1/2] dt-bindings: mux: Document mux-states property Aswath Govindraju
@ 2021-12-02 12:40 ` Aswath Govindraju
  2021-12-17  5:57 ` [PATCH v2 0/2] MUX: Add support for mux-states Peter Rosin
  2 siblings, 0 replies; 10+ messages in thread
From: Aswath Govindraju @ 2021-12-02 12:40 UTC (permalink / raw)
  Cc: linux-kernel, devicetree, Rob Herring, Peter Rosin,
	Marc Kleine-Budde, Vignesh Raghavendra, Kishon Vijay Abraham I,
	Aswath Govindraju

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
mux-states property.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
---
 drivers/mux/core.c           | 219 +++++++++++++++++++++++++++++++----
 include/linux/mux/consumer.h |  19 ++-
 2 files changed, 216 insertions(+), 22 deletions(-)

diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 22f4709768d1..7355c5ad41f7 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -29,6 +29,19 @@
  */
 #define MUX_CACHE_UNKNOWN MUX_IDLE_AS_IS
 
+/**
+ * struct mux_state -	Represents a mux controller specific to a given device
+ * @mux:		Pointer to a mux controller
+ * @state		State of the mux to be set
+ *
+ * This structure is specific to a device that acquires it and has information
+ * specific to the device.
+ */
+struct mux_state {
+	struct mux_control *mux;
+	unsigned int state;
+};
+
 static struct class mux_class = {
 	.name = "mux",
 	.owner = THIS_MODULE,
@@ -370,6 +383,31 @@ int mux_control_select_delay(struct mux_control *mux, unsigned int state,
 }
 EXPORT_SYMBOL_GPL(mux_control_select_delay);
 
+/**
+ * mux_state_select_delay() - Select mux-state
+ * @mstate: The mux-state to select
+ * @delay_us: The time to delay (in microseconds) if the mux control
+ *            changes state on select
+ *
+ * On successfully selecting the mux-state, it will be locked until
+ * there is a call to mux_state_deselect() or mux_control_deselect().
+ * If the mux-control is already selected when mux_state_select() is
+ * called, the caller will be blocked until mux_state_deselect() or
+ * mux_control_deselect() is called (by someone else).
+ *
+ * Therefore, make sure to call mux_state_deselect() when the operation is
+ * complete and the mux-control is free for others to use, but do not call
+ * mux_state_deselect() if mux_state_select() fails.
+ *
+ * Return: 0 when the mux-state has been selected or a negative
+ * errno on error.
+ */
+int mux_state_select_delay(struct mux_state *mstate, unsigned int delay_us)
+{
+	return mux_control_select_delay(mstate->mux, mstate->state, delay_us);
+}
+EXPORT_SYMBOL_GPL(mux_state_select_delay);
+
 /**
  * mux_control_try_select_delay() - Try to select the given multiplexer state.
  * @mux: The mux-control to request a change of state from.
@@ -377,7 +415,7 @@ EXPORT_SYMBOL_GPL(mux_control_select_delay);
  * @delay_us: The time to delay (in microseconds) if the mux state is changed.
  *
  * On successfully selecting the mux-control state, it will be locked until
- * mux_control_deselect() called.
+ * mux_control_deselect() or mux_state_deselect() called.
  *
  * Therefore, make sure to call mux_control_deselect() when the operation is
  * complete and the mux-control is free for others to use, but do not call
@@ -405,6 +443,27 @@ int mux_control_try_select_delay(struct mux_control *mux, unsigned int state,
 }
 EXPORT_SYMBOL_GPL(mux_control_try_select_delay);
 
+/**
+ * mux_state_try_select_delay() - Try to select the mux-state.
+ * @mstate: The mux-state to select
+ * @delay_us: The time to delay (in microseconds) if the mux state is changed.
+ *
+ * On successfully selecting the mux-state, it will be locked until
+ * mux_state_deselect() or mux_control_deselect() is called.
+ *
+ * Therefore, make sure to call mux_state_deselect() when the operation is
+ * complete and the mux-control is free for others to use, but do not call
+ * mux_state_deselect() if mux_state_try_select() fails.
+ *
+ * Return: 0 when the mux-state has been selected or a negative errno on
+ * error. Specifically -EBUSY if the mux-control is contended.
+ */
+int mux_state_try_select_delay(struct mux_state *mstate, unsigned int delay_us)
+{
+	return mux_control_try_select_delay(mstate->mux, mstate->state, delay_us);
+}
+EXPORT_SYMBOL_GPL(mux_state_try_select_delay);
+
 /**
  * mux_control_deselect() - Deselect the previously selected multiplexer state.
  * @mux: The mux-control to deselect.
@@ -431,6 +490,24 @@ int mux_control_deselect(struct mux_control *mux)
 }
 EXPORT_SYMBOL_GPL(mux_control_deselect);
 
+/**
+ * mux_state_deselect() - Deselect the previously selected multiplexer state.
+ * @mstate: The mux-state to deselect.
+ *
+ * It is required that a single call is made to mux_state_deselect() for
+ * each and every successful call made to either of mux_state_select() or
+ * mux_state_try_select().
+ *
+ * Return: 0 on success and a negative errno on error. An error can only
+ * occur if the mux has an idle state. Note that even if an error occurs, the
+ * mux-control is unlocked and is thus free for the next access.
+ */
+int mux_state_deselect(struct mux_state *mstate)
+{
+	return mux_control_deselect(mstate->mux);
+}
+EXPORT_SYMBOL_GPL(mux_state_deselect);
+
 /* Note this function returns a reference to the mux_chip dev. */
 static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
 {
@@ -441,14 +518,17 @@ static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
 	return dev ? to_mux_chip(dev) : NULL;
 }
 
-/**
- * mux_control_get() - Get the mux-control for a device.
+/*
+ * mux_get() - Get the mux-control for a device.
  * @dev: The device that needs a mux-control.
  * @mux_name: The name identifying the mux-control.
+ * @state: Pointer to where the requested state is returned, or NULL when
+ *         the required multiplexer states are handled by other means.
  *
  * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno.
  */
-struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
+static struct mux_control *mux_get(struct device *dev, const char *mux_name,
+				   unsigned int *state)
 {
 	struct device_node *np = dev->of_node;
 	struct of_phandle_args args;
@@ -458,8 +538,12 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
 	int ret;
 
 	if (mux_name) {
-		index = of_property_match_string(np, "mux-control-names",
-						 mux_name);
+		if (state)
+			index = of_property_match_string(np, "mux-state-names",
+							 mux_name);
+		else
+			index = of_property_match_string(np, "mux-control-names",
+							 mux_name);
 		if (index < 0) {
 			dev_err(dev, "mux controller '%s' not found\n",
 				mux_name);
@@ -467,12 +551,17 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
 		}
 	}
 
-	ret = of_parse_phandle_with_args(np,
-					 "mux-controls", "#mux-control-cells",
-					 index, &args);
+	if (state)
+		ret = of_parse_phandle_with_args(np,
+						 "mux-states", "#mux-state-cells",
+						 index, &args);
+	else
+		ret = of_parse_phandle_with_args(np,
+						 "mux-controls", "#mux-control-cells",
+						 index, &args);
 	if (ret) {
-		dev_err(dev, "%pOF: failed to get mux-control %s(%i)\n",
-			np, mux_name ?: "", index);
+		dev_err(dev, "%pOF: failed to get mux-%s %s(%i)\n",
+			np, state ? "state" : "control", mux_name ?: "", index);
 		return ERR_PTR(ret);
 	}
 
@@ -481,17 +570,35 @@ 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))) {
-		dev_err(dev, "%pOF: wrong #mux-control-cells for %pOF\n",
-			np, args.np);
-		put_device(&mux_chip->dev);
-		return ERR_PTR(-EINVAL);
-	}
-
 	controller = 0;
-	if (args.args_count)
-		controller = args.args[0];
+	if (state) {
+		if (args.args_count > 2 || args.args_count == 0 ||
+		    (args.args_count < 2 && mux_chip->controllers > 1)) {
+			dev_err(dev, "%pOF: wrong #mux-state-cells for %pOF\n",
+				np, args.np);
+			put_device(&mux_chip->dev);
+			return ERR_PTR(-EINVAL);
+		}
+
+		if (args.args_count == 2) {
+			controller = args.args[0];
+			*state = args.args[1];
+		} else {
+			*state = args.args[0];
+		}
+
+	} else {
+		if (args.args_count > 1 ||
+		    (!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);
+			return ERR_PTR(-EINVAL);
+		}
+
+		if (args.args_count)
+			controller = args.args[0];
+	}
 
 	if (controller >= mux_chip->controllers) {
 		dev_err(dev, "%pOF: bad mux controller %u specified in %pOF\n",
@@ -502,6 +609,18 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
 
 	return &mux_chip->mux[controller];
 }
+
+/**
+ * mux_control_get() - Get the mux-control for a device.
+ * @dev: The device that needs a mux-control.
+ * @mux_name: The name identifying the mux-control.
+ *
+ * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno.
+ */
+struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
+{
+	return mux_get(dev, mux_name, NULL);
+}
 EXPORT_SYMBOL_GPL(mux_control_get);
 
 /**
@@ -523,6 +642,26 @@ static void devm_mux_control_release(struct device *dev, void *res)
 	mux_control_put(mux);
 }
 
+/**
+ * mux_state_put() - Put away the mux-state for good.
+ * @mstate: The mux-state to put away.
+ *
+ * mux_control_put() reverses the effects of mux_control_get().
+ */
+void mux_state_put(struct mux_state *mstate)
+{
+	mux_control_put(mstate->mux);
+	kfree(mstate);
+}
+EXPORT_SYMBOL_GPL(mux_state_put);
+
+static void devm_mux_state_release(struct device *dev, void *res)
+{
+	struct mux_state *mstate = *(struct mux_state **)res;
+
+	mux_state_put(mstate);
+}
+
 /**
  * devm_mux_control_get() - Get the mux-control for a device, with resource
  *			    management.
@@ -553,6 +692,44 @@ struct mux_control *devm_mux_control_get(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_mux_control_get);
 
+/**
+ * devm_mux_state_get() - Get the mux-state for a device, with resource
+ *			  management.
+ * @dev: The device that needs a mux-control.
+ * @mux_name: The name identifying the mux-control.
+ *
+ * Return: Pointer to the mux-state, or an ERR_PTR with a negative errno.
+ */
+struct mux_state *devm_mux_state_get(struct device *dev,
+				     const char *mux_name)
+{
+	struct mux_state **ptr, *mstate;
+	struct mux_control *mux_ctrl;
+	int state;
+
+	mstate = devm_kzalloc(dev, sizeof(struct mux_state), GFP_KERNEL);
+	if (!mstate)
+		return ERR_PTR(-ENOMEM);
+
+	ptr = devres_alloc(devm_mux_state_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	mux_ctrl = mux_get(dev, mux_name, &state);
+	if (IS_ERR(mux_ctrl)) {
+		devres_free(ptr);
+		return (struct mux_state *)mux_ctrl;
+	}
+
+	mstate->mux = mux_ctrl;
+	mstate->state = state;
+	*ptr = mstate;
+	devres_add(dev, ptr);
+
+	return mstate;
+}
+EXPORT_SYMBOL_GPL(devm_mux_state_get);
+
 /*
  * Using subsys_initcall instead of module_init here to try to ensure - for
  * the non-modular case - that the subsystem is initialized when mux consumers
diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
index 7a09b040ac39..bf5abf062c21 100644
--- a/include/linux/mux/consumer.h
+++ b/include/linux/mux/consumer.h
@@ -14,33 +14,50 @@
 
 struct device;
 struct mux_control;
+struct mux_state;
 
 unsigned int mux_control_states(struct mux_control *mux);
 int __must_check mux_control_select_delay(struct mux_control *mux,
 					  unsigned int state,
 					  unsigned int delay_us);
+int __must_check mux_state_select_delay(struct mux_state *mstate,
+					unsigned int delay_us);
 int __must_check mux_control_try_select_delay(struct mux_control *mux,
 					      unsigned int state,
 					      unsigned int delay_us);
-
+int __must_check mux_state_try_select_delay(struct mux_state *mstate,
+					    unsigned int delay_us);
 static inline int __must_check mux_control_select(struct mux_control *mux,
 						  unsigned int state)
 {
 	return mux_control_select_delay(mux, state, 0);
 }
 
+static inline int __must_check mux_state_select(struct mux_state *mstate)
+{
+	return mux_state_select_delay(mstate, 0);
+}
 static inline int __must_check mux_control_try_select(struct mux_control *mux,
 						      unsigned int state)
 {
 	return mux_control_try_select_delay(mux, state, 0);
 }
 
+static inline int __must_check mux_state_try_select(struct mux_state *mstate)
+{
+	return mux_state_try_select_delay(mstate, 0);
+}
+
 int mux_control_deselect(struct mux_control *mux);
+int mux_state_deselect(struct mux_state *mstate);
 
 struct mux_control *mux_control_get(struct device *dev, const char *mux_name);
 void mux_control_put(struct mux_control *mux);
+void mux_state_put(struct mux_state *mstate);
 
 struct mux_control *devm_mux_control_get(struct device *dev,
 					 const char *mux_name);
+struct mux_state *devm_mux_state_get(struct device *dev,
+				     const char *mux_name);
 
 #endif /* _LINUX_MUX_CONSUMER_H */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] dt-bindings: mux: Document mux-states property
  2021-12-02 12:40 ` [PATCH v2 1/2] dt-bindings: mux: Document mux-states property Aswath Govindraju
@ 2021-12-06 20:55   ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2021-12-06 20:55 UTC (permalink / raw)
  To: Aswath Govindraju
  Cc: Vignesh Raghavendra, Rob Herring, Marc Kleine-Budde,
	linux-kernel, devicetree, Kishon Vijay Abraham I, Peter Rosin

On Thu, 02 Dec 2021 18:10:52 +0530, Aswath Govindraju wrote:
> In some cases, it is required to provide the state to which the mux
> controller has to be set to, from the consumer device tree node. Document
> the property mux-states that can be used for adding this support.
> 
> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
> ---
> 
> Note:
> - on running dt_binding_check with "DT_CHECKER_FLAGS=-m" the following
>   error was seen,
> 
>  LINT    Documentation/devicetree/bindings
>   CHKDT   Documentation/devicetree/bindings/processed-schema-examples.json
>   SCHEMA  Documentation/devicetree/bindings/processed-schema-examples.json
>   DTC     Documentation/devicetree/bindings/mux/mux-controller.example.dt.yaml
>   CHECK   Documentation/devicetree/bindings/mux/mux-controller.example.dt.yaml
> /home/gsaswath/presil/ks3-linux-integrated/linux/Documentation/devicetree/bindings/
> mux/mux-controller.example.dt.yaml: can-phy4: 'mux-states' does not match any of
> the regexes: 'pinctrl-[0-9]+'
> 	From schema: /home/gsaswath/presil/ks3-linux-integrated/linux/
> Documentation/devicetree/bindings/phy/ti,tcan104x-can.yaml
> 
> "mux-states" is a new property that is being added and the patch adding this
> property to TCAN104x can transceiver bindings will be sent as a follow up
> of this series.
> 
>  .../devicetree/bindings/mux/gpio-mux.yaml     | 11 ++++++--
>  .../devicetree/bindings/mux/mux-consumer.yaml | 21 +++++++++++++++
>  .../bindings/mux/mux-controller.yaml          | 26 ++++++++++++++++++-
>  3 files changed, 55 insertions(+), 3 deletions(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/2] MUX: Add support for mux-states
  2021-12-02 12:40 [PATCH v2 0/2] MUX: Add support for mux-states Aswath Govindraju
  2021-12-02 12:40 ` [PATCH v2 1/2] dt-bindings: mux: Document mux-states property Aswath Govindraju
  2021-12-02 12:40 ` [PATCH v2 2/2] mux: Add support for reading mux state from consumer DT node Aswath Govindraju
@ 2021-12-17  5:57 ` Peter Rosin
  2021-12-17  6:26   ` Peter Rosin
  2 siblings, 1 reply; 10+ messages in thread
From: Peter Rosin @ 2021-12-17  5:57 UTC (permalink / raw)
  To: Aswath Govindraju
  Cc: linux-kernel, devicetree, Rob Herring, Marc Kleine-Budde,
	Vignesh Raghavendra, Kishon Vijay Abraham I

Hi Aswath!

On 2021-12-02 13:40, Aswath Govindraju wrote:
> The following series of patches add support for reading mux
> state from the device tree.
> 
> changes since v1:
> - Made grammer corrections and added more information
>   on the usage for mux-states and mux-controls
> 
> Aswath Govindraju (2):
>   dt-bindings: mux: Document mux-states property
>   mux: Add support for reading mux state from consumer DT node
> 
>  .../devicetree/bindings/mux/gpio-mux.yaml     |  11 +-
>  .../devicetree/bindings/mux/mux-consumer.yaml |  21 ++
>  .../bindings/mux/mux-controller.yaml          |  26 ++-
>  drivers/mux/core.c                            | 219 ++++++++++++++++--
>  include/linux/mux/consumer.h                  |  19 +-
>  5 files changed, 271 insertions(+), 25 deletions(-)
> 

I finally found some time to have a last look at this (fingers crossed) and
pushed it out for testing in linux-next.

I did end up squashing in these trivial changes in patch 2/2, I hope that's
fine with you. Just holler if not...

Cheers,
Peter

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index 148e19381b79..5018403fe82f 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -368,6 +368,7 @@ MUX
   devm_mux_chip_alloc()
   devm_mux_chip_register()
   devm_mux_control_get()
+  devm_mux_state_get()
 
 NET
   devm_alloc_etherdev()
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 7355c5ad41f7..bf448069ca85 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -30,12 +30,13 @@
 #define MUX_CACHE_UNKNOWN MUX_IDLE_AS_IS
 
 /**
- * struct mux_state -	Represents a mux controller specific to a given device
- * @mux:		Pointer to a mux controller
- * @state		State of the mux to be set
+ * struct mux_state -	Represents a mux controller state specific to a given
+ *			consumer.
+ * @mux:		Pointer to a mux controller.
+ * @state		State of the mux to be selected.
  *
- * This structure is specific to a device that acquires it and has information
- * specific to the device.
+ * This structure is specific to the consumer that acquires it and has
+ * information specific to that consumer.
  */
 struct mux_state {
 	struct mux_control *mux;
@@ -354,7 +355,8 @@ static void mux_control_delay(struct mux_control *mux, unsigned int delay_us)
  * On successfully selecting the mux-control state, it will be locked until
  * there is a call to mux_control_deselect(). If the mux-control is already
  * selected when mux_control_select() is called, the caller will be blocked
- * until mux_control_deselect() is called (by someone else).
+ * until mux_control_deselect() or mux_state_deselect() is called (by someone
+ * else).
  *
  * Therefore, make sure to call mux_control_deselect() when the operation is
  * complete and the mux-control is free for others to use, but do not call
@@ -384,16 +386,15 @@ int mux_control_select_delay(struct mux_control *mux, unsigned int state,
 EXPORT_SYMBOL_GPL(mux_control_select_delay);
 
 /**
- * mux_state_select_delay() - Select mux-state
- * @mstate: The mux-state to select
- * @delay_us: The time to delay (in microseconds) if the mux control
- *            changes state on select
+ * mux_state_select_delay() - Select the given multiplexer state.
+ * @mstate: The mux-state to select.
+ * @delay_us: The time to delay (in microseconds) if the mux state is changed.
  *
- * On successfully selecting the mux-state, it will be locked until
- * there is a call to mux_state_deselect() or mux_control_deselect().
- * If the mux-control is already selected when mux_state_select() is
- * called, the caller will be blocked until mux_state_deselect() or
- * mux_control_deselect() is called (by someone else).
+ * On successfully selecting the mux-state, its mux-control will be locked
+ * until there is a call to mux_state_deselect(). If the mux-control is already
+ * selected when mux_state_select() is called, the caller will be blocked
+ * until mux_state_deselect() or mux_control_deselect() is called (by someone
+ * else).
  *
  * Therefore, make sure to call mux_state_deselect() when the operation is
  * complete and the mux-control is free for others to use, but do not call
@@ -415,7 +416,7 @@ EXPORT_SYMBOL_GPL(mux_state_select_delay);
  * @delay_us: The time to delay (in microseconds) if the mux state is changed.
  *
  * On successfully selecting the mux-control state, it will be locked until
- * mux_control_deselect() or mux_state_deselect() called.
+ * mux_control_deselect() called.
  *
  * Therefore, make sure to call mux_control_deselect() when the operation is
  * complete and the mux-control is free for others to use, but do not call
@@ -444,12 +445,12 @@ int mux_control_try_select_delay(struct mux_control *mux, unsigned int state,
 EXPORT_SYMBOL_GPL(mux_control_try_select_delay);
 
 /**
- * mux_state_try_select_delay() - Try to select the mux-state.
- * @mstate: The mux-state to select
+ * mux_state_try_select_delay() - Try to select the given multiplexer state.
+ * @mstate: The mux-state to select.
  * @delay_us: The time to delay (in microseconds) if the mux state is changed.
  *
- * On successfully selecting the mux-state, it will be locked until
- * mux_state_deselect() or mux_control_deselect() is called.
+ * On successfully selecting the mux-state, its mux-control will be locked
+ * until mux_state_deselect() is called.
  *
  * Therefore, make sure to call mux_state_deselect() when the operation is
  * complete and the mux-control is free for others to use, but do not call
@@ -642,26 +643,6 @@ static void devm_mux_control_release(struct device *dev, void *res)
 	mux_control_put(mux);
 }
 
-/**
- * mux_state_put() - Put away the mux-state for good.
- * @mstate: The mux-state to put away.
- *
- * mux_control_put() reverses the effects of mux_control_get().
- */
-void mux_state_put(struct mux_state *mstate)
-{
-	mux_control_put(mstate->mux);
-	kfree(mstate);
-}
-EXPORT_SYMBOL_GPL(mux_state_put);
-
-static void devm_mux_state_release(struct device *dev, void *res)
-{
-	struct mux_state *mstate = *(struct mux_state **)res;
-
-	mux_state_put(mstate);
-}
-
 /**
  * devm_mux_control_get() - Get the mux-control for a device, with resource
  *			    management.
@@ -692,6 +673,26 @@ struct mux_control *devm_mux_control_get(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_mux_control_get);
 
+/**
+ * mux_state_put() - Put away the mux-state for good.
+ * @mstate: The mux-state to put away.
+ *
+ * mux_control_put() reverses the effects of mux_control_get().
+ */
+void mux_state_put(struct mux_state *mstate)
+{
+	mux_control_put(mstate->mux);
+	kfree(mstate);
+}
+EXPORT_SYMBOL_GPL(mux_state_put);
+
+static void devm_mux_state_release(struct device *dev, void *res)
+{
+	struct mux_state *mstate = *(struct mux_state **)res;
+
+	mux_state_put(mstate);
+}
+
 /**
  * devm_mux_state_get() - Get the mux-state for a device, with resource
  *			  management.
diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
index bf5abf062c21..babf2a744056 100644
--- a/include/linux/mux/consumer.h
+++ b/include/linux/mux/consumer.h
@@ -27,6 +27,7 @@ int __must_check mux_control_try_select_delay(struct mux_control *mux,
 					      unsigned int delay_us);
 int __must_check mux_state_try_select_delay(struct mux_state *mstate,
 					    unsigned int delay_us);
+
 static inline int __must_check mux_control_select(struct mux_control *mux,
 						  unsigned int state)
 {
@@ -37,6 +38,7 @@ static inline int __must_check mux_state_select(struct mux_state *mstate)
 {
 	return mux_state_select_delay(mstate, 0);
 }
+
 static inline int __must_check mux_control_try_select(struct mux_control *mux,
 						      unsigned int state)
 {

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/2] MUX: Add support for mux-states
  2021-12-17  5:57 ` [PATCH v2 0/2] MUX: Add support for mux-states Peter Rosin
@ 2021-12-17  6:26   ` Peter Rosin
  2021-12-18 18:36     ` Peter Rosin
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Rosin @ 2021-12-17  6:26 UTC (permalink / raw)
  To: Aswath Govindraju
  Cc: linux-kernel, devicetree, Rob Herring, Marc Kleine-Budde,
	Vignesh Raghavendra, Kishon Vijay Abraham I

Hi again.

On 2021-12-17 06:57, Peter Rosin wrote:
> Hi Aswath!
> 
> On 2021-12-02 13:40, Aswath Govindraju wrote:
>> The following series of patches add support for reading mux
>> state from the device tree.
>>
>> changes since v1:
>> - Made grammer corrections and added more information
>>   on the usage for mux-states and mux-controls
>>
>> Aswath Govindraju (2):
>>   dt-bindings: mux: Document mux-states property
>>   mux: Add support for reading mux state from consumer DT node
>>
>>  .../devicetree/bindings/mux/gpio-mux.yaml     |  11 +-
>>  .../devicetree/bindings/mux/mux-consumer.yaml |  21 ++
>>  .../bindings/mux/mux-controller.yaml          |  26 ++-
>>  drivers/mux/core.c                            | 219 ++++++++++++++++--
>>  include/linux/mux/consumer.h                  |  19 +-
>>  5 files changed, 271 insertions(+), 25 deletions(-)
>>
> 
> I finally found some time to have a last look at this (fingers crossed) and
> pushed it out for testing in linux-next.
> 
> I did end up squashing in these trivial changes in patch 2/2, I hope that's
> fine with you. Just holler if not...
> 
> Cheers,
> Peter
> 
> diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
> index 148e19381b79..5018403fe82f 100644
> --- a/Documentation/driver-api/driver-model/devres.rst
> +++ b/Documentation/driver-api/driver-model/devres.rst
> @@ -368,6 +368,7 @@ MUX
>    devm_mux_chip_alloc()
>    devm_mux_chip_register()
>    devm_mux_control_get()
> +  devm_mux_state_get()
>  
>  NET
>    devm_alloc_etherdev()
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index 7355c5ad41f7..bf448069ca85 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -30,12 +30,13 @@
>  #define MUX_CACHE_UNKNOWN MUX_IDLE_AS_IS
>  
>  /**
> - * struct mux_state -	Represents a mux controller specific to a given device
> - * @mux:		Pointer to a mux controller
> - * @state		State of the mux to be set
> + * struct mux_state -	Represents a mux controller state specific to a given
> + *			consumer.
> + * @mux:		Pointer to a mux controller.
> + * @state		State of the mux to be selected.
>   *
> - * This structure is specific to a device that acquires it and has information
> - * specific to the device.
> + * This structure is specific to the consumer that acquires it and has
> + * information specific to that consumer.
>   */
>  struct mux_state {
>  	struct mux_control *mux;
> @@ -354,7 +355,8 @@ static void mux_control_delay(struct mux_control *mux, unsigned int delay_us)
>   * On successfully selecting the mux-control state, it will be locked until
>   * there is a call to mux_control_deselect(). If the mux-control is already
>   * selected when mux_control_select() is called, the caller will be blocked
> - * until mux_control_deselect() is called (by someone else).
> + * until mux_control_deselect() or mux_state_deselect() is called (by someone
> + * else).
>   *
>   * Therefore, make sure to call mux_control_deselect() when the operation is
>   * complete and the mux-control is free for others to use, but do not call
> @@ -384,16 +386,15 @@ int mux_control_select_delay(struct mux_control *mux, unsigned int state,
>  EXPORT_SYMBOL_GPL(mux_control_select_delay);
>  
>  /**
> - * mux_state_select_delay() - Select mux-state
> - * @mstate: The mux-state to select
> - * @delay_us: The time to delay (in microseconds) if the mux control
> - *            changes state on select
> + * mux_state_select_delay() - Select the given multiplexer state.
> + * @mstate: The mux-state to select.
> + * @delay_us: The time to delay (in microseconds) if the mux state is changed.
>   *
> - * On successfully selecting the mux-state, it will be locked until
> - * there is a call to mux_state_deselect() or mux_control_deselect().
> - * If the mux-control is already selected when mux_state_select() is
> - * called, the caller will be blocked until mux_state_deselect() or
> - * mux_control_deselect() is called (by someone else).
> + * On successfully selecting the mux-state, its mux-control will be locked
> + * until there is a call to mux_state_deselect(). If the mux-control is already
> + * selected when mux_state_select() is called, the caller will be blocked
> + * until mux_state_deselect() or mux_control_deselect() is called (by someone
> + * else).
>   *
>   * Therefore, make sure to call mux_state_deselect() when the operation is
>   * complete and the mux-control is free for others to use, but do not call
> @@ -415,7 +416,7 @@ EXPORT_SYMBOL_GPL(mux_state_select_delay);
>   * @delay_us: The time to delay (in microseconds) if the mux state is changed.
>   *
>   * On successfully selecting the mux-control state, it will be locked until
> - * mux_control_deselect() or mux_state_deselect() called.
> + * mux_control_deselect() called.
>   *
>   * Therefore, make sure to call mux_control_deselect() when the operation is
>   * complete and the mux-control is free for others to use, but do not call
> @@ -444,12 +445,12 @@ int mux_control_try_select_delay(struct mux_control *mux, unsigned int state,
>  EXPORT_SYMBOL_GPL(mux_control_try_select_delay);
>  
>  /**
> - * mux_state_try_select_delay() - Try to select the mux-state.
> - * @mstate: The mux-state to select
> + * mux_state_try_select_delay() - Try to select the given multiplexer state.
> + * @mstate: The mux-state to select.
>   * @delay_us: The time to delay (in microseconds) if the mux state is changed.
>   *
> - * On successfully selecting the mux-state, it will be locked until
> - * mux_state_deselect() or mux_control_deselect() is called.
> + * On successfully selecting the mux-state, its mux-control will be locked
> + * until mux_state_deselect() is called.
>   *
>   * Therefore, make sure to call mux_state_deselect() when the operation is
>   * complete and the mux-control is free for others to use, but do not call
> @@ -642,26 +643,6 @@ static void devm_mux_control_release(struct device *dev, void *res)
>  	mux_control_put(mux);
>  }
>  
> -/**
> - * mux_state_put() - Put away the mux-state for good.
> - * @mstate: The mux-state to put away.
> - *
> - * mux_control_put() reverses the effects of mux_control_get().
> - */
> -void mux_state_put(struct mux_state *mstate)
> -{
> -	mux_control_put(mstate->mux);
> -	kfree(mstate);
> -}
> -EXPORT_SYMBOL_GPL(mux_state_put);
> -
> -static void devm_mux_state_release(struct device *dev, void *res)
> -{
> -	struct mux_state *mstate = *(struct mux_state **)res;
> -
> -	mux_state_put(mstate);
> -}
> -
>  /**
>   * devm_mux_control_get() - Get the mux-control for a device, with resource
>   *			    management.
> @@ -692,6 +673,26 @@ struct mux_control *devm_mux_control_get(struct device *dev,
>  }
>  EXPORT_SYMBOL_GPL(devm_mux_control_get);
>  
> +/**
> + * mux_state_put() - Put away the mux-state for good.
> + * @mstate: The mux-state to put away.
> + *
> + * mux_control_put() reverses the effects of mux_control_get().

And, a couple of minutes later, I squashed in this on top:

- * mux_control_put() reverses the effects of mux_control_get().
+ * mux_state_put() reverses the effects of mux_state_get().

Cheers,
Peter

> + */
> +void mux_state_put(struct mux_state *mstate)
> +{
> +	mux_control_put(mstate->mux);
> +	kfree(mstate);
> +}
> +EXPORT_SYMBOL_GPL(mux_state_put);
> +
> +static void devm_mux_state_release(struct device *dev, void *res)
> +{
> +	struct mux_state *mstate = *(struct mux_state **)res;
> +
> +	mux_state_put(mstate);
> +}
> +
>  /**
>   * devm_mux_state_get() - Get the mux-state for a device, with resource
>   *			  management.
> diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
> index bf5abf062c21..babf2a744056 100644
> --- a/include/linux/mux/consumer.h
> +++ b/include/linux/mux/consumer.h
> @@ -27,6 +27,7 @@ int __must_check mux_control_try_select_delay(struct mux_control *mux,
>  					      unsigned int delay_us);
>  int __must_check mux_state_try_select_delay(struct mux_state *mstate,
>  					    unsigned int delay_us);
> +
>  static inline int __must_check mux_control_select(struct mux_control *mux,
>  						  unsigned int state)
>  {
> @@ -37,6 +38,7 @@ static inline int __must_check mux_state_select(struct mux_state *mstate)
>  {
>  	return mux_state_select_delay(mstate, 0);
>  }
> +
>  static inline int __must_check mux_control_try_select(struct mux_control *mux,
>  						      unsigned int state)
>  {
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/2] MUX: Add support for mux-states
  2021-12-17  6:26   ` Peter Rosin
@ 2021-12-18 18:36     ` Peter Rosin
  2021-12-18 18:37       ` [PATCH] mux: add missing mux_state_get Peter Rosin
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Rosin @ 2021-12-18 18:36 UTC (permalink / raw)
  To: Aswath Govindraju
  Cc: linux-kernel, devicetree, Rob Herring, Marc Kleine-Budde,
	Vignesh Raghavendra, Kishon Vijay Abraham I

Hi Aswath!

See below.

On 2021-12-17 07:26, Peter Rosin wrote:
> Hi again.
> 
> On 2021-12-17 06:57, Peter Rosin wrote:
>> Hi Aswath!
>>
>> On 2021-12-02 13:40, Aswath Govindraju wrote:
>>> The following series of patches add support for reading mux
>>> state from the device tree.
>>>
>>> changes since v1:
>>> - Made grammer corrections and added more information
>>>   on the usage for mux-states and mux-controls
>>>
>>> Aswath Govindraju (2):
>>>   dt-bindings: mux: Document mux-states property
>>>   mux: Add support for reading mux state from consumer DT node
>>>
>>>  .../devicetree/bindings/mux/gpio-mux.yaml     |  11 +-
>>>  .../devicetree/bindings/mux/mux-consumer.yaml |  21 ++
>>>  .../bindings/mux/mux-controller.yaml          |  26 ++-
>>>  drivers/mux/core.c                            | 219 ++++++++++++++++--
>>>  include/linux/mux/consumer.h                  |  19 +-
>>>  5 files changed, 271 insertions(+), 25 deletions(-)
>>>
>>
>> I finally found some time to have a last look at this (fingers crossed) and
>> pushed it out for testing in linux-next.
>>
>> I did end up squashing in these trivial changes in patch 2/2, I hope that's
>> fine with you. Just holler if not...
>>
>> Cheers,
>> Peter
>>
>> diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
>> index 148e19381b79..5018403fe82f 100644
>> --- a/Documentation/driver-api/driver-model/devres.rst
>> +++ b/Documentation/driver-api/driver-model/devres.rst
>> @@ -368,6 +368,7 @@ MUX
>>    devm_mux_chip_alloc()
>>    devm_mux_chip_register()
>>    devm_mux_control_get()
>> +  devm_mux_state_get()
>>  
>>  NET
>>    devm_alloc_etherdev()
>> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
>> index 7355c5ad41f7..bf448069ca85 100644
>> --- a/drivers/mux/core.c
>> +++ b/drivers/mux/core.c
>> @@ -30,12 +30,13 @@
>>  #define MUX_CACHE_UNKNOWN MUX_IDLE_AS_IS
>>  
>>  /**
>> - * struct mux_state -	Represents a mux controller specific to a given device
>> - * @mux:		Pointer to a mux controller
>> - * @state		State of the mux to be set
>> + * struct mux_state -	Represents a mux controller state specific to a given
>> + *			consumer.
>> + * @mux:		Pointer to a mux controller.
>> + * @state		State of the mux to be selected.
>>   *
>> - * This structure is specific to a device that acquires it and has information
>> - * specific to the device.
>> + * This structure is specific to the consumer that acquires it and has
>> + * information specific to that consumer.
>>   */
>>  struct mux_state {
>>  	struct mux_control *mux;
>> @@ -354,7 +355,8 @@ static void mux_control_delay(struct mux_control *mux, unsigned int delay_us)
>>   * On successfully selecting the mux-control state, it will be locked until
>>   * there is a call to mux_control_deselect(). If the mux-control is already
>>   * selected when mux_control_select() is called, the caller will be blocked
>> - * until mux_control_deselect() is called (by someone else).
>> + * until mux_control_deselect() or mux_state_deselect() is called (by someone
>> + * else).
>>   *
>>   * Therefore, make sure to call mux_control_deselect() when the operation is
>>   * complete and the mux-control is free for others to use, but do not call
>> @@ -384,16 +386,15 @@ int mux_control_select_delay(struct mux_control *mux, unsigned int state,
>>  EXPORT_SYMBOL_GPL(mux_control_select_delay);
>>  
>>  /**
>> - * mux_state_select_delay() - Select mux-state
>> - * @mstate: The mux-state to select
>> - * @delay_us: The time to delay (in microseconds) if the mux control
>> - *            changes state on select
>> + * mux_state_select_delay() - Select the given multiplexer state.
>> + * @mstate: The mux-state to select.
>> + * @delay_us: The time to delay (in microseconds) if the mux state is changed.
>>   *
>> - * On successfully selecting the mux-state, it will be locked until
>> - * there is a call to mux_state_deselect() or mux_control_deselect().
>> - * If the mux-control is already selected when mux_state_select() is
>> - * called, the caller will be blocked until mux_state_deselect() or
>> - * mux_control_deselect() is called (by someone else).
>> + * On successfully selecting the mux-state, its mux-control will be locked
>> + * until there is a call to mux_state_deselect(). If the mux-control is already
>> + * selected when mux_state_select() is called, the caller will be blocked
>> + * until mux_state_deselect() or mux_control_deselect() is called (by someone
>> + * else).
>>   *
>>   * Therefore, make sure to call mux_state_deselect() when the operation is
>>   * complete and the mux-control is free for others to use, but do not call
>> @@ -415,7 +416,7 @@ EXPORT_SYMBOL_GPL(mux_state_select_delay);
>>   * @delay_us: The time to delay (in microseconds) if the mux state is changed.
>>   *
>>   * On successfully selecting the mux-control state, it will be locked until
>> - * mux_control_deselect() or mux_state_deselect() called.
>> + * mux_control_deselect() called.
>>   *
>>   * Therefore, make sure to call mux_control_deselect() when the operation is
>>   * complete and the mux-control is free for others to use, but do not call
>> @@ -444,12 +445,12 @@ int mux_control_try_select_delay(struct mux_control *mux, unsigned int state,
>>  EXPORT_SYMBOL_GPL(mux_control_try_select_delay);
>>  
>>  /**
>> - * mux_state_try_select_delay() - Try to select the mux-state.
>> - * @mstate: The mux-state to select
>> + * mux_state_try_select_delay() - Try to select the given multiplexer state.
>> + * @mstate: The mux-state to select.
>>   * @delay_us: The time to delay (in microseconds) if the mux state is changed.
>>   *
>> - * On successfully selecting the mux-state, it will be locked until
>> - * mux_state_deselect() or mux_control_deselect() is called.
>> + * On successfully selecting the mux-state, its mux-control will be locked
>> + * until mux_state_deselect() is called.
>>   *
>>   * Therefore, make sure to call mux_state_deselect() when the operation is
>>   * complete and the mux-control is free for others to use, but do not call
>> @@ -642,26 +643,6 @@ static void devm_mux_control_release(struct device *dev, void *res)
>>  	mux_control_put(mux);
>>  }
>>  
>> -/**
>> - * mux_state_put() - Put away the mux-state for good.
>> - * @mstate: The mux-state to put away.
>> - *
>> - * mux_control_put() reverses the effects of mux_control_get().
>> - */
>> -void mux_state_put(struct mux_state *mstate)
>> -{
>> -	mux_control_put(mstate->mux);
>> -	kfree(mstate);
>> -}
>> -EXPORT_SYMBOL_GPL(mux_state_put);
>> -
>> -static void devm_mux_state_release(struct device *dev, void *res)
>> -{
>> -	struct mux_state *mstate = *(struct mux_state **)res;
>> -
>> -	mux_state_put(mstate);
>> -}
>> -
>>  /**
>>   * devm_mux_control_get() - Get the mux-control for a device, with resource
>>   *			    management.
>> @@ -692,6 +673,26 @@ struct mux_control *devm_mux_control_get(struct device *dev,
>>  }
>>  EXPORT_SYMBOL_GPL(devm_mux_control_get);
>>  
>> +/**
>> + * mux_state_put() - Put away the mux-state for good.
>> + * @mstate: The mux-state to put away.
>> + *
>> + * mux_control_put() reverses the effects of mux_control_get().
> 
> And, a couple of minutes later, I squashed in this on top:
> 
> - * mux_control_put() reverses the effects of mux_control_get().
> + * mux_state_put() reverses the effects of mux_state_get().
> 

And now I notice that there is no mux_state_get. There should be one,
in my opinion, at least if there is an exported mux_state_put.

So, Aswath, can you please test the patch that's coming as a reply
to this message on top of what is currently on its way into linux-next?

I.e. wait for the next linux-next to be released, or
https://gitlab.com/peda-linux/mux.git#for-next

Or, optionally, just grab the mux-state-get branch:

https://gitlab.com/peda-linux/mux.git#mux-state-get

Cheers,
Peter

> 
>> + */
>> +void mux_state_put(struct mux_state *mstate)
>> +{
>> +	mux_control_put(mstate->mux);
>> +	kfree(mstate);
>> +}
>> +EXPORT_SYMBOL_GPL(mux_state_put);
>> +
>> +static void devm_mux_state_release(struct device *dev, void *res)
>> +{
>> +	struct mux_state *mstate = *(struct mux_state **)res;
>> +
>> +	mux_state_put(mstate);
>> +}
>> +
>>  /**
>>   * devm_mux_state_get() - Get the mux-state for a device, with resource
>>   *			  management.
>> diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
>> index bf5abf062c21..babf2a744056 100644
>> --- a/include/linux/mux/consumer.h
>> +++ b/include/linux/mux/consumer.h
>> @@ -27,6 +27,7 @@ int __must_check mux_control_try_select_delay(struct mux_control *mux,
>>  					      unsigned int delay_us);
>>  int __must_check mux_state_try_select_delay(struct mux_state *mstate,
>>  					    unsigned int delay_us);
>> +
>>  static inline int __must_check mux_control_select(struct mux_control *mux,
>>  						  unsigned int state)
>>  {
>> @@ -37,6 +38,7 @@ static inline int __must_check mux_state_select(struct mux_state *mstate)
>>  {
>>  	return mux_state_select_delay(mstate, 0);
>>  }
>> +
>>  static inline int __must_check mux_control_try_select(struct mux_control *mux,
>>  						      unsigned int state)
>>  {
>>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] mux: add missing mux_state_get
  2021-12-18 18:36     ` Peter Rosin
@ 2021-12-18 18:37       ` Peter Rosin
  2021-12-20  6:57         ` Aswath Govindraju
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Rosin @ 2021-12-18 18:37 UTC (permalink / raw)
  To: Aswath Govindraju
  Cc: linux-kernel, devicetree, Rob Herring, Marc Kleine-Budde,
	Vignesh Raghavendra, Kishon Vijay Abraham I

And implement devm_mux_state_get in terms of the new function.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/mux/core.c           | 41 ++++++++++++++++++++++++++----------
 include/linux/mux/consumer.h |  1 +
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 7d38e7c0c02e..90073ce01539 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -673,6 +673,33 @@ struct mux_control *devm_mux_control_get(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_mux_control_get);
 
+/**
+ * mux_state_get() - Get the mux-state for a device.
+ * @dev: The device that needs a mux-state.
+ * @mux_name: The name identifying the mux-state.
+ *
+ * Return: A pointer to the mux-state, or an ERR_PTR with a negative errno.
+ */
+struct mux_state *mux_state_get(struct device *dev, const char *mux_name)
+{
+	struct mux_state *mstate;
+
+	mstate = kzalloc(sizeof(*mstate), GFP_KERNEL);
+	if (!mstate)
+		return ERR_PTR(-ENOMEM);
+
+	mstate->mux = mux_get(dev, mux_name, &mstate->state);
+	if (IS_ERR(mstate->mux)) {
+		int err = PTR_ERR(mstate->mux);
+
+		kfree(mstate);
+		return ERR_PTR(err);
+	}
+
+	return mstate;
+}
+EXPORT_SYMBOL_GPL(mux_state_get);
+
 /**
  * mux_state_put() - Put away the mux-state for good.
  * @mstate: The mux-state to put away.
@@ -705,25 +732,17 @@ struct mux_state *devm_mux_state_get(struct device *dev,
 				     const char *mux_name)
 {
 	struct mux_state **ptr, *mstate;
-	struct mux_control *mux_ctrl;
-	int state;
-
-	mstate = devm_kzalloc(dev, sizeof(struct mux_state), GFP_KERNEL);
-	if (!mstate)
-		return ERR_PTR(-ENOMEM);
 
 	ptr = devres_alloc(devm_mux_state_release, sizeof(*ptr), GFP_KERNEL);
 	if (!ptr)
 		return ERR_PTR(-ENOMEM);
 
-	mux_ctrl = mux_get(dev, mux_name, &state);
-	if (IS_ERR(mux_ctrl)) {
+	mstate = mux_state_get(dev, mux_name);
+	if (IS_ERR(mstate)) {
 		devres_free(ptr);
-		return (struct mux_state *)mux_ctrl;
+		return mstate;
 	}
 
-	mstate->mux = mux_ctrl;
-	mstate->state = state;
 	*ptr = mstate;
 	devres_add(dev, ptr);
 
diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
index babf2a744056..944678604549 100644
--- a/include/linux/mux/consumer.h
+++ b/include/linux/mux/consumer.h
@@ -54,6 +54,7 @@ int mux_control_deselect(struct mux_control *mux);
 int mux_state_deselect(struct mux_state *mstate);
 
 struct mux_control *mux_control_get(struct device *dev, const char *mux_name);
+struct mux_state *mux_state_get(struct device *dev, const char *mux_name);
 void mux_control_put(struct mux_control *mux);
 void mux_state_put(struct mux_state *mstate);
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] mux: add missing mux_state_get
  2021-12-18 18:37       ` [PATCH] mux: add missing mux_state_get Peter Rosin
@ 2021-12-20  6:57         ` Aswath Govindraju
  2021-12-20  8:50           ` Peter Rosin
  0 siblings, 1 reply; 10+ messages in thread
From: Aswath Govindraju @ 2021-12-20  6:57 UTC (permalink / raw)
  To: Peter Rosin
  Cc: linux-kernel, devicetree, Rob Herring, Marc Kleine-Budde,
	Vignesh Raghavendra, Kishon Vijay Abraham I


On 19/12/21 12:07 am, Peter Rosin wrote:
> And implement devm_mux_state_get in terms of the new function.
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>

Tested-by: Aswath Govindraju <a-govindraju@ti.com>

Thanks,
Aswath

> ---
>  drivers/mux/core.c           | 41 ++++++++++++++++++++++++++----------
>  include/linux/mux/consumer.h |  1 +
>  2 files changed, 31 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index 7d38e7c0c02e..90073ce01539 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -673,6 +673,33 @@ struct mux_control *devm_mux_control_get(struct device *dev,
>  }
>  EXPORT_SYMBOL_GPL(devm_mux_control_get);
>  
> +/**
> + * mux_state_get() - Get the mux-state for a device.
> + * @dev: The device that needs a mux-state.
> + * @mux_name: The name identifying the mux-state.
> + *
> + * Return: A pointer to the mux-state, or an ERR_PTR with a negative errno.
> + */
> +struct mux_state *mux_state_get(struct device *dev, const char *mux_name)
> +{
> +	struct mux_state *mstate;
> +
> +	mstate = kzalloc(sizeof(*mstate), GFP_KERNEL);
> +	if (!mstate)
> +		return ERR_PTR(-ENOMEM);
> +
> +	mstate->mux = mux_get(dev, mux_name, &mstate->state);
> +	if (IS_ERR(mstate->mux)) {
> +		int err = PTR_ERR(mstate->mux);
> +
> +		kfree(mstate);
> +		return ERR_PTR(err);
> +	}
> +
> +	return mstate;
> +}
> +EXPORT_SYMBOL_GPL(mux_state_get);
> +
>  /**
>   * mux_state_put() - Put away the mux-state for good.
>   * @mstate: The mux-state to put away.
> @@ -705,25 +732,17 @@ struct mux_state *devm_mux_state_get(struct device *dev,
>  				     const char *mux_name)
>  {
>  	struct mux_state **ptr, *mstate;
> -	struct mux_control *mux_ctrl;
> -	int state;
> -
> -	mstate = devm_kzalloc(dev, sizeof(struct mux_state), GFP_KERNEL);
> -	if (!mstate)
> -		return ERR_PTR(-ENOMEM);
>  
>  	ptr = devres_alloc(devm_mux_state_release, sizeof(*ptr), GFP_KERNEL);
>  	if (!ptr)
>  		return ERR_PTR(-ENOMEM);
>  
> -	mux_ctrl = mux_get(dev, mux_name, &state);
> -	if (IS_ERR(mux_ctrl)) {
> +	mstate = mux_state_get(dev, mux_name);
> +	if (IS_ERR(mstate)) {
>  		devres_free(ptr);
> -		return (struct mux_state *)mux_ctrl;
> +		return mstate;
>  	}
>  
> -	mstate->mux = mux_ctrl;
> -	mstate->state = state;
>  	*ptr = mstate;
>  	devres_add(dev, ptr);
>  
> diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
> index babf2a744056..944678604549 100644
> --- a/include/linux/mux/consumer.h
> +++ b/include/linux/mux/consumer.h
> @@ -54,6 +54,7 @@ int mux_control_deselect(struct mux_control *mux);
>  int mux_state_deselect(struct mux_state *mstate);
>  
>  struct mux_control *mux_control_get(struct device *dev, const char *mux_name);
> +struct mux_state *mux_state_get(struct device *dev, const char *mux_name);
>  void mux_control_put(struct mux_control *mux);
>  void mux_state_put(struct mux_state *mstate);
>  
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mux: add missing mux_state_get
  2021-12-20  6:57         ` Aswath Govindraju
@ 2021-12-20  8:50           ` Peter Rosin
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Rosin @ 2021-12-20  8:50 UTC (permalink / raw)
  To: Aswath Govindraju
  Cc: linux-kernel, devicetree, Rob Herring, Marc Kleine-Budde,
	Vignesh Raghavendra, Kishon Vijay Abraham I

On 2021-12-20 07:57, Aswath Govindraju wrote:
> 
> On 19/12/21 12:07 am, Peter Rosin wrote:
>> And implement devm_mux_state_get in terms of the new function.
>>
>> Signed-off-by: Peter Rosin <peda@axentia.se>
> 
> Tested-by: Aswath Govindraju <a-govindraju@ti.com>

Thanks!

I added the commit to the for-next branch. I will pass these mux
patches on to Greg when they have been in linux-next for a couple
of days for the bots to chew on. I can't be sure this will make
5.17-rc1 though, when we're already at 5.16-rc6 and the hollidays
are coming up.

We'll see.

Cheers,
Peter

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-20  8:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 12:40 [PATCH v2 0/2] MUX: Add support for mux-states Aswath Govindraju
2021-12-02 12:40 ` [PATCH v2 1/2] dt-bindings: mux: Document mux-states property Aswath Govindraju
2021-12-06 20:55   ` Rob Herring
2021-12-02 12:40 ` [PATCH v2 2/2] mux: Add support for reading mux state from consumer DT node Aswath Govindraju
2021-12-17  5:57 ` [PATCH v2 0/2] MUX: Add support for mux-states Peter Rosin
2021-12-17  6:26   ` Peter Rosin
2021-12-18 18:36     ` Peter Rosin
2021-12-18 18:37       ` [PATCH] mux: add missing mux_state_get Peter Rosin
2021-12-20  6:57         ` Aswath Govindraju
2021-12-20  8:50           ` Peter Rosin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.