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

net: stmmac: Move subsecond increment configuration in dedicated helper

In preparation for fine/coarse support, let's move the subsecond increment
and addend configuration in a dedicated helper.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/20251024070720.71174-2-maxime.chevallier@bootlin.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Maxime Chevallier and committed by
Paolo Abeni
792000fb d7d5eca4

+28 -20
+28 -20
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 464 464 } 465 465 } 466 466 467 + static void stmmac_update_subsecond_increment(struct stmmac_priv *priv) 468 + { 469 + bool xmac = dwmac_is_xmac(priv->plat->core_type); 470 + u32 sec_inc = 0; 471 + u64 temp = 0; 472 + 473 + stmmac_config_hw_tstamping(priv, priv->ptpaddr, priv->systime_flags); 474 + 475 + /* program Sub Second Increment reg */ 476 + stmmac_config_sub_second_increment(priv, priv->ptpaddr, 477 + priv->plat->clk_ptp_rate, 478 + xmac, &sec_inc); 479 + temp = div_u64(1000000000ULL, sec_inc); 480 + 481 + /* Store sub second increment for later use */ 482 + priv->sub_second_inc = sec_inc; 483 + 484 + /* calculate default added value: 485 + * formula is : 486 + * addend = (2^32)/freq_div_ratio; 487 + * where, freq_div_ratio = 1e9ns/sec_inc 488 + */ 489 + temp = (u64)(temp << 32); 490 + priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate); 491 + stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend); 492 + } 493 + 467 494 /** 468 495 * stmmac_hwtstamp_set - control hardware timestamping. 469 496 * @dev: device pointer. ··· 724 697 static int stmmac_init_tstamp_counter(struct stmmac_priv *priv, 725 698 u32 systime_flags) 726 699 { 727 - bool xmac = dwmac_is_xmac(priv->plat->core_type); 728 700 struct timespec64 now; 729 - u32 sec_inc = 0; 730 - u64 temp = 0; 731 701 732 702 if (!priv->plat->clk_ptp_rate) { 733 703 netdev_err(priv->dev, "Invalid PTP clock rate"); ··· 734 710 stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags); 735 711 priv->systime_flags = systime_flags; 736 712 737 - /* program Sub Second Increment reg */ 738 - stmmac_config_sub_second_increment(priv, priv->ptpaddr, 739 - priv->plat->clk_ptp_rate, 740 - xmac, &sec_inc); 741 - temp = div_u64(1000000000ULL, sec_inc); 742 - 743 - /* Store sub second increment for later use */ 744 - priv->sub_second_inc = sec_inc; 745 - 746 - /* calculate default added value: 747 - * formula is : 748 - * addend = (2^32)/freq_div_ratio; 749 - * where, freq_div_ratio = 1e9ns/sec_inc 750 - */ 751 - temp = (u64)(temp << 32); 752 - priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate); 753 - stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend); 713 + stmmac_update_subsecond_increment(priv); 754 714 755 715 /* initialize system time */ 756 716 ktime_get_real_ts64(&now);