From aa759e5fa327949846ce3e119b0c18ce0b830a4f Mon Sep 17 00:00:00 2001 From: Evan Lojewski Date: Fri, 5 Feb 2021 21:45:47 -0700 Subject: mii: Add an API to update the advertise state to include 1G when available. (#198) --- libs/MII/include/MII.h | 10 ++++++++++ libs/MII/include/bcm5719_MII.h | 2 +- libs/MII/mii.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) (limited to 'libs') 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. -- cgit v1.2.1