Loading Documentation/rtc.txt +304 −159 Original line number Diff line number Diff line Real Time Clock Driver for Linux ================================ Real Time Clock (RTC) Drivers for Linux ======================================= When Linux developers talk about a "Real Time Clock", they usually mean something that tracks wall clock time and is battery backed so that it works even with system power off. Such clocks will normally not track the local time zone or daylight savings time -- unless they dual boot with MS-Windows -- but will instead be set to Coordinated Universal Time (UTC, formerly "Greenwich Mean Time"). The newest non-PC hardware tends to just count seconds, like the time(2) system call reports, but RTCs also very commonly represent time using the Gregorian calendar and 24 hour time, as reported by gmtime(3). Linux has two largely-compatible userspace RTC API families you may need to know about: * /dev/rtc ... is the RTC provided by PC compatible systems, so it's not very portable to non-x86 systems. * /dev/rtc0, /dev/rtc1 ... are part of a framework that's supported by a wide variety of RTC chips on all systems. Programmers need to understand that the PC/AT functionality is not always available, and some systems can do much more. That is, the RTCs use the same API to make requests in both RTC frameworks (using different filenames of course), but the hardware may not offer the same functionality. For example, not every RTC is hooked up to an IRQ, so they can't all issue alarms; and where standard PC RTCs can only issue an alarm up to 24 hours in the future, other hardware may be able to schedule one any time in the upcoming century. Old PC/AT-Compatible driver: /dev/rtc -------------------------------------- All PCs (even Alpha machines) have a Real Time Clock built into them. Usually they are built into the chipset of the computer, but some may actually have a Motorola MC146818 (or clone) on the board. This is the clock that keeps the date and time while your computer is turned off. ACPI has standardized that MC146818 functionality, and extended it in a few ways (enabling longer alarm periods, and wake-from-hibernate). That functionality is NOT exposed in the old driver. However it can also be used to generate signals from a slow 2Hz to a relatively fast 8192Hz, in increments of powers of two. These signals are reported by interrupt number 8. (Oh! So *that* is what IRQ 8 is Loading Loading @@ -63,9 +100,73 @@ Rather than write 50 pages describing the ioctl() and so on, it is perhaps more useful to include a small test program that demonstrates how to use them, and demonstrates the features of the driver. This is probably a lot more useful to people interested in writing applications that will be using this driver. that will be using this driver. See the code at the end of this document. (The original /dev/rtc driver was written by Paul Gortmaker.) New portable "RTC Class" drivers: /dev/rtcN -------------------------------------------- Because Linux supports many non-ACPI and non-PC platforms, some of which have more than one RTC style clock, it needed a more portable solution than expecting a single battery-backed MC146818 clone on every system. Accordingly, a new "RTC Class" framework has been defined. It offers three different userspace interfaces: * /dev/rtcN ... much the same as the older /dev/rtc interface * /sys/class/rtc/rtcN ... sysfs attributes support readonly access to some RTC attributes. * /proc/driver/rtc ... the first RTC (rtc0) may expose itself using a procfs interface. More information is (currently) shown here than through sysfs. The RTC Class framework supports a wide variety of RTCs, ranging from those integrated into embeddable system-on-chip (SOC) processors to discrete chips using I2C, SPI, or some other bus to communicate with the host CPU. There's even support for PC-style RTCs ... including the features exposed on newer PCs through ACPI. The new framework also removes the "one RTC per system" restriction. For example, maybe the low-power battery-backed RTC is a discrete I2C chip, but a high functionality RTC is integrated into the SOC. That system might read the system clock from the discrete RTC, but use the integrated one for all other tasks, because of its greater functionality. The ioctl() calls supported by /dev/rtc are also supported by the RTC class framework. However, because the chips and systems are not standardized, some PC/AT functionality might not be provided. And in the same way, some newer features -- including those enabled by ACPI -- are exposed by the RTC class framework, but can't be supported by the older driver. * RTC_RD_TIME, RTC_SET_TIME ... every RTC supports at least reading time, returning the result as a Gregorian calendar date and 24 hour wall clock time. To be most useful, this time may also be updated. * RTC_AIE_ON, RTC_AIE_OFF, RTC_ALM_SET, RTC_ALM_READ ... when the RTC is connected to an IRQ line, it can often issue an alarm IRQ up to 24 hours in the future. * RTC_WKALM_SET, RTC_WKALM_READ ... RTCs that can issue alarms beyond the next 24 hours use a slightly more powerful API, which supports setting the longer alarm time and enabling its IRQ using a single request (using the same model as EFI firmware). * RTC_UIE_ON, RTC_UIE_OFF ... if the RTC offers IRQs, it probably also offers update IRQs whenever the "seconds" counter changes. If needed, the RTC framework can emulate this mechanism. * RTC_PIE_ON, RTC_PIE_OFF, RTC_IRQP_SET, RTC_IRQP_READ ... another feature often accessible with an IRQ line is a periodic IRQ, issued at settable frequencies (usually 2^N Hz). In many cases, the RTC alarm can be a system wake event, used to force Linux out of a low power sleep state (or hibernation) back to a fully operational state. For example, a system could enter a deep power saving state until it's time to execute some scheduled tasks. Paul Gortmaker -------------------- 8< ---------------- 8< ----------------------------- Loading @@ -83,25 +184,46 @@ that will be using this driver. */ #include <stdio.h> #include <stdlib.h> #include <linux/rtc.h> #include <sys/ioctl.h> #include <sys/time.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> int main(void) { /* * This expects the new RTC class driver framework, working with * clocks that will often not be clones of what the PC-AT had. * Use the command line to specify another RTC if you need one. */ static const char default_rtc[] = "/dev/rtc0"; int main(int argc, char **argv) { int i, fd, retval, irqcount = 0; unsigned long tmp, data; struct rtc_time rtc_tm; const char *rtc = default_rtc; switch (argc) { case 2: rtc = argv[1]; /* FALLTHROUGH */ case 1: break; default: fprintf(stderr, "usage: rtctest [rtcdev]\n"); return 1; } fd = open ("/dev/rtc", O_RDONLY); fd = open(rtc, O_RDONLY); if (fd == -1) { perror("/dev/rtc"); perror(rtc); exit(errno); } Loading @@ -110,11 +232,17 @@ fprintf(stderr, "\n\t\t\tRTC Driver Test Example.\n\n"); /* Turn on update interrupts (one per second) */ retval = ioctl(fd, RTC_UIE_ON, 0); if (retval == -1) { if (errno == ENOTTY) { fprintf(stderr, "\n...Update IRQs not supported.\n"); goto test_READ; } perror("ioctl"); exit(errno); } fprintf(stderr, "Counting 5 update (1/sec) interrupts from reading /dev/rtc:"); fprintf(stderr, "Counting 5 update (1/sec) interrupts from reading %s:", rtc); fflush(stderr); for (i=1; i<6; i++) { /* This read will block */ Loading Loading @@ -160,6 +288,7 @@ if (retval == -1) { exit(errno); } test_READ: /* Read the RTC time/date */ retval = ioctl(fd, RTC_RD_TIME, &rtc_tm); if (retval == -1) { Loading @@ -186,6 +315,11 @@ if (rtc_tm.tm_hour == 24) retval = ioctl(fd, RTC_ALM_SET, &rtc_tm); if (retval == -1) { if (errno == ENOTTY) { fprintf(stderr, "\n...Alarm IRQs not supported.\n"); goto test_PIE; } perror("ioctl"); exit(errno); } Loading Loading @@ -225,13 +359,19 @@ if (retval == -1) { exit(errno); } test_PIE: /* Read periodic IRQ rate */ retval = ioctl(fd, RTC_IRQP_READ, &tmp); if (retval == -1) { /* not all RTCs support periodic IRQs */ if (errno == ENOTTY) { fprintf(stderr, "\nNo periodic IRQ support\n"); return 0; } perror("ioctl"); exit(errno); } fprintf(stderr, "\nPeriodic IRQ rate was %ldHz.\n", tmp); fprintf(stderr, "\nPeriodic IRQ rate is %ldHz.\n", tmp); fprintf(stderr, "Counting 20 interrupts at:"); fflush(stderr); Loading @@ -241,6 +381,12 @@ for (tmp=2; tmp<=64; tmp*=2) { retval = ioctl(fd, RTC_IRQP_SET, tmp); if (retval == -1) { /* not all RTCs can change their periodic IRQ rate */ if (errno == ENOTTY) { fprintf(stderr, "\n...Periodic IRQ rate is fixed\n"); goto done; } perror("ioctl"); exit(errno); } Loading Loading @@ -275,11 +421,10 @@ for (tmp=2; tmp<=64; tmp*=2) { } } done: fprintf(stderr, "\n\n\t\t\t *** Test complete ***\n"); fprintf(stderr, "\nTyping \"cat /proc/interrupts\" will show %d more events on IRQ 8.\n\n", irqcount); close(fd); return 0; } /* end main */ return 0; } MAINTAINERS +6 −0 Original line number Diff line number Diff line Loading @@ -353,6 +353,12 @@ P: Richard Purdie M: rpurdie@rpsys.net S: Maintained ARM/HP JORNADA 7XX MACHINE SUPPORT P: Kristoffer Ericson M: kristoffer_e1@hotmail.com W: www.jlime.com S: Maintained ARM/TOSA MACHINE SUPPORT P: Dirk Opfer M: dirk@opfer-online.de Loading arch/arm/Kconfig +2 −0 Original line number Diff line number Diff line Loading @@ -879,6 +879,8 @@ endif source "drivers/scsi/Kconfig" source "drivers/ata/Kconfig" source "drivers/md/Kconfig" source "drivers/message/fusion/Kconfig" Loading arch/arm/mach-ebsa110/io.c +4 −4 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ #include <asm/io.h> #include <asm/page.h> static void __iomem *__isamem_convert_addr(void __iomem *addr) static void __iomem *__isamem_convert_addr(const volatile void __iomem *addr) { u32 ret, a = (u32 __force) addr; Loading Loading @@ -63,7 +63,7 @@ static void __iomem *__isamem_convert_addr(void __iomem *addr) /* * read[bwl] and write[bwl] */ u8 __readb(void __iomem *addr) u8 __readb(const volatile void __iomem *addr) { void __iomem *a = __isamem_convert_addr(addr); u32 ret; Loading @@ -75,7 +75,7 @@ u8 __readb(void __iomem *addr) return ret; } u16 __readw(void __iomem *addr) u16 __readw(const volatile void __iomem *addr) { void __iomem *a = __isamem_convert_addr(addr); Loading @@ -85,7 +85,7 @@ u16 __readw(void __iomem *addr) return __raw_readw(a); } u32 __readl(void __iomem *addr) u32 __readl(const volatile void __iomem *addr) { void __iomem *a = __isamem_convert_addr(addr); u32 ret; Loading arch/arm/mm/consistent.c +3 −0 Original line number Diff line number Diff line Loading @@ -476,6 +476,9 @@ core_initcall(consistent_init); /* * Make an area consistent for devices. * Note: Drivers should NOT use this function directly, as it will break * platforms with CONFIG_DMABOUNCE. * Use the driver DMA support - see dma-mapping.h (dma_sync_*) */ void consistent_sync(void *vaddr, size_t size, int direction) { Loading Loading
Documentation/rtc.txt +304 −159 Original line number Diff line number Diff line Real Time Clock Driver for Linux ================================ Real Time Clock (RTC) Drivers for Linux ======================================= When Linux developers talk about a "Real Time Clock", they usually mean something that tracks wall clock time and is battery backed so that it works even with system power off. Such clocks will normally not track the local time zone or daylight savings time -- unless they dual boot with MS-Windows -- but will instead be set to Coordinated Universal Time (UTC, formerly "Greenwich Mean Time"). The newest non-PC hardware tends to just count seconds, like the time(2) system call reports, but RTCs also very commonly represent time using the Gregorian calendar and 24 hour time, as reported by gmtime(3). Linux has two largely-compatible userspace RTC API families you may need to know about: * /dev/rtc ... is the RTC provided by PC compatible systems, so it's not very portable to non-x86 systems. * /dev/rtc0, /dev/rtc1 ... are part of a framework that's supported by a wide variety of RTC chips on all systems. Programmers need to understand that the PC/AT functionality is not always available, and some systems can do much more. That is, the RTCs use the same API to make requests in both RTC frameworks (using different filenames of course), but the hardware may not offer the same functionality. For example, not every RTC is hooked up to an IRQ, so they can't all issue alarms; and where standard PC RTCs can only issue an alarm up to 24 hours in the future, other hardware may be able to schedule one any time in the upcoming century. Old PC/AT-Compatible driver: /dev/rtc -------------------------------------- All PCs (even Alpha machines) have a Real Time Clock built into them. Usually they are built into the chipset of the computer, but some may actually have a Motorola MC146818 (or clone) on the board. This is the clock that keeps the date and time while your computer is turned off. ACPI has standardized that MC146818 functionality, and extended it in a few ways (enabling longer alarm periods, and wake-from-hibernate). That functionality is NOT exposed in the old driver. However it can also be used to generate signals from a slow 2Hz to a relatively fast 8192Hz, in increments of powers of two. These signals are reported by interrupt number 8. (Oh! So *that* is what IRQ 8 is Loading Loading @@ -63,9 +100,73 @@ Rather than write 50 pages describing the ioctl() and so on, it is perhaps more useful to include a small test program that demonstrates how to use them, and demonstrates the features of the driver. This is probably a lot more useful to people interested in writing applications that will be using this driver. that will be using this driver. See the code at the end of this document. (The original /dev/rtc driver was written by Paul Gortmaker.) New portable "RTC Class" drivers: /dev/rtcN -------------------------------------------- Because Linux supports many non-ACPI and non-PC platforms, some of which have more than one RTC style clock, it needed a more portable solution than expecting a single battery-backed MC146818 clone on every system. Accordingly, a new "RTC Class" framework has been defined. It offers three different userspace interfaces: * /dev/rtcN ... much the same as the older /dev/rtc interface * /sys/class/rtc/rtcN ... sysfs attributes support readonly access to some RTC attributes. * /proc/driver/rtc ... the first RTC (rtc0) may expose itself using a procfs interface. More information is (currently) shown here than through sysfs. The RTC Class framework supports a wide variety of RTCs, ranging from those integrated into embeddable system-on-chip (SOC) processors to discrete chips using I2C, SPI, or some other bus to communicate with the host CPU. There's even support for PC-style RTCs ... including the features exposed on newer PCs through ACPI. The new framework also removes the "one RTC per system" restriction. For example, maybe the low-power battery-backed RTC is a discrete I2C chip, but a high functionality RTC is integrated into the SOC. That system might read the system clock from the discrete RTC, but use the integrated one for all other tasks, because of its greater functionality. The ioctl() calls supported by /dev/rtc are also supported by the RTC class framework. However, because the chips and systems are not standardized, some PC/AT functionality might not be provided. And in the same way, some newer features -- including those enabled by ACPI -- are exposed by the RTC class framework, but can't be supported by the older driver. * RTC_RD_TIME, RTC_SET_TIME ... every RTC supports at least reading time, returning the result as a Gregorian calendar date and 24 hour wall clock time. To be most useful, this time may also be updated. * RTC_AIE_ON, RTC_AIE_OFF, RTC_ALM_SET, RTC_ALM_READ ... when the RTC is connected to an IRQ line, it can often issue an alarm IRQ up to 24 hours in the future. * RTC_WKALM_SET, RTC_WKALM_READ ... RTCs that can issue alarms beyond the next 24 hours use a slightly more powerful API, which supports setting the longer alarm time and enabling its IRQ using a single request (using the same model as EFI firmware). * RTC_UIE_ON, RTC_UIE_OFF ... if the RTC offers IRQs, it probably also offers update IRQs whenever the "seconds" counter changes. If needed, the RTC framework can emulate this mechanism. * RTC_PIE_ON, RTC_PIE_OFF, RTC_IRQP_SET, RTC_IRQP_READ ... another feature often accessible with an IRQ line is a periodic IRQ, issued at settable frequencies (usually 2^N Hz). In many cases, the RTC alarm can be a system wake event, used to force Linux out of a low power sleep state (or hibernation) back to a fully operational state. For example, a system could enter a deep power saving state until it's time to execute some scheduled tasks. Paul Gortmaker -------------------- 8< ---------------- 8< ----------------------------- Loading @@ -83,25 +184,46 @@ that will be using this driver. */ #include <stdio.h> #include <stdlib.h> #include <linux/rtc.h> #include <sys/ioctl.h> #include <sys/time.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> int main(void) { /* * This expects the new RTC class driver framework, working with * clocks that will often not be clones of what the PC-AT had. * Use the command line to specify another RTC if you need one. */ static const char default_rtc[] = "/dev/rtc0"; int main(int argc, char **argv) { int i, fd, retval, irqcount = 0; unsigned long tmp, data; struct rtc_time rtc_tm; const char *rtc = default_rtc; switch (argc) { case 2: rtc = argv[1]; /* FALLTHROUGH */ case 1: break; default: fprintf(stderr, "usage: rtctest [rtcdev]\n"); return 1; } fd = open ("/dev/rtc", O_RDONLY); fd = open(rtc, O_RDONLY); if (fd == -1) { perror("/dev/rtc"); perror(rtc); exit(errno); } Loading @@ -110,11 +232,17 @@ fprintf(stderr, "\n\t\t\tRTC Driver Test Example.\n\n"); /* Turn on update interrupts (one per second) */ retval = ioctl(fd, RTC_UIE_ON, 0); if (retval == -1) { if (errno == ENOTTY) { fprintf(stderr, "\n...Update IRQs not supported.\n"); goto test_READ; } perror("ioctl"); exit(errno); } fprintf(stderr, "Counting 5 update (1/sec) interrupts from reading /dev/rtc:"); fprintf(stderr, "Counting 5 update (1/sec) interrupts from reading %s:", rtc); fflush(stderr); for (i=1; i<6; i++) { /* This read will block */ Loading Loading @@ -160,6 +288,7 @@ if (retval == -1) { exit(errno); } test_READ: /* Read the RTC time/date */ retval = ioctl(fd, RTC_RD_TIME, &rtc_tm); if (retval == -1) { Loading @@ -186,6 +315,11 @@ if (rtc_tm.tm_hour == 24) retval = ioctl(fd, RTC_ALM_SET, &rtc_tm); if (retval == -1) { if (errno == ENOTTY) { fprintf(stderr, "\n...Alarm IRQs not supported.\n"); goto test_PIE; } perror("ioctl"); exit(errno); } Loading Loading @@ -225,13 +359,19 @@ if (retval == -1) { exit(errno); } test_PIE: /* Read periodic IRQ rate */ retval = ioctl(fd, RTC_IRQP_READ, &tmp); if (retval == -1) { /* not all RTCs support periodic IRQs */ if (errno == ENOTTY) { fprintf(stderr, "\nNo periodic IRQ support\n"); return 0; } perror("ioctl"); exit(errno); } fprintf(stderr, "\nPeriodic IRQ rate was %ldHz.\n", tmp); fprintf(stderr, "\nPeriodic IRQ rate is %ldHz.\n", tmp); fprintf(stderr, "Counting 20 interrupts at:"); fflush(stderr); Loading @@ -241,6 +381,12 @@ for (tmp=2; tmp<=64; tmp*=2) { retval = ioctl(fd, RTC_IRQP_SET, tmp); if (retval == -1) { /* not all RTCs can change their periodic IRQ rate */ if (errno == ENOTTY) { fprintf(stderr, "\n...Periodic IRQ rate is fixed\n"); goto done; } perror("ioctl"); exit(errno); } Loading Loading @@ -275,11 +421,10 @@ for (tmp=2; tmp<=64; tmp*=2) { } } done: fprintf(stderr, "\n\n\t\t\t *** Test complete ***\n"); fprintf(stderr, "\nTyping \"cat /proc/interrupts\" will show %d more events on IRQ 8.\n\n", irqcount); close(fd); return 0; } /* end main */ return 0; }
MAINTAINERS +6 −0 Original line number Diff line number Diff line Loading @@ -353,6 +353,12 @@ P: Richard Purdie M: rpurdie@rpsys.net S: Maintained ARM/HP JORNADA 7XX MACHINE SUPPORT P: Kristoffer Ericson M: kristoffer_e1@hotmail.com W: www.jlime.com S: Maintained ARM/TOSA MACHINE SUPPORT P: Dirk Opfer M: dirk@opfer-online.de Loading
arch/arm/Kconfig +2 −0 Original line number Diff line number Diff line Loading @@ -879,6 +879,8 @@ endif source "drivers/scsi/Kconfig" source "drivers/ata/Kconfig" source "drivers/md/Kconfig" source "drivers/message/fusion/Kconfig" Loading
arch/arm/mach-ebsa110/io.c +4 −4 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ #include <asm/io.h> #include <asm/page.h> static void __iomem *__isamem_convert_addr(void __iomem *addr) static void __iomem *__isamem_convert_addr(const volatile void __iomem *addr) { u32 ret, a = (u32 __force) addr; Loading Loading @@ -63,7 +63,7 @@ static void __iomem *__isamem_convert_addr(void __iomem *addr) /* * read[bwl] and write[bwl] */ u8 __readb(void __iomem *addr) u8 __readb(const volatile void __iomem *addr) { void __iomem *a = __isamem_convert_addr(addr); u32 ret; Loading @@ -75,7 +75,7 @@ u8 __readb(void __iomem *addr) return ret; } u16 __readw(void __iomem *addr) u16 __readw(const volatile void __iomem *addr) { void __iomem *a = __isamem_convert_addr(addr); Loading @@ -85,7 +85,7 @@ u16 __readw(void __iomem *addr) return __raw_readw(a); } u32 __readl(void __iomem *addr) u32 __readl(const volatile void __iomem *addr) { void __iomem *a = __isamem_convert_addr(addr); u32 ret; Loading
arch/arm/mm/consistent.c +3 −0 Original line number Diff line number Diff line Loading @@ -476,6 +476,9 @@ core_initcall(consistent_init); /* * Make an area consistent for devices. * Note: Drivers should NOT use this function directly, as it will break * platforms with CONFIG_DMABOUNCE. * Use the driver DMA support - see dma-mapping.h (dma_sync_*) */ void consistent_sync(void *vaddr, size_t size, int direction) { Loading