xref: /openbmc/linux/drivers/net/dsa/microchip/ksz_ptp.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1eac1ea20SChristian Eggers /* SPDX-License-Identifier: GPL-2.0 */
2eac1ea20SChristian Eggers /* Microchip KSZ PTP Implementation
3eac1ea20SChristian Eggers  *
4eac1ea20SChristian Eggers  * Copyright (C) 2020 ARRI Lighting
5eac1ea20SChristian Eggers  * Copyright (C) 2022 Microchip Technology Inc.
6eac1ea20SChristian Eggers  */
7eac1ea20SChristian Eggers 
8eac1ea20SChristian Eggers #ifndef _NET_DSA_DRIVERS_KSZ_PTP_H
9eac1ea20SChristian Eggers #define _NET_DSA_DRIVERS_KSZ_PTP_H
10eac1ea20SChristian Eggers 
11eac1ea20SChristian Eggers #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP)
12eac1ea20SChristian Eggers 
13eac1ea20SChristian Eggers #include <linux/ptp_clock_kernel.h>
14eac1ea20SChristian Eggers 
15*343d3bd8SArun Ramadoss #define KSZ_PTP_N_GPIO		2
16*343d3bd8SArun Ramadoss 
171f12ae5bSChristian Eggers enum ksz_ptp_tou_mode {
181f12ae5bSChristian Eggers 	KSZ_PTP_TOU_IDLE,
191f12ae5bSChristian Eggers 	KSZ_PTP_TOU_PEROUT,
201f12ae5bSChristian Eggers };
211f12ae5bSChristian Eggers 
22eac1ea20SChristian Eggers struct ksz_ptp_data {
23eac1ea20SChristian Eggers 	struct ptp_clock_info caps;
24eac1ea20SChristian Eggers 	struct ptp_clock *clock;
25*343d3bd8SArun Ramadoss 	struct ptp_pin_desc pin_config[KSZ_PTP_N_GPIO];
26eac1ea20SChristian Eggers 	/* Serializes all operations on the PTP hardware clock */
27eac1ea20SChristian Eggers 	struct mutex lock;
28bb01ad30SChristian Eggers 	/* lock for accessing the clock_time */
29bb01ad30SChristian Eggers 	spinlock_t clock_lock;
30bb01ad30SChristian Eggers 	struct timespec64 clock_time;
311f12ae5bSChristian Eggers 	enum ksz_ptp_tou_mode tou_mode;
321f12ae5bSChristian Eggers 	struct timespec64 perout_target_time_first;  /* start of first pulse */
331f12ae5bSChristian Eggers 	struct timespec64 perout_period;
34eac1ea20SChristian Eggers };
35eac1ea20SChristian Eggers 
36eac1ea20SChristian Eggers int ksz_ptp_clock_register(struct dsa_switch *ds);
37eac1ea20SChristian Eggers 
38eac1ea20SChristian Eggers void ksz_ptp_clock_unregister(struct dsa_switch *ds);
39eac1ea20SChristian Eggers 
40c59e12a1SChristian Eggers int ksz_get_ts_info(struct dsa_switch *ds, int port,
41c59e12a1SChristian Eggers 		    struct ethtool_ts_info *ts);
42c59e12a1SChristian Eggers int ksz_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr);
43c59e12a1SChristian Eggers int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr);
44ab32f56aSChristian Eggers void ksz_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb);
45ab32f56aSChristian Eggers void ksz_port_deferred_xmit(struct kthread_work *work);
4690188fffSChristian Eggers bool ksz_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb,
4790188fffSChristian Eggers 		       unsigned int type);
48cc13ab18SArun Ramadoss int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p);
49cc13ab18SArun Ramadoss void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p);
50c59e12a1SChristian Eggers 
51eac1ea20SChristian Eggers #else
52eac1ea20SChristian Eggers 
53eac1ea20SChristian Eggers struct ksz_ptp_data {
54eac1ea20SChristian Eggers 	/* Serializes all operations on the PTP hardware clock */
55eac1ea20SChristian Eggers 	struct mutex lock;
56eac1ea20SChristian Eggers };
57eac1ea20SChristian Eggers 
ksz_ptp_clock_register(struct dsa_switch * ds)58eac1ea20SChristian Eggers static inline int ksz_ptp_clock_register(struct dsa_switch *ds)
59eac1ea20SChristian Eggers {
60eac1ea20SChristian Eggers 	return 0;
61eac1ea20SChristian Eggers }
62eac1ea20SChristian Eggers 
ksz_ptp_clock_unregister(struct dsa_switch * ds)63eac1ea20SChristian Eggers static inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { }
64eac1ea20SChristian Eggers 
ksz_ptp_irq_setup(struct dsa_switch * ds,u8 p)65cc13ab18SArun Ramadoss static inline int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
66cc13ab18SArun Ramadoss {
67cc13ab18SArun Ramadoss 	return 0;
68cc13ab18SArun Ramadoss }
69cc13ab18SArun Ramadoss 
ksz_ptp_irq_free(struct dsa_switch * ds,u8 p)70cc13ab18SArun Ramadoss static inline void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p) {}
71cc13ab18SArun Ramadoss 
72c59e12a1SChristian Eggers #define ksz_get_ts_info NULL
73c59e12a1SChristian Eggers 
74c59e12a1SChristian Eggers #define ksz_hwtstamp_get NULL
75c59e12a1SChristian Eggers 
76c59e12a1SChristian Eggers #define ksz_hwtstamp_set NULL
77c59e12a1SChristian Eggers 
7890188fffSChristian Eggers #define ksz_port_rxtstamp NULL
7990188fffSChristian Eggers 
80ab32f56aSChristian Eggers #define ksz_port_txtstamp NULL
81ab32f56aSChristian Eggers 
82ab32f56aSChristian Eggers #define ksz_port_deferred_xmit NULL
83ab32f56aSChristian Eggers 
84eac1ea20SChristian Eggers #endif	/* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */
85eac1ea20SChristian Eggers 
86eac1ea20SChristian Eggers #endif
87