Skip to content

Commit 8892b25

Browse files
committed
drivers: ethernet: phy: ksz9131: add getting status for gigabit mode
Read gigabit status from Master Slave Status Register. Signed-off-by: Tony Han <tony.han@microchip.com>
1 parent 78965f4 commit 8892b25

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

drivers/ethernet/phy/phy_microchip_ksz9131.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ struct mchp_ksz9131_data {
4141
#define PHY_ID_KSZ9131 0x00221640
4242
#define PHY_ID_KSZ9131_MSK (~0xF)
4343

44+
#define PHY_KSZ9131_MSS_ADVERTISE_1000_FULL BIT(11)
45+
#define PHY_KSZ9131_MSS_ADVERTISE_1000_HALF BIT(10)
46+
4447
#define PHY_KSZ9131_ICS_REG 0x1B
4548
#define PHY_KSZ9131_ICS_LINK_DOWN_IE_MASK BIT(10)
4649
#define PHY_KSZ9131_ICS_LINK_UP_IE_MASK BIT(8)
@@ -375,6 +378,8 @@ static int phy_mchp_ksz9131_get_link(const struct device *dev, struct phy_link_s
375378
uint16_t mutual_capabilities = 0;
376379
uint16_t anlpar = 0;
377380
uint16_t anar = 0;
381+
uint16_t mscr = 0;
382+
uint16_t mssr = 0;
378383
int ret = 0;
379384

380385
(void)config; /* avoid warnings due to config is only used in LOG_DBG() */
@@ -386,6 +391,27 @@ static int phy_mchp_ksz9131_get_link(const struct device *dev, struct phy_link_s
386391
goto done;
387392
}
388393

394+
/* Read AUTO-NEGOTIATION MASTER SLAVE CONTROL REGISTER */
395+
ret = ksz9131_read(dev, MII_1KTCR, &mscr);
396+
if (ret < 0) {
397+
goto done;
398+
}
399+
400+
/* Read AUTO-NEGOTIATION MASTER SLAVE STATUS REGISTER */
401+
ret = ksz9131_read(dev, MII_1KSTSR, &mssr);
402+
if (ret < 0) {
403+
goto done;
404+
}
405+
406+
if (mscr & MII_ADVERTISE_1000_FULL && mssr & PHY_KSZ9131_MSS_ADVERTISE_1000_FULL) {
407+
state->speed = LINK_FULL_1000BASE;
408+
goto done;
409+
}
410+
if (mscr & MII_ADVERTISE_1000_HALF && mssr & PHY_KSZ9131_MSS_ADVERTISE_1000_HALF) {
411+
state->speed = LINK_HALF_1000BASE;
412+
goto done;
413+
}
414+
389415
/* Read currently configured advertising options */
390416
ret = ksz9131_read(dev, MII_ANAR, &anar);
391417
if (ret < 0) {

0 commit comments

Comments
 (0)