162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Microchip KSZ PTP Implementation
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2020 ARRI Lighting
562306a36Sopenharmony_ci * Copyright (C) 2022 Microchip Technology Inc.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _NET_DSA_DRIVERS_KSZ_PTP_H
962306a36Sopenharmony_ci#define _NET_DSA_DRIVERS_KSZ_PTP_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP)
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <linux/ptp_clock_kernel.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define KSZ_PTP_N_GPIO		2
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cienum ksz_ptp_tou_mode {
1862306a36Sopenharmony_ci	KSZ_PTP_TOU_IDLE,
1962306a36Sopenharmony_ci	KSZ_PTP_TOU_PEROUT,
2062306a36Sopenharmony_ci};
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cistruct ksz_ptp_data {
2362306a36Sopenharmony_ci	struct ptp_clock_info caps;
2462306a36Sopenharmony_ci	struct ptp_clock *clock;
2562306a36Sopenharmony_ci	struct ptp_pin_desc pin_config[KSZ_PTP_N_GPIO];
2662306a36Sopenharmony_ci	/* Serializes all operations on the PTP hardware clock */
2762306a36Sopenharmony_ci	struct mutex lock;
2862306a36Sopenharmony_ci	/* lock for accessing the clock_time */
2962306a36Sopenharmony_ci	spinlock_t clock_lock;
3062306a36Sopenharmony_ci	struct timespec64 clock_time;
3162306a36Sopenharmony_ci	enum ksz_ptp_tou_mode tou_mode;
3262306a36Sopenharmony_ci	struct timespec64 perout_target_time_first;  /* start of first pulse */
3362306a36Sopenharmony_ci	struct timespec64 perout_period;
3462306a36Sopenharmony_ci};
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciint ksz_ptp_clock_register(struct dsa_switch *ds);
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_civoid ksz_ptp_clock_unregister(struct dsa_switch *ds);
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ciint ksz_get_ts_info(struct dsa_switch *ds, int port,
4162306a36Sopenharmony_ci		    struct ethtool_ts_info *ts);
4262306a36Sopenharmony_ciint ksz_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr);
4362306a36Sopenharmony_ciint ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr);
4462306a36Sopenharmony_civoid ksz_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb);
4562306a36Sopenharmony_civoid ksz_port_deferred_xmit(struct kthread_work *work);
4662306a36Sopenharmony_cibool ksz_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb,
4762306a36Sopenharmony_ci		       unsigned int type);
4862306a36Sopenharmony_ciint ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p);
4962306a36Sopenharmony_civoid ksz_ptp_irq_free(struct dsa_switch *ds, u8 p);
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#else
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_cistruct ksz_ptp_data {
5462306a36Sopenharmony_ci	/* Serializes all operations on the PTP hardware clock */
5562306a36Sopenharmony_ci	struct mutex lock;
5662306a36Sopenharmony_ci};
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cistatic inline int ksz_ptp_clock_register(struct dsa_switch *ds)
5962306a36Sopenharmony_ci{
6062306a36Sopenharmony_ci	return 0;
6162306a36Sopenharmony_ci}
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cistatic inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { }
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistatic inline int ksz_ptp_irq_setup(struct dsa_switch *ds, u8 p)
6662306a36Sopenharmony_ci{
6762306a36Sopenharmony_ci	return 0;
6862306a36Sopenharmony_ci}
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistatic inline void ksz_ptp_irq_free(struct dsa_switch *ds, u8 p) {}
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define ksz_get_ts_info NULL
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define ksz_hwtstamp_get NULL
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#define ksz_hwtstamp_set NULL
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define ksz_port_rxtstamp NULL
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define ksz_port_txtstamp NULL
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#define ksz_port_deferred_xmit NULL
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#endif	/* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#endif
87