1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */ 2*4882a593Smuzhiyun /* Copyright (C) 2018 Microchip Technology Inc. */ 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun #ifndef _LAN743X_PTP_H 5*4882a593Smuzhiyun #define _LAN743X_PTP_H 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun #include "linux/ptp_clock_kernel.h" 8*4882a593Smuzhiyun #include "linux/netdevice.h" 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #define LAN7430_N_LED 4 11*4882a593Smuzhiyun #define LAN7430_N_GPIO 4 /* multiplexed with PHY LEDs */ 12*4882a593Smuzhiyun #define LAN7431_N_GPIO 12 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun #define LAN743X_PTP_N_GPIO LAN7431_N_GPIO 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun /* the number of periodic outputs is limited by number of 17*4882a593Smuzhiyun * PTP clock event channels 18*4882a593Smuzhiyun */ 19*4882a593Smuzhiyun #define LAN743X_PTP_N_EVENT_CHAN 2 20*4882a593Smuzhiyun #define LAN743X_PTP_N_PEROUT LAN743X_PTP_N_EVENT_CHAN 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun struct lan743x_adapter; 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun /* GPIO */ 25*4882a593Smuzhiyun struct lan743x_gpio { 26*4882a593Smuzhiyun /* gpio_lock: used to prevent concurrent access to gpio settings */ 27*4882a593Smuzhiyun spinlock_t gpio_lock; 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun int used_bits; 30*4882a593Smuzhiyun int output_bits; 31*4882a593Smuzhiyun int ptp_bits; 32*4882a593Smuzhiyun u32 gpio_cfg0; 33*4882a593Smuzhiyun u32 gpio_cfg1; 34*4882a593Smuzhiyun u32 gpio_cfg2; 35*4882a593Smuzhiyun u32 gpio_cfg3; 36*4882a593Smuzhiyun }; 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun int lan743x_gpio_init(struct lan743x_adapter *adapter); 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun void lan743x_ptp_isr(void *context); 41*4882a593Smuzhiyun bool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter); 42*4882a593Smuzhiyun void lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter); 43*4882a593Smuzhiyun void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter, 44*4882a593Smuzhiyun struct sk_buff *skb, bool ignore_sync); 45*4882a593Smuzhiyun int lan743x_ptp_init(struct lan743x_adapter *adapter); 46*4882a593Smuzhiyun int lan743x_ptp_open(struct lan743x_adapter *adapter); 47*4882a593Smuzhiyun void lan743x_ptp_close(struct lan743x_adapter *adapter); 48*4882a593Smuzhiyun void lan743x_ptp_update_latency(struct lan743x_adapter *adapter, 49*4882a593Smuzhiyun u32 link_speed); 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun #define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4) 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun #define PTP_FLAG_PTP_CLOCK_REGISTERED BIT(1) 56*4882a593Smuzhiyun #define PTP_FLAG_ISR_ENABLED BIT(2) 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun struct lan743x_ptp_perout { 59*4882a593Smuzhiyun int event_ch; /* PTP event channel (0=channel A, 1=channel B) */ 60*4882a593Smuzhiyun int gpio_pin; /* GPIO pin where output appears */ 61*4882a593Smuzhiyun }; 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun struct lan743x_ptp { 64*4882a593Smuzhiyun int flags; 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun /* command_lock: used to prevent concurrent ptp commands */ 67*4882a593Smuzhiyun struct mutex command_lock; 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun struct ptp_clock *ptp_clock; 70*4882a593Smuzhiyun struct ptp_clock_info ptp_clock_info; 71*4882a593Smuzhiyun struct ptp_pin_desc pin_config[LAN743X_PTP_N_GPIO]; 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun unsigned long used_event_ch; 74*4882a593Smuzhiyun struct lan743x_ptp_perout perout[LAN743X_PTP_N_PEROUT]; 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun bool leds_multiplexed; 77*4882a593Smuzhiyun bool led_enabled[LAN7430_N_LED]; 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */ 80*4882a593Smuzhiyun spinlock_t tx_ts_lock; 81*4882a593Smuzhiyun int pending_tx_timestamps; 82*4882a593Smuzhiyun struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 83*4882a593Smuzhiyun unsigned int tx_ts_ignore_sync_queue; 84*4882a593Smuzhiyun int tx_ts_skb_queue_size; 85*4882a593Smuzhiyun u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 86*4882a593Smuzhiyun u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 87*4882a593Smuzhiyun u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 88*4882a593Smuzhiyun int tx_ts_queue_size; 89*4882a593Smuzhiyun }; 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun #endif /* _LAN743X_PTP_H */ 92