Skip to contentSkip to conversation

dt-bindings: add register based devices' mux controller DT bindings

PATCH Superseded Pankaj Bansal 4 participants 11 messages Feb 24, 2019 – Feb 27, 2019

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 dt-bindings: add register based devices' mux controller DT bindings

This adds device tree binding documentation for generic register based multiplexer controlled by a bitfields in a parent device's register range.

---

Notes:
V3:
- Added the patch in series with the driver patch
- Fixed the node value out of bitfield error
- removed the "parent register r/w functions" line V2:
- Removed syscon reference from txt file
- Removed loading zeroes from hex numbers
- Fixed the depth of dts nodes
- fixed minor formatting errors

 .../devicetree/bindings/mux/reg-mux.txt      | 83 ++++++++++++++++++
 1 file changed, 83 insertions(+)
Documentation/devicetree/bindings/mux/reg-mux.txt new file +83 -0
new file mode 100644
index 000000000000..8bea6129c113
@@ -0,0 +1,83 @@
+Generic register bitfield-based multiplexer controller bindings
+
+Define register bitfields to be used to control multiplexers. The parent
+device tree node must be a device node to provide register r/w access.
+
+Required properties:
+- compatible : "reg-mux"
+- #mux-control-cells : <1>
+- mux-reg-masks : an array of register offset and pre-shifted bitfield mask
+                  pairs, each describing a single mux control.
+* Standard mux-controller bindings as decribed in mux-controller.txt
+
+Optional properties:
+- idle-states : if present, the state the muxes will have when idle. The
+		special state MUX_IDLE_AS_IS is the default.
+
+The multiplexer state of each multiplexer is defined as the value of the
+bitfield described by the corresponding register offset and bitfield mask pair
+in the mux-reg-masks array.
+
+Example:
+
+&i2c0 {
+	fpga@66 { // fpga connected to i2c
+		compatible = "fsl,lx2160aqds-fpga", "fsl,fpga-qixis-i2c",
+			     "simple-mfd";
+		reg = <0x66>;
+
+		mux: mux-controller { // Mux Producer
+			compatible = "reg-mux";
+			#mux-control-cells = <1>;
+			mux-reg-masks = <0x54 0xf8>, /* 0: reg 0x54, bits 7:3 */
+					<0x54 0x07>; /* 1: reg 0x54, bits 2:0 */
+		};
+	};
+};
+
+mdio-mux-1 { // Mux consumer
+	compatible = "mdio-mux";
+	mux-controls = <&mux 0>;
+	mdio-parent-bus = <&emdio1>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+
+	mdio@0 {
+		reg = <0x0>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
+
+	mdio@8 {
+		reg = <0x8>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
+
+	..
+	..
+};
+
+mdio-mux-2 { // Mux consumer
+	compatible = "mdio-mux";
+	mux-controls = <&mux 1>;
+	mdio-parent-bus = <&emdio2>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+
+	mdio@0 {
+		reg = <0x0>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
+
+	mdio@1 {
+		reg = <0x1>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
+
+	..
+	..
+};
+
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 2/2 drivers: mux: Add Generic regmap bitfield-based multiplexer in mmio-mux

Generic register bitfield-based multiplexer that controls the multiplexer producer defined under a parent node.
The driver corresponding to parent node provides register read/write capabilities.

---

Notes:
V3:
- Added the patch in series with device tree binding patch
- Added the NULL return handling for regmap
V2:
- removed seperate driver regmap.c and added the regmap function in mmio.c based on compatible field, the syscon or regmap function would be called
- Modified the KConfig as per Peter's comments

 drivers/mux/Kconfig | 12 ++++++------
 drivers/mux/mmio.c  | 10 +++++++---
 2 files changed, 13 insertions(+), 9 deletions(-)
drivers/mux/Kconfig +6 -6
index 7659d6c5f718..e5c571fd232c 100644
@@ -46,14 +46,14 @@ config MUX_GPIO
 	  be called mux-gpio.
 
 config MUX_MMIO
-	tristate "MMIO register bitfield-controlled Multiplexer"
-	depends on (OF && MFD_SYSCON) || COMPILE_TEST
+	tristate "MMIO/Regmap register bitfield-controlled Multiplexer"
+	depends on OF || COMPILE_TEST
 	help
-	  MMIO register bitfield-controlled Multiplexer controller.
+	  MMIO/Regmap register bitfield-controlled Multiplexer controller.
 
-	  The driver builds multiplexer controllers for bitfields in a syscon
-	  register. For N bit wide bitfields, there will be 2^N possible
-	  multiplexer states.
+	  The driver builds multiplexer controllers for bitfields in either
+	  a syscon register or a driver regmap register. For N bit wide
+	  bitfields, there will be 2^N possible multiplexer states.
 
 	  To compile the driver as a module, choose M here: the module will
 	  be called mux-mmio.
drivers/mux/mmio.c +7 -3
index 935ac44aa209..cc02155e4644 100644
@@ -28,6 +28,7 @@ static const struct mux_control_ops mux_mmio_ops = {
 
 static const struct of_device_id mux_mmio_dt_ids[] = {
 	{ .compatible = "mmio-mux", },
+	{ .compatible = "reg-mux", },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, mux_mmio_dt_ids);
@@ -43,9 +44,12 @@ static int mux_mmio_probe(struct platform_device *pdev)
 	int ret;
 	int i;
 
-	regmap = syscon_node_to_regmap(np->parent);
-	if (IS_ERR(regmap)) {
-		ret = PTR_ERR(regmap);
+	if (of_device_is_compatible(np, "mmio-mux"))
+		regmap = syscon_node_to_regmap(np->parent);
+	else
+		regmap = dev_get_regmap(dev->parent, NULL);
+	if (IS_ERR_OR_NULL(regmap)) {
+		ret = PTR_ERR_OR_ZERO(regmap) ? PTR_ERR(regmap) : -ENODEV;
 		dev_err(dev, "failed to get regmap: %d\n", ret);
 		return ret;
 	}
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v3 2/2] drivers: mux: Add Generic regmap bitfield-based multiplexer in mmio-mux

Quoted 61 lines · Pankaj Bansal

Generic register bitfield-based multiplexer that controls the multiplexer producer defined under a parent node.
The driver corresponding to parent node provides register read/write capabilities.

---

Notes:
V3:
- Added the patch in series with device tree binding patch
- Added the NULL return handling for regmap
V2:
- removed seperate driver regmap.c and added the regmap function in mmio.c based on compatible field, the syscon or regmap function would be called
- Modified the KConfig as per Peter's comments

 drivers/mux/Kconfig | 12 ++++++------
 drivers/mux/mmio.c  | 10 +++++++---
 2 files changed, 13 insertions(+), 9 deletions(-)
drivers/mux/Kconfig +6 -6
index 7659d6c5f718..e5c571fd232c 100644
@@ -46,14 +46,14 @@ config MUX_GPIO
 	  be called mux-gpio.
 
 config MUX_MMIO
-	tristate "MMIO register bitfield-controlled Multiplexer"
-	depends on (OF && MFD_SYSCON) || COMPILE_TEST
+	tristate "MMIO/Regmap register bitfield-controlled Multiplexer"
+	depends on OF || COMPILE_TEST
 	help
-	  MMIO register bitfield-controlled Multiplexer controller.
+	  MMIO/Regmap register bitfield-controlled Multiplexer controller.
 
-	  The driver builds multiplexer controllers for bitfields in a syscon
-	  register. For N bit wide bitfields, there will be 2^N possible
-	  multiplexer states.
+	  The driver builds multiplexer controllers for bitfields in either
+	  a syscon register or a driver regmap register. For N bit wide
+	  bitfields, there will be 2^N possible multiplexer states.
 
 	  To compile the driver as a module, choose M here: the module will
 	  be called mux-mmio.
drivers/mux/mmio.c +1 -0
index 935ac44aa209..cc02155e4644 100644
@@ -28,6 +28,7 @@ static const struct mux_control_ops mux_mmio_ops = {
 
 static const struct of_device_id mux_mmio_dt_ids[] = {
 	{ .compatible = "mmio-mux", },
+	{ .compatible = "reg-mux", },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, mux_mmio_dt_ids);
@@ -43,9 +44,12 @@ static int mux_mmio_probe(struct platform_device *pdev)
 	int ret;
 	int i;

drivers/mux/mmio.c static int mux_mmio_probe(struct platform_device *pdev) · line 52

Quoted 10 lines
drivers/mux/mmio.c +6 -3
 
-	regmap = syscon_node_to_regmap(np->parent);
-	if (IS_ERR(regmap)) {
-		ret = PTR_ERR(regmap);
+	if (of_device_is_compatible(np, "mmio-mux"))
+		regmap = syscon_node_to_regmap(np->parent);
+	else
+		regmap = dev_get_regmap(dev->parent, NULL);
+	if (IS_ERR_OR_NULL(regmap)) {
+		ret = PTR_ERR_OR_ZERO(regmap) ? PTR_ERR(regmap) : -ENODEV;

The above is not correct, this should be better (untested):

		ret = PTR_ERR(regmap) ?: -ENODEV;

Cheers,
Peter

Quoted 4 lines
drivers/mux/mmio.c +0 -0
 		dev_err(dev, "failed to get regmap: %d\n", ret);
 		return ret;
 	}
#3 lore raw

RE: [PATCH v3 2/2] drivers: mux: Add Generic regmap bitfield-based multiplexer in mmio-mux

Hi Peter,

Quoted 84 lines

-----Original Message-----
From: Peter Rosin [mailto:[email protected]]
Sent: Monday, 25 February, 2019 08:14 PM
To: Pankaj Bansal <[email protected]>; Leo Li <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v3 2/2] drivers: mux: Add Generic regmap bitfield-based multiplexer in mmio-mux

Quoted 6 lines · Pankaj Bansal

Generic register bitfield-based multiplexer that controls the multiplexer producer defined under a parent node.
The driver corresponding to parent node provides register read/write capabilities.

Quoted 8 lines

---

Notes:
V3:
- Added the patch in series with device tree binding patch
- Added the NULL return handling for regmap
V2:
- removed seperate driver regmap.c and added the regmap function in

mmio.c

Quoted 37 lines

based on compatible field, the syscon or regmap function would be called
- Modified the KConfig as per Peter's comments

 drivers/mux/Kconfig | 12 ++++++------  drivers/mux/mmio.c  | 10
+++++++---
 2 files changed, 13 insertions(+), 9 deletions(-)
drivers/mux/Kconfig index renamed from drivers/mux/Kconfig +0 -0

7659d6c5f718..e5c571fd232c 100644

drivers/mux/Kconfig +6 -6
@@ -46,14 +46,14 @@ config MUX_GPIO
 	  be called mux-gpio.
 
 config MUX_MMIO
-	tristate "MMIO register bitfield-controlled Multiplexer"
-	depends on (OF && MFD_SYSCON) || COMPILE_TEST
+	tristate "MMIO/Regmap register bitfield-controlled Multiplexer"
+	depends on OF || COMPILE_TEST
 	help
-	  MMIO register bitfield-controlled Multiplexer controller.
+	  MMIO/Regmap register bitfield-controlled Multiplexer controller.
 
-	  The driver builds multiplexer controllers for bitfields in a syscon
-	  register. For N bit wide bitfields, there will be 2^N possible
-	  multiplexer states.
+	  The driver builds multiplexer controllers for bitfields in either
+	  a syscon register or a driver regmap register. For N bit wide
+	  bitfields, there will be 2^N possible multiplexer states.
 
 	  To compile the driver as a module, choose M here: the module will
 	  be called mux-mmio.
drivers/mux/mmio.c index renamed from drivers/mux/mmio.c +0 -0

935ac44aa209..cc02155e4644 100644

drivers/mux/mmio.c static const struct mux_control_ops mux_mmio_ops = { · line 34

Quoted 7 lines
drivers/mux/mmio.c +1 -0
@@ -28,6 +28,7 @@ static const struct mux_control_ops mux_mmio_ops = {
 
 static const struct of_device_id mux_mmio_dt_ids[] = {
 	{ .compatible = "mmio-mux", },
+	{ .compatible = "reg-mux", },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, mux_mmio_dt_ids); @@ -43,9 +44,12 @@

static

drivers/mux/mmio.c static int mux_mmio_probe(struct platform_device *pdev)

Quoted 13 lines

int mux_mmio_probe(struct platform_device *pdev)

drivers/mux/mmio.c +6 -3
 	int ret;
 	int i;
 
-	regmap = syscon_node_to_regmap(np->parent);
-	if (IS_ERR(regmap)) {
-		ret = PTR_ERR(regmap);
+	if (of_device_is_compatible(np, "mmio-mux"))
+		regmap = syscon_node_to_regmap(np->parent);
+	else
+		regmap = dev_get_regmap(dev->parent, NULL);
+	if (IS_ERR_OR_NULL(regmap)) {
+		ret = PTR_ERR_OR_ZERO(regmap) ? PTR_ERR(regmap) : -

ENODEV;

Quoted 3 lines

The above is not correct, this should be better (untested):

		ret = PTR_ERR(regmap) ?: -ENODEV;

Omitting the second operand in ternary operator is not standard. https://stackoverflow.com/questions/34559705/ternary-operator-without-the-middle-expression

Although, it *has been* used in kernel in many places
https://livegrep.com/search/linux?q=file%3A%5C.c%24%20%5C%3F%5C%3A&fold_case=auto&regex=true&context=true

Quoted 8 lines

Cheers,
Peter

Quoted 4 lines
drivers/mux/mmio.c +0 -0
 		dev_err(dev, "failed to get regmap: %d\n", ret);
 		return ret;
 	}
#4 lore raw

Re: [PATCH v3 2/2] drivers: mux: Add Generic regmap bitfield-based multiplexer in mmio-mux

Quoted 9 lines · Pankaj Bansal
Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (IS_ERR_OR_NULL(regmap)) {
+		ret = PTR_ERR_OR_ZERO(regmap) ? PTR_ERR(regmap) : -

ENODEV;

The above is not correct, this should be better (untested):

		ret = PTR_ERR(regmap) ?: -ENODEV;

Omitting the second operand in ternary operator is not standard. https://stackoverflow.com/questions/34559705/ternary-operator-without-the-middle-expression

Irrelevant, a great many non-standard features are used in the kernel.

Quoted 2 lines

Although, it *has been* used in kernel in many places
https://livegrep.com/search/linux?q=file%3A%5C.c%24%20%5C%3F%5C%3A&fold_case=auto&regex=true&context=true

Yes, a local grep suggests that there are plenty of instances in the kernel. In fact, there are multiple instances even in the kernel/ directory so it's not some fringe thing. My conclusion is that it makes for readable code and is perfectly safe to use in the kernel, which apparently does not care about compilers that do not understand the construct.

$ git grep '?:' *.[ch] | wc
    773    4830   54975

I you still don't buy that and don't want to sign-off on it, then write

		ret = IS_ERR(regmap) ? PTR_ERR(regmap) : -ENODEV;

But that's just wordy and less readable, methinks.

However, the best thing to do, according to your maintainer, is still the original suggestion to fixup the NULL as early as possible with

		regmap = dev_get_regmap(dev->parent, NULL) ?: ERR_PTR(-ENODEV);

And leave the error handling block alone. Can you please just do that and be done with it?

Cheers,
Peter

maintainer
#5 lore raw
In reply to Pankaj Bansal
Quoted 26 lines · Pankaj Bansal

This adds device tree binding documentation for generic register based multiplexer controlled by a bitfields in a parent device's register range.

---

Notes:
V3:
- Added the patch in series with the driver patch
- Fixed the node value out of bitfield error
- removed the "parent register r/w functions" line V2:
- Removed syscon reference from txt file
- Removed loading zeroes from hex numbers
- Fixed the depth of dts nodes
- fixed minor formatting errors

 .../devicetree/bindings/mux/reg-mux.txt      | 83 ++++++++++++++++++
 1 file changed, 83 insertions(+)
Documentation/devicetree/bindings/mux/reg-mux.txt new file +0 -0
new file mode 100644
index 000000000000..8bea6129c113

Documentation/devicetree/bindings/mux/reg-mux.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +4 -0
@@ -0,0 +1,83 @@
+Generic register bitfield-based multiplexer controller bindings
+
+Define register bitfields to be used to control multiplexers. The parent
+device tree node must be a device node to provide register r/w access.

We generally avoid register bit level bindings like this...

What happens when I need 8 or 16-bit accesses. Or some quirky encoding of the bits. Or non-contiguous bit fields... It's an endless extending of the binding to try to handle different cases.

Quoted 20 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +20 -0
+
+Required properties:
+- compatible : "reg-mux"
+- #mux-control-cells : <1>
+- mux-reg-masks : an array of register offset and pre-shifted bitfield mask
+                  pairs, each describing a single mux control.
+* Standard mux-controller bindings as decribed in mux-controller.txt
+
+Optional properties:
+- idle-states : if present, the state the muxes will have when idle. The
+		special state MUX_IDLE_AS_IS is the default.
+
+The multiplexer state of each multiplexer is defined as the value of the
+bitfield described by the corresponding register offset and bitfield mask pair
+in the mux-reg-masks array.
+
+Example:
+
+&i2c0 {
+	fpga@66 { // fpga connected to i2c

Documentation/devicetree/bindings/mux/reg-mux.txt line 33

Quoted 10 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +9 -0
+		compatible = "fsl,lx2160aqds-fpga", "fsl,fpga-qixis-i2c",
+			     "simple-mfd";
+		reg = <0x66>;
+
+		mux: mux-controller { // Mux Producer
+			compatible = "reg-mux";
 
+			#mux-control-cells = <1>;
+			mux-reg-masks = <0x54 0xf8>, /* 0: reg 0x54, bits 7:3 */
+					<0x54 0x07>; /* 1: reg 0x54, bits 2:0 */

You can accomplish the same thing by moving these 2 properties to the parent. The parent driver can register a generic mux if that's appropriate.

Rob

#6 lore raw
Quoted 35 lines · Rob Herring
Quoted 26 lines · Pankaj Bansal

This adds device tree binding documentation for generic register based multiplexer controlled by a bitfields in a parent device's register range.

---

Notes:
V3:
- Added the patch in series with the driver patch
- Fixed the node value out of bitfield error
- removed the "parent register r/w functions" line V2:
- Removed syscon reference from txt file
- Removed loading zeroes from hex numbers
- Fixed the depth of dts nodes
- fixed minor formatting errors

 .../devicetree/bindings/mux/reg-mux.txt      | 83 ++++++++++++++++++
 1 file changed, 83 insertions(+)
Documentation/devicetree/bindings/mux/reg-mux.txt new file +0 -0
new file mode 100644
index 000000000000..8bea6129c113

Documentation/devicetree/bindings/mux/reg-mux.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +4 -0
@@ -0,0 +1,83 @@
+Generic register bitfield-based multiplexer controller bindings
+
+Define register bitfields to be used to control multiplexers. The parent
+device tree node must be a device node to provide register r/w access.

We generally avoid register bit level bindings like this...

Quoted 3 lines

What happens when I need 8 or 16-bit accesses. Or some quirky encoding of the bits. Or non-contiguous bit fields... It's an endless extending of the binding to try to handle different cases.

I think the intention here is to mimic the existing mmio-mux binding (Documentation/devicetree/bindings/mux/mmio-mux.txt) so that the existing mmio-mux driver can be extended to cover both MMIO and non-MMIO register based muxes. The bit-width of the register access will be taken care of by the regmap framework. It is probably true that this can not cover all the register based mux device if they do have quircky register layout, but I think it should be good enough to cover majority of the cases. If there are devices that cannot be covered by the generic binding and driver, they could create their own bindings and drivers.

Quoted 28 lines
Quoted 27 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +26 -0
+
+Required properties:
+- compatible : "reg-mux"
+- #mux-control-cells : <1>
+- mux-reg-masks : an array of register offset and pre-shifted bitfield mask
+                  pairs, each describing a single mux control.
+* Standard mux-controller bindings as decribed in mux-controller.txt
+
+Optional properties:
+- idle-states : if present, the state the muxes will have when idle. The
+             special state MUX_IDLE_AS_IS is the default.
+
+The multiplexer state of each multiplexer is defined as the value of the
+bitfield described by the corresponding register offset and bitfield mask pair
+in the mux-reg-masks array.
+
+Example:
+
+&i2c0 {
+     fpga@66 { // fpga connected to i2c
+             compatible = "fsl,lx2160aqds-fpga", "fsl,fpga-qixis-i2c",
+                          "simple-mfd";
+             reg = <0x66>;
+
+             mux: mux-controller { // Mux Producer
+                     compatible = "reg-mux";
Quoted 7 lines

Documentation/devicetree/bindings/mux/reg-mux.txt line 33

Quoted 3 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +3 -0
+                     #mux-control-cells = <1>;
+                     mux-reg-masks = <0x54 0xf8>, /* 0: reg 0x54, bits 7:3 */
+                                     <0x54 0x07>; /* 1: reg 0x54, bits 2:0 */

You can accomplish the same thing by moving these 2 properties to the parent. The parent driver can register a generic mux if that's appropriate.

Again, the intention is to reuse the generic mux binding and driver.

Regards,
Leo

maintainer
#7 lore raw
Quoted 40 lines · Li Yang
Quoted 35 lines · Rob Herring
Quoted 26 lines · Pankaj Bansal

This adds device tree binding documentation for generic register based multiplexer controlled by a bitfields in a parent device's register range.

---

Notes:
V3:
- Added the patch in series with the driver patch
- Fixed the node value out of bitfield error
- removed the "parent register r/w functions" line V2:
- Removed syscon reference from txt file
- Removed loading zeroes from hex numbers
- Fixed the depth of dts nodes
- fixed minor formatting errors

 .../devicetree/bindings/mux/reg-mux.txt      | 83 ++++++++++++++++++
 1 file changed, 83 insertions(+)
Documentation/devicetree/bindings/mux/reg-mux.txt new file +0 -0
new file mode 100644
index 000000000000..8bea6129c113

Documentation/devicetree/bindings/mux/reg-mux.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +4 -0
@@ -0,0 +1,83 @@
+Generic register bitfield-based multiplexer controller bindings
+
+Define register bitfields to be used to control multiplexers. The parent
+device tree node must be a device node to provide register r/w access.

We generally avoid register bit level bindings like this...

Quoted 3 lines

What happens when I need 8 or 16-bit accesses. Or some quirky encoding of the bits. Or non-contiguous bit fields... It's an endless extending of the binding to try to handle different cases.

Quoted 10 lines

I think the intention here is to mimic the existing mmio-mux binding (Documentation/devicetree/bindings/mux/mmio-mux.txt) so that the existing mmio-mux driver can be extended to cover both MMIO and non-MMIO register based muxes. The bit-width of the register access will be taken care of by the regmap framework. It is probably true that this can not cover all the register based mux device if they do have quircky register layout, but I think it should be good enough to cover majority of the cases. If there are devices that cannot be covered by the generic binding and driver, they could create their own bindings and drivers.

Other than the somewhat misleading name, why not just reuse the existing binding? Worst case, just add another compatible to it and renane the file. That would have saved me reviewing the whole thing again...

But really, you should just be able to use what is there and determine the type of access from the parent node (or I suppose regmap does that for you).

Rob

#8 lore raw

Hi Rob,

Quoted 64 lines

-----Original Message-----
From: Rob Herring [mailto:[email protected]]
Sent: Wednesday, 27 February, 2019 03:31 AM
To: Leo Li <[email protected]>
Cc: Pankaj Bansal <[email protected]>; Peter Rosin <[email protected]>; Frank Rowand <[email protected]>; [email protected]
Subject: Re: [PATCH v3 1/2] dt-bindings: add register based devices' mux controller DT bindings

Quoted 5 lines · Li Yang
Quoted 4 lines · Rob Herring
Quoted 2 lines · Pankaj Bansal

This adds device tree binding documentation for generic register based multiplexer controlled by a bitfields in a parent device's register

range.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines

---

Notes:
V3:
- Added the patch in series with the driver patch
- Fixed the node value out of bitfield error
- removed the "parent register r/w functions" line V2:
- Removed syscon reference from txt file
- Removed loading zeroes from hex numbers
- Fixed the depth of dts nodes
- fixed minor formatting errors

 .../devicetree/bindings/mux/reg-mux.txt      | 83 ++++++++++++++++++
 1 file changed, 83 insertions(+)
Quoted 11 lines
Quoted 11 lines

Documentation/devicetree/bindings/mux/reg-mux.txt line 4

Quoted 11 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +4 -0
new file mode 100644
index 000000000000..8bea6129c113
@@ -0,0 +1,83 @@
+Generic register bitfield-based multiplexer controller bindings
+
+Define register bitfields to be used to control multiplexers. The
+parent device tree node must be a device node to provide register r/w

access.

Quoted 7 lines
Quoted 6 lines

We generally avoid register bit level bindings like this...

What happens when I need 8 or 16-bit accesses. Or some quirky encoding of the bits. Or non-contiguous bit fields... It's an endless extending of the binding to try to handle different cases.

Quoted 10 lines

I think the intention here is to mimic the existing mmio-mux binding (Documentation/devicetree/bindings/mux/mmio-mux.txt) so that the existing mmio-mux driver can be extended to cover both MMIO and non-MMIO register based muxes. The bit-width of the register access will be taken care of by the regmap framework. It is probably true that this can not cover all the register based mux device if they do have quircky register layout, but I think it should be good enough to cover majority of the cases. If there are devices that cannot be covered by the generic binding and driver, they could create their own bindings and drivers.

Quoted 4 lines

Other than the somewhat misleading name, why not just reuse the existing binding? Worst case, just add another compatible to it and renane the file. That would have saved me reviewing the whole thing again...

I guess I can rename mmio-mux to reg-mux and add the bindings in it. Because really, the MMIO mux is a special case of register based mux, where the register access is memory mapped. @Peter Rosin : Are you okay with this?

Quoted 2 lines

But really, you should just be able to use what is there and determine the type of access from the parent node (or I suppose regmap does that for you).

The intention is to have an indication that the parent devices produces one (or many) mux Producers, which are controlled by parent devices' registers.
Which is why I chose compatible "reg-mux".

The parent device's register can be written in any way (MMIO / SPI / I2C) etc.

Quoted 2 lines

Rob

#9 lore raw
Quoted 66 lines · Pankaj Bansal

Hi Rob,

Quoted 64 lines

-----Original Message-----
From: Rob Herring [mailto:[email protected]]
Sent: Wednesday, 27 February, 2019 03:31 AM
To: Leo Li <[email protected]>
Cc: Pankaj Bansal <[email protected]>; Peter Rosin <[email protected]>; Frank Rowand <[email protected]>; [email protected]
Subject: Re: [PATCH v3 1/2] dt-bindings: add register based devices' mux controller DT bindings

Quoted 5 lines · Li Yang
Quoted 4 lines · Rob Herring
Quoted 2 lines · Pankaj Bansal

This adds device tree binding documentation for generic register based multiplexer controlled by a bitfields in a parent device's register

range.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines

---

Notes:
V3:
- Added the patch in series with the driver patch
- Fixed the node value out of bitfield error
- removed the "parent register r/w functions" line V2:
- Removed syscon reference from txt file
- Removed loading zeroes from hex numbers
- Fixed the depth of dts nodes
- fixed minor formatting errors

 .../devicetree/bindings/mux/reg-mux.txt      | 83 ++++++++++++++++++
 1 file changed, 83 insertions(+)
Quoted 11 lines
Quoted 11 lines

Documentation/devicetree/bindings/mux/reg-mux.txt line 4

Quoted 11 lines
Documentation/devicetree/bindings/mux/reg-mux.txt new file +4 -0
new file mode 100644
index 000000000000..8bea6129c113
@@ -0,0 +1,83 @@
+Generic register bitfield-based multiplexer controller bindings
+
+Define register bitfields to be used to control multiplexers. The
+parent device tree node must be a device node to provide register r/w

access.

Quoted 17 lines
Quoted 6 lines

We generally avoid register bit level bindings like this...

What happens when I need 8 or 16-bit accesses. Or some quirky encoding of the bits. Or non-contiguous bit fields... It's an endless extending of the binding to try to handle different cases.

I think the intention here is to mimic the existing mmio-mux binding (Documentation/devicetree/bindings/mux/mmio-mux.txt) so that the existing mmio-mux driver can be extended to cover both MMIO and non-MMIO register based muxes. The bit-width of the register access will be taken care of by the regmap framework. It is probably true that this can not cover all the register based mux device if they do have quircky register layout, but I think it should be good enough to cover majority of the cases. If there are devices that cannot be covered by the generic binding and driver, they could create their own bindings and drivers.

Quoted 8 lines
Quoted 4 lines

Other than the somewhat misleading name, why not just reuse the existing binding? Worst case, just add another compatible to it and renane the file. That would have saved me reviewing the whole thing again...

I guess I can rename mmio-mux to reg-mux and add the bindings in it. Because really, the MMIO mux is a special case of register based mux, where the register access is memory mapped. @Peter Rosin : Are you okay with this?

It's so obvious now that Rob points it out. Sorry for not realizing this all by myself when I reviewed the initial revisions. I made the connection for the driver itself, but not so for the binding. How silly, and sorry again for the trouble.

So, please rename the file with the binding, and hack the text to cover both compatibles (mmio-mux and reg-mux), because I think it would be very confusing to reuse the mmio-mux compatible for a "reg-mux" that is not mmio based.

Quoted 6 lines
Quoted 2 lines

But really, you should just be able to use what is there and determine the type of access from the parent node (or I suppose regmap does that for you).

The intention is to have an indication that the parent devices produces one (or many) mux Producers, which are controlled by parent devices' registers.
Which is why I chose compatible "reg-mux".

This is not what Rob is talking about, he is talking about /not/ adding a new compatible at all, and have the driver simply try both of syscon_node_to_regmap(np->parent) and dev_get_regmap(dev->parent, NULL) (in some other) and go with anything that is returned.

However, as I said above, that leads to confusing naming in the dts, and adding a new compatible feels like it's worth it.

Cheers,
Peter

Quoted 1 line

The parent device's register can be written in any way (MMIO / SPI / I2C) etc.

#10 lore raw
Quoted 4 lines · Peter Rosin

This is not what Rob is talking about, he is talking about /not/ adding a new compatible at all, and have the driver simply try both of syscon_node_to_regmap(np->parent) and dev_get_regmap(dev->parent, NULL) (in some other) and go with anything that is returned.

"(in some order)", sigh...

Cheers,
Peter