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->cycles = sys_cycles; in e1000e_phc_get_syncdevicetime()
128 system->cs_id = CSID_X86_ART; in e1000e_phc_get_syncdevicetime()
134 * e1000e_phc_getcrosststamp - Reads the current system/device cross timestamp
135 * @ptp: ptp clock structure
138 * Read device and system (ART) clock simultaneously and return the scaled
139 * clock values in ns.
153 * e1000e_phc_gettimex - Reads the current time from the hardware clock and
154 * system clock
155 * @ptp: ptp clock structure
157 * @sts: structure to hold the current system time
171 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_gettimex()
173 /* NOTE: Non-monotonic SYSTIM readings may be returned */ in e1000e_phc_gettimex()
175 ns = timecounter_cyc2time(&adapter->tc, cycles); in e1000e_phc_gettimex()
177 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_gettimex()
185 * e1000e_phc_settime - Set the current time on the hardware clock
186 * @ptp: ptp clock structure
203 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_settime()
204 timecounter_init(&adapter->tc, &adapter->cc, ns); in e1000e_phc_settime()
205 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_settime()
211 * e1000e_phc_enable - enable or disable an ancillary feature
212 * @ptp: ptp clock structure
223 return -EOPNOTSUPP; in e1000e_phc_enable()
230 struct e1000_hw *hw = &adapter->hw; in e1000e_systim_overflow_work()
235 ns = timecounter_read(&adapter->tc); in e1000e_systim_overflow_work()
241 schedule_delayed_work(&adapter->systim_overflow_work, in e1000e_systim_overflow_work()
260 * e1000e_ptp_init - initialize PTP for devices which support it
269 struct e1000_hw *hw = &adapter->hw; in e1000e_ptp_init()
271 adapter->ptp_clock = NULL; in e1000e_ptp_init()
273 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) in e1000e_ptp_init()
276 adapter->ptp_clock_info = e1000e_ptp_clock_info; in e1000e_ptp_init()
278 snprintf(adapter->ptp_clock_info.name, in e1000e_ptp_init()
279 sizeof(adapter->ptp_clock_info.name), "%pm", in e1000e_ptp_init()
280 adapter->netdev->perm_addr); in e1000e_ptp_init()
282 switch (hw->mac.type) { in e1000e_ptp_init()
284 adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ; in e1000e_ptp_init()
288 adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ; in e1000e_ptp_init()
290 adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ; in e1000e_ptp_init()
293 adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ; in e1000e_ptp_init()
303 adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ; in e1000e_ptp_init()
305 adapter->ptp_clock_info.max_adj = MAX_PPB_38400KHZ; in e1000e_ptp_init()
309 adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ; in e1000e_ptp_init()
317 if (hw->mac.type >= e1000_pch_spt && boot_cpu_has(X86_FEATURE_ART)) in e1000e_ptp_init()
318 adapter->ptp_clock_info.getcrosststamp = in e1000e_ptp_init()
322 INIT_DELAYED_WORK(&adapter->systim_overflow_work, in e1000e_ptp_init()
325 schedule_delayed_work(&adapter->systim_overflow_work, in e1000e_ptp_init()
328 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info, in e1000e_ptp_init()
329 &adapter->pdev->dev); in e1000e_ptp_init()
330 if (IS_ERR(adapter->ptp_clock)) { in e1000e_ptp_init()
331 adapter->ptp_clock = NULL; in e1000e_ptp_init()
333 } else if (adapter->ptp_clock) { in e1000e_ptp_init()
334 e_info("registered PHC clock\n"); in e1000e_ptp_init()
339 * e1000e_ptp_remove - disable PTP device and stop the overflow check
346 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) in e1000e_ptp_remove()
349 cancel_delayed_work_sync(&adapter->systim_overflow_work); in e1000e_ptp_remove()
351 if (adapter->ptp_clock) { in e1000e_ptp_remove()
352 ptp_clock_unregister(adapter->ptp_clock); in e1000e_ptp_remove()
353 adapter->ptp_clock = NULL; in e1000e_ptp_remove()