1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (C) 2018 Microchip Technology Inc. */
7 #include "linux/ptp_clock_kernel.h"
8 #include "linux/netdevice.h"
10 #define LAN7430_N_LED 4
11 #define LAN7430_N_GPIO 4 /* multiplexed with PHY LEDs */
12 #define LAN7431_N_GPIO 12
14 #define LAN743X_PTP_N_GPIO LAN7431_N_GPIO
16 /* the number of periodic outputs is limited by number of
17 * PTP clock event channels
19 #define LAN743X_PTP_N_EVENT_CHAN 2
20 #define LAN743X_PTP_N_PEROUT LAN743X_PTP_N_EVENT_CHAN
22 struct lan743x_adapter;
26 /* gpio_lock: used to prevent concurrent access to gpio settings */
38 int lan743x_gpio_init(struct lan743x_adapter *adapter);
40 void lan743x_ptp_isr(void *context);
41 bool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter);
42 void lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter);
43 void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter,
44 struct sk_buff *skb, bool ignore_sync);
45 int lan743x_ptp_init(struct lan743x_adapter *adapter);
46 int lan743x_ptp_open(struct lan743x_adapter *adapter);
47 void lan743x_ptp_close(struct lan743x_adapter *adapter);
48 void lan743x_ptp_update_latency(struct lan743x_adapter *adapter,
51 int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
53 #define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4)
55 #define PTP_FLAG_PTP_CLOCK_REGISTERED BIT(1)
56 #define PTP_FLAG_ISR_ENABLED BIT(2)
58 struct lan743x_ptp_perout {
59 int event_ch; /* PTP event channel (0=channel A, 1=channel B) */
60 int gpio_pin; /* GPIO pin where output appears */
66 /* command_lock: used to prevent concurrent ptp commands */
67 struct mutex command_lock;
69 struct ptp_clock *ptp_clock;
70 struct ptp_clock_info ptp_clock_info;
71 struct ptp_pin_desc pin_config[LAN743X_PTP_N_GPIO];
73 unsigned long used_event_ch;
74 struct lan743x_ptp_perout perout[LAN743X_PTP_N_PEROUT];
76 bool leds_multiplexed;
77 bool led_enabled[LAN7430_N_LED];
79 /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */
80 spinlock_t tx_ts_lock;
81 int pending_tx_timestamps;
82 struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
83 unsigned int tx_ts_ignore_sync_queue;
84 int tx_ts_skb_queue_size;
85 u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
86 u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
87 u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS];
91 #endif /* _LAN743X_PTP_H */