1RTC(4)                     Linux Programmer's Manual                    RTC(4)
2
3
4

NAME

6       rtc - real-time clock
7

SYNOPSIS

9       #include <linux/rtc.h>
10
11       int ioctl(fd, RTC_request, param);
12

DESCRIPTION

14       This is the interface to drivers for real-time clocks (RTCs).
15
16       Most  computers  have one or more hardware clocks which record the cur‐
17       rent "wall clock" time.  These are called "Real  Time  Clocks"  (RTCs).
18       One  of  these  usually  has battery backup power so that it tracks the
19       time even while the computer is turned off.  RTCs often provide  alarms
20       and other interrupts.
21
22       All  i386  PCs,  and ACPI-based systems, have an RTC that is compatible
23       with the Motorola MC146818 chip on the original PC/AT.  Today  such  an
24       RTC  is usually integrated into the mainboard's chipset (south bridge),
25       and uses a replaceable coin-sized backup battery.
26
27       Non-PC systems, such as embedded systems  built  around  system-on-chip
28       processors,  use  other  implementations.  They usually won't offer the
29       same functionality as the RTC from a PC/AT.
30
31   RTC vs system clock
32       RTCs should not be confused with the system clock, which is a  software
33       clock  maintained  by  the kernel and used to implement gettimeofday(2)
34       and time(2), as well as setting timestamps on files, etc.   The  system
35       clock  reports seconds and microseconds since a start point, defined to
36       be the POSIX Epoch:  1970-01-01  00:00:00  +0000  (UTC).   (One  common
37       implementation  counts  timer  interrupts,  once per "jiffy", at a fre‐
38       quency of 100, 250, or 1000 Hz.)  That is, it  is  supposed  to  report
39       wall clock time, which RTCs also do.
40
41       A  key  difference between an RTC and the system clock is that RTCs run
42       even when the system is in a low power state (including "off"), and the
43       system clock can't.  Until it is initialized, the system clock can only
44       report time since system boot ... not since the  POSIX  Epoch.   So  at
45       boot time, and after resuming from a system low power state, the system
46       clock will often be set to the current wall clock time  using  an  RTC.
47       Systems  without  an  RTC  need  to  set the system clock using another
48       clock, maybe across the network or by entering that data manually.
49
50   RTC functionality
51       RTCs can be read and written with  hwclock(8),  or  directly  with  the
52       ioctl requests listed below.
53
54       Besides  tracking the date and time, many RTCs can also generate inter‐
55       rupts
56
57       *  on every clock update (i.e., once per second);
58
59       *  at periodic intervals with a frequency that can be set to any power-
60          of-2 multiple in the range 2 Hz to 8192 Hz;
61
62       *  on reaching a previously specified alarm time.
63
64       Each  of those interrupt sources can be enabled or disabled separately.
65       On many systems, the alarm interrupt can  be  configured  as  a  system
66       wakeup  event,  which can resume the system from a low power state such
67       as Suspend-to-RAM (STR, called S3 in ACPI systems), Hibernation (called
68       S4  in  ACPI  systems),  or even "off" (called S5 in ACPI systems).  On
69       some systems, the  battery  backed  RTC  can't  issue  interrupts,  but
70       another one can.
71
72       The /dev/rtc (or /dev/rtc0, /dev/rtc1, etc.)  device can be opened only
73       once (until it  is  closed)  and  it  is  read-only.   On  read(2)  and
74       select(2)  the calling process is blocked until the next interrupt from
75       that RTC is received.  Following the interrupt, the process can read  a
76       long  integer,  of which the least significant byte contains a bit mask
77       encoding the types of interrupt that occurred, while  the  remaining  3
78       bytes contain the number of interrupts since the last read(2).
79
80   ioctl(2) interface
81       The  following  ioctl(2)  requests are defined on file descriptors con‐
82       nected to RTC devices:
83
84       RTC_RD_TIME
85              Returns this RTC's time in the following structure:
86
87                  struct rtc_time {
88                      int tm_sec;
89                      int tm_min;
90                      int tm_hour;
91                      int tm_mday;
92                      int tm_mon;
93                      int tm_year;
94                      int tm_wday;     /* unused */
95                      int tm_yday;     /* unused */
96                      int tm_isdst;    /* unused */
97                  };
98
99              The fields in this structure have the same meaning and ranges as
100              for  the tm structure described in gmtime(3).  A pointer to this
101              structure should be passed as the third ioctl(2) argument.
102
103       RTC_SET_TIME
104              Sets this RTC's time to  the  time  specified  by  the  rtc_time
105              structure pointed to by the third ioctl(2) argument.  To set the
106              RTC's time the  process  must  be  privileged  (i.e.,  have  the
107              CAP_SYS_TIME capability).
108
109       RTC_ALM_READ, RTC_ALM_SET
110              Read  and set the alarm time, for RTCs that support alarms.  The
111              alarm interrupt must be separately enabled or disabled using the
112              RTC_AIE_ON,  RTC_AIE_OFF  requests.  The third ioctl(2) argument
113              is a pointer to an rtc_time structure.  Only the tm_sec, tm_min,
114              and tm_hour fields of this structure are used.
115
116       RTC_IRQP_READ, RTC_IRQP_SET
117              Read  and  set  the  frequency for periodic interrupts, for RTCs
118              that support periodic interrupts.  The periodic  interrupt  must
119              be   separately   enabled  or  disabled  using  the  RTC_PIE_ON,
120              RTC_PIE_OFF  requests.   The  third  ioctl(2)  argument  is   an
121              unsigned long * or an unsigned long, respectively.  The value is
122              the frequency in interrupts per second.  The  set  of  allowable
123              frequencies  is  the  multiples  of  two in the range 2 to 8192.
124              Only a privileged process (i.e., one having the CAP_SYS_RESOURCE
125              capability)  can  set  frequencies  above the value specified in
126              /proc/sys/dev/rtc/max-user-freq.  (This file contains the  value
127              64 by default.)
128
129       RTC_AIE_ON, RTC_AIE_OFF
130              Enable  or  disable  the  alarm interrupt, for RTCs that support
131              alarms.  The third ioctl(2) argument is ignored.
132
133       RTC_UIE_ON, RTC_UIE_OFF
134              Enable or disable the interrupt on every clock update, for  RTCs
135              that support this once-per-second interrupt.  The third ioctl(2)
136              argument is ignored.
137
138       RTC_PIE_ON, RTC_PIE_OFF
139              Enable or disable the periodic interrupt, for RTCs that  support
140              these  periodic  interrupts.   The  third  ioctl(2)  argument is
141              ignored.  Only  a  privileged  process  (i.e.,  one  having  the
142              CAP_SYS_RESOURCE  capability)  can enable the periodic interrupt
143              if the frequency is currently set above the value  specified  in
144              /proc/sys/dev/rtc/max-user-freq.
145
146       RTC_EPOCH_READ, RTC_EPOCH_SET
147              Many  RTCs  encode the year in an 8-bit register which is either
148              interpreted as an 8-bit binary number or as a  BCD  number.   In
149              both  cases,  the  number  is interpreted relative to this RTC's
150              Epoch.  The RTC's Epoch is initialized to 1900 on  most  systems
151              but  on  Alpha  and  MIPS  it might also be initialized to 1952,
152              1980, or 2000, depending on the value of an RTC register for the
153              year.   With  some RTCs, these operations can be used to read or
154              to set the RTC's Epoch, respectively.  The third ioctl(2)  argu‐
155              ment  is a unsigned long * or a unsigned long, respectively, and
156              the value returned (or assigned) is the Epoch.  To set the RTC's
157              Epoch   the   process   must   be  privileged  (i.e.,  have  the
158              CAP_SYS_TIME capability).
159
160       RTC_WKALM_RD, RTC_WKALM_SET
161              Some RTCs support a more powerful alarm interface,  using  these
162              ioctls to read or write the RTC's alarm time (respectively) with
163              this structure:
164
165                  struct rtc_wkalrm {
166                      unsigned char enabled;
167                      unsigned char pending;
168                      struct rtc_time time;
169                  };
170
171              The enabled flag is used to enable or disable the  alarm  inter‐
172              rupt,  or  to  read  its current status; when using these calls,
173              RTC_AIE_ON and RTC_AIE_OFF are not used.  The  pending  flag  is
174              used  by  RTC_WKALM_RD  to  report  a pending interrupt (so it's
175              mostly useless on Linux, except when talking to the RTC  managed
176              by  EFI  firmware).  The time field is as used with RTC_ALM_READ
177              and RTC_ALM_SET except that the  tm_mday,  tm_mon,  and  tm_year
178              fields  are  also  valid.  A pointer to this structure should be
179              passed as the third ioctl(2) argument.
180

FILES

182       /dev/rtc, /dev/rtc0,  /dev/rtc1,  etc:  RTC  special  character  device
183       files.
184
185       /proc/driver/rtc: status of the (first) RTC.
186

NOTES

188       When  the  kernel's system time is synchronized with an external refer‐
189       ence using adjtimex(2) it will update  a  designated  RTC  periodically
190       every  11  minutes.  To do so, the kernel has to briefly turn off peri‐
191       odic interrupts; this might affect programs using that RTC.
192
193       An RTC's Epoch has nothing to do with the POSIX  Epoch  which  is  used
194       only for the system clock.
195
196       If  the year according to the RTC's Epoch and the year register is less
197       than 1970 it is assumed to be 100 years later, that  is,  between  2000
198       and 2069.
199
200       Some RTCs support "wildcard" values in alarm fields, to support scenar‐
201       ios like periodic alarms at fifteen minutes after every hour, or on the
202       first  day  of  each  month.  Such usage is nonportable; portable user-
203       space code only expects a single alarm interrupt, and will either  dis‐
204       able or reinitialize the alarm after receiving it.
205
206       Some  RTCs  support periodic interrupts with periods that are multiples
207       of a second rather than fractions of a second;  multiple  alarms;  pro‐
208       grammable  output clock signals; nonvolatile memory; and other hardware
209       capabilities that are not currently exposed by this API.
210

SEE ALSO

212       date(1),  adjtimex(2),  gettimeofday(2),   settimeofday(2),   stime(2),
213       time(2), gmtime(3), time(7), hwclock(8)
214
215       Documentation/rtc.txt in the Linux kernel source tree
216

COLOPHON

218       This  page  is  part of release 3.53 of the Linux man-pages project.  A
219       description of the project, and information about reporting  bugs,  can
220       be found at http://www.kernel.org/doc/man-pages/.
221
222
223
224Linux                             2010-02-25                            RTC(4)
Impressum