107624df1SBryan Whitehead /* SPDX-License-Identifier: GPL-2.0+ */ 207624df1SBryan Whitehead /* Copyright (C) 2018 Microchip Technology Inc. */ 307624df1SBryan Whitehead 407624df1SBryan Whitehead #ifndef _LAN743X_PTP_H 507624df1SBryan Whitehead #define _LAN743X_PTP_H 607624df1SBryan Whitehead 707624df1SBryan Whitehead #include "linux/ptp_clock_kernel.h" 807624df1SBryan Whitehead #include "linux/netdevice.h" 907624df1SBryan Whitehead 1022820017SJohn Efstathiades #define LAN7430_N_LED 4 1122820017SJohn Efstathiades #define LAN7430_N_GPIO 4 /* multiplexed with PHY LEDs */ 1222820017SJohn Efstathiades #define LAN7431_N_GPIO 12 1322820017SJohn Efstathiades 1422820017SJohn Efstathiades #define LAN743X_PTP_N_GPIO LAN7431_N_GPIO 1522820017SJohn Efstathiades 1622820017SJohn Efstathiades /* the number of periodic outputs is limited by number of 1722820017SJohn Efstathiades * PTP clock event channels 1822820017SJohn Efstathiades */ 1922820017SJohn Efstathiades #define LAN743X_PTP_N_EVENT_CHAN 2 2022820017SJohn Efstathiades #define LAN743X_PTP_N_PEROUT LAN743X_PTP_N_EVENT_CHAN 2160942c39SRaju Lakkaraju #define LAN743X_PTP_N_EXTTS 4 2260942c39SRaju Lakkaraju #define LAN743X_PTP_N_PPS 0 2360942c39SRaju Lakkaraju #define PCI11X1X_PTP_IO_MAX_CHANNELS 8 2422820017SJohn Efstathiades 2507624df1SBryan Whitehead struct lan743x_adapter; 2607624df1SBryan Whitehead 2707624df1SBryan Whitehead /* GPIO */ 2807624df1SBryan Whitehead struct lan743x_gpio { 2907624df1SBryan Whitehead /* gpio_lock: used to prevent concurrent access to gpio settings */ 3007624df1SBryan Whitehead spinlock_t gpio_lock; 3107624df1SBryan Whitehead 3207624df1SBryan Whitehead int used_bits; 3307624df1SBryan Whitehead int output_bits; 3407624df1SBryan Whitehead int ptp_bits; 3507624df1SBryan Whitehead u32 gpio_cfg0; 3607624df1SBryan Whitehead u32 gpio_cfg1; 3707624df1SBryan Whitehead u32 gpio_cfg2; 3807624df1SBryan Whitehead u32 gpio_cfg3; 3907624df1SBryan Whitehead }; 4007624df1SBryan Whitehead 4107624df1SBryan Whitehead int lan743x_gpio_init(struct lan743x_adapter *adapter); 4207624df1SBryan Whitehead 4307624df1SBryan Whitehead void lan743x_ptp_isr(void *context); 4407624df1SBryan Whitehead bool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter); 4507624df1SBryan Whitehead void lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter); 4607624df1SBryan Whitehead void lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter, 4707624df1SBryan Whitehead struct sk_buff *skb, bool ignore_sync); 4807624df1SBryan Whitehead int lan743x_ptp_init(struct lan743x_adapter *adapter); 4907624df1SBryan Whitehead int lan743x_ptp_open(struct lan743x_adapter *adapter); 5007624df1SBryan Whitehead void lan743x_ptp_close(struct lan743x_adapter *adapter); 5107624df1SBryan Whitehead void lan743x_ptp_update_latency(struct lan743x_adapter *adapter, 5207624df1SBryan Whitehead u32 link_speed); 5307624df1SBryan Whitehead 5407624df1SBryan Whitehead int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); 5507624df1SBryan Whitehead 5607624df1SBryan Whitehead #define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4) 5707624df1SBryan Whitehead 5807624df1SBryan Whitehead #define PTP_FLAG_PTP_CLOCK_REGISTERED BIT(1) 5907624df1SBryan Whitehead #define PTP_FLAG_ISR_ENABLED BIT(2) 6007624df1SBryan Whitehead 6122820017SJohn Efstathiades struct lan743x_ptp_perout { 6222820017SJohn Efstathiades int event_ch; /* PTP event channel (0=channel A, 1=channel B) */ 6322820017SJohn Efstathiades int gpio_pin; /* GPIO pin where output appears */ 6422820017SJohn Efstathiades }; 6522820017SJohn Efstathiades 6660942c39SRaju Lakkaraju struct lan743x_extts { 6760942c39SRaju Lakkaraju int flags; 6860942c39SRaju Lakkaraju struct timespec64 ts; 6960942c39SRaju Lakkaraju }; 7060942c39SRaju Lakkaraju 7107624df1SBryan Whitehead struct lan743x_ptp { 7207624df1SBryan Whitehead int flags; 7307624df1SBryan Whitehead 7407624df1SBryan Whitehead /* command_lock: used to prevent concurrent ptp commands */ 7507624df1SBryan Whitehead struct mutex command_lock; 7607624df1SBryan Whitehead 7707624df1SBryan Whitehead struct ptp_clock *ptp_clock; 7807624df1SBryan Whitehead struct ptp_clock_info ptp_clock_info; 7922820017SJohn Efstathiades struct ptp_pin_desc pin_config[LAN743X_PTP_N_GPIO]; 8007624df1SBryan Whitehead 8107624df1SBryan Whitehead unsigned long used_event_ch; 8222820017SJohn Efstathiades struct lan743x_ptp_perout perout[LAN743X_PTP_N_PEROUT]; 83*e432dd3bSRaju Lakkaraju int ptp_io_perout[LAN743X_PTP_N_PEROUT]; /* PTP event channel (0=channel A, 1=channel B) */ 8460942c39SRaju Lakkaraju struct lan743x_extts extts[LAN743X_PTP_N_EXTTS]; 8507624df1SBryan Whitehead 8622820017SJohn Efstathiades bool leds_multiplexed; 8722820017SJohn Efstathiades bool led_enabled[LAN7430_N_LED]; 8807624df1SBryan Whitehead 8907624df1SBryan Whitehead /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */ 9007624df1SBryan Whitehead spinlock_t tx_ts_lock; 9107624df1SBryan Whitehead int pending_tx_timestamps; 9207624df1SBryan Whitehead struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 9307624df1SBryan Whitehead unsigned int tx_ts_ignore_sync_queue; 9407624df1SBryan Whitehead int tx_ts_skb_queue_size; 9507624df1SBryan Whitehead u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 9607624df1SBryan Whitehead u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 9707624df1SBryan Whitehead u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 9807624df1SBryan Whitehead int tx_ts_queue_size; 9907624df1SBryan Whitehead }; 10007624df1SBryan Whitehead 10107624df1SBryan Whitehead #endif /* _LAN743X_PTP_H */ 102