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 --- 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