ksz_ptp.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Microchip KSZ PTP Implementation
  3. *
  4. * Copyright (C) 2020 ARRI Lighting
  5. * Copyright (C) 2022 Microchip Technology Inc.
  6. */
  7. #ifndef _NET_DSA_DRIVERS_KSZ_PTP_H
  8. #define _NET_DSA_DRIVERS_KSZ_PTP_H
  9. #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP)
  10. #include <linux/ptp_clock_kernel.h>
  11. #define KSZ_PTP_N_GPIO 2
  12. enum ksz_ptp_tou_mode {
  13. KSZ_PTP_TOU_IDLE,
  14. KSZ_PTP_TOU_PEROUT,
  15. };
  16. struct ksz_ptp_data {
  17. struct ptp_clock_info caps;
  18. struct ptp_clock *clock;
  19. struct ptp_pin_desc pin_config[KSZ_PTP_N_GPIO];
  20. /* Serializes all operations on the PTP hardware clock */
  21. struct mutex lock;
  22. /* lock for accessing the clock_time */
  23. spinlock_t clock_lock;
  24. struct timespec64 clock_time;
  25. enum ksz_ptp_tou_mode tou_mode;
  26. struct timespec64 perout_target_time_first; /* start of first pulse */
  27. struct timespec64 perout_period;
  28. };
  29. int ksz_ptp_clock_register(struct dsa_switch *ds);
  30. void ksz_ptp_clock_unregister(struct dsa_switch *ds);
  31. int ksz_get_ts_info(struct dsa_switch *ds, int port,
  32. struct kernel_ethtool_ts_info *ts);
  33. int ksz_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr);
  34. int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr);
  35. void ksz_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb);
  36. void ksz_port_deferred_xmit(struct kthread_work *work);
  37. bool ksz_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb,
  38. unsigned int type);
  39. int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p);
  40. void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p);
  41. #else
  42. struct ksz_ptp_data {
  43. /* Serializes all operations on the PTP hardware clock */
  44. struct mutex lock;
  45. };
  46. static inline int ksz_ptp_clock_register(struct dsa_switch *ds)
  47. {
  48. return 0;
  49. }
  50. static inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { }
  51. static inline int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
  52. {
  53. return 0;
  54. }
  55. static inline void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p) {}
  56. #define ksz_get_ts_info NULL
  57. #define ksz_hwtstamp_get NULL
  58. #define ksz_hwtstamp_set NULL
  59. #define ksz_port_rxtstamp NULL
  60. #define ksz_port_txtstamp NULL
  61. #define ksz_port_deferred_xmit NULL
  62. #endif /* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */
  63. #endif