/**
 * Initialize the LAN8720 PHY.
 * 
 * This function initialises the LAN8720 PHY. It will block until complete. This
 * function is called as part of the EMAC driver Initialisation. Configuration
 * of the PHY at startup is controlled by setting up configuration defines in
 * lpc_emac_config.h.
 *
 * \param [in]     netif   NETIF structure
 * \return         ERR_OK if the setup was successful, otherwise ERR_TIMEOUT
 */
err_t lpc_phy_init(struct netif *netif) {
  u32_t tmp = 2, tmp1;
  s32_t i;

  /**
   * Set these to 2 so there will always be a change and lpc_update_phy_sts does
   * something the first time its called
   */
  olddphysts.phy_speed_100mbs = tmp;
  olddphysts.phy_full_duplex = tmp;
  olddphysts.phy_link_active = tmp;
  phyustate = 0;

  /* Only first read and write are checked for failure */
  /* Put the LAN8720 in reset mode and wait for completion */
  if (lpc_mii_write(LAN8_BCR_REG, LAN8_RESET) != 0)
    return ERR_TIMEOUT;
  i = 400;
  while (i > 0) {
    msDelay(1);   /* 1 ms */
    if (lpc_mii_read(LAN8_BCR_REG, &tmp) != 0)
      return ERR_TIMEOUT;

    if (!(tmp & (LAN8_RESET | LAN8_POWER_DOWN)))
      i = -1;
    else
      i--;
  }
  /* Timeout? */
  if (i == 0)
    return ERR_TIMEOUT;

  /* Setup link based on configuration options */
#if PHY_USE_AUTONEG==1
  tmp = LAN8_AUTONEG;
#else
  tmp = 0;
#endif
#if PHY_USE_100MBS==1
  tmp |= LAN8_SPEED_SELECT;
#endif
#if PHY_USE_FULL_DUPLEX==1
  tmp |= LAN8_DUPLEX_MODE;
#endif
  lpc_mii_write(LAN8_BCR_REG, tmp);

  /**
   * No point in waiting around for the link to go active if the cable is
   * unplugged, so set the current link status and exit.
   */
  lpc_mii_read(LAN8_BSR_REG, &tmp);
  lpc_mii_read(LAN8_PHYSPLCTL_REG, &tmp1);
  lpc_update_phy_sts(netif, tmp, tmp1);

  return ERR_OK;
}
/** \brief  Initialize the DP83848 PHY.
 *
 *  This function initializes the DP83848 PHY. It will block until
 *  complete. This function is called as part of the EMAC driver
 *  initialization. Configuration of the PHY at startup is
 *  controlled by setting up configuration defines in lpc_phy.h.
 *
 *  \param[in]     netif   NETIF structure
 *  \param[in]     rmii    If set, configures the PHY for RMII mode
 *  \return         ERR_OK if the setup was successful, otherwise ERR_TIMEOUT
 */
err_t lpc_phy_init(struct netif *netif, int rmii)
{
    u32_t tmp;
    s32_t i;

    physts.phy_speed_100mbs = olddphysts.phy_speed_100mbs = 2;
    physts.phy_full_duplex = olddphysts.phy_full_duplex = 2;
    physts.phy_link_active = olddphysts.phy_link_active = 2;
    phyustate = 0;

    /* Only first read and write are checked for failure */
    /* Put the DP83848C in reset mode and wait for completion */
    if (lpc_mii_write(DP8_BMCR_REG, DP8_RESET) != 0)
        return ERR_TIMEOUT;
    i = 400;
    while (i > 0) {
        osDelay(1);   /* 1 ms */
        if (lpc_mii_read(DP8_BMCR_REG, &tmp) != 0)
            return ERR_TIMEOUT;

        if (!(tmp & (DP8_RESET | DP8_POWER_DOWN)))
            i = -1;
        else
            i--;
    }
    /* Timeout? */
    if (i == 0)
        return ERR_TIMEOUT;

    /* Setup link based on configuration options */
#if PHY_USE_AUTONEG==1
    tmp = DP8_AUTONEG;
#else
    tmp = 0;
#endif
#if PHY_USE_100MBS==1
    tmp |= DP8_SPEED_SELECT;
#endif
#if PHY_USE_FULL_DUPLEX==1
    tmp |= DP8_DUPLEX_MODE;
#endif
    lpc_mii_write(DP8_BMCR_REG, tmp);

    /* Enable RMII mode for PHY */
    if (rmii)
        lpc_mii_write(DP8_PHY_RBR_REG, DP8_RBR_RMII_MODE);

    /* The link is not set active at this point, but will be detected
       later */

    return ERR_OK;
}
Пример #3
0
/* Initialize the SMSC 87x0 PHY */
uint32_t lpc_phy_init(bool rmii, p_msDelay_func_t pDelayMsFunc)
{
	uint16_t tmp;
	int32_t i;

	pDelayMs = pDelayMsFunc;

	/* Initial states for PHY status and state machine */
	olddphysts = physts = phyustate = 0;

	/* Only first read and write are checked for failure */
	/* Put the DP83848C in reset mode and wait for completion */
	if (lpc_mii_write(LAN8_BCR_REG, LAN8_RESET) != SUCCESS) {
		return ERROR;
	}
	i = 400;
	while (i > 0) {
		pDelayMs(1);
		if (lpc_mii_read(LAN8_BCR_REG, &tmp) != SUCCESS) {
			return ERROR;
		}

		if (!(tmp & (LAN8_RESET | LAN8_POWER_DOWN))) {
			i = -1;
		}
		else {
			i--;
		}
	}
	/* Timeout? */
	if (i == 0) {
		return ERROR;
	}

	/* Setup link */
	lpc_mii_write(LAN8_BCR_REG, LAN8_SPEED_SELECT | LAN8_AUTONEG | LAN8_RESTART_AUTONEG);

	/* The link is not set active at this point, but will be detected
	   later */

	return SUCCESS;
}
Пример #4
0
/* Initialize the DP83848 PHY */
uint32_t lpc_phy_init(bool rmii, p_msDelay_func_t pDelayMsFunc)
{
	uint16_t tmp;
	int32_t i;

	pDelayMs = pDelayMsFunc;

	/* Initial states for PHY status and state machine */
	olddphysts = physts = phyustate = 0;

	/* Only first read and write are checked for failure */
	/* Put the DP83848C in reset mode and wait for completion */
	if (lpc_mii_write(DP8_BMCR_REG, DP8_RESET) != SUCCESS) {
		return ERROR;
	}
	i = 400;
	while (i > 0) {
		pDelayMs(1);
		if (lpc_mii_read(DP8_BMCR_REG, &tmp) != SUCCESS) {
			return ERROR;
		}

		if (!(tmp & (DP8_RESET | DP8_POWER_DOWN))) {
			i = -1;
		}
		else {
			i--;
		}
	}
	/* Timeout? */
	if (i == 0) {
		return ERROR;
	}

#if 0
	/* Setup link based on configuration options */
#if PHY_USE_AUTONEG == 1
	tmp = DP8_AUTONEG;
#else
	tmp = 0;
#endif
#if PHY_USE_100MBS == 1
	tmp |= DP8_SPEED_SELECT;
#endif
#if PHY_USE_FULL_DUPLEX == 1
	tmp |= DP8_DUPLEX_MODE;
#endif

#else
	tmp = DP8_AUTONEG;
#endif

	lpc_mii_write(DP8_BMCR_REG, tmp);

	/* Enable RMII mode for PHY */
	if (rmii) {
		lpc_mii_write(DP8_PHY_RBR_REG, DP8_RBR_RMII_MODE);
	}

	/* The link is not set active at this point, but will be detected
	   later */

	return SUCCESS;
}