xref: /linux-6.15/include/linux/pps_kernel.h (revision 3003d55b)
1eae9d2baSRodolfo Giometti /*
2eae9d2baSRodolfo Giometti  * PPS API kernel header
3eae9d2baSRodolfo Giometti  *
4eae9d2baSRodolfo Giometti  * Copyright (C) 2009   Rodolfo Giometti <[email protected]>
5eae9d2baSRodolfo Giometti  *
6eae9d2baSRodolfo Giometti  *   This program is free software; you can redistribute it and/or modify
7eae9d2baSRodolfo Giometti  *   it under the terms of the GNU General Public License as published by
8eae9d2baSRodolfo Giometti  *   the Free Software Foundation; either version 2 of the License, or
9eae9d2baSRodolfo Giometti  *   (at your option) any later version.
10eae9d2baSRodolfo Giometti  *
11eae9d2baSRodolfo Giometti  *   This program is distributed in the hope that it will be useful,
12eae9d2baSRodolfo Giometti  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13eae9d2baSRodolfo Giometti  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14eae9d2baSRodolfo Giometti  *   GNU General Public License for more details.
15eae9d2baSRodolfo Giometti  *
16eae9d2baSRodolfo Giometti  *   You should have received a copy of the GNU General Public License
17eae9d2baSRodolfo Giometti  *   along with this program; if not, write to the Free Software
18eae9d2baSRodolfo Giometti  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19eae9d2baSRodolfo Giometti  */
20eae9d2baSRodolfo Giometti 
217a21a3ccSAlexander Gordeev #ifndef LINUX_PPS_KERNEL_H
227a21a3ccSAlexander Gordeev #define LINUX_PPS_KERNEL_H
237a21a3ccSAlexander Gordeev 
24eae9d2baSRodolfo Giometti #include <linux/pps.h>
25eae9d2baSRodolfo Giometti 
26eae9d2baSRodolfo Giometti #include <linux/cdev.h>
27eae9d2baSRodolfo Giometti #include <linux/device.h>
28eae9d2baSRodolfo Giometti #include <linux/time.h>
29eae9d2baSRodolfo Giometti 
30eae9d2baSRodolfo Giometti /*
31eae9d2baSRodolfo Giometti  * Global defines
32eae9d2baSRodolfo Giometti  */
33eae9d2baSRodolfo Giometti 
34eae9d2baSRodolfo Giometti /* The specific PPS source info */
35eae9d2baSRodolfo Giometti struct pps_source_info {
36eae9d2baSRodolfo Giometti 	char name[PPS_MAX_NAME_LEN];		/* simbolic name */
37eae9d2baSRodolfo Giometti 	char path[PPS_MAX_NAME_LEN];		/* path of connected device */
38eae9d2baSRodolfo Giometti 	int mode;				/* PPS's allowed mode */
39eae9d2baSRodolfo Giometti 
40eae9d2baSRodolfo Giometti 	void (*echo)(int source, int event, void *data); /* PPS echo function */
41eae9d2baSRodolfo Giometti 
42eae9d2baSRodolfo Giometti 	struct module *owner;
43eae9d2baSRodolfo Giometti 	struct device *dev;
44eae9d2baSRodolfo Giometti };
45eae9d2baSRodolfo Giometti 
46eae9d2baSRodolfo Giometti /* The main struct */
47eae9d2baSRodolfo Giometti struct pps_device {
48eae9d2baSRodolfo Giometti 	struct pps_source_info info;		/* PSS source info */
49eae9d2baSRodolfo Giometti 
50eae9d2baSRodolfo Giometti 	struct pps_kparams params;		/* PPS's current params */
51eae9d2baSRodolfo Giometti 
52eae9d2baSRodolfo Giometti 	__u32 assert_sequence;			/* PPS' assert event seq # */
53eae9d2baSRodolfo Giometti 	__u32 clear_sequence;			/* PPS' clear event seq # */
54eae9d2baSRodolfo Giometti 	struct pps_ktime assert_tu;
55eae9d2baSRodolfo Giometti 	struct pps_ktime clear_tu;
56eae9d2baSRodolfo Giometti 	int current_mode;			/* PPS mode at event time */
57eae9d2baSRodolfo Giometti 
58*3003d55bSAlexander Gordeev 	unsigned int last_ev;			/* last PPS event id */
59eae9d2baSRodolfo Giometti 	wait_queue_head_t queue;		/* PPS event queue */
60eae9d2baSRodolfo Giometti 
61eae9d2baSRodolfo Giometti 	unsigned int id;			/* PPS source unique ID */
62eae9d2baSRodolfo Giometti 	struct cdev cdev;
63eae9d2baSRodolfo Giometti 	struct device *dev;
64eae9d2baSRodolfo Giometti 	int devno;
65eae9d2baSRodolfo Giometti 	struct fasync_struct *async_queue;	/* fasync method */
66eae9d2baSRodolfo Giometti 	spinlock_t lock;
67eae9d2baSRodolfo Giometti 
68eae9d2baSRodolfo Giometti 	atomic_t usage;				/* usage count */
69eae9d2baSRodolfo Giometti };
70eae9d2baSRodolfo Giometti 
71eae9d2baSRodolfo Giometti /*
72eae9d2baSRodolfo Giometti  * Global variables
73eae9d2baSRodolfo Giometti  */
74eae9d2baSRodolfo Giometti 
75eae9d2baSRodolfo Giometti extern spinlock_t pps_idr_lock;
76eae9d2baSRodolfo Giometti extern struct idr pps_idr;
77eae9d2baSRodolfo Giometti 
78eae9d2baSRodolfo Giometti extern struct device_attribute pps_attrs[];
79eae9d2baSRodolfo Giometti 
80eae9d2baSRodolfo Giometti /*
81eae9d2baSRodolfo Giometti  * Exported functions
82eae9d2baSRodolfo Giometti  */
83eae9d2baSRodolfo Giometti 
84eae9d2baSRodolfo Giometti struct pps_device *pps_get_source(int source);
85eae9d2baSRodolfo Giometti extern void pps_put_source(struct pps_device *pps);
86eae9d2baSRodolfo Giometti extern int pps_register_source(struct pps_source_info *info,
87eae9d2baSRodolfo Giometti 				int default_params);
88eae9d2baSRodolfo Giometti extern void pps_unregister_source(int source);
89eae9d2baSRodolfo Giometti extern int pps_register_cdev(struct pps_device *pps);
90eae9d2baSRodolfo Giometti extern void pps_unregister_cdev(struct pps_device *pps);
91eae9d2baSRodolfo Giometti extern void pps_event(int source, struct pps_ktime *ts, int event, void *data);
927a21a3ccSAlexander Gordeev 
937a21a3ccSAlexander Gordeev #endif /* LINUX_PPS_KERNEL_H */
94