net: phy: mscc: consolidate a common RGMII delay implementation
Subsystems (3)
PATCH 1/1 net: phy: mscc: consolidate a common RGMII delay implementation
From: Vladimir Oltean <[email protected]>
It looks like the VSC8584 PHY driver is rolling its own RGMII delay configuration code, despite the fact that the logic is mostly the same.
In fact only the register layout and position for the RGMII controls has changed. So we need to adapt and parameterize the PHY-dependent bit fields when calling the new generic function.
--- drivers/net/phy/mscc/mscc.h | 28 ++++--------- drivers/net/phy/mscc/mscc_main.c | 71 +++++++++++++++----------------- 2 files changed, 42 insertions(+), 57 deletions(-)
drivers/net/phy/mscc/mscc.h +9 -19
@@ -161,25 +161,15 @@ enum rgmii_clock_delay {/* Extended Page 2 Registers */ #define MSCC_PHY_CU_PMD_TX_CNTL 16 -#define MSCC_PHY_RGMII_SETTINGS 18 -#define RGMII_SKEW_RX_POS 1 -#define RGMII_SKEW_TX_POS 4 - -/* RGMII skew values, in ns */ -#define VSC8584_RGMII_SKEW_0_2 0 -#define VSC8584_RGMII_SKEW_0_8 1 -#define VSC8584_RGMII_SKEW_1_1 2 -#define VSC8584_RGMII_SKEW_1_7 3 -#define VSC8584_RGMII_SKEW_2_0 4 -#define VSC8584_RGMII_SKEW_2_3 5 -#define VSC8584_RGMII_SKEW_2_6 6 -#define VSC8584_RGMII_SKEW_3_4 7 - -#define MSCC_PHY_RGMII_CNTL 20 -#define RGMII_RX_CLK_DELAY_MASK 0x0070 -#define RGMII_RX_CLK_DELAY_POS 4 -#define RGMII_TX_CLK_DELAY_MASK 0x0007 -#define RGMII_TX_CLK_DELAY_POS 0 +/* RGMII setting controls at address 18E2, for VSC8572 and similar */ +#define VSC8572_RGMII_CNTL 18 +#define VSC8572_RGMII_RX_DELAY_MASK 0x000E +#define VSC8572_RGMII_TX_DELAY_MASK 0x0070 + +/* RGMII controls at address 20E2, for VSC8502 and similar */ +#define VSC8502_RGMII_CNTL 20 +#define VSC8502_RGMII_RX_DELAY_MASK 0x0070 +#define VSC8502_RGMII_TX_DELAY_MASK 0x0007#define MSCC_PHY_WOL_LOWER_MAC_ADDR 21#define MSCC_PHY_WOL_MID_MAC_ADDR 22
drivers/net/phy/mscc/mscc_main.c +33 -38
107 lines not on this page · raw message
Signature · 1 line
2.17.1
Andrew Lunn
maintainerQuoted 8 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
It looks like the VSC8584 PHY driver is rolling its own RGMII delay configuration code, despite the fact that the logic is mostly the same.
In fact only the register layout and position for the RGMII controls has changed. So we need to adapt and parameterize the PHY-dependent bit fields when calling the new generic function.
Nice.
drivers/net/phy/mscc/mscc_main.c static bool vsc8584_is_pkg_init(struct phy_device *phydev, bool reversed) · line 1310
Quoted 7 lines
drivers/net/phy/mscc/mscc_main.c +0
-7-static void vsc8584_rgmii_set_skews (struct phy_device *phydev) -{ -u32 skew_rx, skew_tx; - -/* We first set the Rx and Tx skews to their default value in h/w -* (0.2 ns). -*/
I like seeing this comment. It makes it clear that PHY_INTERFACE_MODE_RGMII does not actually mean 0ns, but 0.2ns. It also makes it clear that if PHY_INTERFACE_MODE_RGMII_ID, PHY_INTERFACE_MODE_RGMII_RXID or PHY_INTERFACE_MODE_RGMII_TXID is not given, the delay is set to something. We have had PHY drivers which get this wrong and leave the bootloader/strapping value in place.
So if you can keep the comment in some form, that would be good.
Thanks
Andrew
Quoted 28 lines · Andrew Lunn
Quoted 8 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
It looks like the VSC8584 PHY driver is rolling its own RGMII delay configuration code, despite the fact that the logic is mostly the same.
In fact only the register layout and position for the RGMII controls has changed. So we need to adapt and parameterize the PHY-dependent bit fields when calling the new generic function.
Nice.
drivers/net/phy/mscc/mscc_main.c static bool vsc8584_is_pkg_init(struct phy_device *phydev, bool reversed) · line 1310
Quoted 7 lines
drivers/net/phy/mscc/mscc_main.c +0
-7-static void vsc8584_rgmii_set_skews (struct phy_device *phydev) -{ -u32 skew_rx, skew_tx; - -/* We first set the Rx and Tx skews to their default value in h/w -* (0.2 ns). -*/ I like seeing this comment. It makes it clear that
PHY_INTERFACE_MODE_RGMIIdoes not actually mean 0ns, but 0.2ns. It also makes it clear that ifPHY_INTERFACE_MODE_RGMII_ID,PHY_INTERFACE_MODE_RGMII_RXIDorPHY_INTERFACE_MODE_RGMII_TXIDis not given, the delay is set to something. We have had PHY drivers which get this wrong and leave the bootloader/strapping value in place.
Quoted 4 lines
So if you can keep the comment in some form, that would be good.
Thanks
Andrew
I find the comments fairly redundant since the code that does that is already explicit, but anyway I'll send a v2 for the 0.2 ns thing.
Thanks,
-Vladimir