]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/pps_kernel.h
mm/hotplug: invalid PFNs from pfn_to_online_page()
[mirror_ubuntu-bionic-kernel.git] / include / linux / pps_kernel.h
CommitLineData
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 24#include <linux/pps.h>
eae9d2ba
RG
25#include <linux/cdev.h>
26#include <linux/device.h>
27#include <linux/time.h>
28
29/*
30 * Global defines
31 */
32
5e196d34
AG
33struct pps_device;
34
eae9d2ba
RG
35/* The specific PPS source info */
36struct pps_source_info {
a2d81803 37 char name[PPS_MAX_NAME_LEN]; /* symbolic name */
eae9d2ba 38 char path[PPS_MAX_NAME_LEN]; /* path of connected device */
a2d81803 39 int mode; /* PPS allowed mode */
eae9d2ba 40
5e196d34
AG
41 void (*echo)(struct pps_device *pps,
42 int event, void *data); /* PPS echo function */
eae9d2ba
RG
43
44 struct module *owner;
513b032c 45 struct device *dev; /* Parent device for device_create */
eae9d2ba
RG
46};
47
6f4229b5 48struct pps_event_time {
e2c18e49 49#ifdef CONFIG_NTP_PPS
ade1bdff 50 struct timespec64 ts_raw;
e2c18e49 51#endif /* CONFIG_NTP_PPS */
ade1bdff 52 struct timespec64 ts_real;
6f4229b5
AG
53};
54
eae9d2ba
RG
55/* The main struct */
56struct pps_device {
57 struct pps_source_info info; /* PSS source info */
58
a2d81803 59 struct pps_kparams params; /* PPS current params */
eae9d2ba 60
a2d81803
RD
61 __u32 assert_sequence; /* PPS assert event seq # */
62 __u32 clear_sequence; /* PPS clear event seq # */
eae9d2ba
RG
63 struct pps_ktime assert_tu;
64 struct pps_ktime clear_tu;
65 int current_mode; /* PPS mode at event time */
66
3003d55b 67 unsigned int last_ev; /* last PPS event id */
eae9d2ba
RG
68 wait_queue_head_t queue; /* PPS event queue */
69
70 unsigned int id; /* PPS source unique ID */
a2d81803 71 void const *lookup_cookie; /* For pps_lookup_dev() only */
eae9d2ba
RG
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
bd0eae4e 82extern const struct attribute_group *pps_groups[];
eae9d2ba 83
513b032c
GS
84/*
85 * Internal functions.
86 *
87 * These are not actually part of the exported API, but this is a
88 * convenient header file to put them in.
89 */
90
91extern int pps_register_cdev(struct pps_device *pps);
92extern void pps_unregister_cdev(struct pps_device *pps);
93
eae9d2ba
RG
94/*
95 * Exported functions
96 */
97
5e196d34
AG
98extern struct pps_device *pps_register_source(
99 struct pps_source_info *info, int default_params);
100extern void pps_unregister_source(struct pps_device *pps);
5e196d34
AG
101extern void pps_event(struct pps_device *pps,
102 struct pps_event_time *ts, int event, void *data);
a2d81803 103/* Look up a pps_device by magic cookie */
513b032c 104struct pps_device *pps_lookup_dev(void const *cookie);
6f4229b5
AG
105
106static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
ade1bdff 107 struct timespec64 ts)
6f4229b5
AG
108{
109 kt->sec = ts.tv_sec;
110 kt->nsec = ts.tv_nsec;
111}
112
e2c18e49
AG
113static inline void pps_get_ts(struct pps_event_time *ts)
114{
ba26621e 115 struct system_time_snapshot snap;
e2c18e49 116
ba26621e
CH
117 ktime_get_snapshot(&snap);
118 ts->ts_real = ktime_to_timespec64(snap.real);
119#ifdef CONFIG_NTP_PPS
120 ts->ts_raw = ktime_to_timespec64(snap.raw);
121#endif
6f4229b5 122}
7a21a3cc 123
220a60a4 124/* Subtract known time delay from PPS event time(s) */
ade1bdff 125static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
220a60a4 126{
ade1bdff 127 ts->ts_real = timespec64_sub(ts->ts_real, delta);
220a60a4 128#ifdef CONFIG_NTP_PPS
ade1bdff 129 ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
220a60a4
BH
130#endif
131}
132
7a21a3cc 133#endif /* LINUX_PPS_KERNEL_H */