From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.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>,
Frank <Frank.Sae@motor-comm.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v2 2/2] net: phy: motorcomm: Add cable test support for internal YT861x PHYs
Date: Wed, 7 Oct 2026 04:23:48 +0800 [thread overview]
Message-ID: <20261006202352.1616626-3-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261006202352.1616626-1-mmyangfl@gmail.com>
Add TDR cable test support for the internal YT861x PHYs, reporting the
per-pair result and the fault length.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/phy/motorcomm.c | 113 ++++++++++++++++++++++++++++++++++++
1 file changed, 113 insertions(+)
diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index 3ebd911f4400..2a7af80d7845 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -8,6 +8,7 @@
#include <linux/clk.h>
#include <linux/etherdevice.h>
+#include <linux/ethtool_netlink.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/phy.h>
@@ -300,6 +301,19 @@
#define YT8531_SCR_CLK_SRC_REF_25M 4
#define YT8531_SCR_CLK_SRC_SSC_25M 5
+/* TDR (cable diagnostic) test control */
+#define YT861X_TDR_CTRL_REG 0x80
+#define YT861X_TDR_CTRL_START BIT(0)
+
+#define YT861X_TDR_STATUS_REG 0x84
+#define YT861X_TDR_STATUS_BUSY BIT(15)
+#define YT861X_TDR_STATUS_PAIR_OK 0
+#define YT861X_TDR_STATUS_PAIR_UNKNOWN 1
+#define YT861X_TDR_STATUS_PAIR_SHORT 2
+#define YT861X_TDR_STATUS_PAIR_OPEN 3
+
+#define YT861X_TDR_PAIR_LENGTH_REG(n) (0x87 + (n)) /* in cm */
+
#define YT8821_SDS_EXT_CSR_CTRL_REG 0x23
#define YT8821_SDS_EXT_CSR_VCO_LDO_EN BIT(15)
#define YT8821_SDS_EXT_CSR_VCO_BIAS_LPF_EN BIT(8)
@@ -2563,6 +2577,103 @@ static int yt861x_config_init(struct phy_device *phydev)
sleep ? YT8521_ESC1R_SLEEP_SW : 0);
}
+/**
+ * yt861x_cable_test_start() - start a cable diagnostic (TDR) test
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt861x_cable_test_start(struct phy_device *phydev)
+{
+ int ret;
+
+ /* auto sleep would abort the TDR test */
+ ret = ytphy_modify_ext_with_lock(phydev,
+ YT8521_EXTREG_SLEEP_CONTROL1_REG,
+ YT8521_ESC1R_SLEEP_SW, 0);
+ if (ret)
+ return ret;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT861X_TDR_CTRL_REG,
+ YT861X_TDR_CTRL_START);
+ if (ret) {
+ int err = yt861x_config_init(phydev);
+
+ if (err)
+ phydev_warn(phydev,
+ "Failed to restore auto sleep: %d\n",
+ err);
+ }
+
+ return ret;
+}
+
+/**
+ * yt861x_cable_test_get_status() - report cable diagnostic test results
+ * @phydev: a pointer to a &struct phy_device
+ * @finished: set to true when the test is complete
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt861x_cable_test_get_status(struct phy_device *phydev,
+ bool *finished)
+{
+ int status;
+ int ret;
+
+ *finished = false;
+
+ status = ytphy_read_ext_with_lock(phydev, YT861X_TDR_STATUS_REG);
+ if (status < 0)
+ return status;
+
+ if (status & YT861X_TDR_STATUS_BUSY)
+ return 0;
+
+ for (int pair = ETHTOOL_A_CABLE_PAIR_A; pair <= ETHTOOL_A_CABLE_PAIR_D;
+ pair++) {
+ u8 code;
+
+ switch ((status >> (2 * pair)) & 0x3) {
+ case YT861X_TDR_STATUS_PAIR_OK:
+ code = ETHTOOL_A_CABLE_RESULT_CODE_OK;
+ break;
+ case YT861X_TDR_STATUS_PAIR_SHORT:
+ code = ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
+ break;
+ case YT861X_TDR_STATUS_PAIR_OPEN:
+ code = ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
+ break;
+ default:
+ code = ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
+ }
+
+ ethnl_cable_test_result(phydev, pair, code);
+
+ if (code != ETHTOOL_A_CABLE_RESULT_CODE_OK &&
+ code != ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC) {
+ ret = ytphy_read_ext_with_lock(phydev,
+ YT861X_TDR_PAIR_LENGTH_REG(pair));
+ if (ret >= 0)
+ ethnl_cable_test_fault_length(phydev, pair,
+ ret);
+ }
+ }
+
+ /* the reset below does not restore auto sleep by itself */
+ ret = yt861x_config_init(phydev);
+ if (ret)
+ return ret;
+
+ ret = genphy_soft_reset(phydev);
+ if (ret)
+ return ret;
+
+ *finished = true;
+
+ return 0;
+}
+
/**
* yt8821_get_features - read mmd register to get 2.5G capability
* @phydev: target phy_device struct
@@ -3205,6 +3316,8 @@ static struct phy_driver motorcomm_phy_drvs[] = {
.soft_reset = genphy_soft_reset,
.suspend = genphy_suspend,
.resume = genphy_resume,
+ .cable_test_start = yt861x_cable_test_start,
+ .cable_test_get_status = yt861x_cable_test_get_status,
},
{
PHY_ID_MATCH_EXACT(PHY_ID_YT8821),
--
2.53.0
prev parent reply other threads:[~2026-10-06 20:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 20:23 [PATCH net-next v2 0/2] " David Yang
2026-10-06 20:23 ` [PATCH net-next v2 1/2] net: phy: motorcomm: Add driver entry " David Yang
2026-10-06 20:45 ` Andrew Lunn
2026-10-06 20:23 ` David Yang [this message]
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=20261006202352.1616626-3-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=Frank.Sae@motor-comm.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--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
all inboxes | Powered by JetHome®