aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-cmos.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-cmos.c')
-rw-r--r--drivers/rtc/rtc-cmos.c127
1 files changed, 110 insertions, 17 deletions
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index b184367637d0..963ad0b6a4e9 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -636,7 +636,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
636 */ 636 */
637#if defined(CONFIG_ATARI) 637#if defined(CONFIG_ATARI)
638 address_space = 64; 638 address_space = 64;
639#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) 639#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__sparc__)
640 address_space = 128; 640 address_space = 128;
641#else 641#else
642#warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes. 642#warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes.
@@ -699,7 +699,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
699 /* FIXME teach the alarm code how to handle binary mode; 699 /* FIXME teach the alarm code how to handle binary mode;
700 * <asm-generic/rtc.h> doesn't know 12-hour mode either. 700 * <asm-generic/rtc.h> doesn't know 12-hour mode either.
701 */ 701 */
702 if (!(rtc_control & RTC_24H) || (rtc_control & (RTC_DM_BINARY))) { 702 if (is_valid_irq(rtc_irq) &&
703 (!(rtc_control & RTC_24H) || (rtc_control & (RTC_DM_BINARY)))) {
703 dev_dbg(dev, "only 24-hr BCD mode supported\n"); 704 dev_dbg(dev, "only 24-hr BCD mode supported\n");
704 retval = -ENXIO; 705 retval = -ENXIO;
705 goto cleanup1; 706 goto cleanup1;
@@ -912,6 +913,92 @@ static inline int cmos_poweroff(struct device *dev)
912 * predate even PNPBIOS should set up platform_bus devices. 913 * predate even PNPBIOS should set up platform_bus devices.
913 */ 914 */
914 915
916#ifdef CONFIG_ACPI
917
918#include <linux/acpi.h>
919
920#ifdef CONFIG_PM
921static u32 rtc_handler(void *context)
922{
923 acpi_clear_event(ACPI_EVENT_RTC);
924 acpi_disable_event(ACPI_EVENT_RTC, 0);
925 return ACPI_INTERRUPT_HANDLED;
926}
927
928static inline void rtc_wake_setup(void)
929{
930 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
931 /*
932 * After the RTC handler is installed, the Fixed_RTC event should
933 * be disabled. Only when the RTC alarm is set will it be enabled.
934 */
935 acpi_clear_event(ACPI_EVENT_RTC);
936 acpi_disable_event(ACPI_EVENT_RTC, 0);
937}
938
939static void rtc_wake_on(struct device *dev)
940{
941 acpi_clear_event(ACPI_EVENT_RTC);
942 acpi_enable_event(ACPI_EVENT_RTC, 0);
943}
944
945static void rtc_wake_off(struct device *dev)
946{
947 acpi_disable_event(ACPI_EVENT_RTC, 0);
948}
949#else
950#define rtc_wake_setup() do{}while(0)
951#define rtc_wake_on NULL
952#define rtc_wake_off NULL
953#endif
954
955/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
956 * its device node and pass extra config data. This helps its driver use
957 * capabilities that the now-obsolete mc146818 didn't have, and informs it
958 * that this board's RTC is wakeup-capable (per ACPI spec).
959 */
960static struct cmos_rtc_board_info acpi_rtc_info;
961
962static void __devinit
963cmos_wake_setup(struct device *dev)
964{
965 if (acpi_disabled)
966 return;
967
968 rtc_wake_setup();
969 acpi_rtc_info.wake_on = rtc_wake_on;
970 acpi_rtc_info.wake_off = rtc_wake_off;
971
972 /* workaround bug in some ACPI tables */
973 if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
974 dev_dbg(dev, "bogus FADT month_alarm (%d)\n",
975 acpi_gbl_FADT.month_alarm);
976 acpi_gbl_FADT.month_alarm = 0;
977 }
978
979 acpi_rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
980 acpi_rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
981 acpi_rtc_info.rtc_century = acpi_gbl_FADT.century;
982
983 /* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */
984 if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
985 dev_info(dev, "RTC can wake from S4\n");
986
987 dev->platform_data = &acpi_rtc_info;
988
989 /* RTC always wakes from S1/S2/S3, and often S4/STD */
990 device_init_wakeup(dev, 1);
991}
992
993#else
994
995static void __devinit
996cmos_wake_setup(struct device *dev)
997{
998}
999
1000#endif
1001
915#ifdef CONFIG_PNP 1002#ifdef CONFIG_PNP
916 1003
917#include <linux/pnp.h> 1004#include <linux/pnp.h>
@@ -919,6 +1006,8 @@ static inline int cmos_poweroff(struct device *dev)
919static int __devinit 1006static int __devinit
920cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) 1007cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
921{ 1008{
1009 cmos_wake_setup(&pnp->dev);
1010
922 if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0)) 1011 if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0))
923 /* Some machines contain a PNP entry for the RTC, but 1012 /* Some machines contain a PNP entry for the RTC, but
924 * don't define the IRQ. It should always be safe to 1013 * don't define the IRQ. It should always be safe to
@@ -996,6 +1085,7 @@ static struct pnp_driver cmos_pnp_driver = {
996 1085
997static int __init cmos_platform_probe(struct platform_device *pdev) 1086static int __init cmos_platform_probe(struct platform_device *pdev)
998{ 1087{
1088 cmos_wake_setup(&pdev->dev);
999 return cmos_do_probe(&pdev->dev, 1089 return cmos_do_probe(&pdev->dev,
1000 platform_get_resource(pdev, IORESOURCE_IO, 0), 1090 platform_get_resource(pdev, IORESOURCE_IO, 0),
1001 platform_get_irq(pdev, 0)); 1091 platform_get_irq(pdev, 0));
@@ -1030,29 +1120,32 @@ static struct platform_driver cmos_platform_driver = {
1030 1120
1031static int __init cmos_init(void) 1121static int __init cmos_init(void)
1032{ 1122{
1123 int retval = 0;
1124
1033#ifdef CONFIG_PNP 1125#ifdef CONFIG_PNP
1034 if (pnp_platform_devices) 1126 pnp_register_driver(&cmos_pnp_driver);
1035 return pnp_register_driver(&cmos_pnp_driver); 1127#endif
1036 else 1128
1037 return platform_driver_probe(&cmos_platform_driver, 1129 if (!cmos_rtc.dev)
1038 cmos_platform_probe); 1130 retval = platform_driver_probe(&cmos_platform_driver,
1039#else 1131 cmos_platform_probe);
1040 return platform_driver_probe(&cmos_platform_driver, 1132
1041 cmos_platform_probe); 1133 if (retval == 0)
1042#endif /* CONFIG_PNP */ 1134 return 0;
1135
1136#ifdef CONFIG_PNP
1137 pnp_unregister_driver(&cmos_pnp_driver);
1138#endif
1139 return retval;
1043} 1140}
1044module_init(cmos_init); 1141module_init(cmos_init);
1045 1142
1046static void __exit cmos_exit(void) 1143static void __exit cmos_exit(void)
1047{ 1144{
1048#ifdef CONFIG_PNP 1145#ifdef CONFIG_PNP
1049 if (pnp_platform_devices) 1146 pnp_unregister_driver(&cmos_pnp_driver);
1050 pnp_unregister_driver(&cmos_pnp_driver); 1147#endif
1051 else
1052 platform_driver_unregister(&cmos_platform_driver);
1053#else
1054 platform_driver_unregister(&cmos_platform_driver); 1148 platform_driver_unregister(&cmos_platform_driver);
1055#endif /* CONFIG_PNP */
1056} 1149}
1057module_exit(cmos_exit); 1150module_exit(cmos_exit);
1058 1151