Boards such as the Orange Pi 4 Pro wire the external PHY's 125 MHz CLK_OUT to the MAC's RGMII TX clock input rather than using the MAC's internal GMII TX clock, and stall on 1 Gbps TX unless the glue register selects external GMII clocking. Add the boolean allwinner,rgmii-clk-ext property so boards can select the external RGMII TX clock while preserving internal GMII clocking as the default. Assisted-by: LLM Signed-off-by: Alastair D'Silva --- .../devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml index fa28df89b48e..7ff467dbeab9 100644 --- a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml +++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml @@ -104,6 +104,12 @@ properties: description: Internal RGMII PHY RX clock delay chain value in ps. + allwinner,rgmii-clk-ext: + type: boolean + description: + Use the external 125 MHz RGMII TX clock provided by the PHY instead + of the internal MAC GMII clock. + required: - compatible - reg -- 2.53.0 On the Allwinner A733 SoC, GMAC0 sits behind the shared MSI-Lite0 bus fabric, which is gated by ahb-msi-lite0 and mbus-msi-lite0. Without consumers holding references to these gates, clk_disable_unused() shuts down the shared fabric and breaks GMAC0 link-up and DMA. Allow ahb-msi-lite0 and mbus-msi-lite0 as additional clocks on allwinner,sun60i-a733-gmac210 so masters behind MSI-Lite0 can reference them directly instead of marking the clocks critical in the CCU driver. Assisted-by: LLM Signed-off-by: Alastair D'Silva --- .../devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml index 7ff467dbeab9..28ca217157fe 100644 --- a/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml +++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-a83t-emac.yaml @@ -71,7 +71,7 @@ properties: clocks: minItems: 1 - maxItems: 3 + maxItems: 5 clock-names: minItems: 1 @@ -79,6 +79,8 @@ properties: - const: stmmaceth - const: mbus - const: ptp_ref + - const: ahb-msi-lite0 + - const: mbus-msi-lite0 phy-supply: description: PHY regulator @@ -335,8 +337,10 @@ allOf: minItems: 4 clocks: minItems: 3 + maxItems: 5 clock-names: minItems: 3 + maxItems: 5 resets: minItems: 2 reset-names: -- 2.53.0 Select SYSCON_ETCS_EXT_GMII when the "allwinner,rgmii-clk-ext" property is present in RGMII mode, keeping SYSCON_ETCS_INT_GMII as the default. Boards that wire the external PHY's 125 MHz CLK_OUT to the MAC (such as the Orange Pi 4 Pro) stall on 1 Gbps TX with SYSCON_ETCS_INT_GMII, while boards without that clock wired (such as the Cubie A7A) require internal GMII TX clocking. Assisted-by: LLM Signed-off-by: Alastair D'Silva --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c index 675b83cd52c8..7a3ce92be821 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c @@ -158,7 +158,11 @@ static int sun55i_gmac200_setup(struct device *dev, case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII_RXID: case PHY_INTERFACE_MODE_RGMII_TXID: - reg |= SYSCON_EPIT | SYSCON_ETCS_INT_GMII; + reg |= SYSCON_EPIT; + if (device_property_read_bool(dev, "allwinner,rgmii-clk-ext")) + reg |= SYSCON_ETCS_EXT_GMII; + else + reg |= SYSCON_ETCS_INT_GMII; break; case PHY_INTERFACE_MODE_RMII: reg |= SYSCON_RMII_EN; -- 2.53.0 A733 GMAC210 requires RX clock inversion (SYSCON_ERXIE, BIT(4) in glue offset 0x00) for standard RGMII timing. Without ERXIE set, RX requires ~3.8-4.1 ns of total delay (almost half a 125 MHz clock period) instead of standard 2 ns RGMII-ID timing. With ERXIE enabled, RX timing is satisfied without PHY or MAC RX delay chains. Downgrade PHY_INTERFACE_MODE_RGMII_ID to PHY_INTERFACE_MODE_RGMII_TXID (and RGMII_RXID to RGMII) so the PHY only applies TX delay and boards do not need rx-internal-delay-ps overrides. Assisted-by: LLM Signed-off-by: Alastair D'Silva --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c index 7a3ce92be821..e311d5fccfbb 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c @@ -31,7 +31,8 @@ #define SYSCON_ETXDC_MASK GENMASK(12, 10) #define SYSCON_ERXDC_MASK GENMASK(9, 5) /* EMAC PHY Interface Type */ -#define SYSCON_EPIT BIT(2) /* 1: RGMII, 0: MII */ +#define SYSCON_ERXIE BIT(4) /* 1: invert RX clock */ +#define SYSCON_EPIT BIT(2) /* 1: RGMII, 0: MII */ #define SYSCON_ETCS_MASK GENMASK(1, 0) #define SYSCON_ETCS_MII 0x0 #define SYSCON_ETCS_EXT_GMII 0x1 @@ -47,6 +48,7 @@ struct sun55i_gmac_data { u32 txdly_step_ps; u32 rxdly_step_ps; u32 offset; + bool rx_clk_inv; }; struct sun55i_gmac { @@ -163,6 +165,13 @@ static int sun55i_gmac200_setup(struct device *dev, reg |= SYSCON_ETCS_EXT_GMII; else reg |= SYSCON_ETCS_INT_GMII; + if (gmac->data->rx_clk_inv) { + reg |= SYSCON_ERXIE; + if (plat->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) + plat->phy_interface = PHY_INTERFACE_MODE_RGMII_TXID; + else if (plat->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) + plat->phy_interface = PHY_INTERFACE_MODE_RGMII; + } break; case PHY_INTERFACE_MODE_RMII: reg |= SYSCON_RMII_EN; @@ -253,6 +262,7 @@ static const struct sun55i_gmac_data sun60i_a733_gmac210_data = { .etxdc_ext_mask = GENMASK(17, 16), .txdly_step_ps = 180, .rxdly_step_ps = 180, + .rx_clk_inv = true, }; static const struct of_device_id sun55i_gmac200_match[] = { -- 2.53.0 Enable the optional ahb-msi-lite0 and mbus-msi-lite0 bus fabric clocks when provided in the A733 GMAC210 device tree node so the shared MSI-Lite0 fabric remains clocked during clk_disable_unused() without marking the gates CLK_IS_CRITICAL in the CCU driver. Assisted-by: LLM Signed-off-by: Alastair D'Silva --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c index e311d5fccfbb..648e2f9a1b0d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -77,10 +78,23 @@ static const struct regmap_config sun60i_a733_regmap_cfg = { static int sun60i_gmac210_init_resources(struct platform_device *pdev, struct sun55i_gmac *gmac) { + static const char * const msi_clks[] = { + "ahb-msi-lite0", + "mbus-msi-lite0", + }; struct device *dev = &pdev->dev; struct reset_control *ahb_reset; void __iomem *base; + for (unsigned int i = 0; i < ARRAY_SIZE(msi_clks); i++) { + struct clk *clk = devm_clk_get_optional_enabled(dev, msi_clks[i]); + + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), + "Failed to enable %s clock\n", + msi_clks[i]); + } + /* * Get the configuration region out of reset before changing it. * stmmac core holds the same shared reset but only deasserts it later. -- 2.53.0 Boards using the Allwinner A733 SoC need the SoC-level GMAC0 controller, MDIO bus, and PH0-PH15 RGMII pinmux nodes to enable wired Ethernet. Disable internal bias pulls and use drive-strength = <20> on gmac0_rgmii_pins to avoid distorting 125 MHz RGMII signaling. Include the ahb-msi-lite0 and mbus-msi-lite0 clocks so the shared MSI-Lite0 bus fabric stays enabled while GMAC0 is active. Add gmac0, mdio0, and gmac0_rgmii_pins (disabled by default) to sun60i-a733.dtsi. Assisted-by: LLM Signed-off-by: Alastair D'Silva --- .../arm64/boot/dts/allwinner/sun60i-a733.dtsi | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun60i-a733.dtsi b/arch/arm64/boot/dts/allwinner/sun60i-a733.dtsi index e062b08006da..513f30ef1e09 100644 --- a/arch/arm64/boot/dts/allwinner/sun60i-a733.dtsi +++ b/arch/arm64/boot/dts/allwinner/sun60i-a733.dtsi @@ -197,6 +197,18 @@ mmc2_pins: mmc2-pins { bias-pull-up; }; + /omit-if-no-ref/ + gmac0_rgmii_pins: gmac0-rgmii-pins { + pins = "PH0", "PH1", "PH2", "PH3", + "PH4", "PH5", "PH6", "PH7", + "PH8", "PH9", "PH10", "PH11", + "PH12", "PH13", "PH14", "PH15"; + function = "gmac0"; + allwinner,pinmux = <5>; + drive-strength = <20>; + bias-disable; + }; + uart0_pb_pins: uart0-pb-pins { pins = "PB9", "PB10"; function = "uart0"; @@ -546,6 +558,38 @@ mmc2: mmc@4022000 { status = "disabled"; }; + gmac0: ethernet@4500000 { + compatible = "allwinner,sun60i-a733-gmac210", + "snps,dwmac-5.20"; + reg = <0x04500000 0x8000>, + <0x04508000 0x100>; + interrupts = , + , + , + ; + interrupt-names = "macirq", "eth_lpi", + "tx-queue-0", "rx-queue-0"; + clocks = <&ccu CLK_BUS_GMAC0>, + <&ccu CLK_MBUS_GMAC0>, + <&ccu CLK_GMAC_PTP>, + <&ccu CLK_AHB_MSI_LITE0>, + <&ccu CLK_MBUS_MSI_LITE0>; + clock-names = "stmmaceth", "mbus", "ptp_ref", + "ahb-msi-lite0", "mbus-msi-lite0"; + resets = <&ccu RST_BUS_GMAC0_AXI>, + <&ccu RST_BUS_GMAC0>; + reset-names = "stmmaceth", "ahb"; + pinctrl-names = "default"; + pinctrl-0 = <&gmac0_rgmii_pins>; + status = "disabled"; + + mdio0: mdio { + compatible = "snps,dwmac-mdio"; + #address-cells = <1>; + #size-cells = <0>; + }; + }; + r_ccu: clock-controller@7010000 { compatible = "allwinner,sun60i-a733-r-ccu"; reg = <0x07010000 0x250>; -- 2.53.0 The Orange Pi 4 Pro connects A733 GMAC0 to a Motorcomm YT8531 Gigabit PHY over RGMII without PCB trace delays, relies on the PHY 125 MHz CLK_OUT for external GMII TX clocking (allwinner,rgmii-clk-ext), and powers the PHY and PH bank at 3.3V via AXP318W swout1 and swout2. Use phy-mode = "rgmii-id" with no tx/rx-internal-delay-ps overrides so the MAC/PHY pair handles standard RGMII timing (MAC inverts RXC via ERXIE and PHY adds the 2 ns TX delay). Add the reg_swout1 and reg_swout2 switch regulator nodes and enable GMAC0 with its reset GPIO and supplies. Assisted-by: LLM Signed-off-by: Alastair D'Silva --- .../allwinner/sun60i-a733-orangepi-4-pro.dts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun60i-a733-orangepi-4-pro.dts b/arch/arm64/boot/dts/allwinner/sun60i-a733-orangepi-4-pro.dts index 374287d962a8..59d3a699c9a7 100644 --- a/arch/arm64/boot/dts/allwinner/sun60i-a733-orangepi-4-pro.dts +++ b/arch/arm64/boot/dts/allwinner/sun60i-a733-orangepi-4-pro.dts @@ -15,6 +15,7 @@ / { compatible = "xunlong,orangepi-4-pro", "allwinner,sun60i-a733"; aliases { + ethernet0 = &gmac0; serial0 = &uart0; }; @@ -23,10 +24,32 @@ chosen { }; }; +&gmac0 { + assigned-clocks = <&ccu CLK_GMAC0_PHY>; + assigned-clock-rates = <25000000>; + phy-mode = "rgmii-id"; + phy-handle = <&ext_rgmii_phy>; + phy-supply = <®_swout1>; + allwinner,rgmii-clk-ext; + status = "okay"; +}; + &hosc { clock-frequency = <26000000>; }; +&mdio0 { + ext_rgmii_phy: ethernet-phy@1 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <1>; + clocks = <&ccu CLK_GMAC0_PHY>; + motorcomm,clk-out-frequency-hz = <125000000>; + reset-gpios = <&pio 7 16 GPIO_ACTIVE_LOW>; /* PH16 */ + reset-assert-us = <10000>; + reset-deassert-us = <150000>; + }; +}; + &mmc0 { bus-width = <4>; cd-gpios = <&pio 5 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; /* PF6 */ @@ -36,6 +59,10 @@ &mmc0 { status = "okay"; }; +&pio { + vcc-ph-supply = <®_swout2>; +}; + &r_i2c0 { pinctrl-names = "default"; pinctrl-0 = <&r_i2c0_pl_pins>; @@ -64,6 +91,16 @@ reg_dldo1: dldo1 { regulator-max-microvolt = <3300000>; regulator-always-on; }; + + reg_swout1: swout1 { + regulator-name = "vcc-ephy"; + regulator-always-on; + }; + + reg_swout2: swout2 { + regulator-name = "vcc-gmac-io"; + regulator-always-on; + }; }; }; }; -- 2.53.0