From 769e65ef8e9e5600c172b8579775164c201e532a Mon Sep 17 00:00:00 2001 From: Benjamin Tober Date: Thu, 20 Jun 2024 18:45:54 +0200 Subject: [PATCH] stm32h7: allow Ethernet MAC without PHY - In some cases, an operational Ethernet MAC may have no PHY, for example when the system has a direct RMII MAC-to-MAC link. - New config option STM32H7_NO_PHY - With this option, PHY-specific code in the ethernet driver is not built - This option is inherently incompatible with autonegotiation and speed and duplex settings must be compiled in --- arch/arm/src/stm32h7/Kconfig | 4 ++++ arch/arm/src/stm32h7/stm32_ethernet.c | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/arm/src/stm32h7/Kconfig b/arch/arm/src/stm32h7/Kconfig index 77a7ea1314..d7f8a6924a 100644 --- a/arch/arm/src/stm32h7/Kconfig +++ b/arch/arm/src/stm32h7/Kconfig @@ -5519,6 +5519,10 @@ config STM32H7_ETHMAC_REGDEBUG Enable very low-level register access debug. Depends on CONFIG_DEBUG_FEATURES. +config STM32H7_NO_PHY + bool "MAC has no PHY" + default n + endmenu # Ethernet MAC configuration if STM32H7_LTDC diff --git a/arch/arm/src/stm32h7/stm32_ethernet.c b/arch/arm/src/stm32h7/stm32_ethernet.c index 4815970a9f..7425c65525 100644 --- a/arch/arm/src/stm32h7/stm32_ethernet.c +++ b/arch/arm/src/stm32h7/stm32_ethernet.c @@ -748,7 +748,7 @@ static void stm32_rxdescinit(struct stm32_ethmac_s *priv, union stm32_desc_u *rxtable, uint8_t *rxbuffer); /* PHY Initialization */ - +#ifndef CONFIG_STM32H7_NO_PHY #if defined(CONFIG_NETDEV_PHY_IOCTL) && defined(CONFIG_ARCH_PHY_INTERRUPT) static int stm32_phyintenable(struct stm32_ethmac_s *priv); #endif @@ -763,6 +763,7 @@ static int stm32_phyinit(struct stm32_ethmac_s *priv); #ifdef CONFIG_STM32H7_ETHMAC_REGDEBUG static void stm32_phyregdump(void); #endif +#endif /* MAC/DMA Initialization */ @@ -2942,6 +2943,7 @@ static void stm32_rxdescinit(struct stm32_ethmac_s *priv, #ifdef CONFIG_NETDEV_PHY_IOCTL static int stm32_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { +#ifndef CONFIG_STM32H7_NO_PHY #ifdef CONFIG_ARCH_PHY_INTERRUPT struct stm32_ethmac_s *priv = (struct stm32_ethmac_s *)dev->d_private; #endif @@ -2999,9 +3001,13 @@ static int stm32_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) } return ret; +#else + return -EIO; +#endif } #endif /* CONFIG_NETDEV_PHY_IOCTL */ +#ifndef CONFIG_STM32H7_NO_PHY /**************************************************************************** * Function: stm32_phyintenable * @@ -3522,6 +3528,8 @@ static int stm32_phyinit(struct stm32_ethmac_s *priv) return OK; } +#endif + /**************************************************************************** * Name: stm32_selectmii * @@ -4091,6 +4099,19 @@ static int stm32_ethconfig(struct stm32_ethmac_s *priv) /* Initialize the PHY */ +#ifdef CONFIG_STM32H7_NO_PHY + ninfo("MAC without PHY\n"); +#ifdef CONFIG_STM32H7_ETHFD + priv->fduplex = 1; +#else + priv->fduplex = 0; +#endif +#ifdef CONFIG_STM32H7_ETH100MBPS + priv->mbps100 = 1; +#else + priv->mbps100 = 0; +#endif +#else ninfo("Initialize the PHY\n"); ret = stm32_phyinit(priv); if (ret < 0) @@ -4098,6 +4119,7 @@ static int stm32_ethconfig(struct stm32_ethmac_s *priv) return ret; } +#endif /* Initialize the MAC and DMA */ ninfo("Initialize the MAC and DMA\n");