Skip to content

Commit

Permalink
[BACKPORT] stm32h7: allow Ethernet MAC without PHY
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tober-auterion authored and niklaut committed Jun 21, 2024
1 parent 6fbb26e commit 05e1d30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions arch/arm/src/stm32h7/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5249,6 +5249,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

menu "QEncoder Driver"
Expand Down
24 changes: 23 additions & 1 deletion arch/arm/src/stm32h7/stm32_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,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
Expand All @@ -769,6 +769,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 */

Expand Down Expand Up @@ -2996,6 +2997,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
Expand Down Expand Up @@ -3053,9 +3055,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
*
Expand Down Expand Up @@ -3576,6 +3582,8 @@ static int stm32_phyinit(struct stm32_ethmac_s *priv)
return OK;
}

#endif

/****************************************************************************
* Name: stm32_selectmii
*
Expand Down Expand Up @@ -4222,13 +4230,27 @@ 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)
{
return ret;
}

#endif
/* Initialize the MAC and DMA */

ninfo("Initialize the MAC and DMA\n");
Expand Down

0 comments on commit 05e1d30

Please sign in to comment.