| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 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 |  | 
| Alexander Gordeev | 7a21a3c | 2011-01-12 17:00:49 -0800 | [diff] [blame] | 21 | #ifndef LINUX_PPS_KERNEL_H | 
|  | 22 | #define LINUX_PPS_KERNEL_H | 
|  | 23 |  | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 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 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame^] | 34 | struct pps_device; | 
|  | 35 |  | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 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 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame^] | 42 | void (*echo)(struct pps_device *pps, | 
|  | 43 | int event, void *data);	/* PPS echo function */ | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 44 |  | 
|  | 45 | struct module *owner; | 
|  | 46 | struct device *dev; | 
|  | 47 | }; | 
|  | 48 |  | 
| Alexander Gordeev | 6f4229b | 2011-01-12 17:00:50 -0800 | [diff] [blame] | 49 | struct pps_event_time { | 
|  | 50 | struct timespec ts_real; | 
|  | 51 | }; | 
|  | 52 |  | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 53 | /* The main struct */ | 
|  | 54 | struct pps_device { | 
|  | 55 | struct pps_source_info info;		/* PSS source info */ | 
|  | 56 |  | 
|  | 57 | struct pps_kparams params;		/* PPS's current params */ | 
|  | 58 |  | 
|  | 59 | __u32 assert_sequence;			/* PPS' assert event seq # */ | 
|  | 60 | __u32 clear_sequence;			/* PPS' clear event seq # */ | 
|  | 61 | struct pps_ktime assert_tu; | 
|  | 62 | struct pps_ktime clear_tu; | 
|  | 63 | int current_mode;			/* PPS mode at event time */ | 
|  | 64 |  | 
| Alexander Gordeev | 3003d55 | 2011-01-12 17:00:50 -0800 | [diff] [blame] | 65 | unsigned int last_ev;			/* last PPS event id */ | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 66 | wait_queue_head_t queue;		/* PPS event queue */ | 
|  | 67 |  | 
|  | 68 | unsigned int id;			/* PPS source unique ID */ | 
|  | 69 | struct cdev cdev; | 
|  | 70 | struct device *dev; | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 71 | struct fasync_struct *async_queue;	/* fasync method */ | 
|  | 72 | spinlock_t lock; | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 73 | }; | 
|  | 74 |  | 
|  | 75 | /* | 
|  | 76 | * Global variables | 
|  | 77 | */ | 
|  | 78 |  | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 79 | extern struct device_attribute pps_attrs[]; | 
|  | 80 |  | 
|  | 81 | /* | 
|  | 82 | * Exported functions | 
|  | 83 | */ | 
|  | 84 |  | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame^] | 85 | extern struct pps_device *pps_register_source( | 
|  | 86 | struct pps_source_info *info, int default_params); | 
|  | 87 | extern void pps_unregister_source(struct pps_device *pps); | 
| Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 88 | extern int pps_register_cdev(struct pps_device *pps); | 
|  | 89 | extern void pps_unregister_cdev(struct pps_device *pps); | 
| Alexander Gordeev | 5e196d3 | 2011-01-12 17:00:51 -0800 | [diff] [blame^] | 90 | extern void pps_event(struct pps_device *pps, | 
|  | 91 | struct pps_event_time *ts, int event, void *data); | 
| Alexander Gordeev | 6f4229b | 2011-01-12 17:00:50 -0800 | [diff] [blame] | 92 |  | 
|  | 93 | static inline void timespec_to_pps_ktime(struct pps_ktime *kt, | 
|  | 94 | struct timespec ts) | 
|  | 95 | { | 
|  | 96 | kt->sec = ts.tv_sec; | 
|  | 97 | kt->nsec = ts.tv_nsec; | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | static inline void pps_get_ts(struct pps_event_time *ts) | 
|  | 101 | { | 
|  | 102 | getnstimeofday(&ts->ts_real); | 
|  | 103 | } | 
| Alexander Gordeev | 7a21a3c | 2011-01-12 17:00:49 -0800 | [diff] [blame] | 104 |  | 
|  | 105 | #endif /* LINUX_PPS_KERNEL_H */ | 
| Alexander Gordeev | 6f4229b | 2011-01-12 17:00:50 -0800 | [diff] [blame] | 106 |  |