mount_setattr.2: Further tweaks after feedback from Christian Brauner
[man-pages.git] / man4 / rtc.4
blob12c5e0cfedeb29083befcade8d8d5ff3d70c450f
1 .\" rtc.4
2 .\" Copyright 2002 Urs Thuermann (urs@isnogud.escape.de)
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
9 .\"
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
14 .\"
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 .\" GNU General Public License for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .\" $Id: rtc.4,v 1.4 2005/12/05 17:19:49 urs Exp $
26 .\"
27 .\" 2006-02-08 Various additions by mtk
28 .\" 2006-11-26 cleanup, cover the generic rtc framework; David Brownell
29 .\"
30 .TH RTC 4 2021-03-22 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 rtc \- real-time clock
33 .SH SYNOPSIS
34 .nf
35 #include <linux/rtc.h>
36 .PP
37 .BI "int ioctl(" fd ", RTC_" request ", " param ");"
38 .fi
39 .SH DESCRIPTION
40 This is the interface to drivers for real-time clocks (RTCs).
41 .PP
42 Most computers have one or more hardware clocks which record the
43 current "wall clock" time.
44 These are called "Real Time Clocks" (RTCs).
45 One of these usually has battery backup power so that it tracks the time
46 even while the computer is turned off.
47 RTCs often provide alarms and other interrupts.
48 .PP
49 All i386 PCs, and ACPI-based systems, have an RTC that is compatible with
50 the Motorola MC146818 chip on the original PC/AT.
51 Today such an RTC is usually integrated into the mainboard's chipset
52 (south bridge), and uses a replaceable coin-sized backup battery.
53 .PP
54 Non-PC systems, such as embedded systems built around system-on-chip
55 processors, use other implementations.
56 They usually won't offer the same functionality as the RTC from a PC/AT.
57 .SS RTC vs system clock
58 RTCs should not be confused with the system clock, which is
59 a software clock maintained by the kernel and used to implement
60 .BR gettimeofday (2)
61 and
62 .BR time (2),
63 as well as setting timestamps on files, and so on.
64 The system clock reports seconds and microseconds since a start point,
65 defined to be the POSIX Epoch: 1970-01-01 00:00:00 +0000 (UTC).
66 (One common implementation counts timer interrupts, once
67 per "jiffy", at a frequency of 100, 250, or 1000 Hz.)
68 That is, it is supposed to report wall clock time, which RTCs also do.
69 .PP
70 A key difference between an RTC and the system clock is that RTCs
71 run even when the system is in a low power state (including "off"),
72 and the system clock can't.
73 Until it is initialized, the system clock can only report time since
74 system boot ... not since the POSIX Epoch.
75 So at boot time, and after resuming from a system low power state, the
76 system clock will often be set to the current wall clock time using an RTC.
77 Systems without an RTC need to set the system clock using another clock,
78 maybe across the network or by entering that data manually.
79 .SS RTC functionality
80 RTCs can be read and written with
81 .BR hwclock (8),
82 or directly with the
83 .BR ioctl (2)
84 requests listed below.
85 .PP
86 Besides tracking the date and time, many RTCs can also generate
87 interrupts
88 .IP * 3
89 on every clock update (i.e., once per second);
90 .IP *
91 at periodic intervals with a frequency that can be set to
92 any power-of-2 multiple in the range 2 Hz to 8192 Hz;
93 .IP *
94 on reaching a previously specified alarm time.
95 .PP
96 Each of those interrupt sources can be enabled or disabled separately.
97 On many systems, the alarm interrupt can be configured as a system wakeup
98 event, which can resume the system from a low power state such as
99 Suspend-to-RAM (STR, called S3 in ACPI systems),
100 Hibernation (called S4 in ACPI systems),
101 or even "off" (called S5 in ACPI systems).
102 On some systems, the battery backed RTC can't issue
103 interrupts, but another one can.
106 .I /dev/rtc
108 .IR /dev/rtc0 ,
109 .IR /dev/rtc1 ,
110 etc.)
111 device can be opened only once (until it is closed) and it is read-only.
113 .BR read (2)
115 .BR select (2)
116 the calling process is blocked until the next interrupt from that RTC
117 is received.
118 Following the interrupt, the process can read a long integer, of which
119 the least significant byte contains a bit mask encoding
120 the types of interrupt that occurred,
121 while the remaining 3 bytes contain the number of interrupts since the
122 last
123 .BR read (2).
124 .SS ioctl(2) interface
125 The following
126 .BR ioctl (2)
127 requests are defined on file descriptors connected to RTC devices:
129 .B RTC_RD_TIME
130 Returns this RTC's time in the following structure:
132 .in +4n
134 struct rtc_time {
135     int tm_sec;
136     int tm_min;
137     int tm_hour;
138     int tm_mday;
139     int tm_mon;
140     int tm_year;
141     int tm_wday;     /* unused */
142     int tm_yday;     /* unused */
143     int tm_isdst;    /* unused */
148 The fields in this structure have the same meaning and ranges as for the
149 .I tm
150 structure described in
151 .BR gmtime (3).
152 A pointer to this structure should be passed as the third
153 .BR ioctl (2)
154 argument.
156 .B RTC_SET_TIME
157 Sets this RTC's time to the time specified by the
158 .I rtc_time
159 structure pointed to by the third
160 .BR ioctl (2)
161 argument.
162 To set the
163 RTC's time the process must be privileged (i.e., have the
164 .B CAP_SYS_TIME
165 capability).
167 .BR RTC_ALM_READ ", " RTC_ALM_SET
168 Read and set the alarm time, for RTCs that support alarms.
169 The alarm interrupt must be separately enabled or disabled using the
170 .BR RTC_AIE_ON ", " RTC_AIE_OFF
171 requests.
172 The third
173 .BR ioctl (2)
174 argument is a pointer to an
175 .I rtc_time
176 structure.
177 Only the
178 .IR tm_sec ,
179 .IR tm_min ,
181 .I tm_hour
182 fields of this structure are used.
184 .BR RTC_IRQP_READ ", " RTC_IRQP_SET
185 Read and set the frequency for periodic interrupts,
186 for RTCs that support periodic interrupts.
187 The periodic interrupt must be separately enabled or disabled using the
188 .BR RTC_PIE_ON ", " RTC_PIE_OFF
189 requests.
190 The third
191 .BR ioctl (2)
192 argument is an
193 .I "unsigned long\ *"
194 or an
195 .IR "unsigned long" ,
196 respectively.
197 The value is the frequency in interrupts per second.
198 The set of allowable frequencies is the multiples of two
199 in the range 2 to 8192.
200 Only a privileged process (i.e., one having the
201 .B CAP_SYS_RESOURCE
202 capability) can set frequencies above the value specified in
203 .IR /proc/sys/dev/rtc/max\-user\-freq .
204 (This file contains the value 64 by default.)
206 .BR RTC_AIE_ON ", " RTC_AIE_OFF
207 Enable or disable the alarm interrupt, for RTCs that support alarms.
208 The third
209 .BR ioctl (2)
210 argument is ignored.
212 .BR RTC_UIE_ON ", " RTC_UIE_OFF
213 Enable or disable the interrupt on every clock update,
214 for RTCs that support this once-per-second interrupt.
215 The third
216 .BR ioctl (2)
217 argument is ignored.
219 .BR RTC_PIE_ON ", " RTC_PIE_OFF
220 Enable or disable the periodic interrupt,
221 for RTCs that support these periodic interrupts.
222 The third
223 .BR ioctl (2)
224 argument is ignored.
225 Only a privileged process (i.e., one having the
226 .B CAP_SYS_RESOURCE
227 capability) can enable the periodic interrupt if the frequency is
228 currently set above the value specified in
229 .IR /proc/sys/dev/rtc/max\-user\-freq .
231 .BR RTC_EPOCH_READ ", " RTC_EPOCH_SET
232 Many RTCs encode the year in an 8-bit register which is either
233 interpreted as an 8-bit binary number or as a BCD number.
234 In both cases,
235 the number is interpreted relative to this RTC's Epoch.
236 The RTC's Epoch is
237 initialized to 1900 on most systems but on Alpha and MIPS it might
238 also be initialized to 1952, 1980, or 2000, depending on the value of
239 an RTC register for the year.
240 With some RTCs,
241 these operations can be used to read or to set the RTC's Epoch,
242 respectively.
243 The third
244 .BR ioctl (2)
245 argument is an
246 .I "unsigned long\ *"
247 or an
248 .IR "unsigned long" ,
249 respectively, and the value returned (or assigned) is the Epoch.
250 To set the RTC's Epoch the process must be privileged (i.e., have the
251 .B CAP_SYS_TIME
252 capability).
254 .BR RTC_WKALM_RD ", " RTC_WKALM_SET
255 Some RTCs support a more powerful alarm interface, using these ioctls
256 to read or write the RTC's alarm time (respectively) with this structure:
259 .in +4n
261 struct rtc_wkalrm {
262     unsigned char enabled;
263     unsigned char pending;
264     struct rtc_time time;
271 .I enabled
272 flag is used to enable or disable the alarm interrupt,
273 or to read its current status; when using these calls,
274 .BR RTC_AIE_ON " and " RTC_AIE_OFF
275 are not used.
277 .I pending
278 flag is used by
279 .B RTC_WKALM_RD
280 to report a pending interrupt
281 (so it's mostly useless on Linux, except when talking
282 to the RTC managed by EFI firmware).
284 .I time
285 field is as used with
286 .B RTC_ALM_READ
288 .B RTC_ALM_SET
289 except that the
290 .IR tm_mday ,
291 .IR tm_mon ,
293 .I tm_year
294 fields are also valid.
295 A pointer to this structure should be passed as the third
296 .BR ioctl (2)
297 argument.
298 .SH FILES
300 .IR /dev/rtc ", " /dev/rtc0 ", " /dev/rtc1 ", etc."
301 RTC special character device files.
303 .IR /proc/driver/rtc
304 status of the (first) RTC.
305 .SH NOTES
306 When the kernel's system time is synchronized with an external
307 reference using
308 .BR adjtimex (2)
309 it will update a designated RTC periodically every 11 minutes.
310 To do so, the kernel has to briefly turn off periodic interrupts;
311 this might affect programs using that RTC.
313 An RTC's Epoch has nothing to do with the POSIX Epoch which is
314 used only for the system clock.
316 If the year according to the RTC's Epoch and the year register is
317 less than 1970 it is assumed to be 100 years later, that is, between 2000
318 and 2069.
320 Some RTCs support "wildcard" values in alarm fields, to support
321 scenarios like periodic alarms at fifteen minutes after every hour,
322 or on the first day of each month.
323 Such usage is nonportable;
324 portable user-space code expects only a single alarm interrupt, and
325 will either disable or reinitialize the alarm after receiving it.
327 Some RTCs support periodic interrupts with periods that are multiples
328 of a second rather than fractions of a second;
329 multiple alarms;
330 programmable output clock signals;
331 nonvolatile memory;
332 and other hardware
333 capabilities that are not currently exposed by this API.
334 .SH SEE ALSO
335 .BR date (1),
336 .BR adjtimex (2),
337 .BR gettimeofday (2),
338 .BR settimeofday (2),
339 .BR stime (2),
340 .BR time (2),
341 .BR gmtime (3),
342 .BR time (7),
343 .BR hwclock (8)
345 .I Documentation/rtc.txt
346 in the Linux kernel source tree