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
8 #ifndef _NET_DSA_DRIVERS_KSZ_PTP_H
9 #define _NET_DSA_DRIVERS_KSZ_PTP_H
10
11 #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP)
12
13 #include <linux/ptp_clock_kernel.h>
14
15 #define KSZ_PTP_N_GPIO 2
16
17 enum ksz_ptp_tou_mode {
18 KSZ_PTP_TOU_IDLE,
19 KSZ_PTP_TOU_PEROUT,
20 };
21
22 struct ksz_ptp_data {
23 struct ptp_clock_info caps;
24 struct ptp_clock *clock;
25 struct ptp_pin_desc pin_config[KSZ_PTP_N_GPIO];
26 /* Serializes all operations on the PTP hardware clock */
27 struct mutex lock;
28 /* lock for accessing the clock_time */
29 spinlock_t clock_lock;
30 struct timespec64 clock_time;
31 enum ksz_ptp_tou_mode tou_mode;
32 struct timespec64 perout_target_time_first; /* start of first pulse */
33 struct timespec64 perout_period;
34 };
35
36 int ksz_ptp_clock_register(struct dsa_switch *ds);
37
38 void ksz_ptp_clock_unregister(struct dsa_switch *ds);
39
40 int ksz_get_ts_info(struct dsa_switch *ds, int port,
41 struct kernel_ethtool_ts_info *ts);
42 int ksz_hwtstamp_get(struct dsa_switch *ds, int port,
43 struct kernel_hwtstamp_config *config);
44 int ksz_hwtstamp_set(struct dsa_switch *ds, int port,
45 struct kernel_hwtstamp_config *config,
46 struct netlink_ext_ack *extack);
47 void ksz_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb);
48 void ksz_port_deferred_xmit(struct kthread_work *work);
49 bool ksz_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb,
50 unsigned int type);
51 int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p);
52 void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p);
53
54 #else
55
56 struct ksz_ptp_data {
57 /* Serializes all operations on the PTP hardware clock */
58 struct mutex lock;
59 };
60
ksz_ptp_clock_register(struct dsa_switch * ds)61 static inline int ksz_ptp_clock_register(struct dsa_switch *ds)
62 {
63 return 0;
64 }
65
ksz_ptp_clock_unregister(struct dsa_switch * ds)66 static inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { }
67
ksz_ptp_irq_setup(struct dsa_switch * ds,u8 p)68 static inline int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
69 {
70 return 0;
71 }
72
ksz_ptp_irq_free(struct dsa_switch * ds,u8 p)73 static inline void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p) {}
74
75 #define ksz_get_ts_info NULL
76
77 #define ksz_hwtstamp_get NULL
78
79 #define ksz_hwtstamp_set NULL
80
81 #define ksz_port_rxtstamp NULL
82
83 #define ksz_port_txtstamp NULL
84
85 #define ksz_port_deferred_xmit NULL
86
87 #endif /* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */
88
89 #endif
90