Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * PTP 1588 clock support - private declarations for the core module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (C) 2010 OMICRON electronics GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #ifndef _PTP_PRIVATE_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #define _PTP_PRIVATE_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/cdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/posix-clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/ptp_clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/ptp_clock_kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define PTP_MAX_TIMESTAMPS 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define PTP_BUF_TIMESTAMPS 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct timestamp_event_queue {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	int head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	int tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct ptp_clock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	struct posix_clock clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	struct device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	struct ptp_clock_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	dev_t devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	int index; /* index into clocks.map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	struct pps_device *pps_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	long dialed_frequency; /* remembers the frequency adjustment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	struct timestamp_event_queue tsevq; /* simple fifo for time stamps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	struct mutex tsevq_mux; /* one process at a time reading the fifo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	wait_queue_head_t tsev_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	int defunct; /* tells readers to go away when clock is being removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	struct device_attribute *pin_dev_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	struct attribute **pin_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	struct attribute_group pin_attr_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	/* 1st entry is a pointer to the real group, 2nd is NULL terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	const struct attribute_group *pin_attr_groups[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	struct kthread_worker *kworker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	struct kthread_delayed_work aux_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)  * The function queue_cnt() is safe for readers to call without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)  * holding q->lock. Readers use this function to verify that the queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)  * is nonempty before proceeding with a dequeue operation. The fact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)  * that a writer might concurrently increment the tail does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)  * matter, since the queue remains nonempty nonetheless.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static inline int queue_cnt(struct timestamp_event_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	int cnt = q->tail - q->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	return cnt < 0 ? PTP_MAX_TIMESTAMPS + cnt : cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)  * see ptp_chardev.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* caller must hold pincfg_mux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		    enum ptp_pin_function func, unsigned int chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) long ptp_ioctl(struct posix_clock *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	       unsigned int cmd, unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int ptp_open(struct posix_clock *pc, fmode_t fmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ssize_t ptp_read(struct posix_clock *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		 uint flags, char __user *buf, size_t cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) __poll_t ptp_poll(struct posix_clock *pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	      struct file *fp, poll_table *wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)  * see ptp_sysfs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) extern const struct attribute_group *ptp_groups[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int ptp_populate_pin_groups(struct ptp_clock *ptp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) void ptp_cleanup_pin_groups(struct ptp_clock *ptp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #endif