/include/net/caif/

/* PTP 1588 Hardware Clock (PHC) * Derived from PTP Hardware Clock driver for Intel 82576 and 82580 (igb) * Copyright (C) 2011 Richard Cochran */ #include "e1000.h" #ifdef CONFIG_E1000E_HWTS #include #include #include #endif /** * e1000e_phc_adjfreq - adjust the frequency of the hardware clock * @ptp: ptp clock structure * @delta: Desired frequency change in parts per billion * * Adjust the frequency of the PHC cycle counter by the indicated delta from * the base frequency. **/ static int e1000e_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta) { struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, ptp_clock_info); struct e1000_hw *hw = &adapter->hw; bool neg_adj = false; unsigned long flags; u64 adjustment; u32 timinca, incvalue; s32 ret_val; if ((delta > ptp->max_adj) || (delta <= -1000000000)) return -EINVAL; if (delta < 0) { neg_adj = true; delta = -delta; } /* Get the System Time Register SYSTIM base frequency */ ret_val = e1000e_get_base_timinca(adapter, &timinca); if (ret_val) return ret_val; spin_lock_irqsave(&adapter->systim_lock, flags); incvalue = timinca & E1000_TIMINCA_INCVALUE_MASK; adjustment = incvalue; adjustment *= delta; adjustment = div_u64(adjustment, 1000000000); incvalue = neg_adj ? (incvalue - adjustment) : (incvalue + adjustment); timinca &= ~E1000_TIMINCA_INCVALUE_MASK; timinca |= incvalue; ew32(TIMINCA, timinca); adapter->ptp_delta = delta; spin_unlock_irqrestore(&adapter->systim_lock, flags); return 0; } /** * e1000e_phc_adjtime - Shift the time of the hardware clock * @ptp: ptp clock structure * @delta: Desired change in nanoseconds * * Adjust the timer by resetting the timecounter structure. **/ static int e1000e_phc_adjtime(struct ptp_clock_info *ptp, s64 delta) { struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, ptp_clock_info); unsigned long flags; spin_lock_irqsave(&adapter->systim_lock, flags); timecounter_adjtime(&adapter->tc, delta); spin_unlock_irqrestore(&adapter->systim_lock, flags); return 0; } #ifdef CONFIG_E1000E_HWTS #define MAX_HW_WAIT_COUNT (3) /** * e1000e_phc_get_syncdevicetime - Callback given to timekeeping code reads system/device registers * @device: current device time * @system: system counter value read synchronously with device time * @ctx: context provided by timekeeping code * * Read device and system (ART) clock simultaneously and return the corrected * clock values in ns. **/ static int e1000e_phc_get_syncdevicetime(ktime_t *device, struct system_counterval_t *system, void *ctx) { struct e1000_adapter *adapter = (struct e1000_adapter *)ctx; struct e1000_hw *hw = &adapter->hw; unsigned lo