Skip to content
Permalink
Browse files
net: stmmac: Init PTP clock with system clock
Move PTP clock value assignment codes from stmmac_hwtstamp_set() to
stmmac_init_ptp(), so that PTP clock can start running after module
is loaded and eliminate the need for user to run user application such
as ptp4l to start the PTP clock.

Signed-off-by: Wong, Vee Khee <vee.khee.wong@intel.com>
  • Loading branch information
wvk86 authored and wvoon committed Feb 5, 2020
1 parent 9e4f72d commit 91c9a87a5d240e8b419bf735286ce4cfcea30c34
Showing 1 changed file with 40 additions and 29 deletions.
@@ -528,8 +528,6 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
{
struct stmmac_priv *priv = netdev_priv(dev);
struct hwtstamp_config config;
struct timespec64 now;
u64 temp = 0;
u32 ptp_v2 = 0;
u32 tstamp_all = 0;
u32 ptp_over_ipv4_udp = 0;
@@ -538,7 +536,6 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
u32 snap_type_sel = 0;
u32 ts_master_en = 0;
u32 ts_event_en = 0;
u32 sec_inc = 0;
u32 value = 0;
bool xmac;

@@ -711,33 +708,8 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
tstamp_all | ptp_v2 | ptp_over_ethernet |
ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
ts_master_en | snap_type_sel);
stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);

/* program Sub Second Increment reg */
stmmac_config_sub_second_increment(priv,
priv->ptpaddr, priv->plat->clk_ptp_rate,
xmac, &sec_inc, priv->plat->is_hfpga);
temp = div_u64(1000000000ULL, sec_inc);

/* Store sub second increment and flags for later use */
priv->sub_second_inc = sec_inc;
priv->systime_flags = value;

/* calculate default added value:
* formula is :
* addend = (2^32)/freq_div_ratio;
* where, freq_div_ratio = 1e9ns/sec_inc
*/
temp = (u64)(temp << 32);
priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);

/* initialize system time */
ktime_get_real_ts64(&now);

/* lower 32 bits of tv_sec are safe until y2106 */
stmmac_init_systime(priv, priv->ptpaddr,
(u32)now.tv_sec, now.tv_nsec);
stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);
}

memcpy(&priv->tstamp_config, &config, sizeof(config));
@@ -776,6 +748,11 @@ static int stmmac_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
*/
static int stmmac_init_ptp(struct stmmac_priv *priv)
{
struct timespec64 now;
u32 sec_inc;
u32 value;
u64 temp;

bool xmac = priv->plat->has_gmac4 || priv->plat->has_xgmac;

if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
@@ -801,6 +778,40 @@ static int stmmac_init_ptp(struct stmmac_priv *priv)

stmmac_ptp_register(priv);

if (priv->ptp_clock) {
value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR);

stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);

/* program Sub Second Increment reg */
stmmac_config_sub_second_increment(priv,
priv->ptpaddr,
priv->plat->clk_ptp_rate,
xmac, &sec_inc,
priv->plat->is_hfpga);
temp = div_u64(1000000000ULL, sec_inc);

/* Store sub second increment and flags for later use */
priv->sub_second_inc = sec_inc;
priv->systime_flags = value;

/* calculate default added value:
* formula is :
* addend = (2^32)/freq_div_ratio;
* where, freq_div_ratio = 1e9ns/sec_inc
*/
temp = (u64)(temp << 32);
priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);

/* initialize system time */
ktime_get_real_ts64(&now);

/* lower 32 bits of tv_sec are safe until y2106 */
stmmac_init_systime(priv, priv->ptpaddr,
(u32)now.tv_sec, now.tv_nsec);
}

return 0;
}

0 comments on commit 91c9a87

Please sign in to comment.