Skip to contentSkip to conversation

regmap: Add explict native endian flag to DT bindings

PATCH In review Mark Brown 6 participants 10 messages Jan 26, 2016 – Jan 27, 2016

Subsystems (5)
lore
Share & tools
lore

Mark Brown

author maintainer
#0 lore raw

PATCH 1/2 regmap: Add explict native endian flag to DT bindings

Currently the binding document says that if no endianness is configured we use native endian but this is not in fact true for all binding types and we do have some devices that really want native endianness such as Broadcom MIPS SoCs where switching the endianness of the CPU also switches the endianness of external IPs.

Provide an explicit option for this.

---
 Documentation/devicetree/bindings/regmap/regmap.txt | 11 +++++++----
 drivers/base/regmap/regmap.c                        |  2 ++
 2 files changed, 9 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/regmap/regmap.txt +7 -4
index b494f8b8ef72..e98a9652ccc8 100644
@@ -5,15 +5,18 @@ Index     Device     Endianness properties
 ---------------------------------------------------
 1         BE         'big-endian'
 2         LE         'little-endian'
+3	  Native     'native-endian'
 
 For one device driver, which will run in different scenarios above
 on different SoCs using the devicetree, we need one way to simplify
 this.
 
-Required properties:
-- {big,little}-endian: these are boolean properties, if absent
-  meaning that the CPU and the Device are in the same endianness mode,
-  these properties are for register values and all the buffers only.
+Optional properties:
+- {big,little,native}-endian: these are boolean properties, if absent
+  then the implementation will choose a default based on the device
+  being controlled.  These properties are for register values and all
+  the buffers only.  Native endian means that the CPU and device have
+  the same endianness.
 
 Examples:
 Scenario 1 : CPU in LE mode & device in LE mode.
drivers/base/regmap/regmap.c +2 -0
index 4ac63c0e50c7..57a7d144e629 100644
@@ -500,6 +500,8 @@ enum regmap_endian regmap_get_val_endian(struct device *dev,
 			endian = REGMAP_ENDIAN_BIG;
 		else if (of_property_read_bool(np, "little-endian"))
 			endian = REGMAP_ENDIAN_LITTLE;
+		else if (of_property_read_bool(np, "native-endian"))
+			endian = REGMAP_ENDIAN_NATIVE;
 
 		/* If the endianness was specified in DT, use that */
 		if (endian != REGMAP_ENDIAN_DEFAULT)
Signature · 1 line
2.7.0.rc3
author maintainer
#1 lore raw

RFC PATCH 2/2 MIPS: dt: Explicitly specify native endian behaviour for syscon

On many MIPS systems the endianness of IP blocks is kept the same as that of the CPU by the hardware. This includes the system controllers on these systems which are controlled via syscon which uses the regmap API which used readl() and writel() to interact with the hardware, meaning that all writes are converted to little endian when writing to the hardware. This caused a bad interaction with the regmap core in big endian mode since it was not aware of the byte swapping and so ended up performing little endian writes.

Unfortunately when this issue was noticed it was addressed by updating the DT for the affected devices to specify them as little endian. This happened to work since it resulted in two endianness swaps which cancelled each other out and gave little endian behaviour but meant that the DT was clearly not accurately describing the hardware.

The intention of commit 29bb45f25ff305 (regmap-mmio: Use native endianness for read/write) was to fix this by making regmap default to native endianness but this breaks most other MMIO users where the hardware has a fixed endianness and the implementation uses the __raw accessors which are not intended to be used outside of architecture code. Instead use the newly added native-endian DT property to say exactly what we want for these systems.

Fixes 29bb45f25ff305 (regmap-mmio: Use native endianness for read/write)

---

Posted for review only, this will interact with some other patches fixing the implementation of regmap-mmio and will probably need to be merged along with them.

 arch/mips/boot/dts/brcm/bcm6328.dtsi | 1 +
 arch/mips/boot/dts/brcm/bcm7125.dtsi | 1 +
 arch/mips/boot/dts/brcm/bcm7346.dtsi | 1 +
 arch/mips/boot/dts/brcm/bcm7358.dtsi | 1 +
 arch/mips/boot/dts/brcm/bcm7360.dtsi | 1 +
 arch/mips/boot/dts/brcm/bcm7362.dtsi | 1 +
 arch/mips/boot/dts/brcm/bcm7420.dtsi | 1 +
 arch/mips/boot/dts/brcm/bcm7425.dtsi | 1 +
 arch/mips/boot/dts/brcm/bcm7435.dtsi | 1 +
 9 files changed, 9 insertions(+)
arch/mips/boot/dts/brcm/bcm6328.dtsi +1 -0
index d52ce3d07f16..04867035ea0e 100644
@@ -73,6 +73,7 @@
 		timer: timer@10000040 {
 			compatible = "syscon";
 			reg = <0x10000040 0x2c>;
+			native-endian;
 		};
 
 		reboot {
arch/mips/boot/dts/brcm/bcm7125.dtsi +1 -0
index 4fc7ecee273c..3ae16053a0c9 100644
@@ -98,6 +98,7 @@
 		sun_top_ctrl: syscon@404000 {
 			compatible = "brcm,bcm7125-sun-top-ctrl", "syscon";
 			reg = <0x404000 0x60c>;
+			native-endian;
 		};
 
 		reboot {
arch/mips/boot/dts/brcm/bcm7346.dtsi +1 -0
index a3039bb53477..be7991917d29 100644
@@ -118,6 +118,7 @@
 		sun_top_ctrl: syscon@404000 {
 			compatible = "brcm,bcm7346-sun-top-ctrl", "syscon";
 			reg = <0x404000 0x51c>;
+			native-endian;
 		};
 
 		reboot {
arch/mips/boot/dts/brcm/bcm7358.dtsi +1 -0
index 4274ff41ec21..060805be619a 100644
@@ -112,6 +112,7 @@
 		sun_top_ctrl: syscon@404000 {
 			compatible = "brcm,bcm7358-sun-top-ctrl", "syscon";
 			reg = <0x404000 0x51c>;
+			native-endian;
 		};
 
 		reboot {
arch/mips/boot/dts/brcm/bcm7360.dtsi +1 -0
index 0dcc9163c27b..bcdb09bfe07b 100644
@@ -112,6 +112,7 @@
 		sun_top_ctrl: syscon@404000 {
 			compatible = "brcm,bcm7360-sun-top-ctrl", "syscon";
 			reg = <0x404000 0x51c>;
+			native-endian;
 		};
 
 		reboot {
arch/mips/boot/dts/brcm/bcm7362.dtsi +1 -0
index 2f3f9fc2c478..d3b1b762e6c3 100644
@@ -118,6 +118,7 @@
 		sun_top_ctrl: syscon@404000 {
 			compatible = "brcm,bcm7362-sun-top-ctrl", "syscon";
 			reg = <0x404000 0x51c>;
+			native-endian;
 		};
 
 		reboot {
arch/mips/boot/dts/brcm/bcm7420.dtsi +1 -0
index bee221b3b568..3302a1b8a5c9 100644
@@ -99,6 +99,7 @@
 		sun_top_ctrl: syscon@404000 {
 			compatible = "brcm,bcm7420-sun-top-ctrl", "syscon";
 			reg = <0x404000 0x60c>;
+			native-endian;
 		};
 
 		reboot {
arch/mips/boot/dts/brcm/bcm7425.dtsi +1 -0
index 571f30f52e3f..15b27aae15a9 100644
@@ -100,6 +100,7 @@
 		sun_top_ctrl: syscon@404000 {
 			compatible = "brcm,bcm7425-sun-top-ctrl", "syscon";
 			reg = <0x404000 0x51c>;
+			native-endian;
 		};
 
 		reboot {
arch/mips/boot/dts/brcm/bcm7435.dtsi +1 -0
index 614ee211f71a..adb33e355043 100644
@@ -114,6 +114,7 @@
 		sun_top_ctrl: syscon@404000 {
 			compatible = "brcm,bcm7425-sun-top-ctrl", "syscon";
 			reg = <0x404000 0x51c>;
+			native-endian;
 		};
 
 		reboot {
Signature · 1 line
2.7.0.rc3
#2 lore raw

Re: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon

Quoted 26 lines · Mark Brown

On many MIPS systems the endianness of IP blocks is kept the same as that of the CPU by the hardware. This includes the system controllers on these systems which are controlled via syscon which uses the regmap API which used readl() and writel() to interact with the hardware, meaning that all writes are converted to little endian when writing to the hardware. This caused a bad interaction with the regmap core in big endian mode since it was not aware of the byte swapping and so ended up performing little endian writes.

Unfortunately when this issue was noticed it was addressed by updating the DT for the affected devices to specify them as little endian. This happened to work since it resulted in two endianness swaps which cancelled each other out and gave little endian behaviour but meant that the DT was clearly not accurately describing the hardware.

The intention of commit 29bb45f25ff305 (regmap-mmio: Use native endianness for read/write) was to fix this by making regmap default to native endianness but this breaks most other MMIO users where the hardware has a fixed endianness and the implementation uses the __raw accessors which are not intended to be used outside of architecture code. Instead use the newly added native-endian DT property to say exactly what we want for these systems.

Fixes 29bb45f25ff305 (regmap-mmio: Use native endianness for read/write)
Quoted 7 lines

---

Posted for review only, this will interact with some other patches fixing the implementation of regmap-mmio and will probably need to be merged along with them.

 arch/mips/boot/dts/brcm/bcm6328.dtsi | 1 +

v4.5-rc1 now contains an arch/mips/boot/dts/brcm/bcm6368.dtsi which copied the 6328.dtsi and therefore needs this hunk to be added to your patch series:

(quoted diff) +0 -0

b/arch/mips/boot/dts/brcm/bcm6368.dtsi
index 9c8d3fe28b31..1f6b9b5cddb4 100644

arch/mips/boot/dts/brcm/bcm6368.dtsi +1 -1
@@ -54,7 +54,7 @@
                periph_cntl: syscon@10000000 {
                        compatible = "syscon";
                        reg = <0x10000000 0x14>;
-                       little-endian;
+                       native-endian;
                };
 
                reboot: syscon-reboot@10000008 {
Signature · 1 line
Florian
Acked-by
#3 lore raw

Re: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon

Quoted 6 lines · Florian Fainelli
arch/mips/boot/dts/brcm/bcm6368.dtsi +0 -0
index 9c8d3fe28b31..1f6b9b5cddb4 100644

arch/mips/boot/dts/brcm/bcm6368.dtsi line 60

Quoted 8 lines
arch/mips/boot/dts/brcm/bcm6368.dtsi +1 -1
@@ -54,7 +54,7 @@
                periph_cntl: syscon@10000000 {
                        compatible = "syscon";
                        reg = <0x10000000 0x14>;
-                       little-endian;
+                       native-endian;
                };
 
                reboot: syscon-reboot@10000008 {

for the combined patch.

Ralf

#4 lore raw

Re: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon

In reply to Florian Fainelli

Hi,

Quoted 45 lines · Florian Fainelli
Quoted 26 lines · Mark Brown

On many MIPS systems the endianness of IP blocks is kept the same as that of the CPU by the hardware. This includes the system controllers on these systems which are controlled via syscon which uses the regmap API which used readl() and writel() to interact with the hardware, meaning that all writes are converted to little endian when writing to the hardware. This caused a bad interaction with the regmap core in big endian mode since it was not aware of the byte swapping and so ended up performing little endian writes.

Unfortunately when this issue was noticed it was addressed by updating the DT for the affected devices to specify them as little endian. This happened to work since it resulted in two endianness swaps which cancelled each other out and gave little endian behaviour but meant that the DT was clearly not accurately describing the hardware.

The intention of commit 29bb45f25ff305 (regmap-mmio: Use native endianness for read/write) was to fix this by making regmap default to native endianness but this breaks most other MMIO users where the hardware has a fixed endianness and the implementation uses the __raw accessors which are not intended to be used outside of architecture code. Instead use the newly added native-endian DT property to say exactly what we want for these systems.

Fixes 29bb45f25ff305 (regmap-mmio: Use native endianness for read/write)
Quoted 7 lines

---

Posted for review only, this will interact with some other patches fixing the implementation of regmap-mmio and will probably need to be merged along with them.

 arch/mips/boot/dts/brcm/bcm6328.dtsi | 1 +

v4.5-rc1 now contains an arch/mips/boot/dts/brcm/bcm6368.dtsi which copied the 6328.dtsi and therefore needs this hunk to be added to your patch series:

arch/mips/boot/dts/brcm/bcm6368.dtsi +0 -0
index 9c8d3fe28b31..1f6b9b5cddb4 100644

arch/mips/boot/dts/brcm/bcm6368.dtsi line 57

Quoted 5 lines
arch/mips/boot/dts/brcm/bcm6368.dtsi +1 -1
@@ -54,7 +54,7 @@
                periph_cntl: syscon@10000000 {
                        compatible = "syscon";
                        reg = <0x10000000 0x14>;
-                       little-endian;
+                       native-endian;

But native-endian == big-endian usually for bcm63xx, so is this actually a bugfix?

Jonas

#5 lore raw

Re: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon

Quoted 12 lines · Jonas Gorski

arch/mips/boot/dts/brcm/bcm6368.dtsi line 57

Quoted 7 lines

+++ b/arch/mips/boot/dts/brcm/bcm6368.dtsi

arch/mips/boot/dts/brcm/bcm6368.dtsi +1 -1
@@ -54,7 +54,7 @@
                 periph_cntl: syscon@10000000 {
                         compatible = "syscon";
                         reg = <0x10000000 0x14>;
-                       little-endian;
+                       native-endian;

But native-endian == big-endian usually for bcm63xx, so is this actually a bugfix?

It's complicated :)

These were originally specified as little-endian because it _worked_, but that was only because of an issue with the code - it was getting byteswapped twice.

This was "fixed" in commit 29bb45f25ff3051354ed330c0d0f10418a2b8c7c, and I assume this DT file was created/copied before that commit and didn't get that update due to merge delays. So after that commit, this file couldn't have worked, but that's how it got to this point.

johannes

author maintainer
#6 lore raw

Re: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon

In reply to Jonas Gorski
Quoted 5 lines · Jonas Gorski

arch/mips/boot/dts/brcm/bcm6368.dtsi line 57

Quoted 2 lines
arch/mips/boot/dts/brcm/bcm6368.dtsi +1 -1
-                       little-endian;
+                       native-endian;

But native-endian == big-endian usually for bcm63xx, so is this actually a bugfix?

Yes, it's buggy - in v4.5-rc1 we respect the endianness so big endian just won't work, prior to that this was a hack around another bug which was done rather than reporting it so it "just" results in a DT that's obviously incorrect. This local hack has been causing a lot of problems.

author maintainer
#7 lore raw

Re: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon

In reply to Florian Fainelli
Quoted 3 lines · Florian Fainelli

v4.5-rc1 now contains an arch/mips/boot/dts/brcm/bcm6368.dtsi which copied the 6328.dtsi and therefore needs this hunk to be added to your patch series:

Folded that in, thanks.

#8 lore raw
In reply to Mark Brown

Review

Quoted 10 lines · On Tuesday 26 January 2016 22:46:49 Mark Brown wrote:
(quoted diff) +6 -4
-Required properties:
-- {big,little}-endian: these are boolean properties, if absent
-  meaning that the CPU and the Device are in the same endianness mode,
-  these properties are for register values and all the buffers only.
+Optional properties:
+- {big,little,native}-endian: these are boolean properties, if absent
+  then the implementation will choose a default based on the device
+  being controlled.  These properties are for register values and all
+  the buffers only.  Native endian means that the CPU and device have
+  the same endianness.

I think the rest of the file also needs to be changed, and we need some more explanation about native-endian, which people might think is the right one for them when it rarely is in reality (Broadcom MIPS being one notable exception).

How about this version below?

Arnd

Documentation/devicetree/bindings/regmap/regmap.txt +29 -47
dissimilarity index 91%
index b494f8b8ef72..0127be360fe8 100644
@@ -1,47 +1,29 @@
-Device-Tree binding for regmap
-
-The endianness mode of CPU & Device scenarios:
-Index     Device     Endianness properties
----------------------------------------------------
-1         BE         'big-endian'
-2         LE         'little-endian'
-
-For one device driver, which will run in different scenarios above
-on different SoCs using the devicetree, we need one way to simplify
-this.
-
-Required properties:
-- {big,little}-endian: these are boolean properties, if absent
-  meaning that the CPU and the Device are in the same endianness mode,
-  these properties are for register values and all the buffers only.
-
-Examples:
-Scenario 1 : CPU in LE mode & device in LE mode.
-dev: dev@40031000 {
-	      compatible = "name";
-	      reg = <0x40031000 0x1000>;
-	      ...
-};
-
-Scenario 2 : CPU in LE mode & device in BE mode.
-dev: dev@40031000 {
-	      compatible = "name";
-	      reg = <0x40031000 0x1000>;
-	      ...
-	      big-endian;
-};
-
-Scenario 3 : CPU in BE mode & device in BE mode.
-dev: dev@40031000 {
-	      compatible = "name";
-	      reg = <0x40031000 0x1000>;
-	      ...
-};
-
-Scenario 4 : CPU in BE mode & device in LE mode.
-dev: dev@40031000 {
-	      compatible = "name";
-	      reg = <0x40031000 0x1000>;
-	      ...
-	      little-endian;
-};
+Devicetree binding for regmap
+
+Optional properties:
+
+   little-endian,
+   big-endian,
+   native-endian:	See common-properties.txt for a definition
+
+Note:
+Regmap defaults to little-endian register access on MMIO based
+devices, this is by far the most common setting. On CPU
+architectures that typically run big-endian operating systems
+(e.g. PowerPC), registers can be defined as big-endian and must
+be marked that way in the devicetree.
+
+On SoCs that can be operated in both big-endian and little-endian
+modes, with a single hardware switch controlling both the endianess
+of the CPU and a byteswap for MMIO registers (e.g. many Broadcom MIPS
+chips), "native-endian" is used to allow using the same device tree
+blob in both cases.
+
+Examples:
+Scenario 1 : a register set in big-endian mode.
+dev: dev@40031000 {
+	      compatible = "syscon";
+	      reg = <0x40031000 0x1000>;
+	      big-endian;
+	      ...
+};
author maintainer
#9 lore raw
Quoted 4 lines · Arnd Bergmann

I think the rest of the file also needs to be changed, and we need some more explanation about native-endian, which people might think is the right one for them when it rarely is in reality (Broadcom MIPS being one notable exception).

I'm not sure it's *that* confusing at this point but this is definitely a lot clearer.