This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 483afdb155d1ee067466767b9e4d3d645943d02e Author: Jari Nippula <[email protected]> AuthorDate: Fri Nov 6 15:40:11 2026 +0200 drivers/net/phy: rtl8201f and rtl8211f drivers - Add drivers for Realtek RTL8201F and RTL8211F - Make genphy_ functions public to reuse them in vendor drivers - PHY_INTERFACE_RMII_PHY_CLK_OUT phy_interface enum value to indicate that interface clock is provided by PHY - Allow (lower == NULL) in phy_connect for skipping notifications Assisted-by: ChatGPT:GPT-6.1 Signed-off-by: Jari Nippula <[email protected]> --- drivers/net/CMakeLists.txt | 8 +++ drivers/net/Kconfig | 12 ++++ drivers/net/Make.defs | 11 ++- drivers/net/phy/phy.h | 8 +++ drivers/net/phy/phy_core.c | 15 +++- drivers/net/phy/phy_device.c | 36 +++++++--- drivers/net/phy/phy_gen.c | 75 ++++++++++---------- drivers/net/phy/realtek/rtl8201f.c | 106 +++++++++++++++++++++++++++++ drivers/net/phy/realtek/rtl8201f.h | 47 +++++++++++++ drivers/net/phy/realtek/rtl8211f.c | 136 +++++++++++++++++++++++++++++++++++++ drivers/net/phy/realtek/rtl8211f.h | 49 +++++++++++++ include/nuttx/net/phy.h | 11 ++- include/nuttx/net/realtek_phy.h | 8 +++ 13 files changed, 474 insertions(+), 48 deletions(-) diff --git a/drivers/net/CMakeLists.txt b/drivers/net/CMakeLists.txt index 987aa730235..f864fd163de 100644 --- a/drivers/net/CMakeLists.txt +++ b/drivers/net/CMakeLists.txt @@ -133,6 +133,14 @@ if(CONFIG_NET) list(APPEND SRCS phy/phy_genc45.c) endif() + if(CONFIG_NET_PHY_REALTEK_RTL8201F) + list(APPEND SRCS phy/realtek/rtl8201f.c) + endif() + + if(CONFIG_NET_PHY_REALTEK_RTL8211F) + list(APPEND SRCS phy/realtek/rtl8211f.c) + endif() + if(CONFIG_NET_PHY_REALTEK_RTL8221B) list(APPEND SRCS phy/realtek/rtl8221b.c phy/realtek/rtl8221b_fw.c) endif() diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index e177275eaac..d65beb42eea 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -896,6 +896,18 @@ config NET_PHYLIB_MAX_PHYS comment "PHY Device Drivers" +config NET_PHY_REALTEK_RTL8201F + bool "Realtek RTL8201F 10/100Mbps PHY" + ---help--- + Support for the RTL8201F MII/RMII PHY, including RMII reference + clock direction configuration. + +config NET_PHY_REALTEK_RTL8211F + bool "Realtek RTL8211F Gigabit PHY" + ---help--- + Support for RTL8211F-VD and RTL8211F/FDI RGMII PHYs, including + the RGMII internal RX and TX delay modes. + config NET_PHY_REALTEK_RTL8221B bool "Realtek RTL8221B 2.5Gbps PHY" default n diff --git a/drivers/net/Make.defs b/drivers/net/Make.defs index 354dc836336..3c1a4b09a42 100644 --- a/drivers/net/Make.defs +++ b/drivers/net/Make.defs @@ -132,13 +132,22 @@ ifeq ($(CONFIG_NET_PHYLIB),y) CSRCS += phy_core.c phy_access.c phy_device.c CSRCS += phy_gen.c DEPPATH += --dep-path net/phy - VPATH += :net/phy + DEPPATH += --dep-path net/phy/realtek + VPATH += :net/phy:net/phy/realtek CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)drivers$(DELIM)net$(DELIM)phy ifeq ($(CONFIG_MDIO_CLAUSE_45),y) CSRCS += phy_genc45.c endif +ifeq ($(CONFIG_NET_PHY_REALTEK_RTL8201F),y) + CSRCS += rtl8201f.c +endif + +ifeq ($(CONFIG_NET_PHY_REALTEK_RTL8211F),y) + CSRCS += rtl8211f.c +endif + ifeq ($(CONFIG_NET_PHY_REALTEK_RTL8221B),y) CSRCS += rtl8221b.c rtl8221b_fw.c endif diff --git a/drivers/net/phy/phy.h b/drivers/net/phy/phy.h index 4675f1e46bf..0b85aa6e2d1 100644 --- a/drivers/net/phy/phy.h +++ b/drivers/net/phy/phy.h @@ -150,6 +150,14 @@ extern const struct phy_driver_s g_genphy_c45_driver; int phy_driver_register(FAR const struct phy_driver_s *drv); +/* Generic Clause 22 operations shared by vendor drivers. */ + +int genphy_config_init(FAR struct phy_device_s *phydev); +int genphy_config_aneg(FAR struct phy_device_s *phydev); +int genphy_read_status(FAR struct phy_device_s *phydev); +int genphy_config_power(FAR struct phy_device_s *phydev, bool enable); +int genphy_soft_reset(FAR struct phy_device_s *phydev); + /* PHY register utilities (phy_access.c). Internal to the phylib core and * the vendor PHY drivers under drivers/net/phy; not part of the public API. */ diff --git a/drivers/net/phy/phy_core.c b/drivers/net/phy/phy_core.c index a227209385d..3dea632e0a6 100644 --- a/drivers/net/phy/phy_core.c +++ b/drivers/net/phy/phy_core.c @@ -281,10 +281,11 @@ static void phy_work(FAR void *arg) * path takes d_lock before phydev->lock. The carrier notification is * synchronous, so calling it while holding phydev->lock would invert that * order and risk an AB-BA deadlock. Performing it here, after the - * unlock, avoids that. This mirrors phy_stop(). + * unlock, avoids that. Skip notification for MAC-managed carrier + * (lower == NULL). This mirrors phy_stop(). */ - if (newstate != oldstate) + if (lower != NULL && newstate != oldstate) { if (newstate == PHY_RUNNING) { @@ -529,6 +530,8 @@ static int phy_ethtool_set_link_settings( FAR const struct ethtool_link_settings *cmd) { uint32_t advertising; + uint32_t oldadvertising; + bool oldautoneg; int ret = OK; if (cmd->link_mode_masks_nwords != PHY_LINK_MODE_MASK_NWORDS) @@ -554,6 +557,8 @@ static int phy_ethtool_set_link_settings( return -EINVAL; } + oldadvertising = phydev->advertising; + oldautoneg = phydev->autoneg; phydev->advertising = advertising; phydev->autoneg = (cmd->autoneg == AUTONEG_ENABLE); @@ -564,6 +569,12 @@ static int phy_ethtool_set_link_settings( ret = phydev->drv->config_aneg(phydev); } + if (ret < 0) + { + phydev->advertising = oldadvertising; + phydev->autoneg = oldautoneg; + } + nxmutex_unlock(&phydev->lock); return ret; } diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 33cae33b5b6..9e3e6fa8acf 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -235,6 +235,17 @@ int phy_driver_register(FAR const struct phy_driver_s *drv) return ret; } + for (i = 0; i < CONFIG_NET_PHYLIB_MAX_DRIVERS; i++) + { + if (g_phy_drivers[i] == drv) + { + /* Phy driver already registered */ + + nxmutex_unlock(&g_phy_lock); + return OK; + } + } + /* Store the driver in the first free slot of the fixed-size table. */ for (i = 0; i < CONFIG_NET_PHYLIB_MAX_DRIVERS; i++) @@ -418,10 +429,10 @@ ssize_t phy_device_scan(FAR struct mdio_bus_s *bus, * * Input Parameters: * phydev - Pointer to the PHY device structure - * lower - Pointer to the network device lower half + * lower - Network lower half, or NULL for MAC-managed carrier * * Returned Value: - * OK on success; -EINVAL if arguments are NULL; + * OK on success; -EINVAL if phydev is NULL; * -EBUSY if the PHY is already attached. * ****************************************************************************/ @@ -431,21 +442,24 @@ int phy_connect(FAR struct phy_device_s *phydev, { int ret; - if (phydev == NULL || lower == NULL) + if (phydev == NULL) { return -EINVAL; } nxmutex_lock(&phydev->lock); - if (phydev->lower != NULL) + if (phydev->state != PHY_DOWN) { nxmutex_unlock(&phydev->lock); return -EBUSY; } phydev->lower = lower; - lower->phydev = phydev; + if (lower != NULL) + { + lower->phydev = phydev; + } /* Deassert the PHY hardware reset (release the RESET_N line) before * running config_init. The request is forwarded to the lower-half @@ -464,7 +478,11 @@ int phy_connect(FAR struct phy_device_s *phydev, if (ret < 0) { phydev->lower = NULL; - lower->phydev = NULL; + if (lower != NULL) + { + lower->phydev = NULL; + } + nxmutex_unlock(&phydev->lock); return ret; } @@ -472,7 +490,7 @@ int phy_connect(FAR struct phy_device_s *phydev, phydev->state = PHY_READY; ninfo("PHY connected: addr=%d -> %s\n", - phydev->mdio_addr, lower->netdev.d_ifname); + phydev->mdio_addr, lower != NULL ? lower->netdev.d_ifname : "MAC"); nxmutex_unlock(&phydev->lock); return OK; } @@ -558,7 +576,7 @@ int phy_disconnect(FAR struct phy_device_s *phydev) * it to free any discovered phydev it does not go on to phy_connect(), * otherwise the device and its table slot leak. * - * A connected PHY (lower != NULL) must be released with + * A connected PHY (state != PHY_DOWN) must be released with * phy_disconnect() instead, which stops the state machine first. * * Input Parameters: @@ -586,7 +604,7 @@ int phy_device_free(FAR struct phy_device_s *phydev) * handle. */ - if (phydev->lower != NULL) + if (phydev->state != PHY_DOWN) { nxmutex_unlock(&phydev->lock); return -EBUSY; diff --git a/drivers/net/phy/phy_gen.c b/drivers/net/phy/phy_gen.c index 9d3ac2f477a..259601b5c6f 100644 --- a/drivers/net/phy/phy_gen.c +++ b/drivers/net/phy/phy_gen.c @@ -27,6 +27,8 @@ #include <nuttx/config.h> #include <debug.h> +#include <errno.h> +#include <nuttx/arch.h> #include <nuttx/net/phy.h> #include <nuttx/net/mii.h> @@ -34,15 +36,6 @@ #include "phy.h" -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int genphy_config_init(FAR struct phy_device_s *phydev); -static int genphy_config_aneg(FAR struct phy_device_s *phydev); -static int genphy_read_status(FAR struct phy_device_s *phydev); -static int genphy_config_power(FAR struct phy_device_s *phydev, bool enable); - /**************************************************************************** * Public Data ****************************************************************************/ @@ -57,7 +50,7 @@ const struct phy_driver_s g_genphy_driver = }; /**************************************************************************** - * Private Functions + * Public Functions ****************************************************************************/ /**************************************************************************** @@ -74,7 +67,7 @@ const struct phy_driver_s g_genphy_driver = * ****************************************************************************/ -static int genphy_config_init(FAR struct phy_device_s *phydev) +int genphy_config_init(FAR struct phy_device_s *phydev) { int msr; int estatus; @@ -116,17 +109,19 @@ static int genphy_config_init(FAR struct phy_device_s *phydev) if (msr & MII_MSR_ESTATEN) { estatus = phy_read(phydev, MII_ESTATUS); - if (estatus >= 0) + if (estatus < 0) { - if (estatus & MII_ESTATUS_1000BASETHALF) - { - supported |= SUPPORTED_1000BASET_HALF; - } - - if (estatus & MII_ESTATUS_1000BASETFULL) - { - supported |= SUPPORTED_1000BASET_FULL; - } + return estatus; + } + + if (estatus & MII_ESTATUS_1000BASETHALF) + { + supported |= SUPPORTED_1000BASET_HALF; + } + + if (estatus & MII_ESTATUS_1000BASETFULL) + { + supported |= SUPPORTED_1000BASET_FULL; } } @@ -152,12 +147,17 @@ static int genphy_config_init(FAR struct phy_device_s *phydev) * ****************************************************************************/ -static int genphy_config_aneg(FAR struct phy_device_s *phydev) +int genphy_config_aneg(FAR struct phy_device_s *phydev) { uint16_t adv = MII_ADVERTISE_CSMA; uint16_t msctrl = 0; int ret; + if (!phydev->autoneg) + { + return -EOPNOTSUPP; + } + /* Build ADVERTISE register value from advertising bitmask */ if (phydev->advertising & SUPPORTED_10BASET_HALF) @@ -229,7 +229,7 @@ static int genphy_config_aneg(FAR struct phy_device_s *phydev) * ****************************************************************************/ -static int genphy_read_status(FAR struct phy_device_s *phydev) +int genphy_read_status(FAR struct phy_device_s *phydev) { int msr; int lpa; @@ -251,6 +251,10 @@ static int genphy_read_status(FAR struct phy_device_s *phydev) } phydev->link = !!(msr & MII_MSR_LINKSTATUS); + if (phydev->autoneg && (msr & MII_MSR_ANEGCOMPLETE) == 0) + { + phydev->link = false; + } if (!phydev->link) { @@ -294,17 +298,19 @@ static int genphy_read_status(FAR struct phy_device_s *phydev) SUPPORTED_1000BASET_FULL)) { msstatus = phy_read(phydev, MII_MSSTATUS); - if (msstatus >= 0) + if (msstatus < 0) + { + return msstatus; + } + + if (msstatus & MII_MSSTATUS_LP1000BASETHALF) + { + phydev->lp_advertising |= SUPPORTED_1000BASET_HALF; + } + + if (msstatus & MII_MSSTATUS_LP1000BASETFULL) { - if (msstatus & MII_MSSTATUS_LP1000BASETHALF) - { - phydev->lp_advertising |= SUPPORTED_1000BASET_HALF; - } - - if (msstatus & MII_MSSTATUS_LP1000BASETFULL) - { - phydev->lp_advertising |= SUPPORTED_1000BASET_FULL; - } + phydev->lp_advertising |= SUPPORTED_1000BASET_FULL; } } @@ -344,6 +350,7 @@ static int genphy_read_status(FAR struct phy_device_s *phydev) } else { + phydev->link = false; phydev->speed = 0; phydev->duplex = DUPLEX_UNKNOWN; } @@ -366,7 +373,7 @@ static int genphy_read_status(FAR struct phy_device_s *phydev) * ****************************************************************************/ -static int genphy_config_power(FAR struct phy_device_s *phydev, bool enable) +int genphy_config_power(FAR struct phy_device_s *phydev, bool enable) { return enable ? phy_clear_bits(phydev, MII_MCR, MII_MCR_PDOWN) : phy_set_bits(phydev, MII_MCR, MII_MCR_PDOWN); diff --git a/drivers/net/phy/realtek/rtl8201f.c b/drivers/net/phy/realtek/rtl8201f.c new file mode 100644 index 00000000000..0c828d54f43 --- /dev/null +++ b/drivers/net/phy/realtek/rtl8201f.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * drivers/net/phy/realtek/rtl8201f.c + * + * SPDX-License-Identifier: Apache-2.0 + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <errno.h> +#include <nuttx/net/realtek_phy.h> + +#include "phy.h" +#include "rtl8201f.h" + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int rtl8201f_config_init(FAR struct phy_device_s *phydev); +static int rtl8201f_read_page(FAR struct phy_device_s *phydev); +static int rtl8201f_write_page(FAR struct phy_device_s *phydev, int page); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct phy_driver_s g_rtl8201f_driver = +{ + .name = "Realtek RTL8201F", + .phy_id = RTL8201F_PHY_ID, + .phy_id_mask = RTL8201F_PHY_ID_MASK, + .config_init = rtl8201f_config_init, + .config_aneg = genphy_config_aneg, + .read_status = genphy_read_status, + .config_power = genphy_config_power, + .read_page = rtl8201f_read_page, + .write_page = rtl8201f_write_page, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int rtl8201f_read_page(FAR struct phy_device_s *phydev) +{ + uint16_t page; + int ret; + + ret = mdio_read_nolock(phydev->bus, phydev->mdio_addr, + RTL8201F_PAGE_SELECT, &page); + return ret < 0 ? ret : page; +} + +static int rtl8201f_write_page(FAR struct phy_device_s *phydev, int page) +{ + return mdio_write_nolock(phydev->bus, phydev->mdio_addr, + RTL8201F_PAGE_SELECT, page); +} + +static int rtl8201f_config_init(FAR struct phy_device_s *phydev) +{ + uint16_t mode = 0; + int ret; + + switch (phydev->interface) + { + case PHY_INTERFACE_MII: + break; + + case PHY_INTERFACE_RMII: + mode = RTL8201F_RMII_SEL | RTL8201F_REF_CLK_IN; + break; + + case PHY_INTERFACE_RMII_PHY_CLK_OUT: + mode = RTL8201F_RMII_SEL; + break; + + default: + return -EOPNOTSUPP; + } + + ret = phy_write(phydev, RTL8201F_PAGE_SELECT, RTL8201F_DEFAULT_PAGE); + if (ret < 0) + { + return ret; + } + + /* Preserve oscillator configuration, reserved bits and RMII timing. */ + + ret = phy_modify_paged(phydev, RTL8201F_RMII_PAGE, RTL8201F_RMII_MODE, + RTL8201F_RMII_SEL | RTL8201F_REF_CLK_IN, mode); + return ret < 0 ? ret : genphy_config_init(phydev); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int rtl8201f_register(void) +{ + return phy_driver_register(&g_rtl8201f_driver); +} diff --git a/drivers/net/phy/realtek/rtl8201f.h b/drivers/net/phy/realtek/rtl8201f.h new file mode 100644 index 00000000000..1b272af3de2 --- /dev/null +++ b/drivers/net/phy/realtek/rtl8201f.h @@ -0,0 +1,47 @@ +/**************************************************************************** + * drivers/net/phy/realtek/rtl8201f.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __DRIVERS_NET_PHY_REALTEK_RTL8201F_H +#define __DRIVERS_NET_PHY_REALTEK_RTL8201F_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* PHY ID (revision ignored when matching) */ + +#define RTL8201F_PHY_ID 0x001cc816 +#define RTL8201F_PHY_ID_MASK 0xfffffff0 + +/* Register pages and page selector */ + +#define RTL8201F_DEFAULT_PAGE 0 +#define RTL8201F_RMII_PAGE 7 +#define RTL8201F_PAGE_SELECT 0x1f + +/* RMII mode setting register (page 7) */ + +#define RTL8201F_RMII_MODE 0x10 +#define RTL8201F_RMII_SEL (1 << 3) +#define RTL8201F_REF_CLK_IN (1 << 12) + +#endif /* __DRIVERS_NET_PHY_REALTEK_RTL8201F_H */ diff --git a/drivers/net/phy/realtek/rtl8211f.c b/drivers/net/phy/realtek/rtl8211f.c new file mode 100644 index 00000000000..128a6cba9b2 --- /dev/null +++ b/drivers/net/phy/realtek/rtl8211f.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * drivers/net/phy/realtek/rtl8211f.c + * + * SPDX-License-Identifier: Apache-2.0 + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <errno.h> +#include <nuttx/net/realtek_phy.h> + +#include "phy.h" +#include "rtl8211f.h" + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int rtl8211f_config_init(FAR struct phy_device_s *phydev); +static int rtl8211f_read_page(FAR struct phy_device_s *phydev); +static int rtl8211f_write_page(FAR struct phy_device_s *phydev, int page); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct phy_driver_s g_rtl8211f_drivers[] = +{ + { + .name = "Realtek RTL8211F-VD", + .phy_id = RTL8211F_VD_PHY_ID, + .phy_id_mask = RTL8211F_PHY_ID_MASK, + .config_init = rtl8211f_config_init, + .config_aneg = genphy_config_aneg, + .read_status = genphy_read_status, + .config_power = genphy_config_power, + .read_page = rtl8211f_read_page, + .write_page = rtl8211f_write_page, + }, + { + .name = "Realtek RTL8211F", + .phy_id = RTL8211F_PHY_ID, + .phy_id_mask = RTL8211F_PHY_ID_MASK, + .config_init = rtl8211f_config_init, + .config_aneg = genphy_config_aneg, + .read_status = genphy_read_status, + .config_power = genphy_config_power, + .read_page = rtl8211f_read_page, + .write_page = rtl8211f_write_page, + } +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int rtl8211f_read_page(FAR struct phy_device_s *phydev) +{ + uint16_t page; + int ret; + + ret = mdio_read_nolock(phydev->bus, phydev->mdio_addr, + RTL8211F_PAGE_SELECT, &page); + return ret < 0 ? ret : page; +} + +static int rtl8211f_write_page(FAR struct phy_device_s *phydev, int page) +{ + return mdio_write_nolock(phydev->bus, phydev->mdio_addr, + RTL8211F_PAGE_SELECT, page); +} + +static int rtl8211f_config_init(FAR struct phy_device_s *phydev) +{ + uint16_t txdelay = 0; + uint16_t rxdelay = 0; + int ret; + + switch (phydev->interface) + { + case PHY_INTERFACE_RGMII_ID: + txdelay = RTL8211F_TX_DELAY; + rxdelay = RTL8211F_RX_DELAY; + break; + + case PHY_INTERFACE_RGMII_TXID: + txdelay = RTL8211F_TX_DELAY; + break; + + case PHY_INTERFACE_RGMII_RXID: + rxdelay = RTL8211F_RX_DELAY; + break; + + case PHY_INTERFACE_RGMII: + break; + + default: + return -EOPNOTSUPP; + } + + ret = phy_modify_paged(phydev, RTL8211F_DELAY_PAGE, + RTL8211F_TX_DELAY_CTRL, + RTL8211F_TX_DELAY, txdelay); + if (ret < 0) + { + return ret; + } + + ret = phy_modify_paged(phydev, RTL8211F_DELAY_PAGE, + RTL8211F_RX_DELAY_CTRL, + RTL8211F_RX_DELAY, rxdelay); + if (ret < 0) + { + return ret; + } + + ret = phy_write(phydev, RTL8211F_PAGE_SELECT, RTL8211F_DEFAULT_PAGE); + + return ret < 0 ? ret : genphy_config_init(phydev); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int rtl8211f_register(void) +{ + int ret; + + ret = phy_driver_register(&g_rtl8211f_drivers[0]); + return ret < 0 ? ret : phy_driver_register(&g_rtl8211f_drivers[1]); +} diff --git a/drivers/net/phy/realtek/rtl8211f.h b/drivers/net/phy/realtek/rtl8211f.h new file mode 100644 index 00000000000..20154ecf336 --- /dev/null +++ b/drivers/net/phy/realtek/rtl8211f.h @@ -0,0 +1,49 @@ +/**************************************************************************** + * drivers/net/phy/realtek/rtl8211f.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __DRIVERS_NET_PHY_REALTEK_RTL8211F_H +#define __DRIVERS_NET_PHY_REALTEK_RTL8211F_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* PHY IDs (revision ignored when matching) */ + +#define RTL8211F_VD_PHY_ID 0x001cc878 +#define RTL8211F_PHY_ID 0x001cc916 +#define RTL8211F_PHY_ID_MASK 0xfffffff0 + +/* Register pages and page selector */ + +#define RTL8211F_DEFAULT_PAGE 0 +#define RTL8211F_DELAY_PAGE 0x0d08 +#define RTL8211F_PAGE_SELECT 0x1f + +/* RGMII delay controls (page 0xd08) */ + +#define RTL8211F_TX_DELAY_CTRL 0x11 +#define RTL8211F_RX_DELAY_CTRL 0x15 +#define RTL8211F_TX_DELAY (1 << 8) +#define RTL8211F_RX_DELAY (1 << 3) + +#endif /* __DRIVERS_NET_PHY_REALTEK_RTL8211F_H */ diff --git a/include/nuttx/net/phy.h b/include/nuttx/net/phy.h index 1c20e7c6713..76de810c77e 100644 --- a/include/nuttx/net/phy.h +++ b/include/nuttx/net/phy.h @@ -94,13 +94,16 @@ enum phy_state_e PHY_ERROR }; -/* PHY interface modes */ +/* PHY interface modes. RMII uses a reference clock supplied to the PHY; + * RMII_PHY_CLK_OUT uses a reference clock supplied by the PHY. + */ enum phy_interface_e { PHY_INTERFACE_MII = 0, PHY_INTERFACE_GMII, PHY_INTERFACE_RMII, + PHY_INTERFACE_RMII_PHY_CLK_OUT, PHY_INTERFACE_RGMII, PHY_INTERFACE_RGMII_ID, PHY_INTERFACE_RGMII_TXID, @@ -279,7 +282,11 @@ int phy_device_free(FAR struct phy_device_s *phydev); ssize_t phy_device_scan(FAR struct mdio_bus_s *bus, FAR struct phy_device_s **devs, size_t maxdevs); -/* PHY connect/disconnect */ +/* PHY connect/disconnect. lower may be NULL for a PHY whose MAC manages + * carrier itself (for example, an external switch port). Such callers + * consume link state under phydev->lock and must use phy_disconnect() + * rather than phy_device_free() after a successful connection. + */ int phy_connect(FAR struct phy_device_s *phydev, FAR struct netdev_lowerhalf_s *lower); diff --git a/include/nuttx/net/realtek_phy.h b/include/nuttx/net/realtek_phy.h index f36a4c6412d..3158d04e5ea 100644 --- a/include/nuttx/net/realtek_phy.h +++ b/include/nuttx/net/realtek_phy.h @@ -38,6 +38,14 @@ extern "C" { #endif +#ifdef CONFIG_NET_PHY_REALTEK_RTL8201F +int rtl8201f_register(void); +#endif + +#ifdef CONFIG_NET_PHY_REALTEK_RTL8211F +int rtl8211f_register(void); +#endif + /**************************************************************************** * Name: rtl8221b_register *
