diff options
author | Evan Lojewski <github@meklort.com> | 2021-02-05 21:45:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 21:45:47 -0700 |
commit | aa759e5fa327949846ce3e119b0c18ce0b830a4f (patch) | |
tree | 982a7c7491ca881b21c174ef8dd81628a5e6316b | |
parent | ada148573287c596d89182d9729a777cb0c906ee (diff) | |
download | bcm5719-ortega-aa759e5fa327949846ce3e119b0c18ce0b830a4f.tar.gz bcm5719-ortega-aa759e5fa327949846ce3e119b0c18ce0b830a4f.zip |
mii: Add an API to update the advertise state to include 1G when available. (#198)
-rw-r--r-- | libs/MII/include/MII.h | 10 | ||||
-rw-r--r-- | libs/MII/include/bcm5719_MII.h | 2 | ||||
-rw-r--r-- | libs/MII/mii.c | 39 |
3 files changed, 50 insertions, 1 deletions
diff --git a/libs/MII/include/MII.h b/libs/MII/include/MII.h index cea149d..55d0421 100644 --- a/libs/MII/include/MII.h +++ b/libs/MII/include/MII.h @@ -94,6 +94,16 @@ int32_t MII_getBlock(volatile DEVICE_t* device, uint8_t phy); */ bool MII_reset(volatile DEVICE_t* device, uint8_t phy); +/** + * @fn bool MII_UpdateAdvertisement(volatile DEVICE_t *device, uint8_t phy) + * + * Update the PHY to advertise all capabilities + * + * @returns True if updated, false otherwise. + */ +bool MII_UpdateAdvertisement(volatile DEVICE_t *device, uint8_t phy); + + #ifdef CXX_SIMULATOR #undef volatile #endif diff --git a/libs/MII/include/bcm5719_MII.h b/libs/MII/include/bcm5719_MII.h index 81a8bb8..3cbeab2 100644 --- a/libs/MII/include/bcm5719_MII.h +++ b/libs/MII/include/bcm5719_MII.h @@ -10,7 +10,7 @@ /// //////////////////////////////////////////////////////////////////////////////// /// -/// @copyright Copyright (c) 2020, Evan Lojewski +/// @copyright Copyright (c) 2021, Evan Lojewski /// @cond /// /// All rights reserved. diff --git a/libs/MII/mii.c b/libs/MII/mii.c index 0704a9f..9cd6c18 100644 --- a/libs/MII/mii.c +++ b/libs/MII/mii.c @@ -298,6 +298,45 @@ int32_t MII_getBlock(volatile DEVICE_t *device, uint8_t phy) return MII_readRegister(device, phy, (mii_reg_t)REG_MII_BLOCK_SELECT); } +bool MII_UpdateAdvertisement(volatile DEVICE_t *device, uint8_t phy) +{ + int32_t readVal; + + // Ensure 1G is advertised if supported. + readVal = MII_readRegister(device, phy, (mii_reg_t)REG_MII_IEEE_EXTENDED_STATUS); + if (readVal >= 0) + { + RegMIIIeeeExtendedStatus_t status; + status.r16 = (uint16_t)readVal; + + readVal = MII_readRegister(device, phy, (mii_reg_t)REG_MII_1000BASE_T_CONTROL); + if (readVal >= 0) + { + RegMII1000baseTControl_t control1G; + control1G.r16 = (uint16_t)readVal; + + if ((status.bits._1000BASE_THalfDuplexCapable != control1G.bits.Advertise1000BASE_THalfDuplex) || + (status.bits._1000BASE_TFullDuplexCapable != control1G.bits.Advertise1000BASE_TFullDuplex)) + { + control1G.bits.Advertise1000BASE_THalfDuplex = status.bits._1000BASE_THalfDuplexCapable; + control1G.bits.Advertise1000BASE_TFullDuplex = status.bits._1000BASE_TFullDuplexCapable; + (void)MII_writeRegister(device, phy, (mii_reg_t)REG_MII_1000BASE_T_CONTROL, control1G.r16); + + // Restart Autonegotiation. + RegMIIControl_t control; + control.r16 = 0; + control.bits.AutoNegotiationEnable = 1; + control.bits.RestartAutonegotiation = 1; + (void)MII_writeRegister(device, phy, (mii_reg_t)REG_MII_CONTROL, control.r16); + + return true; + } + } + } + + return false; +} + bool MII_reset(volatile DEVICE_t *device, uint8_t phy) { // Set MII_REG_CONTROL to RESET; wait until RESET bit clears. |