/**
 * \brief Issue a SW reset to reset all registers of the PHY.
 * \param pMacb Pointer to the MACB instance
 * \return 1 if successfully, 0 if timeout.
 */
uint8_t GMACB_ResetPhy(GMacb *pMacb)
{
	sGmacd *pDrv = pMacb->pGmacd;
	Gmac *pHw = pDrv->pHw;
	uint32_t retryMax;
	uint32_t bmcr = GMII_RESET;
	uint8_t phyAddress;
	uint32_t timeout = 10;
	uint8_t ret = 1;

	TRACE_INFO(" GMACB_ResetPhy\n\r");

	phyAddress = pMacb->phyAddress;
	retryMax = pMacb->retryMax;

	GMAC_EnableMdio(pHw);
	bmcr = GMII_RESET;
	GMACB_WritePhy(pHw, phyAddress, GMII_BMCR, bmcr, retryMax);

	do {
		GMACB_ReadPhy(pHw, phyAddress, GMII_BMCR, &bmcr, retryMax);
		timeout--;
	} while ((bmcr & GMII_RESET) && timeout);

	GMAC_DisableMdio(pHw);

	if (!timeout)
		ret = 0;

	return (ret);
}
Exemple #2
0
/**
 * \brief Issue a Auto Negotiation of the PHY
 * \param pMacb Pointer to the MACB instance
 * \return 1 if successfully, 0 if timeout.
 */
uint8_t GMACB_AutoNegotiate(GMacb *pMacb)
{
    sGmacd *pDrv = pMacb->pGmacd;
    Gmac *pHw = pDrv->pHw;
    uint32_t retryMax;
    uint32_t value;
    uint32_t phyAnar;
    uint32_t phyAnalpar;
    uint32_t retryCount= 0;
    uint8_t phyAddress;
    uint8_t rc = 1;
    uint32_t duplex, speed;
    phyAddress = pMacb->phyAddress;
    retryMax = pMacb->retryMax;

    GMAC_EnableMdio(pHw);

    if (!GMACB_ReadPhy(pHw,phyAddress, GMII_PHYID1R, &value, retryMax)) {
        TRACE_ERROR("Pb GEMAC_ReadPhy Id1\n\r");
        rc = 0;
        goto AutoNegotiateExit;
    }
    TRACE_DEBUG("ReadPhy Id1 0x%X, addresse: %d\n\r", value, phyAddress);
    if (!GMACB_ReadPhy(pHw,phyAddress, GMII_PHYID2R, &phyAnar, retryMax)) {
        TRACE_ERROR("Pb GMACB_ReadPhy Id2\n\r");
        rc = 0;
        goto AutoNegotiateExit;
    }
    TRACE_DEBUG("ReadPhy Id2 0x%X\n\r", phyAnar);

    if( ( value == GMII_OUI_MSB )
            && ( ((phyAnar)&(~GMII_LSB_MASK)) == GMII_OUI_LSB ) ) {
        TRACE_DEBUG("Vendor Number Model = 0x%X\n\r", ((phyAnar>>4)&0x3F));
        TRACE_DEBUG("Model Revision Number = 0x%X\n\r", (phyAnar&0xF));
    } else {
/**
 * \brief Find a valid PHY Address (from 0 to 31).
 * \param pMacb Pointer to the MACB instance
 * \return 0xFF when no valid PHY Address found.
 */
static uint8_t GMACB_FindValidPhy(GMacb *pMacb)
{
	sGmacd *pDrv = pMacb->pGmacd;
	Gmac *pHw = pDrv->pHw;

	uint32_t  retryMax;
	uint32_t  value = 0;
	uint8_t rc;
	uint8_t phyAddress;
	uint8_t cnt;

	TRACE_DEBUG("GMACB_FindValidPhy\n\r");

	GMAC_EnableMdio(pHw);
	phyAddress = pMacb->phyAddress;
	retryMax = pMacb->retryMax;

	/* Check current phyAddress */
	rc = phyAddress;

	if (GMACB_ReadPhy(pHw, phyAddress, GMII_PHYID1R, &value, retryMax) == 0)
		TRACE_ERROR("GMACB PROBLEM\n\r");

	TRACE_DEBUG("_PHYID1  : 0x%X, addr: %d\n\r", value, phyAddress);

	/* Find another one */
	if (value != GMII_OUI_MSB) {
		rc = 0xFF;

		for (cnt = 0; cnt < 32; cnt ++) {
			phyAddress = (phyAddress + 1) & 0x1F;

			if (GMACB_ReadPhy(pHw, phyAddress, GMII_PHYID1R, &value, retryMax)
				 == 0)
				TRACE_ERROR("MACB PROBLEM\n\r");

			TRACE_DEBUG("_PHYID1  : 0x%X, addr: %d\n\r", value, phyAddress);

			if (value == GMII_OUI_MSB) {

				rc = phyAddress;
				break;
			}
		}
	}

	if (rc != 0xFF) {
		TRACE_INFO("** Valid PHY Found: %d\n\r", rc);
		GMACB_ReadPhy(pHw, phyAddress, GMII_PHYID1R, &value, retryMax);
		TRACE_DEBUG("_PHYID1R  : 0x%X, addr: %d\n\r", value, phyAddress);
		GMACB_ReadPhy(pHw, phyAddress, GMII_PHYID2R, &value, retryMax);
		TRACE_DEBUG("_EMSR  : 0x%X, addr: %d\n\r", value, phyAddress);
	}

	GMAC_DisableMdio(pHw);
	return rc;
}
/**
 * \brief Dump all the useful registers.
 * \param pMacb          Pointer to the MACB instance
 */
void GMACB_DumpRegisters(GMacb *pMacb)
{
	sGmacd *pDrv = pMacb->pGmacd;
	Gmac *pHw = pDrv->pHw;

	uint8_t phyAddress;
	uint32_t retryMax;
	uint32_t value;

	TRACE_INFO("GMACB_DumpRegisters\n\r");

	GMAC_EnableMdio(pHw);
	phyAddress = pMacb->phyAddress;
	retryMax = pMacb->retryMax;

	TRACE_INFO("GMII MACB @ %d) Registers:\n\r", phyAddress);

	GMACB_ReadPhy(pHw, phyAddress, GMII_BMCR, &value, retryMax);
	TRACE_INFO(" _BMCR     : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_BMSR, &value, retryMax);
	TRACE_INFO(" _BMSR     : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_PHYID1R, &value, retryMax);
	TRACE_INFO(" _PHYID1     : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_PHYID2R, &value, retryMax);
	TRACE_INFO(" _PHYID2     : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_ANAR, &value, retryMax);
	TRACE_INFO(" _ANAR     : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_ANLPAR, &value, retryMax);
	TRACE_INFO(" _ANLPAR   : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_ANER, &value, retryMax);
	TRACE_INFO(" _ANER     : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_ANNPR, &value, retryMax);
	TRACE_INFO(" _ANNPR    : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_ANLPNPAR, &value, retryMax);
	TRACE_INFO(" _ANLPNPAR : 0x%X\n\r", (unsigned)value);

	TRACE_INFO(" \n\r");

	GMACB_ReadPhy(pHw, phyAddress, GMII_RXERCR, &value, retryMax);
	TRACE_INFO(" _RXERCR   : 0x%X\n\r", (unsigned)value);
	GMACB_ReadPhy(pHw, phyAddress, GMII_ICSR, &value, retryMax);
	TRACE_INFO(" _ICSR     : 0x%X\n\r", (unsigned)value);
	TRACE_INFO(" \n\r");

	GMAC_DisableMdio(pHw);
}
Exemple #5
0
/**
 * \brief Dump all the useful registers.
 * \param pMacb          Pointer to the MACB instance
 */
void GMACB_DumpRegisters(GMacb *pMacb)
{
    sGmacd *pDrv = pMacb->pGmacd;
    Gmac *pHw = pDrv->pHw;

    uint8_t phyAddress;
    uint32_t retryMax;
    uint32_t value;

    TRACE_INFO("GMACB_DumpRegisters\n\r");

    GMAC_EnableMdio(pHw);
    phyAddress = pMacb->phyAddress;
    retryMax = pMacb->retryMax;

    TRACE_INFO("GMII MACB @%d) Registers:\n\r", phyAddress);

    GMACB_ReadPhy(pHw, phyAddress, GMII_BMCR, &value, retryMax);
    TRACE_INFO(" _BMCR     : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_BMSR, &value, retryMax);
    TRACE_INFO(" _BMSR     : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ANAR, &value, retryMax);
    TRACE_INFO(" _ANAR     : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ANLPAR, &value, retryMax);
    TRACE_INFO(" _ANLPAR   : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ANER, &value, retryMax);
    TRACE_INFO(" _ANER     : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ANNPR, &value, retryMax);
    TRACE_INFO(" _ANNPR    : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ANLPNPAR, &value, retryMax);
    TRACE_INFO(" _ANLPNPAR : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_1000BTCR, &value, retryMax);
    TRACE_INFO(" _1000BTCR : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_1000BTSR, &value, retryMax);
    TRACE_INFO(" _1000BTSR : 0x%X\n\r", value);
  
    GMACB_ReadPhy(pHw, phyAddress, GMII_EMSR, &value, retryMax);
    TRACE_INFO(" _EMSR     : 0x%X\n\r", value);
    TRACE_INFO(" \n\r");
    
    GMACB_ReadPhy(pHw, phyAddress, GMII_RLLMR, &value, retryMax);
    TRACE_INFO(" _RLLMR    : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_LMDCDR, &value, retryMax);
    TRACE_INFO(" _LMDCDR   : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_DPPSR, &value, retryMax);
    TRACE_INFO(" _DPPSR    : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_RXERCR, &value, retryMax);
    TRACE_INFO(" _RXERCR   : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ICSR, &value, retryMax);
    TRACE_INFO(" _ICSR     : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_DDC1R, &value, retryMax);
    TRACE_INFO(" _DDC1R    : 0x%X\n\r", value);
    GMACB_ReadPhy(pHw, phyAddress, GMII_PHYCR, &value, retryMax);
    TRACE_INFO(" _PHYCR    : 0x%X\n\r", value);  
    TRACE_INFO(" \n\r");
   
    value = GMII_CCR;
    GMACB_WritePhy(pHw, phyAddress, GMII_ERCR, value, retryMax);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ERDRR, &value, retryMax);
    TRACE_INFO(" _CCR      : 0x%X\n\r", value);
    value = GMII_SSR;
    GMACB_WritePhy(pHw, phyAddress, GMII_ERCR, value, retryMax);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ERDRR, &value, retryMax);
    TRACE_INFO(" _SSR      : 0x%X\n\r", value);
    value = GMII_OMSOR;
    GMACB_WritePhy(pHw, phyAddress, GMII_ERCR, value, retryMax);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ERDRR, &value, retryMax);
    TRACE_INFO(" _OMSOR    : 0x%X\n\r", value);
    value = GMII_OMSSR;
    GMACB_WritePhy(pHw, phyAddress, GMII_ERCR, value, retryMax);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ERDRR, &value, retryMax);
    TRACE_INFO(" _OMSSR    : 0x%X\n\r", value);
    value = GMII_RCCPSR;
    GMACB_WritePhy(pHw, phyAddress, GMII_ERCR, value, retryMax);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ERDRR, &value, retryMax);
    TRACE_INFO(" _RCCPSR   : 0x%X\n\r", value);
    value = GMII_RRDPSR;
    GMACB_WritePhy(pHw, phyAddress, GMII_ERCR, value, retryMax);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ERDRR, &value, retryMax);
    TRACE_INFO(" _RCCPSR   : 0x%X\n\r", value);
    value = GMII_ATR;   
    GMACB_WritePhy(pHw, phyAddress, GMII_ERCR, value, retryMax);
    GMACB_ReadPhy(pHw, phyAddress, GMII_ERDRR, &value, retryMax);
    TRACE_INFO(" _ATR      : 0x%X\n\r", value);
    
    GMAC_DisableMdio(pHw);
}