0001
0002
0003
0004
0005
0006 #ifndef CAVIUM_PTP_H
0007 #define CAVIUM_PTP_H
0008
0009 #include <linux/ptp_clock_kernel.h>
0010 #include <linux/timecounter.h>
0011
0012 struct cavium_ptp {
0013 struct pci_dev *pdev;
0014
0015
0016 spinlock_t spin_lock;
0017 struct cyclecounter cycle_counter;
0018 struct timecounter time_counter;
0019 void __iomem *reg_base;
0020
0021 u32 clock_rate;
0022
0023 struct ptp_clock_info ptp_info;
0024 struct ptp_clock *ptp_clock;
0025 };
0026
0027 #if IS_REACHABLE(CONFIG_CAVIUM_PTP)
0028
0029 struct cavium_ptp *cavium_ptp_get(void);
0030 void cavium_ptp_put(struct cavium_ptp *ptp);
0031
0032 static inline u64 cavium_ptp_tstamp2time(struct cavium_ptp *ptp, u64 tstamp)
0033 {
0034 unsigned long flags;
0035 u64 ret;
0036
0037 spin_lock_irqsave(&ptp->spin_lock, flags);
0038 ret = timecounter_cyc2time(&ptp->time_counter, tstamp);
0039 spin_unlock_irqrestore(&ptp->spin_lock, flags);
0040
0041 return ret;
0042 }
0043
0044 static inline int cavium_ptp_clock_index(struct cavium_ptp *clock)
0045 {
0046 return ptp_clock_index(clock->ptp_clock);
0047 }
0048
0049 #else
0050
0051 static inline struct cavium_ptp *cavium_ptp_get(void)
0052 {
0053 return ERR_PTR(-ENODEV);
0054 }
0055
0056 static inline void cavium_ptp_put(struct cavium_ptp *ptp) {}
0057
0058 static inline u64 cavium_ptp_tstamp2time(struct cavium_ptp *ptp, u64 tstamp)
0059 {
0060 return 0;
0061 }
0062
0063 static inline int cavium_ptp_clock_index(struct cavium_ptp *clock)
0064 {
0065 return -1;
0066 }
0067
0068 #endif
0069
0070 #endif