/* This function gets the value of the PHY registers through the MII interface.  */
int imx_enet_mii_read(volatile hw_enet_t *enet_reg, unsigned char phy_addr, unsigned char reg_addr, unsigned short int *value)
/* This function gets the value of the PHY registers through the MII interface.  */
int imx_enet_mii_read(volatile hw_enet_t *enet_reg, unsigned char phy_addr, unsigned char reg_addr, unsigned short int *value)
{
    unsigned long waiting = ENET_MII_TIMEOUT;
    if (enet_reg->EIR.U & ENET_EVENT_MII) {
        enet_reg->EIR.U = ENET_EVENT_MII;
    }
    enet_reg->MMFR.U = ENET_MII_READ(phy_addr, reg_addr);
    while (1) {
        if (enet_reg->EIR.U & ENET_EVENT_MII) {
            enet_reg->EIR.U = ENET_EVENT_MII;
            break;
        }
        if ((--waiting) == 0)
            return -1;
        hal_delay_us(ENET_MII_TICK);
    }
    *value = ENET_MII_GET_DATA(enet_reg->MMFR.U);
    return 0;
}