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