186b525beSRodolfo Giometti /* SPDX-License-Identifier: GPL-2.0-or-later */ 286b525beSRodolfo Giometti /* 386b525beSRodolfo Giometti * PPS generator API kernel header 486b525beSRodolfo Giometti * 586b525beSRodolfo Giometti * Copyright (C) 2024 Rodolfo Giometti <[email protected]> 686b525beSRodolfo Giometti */ 786b525beSRodolfo Giometti 886b525beSRodolfo Giometti #ifndef LINUX_PPS_GEN_KERNEL_H 986b525beSRodolfo Giometti #define LINUX_PPS_GEN_KERNEL_H 1086b525beSRodolfo Giometti 1186b525beSRodolfo Giometti #include <linux/pps_gen.h> 1286b525beSRodolfo Giometti #include <linux/cdev.h> 1386b525beSRodolfo Giometti #include <linux/device.h> 1486b525beSRodolfo Giometti 1586b525beSRodolfo Giometti /* 1686b525beSRodolfo Giometti * Global defines 1786b525beSRodolfo Giometti */ 1886b525beSRodolfo Giometti 1986b525beSRodolfo Giometti #define PPS_GEN_MAX_SOURCES 16 /* should be enough... */ 2086b525beSRodolfo Giometti 2186b525beSRodolfo Giometti struct pps_gen_device; 2286b525beSRodolfo Giometti 2386b525beSRodolfo Giometti /** 2486b525beSRodolfo Giometti * struct pps_gen_source_info - the specific PPS generator info 2586b525beSRodolfo Giometti * @use_system_clock: true, if the system clock is used to generate pulses 2686b525beSRodolfo Giometti * @get_time: query the time stored into the generator clock 2786b525beSRodolfo Giometti * @enable: enable/disable the PPS pulses generation 2886b525beSRodolfo Giometti * 2986b525beSRodolfo Giometti * This is the main generator struct where all needed information must be 3086b525beSRodolfo Giometti * placed before calling the pps_gen_register_source(). 3186b525beSRodolfo Giometti */ 3286b525beSRodolfo Giometti struct pps_gen_source_info { 3386b525beSRodolfo Giometti bool use_system_clock; 3486b525beSRodolfo Giometti 3586b525beSRodolfo Giometti int (*get_time)(struct pps_gen_device *pps_gen, 3686b525beSRodolfo Giometti struct timespec64 *time); 3786b525beSRodolfo Giometti int (*enable)(struct pps_gen_device *pps_gen, bool enable); 3886b525beSRodolfo Giometti 3986b525beSRodolfo Giometti /* private: internal use only */ 4086b525beSRodolfo Giometti struct module *owner; 4186b525beSRodolfo Giometti struct device *parent; /* for device_create */ 4286b525beSRodolfo Giometti }; 4386b525beSRodolfo Giometti 4486b525beSRodolfo Giometti /* The main struct */ 4586b525beSRodolfo Giometti struct pps_gen_device { 46*ac9c5170SSubramanian Mohan const struct pps_gen_source_info *info; /* PSS generator info */ 4786b525beSRodolfo Giometti bool enabled; /* PSS generator status */ 4886b525beSRodolfo Giometti 4986b525beSRodolfo Giometti unsigned int event; 5086b525beSRodolfo Giometti unsigned int sequence; 5186b525beSRodolfo Giometti 5286b525beSRodolfo Giometti unsigned int last_ev; /* last PPS event id */ 5386b525beSRodolfo Giometti wait_queue_head_t queue; /* PPS event queue */ 5486b525beSRodolfo Giometti 5586b525beSRodolfo Giometti unsigned int id; /* PPS generator unique ID */ 5686b525beSRodolfo Giometti struct cdev cdev; 5786b525beSRodolfo Giometti struct device *dev; 5886b525beSRodolfo Giometti struct fasync_struct *async_queue; /* fasync method */ 5986b525beSRodolfo Giometti spinlock_t lock; 6086b525beSRodolfo Giometti }; 6186b525beSRodolfo Giometti 6286b525beSRodolfo Giometti /* 6386b525beSRodolfo Giometti * Global variables 6486b525beSRodolfo Giometti */ 6586b525beSRodolfo Giometti 6686b525beSRodolfo Giometti extern const struct attribute_group *pps_gen_groups[]; 6786b525beSRodolfo Giometti 6886b525beSRodolfo Giometti /* 6986b525beSRodolfo Giometti * Exported functions 7086b525beSRodolfo Giometti */ 7186b525beSRodolfo Giometti 7286b525beSRodolfo Giometti extern struct pps_gen_device *pps_gen_register_source( 73*ac9c5170SSubramanian Mohan const struct pps_gen_source_info *info); 7486b525beSRodolfo Giometti extern void pps_gen_unregister_source(struct pps_gen_device *pps_gen); 7586b525beSRodolfo Giometti extern void pps_gen_event(struct pps_gen_device *pps_gen, 7686b525beSRodolfo Giometti unsigned int event, void *data); 7786b525beSRodolfo Giometti 7886b525beSRodolfo Giometti #endif /* LINUX_PPS_GEN_KERNEL_H */ 79