2006-02-08 03:20:03 +00:00
|
|
|
.\" rtc.4
|
|
|
|
.\" Copyright 2002 Urs Thuermann (urs@isnogud.escape.de)
|
|
|
|
.\"
|
|
|
|
.\" This is free documentation; you can redistribute it and/or
|
|
|
|
.\" modify it under the terms of the GNU General Public License as
|
|
|
|
.\" published by the Free Software Foundation; either version 2 of
|
|
|
|
.\" the License, or (at your option) any later version.
|
|
|
|
.\"
|
|
|
|
.\" The GNU General Public License's references to "object code"
|
|
|
|
.\" and "executables" are to be interpreted as the output of any
|
|
|
|
.\" document formatting or typesetting system, including
|
|
|
|
.\" intermediate and printed output.
|
|
|
|
.\"
|
|
|
|
.\" This manual is distributed in the hope that it will be useful,
|
|
|
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
.\" GNU General Public License for more details.
|
|
|
|
.\"
|
|
|
|
.\" You should have received a copy of the GNU General Public
|
|
|
|
.\" License along with this manual; if not, write to the Free
|
|
|
|
.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
|
|
|
|
.\" USA.
|
|
|
|
.\"
|
|
|
|
.\" $Id: rtc.4,v 1.4 2005/12/05 17:19:49 urs Exp $
|
|
|
|
.\"
|
|
|
|
.\" 2006-02-08 Various additions by mtk
|
2006-11-28 04:59:58 +00:00
|
|
|
.\" 2006-11-26 cleanup, cover the generic rtc framework; David Brownell
|
2006-02-08 03:20:03 +00:00
|
|
|
.\"
|
2007-05-18 09:11:21 +00:00
|
|
|
.TH RTC 4 2006-11-26 "Linux" "Linux Programmer's Manual"
|
2006-02-08 03:20:03 +00:00
|
|
|
.SH NAME
|
|
|
|
rtc \- real-time clock
|
|
|
|
.SH SYNOPSIS
|
|
|
|
#include <linux/rtc.h>
|
2006-11-28 04:59:58 +00:00
|
|
|
.sp
|
|
|
|
.BI "int ioctl(" fd ", RTC_" request ", " param ");"
|
2006-02-08 03:20:03 +00:00
|
|
|
.SH DESCRIPTION
|
2006-11-28 04:59:58 +00:00
|
|
|
This is the interface to drivers for real-time clocks (RTCs).
|
2006-02-08 03:20:03 +00:00
|
|
|
|
2006-11-28 04:59:58 +00:00
|
|
|
Most computers have one or more hardware clocks which record the
|
|
|
|
current "wall clock" time.
|
|
|
|
These are called "Real Time Clocks" (RTCs).
|
|
|
|
One of these usually has battery backup power so that it tracks the time
|
|
|
|
even while the computer is turned off.
|
|
|
|
RTCs often provide alarms and other interrupts.
|
2006-02-08 03:20:03 +00:00
|
|
|
|
2006-11-28 04:59:58 +00:00
|
|
|
All x86 PCs, and ACPI based systems, have an RTC that is compatible with
|
|
|
|
the Motorola MC146818 chip on the original PC/AT.
|
|
|
|
Today such an RTC is usually integrated into the mainboard's chipset
|
|
|
|
(south bridge), and uses a replaceable coin-sized backup battery.
|
2006-02-08 03:20:03 +00:00
|
|
|
|
2006-11-28 04:59:58 +00:00
|
|
|
Non-PC systems, such as embedded systems built around system-on-chip
|
|
|
|
processors, use other implementations.
|
|
|
|
They usually won't offer the same functionality as the RTC from a PC/AT.
|
|
|
|
.SS RTC vs System Clock
|
|
|
|
RTCs should not be confused with the system clock, which is
|
|
|
|
a software clock maintained by the kernel and used to implement
|
|
|
|
.BR gettimeofday (2)
|
|
|
|
and
|
2006-02-08 03:20:03 +00:00
|
|
|
.BR time (2),
|
2006-11-28 04:59:58 +00:00
|
|
|
as well as setting timestamps on files, etc.
|
|
|
|
The system clock reports seconds and microseconds since a start point,
|
|
|
|
defined to be the POSIX Epoch: Jan 1, 1970, 0:00 UTC.
|
|
|
|
(One common implementation counts timer interrupts, once
|
|
|
|
per "jiffy", at a frequency of 100, 250, or 1000 Hz.)
|
2007-06-02 05:45:14 +00:00
|
|
|
That is, it is supposed to report wall clock time, which RTCs also do.
|
2006-02-08 03:20:03 +00:00
|
|
|
|
2006-11-28 04:59:58 +00:00
|
|
|
A key difference between an RTC and the system clock is that RTCs
|
|
|
|
run even when the system is in a low power state (including "off"),
|
|
|
|
and the system clock can't.
|
2007-06-02 05:45:14 +00:00
|
|
|
Until it is initialized, the system clock can only report time since
|
2006-11-28 04:59:58 +00:00
|
|
|
system boot ... not since the POSIX Epoch.
|
|
|
|
So at boot time, and after resuming from a system low power state, the
|
|
|
|
system clock will often be set to the current wall clock time using an RTC.
|
|
|
|
Systems without an RTC need to set the system clock using another clock,
|
|
|
|
maybe across the network or by entering that data manually.
|
|
|
|
.SS RTC functionality
|
|
|
|
RTCs can be read and written with
|
|
|
|
.BR hwclock (8),
|
|
|
|
or directly with the ioctl requests listed below.
|
|
|
|
|
|
|
|
Besides tracking the date and time, many RTCs can also generate
|
2006-02-08 03:20:03 +00:00
|
|
|
interrupts
|
|
|
|
.IP *
|
|
|
|
on every clock update (i.e. once per second);
|
|
|
|
.IP *
|
|
|
|
at periodic intervals with a frequency that can be set to
|
|
|
|
any power-of-2 multiple in the range 2 Hz to 8192 Hz;
|
|
|
|
.IP *
|
|
|
|
on reaching a previously specified alarm time.
|
|
|
|
.PP
|
2006-11-28 04:59:58 +00:00
|
|
|
Each of those interrupt sources can be enabled or disabled separately.
|
|
|
|
On many systems, the alarm interrupt can be configured as a system wakeup
|
|
|
|
event, which can resume the system from a low power state such as
|
|
|
|
Suspend-to-RAM (STR, called S3 in ACPI systems),
|
|
|
|
Hibernation (called S4 in ACPI systems),
|
|
|
|
or even "off" (called S5 in ACPI systems).
|
|
|
|
On some systems, the battery backed RTC can't issue
|
|
|
|
interrupts, but another one can.
|
2006-02-08 03:20:03 +00:00
|
|
|
|
|
|
|
The
|
|
|
|
.B /dev/rtc
|
2006-11-28 04:59:58 +00:00
|
|
|
(or
|
|
|
|
.BR /dev/rtc0,
|
|
|
|
.BR /dev/rtc1,
|
|
|
|
etc)
|
|
|
|
device can be opened only once (until it is closed) and it is read-only.
|
|
|
|
On
|
2006-02-08 03:20:03 +00:00
|
|
|
.BR read (2)
|
|
|
|
and
|
|
|
|
.BR select (2)
|
2006-11-28 04:59:58 +00:00
|
|
|
the calling process is blocked until the next interrupt from that RTC
|
2006-02-08 03:20:03 +00:00
|
|
|
is received.
|
|
|
|
Following the interrupt, the process can read a long integer, of which
|
2006-11-28 04:59:58 +00:00
|
|
|
the least significant byte contains a bit mask encoding
|
|
|
|
the types of interrupt that occurred,
|
2006-02-08 03:20:03 +00:00
|
|
|
while the remaining 3 bytes contain the number of interrupts since the
|
|
|
|
last
|
|
|
|
.BR read (2).
|
2007-05-11 23:18:56 +00:00
|
|
|
.SS ioctl(2) interface
|
2007-04-12 22:42:49 +00:00
|
|
|
The following
|
2006-02-08 03:20:03 +00:00
|
|
|
.BR ioctl (2)
|
2006-11-28 04:59:58 +00:00
|
|
|
requests are defined on file descriptors connected to RTC devices:
|
2006-02-08 03:20:03 +00:00
|
|
|
.TP
|
|
|
|
.B RTC_RD_TIME
|
2006-11-28 04:59:58 +00:00
|
|
|
Returns this RTC's time in the following structure:
|
2006-02-08 03:20:03 +00:00
|
|
|
.PP
|
|
|
|
.RS
|
|
|
|
.in +0.5i
|
|
|
|
.nf
|
|
|
|
struct rtc_time {
|
|
|
|
int tm_sec;
|
|
|
|
int tm_min;
|
|
|
|
int tm_hour;
|
|
|
|
int tm_mday;
|
|
|
|
int tm_mon;
|
|
|
|
int tm_year;
|
|
|
|
int tm_wday; /* unused */
|
|
|
|
int tm_yday; /* unused */
|
|
|
|
int tm_isdst; /* unused */
|
|
|
|
};
|
|
|
|
.fi
|
|
|
|
.in -0.5i
|
|
|
|
.RE
|
|
|
|
.IP
|
|
|
|
The fields in this structure have the same meaning and ranges as for the
|
|
|
|
.I tm
|
|
|
|
structure described in
|
|
|
|
.BR gmtime (3).
|
|
|
|
A pointer to this structure should be passed as the third
|
2007-05-11 23:18:56 +00:00
|
|
|
.BR ioctl (2)
|
2006-02-08 03:20:03 +00:00
|
|
|
argument.
|
|
|
|
.TP
|
|
|
|
.B RTC_SET_TIME
|
2007-04-12 22:42:49 +00:00
|
|
|
Sets this RTC's time to the time specified by the
|
2006-02-08 03:20:03 +00:00
|
|
|
.I rtc_time
|
2007-04-12 22:42:49 +00:00
|
|
|
structure pointed to by the third
|
2007-05-11 23:18:56 +00:00
|
|
|
.BR ioctl (2)
|
2006-02-08 03:20:03 +00:00
|
|
|
argument.
|
|
|
|
To set the
|
2006-11-28 04:59:58 +00:00
|
|
|
RTC's time the process must be privileged (i.e., have the
|
2006-02-08 03:20:03 +00:00
|
|
|
.B CAP_SYS_TIME
|
|
|
|
capability).
|
|
|
|
.TP
|
|
|
|
.BR RTC_ALM_READ ", " RTC_ALM_SET
|
2006-11-28 04:59:58 +00:00
|
|
|
Read and set the alarm time, for RTCs that support alarms.
|
|
|
|
The alarm interrupt must be separately enabled or disabled using the
|
|
|
|
.BR RTC_AIE_ON ", " RTC_AIE_OFF
|
|
|
|
requests.
|
2007-05-12 09:06:04 +00:00
|
|
|
The third
|
|
|
|
.BR ioctl (2)
|
|
|
|
argument is a pointer to an
|
2007-04-12 22:42:49 +00:00
|
|
|
.I rtc_time
|
|
|
|
structure.
|
|
|
|
Only the
|
2006-02-08 03:20:03 +00:00
|
|
|
.IR tm_sec ,
|
|
|
|
.IR tm_min ,
|
|
|
|
and
|
|
|
|
.IR tm_hour
|
|
|
|
fields of this structure are used.
|
|
|
|
.TP
|
|
|
|
.BR RTC_IRQP_READ ", " RTC_IRQP_SET
|
2006-11-28 04:59:58 +00:00
|
|
|
Read and set the frequency for periodic interrupts,
|
|
|
|
for RTCs that support periodic interrupts.
|
|
|
|
The periodic interrupt must be separately enabled or disabled using the
|
|
|
|
.BR RTC_PIE_ON ", " RTC_PIE_OFF
|
|
|
|
requests.
|
2007-05-12 09:06:04 +00:00
|
|
|
The third
|
|
|
|
.BR ioctl (2)
|
|
|
|
argument is a
|
2006-11-28 04:59:58 +00:00
|
|
|
.I "unsigned long\ *"
|
2007-04-12 22:42:49 +00:00
|
|
|
or a
|
|
|
|
.IR "unsigned long" ,
|
2006-02-08 03:20:03 +00:00
|
|
|
respectively.
|
2007-04-12 22:42:49 +00:00
|
|
|
The value is the frequency in interrupts per second.
|
|
|
|
The set of allowable frequencies is the multiples of two
|
2006-02-08 03:20:03 +00:00
|
|
|
in the range 2 to 8192.
|
|
|
|
Only a privileged process (i.e., one having the
|
|
|
|
.B CAP_SYS_RESOURCE
|
|
|
|
capability) can set frequencies above the value specified in
|
|
|
|
.IR /proc/sys/dev/rtc/max-user-freq .
|
|
|
|
(This file contains the value 64 by default.)
|
|
|
|
.TP
|
|
|
|
.BR RTC_AIE_ON ", " RTC_AIE_OFF
|
2006-11-28 04:59:58 +00:00
|
|
|
Enable or disable the alarm interrupt, for RTCs that support alarms.
|
2007-05-12 09:06:04 +00:00
|
|
|
The third
|
|
|
|
.BR ioctl (2)
|
|
|
|
argument is ignored.
|
2006-02-08 03:20:03 +00:00
|
|
|
.TP
|
|
|
|
.BR RTC_UIE_ON ", " RTC_UIE_OFF
|
2006-11-28 04:59:58 +00:00
|
|
|
Enable or disable the interrupt on every clock update,
|
|
|
|
for RTCs that support this once-per-second interrupt.
|
2007-05-12 09:06:04 +00:00
|
|
|
The third
|
|
|
|
.BR ioctl (2)
|
|
|
|
argument is ignored.
|
2006-02-08 03:20:03 +00:00
|
|
|
.TP
|
|
|
|
.BR RTC_PIE_ON ", " RTC_PIE_OFF
|
2006-11-28 04:59:58 +00:00
|
|
|
Enable or disable the periodic interrupt,
|
|
|
|
for RTCs that support these periodic interrupts.
|
2007-05-12 09:06:04 +00:00
|
|
|
The third
|
|
|
|
.BR ioctl (2)
|
|
|
|
argument is ignored.
|
2006-02-08 03:20:03 +00:00
|
|
|
Only a privileged process (i.e., one having the
|
|
|
|
.B CAP_SYS_RESOURCE
|
2007-04-12 22:42:49 +00:00
|
|
|
capability) can enable the periodic interrupt if the frequency is
|
2006-02-08 03:20:03 +00:00
|
|
|
currently set above the value specified in
|
|
|
|
.IR /proc/sys/dev/rtc/max-user-freq .
|
|
|
|
.TP
|
|
|
|
.BR RTC_EPOCH_READ ", " RTC_EPOCH_SET
|
2006-11-28 04:59:58 +00:00
|
|
|
Many RTCs encode the year in an 8-bit register which is either
|
2007-04-12 22:42:49 +00:00
|
|
|
interpreted as an 8-bit binary number or as a BCD number.
|
2006-02-08 03:20:03 +00:00
|
|
|
In both cases,
|
2007-04-12 22:42:49 +00:00
|
|
|
the number is interpreted relative to this RTC's Epoch.
|
2006-11-28 04:59:58 +00:00
|
|
|
The RTC's Epoch is
|
|
|
|
initialized to 1900 on most systems but on Alpha and MIPS it might
|
2006-02-08 03:20:03 +00:00
|
|
|
also be initialized to 1952, 1980, or 2000, depending on the value of
|
2007-04-12 22:42:49 +00:00
|
|
|
an RTC register for the year.
|
2006-11-28 04:59:58 +00:00
|
|
|
With some RTCs,
|
|
|
|
these operations can be used to read or to set the RTC's Epoch,
|
|
|
|
respectively.
|
2007-05-12 09:06:04 +00:00
|
|
|
The third
|
|
|
|
.BR ioctl (2)
|
|
|
|
argument is a
|
2006-11-28 04:59:58 +00:00
|
|
|
.I "unsigned long\ *"
|
2007-04-12 22:42:49 +00:00
|
|
|
or a
|
|
|
|
.IR "unsigned long" ,
|
2006-11-28 04:59:58 +00:00
|
|
|
respectively, and the value returned (or assigned) is the epoch.
|
|
|
|
To set the RTC's Epoch the process must be privileged (i.e., have the
|
2006-02-08 03:20:03 +00:00
|
|
|
.B CAP_SYS_TIME
|
|
|
|
capability).
|
2006-11-28 04:59:58 +00:00
|
|
|
.TP
|
|
|
|
.BR RTC_WKALM_RD ", " RTC_WKALM_SET
|
|
|
|
Some RTCs support a more powerful alarm interface, using these ioctls
|
|
|
|
to read or write the RTC's alarm time (respectively) with this structure:
|
|
|
|
.PP
|
|
|
|
.RS
|
|
|
|
.in +0.5i
|
|
|
|
.nf
|
|
|
|
struct rtc_wkalrm {
|
|
|
|
unsigned char enabled;
|
|
|
|
unsigned char pending;
|
|
|
|
struct rtc_time time;
|
|
|
|
};
|
|
|
|
.fi
|
|
|
|
.in -0.5i
|
|
|
|
.RE
|
|
|
|
.IP
|
|
|
|
The
|
|
|
|
.I enabled
|
|
|
|
flag is used to enable or disable the alarm interrupt,
|
|
|
|
or to read its current status; when using these calls,
|
|
|
|
.BR RTC_AIE_ON " and " RTC_AIE_OFF
|
2007-04-12 22:42:49 +00:00
|
|
|
are not used.
|
|
|
|
The
|
2006-11-28 04:59:58 +00:00
|
|
|
.I pending
|
|
|
|
flag is used by RTC_WKALM_RD to report a pending interrupt
|
|
|
|
(so it's mostly useless on Linux, except when talking
|
|
|
|
to the RTC managed by EFI firmware).
|
|
|
|
The
|
|
|
|
.I time
|
|
|
|
field is as used with
|
|
|
|
.B RTC_ALM_READ
|
|
|
|
and
|
|
|
|
.B RTC_ALM_SET
|
|
|
|
except that the
|
|
|
|
.IR tm_mday ,
|
|
|
|
.IR tm_mon ,
|
|
|
|
and
|
|
|
|
.IR tm_year
|
|
|
|
fields are also valid.
|
|
|
|
A pointer to this structure should be passed as the third
|
2007-05-11 23:18:56 +00:00
|
|
|
.BR ioctl (2)
|
2006-11-28 04:59:58 +00:00
|
|
|
argument.
|
2006-02-08 03:20:03 +00:00
|
|
|
.SH FILES
|
2006-11-28 04:59:58 +00:00
|
|
|
.IR /dev/rtc ", "
|
|
|
|
.IR /dev/rtc0 ", "
|
|
|
|
.IR /dev/rtc1 ", "
|
|
|
|
etc: RTC special character device files.
|
2006-02-08 03:20:03 +00:00
|
|
|
|
2006-11-28 04:59:58 +00:00
|
|
|
.IR /proc/driver/rtc :
|
|
|
|
status of the (first) RTC.
|
2006-02-08 03:20:03 +00:00
|
|
|
.SH NOTES
|
|
|
|
When the kernel's system time is synchronized with an external
|
|
|
|
reference using
|
|
|
|
.BR adjtimex (2)
|
2007-04-12 22:42:49 +00:00
|
|
|
it will update a designated RTC periodically every 11 minutes.
|
2006-11-28 04:59:58 +00:00
|
|
|
To do so, the kernel has to briefly turn off periodic interrupts;
|
|
|
|
this might affect programs using that RTC.
|
2006-02-08 03:20:03 +00:00
|
|
|
|
2006-11-28 04:59:58 +00:00
|
|
|
An RTC's Epoch has nothing to do with the POSIX Epoch which is only
|
2006-02-08 03:20:03 +00:00
|
|
|
used for the system clock.
|
|
|
|
|
2006-11-28 04:59:58 +00:00
|
|
|
If the year according to the RTC's Epoch and the year register is
|
2006-02-08 03:20:03 +00:00
|
|
|
less than 1970 it is assumed to be 100 years later, i.e. between 2000
|
|
|
|
and 2069.
|
2006-11-28 04:59:58 +00:00
|
|
|
|
|
|
|
Some RTCs support "wildcard" values in alarm fields, to support
|
|
|
|
scenarios like periodic alarms at fifteen minutes after every hour,
|
2007-04-12 22:42:49 +00:00
|
|
|
or on the first day of each month.
|
|
|
|
Such usage is non portable;
|
2006-11-28 04:59:58 +00:00
|
|
|
portable user space code only expects a single alarm interrupt, and
|
|
|
|
will either disable or reinitialize the alarm after receiving it.
|
|
|
|
|
|
|
|
Some RTCs support periodic interrupts with periods that are multiples
|
|
|
|
of a second rather than fractions of a second;
|
|
|
|
multiple alarms;
|
|
|
|
programmable output clock signals;
|
|
|
|
non-volatile memory;
|
|
|
|
and other hardware
|
|
|
|
capabilities that are not currently exposed by this API.
|
2006-02-08 03:20:03 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR hwclock (8),
|
|
|
|
.BR date (1),
|
|
|
|
.BR time (2),
|
|
|
|
.BR stime (2),
|
|
|
|
.BR gettimeofday (2),
|
|
|
|
.BR settimeofday (2),
|
|
|
|
.BR adjtimex (2),
|
|
|
|
.BR gmtime (3),
|
2006-04-26 07:26:36 +00:00
|
|
|
.BR time (7),
|
2006-02-08 03:20:03 +00:00
|
|
|
/usr/src/linux/Documentation/rtc.txt
|