mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 4/4] net: sparx5/lan969x: scale the nominal TOD increment in adjfine
Date: Fri, 13 Nov 2026 11:19:43 +0100	[thread overview]
Message-ID: <20261113-lan969x-core-skew-v1-4-b9b02b863d38@microchip.com> (raw)
In-Reply-To: <20261113-lan969x-core-skew-v1-0-b9b02b863d38@microchip.com>

sparx5_ptp_adjfine() builds the new TOD increment from two tables: the
nominal increment from sparx5_ptp_get_nominal_value(), and a one ppm
step from sparx5_ptp_get_1ppm(), which it multiplies by the requested
ppm. Nothing ties the two tables together, so they can get out of step.

They already are for the lan969x 328 MHz core clock: the nominal
increment is derived from the skewed rate, the one ppm step from the
328.125 MHz default. A 1 ppm request therefore moves the increment by
1.0002 ppm.

Drop sparx5_ptp_get_1ppm() and scale the nominal increment directly with
adjust_by_scaled_ppm(). The sparx5 core clocks are unchanged, as their
two tables agree.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c | 49 +---------------------
 1 file changed, 2 insertions(+), 47 deletions(-)

diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c b/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
index 544e9513a9a53..e37635e8fd730 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
@@ -22,37 +22,6 @@ enum {
 	PTP_PIN_ACTION_TOD
 };
 
-static u64 sparx5_ptp_get_1ppm(struct sparx5 *sparx5)
-{
-	/* Represents 1ppm adjustment in 2^59 format with 1.59687500000(625)
-	 * 1.99609375000(500), 3.99218750000(250) as reference
-	 * The value is calculated as following:
-	 * (1/1000000)/((2^-59)/X)
-	 */
-
-	u64 res = 0;
-
-	switch (sparx5->coreclock) {
-	case SPX5_CORE_CLOCK_250MHZ:
-		res = 2301339409586;
-		break;
-	case SPX5_CORE_CLOCK_328MHZ:
-		res = 1756832768924;
-		break;
-	case SPX5_CORE_CLOCK_500MHZ:
-		res = 1150669704793;
-		break;
-	case SPX5_CORE_CLOCK_625MHZ:
-		res =  920535763834;
-		break;
-	default:
-		WARN(1, "Invalid core clock");
-		break;
-	}
-
-	return res;
-}
-
 static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
 {
 	u64 res = 0;
@@ -407,27 +376,13 @@ static int sparx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 	struct sparx5_phc *phc = container_of(ptp, struct sparx5_phc, info);
 	struct sparx5 *sparx5 = phc->sparx5;
 	unsigned long flags;
-	bool neg_adj = 0;
 	u64 tod_inc;
-	u64 ref;
 
 	if (!scaled_ppm)
 		return 0;
 
-	if (scaled_ppm < 0) {
-		neg_adj = 1;
-		scaled_ppm = -scaled_ppm;
-	}
-
-	tod_inc = sparx5_ptp_get_nominal_value(sparx5);
-
-	/* The multiplication is split in 2 separate additions because of
-	 * overflow issues. If scaled_ppm with 16bit fractional part was bigger
-	 * than 20ppm then we got overflow.
-	 */
-	ref = sparx5_ptp_get_1ppm(sparx5) * (scaled_ppm >> 16);
-	ref += (sparx5_ptp_get_1ppm(sparx5) * (0xffff & scaled_ppm)) >> 16;
-	tod_inc = neg_adj ? tod_inc - ref : tod_inc + ref;
+	tod_inc = adjust_by_scaled_ppm(sparx5_ptp_get_nominal_value(sparx5),
+				       scaled_ppm);
 
 	spin_lock_irqsave(&sparx5->ptp_clock_lock, flags);
 

-- 
2.34.1


  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 ` [PATCH net-next 3/4] net: lan969x: configure the core PLL Daniel Machon
2026-11-16 13:22   ` netdev-bot+sashiko
2026-11-16 14:02     ` Daniel Machon
2026-11-13 10:19 ` Daniel Machon [this message]
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-4-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®