From: Daniel Machon <daniel.machon@microchip.com>
To: <UNGLinuxDriver@microchip.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
"Steen Hegelund" <Steen.Hegelund@microchip.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Richard Cochran <richardcochran@gmail.com>
Cc: <netdev@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH net-next 3/4] net: lan969x: configure the core PLL
Date: Fri, 13 Nov 2026 11:19:42 +0100 [thread overview]
Message-ID: <20261113-lan969x-core-skew-v1-3-b9b02b863d38@microchip.com> (raw)
In-Reply-To: <20261113-lan969x-core-skew-v1-0-b9b02b863d38@microchip.com>
The lan969x core PLL is left at its 328.125 MHz default, while the PTP
time of day (TOD) increment from sparx5_ptp_get_nominal_value() assumes
a core clock skewed about 200 ppm up, as recommended for the high
accuracy phase detectors. The TOD and the clock that drives the
scheduler therefore run 200 ppm apart: a 1 ms taprio cycle takes about
1000.2 us.
Program the core PLL to the skewed rate from sparx5_init_coreclock(),
using the glitch free divider change documented for CORE_PLL_CFG.
Select the dividers, and the matching TOD increment, from the reference
clock read from the strapping pin. Leave the PLL alone if it is already
configured, and disable the register configuration again if the change
fails.
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
.../net/ethernet/microchip/sparx5/sparx5_main.c | 119 +++++++++++++++++++++
.../net/ethernet/microchip/sparx5/sparx5_main.h | 7 ++
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c | 5 +-
3 files changed, 130 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
index 93a7cb89493c4..244974ffe496b 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
@@ -474,10 +474,120 @@ static int sparx5_init_switchcore(struct sparx5 *sparx5)
return 0;
}
+struct lan969x_core_pll_dividers {
+ u32 divfi;
+ u32 divff;
+ u32 divr;
+ u32 divq;
+};
+
+static const struct lan969x_core_pll_dividers lan969x_core_pll_328mhz[] = {
+ [SPX5_CORE_CLOCK_REF_25MHZ] = {
+ .divfi = 64, .divff = 0xa36076, .divr = 3, .divq = 10,
+ },
+ [SPX5_CORE_CLOCK_REF_39MHZ] = {
+ .divfi = 72, .divff = 0x83c361, .divr = 6, .divq = 10,
+ },
+};
+
+static int lan969x_init_core_pll(struct sparx5 *sparx5)
+{
+ const struct lan969x_core_pll_dividers *div;
+ u32 hw_stat, pll_cfg, freq_cfg;
+ enum sparx5_core_clockref ref;
+ int err;
+
+ hw_stat = spx5_rd(sparx5, CHIP_TOP_HW_STAT);
+ ref = CHIP_TOP_HW_STAT_REFCLK_SEL_GET(hw_stat) ?
+ SPX5_CORE_CLOCK_REF_39MHZ : SPX5_CORE_CLOCK_REF_25MHZ;
+ div = &lan969x_core_pll_328mhz[ref];
+ sparx5->coreclockref = ref;
+
+ /* Already configured by an earlier probe? */
+ pll_cfg = spx5_rd(sparx5, CHIP_TOP_CORE_PLL_CFG);
+ freq_cfg = spx5_rd(sparx5, CHIP_TOP_CORE_PLL_FREQ_CFG);
+ if (CHIP_TOP_CORE_PLL_CFG_ENA_CFG_GET(pll_cfg) &&
+ CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI_GET(freq_cfg) == div->divfi &&
+ CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF_GET(freq_cfg) == div->divff)
+ return 0;
+
+ spx5_rmw(CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI_SET(div->divfi) |
+ CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF_SET(div->divff),
+ CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFI |
+ CHIP_TOP_CORE_PLL_FREQ_CFG_DIVFF,
+ sparx5, CHIP_TOP_CORE_PLL_FREQ_CFG);
+
+ /* Set the reference and output dividers, select the reference clock
+ * from the strapping pin and use fractional mode.
+ */
+ spx5_rmw(CHIP_TOP_CORE_PLL_CFG_DIVQ_SET(div->divq) |
+ CHIP_TOP_CORE_PLL_CFG_DIVR_SET(div->divr) |
+ CHIP_TOP_CORE_PLL_CFG_REF_CLK_SEL_SET(0) |
+ CHIP_TOP_CORE_PLL_CFG_FILTER_RANGE_SET(0),
+ CHIP_TOP_CORE_PLL_CFG_DIVQ |
+ CHIP_TOP_CORE_PLL_CFG_DIVR |
+ CHIP_TOP_CORE_PLL_CFG_REF_CLK_SEL |
+ CHIP_TOP_CORE_PLL_CFG_FILTER_RANGE,
+ sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+ /* Switch the PLL from its reset defaults to the register settings */
+ spx5_rmw(CHIP_TOP_CORE_PLL_CFG_ENA_CFG_SET(1),
+ CHIP_TOP_CORE_PLL_CFG_ENA_CFG,
+ sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+ spx5_rmw(CHIP_TOP_CORE_PLL_CFG_NEWDIV_SET(1),
+ CHIP_TOP_CORE_PLL_CFG_NEWDIV,
+ sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+ err = read_poll_timeout(spx5_rd,
+ pll_cfg,
+ CHIP_TOP_CORE_PLL_CFG_DIVACK_GET(pll_cfg),
+ 100,
+ 10000,
+ false,
+ sparx5,
+ CHIP_TOP_CORE_PLL_CFG);
+
+ spx5_rmw(CHIP_TOP_CORE_PLL_CFG_NEWDIV_SET(0),
+ CHIP_TOP_CORE_PLL_CFG_NEWDIV,
+ sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+ if (err) {
+ dev_err(sparx5->dev,
+ "Failed to change the core PLL dividers\n");
+ goto err_disable;
+ }
+
+ /* LOCK_STAT resets to 1, so sleep before the first read */
+ err = read_poll_timeout(spx5_rd,
+ pll_cfg,
+ CHIP_TOP_CORE_PLL_CFG_LOCK_STAT_GET(pll_cfg),
+ 100,
+ 10000,
+ true,
+ sparx5,
+ CHIP_TOP_CORE_PLL_CFG);
+ if (err) {
+ dev_err(sparx5->dev, "Failed to lock the core PLL\n");
+ goto err_disable;
+ }
+
+ return 0;
+
+err_disable:
+ /* Make the next probe redo the change */
+ spx5_rmw(CHIP_TOP_CORE_PLL_CFG_ENA_CFG_SET(0),
+ CHIP_TOP_CORE_PLL_CFG_ENA_CFG,
+ sparx5, CHIP_TOP_CORE_PLL_CFG);
+
+ return err;
+}
+
static int sparx5_init_coreclock(struct sparx5 *sparx5)
{
enum sparx5_core_clockfreq freq = sparx5->coreclock;
u32 clk_div, clk_period, pol_upd_int, idx;
+ int err;
/* Verify if core clock frequency is supported on target.
* If 'VTSS_CORE_CLOCK_DEFAULT' then the highest supported
@@ -573,6 +683,15 @@ static int sparx5_init_coreclock(struct sparx5 *sparx5)
CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_ENA,
sparx5, CLKGEN_LCPLL1_CORE_CLK_CFG);
} else {
+ if (freq != SPX5_CORE_CLOCK_328MHZ) {
+ dev_err(sparx5->dev,
+ "%d coreclock not supported\n",
+ freq);
+ return -EINVAL;
+ }
+ err = lan969x_init_core_pll(sparx5);
+ if (err)
+ return err;
pol_upd_int = 820; // SPX5_CORE_CLOCK_328MHZ
}
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
index ad29db91ce91e..f6316086e6ecb 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h
@@ -266,6 +266,12 @@ struct sparx5_port {
} tas_lists[SPX5_TAS_ENTRIES_PER_PORT];
};
+/* lan969x core PLL reference clock, from CHIP_TOP:HW_STAT.REFCLK_SEL */
+enum sparx5_core_clockref {
+ SPX5_CORE_CLOCK_REF_25MHZ,
+ SPX5_CORE_CLOCK_REF_39MHZ,
+};
+
enum sparx5_core_clockfreq {
SPX5_CORE_CLOCK_DEFAULT, /* Defaults to the highest supported frequency */
SPX5_CORE_CLOCK_250MHZ, /* 250MHZ core clock frequency */
@@ -415,6 +421,7 @@ struct sparx5 {
/* port structures are in net device */
struct sparx5_port *ports[SPX5_PORTS];
enum sparx5_core_clockfreq coreclock;
+ enum sparx5_core_clockref coreclockref;
/* Statistics */
u32 num_stats;
u32 num_ethtool_stats;
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c b/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
index 9f61692b243b7..544e9513a9a53 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
@@ -62,7 +62,10 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
res = 0x1FF0000000000000;
break;
case SPX5_CORE_CLOCK_328MHZ:
- res = 0x18604697DD0F9B5B;
+ if (sparx5->coreclockref == SPX5_CORE_CLOCK_REF_25MHZ)
+ res = 0x186044FEF1EA9C10;
+ else
+ res = 0x18604697DD0F9B5B;
break;
case SPX5_CORE_CLOCK_500MHZ:
res = 0x0FF8000000000000;
--
2.34.1
next prev parent reply other threads:[~2026-11-13 10:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 10:19 [PATCH net-next 0/4] net: lan969x: skew the core clock by 200 ppm Daniel Machon
2026-11-13 10:19 ` [PATCH net-next 1/4] net: lan969x: add the core PLL registers Daniel Machon
2026-11-13 10:19 ` [PATCH net-next 2/4] net: sparx5/lan969x: enable the switch core after clock setup Daniel Machon
2026-11-13 10:19 ` Daniel Machon [this message]
2026-11-16 13:22 ` [PATCH net-next 3/4] net: lan969x: configure the core PLL netdev-bot+sashiko
2026-11-16 14:02 ` Daniel Machon
2026-11-13 10:19 ` [PATCH net-next 4/4] net: sparx5/lan969x: scale the nominal TOD increment in adjfine Daniel Machon
2026-11-17 14:00 ` [PATCH net-next 0/4] net: lan969x: skew the core clock by 200 ppm patchwork-bot+netdevbpf
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=20261113-lan969x-core-skew-v1-3-b9b02b863d38@microchip.com \
--to=daniel.machon@microchip.com \
--cc=Steen.Hegelund@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.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®