1 /* 2 * PPS API kernel header 3 * 4 * Copyright (C) 2009 Rodolfo Giometti <[email protected]> 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 34 /* The specific PPS source info */ 35 struct pps_source_info { 36 char name[PPS_MAX_NAME_LEN]; /* simbolic name */ 37 char path[PPS_MAX_NAME_LEN]; /* path of connected device */ 38 int mode; /* PPS's allowed mode */ 39 40 void (*echo)(int source, int event, void *data); /* PPS echo function */ 41 42 struct module *owner; 43 struct device *dev; 44 }; 45 46 struct pps_event_time { 47 struct timespec ts_real; 48 }; 49 50 /* The main struct */ 51 struct pps_device { 52 struct pps_source_info info; /* PSS source info */ 53 54 struct pps_kparams params; /* PPS's current params */ 55 56 __u32 assert_sequence; /* PPS' assert event seq # */ 57 __u32 clear_sequence; /* PPS' clear event seq # */ 58 struct pps_ktime assert_tu; 59 struct pps_ktime clear_tu; 60 int current_mode; /* PPS mode at event time */ 61 62 unsigned int last_ev; /* last PPS event id */ 63 wait_queue_head_t queue; /* PPS event queue */ 64 65 unsigned int id; /* PPS source unique ID */ 66 struct cdev cdev; 67 struct device *dev; 68 int devno; 69 struct fasync_struct *async_queue; /* fasync method */ 70 spinlock_t lock; 71 72 atomic_t usage; /* usage count */ 73 }; 74 75 /* 76 * Global variables 77 */ 78 79 extern spinlock_t pps_idr_lock; 80 extern struct idr pps_idr; 81 82 extern struct device_attribute pps_attrs[]; 83 84 /* 85 * Exported functions 86 */ 87 88 struct pps_device *pps_get_source(int source); 89 extern void pps_put_source(struct pps_device *pps); 90 extern int pps_register_source(struct pps_source_info *info, 91 int default_params); 92 extern void pps_unregister_source(int source); 93 extern int pps_register_cdev(struct pps_device *pps); 94 extern void pps_unregister_cdev(struct pps_device *pps); 95 extern void pps_event(int source, struct pps_event_time *ts, int event, 96 void *data); 97 98 static inline void timespec_to_pps_ktime(struct pps_ktime *kt, 99 struct timespec ts) 100 { 101 kt->sec = ts.tv_sec; 102 kt->nsec = ts.tv_nsec; 103 } 104 105 static inline void pps_get_ts(struct pps_event_time *ts) 106 { 107 getnstimeofday(&ts->ts_real); 108 } 109 110 #endif /* LINUX_PPS_KERNEL_H */ 111 112