Skip to content

Commit ef7bf97

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 fbd9521 commit ef7bf97

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

drivers/ethernet/phy/phy_microchip_ksz9131.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,28 @@ static int phy_mchp_ksz9131_cfg_link(const struct device *dev, enum phy_link_spe
337337
goto done;
338338
}
339339

340+
ret = ksz9131_read(dev, MII_1KTCR, &c1kt);
341+
if (ret < 0) {
342+
goto done;
343+
}
344+
345+
if (adv_speeds & LINK_FULL_1000BASE) {
346+
c1kt |= MII_ADVERTISE_1000_FULL;
347+
} else {
348+
c1kt &= ~MII_ADVERTISE_1000_FULL;
349+
}
350+
351+
if (adv_speeds & LINK_HALF_1000BASE) {
352+
c1kt |= MII_ADVERTISE_1000_HALF;
353+
} else {
354+
c1kt &= ~MII_ADVERTISE_1000_HALF;
355+
}
356+
357+
ret = ksz9131_write(dev, MII_1KTCR, c1kt);
358+
if (ret < 0) {
359+
goto done;
360+
}
361+
340362
ret = phy_mchp_ksz9131_autonegotiate(dev);
341363
done:
342364
k_sem_give(&data->sem);
@@ -353,6 +375,36 @@ static int phy_mchp_ksz9131_cfg_link(const struct device *dev, enum phy_link_spe
353375
return ret;
354376
}
355377

378+
static bool phy_mchp_ksz9131_gigabit(const struct device *dev, enum phy_link_speed *speed, int *ret)
379+
{
380+
uint16_t mutual_capabilities = 0;
381+
uint16_t mscr = 0;
382+
uint16_t mssr = 0;
383+
384+
/* Read AUTO-NEGOTIATION MASTER SLAVE CONTROL REGISTER */
385+
*ret = ksz9131_read(dev, MII_1KTCR, &mscr);
386+
if (*ret < 0) {
387+
return true;
388+
}
389+
390+
/* Read AUTO-NEGOTIATION MASTER SLAVE STATUS REGISTER */
391+
*ret = ksz9131_read(dev, MII_1KSTSR, &mssr);
392+
if (*ret < 0) {
393+
return true;
394+
}
395+
396+
mutual_capabilities = mscr & (mssr >> 2);
397+
if (mutual_capabilities & MII_ADVERTISE_1000_FULL) {
398+
*speed = LINK_FULL_1000BASE;
399+
return true;
400+
} else if (mutual_capabilities & MII_ADVERTISE_1000_HALF) {
401+
*speed = LINK_HALF_1000BASE;
402+
return true;
403+
}
404+
405+
return false;
406+
}
407+
356408
static int phy_mchp_ksz9131_get_link(const struct device *dev, struct phy_link_state *state)
357409
{
358410
const struct mchp_ksz9131_config *config = dev->config;
@@ -372,6 +424,10 @@ static int phy_mchp_ksz9131_get_link(const struct device *dev, struct phy_link_s
372424
goto done;
373425
}
374426

427+
if (phy_mchp_ksz9131_gigabit(dev, &state->speed, &ret)) {
428+
goto done;
429+
}
430+
375431
/* Read currently configured advertising options */
376432
ret = ksz9131_read(dev, MII_ANAR, &anar);
377433
if (ret < 0) {

0 commit comments

Comments
 (0)