162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 262306a36Sopenharmony_ci/* Copyright (C) 2018 Microchip Technology Inc. */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#ifndef _LAN743X_PTP_H 562306a36Sopenharmony_ci#define _LAN743X_PTP_H 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include "linux/ptp_clock_kernel.h" 862306a36Sopenharmony_ci#include "linux/netdevice.h" 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#define LAN7430_N_LED 4 1162306a36Sopenharmony_ci#define LAN7430_N_GPIO 4 /* multiplexed with PHY LEDs */ 1262306a36Sopenharmony_ci#define LAN7431_N_GPIO 12 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define LAN743X_PTP_N_GPIO LAN7431_N_GPIO 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* the number of periodic outputs is limited by number of 1762306a36Sopenharmony_ci * PTP clock event channels 1862306a36Sopenharmony_ci */ 1962306a36Sopenharmony_ci#define LAN743X_PTP_N_EVENT_CHAN 2 2062306a36Sopenharmony_ci#define LAN743X_PTP_N_PEROUT LAN743X_PTP_N_EVENT_CHAN 2162306a36Sopenharmony_ci#define LAN743X_PTP_N_EXTTS 4 2262306a36Sopenharmony_ci#define LAN743X_PTP_N_PPS 0 2362306a36Sopenharmony_ci#define PCI11X1X_PTP_IO_MAX_CHANNELS 8 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistruct lan743x_adapter; 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* GPIO */ 2862306a36Sopenharmony_cistruct lan743x_gpio { 2962306a36Sopenharmony_ci /* gpio_lock: used to prevent concurrent access to gpio settings */ 3062306a36Sopenharmony_ci spinlock_t gpio_lock; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci int used_bits; 3362306a36Sopenharmony_ci int output_bits; 3462306a36Sopenharmony_ci int ptp_bits; 3562306a36Sopenharmony_ci u32 gpio_cfg0; 3662306a36Sopenharmony_ci u32 gpio_cfg1; 3762306a36Sopenharmony_ci u32 gpio_cfg2; 3862306a36Sopenharmony_ci u32 gpio_cfg3; 3962306a36Sopenharmony_ci}; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciint lan743x_gpio_init(struct lan743x_adapter *adapter); 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_civoid lan743x_ptp_isr(void *context); 4462306a36Sopenharmony_cibool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter); 4562306a36Sopenharmony_civoid lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter); 4662306a36Sopenharmony_civoid lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter, 4762306a36Sopenharmony_ci struct sk_buff *skb, bool ignore_sync); 4862306a36Sopenharmony_ciint lan743x_ptp_init(struct lan743x_adapter *adapter); 4962306a36Sopenharmony_ciint lan743x_ptp_open(struct lan743x_adapter *adapter); 5062306a36Sopenharmony_civoid lan743x_ptp_close(struct lan743x_adapter *adapter); 5162306a36Sopenharmony_civoid lan743x_ptp_update_latency(struct lan743x_adapter *adapter, 5262306a36Sopenharmony_ci u32 link_speed); 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ciint lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4) 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define PTP_FLAG_PTP_CLOCK_REGISTERED BIT(1) 5962306a36Sopenharmony_ci#define PTP_FLAG_ISR_ENABLED BIT(2) 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_cistruct lan743x_ptp_perout { 6262306a36Sopenharmony_ci int event_ch; /* PTP event channel (0=channel A, 1=channel B) */ 6362306a36Sopenharmony_ci int gpio_pin; /* GPIO pin where output appears */ 6462306a36Sopenharmony_ci}; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_cistruct lan743x_extts { 6762306a36Sopenharmony_ci int flags; 6862306a36Sopenharmony_ci struct timespec64 ts; 6962306a36Sopenharmony_ci}; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_cistruct lan743x_ptp { 7262306a36Sopenharmony_ci int flags; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci /* command_lock: used to prevent concurrent ptp commands */ 7562306a36Sopenharmony_ci struct mutex command_lock; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci struct ptp_clock *ptp_clock; 7862306a36Sopenharmony_ci struct ptp_clock_info ptp_clock_info; 7962306a36Sopenharmony_ci struct ptp_pin_desc pin_config[LAN743X_PTP_N_GPIO]; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci unsigned long used_event_ch; 8262306a36Sopenharmony_ci struct lan743x_ptp_perout perout[LAN743X_PTP_N_PEROUT]; 8362306a36Sopenharmony_ci int ptp_io_perout[LAN743X_PTP_N_PEROUT]; /* PTP event channel (0=channel A, 1=channel B) */ 8462306a36Sopenharmony_ci struct lan743x_extts extts[LAN743X_PTP_N_EXTTS]; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci bool leds_multiplexed; 8762306a36Sopenharmony_ci bool led_enabled[LAN7430_N_LED]; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */ 9062306a36Sopenharmony_ci spinlock_t tx_ts_lock; 9162306a36Sopenharmony_ci int pending_tx_timestamps; 9262306a36Sopenharmony_ci struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 9362306a36Sopenharmony_ci unsigned int tx_ts_ignore_sync_queue; 9462306a36Sopenharmony_ci int tx_ts_skb_queue_size; 9562306a36Sopenharmony_ci u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 9662306a36Sopenharmony_ci u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 9762306a36Sopenharmony_ci u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 9862306a36Sopenharmony_ci int tx_ts_queue_size; 9962306a36Sopenharmony_ci}; 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#endif /* _LAN743X_PTP_H */ 102