From d1e993f872293fc74b72d0d189c9610b66c61d21 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 3 Nov 2025 23:54:03 +1100 Subject: [PATCH] stm32/eth_phy: Add support for RTL8211 inititialization. This gets the status indicator working on the RTL8211. Signed-off-by: Damien George --- ports/stm32/eth.c | 1 + ports/stm32/eth_phy.c | 12 ++++++++++++ ports/stm32/eth_phy.h | 1 + 3 files changed, 14 insertions(+) diff --git a/ports/stm32/eth.c b/ports/stm32/eth.c index c2155399eb..d1ded64877 100644 --- a/ports/stm32/eth.c +++ b/ports/stm32/eth.c @@ -219,6 +219,7 @@ int eth_init(eth_t *self, int mac_idx, uint32_t phy_addr, int phy_type) { } else if (phy_type == ETH_PHY_LAN8720 || phy_type == ETH_PHY_LAN8742) { self->phy_get_link_status = eth_phy_lan87xx_get_link_status; } else if (phy_type == ETH_PHY_RTL8211) { + self->phy_init = eth_phy_rtl8211_init; self->phy_get_link_status = eth_phy_rtl8211_get_link_status; } else { return -1; diff --git a/ports/stm32/eth_phy.c b/ports/stm32/eth_phy.c index fa4364a910..cdc632f26f 100644 --- a/ports/stm32/eth_phy.c +++ b/ports/stm32/eth_phy.c @@ -47,6 +47,8 @@ #define PHY_RTL8211_PHYSR_SPEED_Pos (4) #define PHY_RTL8211_PHYSR_SPEED_Msk (3 << PHY_RTL8211_PHYSR_SPEED_Pos) #define PHY_RTL8211_PHYSR_DUPLEX_Msk (0x0008) +#define PHY_RTL8211_LCR_PAGE (0xd04) +#define PHY_RTL8211_LCR_ADDR (0x10) void eth_phy_generic_init(uint32_t phy_addr) { // Reset the PHY. @@ -81,6 +83,16 @@ int16_t eth_phy_dp838xx_get_link_status(uint32_t phy_addr) { return scsr; } +void eth_phy_rtl8211_init(uint32_t phy_addr) { + // Perform generic PHY initialization. + eth_phy_generic_init(phy_addr); + + // Configure LED0 output to show 10/100/1000 link speed, and activity. + eth_phy_write(phy_addr, PHY_RTL8211_PAGSR_ADDR, PHY_RTL8211_LCR_PAGE); + eth_phy_write(phy_addr, PHY_RTL8211_LCR_ADDR, 0x001b); + eth_phy_write(phy_addr, PHY_RTL8211_PAGSR_ADDR, PHY_RTL8211_DEFAULT_PAGE); +} + int16_t eth_phy_rtl8211_get_link_status(uint32_t phy_addr) { // Get the link mode & speed eth_phy_write(phy_addr, PHY_RTL8211_PAGSR_ADDR, PHY_RTL8211_PHYSR_PAGE); diff --git a/ports/stm32/eth_phy.h b/ports/stm32/eth_phy.h index c369de1f43..7d4bf4c468 100644 --- a/ports/stm32/eth_phy.h +++ b/ports/stm32/eth_phy.h @@ -64,6 +64,7 @@ void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val); void eth_phy_generic_init(uint32_t phy_addr); int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr); int16_t eth_phy_dp838xx_get_link_status(uint32_t phy_addr); +void eth_phy_rtl8211_init(uint32_t phy_addr); int16_t eth_phy_rtl8211_get_link_status(uint32_t phy_addr); #endif