Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Mar 24-27, 2025, special US time zones
Register
Loading...
v5.9
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 * PPS API kernel header
  4 *
  5 * Copyright (C) 2009   Rodolfo Giometti <giometti@linux.it>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#ifndef LINUX_PPS_KERNEL_H
  9#define LINUX_PPS_KERNEL_H
 10
 11#include <linux/pps.h>
 
 12#include <linux/cdev.h>
 13#include <linux/device.h>
 14#include <linux/time.h>
 15
 16/*
 17 * Global defines
 18 */
 19
 20struct pps_device;
 21
 22/* The specific PPS source info */
 23struct pps_source_info {
 24	char name[PPS_MAX_NAME_LEN];		/* symbolic name */
 25	char path[PPS_MAX_NAME_LEN];		/* path of connected device */
 26	int mode;				/* PPS allowed mode */
 27
 28	void (*echo)(struct pps_device *pps,
 29			int event, void *data);	/* PPS echo function */
 30
 31	struct module *owner;
 32	struct device *dev;		/* Parent device for device_create */
 33};
 34
 35struct pps_event_time {
 36#ifdef CONFIG_NTP_PPS
 37	struct timespec64 ts_raw;
 38#endif /* CONFIG_NTP_PPS */
 39	struct timespec64 ts_real;
 40};
 41
 42/* The main struct */
 43struct pps_device {
 44	struct pps_source_info info;		/* PSS source info */
 45
 46	struct pps_kparams params;		/* PPS current params */
 47
 48	__u32 assert_sequence;			/* PPS assert event seq # */
 49	__u32 clear_sequence;			/* PPS clear event seq # */
 50	struct pps_ktime assert_tu;
 51	struct pps_ktime clear_tu;
 52	int current_mode;			/* PPS mode at event time */
 53
 54	unsigned int last_ev;			/* last PPS event id */
 55	wait_queue_head_t queue;		/* PPS event queue */
 56
 57	unsigned int id;			/* PPS source unique ID */
 58	void const *lookup_cookie;		/* For pps_lookup_dev() only */
 59	struct cdev cdev;
 60	struct device *dev;
 61	struct fasync_struct *async_queue;	/* fasync method */
 62	spinlock_t lock;
 63};
 64
 65/*
 66 * Global variables
 67 */
 68
 69extern const struct attribute_group *pps_groups[];
 70
 71/*
 72 * Internal functions.
 73 *
 74 * These are not actually part of the exported API, but this is a
 75 * convenient header file to put them in.
 76 */
 77
 78extern int pps_register_cdev(struct pps_device *pps);
 79extern void pps_unregister_cdev(struct pps_device *pps);
 80
 81/*
 82 * Exported functions
 83 */
 84
 85extern struct pps_device *pps_register_source(
 86		struct pps_source_info *info, int default_params);
 87extern void pps_unregister_source(struct pps_device *pps);
 88extern void pps_event(struct pps_device *pps,
 89		struct pps_event_time *ts, int event, void *data);
 90/* Look up a pps_device by magic cookie */
 91struct pps_device *pps_lookup_dev(void const *cookie);
 92
 93static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
 94		struct timespec64 ts)
 95{
 96	kt->sec = ts.tv_sec;
 97	kt->nsec = ts.tv_nsec;
 98}
 99
100static inline void pps_get_ts(struct pps_event_time *ts)
101{
102	struct system_time_snapshot snap;
103
104	ktime_get_snapshot(&snap);
105	ts->ts_real = ktime_to_timespec64(snap.real);
106#ifdef CONFIG_NTP_PPS
107	ts->ts_raw = ktime_to_timespec64(snap.raw);
108#endif
109}
110
111/* Subtract known time delay from PPS event time(s) */
112static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
113{
114	ts->ts_real = timespec64_sub(ts->ts_real, delta);
115#ifdef CONFIG_NTP_PPS
116	ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
117#endif
118}
119
120#endif /* LINUX_PPS_KERNEL_H */
v4.10.11
 
  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
 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/*
 31 * Global defines
 32 */
 33
 34struct pps_device;
 35
 36/* The specific PPS source info */
 37struct 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
 42	void (*echo)(struct pps_device *pps,
 43			int event, void *data);	/* PPS echo function */
 44
 45	struct module *owner;
 46	struct device *dev;		/* Parent device for device_create */
 47};
 48
 49struct pps_event_time {
 50#ifdef CONFIG_NTP_PPS
 51	struct timespec64 ts_raw;
 52#endif /* CONFIG_NTP_PPS */
 53	struct timespec64 ts_real;
 54};
 55
 56/* The main struct */
 57struct 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
 68	unsigned int last_ev;			/* last PPS event id */
 69	wait_queue_head_t queue;		/* PPS event queue */
 70
 71	unsigned int id;			/* PPS source unique ID */
 72	void const *lookup_cookie;		/* pps_lookup_dev only */
 73	struct cdev cdev;
 74	struct device *dev;
 75	struct fasync_struct *async_queue;	/* fasync method */
 76	spinlock_t lock;
 77};
 78
 79/*
 80 * Global variables
 81 */
 82
 83extern const struct attribute_group *pps_groups[];
 84
 85/*
 86 * Internal functions.
 87 *
 88 * These are not actually part of the exported API, but this is a
 89 * convenient header file to put them in.
 90 */
 91
 92extern int pps_register_cdev(struct pps_device *pps);
 93extern void pps_unregister_cdev(struct pps_device *pps);
 94
 95/*
 96 * Exported functions
 97 */
 98
 99extern struct pps_device *pps_register_source(
100		struct pps_source_info *info, int default_params);
101extern void pps_unregister_source(struct pps_device *pps);
102extern void pps_event(struct pps_device *pps,
103		struct pps_event_time *ts, int event, void *data);
104/* Look up a pps device by magic cookie */
105struct pps_device *pps_lookup_dev(void const *cookie);
106
107static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
108		struct timespec64 ts)
109{
110	kt->sec = ts.tv_sec;
111	kt->nsec = ts.tv_nsec;
112}
113
114static inline void pps_get_ts(struct pps_event_time *ts)
115{
116	struct system_time_snapshot snap;
117
118	ktime_get_snapshot(&snap);
119	ts->ts_real = ktime_to_timespec64(snap.real);
120#ifdef CONFIG_NTP_PPS
121	ts->ts_raw = ktime_to_timespec64(snap.raw);
122#endif
123}
124
125/* Subtract known time delay from PPS event time(s) */
126static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
127{
128	ts->ts_real = timespec64_sub(ts->ts_real, delta);
129#ifdef CONFIG_NTP_PPS
130	ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
131#endif
132}
133
134#endif /* LINUX_PPS_KERNEL_H */
135