net: stmmac: dwmac-rk: add RK3576 GMAC 25M refout support
Subsystems (6)
cover net: stmmac: dwmac-rk: add RK3576 GMAC 25M refout support
Hi,
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY. Boards already describe the MAC clock direction with clock_in_out = "output", but the dwmac-rk driver does not currently request or enable the corresponding 25 MHz reference output clock.
On RK3576, this means the REFCLKO25M_GMACx_OUT clock may be disabled by the common clock framework as unused, even though the board expects the GMAC block to provide the PHY reference clock.
This series adds an optional "clk_mac_25m_refout" clock name to the Rockchip DWMAC binding, wires it up for RK3576 GMAC0/GMAC1, and enables it from the dwmac-rk driver when the MAC is configured for RGMII output clock mode.
The clock remains optional, so existing device trees and SoCs are not affected.
Tested on a PicoCOM RK3576 ACP board with a Motorcomm YT8521 PHY. The GMAC 25 MHz reference clock output remains active and Ethernet works.
Gavin Gao (3):
dt-bindings: net: rockchip-dwmac: Add 25M refout clock
arm64: dts: rockchip: Add RK3576 GMAC 25M refout clocks
net: stmmac: dwmac-rk: Enable RGMII 25M refout clock
.../bindings/net/rockchip-dwmac.yaml | 1 + arch/arm64/boot/dts/rockchip/rk3576.dtsi | 8 ++--- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 33 ++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/3 dt-bindings: net: rockchip-dwmac: Add 25M refout clock
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY.
Add a clock name for this 25 MHz reference output so SoC dtsi files can describe it separately from the existing MAC reference clocks.
--- Documentation/devicetree/bindings/net/rockchip-dwmac.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +1 -0
@@ -81,6 +81,7 @@ properties: - pclk_mac - clk_mac_ref - clk_mac_refout + - clk_mac_25m_refout - clk_mac_speed clock_in_out:
Signature · 1 line
2.55.0
Re: [PATCH net-next 1/3] dt-bindings: net: rockchip-dwmac: Add 25M refout clock
Quoted 16 lines · Gavin Gao
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY.
Add a clock name for this 25 MHz reference output so SoC dtsi files can describe it separately from the existing MAC reference clocks.
Signed-off-by Gavin Gao <[email protected]>--- Documentation/devicetree/bindings/net/rockchip-dwmac.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +0
-0
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml properties: · line 84
Quoted 4 lines
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +1
-0@@ -81,6 +81,7 @@ properties: - pclk_mac - clk_mac_ref - clk_mac_refout + - clk_mac_25m_refout
That's the same as clk_mac_ref and clk_mac_refout. clocks are not outputs but inputs, so explain how does the device take three SAME
clocks: clk_mac_ref, clk_mac_refout and clk_mac_25m_refout?
Best regards,
Krzysztof
Re: [PATCH net-next 1/3] dt-bindings: net: rockchip-dwmac: Add 25M refout clock
Quoted 27 lines · Krzysztof Kozlowski
Quoted 16 lines · Gavin Gao
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY.
Add a clock name for this 25 MHz reference output so SoC dtsi files can describe it separately from the existing MAC reference clocks.
Signed-off-by Gavin Gao <[email protected]>--- Documentation/devicetree/bindings/net/rockchip-dwmac.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +0
-0Documentation/devicetree/bindings/net/rockchip-dwmac.yaml properties: · line 84
Quoted 4 lines
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +1
-0@@ -81,6 +81,7 @@ properties: - pclk_mac - clk_mac_ref - clk_mac_refout + - clk_mac_25m_refoutThat's the same as
clk_mac_refandclk_mac_refout. clocks are not outputs but inputs, so explain how does the device take three SAME
clocks:clk_mac_ref,clk_mac_refoutandclk_mac_25m_refout?
Quoted 3 lines
Best regards,
Krzysztof
This is not the existing clk_mac_refout clock. On RK3576 the REFCLKO25M_GMAC[01]_OUT clocks are separate 25 MHz reference clock outputs intended for RGMII PHYs, while clk_mac_refout is the existing refout clock used by the Rockchip DWMAC binding for the RMII reference output path.
Signature · 2 lines
Best Regards, Gavin Gao
Re: [PATCH net-next 1/3] dt-bindings: net: rockchip-dwmac: Add 25M refout clock
Quoted 28 lines · Gavin Gao
Quoted 27 lines · Krzysztof Kozlowski
Quoted 16 lines · Gavin Gao
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY.
Add a clock name for this 25 MHz reference output so SoC dtsi files can describe it separately from the existing MAC reference clocks.
Signed-off-by Gavin Gao <[email protected]>--- Documentation/devicetree/bindings/net/rockchip-dwmac.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +0
-0Documentation/devicetree/bindings/net/rockchip-dwmac.yaml properties: · line 84
Quoted 4 lines
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +1
-0@@ -81,6 +81,7 @@ properties: - pclk_mac - clk_mac_ref - clk_mac_refout + - clk_mac_25m_refoutThat's the same as
clk_mac_refandclk_mac_refout. clocks are not outputs but inputs, so explain how does the device take three SAME
clocks:clk_mac_ref,clk_mac_refoutandclk_mac_25m_refout?
Quoted 6 lines
Quoted 3 lines
Best regards,
KrzysztofThis is not the existing
clk_mac_refoutclock. On RK3576 the REFCLKO25M_GMAC[01]_OUT clocks are separate 25 MHz reference clock outputs
That's why I emphasized here and in other patch we do not talk about outputs. Read the comments.
Quoted 2 lines
intended for RGMII PHYs, while
clk_mac_refoutis the existing refout clock used by the Rockchip DWMAC binding for the RMII reference output path.
Best regards,
Krzysztof
PATCH 2/3 arm64: dts: rockchip: Add RK3576 GMAC 25M refout clocks
In reply to Gavin GaoRK3576 provides REFCLKO25M_GMAC0_OUT and REFCLKO25M_GMAC1_OUT clocks for the two GMAC instances.
Describe these clocks with the clk_mac_25m_refout clock name so boards using RGMII output clock mode can let the MAC driver manage the 25 MHz reference output.
--- arch/arm64/boot/dts/rockchip/rk3576.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/rockchip/rk3576.dtsi +4 -4
@@ -1692,10 +1692,10 @@ gmac0: ethernet@2a220000 { reg = <0x0 0x2a220000 0x0 0x10000>; clocks = <&cru CLK_GMAC0_125M_SRC>, <&cru CLK_GMAC0_RMII_CRU>, <&cru PCLK_GMAC0>, <&cru ACLK_GMAC0>, - <&cru CLK_GMAC0_PTP_REF>; + <&cru CLK_GMAC0_PTP_REF>, <&cru REFCLKO25M_GMAC0_OUT>; clock-names = "stmmaceth", "clk_mac_ref", "pclk_mac", "aclk_mac", - "ptp_ref"; + "ptp_ref", "clk_mac_25m_refout"; interrupts = <GIC_SPI 293 IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI 298 IRQ_TYPE_LEVEL_HIGH>; interrupt-names = "macirq", "eth_wake_irq";
@@ -1739,10 +1739,10 @@ gmac1: ethernet@2a230000 { reg = <0x0 0x2a230000 0x0 0x10000>; clocks = <&cru CLK_GMAC1_125M_SRC>, <&cru CLK_GMAC1_RMII_CRU>, <&cru PCLK_GMAC1>, <&cru ACLK_GMAC1>, - <&cru CLK_GMAC1_PTP_REF>; + <&cru CLK_GMAC1_PTP_REF>, <&cru REFCLKO25M_GMAC1_OUT>; clock-names = "stmmaceth", "clk_mac_ref", "pclk_mac", "aclk_mac", - "ptp_ref"; + "ptp_ref", "clk_mac_25m_refout"; interrupts = <GIC_SPI 301 IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI 306 IRQ_TYPE_LEVEL_HIGH>; interrupt-names = "macirq", "eth_wake_irq";
Signature · 1 line
2.55.0
Re: [PATCH net-next 2/3] arm64: dts: rockchip: Add RK3576 GMAC 25M refout clocks
Quoted 17 lines · Gavin Gao
RK3576 provides
REFCLKO25M_GMAC0_OUTandREFCLKO25M_GMAC1_OUTclocks for the two GMAC instances.Describe these clocks with the
clk_mac_25m_refoutclock name so boards using RGMII output clock mode can let the MAC driver manage the 25 MHz reference output.Signed-off-by Gavin Gao <[email protected]>--- arch/arm64/boot/dts/rockchip/rk3576.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/arm64/boot/dts/rockchip/rk3576.dtsi +0
-0
arch/arm64/boot/dts/rockchip/rk3576.dtsi gmac0: ethernet@2a220000 { · line 1698
Quoted 9 lines
arch/arm64/boot/dts/rockchip/rk3576.dtsi +2
-2@@ -1692,10 +1692,10 @@ gmac0: ethernet@2a220000 { reg = <0x0 0x2a220000 0x0 0x10000>; clocks = <&cru CLK_GMAC0_125M_SRC>, <&cru CLK_GMAC0_RMII_CRU>, <&cru PCLK_GMAC0>, <&cru ACLK_GMAC0>, - <&cru CLK_GMAC0_PTP_REF>; + <&cru CLK_GMAC0_PTP_REF>, <&cru REFCLKO25M_GMAC0_OUT>; clock-names = "stmmaceth", "clk_mac_ref", "pclk_mac", "aclk_mac", - "ptp_ref"; + "ptp_ref", "clk_mac_25m_refout";
Where is clk_mac_refout? Why do you claim this is a different input (important: INPUT)?
Best regards,
Krzysztof
PATCH 3/3 net: stmmac: dwmac-rk: Enable RGMII 25M refout clock
In reply to Gavin GaoBoards can set clock_in_out = "output" to request a MAC-provided clock, but dwmac-rk currently does not enable the optional 25 MHz RGMII reference output clock. The common clock framework may therefore disable the clock as unused.
Request the optional clk_mac_25m_refout clock in RGMII output mode, set it to 25 MHz, and keep it enabled while the MAC clocks are enabled.
--- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +32 -1
@@ -81,6 +81,7 @@ struct rk_priv_data {struct clk_bulk_data *clks;int num_clks;struct clk *clk_phy; +struct clk *clk_mac_25m_refout;struct reset_control *phy_reset;
@@ -1419,6 +1420,24 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat)clk_set_rate (bsp_priv->clk_phy,50000000 ); } +if (!bsp_priv->clock_input &&phy_interface_mode_is_rgmii (phy_iface)) { + bsp_priv->clk_mac_25m_refout = +devm_clk_get_optional (dev,"clk_mac_25m_refout" ); +if (IS_ERR (bsp_priv->clk_mac_25m_refout)) { + ret =PTR_ERR (bsp_priv->clk_mac_25m_refout); +return dev_err_probe (dev, ret, +"Cannot get 25M refout clock\n" ); + } + +if (bsp_priv->clk_mac_25m_refout) { + ret =clk_set_rate (bsp_priv->clk_mac_25m_refout, +25000000 ); +if (ret) +return dev_err_probe (dev, ret, +"Cannot set 25M refout clock rate\n" ); + } + } +return 0 ; }
@@ -1433,9 +1452,13 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)if (ret)return ret; + ret =clk_prepare_enable (bsp_priv->clk_mac_25m_refout); +if (ret) + goto err_disable_clks; + ret =clk_prepare_enable (bsp_priv->clk_phy);if (ret) -return ret; + goto err_disable_25m_refout;if (bsp_priv->ops && bsp_priv->ops->set_clock_selection) bsp_priv->ops->set_clock_selection(bsp_priv,
@@ -1454,12 +1477,20 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)clk_bulk_disable_unprepare (bsp_priv->num_clks, bsp_priv->clks);clk_disable_unprepare (bsp_priv->clk_phy); +clk_disable_unprepare (bsp_priv->clk_mac_25m_refout); bsp_priv->clk_enabled = false; } }return 0 ; + +err_disable_25m_refout: +clk_disable_unprepare (bsp_priv->clk_mac_25m_refout); +err_disable_clks: +clk_bulk_disable_unprepare (bsp_priv->num_clks, bsp_priv->clks); + +return ret; }static int phy_power_on (struct rk_priv_data *bsp_priv,bool enable)
Signature · 1 line
2.55.0
Maxime Chevallier
maintainerHi,
Quoted 16 lines · Gavin Gao
Hi,
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY. Boards already describe the MAC clock direction with
clock_in_out= "output", but the dwmac-rk driver does not currently request or enable the corresponding 25 MHz reference output clock.On RK3576, this means the
REFCLKO25M_GMACx_OUTclock may be disabled by the common clock framework as unused, even though the board expects the GMAC block to provide the PHY reference clock.This series adds an optional "
clk_mac_25m_refout" clock name to the Rockchip DWMAC binding, wires it up for RK3576 GMAC0/GMAC1, and enables it from the dwmac-rk driver when the MAC is configured for RGMII output clock mode.
Quoted 5 lines
The clock remains optional, so existing device trees and SoCs are not affected.
Tested on a PicoCOM RK3576 ACP board with a Motorcomm YT8521 PHY. The GMAC 25 MHz reference clock output remains active and Ethernet works.
I have a feeling this is using the common clock framework backwards. The MAC in this case is a clock provider yet it uses the consumer API.
Shouldn't the MAC instead register a new clock, as a provider, for the ref out ? The PHY device would then need to get/prepare/enable that clock.
I know we don't have a lot of clock providers in drivers/net/ethernet, but I think we should have more...
Maxime
Hi Maxime,
Quoted 23 lines · Maxime Chevallier
Hi,
Quoted 19 lines · Gavin Gao
Hi,
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY. Boards already describe the MAC clock direction with
clock_in_out= "output", but the dwmac-rk driver does not currently request or enable the corresponding 25 MHz reference output clock.On RK3576, this means the
REFCLKO25M_GMACx_OUTclock may be disabled by the common clock framework as unused, even though the board expects the GMAC block to provide the PHY reference clock.This series adds an optional "
clk_mac_25m_refout" clock name to the Rockchip DWMAC binding, wires it up for RK3576 GMAC0/GMAC1, and enables it from the dwmac-rk driver when the MAC is configured for RGMII output clock mode.The clock remains optional, so existing device trees and SoCs are not affected.
Quoted 8 lines
Quoted 2 lines
Tested on a PicoCOM RK3576 ACP board with a Motorcomm YT8521 PHY. The GMAC 25 MHz reference clock output remains active and Ethernet works.
I have a feeling this is using the common clock framework backwards. The MAC in this case is a clock provider yet it uses the consumer API.
Shouldn't the MAC instead register a new clock, as a provider, for the ref out ? The PHY device would then need to get/prepare/enable that clock.
The clock name is a misnomer frankly. It's configured in the CRU and muxed to the output pin via IO registers, so it has little to do with the GMAC itself - rather it's SoC wide. It's already exposed by the SoC clock drivers, so nothing to be done in drivers/net/ethernet.
Looks like Motorcomm PHY drivers don't request the clock though, thus we're seeing a second nearly identical attempt within the same development cycle to shoehorn clock enablement into the GMAC driver and binding, where it doesn't belong.
Best regards,
Alexey
Hi Gavin,
Quoted 28 lines · Gavin Gao
Hi,
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY. Boards already describe the MAC clock direction with
clock_in_out= "output", but the dwmac-rk driver does not currently request or enable the corresponding 25 MHz reference output clock.On RK3576, this means the
REFCLKO25M_GMACx_OUTclock may be disabled by the common clock framework as unused, even though the board expects the GMAC block to provide the PHY reference clock.This series adds an optional "
clk_mac_25m_refout" clock name to the Rockchip DWMAC binding, wires it up for RK3576 GMAC0/GMAC1, and enables it from the dwmac-rk driver when the MAC is configured for RGMII output clock mode.The clock remains optional, so existing device trees and SoCs are not affected.
Tested on a PicoCOM RK3576 ACP board with a Motorcomm YT8521 PHY. The GMAC 25 MHz reference clock output remains active and Ethernet works.
Gavin Gao (3):
dt-bindings: net: rockchip-dwmac: Add 25M refout clock
arm64: dts: rockchip: Add RK3576 GMAC 25M refout clocks
net: stmmac: dwmac-rk: Enable RGMII 25M refout clock
Quoted 4 lines
.../bindings/net/rockchip-dwmac.yaml | 1 + arch/arm64/boot/dts/rockchip/rk3576.dtsi | 8 ++--- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 33 ++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-)
Can you please try something like this [1] instead?
[1] https://lore.kernel.org/linux-rockchip/[email protected]/
The GMAC on RK3576 neither produces nor consumes the clock. CRU is the producer, and PHY is the consumer. So the GMAC driver shouldn't be the one to enable it, nor should the dwmac binding have anything to do with it.
Have a look at how other boards already upstream handle this. For example, the RK3576 EVB1 uses a similar arrangement but with a different PHY.
Best regards,
Alexey
Quoted 40 lines · Alexey Charkov
Hi Gavin,
Quoted 28 lines · Gavin Gao
Hi,
Some Rockchip GMAC instances can provide a 25 MHz reference clock output for an external RGMII PHY. Boards already describe the MAC clock direction with
clock_in_out= "output", but the dwmac-rk driver does not currently request or enable the corresponding 25 MHz reference output clock.On RK3576, this means the
REFCLKO25M_GMACx_OUTclock may be disabled by the common clock framework as unused, even though the board expects the GMAC block to provide the PHY reference clock.This series adds an optional "
clk_mac_25m_refout" clock name to the Rockchip DWMAC binding, wires it up for RK3576 GMAC0/GMAC1, and enables it from the dwmac-rk driver when the MAC is configured for RGMII output clock mode.The clock remains optional, so existing device trees and SoCs are not affected.
Tested on a PicoCOM RK3576 ACP board with a Motorcomm YT8521 PHY. The GMAC 25 MHz reference clock output remains active and Ethernet works.
Gavin Gao (3):
dt-bindings: net: rockchip-dwmac: Add 25M refout clock
arm64: dts: rockchip: Add RK3576 GMAC 25M refout clocks
net: stmmac: dwmac-rk: Enable RGMII 25M refout clockQuoted 4 lines
.../bindings/net/rockchip-dwmac.yaml | 1 + arch/arm64/boot/dts/rockchip/rk3576.dtsi | 8 ++--- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 33 ++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-)Can you please try something like this [1] instead?
[1] https://lore.kernel.org/linux-rockchip/[email protected]/
Quoted 8 lines
The GMAC on RK3576 neither produces nor consumes the clock. CRU is the producer, and PHY is the consumer. So the GMAC driver shouldn't be the one to enable it, nor should the dwmac binding have anything to do with it.
Have a look at how other boards already upstream handle this. For example, the RK3576 EVB1 uses a similar arrangement but with a different PHY.
Yep, we had a similar fix, but it was rejected. Please see how RK3576 EVB1 does it:
https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Best, Chaoyi
Hi Gavin,
We ran into the same thing on the ArmSoM CM5-IO. As Alexey and Maxime say, the 25 MHz output is a CRU clock muxed to a pin, so the PHY should enable it, not the GMAC. I sent that for the YT8531:
https://lore.kernel.org/all/[email protected]/
It has Andrew's Reviewed-by and is waiting for net-next. On the CM5-IO the YT8531 comes up at 1000 Mbit/s with no dwmac-rk change and no dwmac binding change.
Your board has a YT8521, which uses yt8521_probe(), so it needs the same devm_clk_get_optional_enabled() there rather than in yt8531_probe(). I am happy to fold YT8521 into my patch, or you can send a small follow-up once mine lands, whichever the maintainers prefer. The board DTS then just needs a clocks phandle to the CRU on the PHY node.
Thanks,
Jiaxing