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 ethtool_ts_info *ts);
42 int ksz_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr);
43 int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr);
44 void ksz_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb);
45 void ksz_port_deferred_xmit(struct kthread_work *work);
46 bool ksz_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb,
47 		       unsigned int type);
48 int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p);
49 void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p);
50 
51 #else
52 
53 struct ksz_ptp_data {
54 	/* Serializes all operations on the PTP hardware clock */
55 	struct mutex lock;
56 };
57 
ksz_ptp_clock_register(struct dsa_switch * ds)58 static inline int ksz_ptp_clock_register(struct dsa_switch *ds)
59 {
60 	return 0;
61 }
62 
ksz_ptp_clock_unregister(struct dsa_switch * ds)63 static inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { }
64 
ksz_ptp_irq_setup(struct dsa_switch * ds,u8 p)65 static inline int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
66 {
67 	return 0;
68 }
69 
ksz_ptp_irq_free(struct dsa_switch * ds,u8 p)70 static inline void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p) {}
71 
72 #define ksz_get_ts_info NULL
73 
74 #define ksz_hwtstamp_get NULL
75 
76 #define ksz_hwtstamp_set NULL
77 
78 #define ksz_port_rxtstamp NULL
79 
80 #define ksz_port_txtstamp NULL
81 
82 #define ksz_port_deferred_xmit NULL
83 
84 #endif	/* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */
85 
86 #endif
87