Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptp: lan743x: use diff_by_scaled_ppm in .adjfine implementation

Update the lan743x driver to use the recently added diff_by_scaled_ppm
helper function. This reduces the amount of code required in lan743x_ptp.c
driver file.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Cc: Bryan Whitehead <bryan.whitehead@microchip.com>
Cc: UNGLinuxDriver@microchip.com
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jacob Keller and committed by
David S. Miller
8bc900cb c56dff6a

+6 -13
+6 -13
drivers/net/ethernet/microchip/lan743x_ptp.c
··· 339 339 struct lan743x_adapter *adapter = 340 340 container_of(ptp, struct lan743x_adapter, ptp); 341 341 u32 lan743x_rate_adj = 0; 342 - bool positive = true; 343 - u64 u64_delta = 0; 342 + u64 u64_delta; 344 343 345 344 if ((scaled_ppm < (-LAN743X_PTP_MAX_FINE_ADJ_IN_SCALED_PPM)) || 346 345 scaled_ppm > LAN743X_PTP_MAX_FINE_ADJ_IN_SCALED_PPM) { 347 346 return -EINVAL; 348 347 } 349 - if (scaled_ppm > 0) { 350 - u64_delta = (u64)scaled_ppm; 351 - positive = true; 352 - } else { 353 - u64_delta = (u64)(-scaled_ppm); 354 - positive = false; 355 - } 356 - u64_delta = (u64_delta << 19); 357 - lan743x_rate_adj = div_u64(u64_delta, 1000000); 358 348 359 - if (positive) 360 - lan743x_rate_adj |= PTP_CLOCK_RATE_ADJ_DIR_; 349 + /* diff_by_scaled_ppm returns true if the difference is negative */ 350 + if (diff_by_scaled_ppm(1ULL << 35, scaled_ppm, &u64_delta)) 351 + lan743x_rate_adj = (u32)u64_delta; 352 + else 353 + lan743x_rate_adj = (u32)u64_delta | PTP_CLOCK_RATE_ADJ_DIR_; 361 354 362 355 lan743x_csr_write(adapter, PTP_CLOCK_RATE_ADJ, 363 356 lan743x_rate_adj);