Skip to content

Commit 7713cdd

Browse files
committed
stm32/eth_phy: Add support for RTL8211 ETH PHY.
Signed-off-by: Damien George <[email protected]>
1 parent 769f5cf commit 7713cdd

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

ports/stm32/eth.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ int eth_init(eth_t *self, int mac_idx, uint32_t phy_addr, int phy_type) {
216216
self->phy_get_link_status = eth_phy_dp838xx_get_link_status;
217217
} else if (phy_type == ETH_PHY_LAN8720 || phy_type == ETH_PHY_LAN8742) {
218218
self->phy_get_link_status = eth_phy_lan87xx_get_link_status;
219+
} else if (phy_type == ETH_PHY_RTL8211) {
220+
self->phy_get_link_status = eth_phy_rtl8211_get_link_status;
219221
} else {
220222
return -1;
221223
}

ports/stm32/eth.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ enum {
3030
ETH_PHY_LAN8742 = 0,
3131
ETH_PHY_LAN8720,
3232
ETH_PHY_DP83848,
33-
ETH_PHY_DP83825
33+
ETH_PHY_DP83825,
34+
ETH_PHY_RTL8211
3435
};
3536

3637
typedef struct _eth_t eth_t;

ports/stm32/eth_phy.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
#define PHY_SCSR_DP838XX_DUPLEX_Msk (4)
4141
#define PHY_SCSR_DP838XX_10M_Msk (2)
4242

43+
#define PHY_RTL8211_DEFAULT_PAGE (0xa42)
44+
#define PHY_RTL8211_PAGSR_ADDR (0x1f)
45+
#define PHY_RTL8211_PHYSR_PAGE (0xa43)
46+
#define PHY_RTL8211_PHYSR_ADDR (0x1a)
47+
#define PHY_RTL8211_PHYSR_SPEED_Pos (4)
48+
#define PHY_RTL8211_PHYSR_SPEED_Msk (3 << PHY_RTL8211_PHYSR_SPEED_Pos)
49+
#define PHY_RTL8211_PHYSR_DUPLEX_Msk (0x0008)
50+
4351
int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr) {
4452
// Get the link mode & speed
4553
uint16_t scsr = eth_phy_read(phy_addr, PHY_SCSR_LAN87XX);
@@ -67,4 +75,27 @@ int16_t eth_phy_dp838xx_get_link_status(uint32_t phy_addr) {
6775
return scsr;
6876
}
6977

78+
int16_t eth_phy_rtl8211_get_link_status(uint32_t phy_addr) {
79+
// Get the link mode & speed
80+
eth_phy_write(phy_addr, PHY_RTL8211_PAGSR_ADDR, PHY_RTL8211_PHYSR_PAGE);
81+
int16_t physr = eth_phy_read(phy_addr, PHY_RTL8211_PHYSR_ADDR);
82+
eth_phy_write(phy_addr, PHY_RTL8211_PAGSR_ADDR, PHY_RTL8211_DEFAULT_PAGE);
83+
int16_t status = 0;
84+
switch ((physr & PHY_RTL8211_PHYSR_SPEED_Msk) >> PHY_RTL8211_PHYSR_SPEED_Pos) {
85+
case 0:
86+
status |= PHY_SPEED_10HALF;
87+
break;
88+
case 1:
89+
status |= PHY_SPEED_100HALF;
90+
break;
91+
case 2:
92+
status |= PHY_SPEED_1000HALF;
93+
break;
94+
}
95+
if (physr & PHY_RTL8211_PHYSR_DUPLEX_Msk) {
96+
status |= PHY_DUPLEX;
97+
}
98+
return status;
99+
}
100+
70101
#endif

ports/stm32/eth_phy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val);
6363

6464
int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr);
6565
int16_t eth_phy_dp838xx_get_link_status(uint32_t phy_addr);
66+
int16_t eth_phy_rtl8211_get_link_status(uint32_t phy_addr);
6667

6768
#endif
6869

0 commit comments

Comments
 (0)