2 * posix-clock.h - support for dynamic clock devices
4 * Copyright (C) 2010 OMICRON electronics GmbH
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.
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.
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.
20 #ifndef _LINUX_POSIX_CLOCK_H_
21 #define _LINUX_POSIX_CLOCK_H_
23 #include <linux/cdev.h>
25 #include <linux/poll.h>
26 #include <linux/posix-timers.h>
27 #include <linux/rwsem.h>
32 * struct posix_clock_operations - functional interface to the clock
34 * Every posix clock is represented by a character device. Drivers may
35 * optionally offer extended capabilities by implementing the
36 * character device methods. The character device file operations are
37 * first handled by the clock device layer, then passed on to the
38 * driver by calling these functions.
40 * @owner: The clock driver should set to THIS_MODULE
41 * @clock_adjtime: Adjust the clock
42 * @clock_gettime: Read the current time
43 * @clock_getres: Get the clock resolution
44 * @clock_settime: Set the current time value
45 * @open: Optional character device open method
46 * @release: Optional character device release method
47 * @ioctl: Optional character device ioctl method
48 * @read: Optional character device read method
49 * @poll: Optional character device poll method
51 struct posix_clock_operations {
54 int (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
56 int (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
58 int (*clock_getres) (struct posix_clock *pc, struct timespec64 *ts);
60 int (*clock_settime)(struct posix_clock *pc,
61 const struct timespec64 *ts);
64 * Optional character device methods:
66 long (*ioctl) (struct posix_clock *pc,
67 unsigned int cmd, unsigned long arg);
69 int (*open) (struct posix_clock *pc, fmode_t f_mode);
71 __poll_t (*poll) (struct posix_clock *pc,
72 struct file *file, poll_table *wait);
74 int (*release) (struct posix_clock *pc);
76 ssize_t (*read) (struct posix_clock *pc,
77 uint flags, char __user *buf, size_t cnt);
81 * struct posix_clock - represents a dynamic posix clock
83 * @ops: Functional interface to the clock
84 * @cdev: Character device instance for this clock
85 * @kref: Reference count.
86 * @rwsem: Protects the 'zombie' field from concurrent access.
87 * @zombie: If 'zombie' is true, then the hardware has disappeared.
88 * @release: A function to free the structure when the reference count reaches
89 * zero. May be NULL if structure is statically allocated.
91 * Drivers should embed their struct posix_clock within a private
92 * structure, obtaining a reference to it during callbacks using
96 struct posix_clock_operations ops;
99 struct rw_semaphore rwsem;
101 void (*release)(struct posix_clock *clk);
105 * posix_clock_register() - register a new clock
106 * @clk: Pointer to the clock. Caller must provide 'ops' and 'release'
107 * @devid: Allocated device id
109 * A clock driver calls this function to register itself with the
110 * clock device subsystem. If 'clk' points to dynamically allocated
111 * memory, then the caller must provide a 'release' function to free
114 * Returns zero on success, non-zero otherwise.
116 int posix_clock_register(struct posix_clock *clk, dev_t devid);
119 * posix_clock_unregister() - unregister a clock
120 * @clk: Clock instance previously registered via posix_clock_register()
122 * A clock driver calls this function to remove itself from the clock
123 * device subsystem. The posix_clock itself will remain (in an
124 * inactive state) until its reference count drops to zero, at which
125 * point it will be deallocated with its 'release' method.
127 void posix_clock_unregister(struct posix_clock *clk);