Lines Matching +full:system +full:- +full:clock +full:- +full:frequency
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
4 /* PTP 1588 Hardware Clock (PHC)
5 * Derived from PTP Hardware Clock driver for Intel 82576 and 82580 (igb)
18 * e1000e_phc_adjfine - adjust the frequency of the hardware clock
19 * @ptp: ptp clock structure
20 * @delta: Desired frequency chance in scaled parts per million
22 * Adjust the frequency of the PHC cycle counter by the indicated delta from
23 * the base frequency.
31 struct e1000_hw *hw = &adapter->hw; in e1000e_phc_adjfine()
37 /* Get the System Time Register SYSTIM base frequency */ in e1000e_phc_adjfine()
42 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_adjfine()
52 adapter->ptp_delta = delta; in e1000e_phc_adjfine()
54 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_adjfine()
60 * e1000e_phc_adjtime - Shift the time of the hardware clock
61 * @ptp: ptp clock structure
72 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_adjtime()
73 timecounter_adjtime(&adapter->tc, delta); in e1000e_phc_adjtime()
74 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_adjtime()
83 * e1000e_phc_get_syncdevicetime - Callback given to timekeeping code reads system/device registers
85 * @system: system counter value read synchronously with device time
88 * Read device and system (ART) clock simultaneously and return the corrected
89 * clock values in ns.
92 struct system_counterval_t *system, in e1000e_phc_get_syncdevicetime() argument
96 struct e1000_hw *hw = &adapter->hw; in e1000e_phc_get_syncdevicetime()
115 return -ETIMEDOUT; in e1000e_phc_get_syncdevicetime()
120 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_get_syncdevicetime()
121 *device = ns_to_ktime(timecounter_cyc2time(&adapter->tc, dev_cycles)); in e1000e_phc_get_syncdevicetime()
122 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_get_syncdevicetime()
127 *system = convert_art_to_tsc(sys_cycles); in e1000e_phc_get_syncdevicetime()
133 * e1000e_phc_getcrosststamp - Reads the current system/device cross timestamp
134 * @ptp: ptp clock structure
137 * Read device and system (ART) clock simultaneously and return the scaled
138 * clock values in ns.
152 * e1000e_phc_gettimex - Reads the current time from the hardware clock and
153 * system clock
154 * @ptp: ptp clock structure
156 * @sts: structure to hold the current system time
170 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_gettimex()
172 /* NOTE: Non-monotonic SYSTIM readings may be returned */ in e1000e_phc_gettimex()
174 ns = timecounter_cyc2time(&adapter->tc, cycles); in e1000e_phc_gettimex()
176 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_gettimex()
184 * e1000e_phc_settime - Set the current time on the hardware clock
185 * @ptp: ptp clock structure
202 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_settime()
203 timecounter_init(&adapter->tc, &adapter->cc, ns); in e1000e_phc_settime()
204 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_settime()
210 * e1000e_phc_enable - enable or disable an ancillary feature
211 * @ptp: ptp clock structure
222 return -EOPNOTSUPP; in e1000e_phc_enable()
229 struct e1000_hw *hw = &adapter->hw; in e1000e_systim_overflow_work()
234 ns = timecounter_read(&adapter->tc); in e1000e_systim_overflow_work()
240 schedule_delayed_work(&adapter->systim_overflow_work, in e1000e_systim_overflow_work()
259 * e1000e_ptp_init - initialize PTP for devices which support it
268 struct e1000_hw *hw = &adapter->hw; in e1000e_ptp_init()
270 adapter->ptp_clock = NULL; in e1000e_ptp_init()
272 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) in e1000e_ptp_init()
275 adapter->ptp_clock_info = e1000e_ptp_clock_info; in e1000e_ptp_init()
277 snprintf(adapter->ptp_clock_info.name, in e1000e_ptp_init()
278 sizeof(adapter->ptp_clock_info.name), "%pm", in e1000e_ptp_init()
279 adapter->netdev->perm_addr); in e1000e_ptp_init()
281 switch (hw->mac.type) { in e1000e_ptp_init()
283 adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ; in e1000e_ptp_init()
287 adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ; in e1000e_ptp_init()
289 adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ; in e1000e_ptp_init()
292 adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ; in e1000e_ptp_init()
302 adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ; in e1000e_ptp_init()
304 adapter->ptp_clock_info.max_adj = MAX_PPB_38400KHZ; in e1000e_ptp_init()
308 adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ; in e1000e_ptp_init()
316 if (hw->mac.type >= e1000_pch_spt && boot_cpu_has(X86_FEATURE_ART)) in e1000e_ptp_init()
317 adapter->ptp_clock_info.getcrosststamp = in e1000e_ptp_init()
321 INIT_DELAYED_WORK(&adapter->systim_overflow_work, in e1000e_ptp_init()
324 schedule_delayed_work(&adapter->systim_overflow_work, in e1000e_ptp_init()
327 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info, in e1000e_ptp_init()
328 &adapter->pdev->dev); in e1000e_ptp_init()
329 if (IS_ERR(adapter->ptp_clock)) { in e1000e_ptp_init()
330 adapter->ptp_clock = NULL; in e1000e_ptp_init()
332 } else if (adapter->ptp_clock) { in e1000e_ptp_init()
333 e_info("registered PHC clock\n"); in e1000e_ptp_init()
338 * e1000e_ptp_remove - disable PTP device and stop the overflow check
345 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) in e1000e_ptp_remove()
348 cancel_delayed_work_sync(&adapter->systim_overflow_work); in e1000e_ptp_remove()
350 if (adapter->ptp_clock) { in e1000e_ptp_remove()
351 ptp_clock_unregister(adapter->ptp_clock); in e1000e_ptp_remove()
352 adapter->ptp_clock = NULL; in e1000e_ptp_remove()