From 8853e725023817d1ecee7d2c4c1d68047b44c1de Mon Sep 17 00:00:00 2001 From: Simon Filgis Date: Sun, 17 Sep 2023 15:14:52 +0200 Subject: [PATCH] add phy bordinit functionality on boardlevel one can do reset, cable-check, diagnostics, check link quality and more on every link up --- arch/arm/src/samv7/sam_emac.c | 24 ++++++++++++++++++++++++ arch/arm/src/samv7/sam_ethernet.h | 9 +++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/arch/arm/src/samv7/sam_emac.c b/arch/arm/src/samv7/sam_emac.c index c470f530f2..9a8fe99c9e 100644 --- a/arch/arm/src/samv7/sam_emac.c +++ b/arch/arm/src/samv7/sam_emac.c @@ -4022,6 +4022,30 @@ static int sam_phyinit(struct sam_emac_s *priv) regval |= EMAC_NCFGR_CLK_DIV8; /* MCK divided by 8 (MCK up to 20 MHz) */ } +#ifdef CONFIG_SAMV7_EMAC0_PHYINIT + if (priv->attr->emac == EMAC0_INTF) + { + ret = sam_phy_boardinitialize(0); + if (ret < 0) + { + nerr("ERROR: Failed to initialize the PHY: %d\n", ret); + return ret; + } + } +#endif + +#ifdef CONFIG_SAMV7_EMAC1_PHYINIT + if (priv->attr->emac == EMAC1_INTF) + { + ret = sam_phy_boardinitialize(1); + if (ret < 0) + { + nerr("ERROR: Failed to initialize the PHY: %d\n", ret); + return ret; + } + } +#endif + sam_putreg(priv, SAM_EMAC_NCFGR_OFFSET, regval); /* Check the PHY Address */ diff --git a/arch/arm/src/samv7/sam_ethernet.h b/arch/arm/src/samv7/sam_ethernet.h index 29c7b6efd7..829e5b04aa 100644 --- a/arch/arm/src/samv7/sam_ethernet.h +++ b/arch/arm/src/samv7/sam_ethernet.h @@ -227,13 +227,14 @@ int sam_emac_setmacaddr(int intf, uint8_t mac[6]); * Description: * Some boards require specialized initialization of the PHY before it can * be used. This may include such things as configuring GPIOs, resetting - * the PHY, etc. If CONFIG_SAMV7_PHYINIT is defined in the configuration - * then the board specific logic must provide sam_phyinitialize(); + * the PHY, etc. If CONFIG_SAMV7_EMAC0_PHYINIT or + * CONFIG_SAMV7_EMAC1_PHYINIT is defined in the configuration then the + * board specific logic must provide sam_phyinitialize(); * The SAMV7 Ethernet driver will call this function one time before it * first uses the PHY. * * Input Parameters: - * intf - Always zero for now. + * intf - 0 for EMAC0 and 1 for EMAC1. * * Returned Value: * OK on success; Negated errno on failure. @@ -242,7 +243,7 @@ int sam_emac_setmacaddr(int intf, uint8_t mac[6]); * ****************************************************************************/ -#ifdef CONFIG_SAMV7_PHYINIT +#if defined(CONFIG_SAMV7_EMAC0_PHYINIT) | defined(CONFIG_SAMV7_EMAC1_PHYINIT) int sam_phy_boardinitialize(int intf); #endif