Commit | Line | Data |
---|---|---|
eae9d2ba RG |
1 | /* |
2 | * PPS API kernel header | |
3 | * | |
4 | * Copyright (C) 2009 Rodolfo Giometti <giometti@linux.it> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | */ | |
20 | ||
7a21a3cc AG |
21 | #ifndef LINUX_PPS_KERNEL_H |
22 | #define LINUX_PPS_KERNEL_H | |
23 | ||
eae9d2ba RG |
24 | #include <linux/pps.h> |
25 | ||
26 | #include <linux/cdev.h> | |
27 | #include <linux/device.h> | |
28 | #include <linux/time.h> | |
29 | ||
30 | /* | |
31 | * Global defines | |
32 | */ | |
33 | ||
5e196d34 AG |
34 | struct pps_device; |
35 | ||
eae9d2ba RG |
36 | /* The specific PPS source info */ |
37 | struct pps_source_info { | |
38 | char name[PPS_MAX_NAME_LEN]; /* simbolic name */ | |
39 | char path[PPS_MAX_NAME_LEN]; /* path of connected device */ | |
40 | int mode; /* PPS's allowed mode */ | |
41 | ||
5e196d34 AG |
42 | void (*echo)(struct pps_device *pps, |
43 | int event, void *data); /* PPS echo function */ | |
eae9d2ba RG |
44 | |
45 | struct module *owner; | |
46 | struct device *dev; | |
47 | }; | |
48 | ||
6f4229b5 | 49 | struct pps_event_time { |
e2c18e49 AG |
50 | #ifdef CONFIG_NTP_PPS |
51 | struct timespec ts_raw; | |
52 | #endif /* CONFIG_NTP_PPS */ | |
6f4229b5 AG |
53 | struct timespec ts_real; |
54 | }; | |
55 | ||
eae9d2ba RG |
56 | /* The main struct */ |
57 | struct pps_device { | |
58 | struct pps_source_info info; /* PSS source info */ | |
59 | ||
60 | struct pps_kparams params; /* PPS's current params */ | |
61 | ||
62 | __u32 assert_sequence; /* PPS' assert event seq # */ | |
63 | __u32 clear_sequence; /* PPS' clear event seq # */ | |
64 | struct pps_ktime assert_tu; | |
65 | struct pps_ktime clear_tu; | |
66 | int current_mode; /* PPS mode at event time */ | |
67 | ||
3003d55b | 68 | unsigned int last_ev; /* last PPS event id */ |
eae9d2ba RG |
69 | wait_queue_head_t queue; /* PPS event queue */ |
70 | ||
71 | unsigned int id; /* PPS source unique ID */ | |
72 | struct cdev cdev; | |
73 | struct device *dev; | |
eae9d2ba RG |
74 | struct fasync_struct *async_queue; /* fasync method */ |
75 | spinlock_t lock; | |
eae9d2ba RG |
76 | }; |
77 | ||
78 | /* | |
79 | * Global variables | |
80 | */ | |
81 | ||
eae9d2ba RG |
82 | extern struct device_attribute pps_attrs[]; |
83 | ||
84 | /* | |
85 | * Exported functions | |
86 | */ | |
87 | ||
5e196d34 AG |
88 | extern struct pps_device *pps_register_source( |
89 | struct pps_source_info *info, int default_params); | |
90 | extern void pps_unregister_source(struct pps_device *pps); | |
eae9d2ba RG |
91 | extern int pps_register_cdev(struct pps_device *pps); |
92 | extern void pps_unregister_cdev(struct pps_device *pps); | |
5e196d34 AG |
93 | extern void pps_event(struct pps_device *pps, |
94 | struct pps_event_time *ts, int event, void *data); | |
6f4229b5 AG |
95 | |
96 | static inline void timespec_to_pps_ktime(struct pps_ktime *kt, | |
97 | struct timespec ts) | |
98 | { | |
99 | kt->sec = ts.tv_sec; | |
100 | kt->nsec = ts.tv_nsec; | |
101 | } | |
102 | ||
e2c18e49 AG |
103 | #ifdef CONFIG_NTP_PPS |
104 | ||
105 | static inline void pps_get_ts(struct pps_event_time *ts) | |
106 | { | |
107 | getnstime_raw_and_real(&ts->ts_raw, &ts->ts_real); | |
108 | } | |
109 | ||
110 | #else /* CONFIG_NTP_PPS */ | |
111 | ||
6f4229b5 AG |
112 | static inline void pps_get_ts(struct pps_event_time *ts) |
113 | { | |
114 | getnstimeofday(&ts->ts_real); | |
115 | } | |
7a21a3cc | 116 | |
e2c18e49 AG |
117 | #endif /* CONFIG_NTP_PPS */ |
118 | ||
7a21a3cc | 119 | #endif /* LINUX_PPS_KERNEL_H */ |
6f4229b5 | 120 |