1eae9d2baSRodolfo Giometti /* 2eae9d2baSRodolfo Giometti * PPS API kernel header 3eae9d2baSRodolfo Giometti * 4eae9d2baSRodolfo Giometti * Copyright (C) 2009 Rodolfo Giometti <[email protected]> 5eae9d2baSRodolfo Giometti * 6eae9d2baSRodolfo Giometti * This program is free software; you can redistribute it and/or modify 7eae9d2baSRodolfo Giometti * it under the terms of the GNU General Public License as published by 8eae9d2baSRodolfo Giometti * the Free Software Foundation; either version 2 of the License, or 9eae9d2baSRodolfo Giometti * (at your option) any later version. 10eae9d2baSRodolfo Giometti * 11eae9d2baSRodolfo Giometti * This program is distributed in the hope that it will be useful, 12eae9d2baSRodolfo Giometti * but WITHOUT ANY WARRANTY; without even the implied warranty of 13eae9d2baSRodolfo Giometti * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14eae9d2baSRodolfo Giometti * GNU General Public License for more details. 15eae9d2baSRodolfo Giometti * 16eae9d2baSRodolfo Giometti * You should have received a copy of the GNU General Public License 17eae9d2baSRodolfo Giometti * along with this program; if not, write to the Free Software 18eae9d2baSRodolfo Giometti * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19eae9d2baSRodolfo Giometti */ 20eae9d2baSRodolfo Giometti 217a21a3ccSAlexander Gordeev #ifndef LINUX_PPS_KERNEL_H 227a21a3ccSAlexander Gordeev #define LINUX_PPS_KERNEL_H 237a21a3ccSAlexander Gordeev 24eae9d2baSRodolfo Giometti #include <linux/pps.h> 25eae9d2baSRodolfo Giometti 26eae9d2baSRodolfo Giometti #include <linux/cdev.h> 27eae9d2baSRodolfo Giometti #include <linux/device.h> 28eae9d2baSRodolfo Giometti #include <linux/time.h> 29eae9d2baSRodolfo Giometti 30eae9d2baSRodolfo Giometti /* 31eae9d2baSRodolfo Giometti * Global defines 32eae9d2baSRodolfo Giometti */ 33eae9d2baSRodolfo Giometti 34eae9d2baSRodolfo Giometti /* The specific PPS source info */ 35eae9d2baSRodolfo Giometti struct pps_source_info { 36eae9d2baSRodolfo Giometti char name[PPS_MAX_NAME_LEN]; /* simbolic name */ 37eae9d2baSRodolfo Giometti char path[PPS_MAX_NAME_LEN]; /* path of connected device */ 38eae9d2baSRodolfo Giometti int mode; /* PPS's allowed mode */ 39eae9d2baSRodolfo Giometti 40eae9d2baSRodolfo Giometti void (*echo)(int source, int event, void *data); /* PPS echo function */ 41eae9d2baSRodolfo Giometti 42eae9d2baSRodolfo Giometti struct module *owner; 43eae9d2baSRodolfo Giometti struct device *dev; 44eae9d2baSRodolfo Giometti }; 45eae9d2baSRodolfo Giometti 46*6f4229b5SAlexander Gordeev struct pps_event_time { 47*6f4229b5SAlexander Gordeev struct timespec ts_real; 48*6f4229b5SAlexander Gordeev }; 49*6f4229b5SAlexander Gordeev 50eae9d2baSRodolfo Giometti /* The main struct */ 51eae9d2baSRodolfo Giometti struct pps_device { 52eae9d2baSRodolfo Giometti struct pps_source_info info; /* PSS source info */ 53eae9d2baSRodolfo Giometti 54eae9d2baSRodolfo Giometti struct pps_kparams params; /* PPS's current params */ 55eae9d2baSRodolfo Giometti 56eae9d2baSRodolfo Giometti __u32 assert_sequence; /* PPS' assert event seq # */ 57eae9d2baSRodolfo Giometti __u32 clear_sequence; /* PPS' clear event seq # */ 58eae9d2baSRodolfo Giometti struct pps_ktime assert_tu; 59eae9d2baSRodolfo Giometti struct pps_ktime clear_tu; 60eae9d2baSRodolfo Giometti int current_mode; /* PPS mode at event time */ 61eae9d2baSRodolfo Giometti 623003d55bSAlexander Gordeev unsigned int last_ev; /* last PPS event id */ 63eae9d2baSRodolfo Giometti wait_queue_head_t queue; /* PPS event queue */ 64eae9d2baSRodolfo Giometti 65eae9d2baSRodolfo Giometti unsigned int id; /* PPS source unique ID */ 66eae9d2baSRodolfo Giometti struct cdev cdev; 67eae9d2baSRodolfo Giometti struct device *dev; 68eae9d2baSRodolfo Giometti int devno; 69eae9d2baSRodolfo Giometti struct fasync_struct *async_queue; /* fasync method */ 70eae9d2baSRodolfo Giometti spinlock_t lock; 71eae9d2baSRodolfo Giometti 72eae9d2baSRodolfo Giometti atomic_t usage; /* usage count */ 73eae9d2baSRodolfo Giometti }; 74eae9d2baSRodolfo Giometti 75eae9d2baSRodolfo Giometti /* 76eae9d2baSRodolfo Giometti * Global variables 77eae9d2baSRodolfo Giometti */ 78eae9d2baSRodolfo Giometti 79eae9d2baSRodolfo Giometti extern spinlock_t pps_idr_lock; 80eae9d2baSRodolfo Giometti extern struct idr pps_idr; 81eae9d2baSRodolfo Giometti 82eae9d2baSRodolfo Giometti extern struct device_attribute pps_attrs[]; 83eae9d2baSRodolfo Giometti 84eae9d2baSRodolfo Giometti /* 85eae9d2baSRodolfo Giometti * Exported functions 86eae9d2baSRodolfo Giometti */ 87eae9d2baSRodolfo Giometti 88eae9d2baSRodolfo Giometti struct pps_device *pps_get_source(int source); 89eae9d2baSRodolfo Giometti extern void pps_put_source(struct pps_device *pps); 90eae9d2baSRodolfo Giometti extern int pps_register_source(struct pps_source_info *info, 91eae9d2baSRodolfo Giometti int default_params); 92eae9d2baSRodolfo Giometti extern void pps_unregister_source(int source); 93eae9d2baSRodolfo Giometti extern int pps_register_cdev(struct pps_device *pps); 94eae9d2baSRodolfo Giometti extern void pps_unregister_cdev(struct pps_device *pps); 95*6f4229b5SAlexander Gordeev extern void pps_event(int source, struct pps_event_time *ts, int event, 96*6f4229b5SAlexander Gordeev void *data); 97*6f4229b5SAlexander Gordeev 98*6f4229b5SAlexander Gordeev static inline void timespec_to_pps_ktime(struct pps_ktime *kt, 99*6f4229b5SAlexander Gordeev struct timespec ts) 100*6f4229b5SAlexander Gordeev { 101*6f4229b5SAlexander Gordeev kt->sec = ts.tv_sec; 102*6f4229b5SAlexander Gordeev kt->nsec = ts.tv_nsec; 103*6f4229b5SAlexander Gordeev } 104*6f4229b5SAlexander Gordeev 105*6f4229b5SAlexander Gordeev static inline void pps_get_ts(struct pps_event_time *ts) 106*6f4229b5SAlexander Gordeev { 107*6f4229b5SAlexander Gordeev getnstimeofday(&ts->ts_real); 108*6f4229b5SAlexander Gordeev } 1097a21a3ccSAlexander Gordeev 1107a21a3ccSAlexander Gordeev #endif /* LINUX_PPS_KERNEL_H */ 111*6f4229b5SAlexander Gordeev 112