1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * PPS generator API kernel header 4 * 5 * Copyright (C) 2024 Rodolfo Giometti <[email protected]> 6 */ 7 8 #ifndef LINUX_PPS_GEN_KERNEL_H 9 #define LINUX_PPS_GEN_KERNEL_H 10 11 #include <linux/pps_gen.h> 12 #include <linux/cdev.h> 13 #include <linux/device.h> 14 15 /* 16 * Global defines 17 */ 18 19 #define PPS_GEN_MAX_SOURCES 16 /* should be enough... */ 20 21 struct pps_gen_device; 22 23 /** 24 * struct pps_gen_source_info - the specific PPS generator info 25 * @use_system_clock: true, if the system clock is used to generate pulses 26 * @get_time: query the time stored into the generator clock 27 * @enable: enable/disable the PPS pulses generation 28 * 29 * This is the main generator struct where all needed information must be 30 * placed before calling the pps_gen_register_source(). 31 */ 32 struct pps_gen_source_info { 33 bool use_system_clock; 34 35 int (*get_time)(struct pps_gen_device *pps_gen, 36 struct timespec64 *time); 37 int (*enable)(struct pps_gen_device *pps_gen, bool enable); 38 39 /* private: internal use only */ 40 struct module *owner; 41 struct device *parent; /* for device_create */ 42 }; 43 44 /* The main struct */ 45 struct pps_gen_device { 46 struct pps_gen_source_info info; /* PSS generator info */ 47 bool enabled; /* PSS generator status */ 48 49 unsigned int event; 50 unsigned int sequence; 51 52 unsigned int last_ev; /* last PPS event id */ 53 wait_queue_head_t queue; /* PPS event queue */ 54 55 unsigned int id; /* PPS generator unique ID */ 56 struct cdev cdev; 57 struct device *dev; 58 struct fasync_struct *async_queue; /* fasync method */ 59 spinlock_t lock; 60 }; 61 62 /* 63 * Global variables 64 */ 65 66 extern const struct attribute_group *pps_gen_groups[]; 67 68 /* 69 * Exported functions 70 */ 71 72 extern struct pps_gen_device *pps_gen_register_source( 73 struct pps_gen_source_info *info); 74 extern void pps_gen_unregister_source(struct pps_gen_device *pps_gen); 75 extern void pps_gen_event(struct pps_gen_device *pps_gen, 76 unsigned int event, void *data); 77 78 #endif /* LINUX_PPS_GEN_KERNEL_H */ 79