From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev@vger.kernel.org
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
Nicolai Buchwitz <nb@tipi-net.de>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next v2 2/4] net: phy: broadcom: Implement cable test initialization for BCM54210E
Date: Fri, 4 Dec 2026 15:36:31 -0800 [thread overview]
Message-ID: <20261204233633.3790143-3-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261204233633.3790143-1-florian.fainelli@broadcom.com>
Load the vendor ECD parameters before starting a cable test on the
BCM54210E. The sequence was verified on a Raspberry Pi 4B with this
PHY. Match the BCM54210E model in the shared start helper so the
BCM54140 continues to use its existing start sequence.
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
Co-developed-by: Nicolai Buchwitz <nb@tipi-net.de>
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
drivers/net/phy/bcm-phy-lib.c | 156 ++++++++++++++++++++++++++++++++++
1 file changed, 156 insertions(+)
diff --git a/drivers/net/phy/bcm-phy-lib.c b/drivers/net/phy/bcm-phy-lib.c
index 4911dc8210cd..1a170faf05ae 100644
--- a/drivers/net/phy/bcm-phy-lib.c
+++ b/drivers/net/phy/bcm-phy-lib.c
@@ -657,6 +657,156 @@ static int __bcm_phy_enable_legacy_access(struct phy_device *phydev)
BCM54XX_ACCESS_MODE_LEGACY_EN);
}
+struct __bcm_phy_regs {
+ u16 reg;
+ u16 val;
+};
+
+/* Load the ECD page and clear the staging registers afterwards.
+ * The enable mask requires regs[] to list consecutive offsets from 0xe0.
+ */
+static int _bcm_phy_load_values(struct phy_device *phydev,
+ const struct __bcm_phy_regs *regs,
+ size_t num_regs,
+ u16 page_num)
+{
+ unsigned int i;
+ int ret;
+
+ /* Load the registers into the expansion E* registers */
+ for (i = 0; i < num_regs; i++) {
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER +
+ regs[i].reg, regs[i].val);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Set the page number and the E* register enable mask */
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xef,
+ page_num << 14 | GENMASK(num_regs - 1, 0));
+ if (ret < 0)
+ return ret;
+
+ /* Write strobe 1 */
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xcd,
+ 0x1000);
+ if (ret < 0)
+ return ret;
+
+ /* Write strobe 0 */
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xcd, 0);
+ if (ret < 0)
+ return ret;
+
+ /* Restore expansion E* register values */
+ for (i = 0; i < num_regs; i++) {
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER +
+ regs[i].reg, 0);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* And restore 0xEF register */
+ return __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xef, 0);
+}
+
+/* Must be called with the MDIO bus lock held and legacy expansion register
+ * access enabled.
+ */
+static int __bcm_phy_cable_test_init(struct phy_device *phydev)
+{
+ static const struct __bcm_phy_regs init_regs[] = {
+ { 0xc7, 0xA01A },
+ { 0xc8, 0x0300 },
+ { 0xc9, 0x00EF },
+ { 0xcb, 0x1304 },
+ { 0xcc, 0x0180 },
+ { 0xce, 0x4000 },
+ { 0xcf, 0x3000 },
+ };
+ static const struct __bcm_phy_regs page1_init_regs[] = {
+ /* Page 1 */
+ { 0xe0, 0x0119 },
+ { 0xe1, 0x0202 },
+ { 0xe2, 0x000F },
+ { 0xe3, 0x5000 },
+ { 0xe4, 0x738E },
+ { 0xe5, 0x1000 },
+ { 0xe6, 0x1000 },
+ { 0xe7, 0xAA00 },
+ };
+ static const struct __bcm_phy_regs page2_init_regs[] = {
+ /* page 2 */
+ { 0xe0, 0x0B00 },
+ { 0xe1, 0x313D },
+ { 0xe2, 0x007C },
+ };
+ static const struct __bcm_phy_regs page0_init_regs[] = {
+ /* page 0 */
+ { 0xe0, 0x0001 },
+ { 0xe1, 0x0540 },
+ { 0xe2, 0x0E40 },
+ { 0xe3, 0x0841 },
+ { 0xe4, 0x1344 },
+ { 0xe8, 0x8760 },
+ { 0xe9, 0x4B33 },
+ { 0xea, 0x0400 },
+ };
+ unsigned int i;
+ int ret;
+
+ /* Disable ECD to load parameters. Note that the reference sequence
+ * soft-resets the PHY first, but that is only needed for the Broadcom
+ * DVT process and would discard the configuration done at
+ * config_init() time.
+ */
+ ret = __bcm_phy_write_exp(phydev, BCM54XX_EXP_ECD_CTRL, 0);
+ if (ret < 0)
+ return ret;
+
+ /* Prepare for loading value */
+ for (i = 0; i < ARRAY_SIZE(init_regs); i++) {
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER +
+ init_regs[i].reg,
+ init_regs[i].val);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Load page 1 values */
+ ret = _bcm_phy_load_values(phydev, page1_init_regs,
+ ARRAY_SIZE(page1_init_regs), 1);
+ if (ret < 0)
+ return ret;
+
+ /* Load page 2 values */
+ ret = _bcm_phy_load_values(phydev, page2_init_regs,
+ ARRAY_SIZE(page2_init_regs), 2);
+ if (ret < 0)
+ return ret;
+
+ /* Load the page 0 values */
+ for (i = 0; i < ARRAY_SIZE(page0_init_regs); i++) {
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER +
+ page0_init_regs[i].reg,
+ page0_init_regs[i].val);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Finish loading */
+ ret = __bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0xcd, 0xd0);
+ if (ret < 0)
+ return ret;
+
+ /* Dummy read to flush the ECD register */
+ ret = __bcm_phy_read_exp(phydev, BCM54XX_EXP_ECD_CTRL);
+ if (ret < 0)
+ return ret;
+
+ return __bcm_phy_write_exp(phydev, BCM54XX_EXP_ECD_CTRL, 0);
+}
+
static int _bcm_phy_cable_test_start(struct phy_device *phydev, bool is_rdb)
{
u16 mask, set;
@@ -676,6 +826,12 @@ static int _bcm_phy_cable_test_start(struct phy_device *phydev, bool is_rdb)
goto out;
}
+ if (phy_id_compare_model(phydev->phy_id, PHY_ID_BCM54210E)) {
+ ret = __bcm_phy_cable_test_init(phydev);
+ if (ret < 0)
+ goto out;
+ }
+
mask = BCM54XX_ECD_CTRL_CROSS_SHORT_DIS | BCM54XX_ECD_CTRL_UNIT_MASK;
set = BCM54XX_ECD_CTRL_RUN | BCM54XX_ECD_CTRL_BREAK_LINK |
FIELD_PREP(BCM54XX_ECD_CTRL_UNIT_MASK,
--
2.56.1
next prev parent reply other threads:[~2026-12-04 23:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 23:36 [PATCH net-next v2 0/4] net: phy: Cable tests for BCM54210E Florian Fainelli
2026-12-04 23:36 ` [PATCH net-next v2 1/4] net: phy: broadcom: Report failed ECD pairs as unspecified Florian Fainelli
2026-12-04 23:36 ` Florian Fainelli [this message]
2026-12-04 23:36 ` [PATCH net-next v2 3/4] net: phy: broadcom: Wire-up cable tests for BCM54210E Florian Fainelli
2026-12-04 23:36 ` [PATCH net-next v2 4/4] net: phy: broadcom: Recover BCM54210E from aborted cable tests Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204233633.3790143-3-florian.fainelli@broadcom.com \
--to=florian.fainelli@broadcom.com \
--cc=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=nb@tipi-net.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox