From 6eb6a5892d9a8a139faecf30c09cb26a5982251c Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Wed, 20 Sep 2023 00:44:08 +0200 Subject: [PATCH] bigmac: fix/improve PHY interface. --- devices/ethernet/bigmac.cpp | 11 +++++++++++ devices/ethernet/bigmac.h | 1 + 2 files changed, 12 insertions(+) diff --git a/devices/ethernet/bigmac.cpp b/devices/ethernet/bigmac.cpp index 250cf56..dfe91c5 100644 --- a/devices/ethernet/bigmac.cpp +++ b/devices/ethernet/bigmac.cpp @@ -124,6 +124,9 @@ void BigMac::mii_rcv_bit() { this->mii_reset(); } break; + case MII_FRAME_SM::Stop: + this->mii_reset(); + break; default: LOG_F(ERROR, "%s: unhandled state %d in mii_rcv_bit", this->name.c_str(), this->mii_state); @@ -245,6 +248,10 @@ void BigMac::phy_reset() { uint16_t BigMac::phy_reg_read(uint8_t reg_num) { switch(reg_num) { + case PHY_BMCR: + return this->phy_bmcr; + case PHY_BMSR: + return 0x7809; // value from LXT970 datasheet case PHY_ID1: return (this->phy_oui >> 6) & 0xFFFFU; case PHY_ID2: @@ -261,6 +268,10 @@ uint16_t BigMac::phy_reg_read(uint8_t reg_num) { void BigMac::phy_reg_write(uint8_t reg_num, uint16_t value) { switch(reg_num) { case PHY_BMCR: + if (value & 0x8000) { + LOG_F(INFO, "PHY reset requested"); + value &= ~0x8000; // Reset bit is self-clearing + } this->phy_bmcr = value; break; case PHY_ANAR: diff --git a/devices/ethernet/bigmac.h b/devices/ethernet/bigmac.h index ac5f8a1..fd83f2b 100644 --- a/devices/ethernet/bigmac.h +++ b/devices/ethernet/bigmac.h @@ -84,6 +84,7 @@ enum MII_FRAME_SM { /* PHY control/status registers. */ enum { PHY_BMCR = 0, + PHY_BMSR = 1, PHY_ID1 = 2, PHY_ID2 = 3, PHY_ANAR = 4,