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 c51503ccb44d1d0eb1e5f084759edf21190514ec Author: zhangkai25 <[email protected]> AuthorDate: Tue Jul 28 09:45:13 2026 +0800 net/phy: add Realtek RTL8221B PHY driver Add the Realtek RTL8221B 2.5Gbps PHY vendor driver on top of the PHYLIB framework, including the firmware patch blob and the config_init / config_aneg / read_status / config_intr / handle_interrupt callbacks. Registered via phy_realtek_register() and matched by PHY ID. Built under CONFIG_NET_PHYLIB. Signed-off-by: zhangkai25 <[email protected]> --- drivers/net/CMakeLists.txt | 4 + drivers/net/Kconfig | 12 + drivers/net/Make.defs | 7 + drivers/net/phy/realtek/rtl8221b.c | 934 +++++++++++++++++++++++ drivers/net/phy/realtek/rtl8221b.h | 118 +++ drivers/net/phy/realtek/rtl8221b_fw.c | 1308 +++++++++++++++++++++++++++++++++ drivers/net/phy/realtek/rtl8221b_fw.h | 80 ++ include/nuttx/net/realtek_phy.h | 64 ++ 8 files changed, 2527 insertions(+) diff --git a/drivers/net/CMakeLists.txt b/drivers/net/CMakeLists.txt index 2faa773cf6d..8074a1f480b 100644 --- a/drivers/net/CMakeLists.txt +++ b/drivers/net/CMakeLists.txt @@ -132,6 +132,10 @@ if(CONFIG_NET) if(CONFIG_MDIO_CLAUSE_45) list(APPEND SRCS phy/phy_genc45.c) endif() + + if(CONFIG_NET_PHY_REALTEK_RTL8221B) + list(APPEND SRCS phy/realtek/rtl8221b.c phy/realtek/rtl8221b_fw.c) + endif() endif() target_sources(drivers PRIVATE ${SRCS}) diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index bccc09d533c..9a5766d9a0d 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -873,6 +873,18 @@ config NET_PHYLIB_MAX_PHYS Maximum number of PHY devices that can be tracked simultaneously. +comment "PHY Device Drivers" + +config NET_PHY_REALTEK_RTL8221B + bool "Realtek RTL8221B 2.5Gbps PHY" + default n + depends on MDIO_CLAUSE_45 + ---help--- + Support for the Realtek RTL8221B 2.5Gbps Ethernet PHY. Enable + only on boards that use an RTL8221B. Includes the firmware patch + (ramcode) blob, which consumes a few KB of flash, so leaving this + disabled keeps flash/RAM usage minimal on embedded targets. + endif # NET_PHYLIB endif # NETDEVICES diff --git a/drivers/net/Make.defs b/drivers/net/Make.defs index 7583985094f..2c7dcf53734 100644 --- a/drivers/net/Make.defs +++ b/drivers/net/Make.defs @@ -138,6 +138,13 @@ ifeq ($(CONFIG_NET_PHYLIB),y) ifeq ($(CONFIG_MDIO_CLAUSE_45),y) CSRCS += phy_genc45.c endif + +ifeq ($(CONFIG_NET_PHY_REALTEK_RTL8221B),y) + CSRCS += rtl8221b.c rtl8221b_fw.c +endif + + DEPPATH += --dep-path net/phy/realtek + VPATH += :net/phy/realtek endif # Include network build support diff --git a/drivers/net/phy/realtek/rtl8221b.c b/drivers/net/phy/realtek/rtl8221b.c new file mode 100644 index 00000000000..b62fa4abfe6 --- /dev/null +++ b/drivers/net/phy/realtek/rtl8221b.c @@ -0,0 +1,934 @@ +/**************************************************************************** + * drivers/net/phy/realtek/rtl8221b.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <errno.h> +#include <debug.h> +#include <inttypes.h> +#include <syslog.h> +#include <unistd.h> + +#include <nuttx/arch.h> +#include <nuttx/clock.h> +#include <nuttx/signal.h> +#include <nuttx/net/phy.h> +#include <nuttx/net/mii.h> +#include <nuttx/net/realtek_phy.h> +#include <nuttx/ethtool.h> + +#include "phy.h" +#include "rtl8221b.h" +#include "rtl8221b_fw.h" + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int rtl8221b_config_init(FAR struct phy_device_s *phydev); +static int rtl8221b_config_aneg(FAR struct phy_device_s *phydev); +static int rtl8221b_read_status(FAR struct phy_device_s *phydev); +static int rtl8221b_config_intr(FAR struct phy_device_s *phydev, + bool enable); +static int rtl8221b_handle_interrupt(FAR struct phy_device_s *phydev); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct phy_driver_s g_rtl8221b_driver = +{ + .name = "RTL8221B 2.5Gbps PHY", + .phy_id = RTL8221B_VB_CG_PHY_ID, + .phy_id_mask = RTL8221B_PHY_ID_MASK, + .config_init = rtl8221b_config_init, + .config_aneg = rtl8221b_config_aneg, + .read_status = rtl8221b_read_status, + .config_intr = rtl8221b_config_intr, + .handle_interrupt = rtl8221b_handle_interrupt, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtl8221b_write_ramcode + * + * Description: + * Write one firmware patch (ramcode) table to the PHY via MMD writes. + * + * Input Parameters: + * phydev - PHY device + * code - Ramcode table (MMD device/address/value triples) to write + * len - Number of entries in the ramcode table + * + * Returned Value: + * OK on success; a negated errno value on failure. + * + ****************************************************************************/ + +static int rtl8221b_write_ramcode(FAR struct phy_device_s *phydev, + FAR const struct rtl8221b_mmd_reg_s *code, + size_t len) +{ + size_t i; + int ret; + + for (i = 0; i < len; i++) + { + ret = phy_write_mmd(phydev, MII_MMD_VEND2, code[i].addr, + code[i].value); + if (ret < 0) + { + return ret; + } + } + + return OK; +} + +/**************************************************************************** + * Name: rtl8221b_apply_patch + * + * Description: + * Apply the RTL8221B firmware patch (NC0/NC1/NC2/UC2/UC ramcode plus the + * SDS patch and GPHY parameter tuning). Mirrors the vendor reference + * initialization sequence, expressed purely through Clause-45 MMD + * register access. + * + * Input Parameters: + * phydev - PHY device + * + * Returned Value: + * OK on success; a negated errno value on failure. + * + ****************************************************************************/ + +static int rtl8221b_apply_patch(FAR struct phy_device_s *phydev) +{ + int ret; + int val; + int timeout; + + /* Patch request: MMD31.0xb820[4] = 1 */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_CTRL, + RTL_VEND2_PATCH_REQ, RTL_VEND2_PATCH_REQ); + if (ret < 0) + { + return ret; + } + + /* Wait for patch ready: MMD31.0xb800[6] = 1 (bounded timeout) */ + + for (timeout = RTL_PATCH_READY_TIMEOUT_MS; timeout > 0; timeout--) + { + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_STATUS); + if (val < 0) + { + return val; + } + + if (val & RTL_VEND2_PATCH_RDY) + { + break; + } + + nxsig_usleep(USEC_PER_MSEC); + } + + if (timeout == 0) + { + nerr("ERROR: RTL8221B patch ready (set) timeout\n"); + return -ETIMEDOUT; + } + + /* Set patch_key & patch_lock */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xa436, 0x8024); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xa438, 0x3701); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xa436, 0xb82e); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xa438, 0x0001); + if (ret < 0) + { + return ret; + } + + /* Enable NC & UC patch: MMD31.0xb820[7] = 1 */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_CTRL, + RTL_VEND2_UCODE_EN, RTL_VEND2_UCODE_EN); + if (ret < 0) + { + return ret; + } + + /* Load NC ramcode banks */ + + ret = rtl8221b_write_ramcode(phydev, g_rtl8221b_n0_ramcode, + g_rtl8221b_n0_ramcode_len); + if (ret < 0) + { + return ret; + } + + ret = rtl8221b_write_ramcode(phydev, g_rtl8221b_n1_ramcode, + g_rtl8221b_n1_ramcode_len); + if (ret < 0) + { + return ret; + } + + ret = rtl8221b_write_ramcode(phydev, g_rtl8221b_n2_ramcode, + g_rtl8221b_n2_ramcode_len); + if (ret < 0) + { + return ret; + } + + ret = rtl8221b_write_ramcode(phydev, g_rtl8221b_uc2_ramcode, + g_rtl8221b_uc2_ramcode_len); + if (ret < 0) + { + return ret; + } + + /* Disable NC & UC patch: MMD31.0xb820[7] = 0 */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_CTRL, + RTL_VEND2_UCODE_EN, 0); + if (ret < 0) + { + return ret; + } + + /* Load UC ramcode bank */ + + ret = rtl8221b_write_ramcode(phydev, g_rtl8221b_uc_ramcode, + g_rtl8221b_uc_ramcode_len); + if (ret < 0) + { + return ret; + } + + /* GPHY OCP 0xb896[0] = 0 */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, 0xb896, 0x0001, 0); + if (ret < 0) + { + return ret; + } + + /* GPHY OCP 0xb892[15:8] = 0 */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xb892, 0x0000); + if (ret < 0) + { + return ret; + } + + /* GPHY OCP 0xb896[0] = 1 */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, 0xb896, 0x0001, 0x0001); + if (ret < 0) + { + return ret; + } + + /* Clear patch_key & patch_lock */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xa436, 0x0000); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xa438, 0x0000); + if (ret < 0) + { + return ret; + } + + /* MMD31.0xb82e[0] = 0 */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, 0xb82e, 0x0001, 0); + if (ret < 0) + { + return ret; + } + + /* Clear patch key address */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xa436, 0x8024); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, 0xa438, 0x0000); + if (ret < 0) + { + return ret; + } + + /* Release patch request: MMD31.0xb820[4] = 0 */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_CTRL, + RTL_VEND2_PATCH_REQ, 0); + if (ret < 0) + { + return ret; + } + + /* Wait for patch ready bit to clear: MMD31.0xb800[6] = 0 (bounded) */ + + for (timeout = RTL_PATCH_READY_TIMEOUT_MS; timeout > 0; timeout--) + { + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_STATUS); + if (val < 0) + { + return val; + } + + if (!(val & RTL_VEND2_PATCH_RDY)) + { + break; + } + + nxsig_usleep(USEC_PER_MSEC); + } + + if (timeout == 0) + { + nerr("ERROR: RTL8221B patch ready (clear) timeout\n"); + return -ETIMEDOUT; + } + + /* Apply GPHY tuning and OCP programming (all on VEND2). */ + + ret = rtl8221b_write_ramcode(phydev, g_rtl8221b_gphy_tuning, + g_rtl8221b_gphy_tuning_len); + if (ret < 0) + { + return ret; + } + + /* SDS patch (MMD30 / VEND1) */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, 0x75b5, 0xe086); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, 0x75b6, 0x0024); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, 0x75b1, 0x0013); + if (ret < 0) + { + return ret; + } + + /* Update patch version marker (VEND2) */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_REG_SEL, + RTL_VEND2_PATCH_VER_SEL); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_REG_DATA, + RTL_VEND2_PATCH_VERSION); + if (ret < 0) + { + return ret; + } + + /* PHY reset & restart Nway */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PHYRST_REG, + RTL_VEND2_PHYRST_NWAY); + if (ret < 0) + { + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: rtl8221b_config_serdes + * + * Description: + * Configure the RTL8221B SerDes interface toward the MAC as a fixed + * 2500BASE-X / SGMII link with auto-negotiation disabled, then wait for + * the SerDes link to come up. All accesses are pure Clause-45 MMD + * register operations (MMD30 / VEND1 and MMD31 / VEND2). + * + * Input Parameters: + * phydev - PHY device + * + * Returned Value: + * OK on success; a negated errno value on failure. + * + ****************************************************************************/ + +static int rtl8221b_config_serdes(FAR struct phy_device_s *phydev) +{ + int val; + int ret; + int waited; + + /* --- SerDes option set: 2500BASE-X + SGMII --- */ + + /* Clear MMD30.0x75f3[0] */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND1, RTL_VEND1_SDS_75F3, 0x0001, 0); + if (ret < 0) + { + return ret; + } + + /* Program SerDes mode select MMD30.0x697a[5:0] */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND1, RTL_VEND1_SDS_OPTION, + RTL_VEND1_SDS_MODE_MASK, + RTL_SDS_OPTION_2500BASEX_SGMII); + if (ret < 0) + { + return ret; + } + + /* 2500BASE-X specific SerDes tuning */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, RTL_VEND1_SDS_CTRL1, 0x0503); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, RTL_VEND1_SDS_6F10, 0xd455); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, RTL_VEND1_SDS_6F11, 0x8020); + if (ret < 0) + { + return ret; + } + + /* Toggle link state: set MMD31.0xa400[14] */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PHYRST_REG, + RTL_VEND2_LINK_CHG, RTL_VEND2_LINK_CHG); + if (ret < 0) + { + return ret; + } + + /* Wait for the SerDes link: MMD31.0xa434[2] (bounded timeout) */ + + for (waited = 0; waited < RTL_SDS_LINK_TIMEOUT_MS; waited += 10) + { + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PHYSR); + if (val < 0) + { + return val; + } + + if (val & RTL_PHYSR_LINK_RT) + { + break; + } + + nxsig_usleep(10 * USEC_PER_MSEC); + } + + if (waited >= RTL_SDS_LINK_TIMEOUT_MS) + { + nwarn("WARNING: RTL8221B SerDes link not up within %dms\n", + RTL_SDS_LINK_TIMEOUT_MS); + } + + /* Clear link-change bit: MMD31.0xa400[14] = 0 */ + + ret = phy_modify_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PHYRST_REG, + RTL_VEND2_LINK_CHG, 0); + if (ret < 0) + { + return ret; + } + + /* --- Disable SerDes auto-negotiation (fixed-speed link) --- */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, RTL_VEND1_SDS_ANEG_7588, + 0x0002); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, RTL_VEND1_SDS_ANEG_7589, + 0x71d0); + if (ret < 0) + { + return ret; + } + + ret = phy_write_mmd(phydev, MII_MMD_VEND1, RTL_VEND1_SDS_ANEG_7587, + 0x0003); + if (ret < 0) + { + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: rtl8221b_config_init + * + * Description: + * Initialize RTL8221B PHY: wait for the PHY to become ready, apply the + * firmware patch (ramcode) when the running patch version does not match, + * then advertise the supported capabilities. + * + * Input Parameters: + * phydev - PHY device + * + * Returned Value: + * OK on success; a negated errno value on failure. + * + ****************************************************************************/ + +static int rtl8221b_config_init(FAR struct phy_device_s *phydev) +{ + int timeout; + int val; + int ret; + + /* Wait until the PHY reports ready: MMD31.0xa420[1:0] == 0x3 */ + + for (timeout = RTL_PHY_READY_TIMEOUT_MS; timeout > 0; timeout--) + { + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PHY_READY_REG); + if (val < 0) + { + return val; + } + + if (val != 0xffff && (val & 0x3) == 0x3) + { + break; + } + + nxsig_usleep(USEC_PER_MSEC); + } + + if (timeout == 0) + { + nerr("ERROR: RTL8221B not ready\n"); + return -ETIMEDOUT; + } + + /* Check whether the firmware patch is already applied (idempotent): + * read the running patch version from OCP 0x801e. + */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_REG_SEL, + RTL_VEND2_PATCH_VER_SEL); + if (ret < 0) + { + return ret; + } + + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_REG_DATA); + if (val < 0) + { + return val; + } + + if (val != RTL_VEND2_PATCH_VERSION) + { + /* Patch not present or stale: apply it */ + + ret = rtl8221b_apply_patch(phydev); + if (ret < 0) + { + nerr("ERROR: RTL8221B patch failed: %d\n", ret); + return ret; + } + + /* Verify the patch version was written back */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_REG_SEL, + RTL_VEND2_PATCH_VER_SEL); + if (ret < 0) + { + return ret; + } + + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PATCH_REG_DATA); + if (val < 0) + { + return val; + } + + if (val != RTL_VEND2_PATCH_VERSION) + { + nerr("ERROR: RTL8221B patch verification failed (0x%04x)\n", val); + return -EIO; + } + } + + phydev->supported = SUPPORTED_10BASET_FULL | + SUPPORTED_100BASET_FULL | + SUPPORTED_1000BASET_FULL | + SUPPORTED_AUTONEG | + SUPPORTED_TP | + SUPPORTED_MII; + + phydev->advertising = phydev->supported; + + /* The PHY was (potentially) soft-reset at the end of the firmware patch, + * which clears any prior SerDes configuration. Re-arm the one-shot + * SerDes setup so it is (re)applied by read_status on the next link-up. + */ + + phydev->priv = NULL; + + /* NOTE: SerDes configuration toward the MAC is intentionally NOT done + * here. The SerDes "set option" sequence ends by toggling the link and + * waiting for the real-time link bit, which only asserts once the UTP + * link is established. Doing it at config_init time (UTP link not yet + * up) would stall and leave the SerDes data path unconfigured. Instead + * it is performed from read_status when link-up is first observed. + */ + + ninfo("RTL8221B config_init done: supported=0x%08" PRIx32 "\n", + phydev->supported); + return OK; +} + +/**************************************************************************** + * Name: rtl8221b_config_aneg + * + * Description: + * Enable and restart auto-negotiation on RTL8221B via MMD7. + * + * Input Parameters: + * phydev - PHY device + * + * Returned Value: + * OK on success; a negated errno value on failure. + * + ****************************************************************************/ + +static int rtl8221b_config_aneg(FAR struct phy_device_s *phydev) +{ + return phy_write_mmd(phydev, MII_MMD_AN, MII_MMD_AN_CTRL1, + MII_MMD_AN_CTRL1_ENABLE | MII_MMD_AN_CTRL1_RESTART); +} + +/**************************************************************************** + * Name: rtl8221b_read_status + * + * Description: + * Read link status and speed from RTL8221B vendor-specific registers. + * Uses MMD30 reg 0xa400 for link and MMD30 reg 0xa434 for speed. + * + * Input Parameters: + * phydev - PHY device + * + * Returned Value: + * OK on success; a negated errno value on failure. + * + ****************************************************************************/ + +static int rtl8221b_read_status(FAR struct phy_device_s *phydev) +{ + int val; + int speed_hi; + int speed_lo; + int ret; + + /* Read PHYSR (MMD31 reg 0xa434): contains real-time link, speed and + * duplex in a single register, so link/speed/duplex stay consistent. + */ + + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PHYSR); + if (val < 0) + { + return val; + } + + /* bit2: real-time link status (use this rather than FESR.2 which is a + * latched "link lost since last read" indication). + */ + + phydev->link = !!(val & RTL_PHYSR_LINK_RT); + + if (!phydev->link) + { + phydev->speed = 0; + phydev->duplex = DUPLEX_UNKNOWN; + + /* Do NOT re-arm the SerDes setup here. The SerDes configuration is + * persistent in the PHY registers and only needs to be applied once + * per config_init (which clears the flag). Re-arming on every + * link-down would cause the config_serdes link toggle to bounce the + * link, creating a perpetual up/down loop. + */ + + return OK; + } + + /* Link is up. Configure the host-side SerDes once per link-up session. + * This is deferred here (rather than config_init) because the SerDes + * "set option" sequence waits on the real-time link bit, which is only + * valid once the UTP link is established. + * + * No locking is needed around the SDS-done marker: read_status() for a + * given PHY is only ever invoked from the phylib state machine via the + * single state_work handle (the poll and interrupt paths are funnelled + * onto the same work), so calls for the same phydev are strictly + * serialized and never run concurrently. The marker is stored directly + * in phydev->priv as a boolean (NULL = not configured, non-NULL = SerDes + * already set up for this session), so distinct PHYs keep independent + * state, and rtl8221b_config_serdes() writes idempotent persistent PHY + * registers, so even a redundant call would be harmless. + */ + + if (phydev->priv == NULL) + { + ret = rtl8221b_config_serdes(phydev); + if (ret < 0) + { + nerr("ERROR: RTL8221B SerDes config failed: %d\n", ret); + return ret; + } + + phydev->priv = (FAR void *)1; + + /* Re-read PHYSR after SerDes (re)configuration to report a coherent + * speed/duplex below. + */ + + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_PHYSR); + if (val < 0) + { + return val; + } + } + + speed_hi = (val & RTL_PHYSR_SPEED_HI_MASK) >> RTL_PHYSR_SPEED_HI_SHIFT; + speed_lo = (val & RTL_PHYSR_SPEED_LO_MASK) >> RTL_PHYSR_SPEED_LO_SHIFT; + + /* PHYSR Speed_h(bit10:9) + Speed_l(bit5:4) per datasheet table: + * 00 00 -> 10M 00 01 -> 100M 00 10 -> 1000M + * 01 11 -> 2.5G Lite (1G data) 01 01 -> 2.5G + * other combinations are reserved. + */ + + switch (speed_hi) + { + case 0: + switch (speed_lo) + { + case 0: + phydev->speed = 10; + break; + case 1: + phydev->speed = 100; + break; + case 2: + phydev->speed = 1000; + break; + default: + phydev->speed = 0; + break; + } + break; + + case 1: + switch (speed_lo) + { + case 1: + phydev->speed = 2500; + break; + case 3: + phydev->speed = 2500; /* 2.5G lite */ + break; + default: + phydev->speed = 0; + break; + } + break; + + default: + phydev->speed = 0; + break; + } + + phydev->duplex = (val & RTL_PHYSR_DUPLEX) ? DUPLEX_FULL : DUPLEX_HALF; + + return OK; +} + +/**************************************************************************** + * Name: rtl8221b_config_intr + * + * Description: + * Enable or disable the RTL8221B PHY interrupt output (INTB). Programs + * the vendor interrupt-enable register (MMD31.0xa4d2) to assert INTB on + * link status changes. When disabling, the pending interrupt status is + * also cleared. + * + * Input Parameters: + * phydev - PHY device + * enable - true to enable link-change interrupts, false to disable + * + * Returned Value: + * OK on success; negated errno on failure. + * + ****************************************************************************/ + +static int rtl8221b_config_intr(FAR struct phy_device_s *phydev, bool enable) +{ + int ret; + + if (enable) + { + /* Clear any stale status first (read-to-clear), then enable the + * link-change interrupt source. The status read is a best-effort + * clear; its value is intentionally ignored. + */ + + phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_INSR_REG); + ret = phy_write_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_INER_REG, + RTL_VEND2_INTR_LINK_CHG); + } + else + { + /* Mask all interrupt sources, then clear any pending status. The + * trailing status read is a best-effort clear; its value is + * intentionally ignored. + */ + + ret = phy_write_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_INER_REG, 0); + phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_INSR_REG); + } + + return ret; +} + +/**************************************************************************** + * Name: rtl8221b_handle_interrupt + * + * Description: + * Handle a pending RTL8221B PHY interrupt. Reads (and thereby clears) the + * vendor interrupt status register (MMD31.0xa4d4), releasing the INTB + * line, and decodes the pending sources. The driver fully owns interrupt + * decode/ack. + * + * Input Parameters: + * phydev - PHY device + * + * Returned Value: + * >0 if a link-relevant event is pending (the phylib state machine then + * re-reads link status); + * 0 if no link-relevant event was pending; + * <0 (negated errno) on MDIO/HW failure (the state machine enters + * PHY_ERROR). + * + ****************************************************************************/ + +static int rtl8221b_handle_interrupt(FAR struct phy_device_s *phydev) +{ + int val; + + /* Reading INSR clears the status and de-asserts INTB. */ + + val = phy_read_mmd(phydev, MII_MMD_VEND2, RTL_VEND2_INSR_REG); + if (val < 0) + { + return val; + } + + /* Only the link-change source is enabled (see config_intr); report + * whether a link-relevant event is pending so the state machine re-reads + * link status. Any other (currently unused) sources are simply cleared + * by the read above. + */ + + return (val & RTL_VEND2_INTR_LINK_CHG) ? 1 : 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtl8221b_register + * + * Description: + * Register the RTL8221B PHY driver with the phylib framework. + * + * Input Parameters: + * None + * + * Returned Value: + * OK on success; a negated errno value on failure. + * + ****************************************************************************/ + +int rtl8221b_register(void) +{ + return phy_driver_register(&g_rtl8221b_driver); +} diff --git a/drivers/net/phy/realtek/rtl8221b.h b/drivers/net/phy/realtek/rtl8221b.h new file mode 100644 index 00000000000..f975fdbc6bb --- /dev/null +++ b/drivers/net/phy/realtek/rtl8221b.h @@ -0,0 +1,118 @@ +/**************************************************************************** + * drivers/net/phy/realtek/rtl8221b.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_RTL8221B_H +#define __DRIVERS_NET_PHY_REALTEK_RTL8221B_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/net/phy.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* PHY IDs */ + +#define RTL8221B_VB_CG_PHY_ID 0x001cc849 +#define RTL8221B_PHY_ID_MASK 0xfffffff0 + +/* Standard IEEE 802.3 Clause 45 MMD addresses are defined in + * <nuttx/net/mii.h> as MII_MMD_PMAPMD (1), MII_MMD_AN (7), + * MII_MMD_VEND1 (30) and MII_MMD_VEND2 (31); this driver uses those + * directly instead of redefining them here. + */ + +/* Vendor registers (MMD31) */ + +#define RTL_VEND2_PHYSR 0xa434 /* PHY specific status register */ + +/* PHYSR (MMD31.0xa434) field definitions */ + +#define RTL_PHYSR_LINK_RT (1 << 2) /* bit2: real-time link status */ +#define RTL_PHYSR_DUPLEX (1 << 3) /* bit3: 1=full, 0=half duplex */ +#define RTL_PHYSR_SPEED_HI_MASK 0x0600 /* bits[10:9] Speed_h */ +#define RTL_PHYSR_SPEED_HI_SHIFT 9 +#define RTL_PHYSR_SPEED_LO_MASK 0x0030 /* bits[5:4] Speed_l */ +#define RTL_PHYSR_SPEED_LO_SHIFT 4 + +/* Patch / init related vendor registers (MMD31) */ + +#define RTL_VEND2_PHY_READY_REG 0xa420 /* bit[1:0]==0x3 => PHY ready */ +#define RTL_VEND2_PATCH_REG_SEL 0xa436 /* OCP register selector */ +#define RTL_VEND2_PATCH_REG_DATA 0xa438 /* OCP register data */ +#define RTL_VEND2_PATCH_VER_SEL 0x801e /* selector for patch version */ +#define RTL_VEND2_PATCH_VERSION 0x0020 /* expected driver patch version */ +#define RTL_VEND2_PATCH_CTRL 0xb820 /* patch request/ucode control */ +#define RTL_VEND2_PATCH_STATUS 0xb800 /* patch ready status */ +#define RTL_VEND2_PATCH_REQ 0x0010 /* B820 bit4: patch request */ +#define RTL_VEND2_PATCH_RDY 0x0040 /* B800 bit6: patch ready */ +#define RTL_VEND2_UCODE_EN 0x0080 /* B820 bit7: NC/UC ucode enable */ + +/* PHY reset / restart auto-negotiation (MMD31.0xa400) */ + +#define RTL_VEND2_PHYRST_REG 0xa400 +#define RTL_VEND2_PHYRST_NWAY 0x9200 /* PHY reset + restart Nway */ +#define RTL_VEND2_LINK_CHG 0x4000 /* A400 bit14: change link state */ + +/* PHY interrupt registers (MMD31 / VEND2) */ + +#define RTL_VEND2_INER_REG 0xa4d2 /* Interrupt enable register */ +#define RTL_VEND2_INSR_REG 0xa4d4 /* Interrupt status (read-clr) */ +#define RTL_VEND2_INTR_LINK_CHG (1 << 2) /* bit2: link status change */ + +/* SerDes registers (MMD30 / VEND1) and option codes */ + +#define RTL_VEND1_SDS_OPTION 0x697a /* SerDes mode select [5:0] */ +#define RTL_VEND1_SDS_MODE_MASK 0x3f +#define RTL_VEND1_SDS_75F3 0x75f3 +#define RTL_VEND1_SDS_CTRL1 0x6a04 +#define RTL_VEND1_SDS_6F10 0x6f10 +#define RTL_VEND1_SDS_6F11 0x6f11 +#define RTL_VEND1_SDS_ANEG_7587 0x7587 +#define RTL_VEND1_SDS_ANEG_7588 0x7588 +#define RTL_VEND1_SDS_ANEG_7589 0x7589 +#define RTL_VEND1_SDS_CTRL3 0x7580 /* SerDes mode status [4:0] */ +#define RTL_VEND1_SDS_CTRL7 0x758b /* SerDes valid status */ +#define RTL_VEND1_SDS_CTRL9 0x758d /* SerDes link status */ + +/* SerDes option code written into 0x697a[5:0]: + * 0 = 2500BASE-X + SGMII (fixed, no auto-negotiation), per vendor enum. + */ + +#define RTL_SDS_OPTION_2500BASEX_SGMII 0x00 + +/* SerDes link poll timeout (ms) when waiting for the PHY<->MAC link */ + +#define RTL_SDS_LINK_TIMEOUT_MS 10000 + +/* Timeout for PHY-ready polling (in 1ms iterations) */ + +#define RTL_PHY_READY_TIMEOUT_MS 5000 + +/* Timeout for patch request/ready handshake polling (in 1ms iterations) */ + +#define RTL_PATCH_READY_TIMEOUT_MS 1000 + +#endif /* __DRIVERS_NET_PHY_REALTEK_RTL8221B_H */ diff --git a/drivers/net/phy/realtek/rtl8221b_fw.c b/drivers/net/phy/realtek/rtl8221b_fw.c new file mode 100644 index 00000000000..213159ce0d9 --- /dev/null +++ b/drivers/net/phy/realtek/rtl8221b_fw.c @@ -0,0 +1,1308 @@ +/**************************************************************************** + * drivers/net/phy/realtek/rtl8221b_fw.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "rtl8221b_fw.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* RTL8221B NC0 patch ramcode */ + +const struct rtl8221b_mmd_reg_s g_rtl8221b_n0_ramcode[] = +{ + { 0xa436, 0xa016, }, + { 0xa438, 0x0000, }, + { 0xa436, 0xa012, }, + { 0xa438, 0x0000, }, + { 0xa436, 0xa014, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x8010, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x801a, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x803f, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x8045, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x8067, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x806d, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x8079, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x807e, }, + { 0xa438, 0xd093, }, + { 0xa438, 0xd1c4, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x135c, }, + { 0xa438, 0xd704, }, + { 0xa438, 0x5fbc, }, + { 0xa438, 0xd504, }, + { 0xa438, 0xc9f1, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x0fc9, }, + { 0xa438, 0xbb50, }, + { 0xa438, 0xd505, }, + { 0xa438, 0xa202, }, + { 0xa438, 0xd504, }, + { 0xa438, 0x8c0f, }, + { 0xa438, 0xd500, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x1519, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x135c, }, + { 0xa438, 0xd75e, }, + { 0xa438, 0x5fae, }, + { 0xa438, 0x9b50, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x135c, }, + { 0xa438, 0xd75e, }, + { 0xa438, 0x7fae, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x135c, }, + { 0xa438, 0xd707, }, + { 0xa438, 0x40a7, }, + { 0xa438, 0xd719, }, + { 0xa438, 0x4071, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x1557, }, + { 0xa438, 0xd719, }, + { 0xa438, 0x2f70, }, + { 0xa438, 0x803b, }, + { 0xa438, 0x2f73, }, + { 0xa438, 0x156a, }, + { 0xa438, 0x5e70, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x155d, }, + { 0xa438, 0xd505, }, + { 0xa438, 0xa202, }, + { 0xa438, 0xd500, }, + { 0xa438, 0xffed, }, + { 0xa438, 0xd709, }, + { 0xa438, 0x4054, }, + { 0xa438, 0xa788, }, + { 0xa438, 0xd70b, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x172a, }, + { 0xa438, 0xc0c1, }, + { 0xa438, 0xc0c0, }, + { 0xa438, 0xd05a, }, + { 0xa438, 0xd1ba, }, + { 0xa438, 0xd701, }, + { 0xa438, 0x2529, }, + { 0xa438, 0x022a, }, + { 0xa438, 0xd0a7, }, + { 0xa438, 0xd1b9, }, + { 0xa438, 0xa208, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x080e, }, + { 0xa438, 0xd701, }, + { 0xa438, 0x408b, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x0a65, }, + { 0xa438, 0xf003, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x0a6b, }, + { 0xa438, 0xd701, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x0920, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x0915, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x0909, }, + { 0xa438, 0x228f, }, + { 0xa438, 0x804e, }, + { 0xa438, 0x9801, }, + { 0xa438, 0xd71e, }, + { 0xa438, 0x5d61, }, + { 0xa438, 0xd701, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x022a, }, + { 0xa438, 0x2005, }, + { 0xa438, 0x091a, }, + { 0xa438, 0x3bd9, }, + { 0xa438, 0x0919, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x0916, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x14c5, }, + { 0xa438, 0xd703, }, + { 0xa438, 0x3181, }, + { 0xa438, 0x8077, }, + { 0xa438, 0x60ad, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x135c, }, + { 0xa438, 0xd703, }, + { 0xa438, 0x5fba, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x0cc7, }, + { 0xa438, 0xd096, }, + { 0xa438, 0xd1a9, }, + { 0xa438, 0xd503, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x0c94, }, + { 0xa438, 0xa802, }, + { 0xa438, 0xa301, }, + { 0xa438, 0xa801, }, + { 0xa438, 0xc004, }, + { 0xa438, 0xd710, }, + { 0xa438, 0x4000, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x1e79, }, + { 0xa436, 0xa026, }, + { 0xa438, 0x1e78, }, + { 0xa436, 0xa024, }, + { 0xa438, 0x0c93, }, + { 0xa436, 0xa022, }, + { 0xa438, 0x0cc5, }, + { 0xa436, 0xa020, }, + { 0xa438, 0x0915, }, + { 0xa436, 0xa006, }, + { 0xa438, 0x020a, }, + { 0xa436, 0xa004, }, + { 0xa438, 0x1726, }, + { 0xa436, 0xa002, }, + { 0xa438, 0x1542, }, + { 0xa436, 0xa000, }, + { 0xa438, 0x0fc7, }, + { 0xa436, 0xa008, }, + { 0xa438, 0xff00, }, +}; + +const size_t g_rtl8221b_n0_ramcode_len = + sizeof(g_rtl8221b_n0_ramcode) / sizeof(g_rtl8221b_n0_ramcode[0]); + +/* RTL8221B NC1 patch ramcode */ + +const struct rtl8221b_mmd_reg_s g_rtl8221b_n1_ramcode[] = +{ + { 0xa436, 0xa016, }, + { 0xa438, 0x0010, }, + { 0xa436, 0xa012, }, + { 0xa438, 0x0000, }, + { 0xa436, 0xa014, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x8010, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x801d, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x802c, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x802c, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x802c, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x802c, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x802c, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x802c, }, + { 0xa438, 0xd700, }, + { 0xa438, 0x6090, }, + { 0xa438, 0x60d1, }, + { 0xa438, 0xc95c, }, + { 0xa438, 0xf007, }, + { 0xa438, 0x60b1, }, + { 0xa438, 0xc95a, }, + { 0xa438, 0xf004, }, + { 0xa438, 0xc956, }, + { 0xa438, 0xf002, }, + { 0xa438, 0xc94e, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x00cd, }, + { 0xa438, 0xd700, }, + { 0xa438, 0x6090, }, + { 0xa438, 0x60d1, }, + { 0xa438, 0xc95c, }, + { 0xa438, 0xf007, }, + { 0xa438, 0x60b1, }, + { 0xa438, 0xc95a, }, + { 0xa438, 0xf004, }, + { 0xa438, 0xc956, }, + { 0xa438, 0xf002, }, + { 0xa438, 0xc94e, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x022a, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x0132, }, + { 0xa436, 0xa08e, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa08c, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa08a, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa088, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa086, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa084, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa082, }, + { 0xa438, 0x012f, }, + { 0xa436, 0xa080, }, + { 0xa438, 0x00cc, }, + { 0xa436, 0xa090, }, + { 0xa438, 0x0103, }, +}; + +const size_t g_rtl8221b_n1_ramcode_len = + sizeof(g_rtl8221b_n1_ramcode) / sizeof(g_rtl8221b_n1_ramcode[0]); + +/* RTL8221B NC2 patch ramcode */ + +const struct rtl8221b_mmd_reg_s g_rtl8221b_n2_ramcode[] = +{ + { 0xa436, 0xa016, }, + { 0xa438, 0x0020, }, + { 0xa436, 0xa012, }, + { 0xa438, 0x0000, }, + { 0xa436, 0xa014, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x8010, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x8020, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x802a, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x8035, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x803c, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x803c, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x803c, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x803c, }, + { 0xa438, 0xd107, }, + { 0xa438, 0xd042, }, + { 0xa438, 0xa404, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x09df, }, + { 0xa438, 0xd700, }, + { 0xa438, 0x5fb4, }, + { 0xa438, 0x8280, }, + { 0xa438, 0xd700, }, + { 0xa438, 0x6065, }, + { 0xa438, 0xd125, }, + { 0xa438, 0xf002, }, + { 0xa438, 0xd12b, }, + { 0xa438, 0xd040, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x077f, }, + { 0xa438, 0x0cf0, }, + { 0xa438, 0x0c50, }, + { 0xa438, 0xd104, }, + { 0xa438, 0xd040, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x0aa8, }, + { 0xa438, 0xd700, }, + { 0xa438, 0x5fb4, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x0a2e, }, + { 0xa438, 0xcb9b, }, + { 0xa438, 0xd110, }, + { 0xa438, 0xd040, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x0b7b, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x09df, }, + { 0xa438, 0xd700, }, + { 0xa438, 0x5fb4, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x081b, }, + { 0xa438, 0x1000, }, + { 0xa438, 0x09df, }, + { 0xa438, 0xd704, }, + { 0xa438, 0x7fb8, }, + { 0xa438, 0xa718, }, + { 0xa438, 0x1800, }, + { 0xa438, 0x074e, }, + { 0xa436, 0xa10e, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa10c, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa10a, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa108, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xa106, }, + { 0xa438, 0x074d, }, + { 0xa436, 0xa104, }, + { 0xa438, 0x0818, }, + { 0xa436, 0xa102, }, + { 0xa438, 0x0a2c, }, + { 0xa436, 0xa100, }, + { 0xa438, 0x077e, }, + { 0xa436, 0xa110, }, + { 0xa438, 0x000f, }, +}; + +const size_t g_rtl8221b_n2_ramcode_len = + sizeof(g_rtl8221b_n2_ramcode) / sizeof(g_rtl8221b_n2_ramcode[0]); + +/* RTL8221B UC patch ramcode */ + +const struct rtl8221b_mmd_reg_s g_rtl8221b_uc_ramcode[] = +{ + { 0xa436, 0x846e, }, + { 0xa438, 0xaf84, }, + { 0xa438, 0x86af, }, + { 0xa438, 0x8690, }, + { 0xa438, 0xaf86, }, + { 0xa438, 0xa4af, }, + { 0xa438, 0x86a4, }, + { 0xa438, 0xaf86, }, + { 0xa438, 0xa4af, }, + { 0xa438, 0x86a4, }, + { 0xa438, 0xaf86, }, + { 0xa438, 0xa4af, }, + { 0xa438, 0x86a4, }, + { 0xa438, 0xee82, }, + { 0xa438, 0x5f00, }, + { 0xa438, 0x0284, }, + { 0xa438, 0x90af, }, + { 0xa438, 0x0441, }, + { 0xa438, 0xf8e0, }, + { 0xa438, 0x8ff3, }, + { 0xa438, 0xa000, }, + { 0xa438, 0x0502, }, + { 0xa438, 0x84a4, }, + { 0xa438, 0xae06, }, + { 0xa438, 0xa001, }, + { 0xa438, 0x0302, }, + { 0xa438, 0x84c8, }, + { 0xa438, 0xfc04, }, + { 0xa438, 0xf8f9, }, + { 0xa438, 0xef59, }, + { 0xa438, 0xe080, }, + { 0xa438, 0x15ad, }, + { 0xa438, 0x2702, }, + { 0xa438, 0xae03, }, + { 0xa438, 0xaf84, }, + { 0xa438, 0xc3bf, }, + { 0xa438, 0x53ca, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8ad, }, + { 0xa438, 0x2807, }, + { 0xa438, 0x0285, }, + { 0xa438, 0x2cee, }, + { 0xa438, 0x8ff3, }, + { 0xa438, 0x01ef, }, + { 0xa438, 0x95fd, }, + { 0xa438, 0xfc04, }, + { 0xa438, 0xf8f9, }, + { 0xa438, 0xfaef, }, + { 0xa438, 0x69bf, }, + { 0xa438, 0x53ca, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8ac, }, + { 0xa438, 0x2822, }, + { 0xa438, 0xd480, }, + { 0xa438, 0x00bf, }, + { 0xa438, 0x8684, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9bf, }, + { 0xa438, 0x8687, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9bf, }, + { 0xa438, 0x868a, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9bf, }, + { 0xa438, 0x868d, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9ee, }, + { 0xa438, 0x8ff3, }, + { 0xa438, 0x00af, }, + { 0xa438, 0x8526, }, + { 0xa438, 0xe08f, }, + { 0xa438, 0xf4e1, }, + { 0xa438, 0x8ff5, }, + { 0xa438, 0xe28f, }, + { 0xa438, 0xf6e3, }, + { 0xa438, 0x8ff7, }, + { 0xa438, 0x1b45, }, + { 0xa438, 0xac27, }, + { 0xa438, 0x0eee, }, + { 0xa438, 0x8ff4, }, + { 0xa438, 0x00ee, }, + { 0xa438, 0x8ff5, }, + { 0xa438, 0x0002, }, + { 0xa438, 0x852c, }, + { 0xa438, 0xaf85, }, + { 0xa438, 0x26e0, }, + { 0xa438, 0x8ff4, }, + { 0xa438, 0xe18f, }, + { 0xa438, 0xf52c, }, + { 0xa438, 0x0001, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xf4e5, }, + { 0xa438, 0x8ff5, }, + { 0xa438, 0xef96, }, + { 0xa438, 0xfefd, }, + { 0xa438, 0xfc04, }, + { 0xa438, 0xf8f9, }, + { 0xa438, 0xef59, }, + { 0xa438, 0xbf53, }, + { 0xa438, 0x2202, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xa18b, }, + { 0xa438, 0x02ae, }, + { 0xa438, 0x03af, }, + { 0xa438, 0x85da, }, + { 0xa438, 0xbf57, }, + { 0xa438, 0x7202, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xf8e5, }, + { 0xa438, 0x8ff9, }, + { 0xa438, 0xbf57, }, + { 0xa438, 0x7502, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xfae5, }, + { 0xa438, 0x8ffb, }, + { 0xa438, 0xbf57, }, + { 0xa438, 0x7802, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xfce5, }, + { 0xa438, 0x8ffd, }, + { 0xa438, 0xbf57, }, + { 0xa438, 0x7b02, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xfee5, }, + { 0xa438, 0x8fff, }, + { 0xa438, 0xbf57, }, + { 0xa438, 0x6c02, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xa102, }, + { 0xa438, 0x13ee, }, + { 0xa438, 0x8ffc, }, + { 0xa438, 0x80ee, }, + { 0xa438, 0x8ffd, }, + { 0xa438, 0x00ee, }, + { 0xa438, 0x8ffe, }, + { 0xa438, 0x80ee, }, + { 0xa438, 0x8fff, }, + { 0xa438, 0x00af, }, + { 0xa438, 0x8599, }, + { 0xa438, 0xa101, }, + { 0xa438, 0x0cbf, }, + { 0xa438, 0x534c, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8a1, }, + { 0xa438, 0x0303, }, + { 0xa438, 0xaf85, }, + { 0xa438, 0x77bf, }, + { 0xa438, 0x5322, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8a1, }, + { 0xa438, 0x8b02, }, + { 0xa438, 0xae03, }, + { 0xa438, 0xaf86, }, + { 0xa438, 0x64e0, }, + { 0xa438, 0x8ff8, }, + { 0xa438, 0xe18f, }, + { 0xa438, 0xf9bf, }, + { 0xa438, 0x8684, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9e0, }, + { 0xa438, 0x8ffa, }, + { 0xa438, 0xe18f, }, + { 0xa438, 0xfbbf, }, + { 0xa438, 0x8687, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9e0, }, + { 0xa438, 0x8ffc, }, + { 0xa438, 0xe18f, }, + { 0xa438, 0xfdbf, }, + { 0xa438, 0x868a, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9e0, }, + { 0xa438, 0x8ffe, }, + { 0xa438, 0xe18f, }, + { 0xa438, 0xffbf, }, + { 0xa438, 0x868d, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9af, }, + { 0xa438, 0x867f, }, + { 0xa438, 0xbf53, }, + { 0xa438, 0x2202, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xa144, }, + { 0xa438, 0x3cbf, }, + { 0xa438, 0x547b, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8e4, }, + { 0xa438, 0x8ff8, }, + { 0xa438, 0xe58f, }, + { 0xa438, 0xf9bf, }, + { 0xa438, 0x547e, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8e4, }, + { 0xa438, 0x8ffa, }, + { 0xa438, 0xe58f, }, + { 0xa438, 0xfbbf, }, + { 0xa438, 0x5481, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8e4, }, + { 0xa438, 0x8ffc, }, + { 0xa438, 0xe58f, }, + { 0xa438, 0xfdbf, }, + { 0xa438, 0x5484, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8e4, }, + { 0xa438, 0x8ffe, }, + { 0xa438, 0xe58f, }, + { 0xa438, 0xffbf, }, + { 0xa438, 0x5322, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8a1, }, + { 0xa438, 0x4448, }, + { 0xa438, 0xaf85, }, + { 0xa438, 0xa7bf, }, + { 0xa438, 0x5322, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xc8a1, }, + { 0xa438, 0x313c, }, + { 0xa438, 0xbf54, }, + { 0xa438, 0x7b02, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xf8e5, }, + { 0xa438, 0x8ff9, }, + { 0xa438, 0xbf54, }, + { 0xa438, 0x7e02, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xfae5, }, + { 0xa438, 0x8ffb, }, + { 0xa438, 0xbf54, }, + { 0xa438, 0x8102, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xfce5, }, + { 0xa438, 0x8ffd, }, + { 0xa438, 0xbf54, }, + { 0xa438, 0x8402, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xe48f, }, + { 0xa438, 0xfee5, }, + { 0xa438, 0x8fff, }, + { 0xa438, 0xbf53, }, + { 0xa438, 0x2202, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xa131, }, + { 0xa438, 0x03af, }, + { 0xa438, 0x85a7, }, + { 0xa438, 0xd480, }, + { 0xa438, 0x00bf, }, + { 0xa438, 0x8684, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9bf, }, + { 0xa438, 0x8687, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9bf, }, + { 0xa438, 0x868a, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9bf, }, + { 0xa438, 0x868d, }, + { 0xa438, 0x0252, }, + { 0xa438, 0xa9ef, }, + { 0xa438, 0x95fd, }, + { 0xa438, 0xfc04, }, + { 0xa438, 0xf0d1, }, + { 0xa438, 0x2af0, }, + { 0xa438, 0xd12c, }, + { 0xa438, 0xf0d1, }, + { 0xa438, 0x44f0, }, + { 0xa438, 0xd146, }, + { 0xa438, 0xbf86, }, + { 0xa438, 0xa102, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xbf86, }, + { 0xa438, 0xa102, }, + { 0xa438, 0x52c8, }, + { 0xa438, 0xd101, }, + { 0xa438, 0xaf06, }, + { 0xa438, 0xa570, }, + { 0xa438, 0xce42, }, + { 0xa436, 0xb818, }, + { 0xa438, 0x043d, }, + { 0xa436, 0xb81a, }, + { 0xa438, 0x06a3, }, + { 0xa436, 0xb81c, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb81e, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb850, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb852, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb878, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb884, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb832, }, + { 0xa438, 0x0003, }, +}; + +const size_t g_rtl8221b_uc_ramcode_len = + sizeof(g_rtl8221b_uc_ramcode) / sizeof(g_rtl8221b_uc_ramcode[0]); + +/* RTL8221B UC2 patch ramcode */ + +const struct rtl8221b_mmd_reg_s g_rtl8221b_uc2_ramcode[] = +{ + { 0xa436, 0xb87c, }, + { 0xa438, 0x8625, }, + { 0xa436, 0xb87e, }, + { 0xa438, 0xaf86, }, + { 0xa438, 0x3daf, }, + { 0xa438, 0x8689, }, + { 0xa438, 0xaf88, }, + { 0xa438, 0x69af, }, + { 0xa438, 0x8887, }, + { 0xa438, 0xaf88, }, + { 0xa438, 0x9caf, }, + { 0xa438, 0x889c, }, + { 0xa438, 0xaf88, }, + { 0xa438, 0x9caf, }, + { 0xa438, 0x889c, }, + { 0xa438, 0xbf86, }, + { 0xa438, 0x49d7, }, + { 0xa438, 0x0040, }, + { 0xa438, 0x0277, }, + { 0xa438, 0x7daf, }, + { 0xa438, 0x2727, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7205, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7208, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x71f3, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x71f6, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7229, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x722c, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7217, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x721a, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x721d, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7211, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7220, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7214, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x722f, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7223, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7232, }, + { 0xa438, 0x0000, }, + { 0xa438, 0x7226, }, + { 0xa438, 0xf8f9, }, + { 0xa438, 0xfae0, }, + { 0xa438, 0x85b3, }, + { 0xa438, 0x3802, }, + { 0xa438, 0xad27, }, + { 0xa438, 0x02ae, }, + { 0xa438, 0x03af, }, + { 0xa438, 0x8830, }, + { 0xa438, 0x1f66, }, + { 0xa438, 0xef65, }, + { 0xa438, 0xbfc2, }, + { 0xa438, 0x1f1a, }, + { 0xa438, 0x96f7, }, + { 0xa438, 0x05ee, }, + { 0xa438, 0xffd2, }, + { 0xa438, 0x00da, }, + { 0xa438, 0xf605, }, + { 0xa438, 0xbfc2, }, + { 0xa438, 0x2f1a, }, + { 0xa438, 0x96f7, }, + { 0xa438, 0x05ee, }, + { 0xa438, 0xffd2, }, + { 0xa438, 0x00db, }, + { 0xa438, 0xf605, }, + { 0xa438, 0xef02, }, + { 0xa438, 0x1f11, }, + { 0xa438, 0x0d42, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x4202, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xef02, }, + { 0xa438, 0x1b03, }, + { 0xa438, 0x1f11, }, + { 0xa438, 0x0d42, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x4502, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xef02, }, + { 0xa438, 0x1a03, }, + { 0xa438, 0x1f11, }, + { 0xa438, 0x0d42, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x4802, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xbfc2, }, + { 0xa438, 0x3f1a, }, + { 0xa438, 0x96f7, }, + { 0xa438, 0x05ee, }, + { 0xa438, 0xffd2, }, + { 0xa438, 0x00da, }, + { 0xa438, 0xf605, }, + { 0xa438, 0xbfc2, }, + { 0xa438, 0x4f1a, }, + { 0xa438, 0x96f7, }, + { 0xa438, 0x05ee, }, + { 0xa438, 0xffd2, }, + { 0xa438, 0x00db, }, + { 0xa438, 0xf605, }, + { 0xa438, 0xef02, }, + { 0xa438, 0x1f11, }, + { 0xa438, 0x0d42, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x4b02, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xef02, }, + { 0xa438, 0x1b03, }, + { 0xa438, 0x1f11, }, + { 0xa438, 0x0d42, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x4e02, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xef02, }, + { 0xa438, 0x1a03, }, + { 0xa438, 0x1f11, }, + { 0xa438, 0x0d42, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x5102, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xef56, }, + { 0xa438, 0xd020, }, + { 0xa438, 0x1f11, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x5402, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x5702, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x5a02, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xe185, }, + { 0xa438, 0xa0ef, }, + { 0xa438, 0x0348, }, + { 0xa438, 0x0a28, }, + { 0xa438, 0x05ef, }, + { 0xa438, 0x201b, }, + { 0xa438, 0x01ad, }, + { 0xa438, 0x2735, }, + { 0xa438, 0x1f44, }, + { 0xa438, 0xe085, }, + { 0xa438, 0x88e1, }, + { 0xa438, 0x8589, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x5d02, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xe085, }, + { 0xa438, 0x8ee1, }, + { 0xa438, 0x858f, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x6002, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xe085, }, + { 0xa438, 0x94e1, }, + { 0xa438, 0x8595, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x6302, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xe085, }, + { 0xa438, 0x9ae1, }, + { 0xa438, 0x859b, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x6602, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xaf88, }, + { 0xa438, 0x3cbf, }, + { 0xa438, 0x883f, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x9cad, }, + { 0xa438, 0x2835, }, + { 0xa438, 0x1f44, }, + { 0xa438, 0xe08f, }, + { 0xa438, 0xf8e1, }, + { 0xa438, 0x8ff9, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x5d02, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xe08f, }, + { 0xa438, 0xfae1, }, + { 0xa438, 0x8ffb, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x6002, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xe08f, }, + { 0xa438, 0xfce1, }, + { 0xa438, 0x8ffd, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x6302, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xe08f, }, + { 0xa438, 0xfee1, }, + { 0xa438, 0x8fff, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x6602, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xaf88, }, + { 0xa438, 0x3ce1, }, + { 0xa438, 0x85a1, }, + { 0xa438, 0x1b21, }, + { 0xa438, 0xad37, }, + { 0xa438, 0x341f, }, + { 0xa438, 0x44e0, }, + { 0xa438, 0x858a, }, + { 0xa438, 0xe185, }, + { 0xa438, 0x8bbf, }, + { 0xa438, 0x885d, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x7de0, }, + { 0xa438, 0x8590, }, + { 0xa438, 0xe185, }, + { 0xa438, 0x91bf, }, + { 0xa438, 0x8860, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x7de0, }, + { 0xa438, 0x8596, }, + { 0xa438, 0xe185, }, + { 0xa438, 0x97bf, }, + { 0xa438, 0x8863, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x7de0, }, + { 0xa438, 0x859c, }, + { 0xa438, 0xe185, }, + { 0xa438, 0x9dbf, }, + { 0xa438, 0x8866, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x7dae, }, + { 0xa438, 0x401f, }, + { 0xa438, 0x44e0, }, + { 0xa438, 0x858c, }, + { 0xa438, 0xe185, }, + { 0xa438, 0x8dbf, }, + { 0xa438, 0x885d, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x7de0, }, + { 0xa438, 0x8592, }, + { 0xa438, 0xe185, }, + { 0xa438, 0x93bf, }, + { 0xa438, 0x8860, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x7de0, }, + { 0xa438, 0x8598, }, + { 0xa438, 0xe185, }, + { 0xa438, 0x99bf, }, + { 0xa438, 0x8863, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x7de0, }, + { 0xa438, 0x859e, }, + { 0xa438, 0xe185, }, + { 0xa438, 0x9fbf, }, + { 0xa438, 0x8866, }, + { 0xa438, 0x026e, }, + { 0xa438, 0x7dae, }, + { 0xa438, 0x0ce1, }, + { 0xa438, 0x85b3, }, + { 0xa438, 0x3904, }, + { 0xa438, 0xac2f, }, + { 0xa438, 0x04ee, }, + { 0xa438, 0x85b3, }, + { 0xa438, 0x00af, }, + { 0xa438, 0x39d9, }, + { 0xa438, 0x22ac, }, + { 0xa438, 0xeaf0, }, + { 0xa438, 0xacf6, }, + { 0xa438, 0xf0ac, }, + { 0xa438, 0xfaf0, }, + { 0xa438, 0xacf8, }, + { 0xa438, 0xf0ac, }, + { 0xa438, 0xfcf0, }, + { 0xa438, 0xad00, }, + { 0xa438, 0xf0ac, }, + { 0xa438, 0xfef0, }, + { 0xa438, 0xacf0, }, + { 0xa438, 0xf0ac, }, + { 0xa438, 0xf4f0, }, + { 0xa438, 0xacf2, }, + { 0xa438, 0xf0ac, }, + { 0xa438, 0xb0f0, }, + { 0xa438, 0xacae, }, + { 0xa438, 0xf0ac, }, + { 0xa438, 0xacf0, }, + { 0xa438, 0xacaa, }, + { 0xa438, 0xa100, }, + { 0xa438, 0x0ce1, }, + { 0xa438, 0x8ff7, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x8402, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xaf26, }, + { 0xa438, 0xe9e1, }, + { 0xa438, 0x8ff6, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x8402, }, + { 0xa438, 0x6e7d, }, + { 0xa438, 0xaf26, }, + { 0xa438, 0xf520, }, + { 0xa438, 0xac86, }, + { 0xa438, 0xbf88, }, + { 0xa438, 0x3f02, }, + { 0xa438, 0x6e9c, }, + { 0xa438, 0xad28, }, + { 0xa438, 0x03af, }, + { 0xa438, 0x3324, }, + { 0xa438, 0xad38, }, + { 0xa438, 0x03af, }, + { 0xa438, 0x32e6, }, + { 0xa438, 0xaf32, }, + { 0xa438, 0xfb00, }, + { 0xa436, 0xb87c, }, + { 0xa438, 0x8ff6, }, + { 0xa436, 0xb87e, }, + { 0xa438, 0x0705, }, + { 0xa436, 0xb87c, }, + { 0xa438, 0x8ff8, }, + { 0xa436, 0xb87e, }, + { 0xa438, 0x19cc, }, + { 0xa436, 0xb87c, }, + { 0xa438, 0x8ffa, }, + { 0xa436, 0xb87e, }, + { 0xa438, 0x28e3, }, + { 0xa436, 0xb87c, }, + { 0xa438, 0x8ffc, }, + { 0xa436, 0xb87e, }, + { 0xa438, 0x1047, }, + { 0xa436, 0xb87c, }, + { 0xa438, 0x8ffe, }, + { 0xa436, 0xb87e, }, + { 0xa438, 0x0a45, }, + { 0xa436, 0xb85e, }, + { 0xa438, 0x271e, }, + { 0xa436, 0xb860, }, + { 0xa438, 0x3846, }, + { 0xa436, 0xb862, }, + { 0xa438, 0x26e6, }, + { 0xa436, 0xb864, }, + { 0xa438, 0x32e3, }, + { 0xa436, 0xb886, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb888, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb88a, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb88c, }, + { 0xa438, 0xffff, }, + { 0xa436, 0xb838, }, + { 0xa438, 0x000f, }, +}; + +const size_t g_rtl8221b_uc2_ramcode_len = + sizeof(g_rtl8221b_uc2_ramcode) / sizeof(g_rtl8221b_uc2_ramcode[0]); + +/* GPHY parameter tuning, OCP key/value programming and the patch-version + * marker. One contiguous run of MMD writes from the vendor init sequence + * (no read-modify-write or status polling in between), applied through the + * same writer used for the ramcode banks. + */ + +const struct rtl8221b_mmd_reg_s g_rtl8221b_gphy_tuning[] = +{ + /* Lock Main */ + + { + 0xa46a, 0x0302 + }, + + /* GPHY parameter tuning (XG INRX, Fnet/Giga CHNEST, etc.) */ + + { + 0xac46, 0xb794 + }, + { + 0xa412, 0x0200 + }, + { + 0xa5d4, 0x0081 + }, + { + 0xad30, 0x0a57 + }, + { + 0xad30, 0x0a55 + }, + { + 0xb87c, 0x80f5 + }, + { + 0xb87e, 0x760e + }, + { + 0xb87c, 0x8107 + }, + { + 0xb87e, 0x360e + }, + { + 0xb87c, 0x8551 + }, + { + 0xb87e, 0x080e + }, + { + 0xbf00, 0xb202 + }, + { + 0xbf46, 0x0300 + }, + + /* OCP key/value tuning block (8044..807B = 0x240f / 0x1700) */ + + { + 0xa436, 0x8044 + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x804a + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x8050 + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x8056 + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x805c + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x8062 + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x8068 + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x806e + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x8074 + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x807a + }, + { + 0xa438, 0x240f + }, + { + 0xa436, 0x8045 + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x804b + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x8051 + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x8057 + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x805d + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x8063 + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x8069 + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x806f + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x8075 + }, + { + 0xa438, 0x1700 + }, + { + 0xa436, 0x807b + }, + { + 0xa438, 0x1700 + }, + { + 0xa4ca, 0x6a50 + }, + + /* OCP fine-tuning constants */ + + { + 0xa436, 0x8ff4 + }, + { + 0xa438, 0x0000 + }, + { + 0xa436, 0x8ff6 + }, + { + 0xa438, 0x03e8 + }, + { + 0xa436, 0x8ff8 + }, + { + 0xa438, 0x8000 + }, + { + 0xa436, 0x8ffa + }, + { + 0xa438, 0x8000 + }, + { + 0xa436, 0x8ffc + }, + { + 0xa438, 0x8000 + }, + { + 0xa436, 0x8ffe + }, + { + 0xa438, 0x8000 + }, + { + 0xa436, 0x8015 + }, + { + 0xa438, 0xf9bf + }, + { + 0xd12a, 0x8000 + }, + { + 0xd12c, 0x8000 + }, + { + 0xd144, 0x8000 + }, + { + 0xd146, 0x8000 + }, + { + 0xbf84, 0xac00 + }, + { + 0xa436, 0x8170 + }, + { + 0xa438, 0xd8a0 + }, + + /* Release Lock Main */ + + { + 0xa46a, 0x0300 + }, +}; + +const size_t g_rtl8221b_gphy_tuning_len = + sizeof(g_rtl8221b_gphy_tuning) / sizeof(g_rtl8221b_gphy_tuning[0]); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/* This file only provides the RTL8221B firmware patch tables; there are no + * functions defined here. + */ diff --git a/drivers/net/phy/realtek/rtl8221b_fw.h b/drivers/net/phy/realtek/rtl8221b_fw.h new file mode 100644 index 00000000000..4a6f809cae9 --- /dev/null +++ b/drivers/net/phy/realtek/rtl8221b_fw.h @@ -0,0 +1,80 @@ +/**************************************************************************** + * drivers/net/phy/realtek/rtl8221b_fw.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_RTL8221B_FW_H +#define __DRIVERS_NET_PHY_REALTEK_RTL8221B_FW_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stddef.h> + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* A single MMD register write entry used by the RTL8221B firmware patch + * (ramcode) sequences. Each entry writes 'value' to register 'addr' via + * Clause-45 access on the vendor MMD (MII_MMD_VEND2); the MMD is implied + * rather than stored per-entry to keep these large tables compact. + */ + +struct rtl8221b_mmd_reg_s +{ + uint16_t addr; + uint16_t value; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern const struct rtl8221b_mmd_reg_s g_rtl8221b_n0_ramcode[]; +extern const size_t g_rtl8221b_n0_ramcode_len; + +extern const struct rtl8221b_mmd_reg_s g_rtl8221b_n1_ramcode[]; +extern const size_t g_rtl8221b_n1_ramcode_len; + +extern const struct rtl8221b_mmd_reg_s g_rtl8221b_n2_ramcode[]; +extern const size_t g_rtl8221b_n2_ramcode_len; + +extern const struct rtl8221b_mmd_reg_s g_rtl8221b_uc_ramcode[]; +extern const size_t g_rtl8221b_uc_ramcode_len; + +extern const struct rtl8221b_mmd_reg_s g_rtl8221b_uc2_ramcode[]; +extern const size_t g_rtl8221b_uc2_ramcode_len; + +extern const struct rtl8221b_mmd_reg_s g_rtl8221b_gphy_tuning[]; +extern const size_t g_rtl8221b_gphy_tuning_len; + +#ifdef __cplusplus +} +#endif + +#endif /* __DRIVERS_NET_PHY_REALTEK_RTL8221B_FW_H */ diff --git a/include/nuttx/net/realtek_phy.h b/include/nuttx/net/realtek_phy.h new file mode 100644 index 00000000000..a4c49c81a9b --- /dev/null +++ b/include/nuttx/net/realtek_phy.h @@ -0,0 +1,64 @@ +/**************************************************************************** + * include/nuttx/net/realtek_phy.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 __INCLUDE_NUTTX_NET_REALTEK_PHY_H +#define __INCLUDE_NUTTX_NET_REALTEK_PHY_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/**************************************************************************** + * Name: rtl8221b_register + * + * Description: + * Register the RTL8221B PHY driver with the PHYLIB framework. Must be + * called once from board/MAC initialization, before connecting an + * RTL8221B PHY. Registration is not idempotent: each call consumes one + * entry of the fixed-size driver table (CONFIG_NET_PHYLIB_MAX_DRIVERS), + * so it must not be called repeatedly. + * + * Returned Value: + * OK on success; negated errno on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_PHY_REALTEK_RTL8221B +int rtl8221b_register(void); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_NET_REALTEK_PHY_H */
