History log of /drivers/rtc/rtc-cmos.c
Revision Date Author Comments
2f6e5f9458646263d3d9ffadd5e11e3d8d15a7d0 23-Mar-2012 Yong Zhang <yong.zhang0@gmail.com> drivers/rtc: remove IRQF_DISABLED

Since commit e58aa3d2d0cc ("genirq: run irq handlers with interrupts
disabled") we run all interrupt handlers with interrupts disabled and we
even check and yell when an interrupt handler returns with interrupts
enabled - see commit b738a50a2026 ("genirq: warn when handler enables
interrupts").

So now this flag is a NOOP and can be removed.

Signed-off-by: Yong Zhang <yong.zhang0@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Wan ZongShun <mcuos.com@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
b43c1ea4d622b6951377de92edfb219d893e23ef 11-Jan-2012 Ondrej Zary <linux@rainbow-software.org> drivers/rtc/rtc-cmos.c: fix broken NVRAM bank 2 writing

Fix writing to NVRAM bank 2 in rtc-cmos driver. It never worked since its
introduction in 2.6.28 because of a typo.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
28f65c11f2ffb3957259dece647a24f8ad2e241b 09-Jun-2011 Joe Perches <joe@perches.com> treewide: Convert uses of struct resource to resource_size(ptr)

Several fixes as well where the +1 was missing.

Done via coccinelle scripts like:

@@
struct resource *ptr;
@@

- ptr->end - ptr->start + 1
+ resource_size(ptr)

and some grep and typing.

Mostly uncompiled, no cross-compilers.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
51ba60c5bb3b0f71bee26404ddc22d8e4109e88a 03-Feb-2011 John Stultz <john.stultz@linaro.org> RTC: Cleanup rtc_class_ops->update_irq_enable()

Now that the generic code handles UIE mode irqs via periodic
alarm interrupts, no one calls the
rtc_class_ops->update_irq_enable() method anymore.

This patch removes the driver hooks and implementations of
update_irq_enable if no one else is calling it.

CC: Thomas Gleixner <tglx@linutronix.de>
CC: Alessandro Zummo <a.zummo@towertech.it>
CC: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
CC: rtc-linux@googlegroups.com
Signed-off-by: John Stultz <john.stultz@linaro.org>
696160fec162601d06940862b5b3aa4460344c1b 03-Feb-2011 John Stultz <john.stultz@linaro.org> RTC: Cleanup rtc_class_ops->irq_set_freq()

With the generic rtc code now emulating PIE mode irqs via an
hrtimer, no one calls the rtc_class_ops->irq_set_freq call.

This patch removes the hook and deletes the driver functions
if no one else calls them.

CC: Thomas Gleixner <tglx@linutronix.de>
CC: Alessandro Zummo <a.zummo@towertech.it>
CC: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
CC: rtc-linux@googlegroups.com
Signed-off-by: John Stultz <john.stultz@linaro.org>
80d4bb515b78f38738f3378fd1be6039063ab040 03-Feb-2011 John Stultz <john.stultz@linaro.org> RTC: Cleanup rtc_class_ops->irq_set_state

With PIE mode interrupts now emulated in generic code via an hrtimer,
no one calls rtc_class_ops->irq_set_state(), so this patch removes it
along with driver implementations.

CC: Thomas Gleixner <tglx@linutronix.de>
CC: Alessandro Zummo <a.zummo@towertech.it>
CC: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
CC: rtc-linux@googlegroups.com
Signed-off-by: John Stultz <john.stultz@linaro.org>
3bcbaf6e08d8d82cde781997bd2c56dda87049b5 22-Feb-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de> rtc: cmos: Add OF bindings

This allows to load the OF driver based informations from the device
tree. Systems without BIOS may need to perform some initialization.
PowerPC creates a PNP device from the OF information and performs this
kind of initialization in their private PCI quirk. This looks more
generic.

This patch also avoids registering the platform RTC driver on X86 if
we have a device tree blob. Otherwise we would setup the device based
on the hardcoded information in arch/x86 rather than the device tree
based one.

[ tglx: Changed "int of_have_populated_dt()" to bool as recommended by
Grant ]

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: sodaville@linutronix.de
Cc: devicetree-discuss@lists.ozlabs.org
Cc: rtc-linux@googlegroups.com
Cc: Alessandro Zummo <a.zummo@towertech.it>
LKML-Reference: <1298405266-1624-12-git-send-email-bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2fb08e6ca9f00d1aedb3964983e9c8f84b36b807 13-Jan-2011 Paul Fox <pgf@laptop.org> rtc-cmos: fix suspend/resume

rtc-cmos was setting suspend/resume hooks at the device_driver level.
However, the platform bus code (drivers/base/platform.c) only looks for
resume hooks at the dev_pm_ops level, or within the platform_driver.

Switch rtc_cmos to use dev_pm_ops so that suspend/resume code is executed
again.

Paul said:

: The user visible symptom in our (XO laptop) case was that rtcwake would
: fail to wake the laptop. The RTC alarm would expire, but the wakeup
: wasn't unmasked.
:
: As for severity, the impact may have been reduced because if I recall
: correctly, the bug only affected platforms with CONFIG_PNP disabled.

Signed-off-by: Paul Fox <pgf@laptop.org>
Signed-off-by: Daniel Drake <dsd@laptop.org>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: <stable@kernel.org> [2.6.37.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
8cb7c71bda16e2d67a332642661e0b4219641a23 14-Oct-2010 Srikanth Krishnakar <skrishna@mvista.com> rtc-cmos.c : Fix warning on PowerPC

The following warning is seen while compilation of PowerPC kernel:

CC drivers/rtc/rtc-cmos.o
drivers/rtc/rtc-cmos.c:697:2: warning: #warning Assuming 128 bytes
of RTC+NVRAM address space, not 64 bytes.

Fix it by adding defined(__powerpc__).

Signed-off-by: Srikanth Krishnakar <skrishna@mvista.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
de639c311689f4dbf3f9df734a8243e7e44b79da 11-Aug-2010 Christian Dietrich <qy03fugy@stud.informatik.uni-erlangen.de> drivers/rtc: remove unneeded ifdef CONFIG_PM

Because CONFIG_PM is a precondition to CONFIG_ACPI, the ifdef CONFIG_PM
within ifdef CONFIG_ACPI is redundant.

Signed-off-by: Christian Dietrich <qy03fugy@stud.informatik.uni-erlangen.de>
Acked-by: Wan ZongShun <mcuos.com@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
6ba8bcd457d9fc793ac9435aa2e4138f571d4ec5 24-May-2010 Dan Carpenter <error27@gmail.com> rtc-cmos: do dev_set_drvdata() earlier in the initialization

The bug is an oops when dev_get_drvdata() returned null in
cmos_update_irq_enable(). The call tree looks like this:
rtc_dev_ioctl()
=> rtc_update_irq_enable()
=> cmos_update_irq_enable()

It's caused by a race condition in the module initialization. It is
rtc_device_register() which makes the ioctl operations live so I moved
the call to dev_set_drvdata() before the call to rtc_device_register().

Addresses https://bugzilla.kernel.org/show_bug.cgi?id=15963

Reported-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Dan Carpenter <error27@gmail.com>
Tested-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Paul Gortmaker <p_gortmaker@yahoo.com>
Cc: Malte Schroder <maltesch@gmx.de>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
3804a89bfb84fb8849c72e3bbafddaee539b3430 29-Apr-2010 Arnaud Patard <apatard@mandriva.com> RTC: rtc-cmos: Fix binary mode support

As a follow-up to the thread about RTC support for some Loongson 2E/2F
boards, this patch tries to address the "REVISIT"/"FIXME" comments about
rtc binary mode handling and allow rtc to work with rtc in binary mode.
I've also raised the message about 24-h mode not supported to warning
otherwise, one may end up with no rtc without any message in the kernel
log.

Signed-off-by: Arnaud Patard <apatard@mandriva.com>
To: linux-mips@linux-mips.org
To: rtc-linux@googlegroups.com
Cc: david-b@pacbell.net
Cc: a.zummo@towertech.it
Cc: akpm@linux-foundation.org
Patchwork: http://patchwork.linux-mips.org/patch/1158/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2c3c8bea608866d8bd9dcf92657d57fdcac011c5 13-May-2010 Chris Wright <chrisw@sous-sol.org> sysfs: add struct file* to bin_attr callbacks

This allows bin_attr->read,write,mmap callbacks to check file specific data
(such as inode owner) as part of any privilege validation.

Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
004731b2c7c658d36bee167cb1e1a399c2cbccc9 08-Jan-2010 OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> rtc_cmos: convert shutdown to new pnp_driver->shutdown

commit abd6633c67925f90775bb74755f9c547e30f1f20 ("pnp: add a shutdown
method to pnp drivers") adds shutdown method to bus driver blindly. With
it, driver->shutdown is no longer valid.

Use pnp_driver->shutdown instead.

Addresses http://bugzilla.kernel.org/show_bug.cgi?id=14889

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Reported-by: Malte Schröder <maltesch@gmx.de>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: David Hardeman <david@hardeman.nu>
Cc: Dmitry Torokhov <dtor@mail.ru>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Paul Gortmaker <p_gortmaker@yahoo.com>
Cc: <stable@kernel.org> [2.6.32.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
95abd0dfaf5d2741dc9ebe733c9d609629a92b77 05-Nov-2009 Wu Zhangjin <wuzhangjin@gmail.com> RTC: rtc-cmos.c: Fix warning on MIPS

This patch fixes the following warning with RTC_LIB on MIPS:

drivers/rtc/rtc-cmos.c:697:2: warning: #warning Assuming 128 bytes of
RTC+NVRAM address space, not 64 bytes.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
Cc: Arnaud Patard <apatard@mandriva.com>
Cc: linux-mips@linux-mips.org
Cc: rtc-linux@googlegroups.com
Cc: Paul Gortmaker <p_gortmaker@yahoo.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Patchwork: http://patchwork.linux-mips.org/patch/570/
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
a8462ef63c961639a743f9fcddf408da46641281 16-Dec-2009 Herton Ronaldo Krzesinski <herton@mandriva.com.br> rtc-cmos: convert RTC_AIE/RTC_UIE to rtc irq API

Drop ioctl function that handles RTC_AIE/RTC_UIE, and use instead the
rtc subsystem API (alarm_irq_enable/update_irq_enable callbacks).

Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
d1b2efa83fbf7b33919238fa29ef6ab935820103 16-Dec-2009 Maxim Levitsky <maximlevitsky@gmail.com> rtc: disable hpet emulation on suspend

I noticed that rtc wont generate interrupts after a resume from disk.
Here hpet rtc emulation is used.

Problem is that rtc hpet comparator, isn't reinitialized after resume.
Easiest way to solve this, is always mask all hpet interrupts on suspend
This is triggered, when suspending with alarm set.

Otherwise, hpet driver will think it doesn't need to reinitialize
the rtc comparator, thus rtc interrupts won't work.

This emulation isn't need for wakealarm.

Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
659098141d02eb8e3545be8969d262e02d2f3f98 30-Jul-2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com> rtc: mark if rtc-cmos drivers were successfully registered

rtc-cmos has two drivers, one PNP and one platform. When PNP has not
succeeded probing, platform is registered. However, it tries to
unregister both drivers unconditionally, instead of only unregistering
those that were successfully registered. This causes runtime warnings to
be emitted from the driver core code.

Fix this with a boolean variable for each driver indicating whether
registering was successful.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Alessandro Zummo <alessandro.zummo@towertech.it>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David Brownell <david-b@pacbell.net>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Greg KH <greg@kroah.com>
Cc: Ozan Caglayan <ozan@pardus.org.tr>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
6d029b645175ae71fdeedea84b246ecb1362d003 21-Apr-2009 Krzysztof Halasa <khc@pm.waw.pl> rtc-cmos: fix printk output

With no IRQ available/defined, RTC-CMOS driver prints something like:
rtc0: alarms up to one no, y3k, 114 bytes nvram
^^^^
I guess the following is a bit easier to understand:
rtc0: no alarms, y3k, 114 bytes nvram

Signed-off-by: Krzysztof Halasa <khc@pm.waw.pl>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
5d2a50371ddf127afa782ad3147469be8e9bd69f 06-Jan-2009 Jonathan Cameron <jic23@cam.ac.uk> rtc: move power of 2 periodic frequency check down into drivers

Move the power of 2 check on frequencies down into individual rtc drivers

This is to allow for non power of 2 real time clock periodic interrupts
such as those on the pxa27x to be found in the new pxa27x-rtc driver

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2fac6674ddf3164da42a76d62f8912073d629a30 06-Jan-2009 Anton Vorontsov <avorontsov@ru.mvista.com> rtc: bunch of drivers: fix 'no irq' case handing

This patch fixes a bunch of irq checking misuses. Most drivers were
getting irq via platform_get_irq(), which returns -ENXIO or r->start.

rtc-cmos.c is special. It is using PNP and platform bindings. Hopefully
nobody is using PNP IRQ 0 for RTC. So the changes should be safe.

rtc-sh.c is using platform_get_irq, but was storing a result into an
unsigned type, then was checking for < 0. This is fixed now.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
d4afc76c0b59a37113e184004f8a9989cfc1ddd3 06-Jan-2009 Kay Sievers <kay.sievers@vrfy.org> rtc: struct device: replace bus_id with dev_name(), dev_set_name()

Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Acked-By: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
80bb26d4062657c52862d1b112beead47ff9b793 06-Nov-2008 Frans Pop <elendil@planet.nl> rtc-cmos: fix boot log message

-rtc0: alarms up to one month, y3k, 114 bytes nvram, , hpet irqs irqs
+rtc0: alarms up to one month, y3k, 114 bytes nvram, hpet irqs

Signed-off-by: Frans Pop <elendil@planet.nl>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
01e8ef11bc1a74e65678ed55795f59266d4add01 19-Oct-2008 Parag Warudkar <parag.lkml@gmail.com> x86: sysfs: kill owner field from attribute

Tejun's commit 7b595756ec1f49e0049a9e01a1298d53a7faaa15 made sysfs
attribute->owner unnecessary. But the field was left in the structure to
ease the merge. It's been over a year since that change and it is now
time to start killing attribute->owner along with its users - one arch at
a time!

This patch is attempt #1 to get rid of attribute->owner only for
CONFIG_X86_64 or CONFIG_X86_32 . We will deal with other arches later on
as and when possible - avr32 will be the next since that is something I
can test. Compile (make allyesconfig / make allmodconfig / custom config)
and boot tested.

akpm: the idea is that we put the declaration of sttribute.owner inside
`#ifndef CONFIG_X86'. But that proved to be too ambitious for now because
new usages kept on turning up in subsystem trees.

[akpm: remove the ifdef for now]
Signed-off-by: Parag Warudkar <parag.lkml@gmail.com>
Cc: Greg KH <greg@kroah.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Tejun Heo <htejun@gmail.com>
Cc: Len Brown <lenb@kernel.org>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Roland Dreier <rolandd@cisco.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fe20ba70abf7d6e5855c3dacc729490b3d0d077f 19-Oct-2008 Adrian Bunk <bunk@kernel.org> drivers/rtc/: use bcd2bin/bin2bcd

Change drivers/rtc/ to use the new bcd2bin/bin2bcd functions instead of
the obsolete BCD_TO_BIN/BIN_TO_BCD/BCD2BIN/BIN2BCD macros.

Signed-off-by: Adrian Bunk <bunk@kernel.org>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
c8fc40cd345bfd88d8a98e7916909b9143502999 19-Oct-2008 David Brownell <dbrownell@users.sourceforge.net> rtc-cmos: export second NVRAM bank

Teach rtc-cmos about the second bank of registers found on most modern x86
systems, giving access to 128 bytes more NVRAM.

This version only sees that extra NVRAM when both register banks are
provided as part of *one* PNP resource. Since BIOS on some systems
presents them using two IO resources, and nothing merges them, this can't
always show all the NVRAM. (We're supposed to be able to use PNP id
PNP0b01 too, but BIOS tables doesn't often seem to use that particular
option.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
bb93d802ae5c1949977cc6da247b218240677f11 19-Oct-2008 David Brownell <dbrownell@users.sourceforge.net> rtc-cmos: export second NVRAM bank

Teach rtc-cmos about the second bank of registers found on most modern x86
systems, giving access to 128 bytes more NVRAM.

This version only sees that extra NVRAM when both register banks are
provided as part of *one* PNP resource. Since BIOS on some systems
presents them using two IO resources, and nothing merges them, this can't
always show all the NVRAM. (We're supposed to be able to use PNP id
PNP0b01 too, but BIOS tables doesn't often seem to use that particular
option.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: torvalds@linux-foundation.org
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
72f22b1eb6ca5e4676a632a04d40d46cb61d4562 15-Oct-2008 Bjorn Helgaas <bjorn.helgaas@hp.com> rtc-cmos: look for PNP RTC first, then for platform RTC

We shouldn't rely on "pnp_platform_devices" to tell us whether there
is a PNP RTC device.

I introduced "pnp_platform_devices", but I think it was a mistake.
All it tells us is whether we found any PNPBIOS or PNPACPI devices.
Many machines have some PNP devices, but do not describe the RTC
via PNP. On those machines, we need to do the platform driver probe
to find the RTC.

We should just register the PNP driver and see whether it claims anything.
If we don't find a PNP RTC, fall back to the platform driver probe.

This (in conjunction with the arch/x86/kernel/rtc.c patch to add
a platform RTC device when PNP doesn't have one) should resolve
these issues:

http://bugzilla.kernel.org/show_bug.cgi?id=11580
https://bugzilla.redhat.com/show_bug.cgi?id=451188

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Reported-by: Rik Theys <rik.theys@esat.kuleuven.be>
Reported-by: shr_msn@yahoo.com.tw
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
a474aaedac99ba86e28ef6c912a7647c482db6dd 14-Oct-2008 Bjorn Helgaas <bjorn.helgaas@hp.com> rtc-cmos: move wake setup from ACPI glue into RTC driver

Move rtc_wake_setup() from drivers/acpi/glue.c into the RTC driver
in drivers/rtc/rtc-cmos.c.

This removes the ordering constraint between the module_init(acpi_rtc_init)
and the cmos_do_probe() code that depends on it.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
74c4633da7994eddcfcd2762a448c6889cc2b5bd 02-Sep-2008 Rafael J. Wysocki <rjw@sisk.pl> rtc-cmos: wake again from S5

Update rtc-cmos shutdown handling to leave RTC alarms active, resolving
http://bugzilla.kernel.org/show_bug.cgi?id=11411 on several boards. There
are still some systems where the ACPI event handling doesn't cooperate.
(Possibly related to bugid 11312, reporting the spontaneous disabling of
RTC events.)

Bug 11411 reported that changes to work around some ACPI event issues
broke wake-from-S5 handling, as used for DVR applications. (They like to
power off, then wake later to record programs.)

[yakui.zhao@intel.com: add shutdown for PNP devices]
[dbrownell@users.sourceforge.net: update comments]
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Stefan Bauer <stefan.bauer@cs.tu-chemnitz.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
582defd8ddb90448d72692a8e1d5b2966d2ed819 29-Aug-2008 David S. Miller <davem@davemloft.net> rtc: Allow RTC_DRV_CMOS to be used on SPARC.

Add Sparc to the Kconfig depends list.

Add __sparc___ to address_sparc = 128 ifdef.

Finally, don't be concerned about 24-hour BCD mode support if the RTC
doesn't have a valid IRQ. We won't even use the alarm code in this
case and the Sparc RTCs have this limitation.

Signed-off-by: David S. Miller <davem@davemloft.net>
7e2a31da854dcf8324012a83a31b40bc11e52589 24-Jul-2008 David Brownell <dbrownell@users.sourceforge.net> rtc-cmos: avoid spurious irqs

This fixes kernel http://bugzilla.kernel.org/show_bug.cgi?id=11112 (bogus
RTC update IRQs reported) for rtc-cmos, in two ways:

- When HPET is stealing the IRQs, use the first IRQ to grab
the seconds counter which will be monitored (instead of
using whatever was previously in that memory);

- In sane IRQ handling modes, scrub out old IRQ status before
enabling IRQs.

That latter is done by tightening up IRQ handling for rtc-cmos everywhere,
also ensuring that when HPET is used it's the only thing triggering IRQ
reports to userspace; net object shrink.

Also fix a bogus HPET message related to its RTC emulation.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Report-by: W Unruh <unruh@physics.ubc.ca>
Cc: Andrew Victor <avictor.za@gmail.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
35d3fdd5f304c06654c940921fc045c60df34693 24-Jul-2008 David Brownell <dbrownell@users.sourceforge.net> rtc-cmos: improve HPET IRQ glue

Resolve http://bugzilla.kernel.org/show_bug.cgi?id=11051 and other bugs
related to the way the HPET glue code in rtc-cmos was incomplete and
inconsistent:

* Switch the approach so that the basic driver code flow isn't
changed by having HPET ... instead, just have HPET shadow the
RTC_CONTROL irq enables and RTC_FREQ_SELECT data. It's only
coping with IRQ thievery, after all.

* Do that consistently (!!) to avoid problems when the HPET code
is out of sync with the real RTC intent. Examples include:

- cmos_procfs(), which now reports correct data

- cmos_irq_set_state() ... also removing the previous PIE_{ON,OFF}
ioctl support so only one code path manages "periodic" IRQs

- cmos_do_shutdown() ... currently a "just in case" change.

- cmos_suspend() and cmos_resume() ... also handling a bug that
was specific to HPET's IRQ thievery, where the alarm wasn't
disabled after waking the system

* Always call that HPET code under the RTC spinlock (it doesn't do
its own locking)

Also clean up the HPET glue:

* Add some comments explaining what's going on.

* Switch to having just one #ifdef for the HPET glue, and inline
functions (not #defines) to avoid some compiler warnings.

* Have the probe message also report when HPET IRQs are involved

This still leaves various holes in the HPET glue, like the emulated update
IRQs being out of sync with the RTC, alarms never using day or month
matches, and many extra IRQs (at 64 Hz).

[akpm@linux-foundation.org: fix build]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Tomas Janousek <tomi@nomi.cz>
Cc: Bernhard Walle <bwalle@suse.de>
Cc: Carlos R. Mafra <crmafra@ift.unesp.br>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
c68d07b2da54c941bb36c9d6d35fe8f263ee10ef 24-Jul-2008 Carlos R. Mafra <crmafra@ift.unesp.br> rtc: remove and clarify unneeded externs

When CONFIG_HPET_EMULATE_RTC is defined the external declaration of
hpet_rtc_interrupt is redundant due to the inclusion of hpet.h.

When !CONFIG_HPET_EMULATE_RTC we make it clear that hpet_rtc_interrupt is
not used by defining it to return zero.

Signed-off-by: Carlos R. Mafra <crmafra@ift.unesp.br>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1da2e3d679a8ea2d9e82040359a706da0bd3bef6 13-Jun-2008 Stas Sergeev <stsp@aknet.ru> provide rtc_cmos platform device

Recently (around 2.6.25) I've noticed that RTC no longer works for me. It
turned out this is because I use pnpacpi=off kernel option to work around
the parport_pc bugs. I always did so, but RTC used to work fine in the
past, and now it have regressed.

The patch fixes the problem by creating the platform device for the RTC
when PNP is disabled. This may also help running the PNP-enabled kernel
on an older PCs.

Signed-off-by: Stas Sergeev <stsp@aknet.ru>
Cc: David Brownell <david-b@pacbell.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Adam Belay <ambx1@neo.rr.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
8766ad0ce8621aa6f0e4a91ef355509cc3364d5b 29-Apr-2008 Bjorn Helgaas <bjorn.helgaas@hp.com> rtc: dont reference pnp_resource_table directly

pnp_resource_table is going away soon, so use the more
generic public interfaces instead.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2b653e06ce2d70d21483f22ef1b1b63749c54223 15-Apr-2008 Zhao Yakui <yakui.zhao@intel.com> rtc: fix the error in the function of cmos_set_alarm

There is a bug in the function of cmos_set_alarm. RTC alarm time for October
can't be set correctly.

For October: 0x0A will be written into the RTC region (MONTH_ALARM) in current
kernel. But in fact 0x10 should be written. Wildcards are also not handled
correctly.

Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
ad28a07bcadc5945f7a90d9de3a196825e69d9d3 11-Apr-2008 Kay Sievers <kay.sievers@vrfy.org> rtc: fix platform driver hotplug/coldplug

Since 43cc71eed1250755986da4c0f9898f9a635cb3bf, the platform modalias is
prefixed with "platform:". Add MODULE_ALIAS() to the hotpluggable RTC
platform drivers, to re-enable module auto loading.

[dbrownell@users.sourceforge.net: more drivers, minor fix]
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Greg KH <greg@kroah.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
c8626a1d7250c593f148530b559c20f6f6af18e8 24-Feb-2008 David Brownell <david-b@pacbell.net> rtc-cmos: display HPET emulation mode

For the "cmos" RTC, have /proc/driver/rtc say whether HPET based IRQ
emulation is in effect. Given the problems we've had with this particular
hardware maldesign (and the fact that most BIOS code seems not to provide
the IRQ routing needed to use the saner HPET modes), this should help
troubleshooting.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
9d8af78b07976d4d84e0df491abd4e9db848d0ad 06-Feb-2008 Bernhard Walle <bwalle@suse.de> rtc: add HPET RTC emulation to RTC_DRV_CMOS

That patch adds the RTC emulation of the HPET timer to the new RTC_DRV_CMOS.
The old drivers/char/rtc.ko driver had that functionality and it's important
on new systems.

[akpm@linux-foundation.org: unbreak alpha build]
Signed-off-by: Bernhard Walle <bwalle@suse.de>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andi Kleen <ak@suse.de>
Cc: john stultz <johnstul@us.ibm.com>
Cc: Robert Picco <Robert.Picco@hp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
8a0bdfd7a05f5bb0486fbe7146a2cf775957e95e 06-Feb-2008 David Brownell <david-b@pacbell.net> rtc-cmos alarm acts as oneshot

Start making the rtc-cmos alarm act more like a oneshot alarm by disabling
that alarm after its IRQ fires. (ACPI hooks are also needed.)

The Linux RTC framework has previously been a bit vague in this area, but
any other behavior is problematic and not very portable. RTCs with full
YYYY-MM-DD HH:MM[:SS] alarms won't have a problem here. Only ones with
partial match criteria, with the most visible example being the PC RTC, get
confused. (Because the criteria will match repeatedly.)

Update comments relating to that oneshot behavior and timezone handling.
(Timezones are another issue that's mostly visible with rtc-cmos. That's
because PCs often dual-boot MS-Windows, which likes its RTC to match local
wall-clock time instead of UTC.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
e07e232cd96ef0092b2bddc72f9b7caf284633cb 06-Feb-2008 David Brownell <david-b@pacbell.net> rtc-cmos: export nvram in sysfs

This makes rtc-cmos export its NVRAM, like several other RTC drivers.

It still works within the limits of the current CMOS_READ/CMOS_WRITE calls,
which don't understand how to access multiple register banks. The primary
impact of that limitation is that Linux can't access the uppermost 128
bytes of NVRAM on many systems.

Note that this isn't aiming to be a drop-in replacement for the legacy
/dev/nvram support. (Presumably that has real users, and isn't just
getting carried forward automatically?) Userspace handles more work:

- When userspace code updates NVRAM, that will need to include
updating any platform-specific checksums that may apply.

- No /proc/driver/nvram file will parse and display NVRAM data
according to whichever boot firmware your board expects.

Also minor pnp-related updates: update a comment, remove dead code.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
615bb29ccbe9fa06d9f33b29d9c3f51340726656 04-Nov-2007 Mark Lord <lkml@rtr.ca> rtc: ignore msb when reading back mday from alarm

I have a system here that actively relies upon RTC wake alarms, and it
has been failing (again) for a few days when attempting to use the
/sys/class/rtc/rtc?/wakealarm interface.

The old (fixed by Linus) /proc/ interface still works, but I'd like to
get it using the new one.

This patch fixes rtc-cmos to ignore the two upper bits when reading the
BCD mday (day of month) register from CMOS. Some systems (eg. mine)
seem to have the top bit set to "1" for some reason.

The older /proc/ interface ignores the upper bits, and so we should too.

Signed-off-by: Mark Lord <mlord@pobox.com>
Acked-by: David Brownell <david-b@pacbell.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
05440dfcfcabde6fcf7297dfa5a29f0355b78ffb 16-Oct-2007 David Brownell <david-b@pacbell.net> rtc-cmos probe() cleanup

Some cleanups for the rtc-cmos probe logic:

- Claim i/o ports with request_region() not request_resource(),
for better coexistence betwen platform and pnp bus glues.

- Claim those ports earlier, to help work around procfs bugs
(it allows duplicate names, like /proc/driver/rtc).

- Fix some glitches in cleanup code, notably a cut'n'paste-o
where the i/o port region might not get released during
cleanup after a probe fault.

And some comment clarifications, including noting that this code
must work with PNPBIOS not just PNPACPI..

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
97144c67566241db46633727f2860e6428373fe4 16-Oct-2007 David Brownell <david-b@pacbell.net> rtc_irq_set_freq() requires power-of-two and associated kerneldoc

RTC periodic IRQs are only defined to work for 2^N Hz values. This patch
moves that validity check into the infrastructure, so drivers don't need to
check it; and adds kerneldoc for the two interface functions related to
periodic IRQs. (One of which was quite mysterious until its first use was
recently checked in!)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
57deb52622f3700d154e32662f36cd5f4053f6ed 19-Jul-2007 Alessandro Zummo <alessandro.zummo@towertech.it> RTC: add periodic irq support to rtc-cmos

Adds support for periodic irq enabling in rtc-cmos. This could be used by
the ALSA driver and is already being tested with the zaptel ztdummy module.

Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
6cd8fa87fbf31b2ab77b8aaec497e7f6a3757578 01-Jun-2007 Matthew Garrett <mjg59@srcf.ucam.org> RTC: use fallback IRQ if PNP tables don't provide one

Intel Macs (and possibly other machines) provide a PNP entry for the RTC,
but provide no IRQ. As a result the rtc-cmos driver doesn't allow wakeup
alarms. If the RTC is located at the legacy ioport range, assume that it's
on IRQ 8 unless the tables say otherwise.

Signed-off-by: Matthew Garrett <mjg59@srcf.ucam.org>
Cc: Matthieu CASTET <castet.matthieu@free.fr>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
41ac8df9d5b731a4dd8f1f4e5a9de6ef8768383d 08-May-2007 Marko Vrh <mvrh@freeshells.ch> rtc-cmos: make it load on PNPBIOS systems

Replace CONFIG_PNPACPI with CONFIG_PNP, so it loads on ACPI-less PNPBIOS
systems.

Signed-off-by: Marko Vrh <mvrh@freeshells.ch>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
87ac84f42a7a580d0dd72ae31d6a5eb4bfe04c6d 08-May-2007 David Brownell <david-b@pacbell.net> rtc-cmos wakeup interface

I finally got around to testing the updated wakeup event hooks for rtc-cmos,
and they follow in two patches:

- Interface update ... when a simple enable_irq_wake() doesn't suffice,
the platform data can hold suspend/resume callback hooks.

- ACPI implementation ... provides callback hooks to do ACPI magic, and
eliminate the legacy /proc/acpi/alarm file.

The interface update could go into 2.6.21, but that's not essential; they
will be NOPs on most PCs, without the ACPI stuff.

I suspect the ACPI folk may have opinions about how to merge that second
patch, and how to obsolete that legacy procfs file. I'd like to see that
merge into 2.6.22 if possible...

As for how to kick it in ... two ways:

- The appended "rtcwake" program; updated since the last time it was
posted, it deals much better with timezones and DST.

- Write the /sys/class/rtc/.../wakealarm file, then go to sleep.

For some reason RTC wake from "swsusp" stopped working on a system where
it previously worked; the alarm setting appears to get clobbered. But
on the bright side, RTC wake from "standby" worked on a system that had
never been able to resume from that state before ... IDEACPI is my guess
as to why it finally started to work. It's the old "two steps forward,
one step back" dance, I guess.

- Dave

/* gcc -Wall -Os -o rtcwake rtcwake.c */

#include <stdio.h>
#include <getopt.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>

#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>

#include <linux/rtc.h>

/* constants from legacy PC/AT hardware */
#define RTC_PF 0x40
#define RTC_AF 0x20
#define RTC_UF 0x10

/*
* rtcwake -- enter a system sleep state until specified wakeup time.
*
* This uses cross-platform Linux interfaces to enter a system sleep state,
* and leave it no later than a specified time. It uses any RTC framework
* driver that supports standard driver model wakeup flags.
*
* This is normally used like the old "apmsleep" utility, to wake from a
* suspend state like ACPI S1 (standby) or S3 (suspend-to-RAM). Most
* platforms can implement those without analogues of BIOS, APM, or ACPI.
*
* On some systems, this can also be used like "nvram-wakeup", waking
* from states like ACPI S4 (suspend to disk). Not all systems have
* persistent media that are appropriate for such suspend modes.
*
* The best way to set the system's RTC is so that it holds the current
* time in UTC. Use the "-l" flag to tell this program that the system
* RTC uses a local timezone instead (maybe you dual-boot MS-Windows).
*/

static char *progname;

#ifdef DEBUG
#define VERSION "1.0 dev (" __DATE__ " " __TIME__ ")"
#else
#define VERSION "0.9"
#endif

static unsigned verbose;
static int rtc_is_utc = -1;

static int may_wakeup(const char *devname)
{
char buf[128], *s;
FILE *f;

snprintf(buf, sizeof buf, "/sys/class/rtc/%s/device/power/wakeup",
devname);
f = fopen(buf, "r");
if (!f) {
perror(buf);
return 0;
}
fgets(buf, sizeof buf, f);
fclose(f);

s = strchr(buf, '\n');
if (!s)
return 0;
*s = 0;

/* wakeup events could be disabled or not supported */
return strcmp(buf, "enabled") == 0;
}

/* all times should be in UTC */
static time_t sys_time;
static time_t rtc_time;

static int get_basetimes(int fd)
{
struct tm tm;
struct rtc_time rtc;

/* this process works in RTC time, except when working
* with the system clock (which always uses UTC).
*/
if (rtc_is_utc)
setenv("TZ", "UTC", 1);
tzset();

/* read rtc and system clocks "at the same time", or as
* precisely (+/- a second) as we can read them.
*/
if (ioctl(fd, RTC_RD_TIME, &rtc) < 0) {
perror("read rtc time");
return 0;
}
sys_time = time(0);
if (sys_time == (time_t)-1) {
perror("read system time");
return 0;
}

/* convert rtc_time to normal arithmetic-friendly form,
* updating tm.tm_wday as used by asctime().
*/
memset(&tm, 0, sizeof tm);
tm.tm_sec = rtc.tm_sec;
tm.tm_min = rtc.tm_min;
tm.tm_hour = rtc.tm_hour;
tm.tm_mday = rtc.tm_mday;
tm.tm_mon = rtc.tm_mon;
tm.tm_year = rtc.tm_year;
tm.tm_isdst = rtc.tm_isdst; /* stays unspecified? */
rtc_time = mktime(&tm);

if (rtc_time == (time_t)-1) {
perror("convert rtc time");
return 0;
}

if (verbose) {
if (!rtc_is_utc) {
printf("\ttzone = %ld\n", timezone);
printf("\ttzname = %s\n", tzname[daylight]);
gmtime_r(&rtc_time, &tm);
}
printf("\tsystime = %ld, (UTC) %s",
(long) sys_time, asctime(gmtime(&sys_time)));
printf("\trtctime = %ld, (UTC) %s",
(long) rtc_time, asctime(&tm));
}

return 1;
}

static int setup_alarm(int fd, time_t *wakeup)
{
struct tm *tm;
struct rtc_wkalrm wake;

tm = gmtime(wakeup);

wake.time.tm_sec = tm->tm_sec;
wake.time.tm_min = tm->tm_min;
wake.time.tm_hour = tm->tm_hour;
wake.time.tm_mday = tm->tm_mday;
wake.time.tm_mon = tm->tm_mon;
wake.time.tm_year = tm->tm_year;
wake.time.tm_wday = tm->tm_wday;
wake.time.tm_yday = tm->tm_yday;
wake.time.tm_isdst = tm->tm_isdst;

/* many rtc alarms only support up to 24 hours from 'now' ... */
if ((rtc_time + (24 * 60 * 60)) > *wakeup) {
if (ioctl(fd, RTC_ALM_SET, &wake.time) < 0) {
perror("set rtc alarm");
return 0;
}
if (ioctl(fd, RTC_AIE_ON, 0) < 0) {
perror("enable rtc alarm");
return 0;
}

/* ... so use the "more than 24 hours" request only if we must */
} else {
/* avoid an extra AIE_ON call */
wake.enabled = 1;

if (ioctl(fd, RTC_WKALM_SET, &wake) < 0) {
perror("set rtc wake alarm");
return 0;
}
}

return 1;
}

static void suspend_system(const char *suspend)
{
FILE *f = fopen("/sys/power/state", "w");

if (!f) {
perror("/sys/power/state");
return;
}

fprintf(f, "%s\n", suspend);
fflush(f);

/* this executes after wake from suspend */
fclose(f);
}

int main(int argc, char **argv)
{
static char *devname = "rtc0";
static unsigned seconds = 0;
static char *suspend = "standby";

int t;
int fd;
time_t alarm = 0;

progname = strrchr(argv[0], '/');
if (progname)
progname++;
else
progname = argv[0];
if (chdir("/dev/") < 0) {
perror("chdir /dev");
return 1;
}

while ((t = getopt(argc, argv, "d:lm:s:t:uVv")) != EOF) {
switch (t) {

case 'd':
devname = optarg;
break;

case 'l':
rtc_is_utc = 0;
break;

/* what system power mode to use? for now handle only
* standardized mode names; eventually when systems define
* their own state names, parse /sys/power/state.
*
* "on" is used just to test the RTC alarm mechanism,
* bypassing all the wakeup-from-sleep infrastructure.
*/
case 'm':
if (strcmp(optarg, "standby") == 0
|| strcmp(optarg, "mem") == 0
|| strcmp(optarg, "disk") == 0
|| strcmp(optarg, "on") == 0
) {
suspend = optarg;
break;
}
printf("%s: unrecognized suspend state '%s'\n",
progname, optarg);
goto usage;

/* alarm time, seconds-to-sleep (relative) */
case 's':
t = atoi(optarg);
if (t < 0) {
printf("%s: illegal interval %s seconds\n",
progname, optarg);
goto usage;
}
seconds = t;
break;

/* alarm time, time_t (absolute, seconds since 1/1 1970 UTC) */
case 't':
t = atoi(optarg);
if (t < 0) {
printf("%s: illegal time_t value %s\n",
progname, optarg);
goto usage;
}
alarm = t;
break;

case 'u':
rtc_is_utc = 1;
break;

case 'v':
verbose++;
break;

case 'V':
printf("%s: version %s\n", progname, VERSION);
break;

default:
usage:
printf("usage: %s [options]"
"\n\t"
"-d rtc0|rtc1|...\t(select rtc)"
"\n\t"
"-l\t\t\t(RTC uses local timezone)"
"\n\t"
"-m standby|mem|...\t(sleep mode)"
"\n\t"
"-s seconds\t\t(seconds to sleep)"
"\n\t"
"-t time_t\t\t(time to wake)"
"\n\t"
"-u\t\t\t(RTC uses UTC)"
"\n\t"
"-v\t\t\t(verbose messages)"
"\n\t"
"-V\t\t\t(show version)"
"\n",
progname);
return 1;
}
}

if (!alarm && !seconds) {
printf("%s: must provide wake time\n", progname);
goto usage;
}

/* REVISIT: if /etc/adjtime exists, read it to see what
* the util-linux version of hwclock assumes.
*/
if (rtc_is_utc == -1) {
printf("%s: assuming RTC uses UTC ...\n", progname);
rtc_is_utc = 1;
}

/* this RTC must exist and (if we'll sleep) be wakeup-enabled */
fd = open(devname, O_RDONLY);
if (fd < 0) {
perror(devname);
return 1;
}
if (strcmp(suspend, "on") != 0 && !may_wakeup(devname)) {
printf("%s: %s not enabled for wakeup events\n",
progname, devname);
return 1;
}

/* relative or absolute alarm time, normalized to time_t */
if (!get_basetimes(fd))
return 1;
if (verbose)
printf("alarm %ld, sys_time %ld, rtc_time %ld, seconds %u\n",
alarm, sys_time, rtc_time, seconds);
if (alarm) {
if (alarm < sys_time) {
printf("%s: time doesn't go backward to %s",
progname, ctime(&alarm));
return 1;
}
alarm += sys_time - rtc_time;
} else
alarm = rtc_time + seconds + 1;
if (setup_alarm(fd, &alarm) < 0)
return 1;

sync();
printf("%s: wakeup from \"%s\" using %s at %s",
progname, suspend, devname,
ctime(&alarm));
fflush(stdout);
usleep(10 * 1000);

if (strcmp(suspend, "on") != 0)
suspend_system(suspend);
else {
unsigned long data;

do {
t = read(fd, &data, sizeof data);
if (t < 0) {
perror("rtc read");
break;
}
if (verbose)
printf("... %s: %03lx\n", devname, data);
} while (!(data & RTC_AF));
}

if (ioctl(fd, RTC_AIE_OFF, 0) < 0)
perror("disable rtc alarm interrupt");

close(fd);
return 0;
}

This patch:

Make rtc-cmos do the relevant magic so this RTC can wake the system from a
sleep state. That magic comes in two basic flavors:

- Straightforward: enable_irq_wake(), the way it'd work on most SOC chips;
or generally with system sleep states which don't disable core IRQ logic.

- Roundabout, using non-IRQ platform hooks. This is needed with ACPI and
one almost-clone chip which uses a special wakeup-only alarm. (That's
the RTC used on Footbridge boards, FWIW, which don't do PM in Linux.)

A separate patch implements those hooks for ACPI platforms, so that rtc_cmos
can issue system wakeup events (and its sysfs "wakealarm" attribute works on
at least some systems).

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Len Brown <lenb@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
cd9662094edf4173e87f0452e57e4eacc228f8ff 08-May-2007 David Brownell <david-b@pacbell.net> rtc: remove rest of class_device

Finish converting the RTC framework so it no longer uses class_device.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-By: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
ab6a2d70d18edc7a716ef3127b9e13382faec98c 08-May-2007 David Brownell <david-b@pacbell.net> rtc: rtc interfaces don't use class_device

This patch removes class_device from the programming interface that the RTC
framework exposes to the rest of the kernel. Now an rtc_device is passed,
which is more type-safe and streamlines all the relevant code.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-By: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
bcd9b89c02295b075fda4bdb666f6641f8212226 02-Apr-2007 David Brownell <david-b@pacbell.net> [PATCH] rtc-cmos lockdep fix, irq updates

Lockdep reported cmos_suspend() and cmos_resume() calling rtc_update_irq()
with IRQs enabled; not allowed.

Also fix problems seen on some hardware, whereby false alarm IRQs could be
reported (primarily to userspace); and update two comments to match changes
in ACPI. Those make up most of this patch, by volume.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
7be2c7c96aff2871240d61fef508c41176c688b5 10-Feb-2007 David Brownell <david-b@pacbell.net> [PATCH] RTC framework driver for CMOS RTCs

This is an "RTC framework" driver for the "CMOS" RTCs which are standard on
PCs and some other platforms. That's MC146818 compatible silicon.
Advantages of this vs. drivers/char/rtc.c (use one _or_ the other, only
one will be able to claim the RTC irq) include:

- This leverages both the new RTC framework and the driver model; both
PNPACPI and platform device modes are supported. (A separate patch
creates a platform device on PCs where PNPACPI isn't configured.)

- It supports common extensions like longer alarms. (A separate patch
exports that information from ACPI through platform_data.)

- Likewise, system wakeup events use "real driver model support", with
policy control via sysfs "wakeup" attributes and and using normal rtc
ioctls to manage wakeup. (Patch in the works. The ACPI hooks are
known; /proc/acpi/alarm can vanish. Making it work with EFI will
be a minor challenge to someone with e.g. a MiniMac.)

It's not yet been tested on non-x86 systems, without ACPI, or with HPET.
And the RTC framework will surely have teething pains on "mainstream"
PC-based systems (though must embedded Linux systems use it heavily), not
limited to sorting out the "/dev/rtc0" issue (udev easily tweaked). Also,
the ALSA rtctimer code doesn't use the new RTC API.

Otherwise, this should be a no-known-regressions replacement for the old
drivers/char/rtc.c driver, and should help the non-embedded distros (and
the new timekeeping code) start to switch to the framework.

Note also that any systems using "rtc-m48t86" are candidates to switch over
to this more functional driver; the platform data is different, and the way
bytes are read is different, but otherwise those chips should be compatible.

[akpm@osdl.org: sparc32 fix]
[akpm@osdl.org: sparc64 fix]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Woody Suwalski <woodys@xandros.com>
Cc: Alessandro Zummo <alessandro.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>