regmap: Add explict native endian flag to DT bindings
Subsystems (5)
Mark Brown
maintainerPATCH 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
@@ -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
@@ -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
Mark Brown
maintainerRFC 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.
---
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
@@ -73,6 +73,7 @@ timer: timer@10000040 { compatible = "syscon"; reg = <0x10000040 0x2c>; + native-endian; }; reboot {
arch/mips/boot/dts/brcm/bcm7125.dtsi +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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()andwritel()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__rawaccessors 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)Reported-by Johannes Berg <[email protected]>Signed-off-by Mark Brown <[email protected]>
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
Ralf Baechle
Acked-byRe: [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
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
Re: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon
In reply to Florian FainelliHi,
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()andwritel()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__rawaccessors 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)Reported-by Johannes Berg <[email protected]>Signed-off-by Mark Brown <[email protected]>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.dtsiwhich 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
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
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.dtsiarch/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
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
@@ -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; + ... +};
Mark Brown
maintainerRe: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon
In reply to Jonas GorskiQuoted 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.
Mark Brown
maintainerQuoted 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.
Mark Brown
maintainerRe: [PATCH RFC 2/2] MIPS: dt: Explicitly specify native endian behaviour for syscon
In reply to Florian FainelliQuoted 3 lines · Florian Fainelli
v4.5-rc1 now contains an
arch/mips/boot/dts/brcm/bcm6368.dtsiwhich copied the 6328.dtsi and therefore needs this hunk to be added to your patch series:
Folded that in, thanks.