From: Ondrej Jirman <redacted>
This series implements ethernet support for Xunlong Orange Pi 3 board, by:
- making small cleanups of existing dwmac-sun8i code
- adding DT bindings docummentation
- adding support for phy-io-supply to dwmac-sun8i code
- adding DT configuration for Orange Pi 3 board
For some people, ethernet doesn't work after reboot because u-boot doesn't
support AXP805 PMIC, and will not turn off the etherent PHY regulators.
So the regulator controlled by gpio will be shut down, but the other one
controlled by the AXP PMIC will not.
This is a problem only when running with a builtin driver. This needs
to be fixed in u-boot and should not prevent these patches from being
merged.
This evolved out of the Orange Pi 3 patches series, as I didn't want
to stretch that out any longer.
Please take a look.
thank you and regards,
Ondrej Jirman
Ondrej Jirman (6):
dt-bindings: net: sun8i-a83t-emac: Add phy-supply property
dt-bindings: net: sun8i-a83t-emac: Add phy-io-supply property
net: stmmac: sun8i: Use devm_regulator_get for PHY regulator
net: stmmac: sun8i: Rename PHY regulator variable to regulator_phy
net: stmmac: sun8i: Add support for enabling a regulator for PHY I/O
pins
arm64: dts: allwinner: orange-pi-3: Enable ethernet
.../net/allwinner,sun8i-a83t-emac.yaml | 8 ++
.../dts/allwinner/sun50i-h6-orangepi-3.dts | 40 ++++++++++
.../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 74 ++++++++++++-------
3 files changed, 96 insertions(+), 26 deletions(-)
--
2.22.1
From: Ondrej Jirman <redacted>
Use devm_regulator_get instead of devm_regulator_get_optional and rely
on dummy supply. This avoids NULL checks before regulator_enable/disable
calls.
This path also improves error reporting, because we now report both
use of dummy supply and error during registration with more detail,
instead of generic info level message "No regulator found" that
was reported previously on errors and lack of regulator property in DT.
Finally, we'll be adding further optional regulators, and the overall
code will be simpler.
Signed-off-by: Ondrej Jirman <redacted>
---
.../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 23 ++++++++-----------
1 file changed, 10 insertions(+), 13 deletions(-)
@@ -1129,12 +1126,12 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)}/* Optional regulator for PHY */-gmac->regulator=devm_regulator_get_optional(dev,"phy");+gmac->regulator=devm_regulator_get(dev,"phy");if(IS_ERR(gmac->regulator)){-if(PTR_ERR(gmac->regulator)==-EPROBE_DEFER)-return-EPROBE_DEFER;-dev_info(dev,"No regulator found\n");-gmac->regulator=NULL;+ret=PTR_ERR(gmac->regulator);+if(ret!=-EPROBE_DEFER)+dev_err(dev,"Failed to get PHY regulator (%d)\n",ret);+returnret;}/* The "GMAC clock control" register might be located in the
From: Ondrej Jirman <redacted>
Orange Pi 3 has two regulators that power the Realtek RTL8211E
PHY. According to the datasheet, both regulators need to be enabled
at the same time, or that "phy-io" should be enabled slightly earlier
than "phy" regulator.
RTL8211E/RTL8211EG datasheet says:
Note 4: 2.5V (or 1.8/1.5V) RGMII power should be risen simultaneously
or slightly earlier than 3.3V power. Rising 2.5V (or 1.8/1.5V) power
later than 3.3V power may lead to errors.
The driver ensures the regulator enable ordering. The timing is set
in DT via startup-delay-us.
We also need to wait at least 30ms after power-up/reset, before
accessing the PHY registers.
All values of RX/TX delay were tested exhaustively and a middle one
of the range of working values was chosen.
Signed-off-by: Ondrej Jirman <redacted>
---
.../dts/allwinner/sun50i-h6-orangepi-3.dts | 40 +++++++++++++++++++
1 file changed, 40 insertions(+)
@@ -136,6 +175,7 @@regulator-min-microvolt=<3300000>;regulator-max-microvolt=<3300000>;regulator-name="vcc33-audio-tv-ephy-mac";+regulator-enable-ramp-delay=<100000>;};/* ALDO3 is shorted to CLDO1 */
From: Ondrej Jirman <redacted>
Some PHYs require separate power supply for I/O pins in some modes
of operation. Add phy-io-supply property, to allow enabling this
power supply.
Signed-off-by: Ondrej Jirman <redacted>
---
.../devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml | 4 ++++
1 file changed, 4 insertions(+)
From: Ondrej Jirman <redacted>
Orange Pi 3 has two regulators that power the Realtek RTL8211E. According
to the phy datasheet, both regulators need to be enabled at the same time.
Add support for the second optional regulator, "phy-io", to the glue
driver.
Signed-off-by: Ondrej Jirman <redacted>
---
.../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 31 ++++++++++++++++---
1 file changed, 27 insertions(+), 4 deletions(-)
@@ -1136,6 +1149,16 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)returnret;}+/* Optional regulator for PHY I/O pins */+gmac->regulator_phy_io=devm_regulator_get(dev,"phy-io");+if(IS_ERR(gmac->regulator_phy_io)){+ret=PTR_ERR(gmac->regulator_phy_io);+if(ret!=-EPROBE_DEFER)+dev_err(dev,"Failed to get PHY I/O regulator (%d)\n",+ret);+returnret;+}+/* The "GMAC clock control" register might be located in the*CCUaddressrange(ontheR40),orthesystemcontroladdress*range(onmostothersun8iandlaterSoCs).
From: Ondrej Jirman <redacted>
We'll be adding further optional regulators, and this makes it clearer
what the regulator is for.
Signed-off-by: Ondrej Jirman <redacted>
---
.../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 32 ++++++++++---------
1 file changed, 17 insertions(+), 15 deletions(-)
@@ -1126,9 +1128,9 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)}/* Optional regulator for PHY */-gmac->regulator=devm_regulator_get(dev,"phy");-if(IS_ERR(gmac->regulator)){-ret=PTR_ERR(gmac->regulator);+gmac->regulator_phy=devm_regulator_get(dev,"phy");+if(IS_ERR(gmac->regulator_phy)){+ret=PTR_ERR(gmac->regulator_phy);if(ret!=-EPROBE_DEFER)dev_err(dev,"Failed to get PHY regulator (%d)\n",ret);returnret;
From: Ondrej Jirman <redacted>
This is already supported by the driver, but is missing from the
bindings.
Signed-off-by: Ondrej Jirman <redacted>
---
.../devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml | 4 ++++
1 file changed, 4 insertions(+)
@@ -43,6 +43,10 @@ properties:Phandle to the device containing the EMAC or GMAC clockregister+phy-supply:+description:+PHY regulator+required:-compatible-reg
From: Andrew Lunn <andrew@lunn.ch> Date: 2019-08-20 15:39:55
On Tue, Aug 20, 2019 at 04:53:40PM +0200, megous@megous.com wrote:
From: Ondrej Jirman <redacted>
Use devm_regulator_get instead of devm_regulator_get_optional and rely
on dummy supply. This avoids NULL checks before regulator_enable/disable
calls.
Hi Ondrej
What do you mean by a dummy supply? I'm just trying to make sure you
are not breaking backwards compatibility.
Thanks
Andrew
Hi Andrew,
On Tue, Aug 20, 2019 at 05:39:39PM +0200, Andrew Lunn wrote:
On Tue, Aug 20, 2019 at 04:53:40PM +0200, megous@megous.com wrote:
quoted
From: Ondrej Jirman <redacted>
Use devm_regulator_get instead of devm_regulator_get_optional and rely
on dummy supply. This avoids NULL checks before regulator_enable/disable
calls.
Hi Ondrej
What do you mean by a dummy supply? I'm just trying to make sure you
are not breaking backwards compatibility.
Sorry, I mean dummy regulator. See:
https://elixir.bootlin.com/linux/latest/source/drivers/regulator/core.c#L1874
On systems that use DT (i.e. have_full_constraints() == true), when the
regulator is not found (ENODEV, not specified in DT), regulator_get will return
a fake dummy regulator that can be enabled/disabled, but doesn't do anything
real.
This can be used to avoid NULL checks and make the code simpler.
regards,
Ondrej
On Tue, Aug 20, 2019 at 05:39:39PM +0200, Andrew Lunn wrote:
On Tue, Aug 20, 2019 at 04:53:40PM +0200, megous@megous.com wrote:
quoted
From: Ondrej Jirman <redacted>
Use devm_regulator_get instead of devm_regulator_get_optional and rely
on dummy supply. This avoids NULL checks before regulator_enable/disable
calls.
Hi Ondrej
What do you mean by a dummy supply? I'm just trying to make sure you
are not breaking backwards compatibility.
I have tested it on Orange Pi PC 2, that uses only phy-supply, but not
phy-io-supply, and the kernel now prints:
[ 1.410137] dwmac-sun8i 1c30000.ethernet: 1c30000.ethernet supply phy-io not found, using dummy regulator
I have also tested it on Orange Pi PC, that doesn't use external phy, and
instead of:
[ 1.081378] dwmac-sun8i 1c30000.ethernet: No regulator found
The kernel now prints:
[ 1.112752] dwmac-sun8i 1c30000.ethernet: 1c30000.ethernet supply phy not found, using dummy regulator
[ 1.112814] dwmac-sun8i 1c30000.ethernet: 1c30000.ethernet supply phy-io not found, using dummy regulator
Ethernet works in both cases, so that should cover all existing combinations. :)
regards,
Ondrej
From: Andrew Lunn <andrew@lunn.ch> Date: 2019-08-20 15:57:56
On Tue, Aug 20, 2019 at 05:47:14PM +0200, Ondřej Jirman wrote:
Hi Andrew,
On Tue, Aug 20, 2019 at 05:39:39PM +0200, Andrew Lunn wrote:
quoted
On Tue, Aug 20, 2019 at 04:53:40PM +0200, megous@megous.com wrote:
quoted
From: Ondrej Jirman <redacted>
Use devm_regulator_get instead of devm_regulator_get_optional and rely
on dummy supply. This avoids NULL checks before regulator_enable/disable
calls.
Hi Ondrej
What do you mean by a dummy supply? I'm just trying to make sure you
are not breaking backwards compatibility.
Sorry, I mean dummy regulator. See:
https://elixir.bootlin.com/linux/latest/source/drivers/regulator/core.c#L1874
On systems that use DT (i.e. have_full_constraints() == true), when the
regulator is not found (ENODEV, not specified in DT), regulator_get will return
a fake dummy regulator that can be enabled/disabled, but doesn't do anything
real.
Hi Ondrej
But we also gain a new warning:
dev_warn(dev,
"%s supply %s not found, using dummy regulator\n",
devname, id);
This regulator is clearly optional, so there should not be a warning.
Maybe you can add a new get_type, OPTIONAL_GET, which does not issue
the warning, but does give back a dummy regulator.
Thanks
Andrew
Hi,
On Tue, Aug 20, 2019 at 05:57:44PM +0200, Andrew Lunn wrote:
On Tue, Aug 20, 2019 at 05:47:14PM +0200, Ondřej Jirman wrote:
quoted
Hi Andrew,
On Tue, Aug 20, 2019 at 05:39:39PM +0200, Andrew Lunn wrote:
quoted
On Tue, Aug 20, 2019 at 04:53:40PM +0200, megous@megous.com wrote:
quoted
From: Ondrej Jirman <redacted>
Use devm_regulator_get instead of devm_regulator_get_optional and rely
on dummy supply. This avoids NULL checks before regulator_enable/disable
calls.
Hi Ondrej
What do you mean by a dummy supply? I'm just trying to make sure you
are not breaking backwards compatibility.
Sorry, I mean dummy regulator. See:
https://elixir.bootlin.com/linux/latest/source/drivers/regulator/core.c#L1874
On systems that use DT (i.e. have_full_constraints() == true), when the
regulator is not found (ENODEV, not specified in DT), regulator_get will return
a fake dummy regulator that can be enabled/disabled, but doesn't do anything
real.
Hi Ondrej
But we also gain a new warning:
dev_warn(dev,
"%s supply %s not found, using dummy regulator\n",
devname, id);
This regulator is clearly optional, so there should not be a warning.
Maybe you can add a new get_type, OPTIONAL_GET, which does not issue
the warning, but does give back a dummy regulator.
We already had a info message. See my other e-mail with the dmesg output.
IMO, that warning is useful during development, and more informative than the
previous one.
regards,
o.
From: Rob Herring <robh+dt@kernel.org> Date: 2019-08-20 16:20:39
On Tue, Aug 20, 2019 at 9:53 AM [off-list ref] wrote:
From: Ondrej Jirman <redacted>
Some PHYs require separate power supply for I/O pins in some modes
of operation. Add phy-io-supply property, to allow enabling this
power supply.
Perhaps since this is new, such phys should have *-supply in their nodes.
On Tue, Aug 20, 2019 at 11:20:22AM -0500, Rob Herring wrote:
On Tue, Aug 20, 2019 at 9:53 AM [off-list ref] wrote:
quoted
From: Ondrej Jirman <redacted>
Some PHYs require separate power supply for I/O pins in some modes
of operation. Add phy-io-supply property, to allow enabling this
power supply.
Perhaps since this is new, such phys should have *-supply in their nodes.
Yes, I just don't understand, since external ethernet phys are so common,
and they require power, how there's no fairly generic mechanism for this
already in the PHY subsystem, or somewhere?
It looks like other ethernet mac drivers also implement supplies on phys
on the EMAC nodes. Just grep phy-supply through dt-bindings/net.
Historical reasons, or am I missing something? It almost seems like I must
be missing something, since putting these properties to phy nodes
seems so obvious.
thank you and regards,
Ondrej
From: Rob Herring <robh+dt@kernel.org> Date: 2019-08-20 16:57:20
On Tue, Aug 20, 2019 at 11:34 AM Ondřej Jirman [off-list ref] wrote:
On Tue, Aug 20, 2019 at 11:20:22AM -0500, Rob Herring wrote:
quoted
On Tue, Aug 20, 2019 at 9:53 AM [off-list ref] wrote:
quoted
From: Ondrej Jirman <redacted>
Some PHYs require separate power supply for I/O pins in some modes
of operation. Add phy-io-supply property, to allow enabling this
power supply.
Perhaps since this is new, such phys should have *-supply in their nodes.
Yes, I just don't understand, since external ethernet phys are so common,
and they require power, how there's no fairly generic mechanism for this
already in the PHY subsystem, or somewhere?
Because generic mechanisms for this don't work. For example, what
happens when the 2 supplies need to be turned on in a certain order
and with certain timings? And then add in reset or control lines into
the mix... You can see in the bindings we already have some of that.
It looks like other ethernet mac drivers also implement supplies on phys
on the EMAC nodes. Just grep phy-supply through dt-bindings/net.
Historical reasons, or am I missing something? It almost seems like I must
be missing something, since putting these properties to phy nodes
seems so obvious.
Things get added one by one and one new property isn't that
controversial. We've generally learned the lesson and avoid this
pattern now, but ethernet phys are one of the older bindings.
Rob
From: David Miller <davem@davemloft.net> Date: 2019-08-20 20:56:22
It looks like there will be some updates to this series either involving
adding -supply to the property names or adjusting some of the kernel log
messages.
Seriously, I would prefer less verbiage in the logs rather than more.
On Tue, Aug 20, 2019 at 11:57:06AM -0500, Rob Herring wrote:
On Tue, Aug 20, 2019 at 11:34 AM Ondřej Jirman [off-list ref] wrote:
quoted
On Tue, Aug 20, 2019 at 11:20:22AM -0500, Rob Herring wrote:
quoted
On Tue, Aug 20, 2019 at 9:53 AM [off-list ref] wrote:
quoted
From: Ondrej Jirman <redacted>
Some PHYs require separate power supply for I/O pins in some modes
of operation. Add phy-io-supply property, to allow enabling this
power supply.
Perhaps since this is new, such phys should have *-supply in their nodes.
Yes, I just don't understand, since external ethernet phys are so common,
and they require power, how there's no fairly generic mechanism for this
already in the PHY subsystem, or somewhere?
Because generic mechanisms for this don't work. For example, what
happens when the 2 supplies need to be turned on in a certain order
and with certain timings? And then add in reset or control lines into
the mix... You can see in the bindings we already have some of that.
I've looked at the emac bindings that have phy-supply, and don't see reason
why this can't be generic for the phy. Just like there's generic reset
properties for phys, now. Some bindings, like fsl-fec.txt even list
custom reset properties for phy as deprecated, and recommend using
generic ones.
From the point of the view of the emac driver, it just wants to power on/power
off the phy, and wait until it's ready to be communicated with.
It's probably better to have power supplies of the phy covered by generic
phy code, because then you don't have to duplicate all this special power
up logic in every emac driver, whenever a HW designer decides to combine
such emac with external phy that requires some special hadnling on powerup.
At the moment, this lack of flexibility is hacked around by adding multiple
regulators to the DTS, and making them dependent on each other (even if one
doesn't supply the other), just because this makes the regulator core driver
enable them all. Power up delays for the PHY are described as enable-ramp-delays
on the regulators (actual regulator ramp delay + wait time for PHY to initialize).
Basically just hacking the DT so that the Linux kernel in the end does what's
necessary, instead of DT describing the actual HW.
Adding a single supply property to the phy node, as you suggest will do nothing
to help this situation. It will just result in a more complicated dwmac-sun8i
driver and will not help anyone in the future.
So I think, maybe phy powerup should be moved to generic code, just like the
phy reset code was. Generic code can have multiple supplies and some generic
way to specify power up order and timings.
But I guess, this patch series is a dead end.
quoted
It looks like other ethernet mac drivers also implement supplies on phys
on the EMAC nodes. Just grep phy-supply through dt-bindings/net.
Historical reasons, or am I missing something? It almost seems like I must
be missing something, since putting these properties to phy nodes
seems so obvious.
Things get added one by one and one new property isn't that
controversial. We've generally learned the lesson and avoid this
pattern now, but ethernet phys are one of the older bindings.
Understood. So maybe the solution suggested above would improve the situation
eventually?
regards,
o.