cavium_ptp.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* cavium_ptp.h - PTP 1588 clock on Cavium hardware
  3. * Copyright (c) 2003-2015, 2017 Cavium, Inc.
  4. */
  5. #ifndef CAVIUM_PTP_H
  6. #define CAVIUM_PTP_H
  7. #include <linux/ptp_clock_kernel.h>
  8. #include <linux/timecounter.h>
  9. struct cavium_ptp {
  10. struct pci_dev *pdev;
  11. /* Serialize access to cycle_counter, time_counter and hw_registers */
  12. spinlock_t spin_lock;
  13. struct cyclecounter cycle_counter;
  14. struct timecounter time_counter;
  15. void __iomem *reg_base;
  16. u32 clock_rate;
  17. struct ptp_clock_info ptp_info;
  18. struct ptp_clock *ptp_clock;
  19. };
  20. #if IS_ENABLED(CONFIG_CAVIUM_PTP)
  21. struct cavium_ptp *cavium_ptp_get(void);
  22. void cavium_ptp_put(struct cavium_ptp *ptp);
  23. static inline u64 cavium_ptp_tstamp2time(struct cavium_ptp *ptp, u64 tstamp)
  24. {
  25. unsigned long flags;
  26. u64 ret;
  27. spin_lock_irqsave(&ptp->spin_lock, flags);
  28. ret = timecounter_cyc2time(&ptp->time_counter, tstamp);
  29. spin_unlock_irqrestore(&ptp->spin_lock, flags);
  30. return ret;
  31. }
  32. static inline int cavium_ptp_clock_index(struct cavium_ptp *clock)
  33. {
  34. return ptp_clock_index(clock->ptp_clock);
  35. }
  36. #else
  37. static inline struct cavium_ptp *cavium_ptp_get(void)
  38. {
  39. return ERR_PTR(-ENODEV);
  40. }
  41. static inline void cavium_ptp_put(struct cavium_ptp *ptp) {}
  42. static inline u64 cavium_ptp_tstamp2time(struct cavium_ptp *ptp, u64 tstamp)
  43. {
  44. return 0;
  45. }
  46. static inline int cavium_ptp_clock_index(struct cavium_ptp *clock)
  47. {
  48. return -1;
  49. }
  50. #endif
  51. #endif