Debian Codegraph @

upstream/debian-unstable/man4/rtc.4

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