2019-05-20 15:19:02 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2009-06-18 07:28:37 +08:00
|
|
|
/*
|
|
|
|
* PPS API kernel header
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Rodolfo Giometti <giometti@linux.it>
|
|
|
|
*/
|
|
|
|
|
2011-01-13 09:00:49 +08:00
|
|
|
#ifndef LINUX_PPS_KERNEL_H
|
|
|
|
#define LINUX_PPS_KERNEL_H
|
|
|
|
|
2009-06-18 07:28:37 +08:00
|
|
|
#include <linux/pps.h>
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global defines
|
|
|
|
*/
|
|
|
|
|
2011-01-13 09:00:51 +08:00
|
|
|
struct pps_device;
|
|
|
|
|
2009-06-18 07:28:37 +08:00
|
|
|
/* The specific PPS source info */
|
|
|
|
struct pps_source_info {
|
2017-09-09 07:17:19 +08:00
|
|
|
char name[PPS_MAX_NAME_LEN]; /* symbolic name */
|
2009-06-18 07:28:37 +08:00
|
|
|
char path[PPS_MAX_NAME_LEN]; /* path of connected device */
|
2017-09-09 07:17:19 +08:00
|
|
|
int mode; /* PPS allowed mode */
|
2009-06-18 07:28:37 +08:00
|
|
|
|
2011-01-13 09:00:51 +08:00
|
|
|
void (*echo)(struct pps_device *pps,
|
|
|
|
int event, void *data); /* PPS echo function */
|
2009-06-18 07:28:37 +08:00
|
|
|
|
|
|
|
struct module *owner;
|
2013-02-10 17:08:32 +08:00
|
|
|
struct device *dev; /* Parent device for device_create */
|
2009-06-18 07:28:37 +08:00
|
|
|
};
|
|
|
|
|
2011-01-13 09:00:50 +08:00
|
|
|
struct pps_event_time {
|
2011-01-13 09:00:57 +08:00
|
|
|
#ifdef CONFIG_NTP_PPS
|
2015-09-29 04:21:31 +08:00
|
|
|
struct timespec64 ts_raw;
|
2011-01-13 09:00:57 +08:00
|
|
|
#endif /* CONFIG_NTP_PPS */
|
2015-09-29 04:21:31 +08:00
|
|
|
struct timespec64 ts_real;
|
2011-01-13 09:00:50 +08:00
|
|
|
};
|
|
|
|
|
2009-06-18 07:28:37 +08:00
|
|
|
/* The main struct */
|
|
|
|
struct pps_device {
|
|
|
|
struct pps_source_info info; /* PSS source info */
|
|
|
|
|
2017-09-09 07:17:19 +08:00
|
|
|
struct pps_kparams params; /* PPS current params */
|
2009-06-18 07:28:37 +08:00
|
|
|
|
2017-09-09 07:17:19 +08:00
|
|
|
__u32 assert_sequence; /* PPS assert event seq # */
|
|
|
|
__u32 clear_sequence; /* PPS clear event seq # */
|
2009-06-18 07:28:37 +08:00
|
|
|
struct pps_ktime assert_tu;
|
|
|
|
struct pps_ktime clear_tu;
|
|
|
|
int current_mode; /* PPS mode at event time */
|
|
|
|
|
2011-01-13 09:00:50 +08:00
|
|
|
unsigned int last_ev; /* last PPS event id */
|
2009-06-18 07:28:37 +08:00
|
|
|
wait_queue_head_t queue; /* PPS event queue */
|
|
|
|
|
|
|
|
unsigned int id; /* PPS source unique ID */
|
2017-09-09 07:17:19 +08:00
|
|
|
void const *lookup_cookie; /* For pps_lookup_dev() only */
|
2009-06-18 07:28:37 +08:00
|
|
|
struct cdev cdev;
|
|
|
|
struct device *dev;
|
|
|
|
struct fasync_struct *async_queue; /* fasync method */
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
|
|
|
|
2013-07-25 06:05:19 +08:00
|
|
|
extern const struct attribute_group *pps_groups[];
|
2009-06-18 07:28:37 +08:00
|
|
|
|
2013-02-10 17:08:32 +08:00
|
|
|
/*
|
|
|
|
* Internal functions.
|
|
|
|
*
|
|
|
|
* These are not actually part of the exported API, but this is a
|
|
|
|
* convenient header file to put them in.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern int pps_register_cdev(struct pps_device *pps);
|
|
|
|
extern void pps_unregister_cdev(struct pps_device *pps);
|
|
|
|
|
2009-06-18 07:28:37 +08:00
|
|
|
/*
|
|
|
|
* Exported functions
|
|
|
|
*/
|
|
|
|
|
2011-01-13 09:00:51 +08:00
|
|
|
extern struct pps_device *pps_register_source(
|
|
|
|
struct pps_source_info *info, int default_params);
|
|
|
|
extern void pps_unregister_source(struct pps_device *pps);
|
|
|
|
extern void pps_event(struct pps_device *pps,
|
|
|
|
struct pps_event_time *ts, int event, void *data);
|
2017-09-09 07:17:19 +08:00
|
|
|
/* Look up a pps_device by magic cookie */
|
2013-02-10 17:08:32 +08:00
|
|
|
struct pps_device *pps_lookup_dev(void const *cookie);
|
2011-01-13 09:00:50 +08:00
|
|
|
|
|
|
|
static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
|
2015-09-29 04:21:31 +08:00
|
|
|
struct timespec64 ts)
|
2011-01-13 09:00:50 +08:00
|
|
|
{
|
|
|
|
kt->sec = ts.tv_sec;
|
|
|
|
kt->nsec = ts.tv_nsec;
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:00:57 +08:00
|
|
|
static inline void pps_get_ts(struct pps_event_time *ts)
|
|
|
|
{
|
2016-02-22 19:15:21 +08:00
|
|
|
struct system_time_snapshot snap;
|
2011-01-13 09:00:57 +08:00
|
|
|
|
2016-02-22 19:15:21 +08:00
|
|
|
ktime_get_snapshot(&snap);
|
|
|
|
ts->ts_real = ktime_to_timespec64(snap.real);
|
|
|
|
#ifdef CONFIG_NTP_PPS
|
|
|
|
ts->ts_raw = ktime_to_timespec64(snap.raw);
|
|
|
|
#endif
|
2011-01-13 09:00:50 +08:00
|
|
|
}
|
2011-01-13 09:00:49 +08:00
|
|
|
|
2012-09-03 18:34:58 +08:00
|
|
|
/* Subtract known time delay from PPS event time(s) */
|
2015-09-29 04:21:31 +08:00
|
|
|
static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
|
2012-09-03 18:34:58 +08:00
|
|
|
{
|
2015-09-29 04:21:31 +08:00
|
|
|
ts->ts_real = timespec64_sub(ts->ts_real, delta);
|
2012-09-03 18:34:58 +08:00
|
|
|
#ifdef CONFIG_NTP_PPS
|
2015-09-29 04:21:31 +08:00
|
|
|
ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
|
2012-09-03 18:34:58 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:00:49 +08:00
|
|
|
#endif /* LINUX_PPS_KERNEL_H */
|