blob: 1edf24ac1355090e87dee80baebd78009e7349bb [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001/*
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
21#ifndef LINUX_PPS_KERNEL_H
22#define LINUX_PPS_KERNEL_H
23
24#include <linux/pps.h>
25
26#include <linux/cdev.h>
27#include <linux/device.h>
28#include <linux/time.h>
29
30
31struct pps_device;
32
33struct pps_source_info {
34 char name[PPS_MAX_NAME_LEN];
35 char path[PPS_MAX_NAME_LEN];
36 int mode;
37
38 void (*echo)(struct pps_device *pps,
39 int event, void *data);
40
41 struct module *owner;
42 struct device *dev;
43};
44
45struct pps_event_time {
46#ifdef CONFIG_NTP_PPS
47 struct timespec ts_raw;
48#endif
49 struct timespec ts_real;
50};
51
52struct pps_device {
53 struct pps_source_info info;
54
55 struct pps_kparams params;
56
57 __u32 assert_sequence;
58 __u32 clear_sequence;
59 struct pps_ktime assert_tu;
60 struct pps_ktime clear_tu;
61 int current_mode;
62
63 unsigned int last_ev;
64 wait_queue_head_t queue;
65
66 unsigned int id;
67 struct cdev cdev;
68 struct device *dev;
69 struct fasync_struct *async_queue;
70 spinlock_t lock;
71};
72
73
74extern struct device_attribute pps_attrs[];
75
76
77extern struct pps_device *pps_register_source(
78 struct pps_source_info *info, int default_params);
79extern void pps_unregister_source(struct pps_device *pps);
80extern int pps_register_cdev(struct pps_device *pps);
81extern void pps_unregister_cdev(struct pps_device *pps);
82extern void pps_event(struct pps_device *pps,
83 struct pps_event_time *ts, int event, void *data);
84
85static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
86 struct timespec ts)
87{
88 kt->sec = ts.tv_sec;
89 kt->nsec = ts.tv_nsec;
90}
91
92#ifdef CONFIG_NTP_PPS
93
94static inline void pps_get_ts(struct pps_event_time *ts)
95{
96 getnstime_raw_and_real(&ts->ts_raw, &ts->ts_real);
97}
98
99#else
100
101static inline void pps_get_ts(struct pps_event_time *ts)
102{
103 getnstimeofday(&ts->ts_real);
104}
105
106#endif
107
108#endif
109