18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* Copyright (C) 2018 Microchip Technology Inc. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _LAN743X_PTP_H 58c2ecf20Sopenharmony_ci#define _LAN743X_PTP_H 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include "linux/ptp_clock_kernel.h" 88c2ecf20Sopenharmony_ci#include "linux/netdevice.h" 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define LAN7430_N_LED 4 118c2ecf20Sopenharmony_ci#define LAN7430_N_GPIO 4 /* multiplexed with PHY LEDs */ 128c2ecf20Sopenharmony_ci#define LAN7431_N_GPIO 12 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define LAN743X_PTP_N_GPIO LAN7431_N_GPIO 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* the number of periodic outputs is limited by number of 178c2ecf20Sopenharmony_ci * PTP clock event channels 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci#define LAN743X_PTP_N_EVENT_CHAN 2 208c2ecf20Sopenharmony_ci#define LAN743X_PTP_N_PEROUT LAN743X_PTP_N_EVENT_CHAN 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistruct lan743x_adapter; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* GPIO */ 258c2ecf20Sopenharmony_cistruct lan743x_gpio { 268c2ecf20Sopenharmony_ci /* gpio_lock: used to prevent concurrent access to gpio settings */ 278c2ecf20Sopenharmony_ci spinlock_t gpio_lock; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci int used_bits; 308c2ecf20Sopenharmony_ci int output_bits; 318c2ecf20Sopenharmony_ci int ptp_bits; 328c2ecf20Sopenharmony_ci u32 gpio_cfg0; 338c2ecf20Sopenharmony_ci u32 gpio_cfg1; 348c2ecf20Sopenharmony_ci u32 gpio_cfg2; 358c2ecf20Sopenharmony_ci u32 gpio_cfg3; 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciint lan743x_gpio_init(struct lan743x_adapter *adapter); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_civoid lan743x_ptp_isr(void *context); 418c2ecf20Sopenharmony_cibool lan743x_ptp_request_tx_timestamp(struct lan743x_adapter *adapter); 428c2ecf20Sopenharmony_civoid lan743x_ptp_unrequest_tx_timestamp(struct lan743x_adapter *adapter); 438c2ecf20Sopenharmony_civoid lan743x_ptp_tx_timestamp_skb(struct lan743x_adapter *adapter, 448c2ecf20Sopenharmony_ci struct sk_buff *skb, bool ignore_sync); 458c2ecf20Sopenharmony_ciint lan743x_ptp_init(struct lan743x_adapter *adapter); 468c2ecf20Sopenharmony_ciint lan743x_ptp_open(struct lan743x_adapter *adapter); 478c2ecf20Sopenharmony_civoid lan743x_ptp_close(struct lan743x_adapter *adapter); 488c2ecf20Sopenharmony_civoid lan743x_ptp_update_latency(struct lan743x_adapter *adapter, 498c2ecf20Sopenharmony_ci u32 link_speed); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciint lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS (4) 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define PTP_FLAG_PTP_CLOCK_REGISTERED BIT(1) 568c2ecf20Sopenharmony_ci#define PTP_FLAG_ISR_ENABLED BIT(2) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistruct lan743x_ptp_perout { 598c2ecf20Sopenharmony_ci int event_ch; /* PTP event channel (0=channel A, 1=channel B) */ 608c2ecf20Sopenharmony_ci int gpio_pin; /* GPIO pin where output appears */ 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistruct lan743x_ptp { 648c2ecf20Sopenharmony_ci int flags; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci /* command_lock: used to prevent concurrent ptp commands */ 678c2ecf20Sopenharmony_ci struct mutex command_lock; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci struct ptp_clock *ptp_clock; 708c2ecf20Sopenharmony_ci struct ptp_clock_info ptp_clock_info; 718c2ecf20Sopenharmony_ci struct ptp_pin_desc pin_config[LAN743X_PTP_N_GPIO]; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci unsigned long used_event_ch; 748c2ecf20Sopenharmony_ci struct lan743x_ptp_perout perout[LAN743X_PTP_N_PEROUT]; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci bool leds_multiplexed; 778c2ecf20Sopenharmony_ci bool led_enabled[LAN7430_N_LED]; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci /* tx_ts_lock: used to prevent concurrent access to timestamp arrays */ 808c2ecf20Sopenharmony_ci spinlock_t tx_ts_lock; 818c2ecf20Sopenharmony_ci int pending_tx_timestamps; 828c2ecf20Sopenharmony_ci struct sk_buff *tx_ts_skb_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 838c2ecf20Sopenharmony_ci unsigned int tx_ts_ignore_sync_queue; 848c2ecf20Sopenharmony_ci int tx_ts_skb_queue_size; 858c2ecf20Sopenharmony_ci u32 tx_ts_seconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 868c2ecf20Sopenharmony_ci u32 tx_ts_nseconds_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 878c2ecf20Sopenharmony_ci u32 tx_ts_header_queue[LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS]; 888c2ecf20Sopenharmony_ci int tx_ts_queue_size; 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#endif /* _LAN743X_PTP_H */ 92