hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rtc/rtc-cmos.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * RTC class driver for "CMOS RTC": PCs, ACPI, etc
34 *
45 * Copyright (C) 1996 Paul Gortmaker (drivers/char/rtc.c)
56 * Copyright (C) 2006 David Brownell (convert to new framework)
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; either version
10
- * 2 of the License, or (at your option) any later version.
117 */
128
139 /*
....@@ -226,6 +222,8 @@
226222
227223 static int cmos_read_time(struct device *dev, struct rtc_time *t)
228224 {
225
+ int ret;
226
+
229227 /*
230228 * If pm_trace abused the RTC for storage, set the timespec to 0,
231229 * which tells the caller that this RTC value is unusable.
....@@ -233,29 +231,64 @@
233231 if (!pm_trace_rtc_valid())
234232 return -EIO;
235233
236
- /* REVISIT: if the clock has a "century" register, use
237
- * that instead of the heuristic in mc146818_get_time().
238
- * That'll make Y3K compatility (year > 2070) easy!
239
- */
240
- mc146818_get_time(t);
234
+ ret = mc146818_get_time(t);
235
+ if (ret < 0) {
236
+ dev_err_ratelimited(dev, "unable to read current time\n");
237
+ return ret;
238
+ }
239
+
241240 return 0;
242241 }
243242
244243 static int cmos_set_time(struct device *dev, struct rtc_time *t)
245244 {
246
- /* REVISIT: set the "century" register if available
247
- *
248
- * NOTE: this ignores the issue whereby updating the seconds
245
+ /* NOTE: this ignores the issue whereby updating the seconds
249246 * takes effect exactly 500ms after we write the register.
250247 * (Also queueing and other delays before we get this far.)
251248 */
252249 return mc146818_set_time(t);
253250 }
254251
252
+struct cmos_read_alarm_callback_param {
253
+ struct cmos_rtc *cmos;
254
+ struct rtc_time *time;
255
+ unsigned char rtc_control;
256
+};
257
+
258
+static void cmos_read_alarm_callback(unsigned char __always_unused seconds,
259
+ void *param_in)
260
+{
261
+ struct cmos_read_alarm_callback_param *p =
262
+ (struct cmos_read_alarm_callback_param *)param_in;
263
+ struct rtc_time *time = p->time;
264
+
265
+ time->tm_sec = CMOS_READ(RTC_SECONDS_ALARM);
266
+ time->tm_min = CMOS_READ(RTC_MINUTES_ALARM);
267
+ time->tm_hour = CMOS_READ(RTC_HOURS_ALARM);
268
+
269
+ if (p->cmos->day_alrm) {
270
+ /* ignore upper bits on readback per ACPI spec */
271
+ time->tm_mday = CMOS_READ(p->cmos->day_alrm) & 0x3f;
272
+ if (!time->tm_mday)
273
+ time->tm_mday = -1;
274
+
275
+ if (p->cmos->mon_alrm) {
276
+ time->tm_mon = CMOS_READ(p->cmos->mon_alrm);
277
+ if (!time->tm_mon)
278
+ time->tm_mon = -1;
279
+ }
280
+ }
281
+
282
+ p->rtc_control = CMOS_READ(RTC_CONTROL);
283
+}
284
+
255285 static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
256286 {
257287 struct cmos_rtc *cmos = dev_get_drvdata(dev);
258
- unsigned char rtc_control;
288
+ struct cmos_read_alarm_callback_param p = {
289
+ .cmos = cmos,
290
+ .time = &t->time,
291
+ };
259292
260293 /* This not only a rtc_op, but also called directly */
261294 if (!is_valid_irq(cmos->irq))
....@@ -266,28 +299,18 @@
266299 * the future.
267300 */
268301
269
- spin_lock_irq(&rtc_lock);
270
- t->time.tm_sec = CMOS_READ(RTC_SECONDS_ALARM);
271
- t->time.tm_min = CMOS_READ(RTC_MINUTES_ALARM);
272
- t->time.tm_hour = CMOS_READ(RTC_HOURS_ALARM);
302
+ /* Some Intel chipsets disconnect the alarm registers when the clock
303
+ * update is in progress - during this time reads return bogus values
304
+ * and writes may fail silently. See for example "7th Generation IntelĀ®
305
+ * Processor Family I/O for U/Y Platforms [...] Datasheet", section
306
+ * 27.7.1
307
+ *
308
+ * Use the mc146818_avoid_UIP() function to avoid this.
309
+ */
310
+ if (!mc146818_avoid_UIP(cmos_read_alarm_callback, &p))
311
+ return -EIO;
273312
274
- if (cmos->day_alrm) {
275
- /* ignore upper bits on readback per ACPI spec */
276
- t->time.tm_mday = CMOS_READ(cmos->day_alrm) & 0x3f;
277
- if (!t->time.tm_mday)
278
- t->time.tm_mday = -1;
279
-
280
- if (cmos->mon_alrm) {
281
- t->time.tm_mon = CMOS_READ(cmos->mon_alrm);
282
- if (!t->time.tm_mon)
283
- t->time.tm_mon = -1;
284
- }
285
- }
286
-
287
- rtc_control = CMOS_READ(RTC_CONTROL);
288
- spin_unlock_irq(&rtc_lock);
289
-
290
- if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
313
+ if (!(p.rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
291314 if (((unsigned)t->time.tm_sec) < 0x60)
292315 t->time.tm_sec = bcd2bin(t->time.tm_sec);
293316 else
....@@ -316,7 +339,7 @@
316339 }
317340 }
318341
319
- t->enabled = !!(rtc_control & RTC_AIE);
342
+ t->enabled = !!(p.rtc_control & RTC_AIE);
320343 t->pending = 0;
321344
322345 return 0;
....@@ -447,10 +470,57 @@
447470 return 0;
448471 }
449472
473
+struct cmos_set_alarm_callback_param {
474
+ struct cmos_rtc *cmos;
475
+ unsigned char mon, mday, hrs, min, sec;
476
+ struct rtc_wkalrm *t;
477
+};
478
+
479
+/* Note: this function may be executed by mc146818_avoid_UIP() more then
480
+ * once
481
+ */
482
+static void cmos_set_alarm_callback(unsigned char __always_unused seconds,
483
+ void *param_in)
484
+{
485
+ struct cmos_set_alarm_callback_param *p =
486
+ (struct cmos_set_alarm_callback_param *)param_in;
487
+
488
+ /* next rtc irq must not be from previous alarm setting */
489
+ cmos_irq_disable(p->cmos, RTC_AIE);
490
+
491
+ /* update alarm */
492
+ CMOS_WRITE(p->hrs, RTC_HOURS_ALARM);
493
+ CMOS_WRITE(p->min, RTC_MINUTES_ALARM);
494
+ CMOS_WRITE(p->sec, RTC_SECONDS_ALARM);
495
+
496
+ /* the system may support an "enhanced" alarm */
497
+ if (p->cmos->day_alrm) {
498
+ CMOS_WRITE(p->mday, p->cmos->day_alrm);
499
+ if (p->cmos->mon_alrm)
500
+ CMOS_WRITE(p->mon, p->cmos->mon_alrm);
501
+ }
502
+
503
+ if (use_hpet_alarm()) {
504
+ /*
505
+ * FIXME the HPET alarm glue currently ignores day_alrm
506
+ * and mon_alrm ...
507
+ */
508
+ hpet_set_alarm_time(p->t->time.tm_hour, p->t->time.tm_min,
509
+ p->t->time.tm_sec);
510
+ }
511
+
512
+ if (p->t->enabled)
513
+ cmos_irq_enable(p->cmos, RTC_AIE);
514
+}
515
+
450516 static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
451517 {
452518 struct cmos_rtc *cmos = dev_get_drvdata(dev);
453
- unsigned char mon, mday, hrs, min, sec, rtc_control;
519
+ struct cmos_set_alarm_callback_param p = {
520
+ .cmos = cmos,
521
+ .t = t
522
+ };
523
+ unsigned char rtc_control;
454524 int ret;
455525
456526 /* This not only a rtc_op, but also called directly */
....@@ -461,11 +531,11 @@
461531 if (ret < 0)
462532 return ret;
463533
464
- mon = t->time.tm_mon + 1;
465
- mday = t->time.tm_mday;
466
- hrs = t->time.tm_hour;
467
- min = t->time.tm_min;
468
- sec = t->time.tm_sec;
534
+ p.mon = t->time.tm_mon + 1;
535
+ p.mday = t->time.tm_mday;
536
+ p.hrs = t->time.tm_hour;
537
+ p.min = t->time.tm_min;
538
+ p.sec = t->time.tm_sec;
469539
470540 spin_lock_irq(&rtc_lock);
471541 rtc_control = CMOS_READ(RTC_CONTROL);
....@@ -473,43 +543,21 @@
473543
474544 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
475545 /* Writing 0xff means "don't care" or "match all". */
476
- mon = (mon <= 12) ? bin2bcd(mon) : 0xff;
477
- mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff;
478
- hrs = (hrs < 24) ? bin2bcd(hrs) : 0xff;
479
- min = (min < 60) ? bin2bcd(min) : 0xff;
480
- sec = (sec < 60) ? bin2bcd(sec) : 0xff;
546
+ p.mon = (p.mon <= 12) ? bin2bcd(p.mon) : 0xff;
547
+ p.mday = (p.mday >= 1 && p.mday <= 31) ? bin2bcd(p.mday) : 0xff;
548
+ p.hrs = (p.hrs < 24) ? bin2bcd(p.hrs) : 0xff;
549
+ p.min = (p.min < 60) ? bin2bcd(p.min) : 0xff;
550
+ p.sec = (p.sec < 60) ? bin2bcd(p.sec) : 0xff;
481551 }
482552
483
- spin_lock_irq(&rtc_lock);
484
-
485
- /* next rtc irq must not be from previous alarm setting */
486
- cmos_irq_disable(cmos, RTC_AIE);
487
-
488
- /* update alarm */
489
- CMOS_WRITE(hrs, RTC_HOURS_ALARM);
490
- CMOS_WRITE(min, RTC_MINUTES_ALARM);
491
- CMOS_WRITE(sec, RTC_SECONDS_ALARM);
492
-
493
- /* the system may support an "enhanced" alarm */
494
- if (cmos->day_alrm) {
495
- CMOS_WRITE(mday, cmos->day_alrm);
496
- if (cmos->mon_alrm)
497
- CMOS_WRITE(mon, cmos->mon_alrm);
498
- }
499
-
500
- if (use_hpet_alarm()) {
501
- /*
502
- * FIXME the HPET alarm glue currently ignores day_alrm
503
- * and mon_alrm ...
504
- */
505
- hpet_set_alarm_time(t->time.tm_hour, t->time.tm_min,
506
- t->time.tm_sec);
507
- }
508
-
509
- if (t->enabled)
510
- cmos_irq_enable(cmos, RTC_AIE);
511
-
512
- spin_unlock_irq(&rtc_lock);
553
+ /*
554
+ * Some Intel chipsets disconnect the alarm registers when the clock
555
+ * update is in progress - during this time writes fail silently.
556
+ *
557
+ * Use mc146818_avoid_UIP() to avoid this.
558
+ */
559
+ if (!mc146818_avoid_UIP(cmos_set_alarm_callback, &p))
560
+ return -EIO;
513561
514562 cmos->alarm_expires = rtc_tm_to_time64(&t->time);
515563
....@@ -702,6 +750,168 @@
702750 return IRQ_NONE;
703751 }
704752
753
+#ifdef CONFIG_ACPI
754
+
755
+#include <linux/acpi.h>
756
+
757
+static u32 rtc_handler(void *context)
758
+{
759
+ struct device *dev = context;
760
+ struct cmos_rtc *cmos = dev_get_drvdata(dev);
761
+ unsigned char rtc_control = 0;
762
+ unsigned char rtc_intr;
763
+ unsigned long flags;
764
+
765
+
766
+ /*
767
+ * Always update rtc irq when ACPI is used as RTC Alarm.
768
+ * Or else, ACPI SCI is enabled during suspend/resume only,
769
+ * update rtc irq in that case.
770
+ */
771
+ if (cmos_use_acpi_alarm())
772
+ cmos_interrupt(0, (void *)cmos->rtc);
773
+ else {
774
+ /* Fix me: can we use cmos_interrupt() here as well? */
775
+ spin_lock_irqsave(&rtc_lock, flags);
776
+ if (cmos_rtc.suspend_ctrl)
777
+ rtc_control = CMOS_READ(RTC_CONTROL);
778
+ if (rtc_control & RTC_AIE) {
779
+ cmos_rtc.suspend_ctrl &= ~RTC_AIE;
780
+ CMOS_WRITE(rtc_control, RTC_CONTROL);
781
+ rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
782
+ rtc_update_irq(cmos->rtc, 1, rtc_intr);
783
+ }
784
+ spin_unlock_irqrestore(&rtc_lock, flags);
785
+ }
786
+
787
+ pm_wakeup_hard_event(dev);
788
+ acpi_clear_event(ACPI_EVENT_RTC);
789
+ acpi_disable_event(ACPI_EVENT_RTC, 0);
790
+ return ACPI_INTERRUPT_HANDLED;
791
+}
792
+
793
+static void acpi_rtc_event_setup(struct device *dev)
794
+{
795
+ if (acpi_disabled)
796
+ return;
797
+
798
+ acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, dev);
799
+ /*
800
+ * After the RTC handler is installed, the Fixed_RTC event should
801
+ * be disabled. Only when the RTC alarm is set will it be enabled.
802
+ */
803
+ acpi_clear_event(ACPI_EVENT_RTC);
804
+ acpi_disable_event(ACPI_EVENT_RTC, 0);
805
+}
806
+
807
+static void acpi_rtc_event_cleanup(void)
808
+{
809
+ if (acpi_disabled)
810
+ return;
811
+
812
+ acpi_remove_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler);
813
+}
814
+
815
+static void rtc_wake_on(struct device *dev)
816
+{
817
+ acpi_clear_event(ACPI_EVENT_RTC);
818
+ acpi_enable_event(ACPI_EVENT_RTC, 0);
819
+}
820
+
821
+static void rtc_wake_off(struct device *dev)
822
+{
823
+ acpi_disable_event(ACPI_EVENT_RTC, 0);
824
+}
825
+
826
+#ifdef CONFIG_X86
827
+/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
828
+static void use_acpi_alarm_quirks(void)
829
+{
830
+ if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
831
+ return;
832
+
833
+ if (!is_hpet_enabled())
834
+ return;
835
+
836
+ if (dmi_get_bios_year() < 2015)
837
+ return;
838
+
839
+ use_acpi_alarm = true;
840
+}
841
+#else
842
+static inline void use_acpi_alarm_quirks(void) { }
843
+#endif
844
+
845
+static void acpi_cmos_wake_setup(struct device *dev)
846
+{
847
+ if (acpi_disabled)
848
+ return;
849
+
850
+ use_acpi_alarm_quirks();
851
+
852
+ cmos_rtc.wake_on = rtc_wake_on;
853
+ cmos_rtc.wake_off = rtc_wake_off;
854
+
855
+ /* ACPI tables bug workaround. */
856
+ if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
857
+ dev_dbg(dev, "bogus FADT month_alarm (%d)\n",
858
+ acpi_gbl_FADT.month_alarm);
859
+ acpi_gbl_FADT.month_alarm = 0;
860
+ }
861
+
862
+ cmos_rtc.day_alrm = acpi_gbl_FADT.day_alarm;
863
+ cmos_rtc.mon_alrm = acpi_gbl_FADT.month_alarm;
864
+ cmos_rtc.century = acpi_gbl_FADT.century;
865
+
866
+ if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
867
+ dev_info(dev, "RTC can wake from S4\n");
868
+
869
+ /* RTC always wakes from S1/S2/S3, and often S4/STD */
870
+ device_init_wakeup(dev, 1);
871
+}
872
+
873
+static void cmos_check_acpi_rtc_status(struct device *dev,
874
+ unsigned char *rtc_control)
875
+{
876
+ struct cmos_rtc *cmos = dev_get_drvdata(dev);
877
+ acpi_event_status rtc_status;
878
+ acpi_status status;
879
+
880
+ if (acpi_gbl_FADT.flags & ACPI_FADT_FIXED_RTC)
881
+ return;
882
+
883
+ status = acpi_get_event_status(ACPI_EVENT_RTC, &rtc_status);
884
+ if (ACPI_FAILURE(status)) {
885
+ dev_err(dev, "Could not get RTC status\n");
886
+ } else if (rtc_status & ACPI_EVENT_FLAG_SET) {
887
+ unsigned char mask;
888
+ *rtc_control &= ~RTC_AIE;
889
+ CMOS_WRITE(*rtc_control, RTC_CONTROL);
890
+ mask = CMOS_READ(RTC_INTR_FLAGS);
891
+ rtc_update_irq(cmos->rtc, 1, mask);
892
+ }
893
+}
894
+
895
+#else /* !CONFIG_ACPI */
896
+
897
+static inline void acpi_rtc_event_setup(struct device *dev)
898
+{
899
+}
900
+
901
+static inline void acpi_rtc_event_cleanup(void)
902
+{
903
+}
904
+
905
+static inline void acpi_cmos_wake_setup(struct device *dev)
906
+{
907
+}
908
+
909
+static inline void cmos_check_acpi_rtc_status(struct device *dev,
910
+ unsigned char *rtc_control)
911
+{
912
+}
913
+#endif /* CONFIG_ACPI */
914
+
705915 #ifdef CONFIG_PNP
706916 #define INITSECTION
707917
....@@ -785,18 +995,26 @@
785995 if (info->address_space)
786996 address_space = info->address_space;
787997
788
- if (info->rtc_day_alarm && info->rtc_day_alarm < 128)
789
- cmos_rtc.day_alrm = info->rtc_day_alarm;
790
- if (info->rtc_mon_alarm && info->rtc_mon_alarm < 128)
791
- cmos_rtc.mon_alrm = info->rtc_mon_alarm;
792
- if (info->rtc_century && info->rtc_century < 128)
793
- cmos_rtc.century = info->rtc_century;
998
+ cmos_rtc.day_alrm = info->rtc_day_alarm;
999
+ cmos_rtc.mon_alrm = info->rtc_mon_alarm;
1000
+ cmos_rtc.century = info->rtc_century;
7941001
7951002 if (info->wake_on && info->wake_off) {
7961003 cmos_rtc.wake_on = info->wake_on;
7971004 cmos_rtc.wake_off = info->wake_off;
7981005 }
1006
+ } else {
1007
+ acpi_cmos_wake_setup(dev);
7991008 }
1009
+
1010
+ if (cmos_rtc.day_alrm >= 128)
1011
+ cmos_rtc.day_alrm = 0;
1012
+
1013
+ if (cmos_rtc.mon_alrm >= 128)
1014
+ cmos_rtc.mon_alrm = 0;
1015
+
1016
+ if (cmos_rtc.century >= 128)
1017
+ cmos_rtc.century = 0;
8001018
8011019 cmos_rtc.dev = dev;
8021020 dev_set_drvdata(dev, &cmos_rtc);
....@@ -808,6 +1026,12 @@
8081026 }
8091027
8101028 rename_region(ports, dev_name(&cmos_rtc.rtc->dev));
1029
+
1030
+ if (!mc146818_does_rtc_work()) {
1031
+ dev_warn(dev, "broken or not accessible\n");
1032
+ retval = -ENXIO;
1033
+ goto cleanup1;
1034
+ }
8111035
8121036 spin_lock_irq(&rtc_lock);
8131037
....@@ -879,6 +1103,13 @@
8791103 if (rtc_nvmem_register(cmos_rtc.rtc, &nvmem_cfg))
8801104 dev_err(dev, "nvmem registration failed\n");
8811105
1106
+ /*
1107
+ * Everything has gone well so far, so by default register a handler for
1108
+ * the ACPI RTC fixed event.
1109
+ */
1110
+ if (!info)
1111
+ acpi_rtc_event_setup(dev);
1112
+
8821113 dev_info(dev, "%s%s, %d bytes nvram%s\n",
8831114 !is_valid_irq(rtc_irq) ? "no alarms" :
8841115 cmos_rtc.mon_alrm ? "alarms up to one year" :
....@@ -923,6 +1154,9 @@
9231154 if (use_hpet_alarm())
9241155 hpet_unregister_irq_handler(cmos_interrupt);
9251156 }
1157
+
1158
+ if (!dev_get_platdata(dev))
1159
+ acpi_rtc_event_cleanup();
9261160
9271161 cmos->rtc = NULL;
9281162
....@@ -1012,6 +1246,7 @@
10121246 enable_irq_wake(cmos->irq);
10131247 }
10141248
1249
+ memset(&cmos->saved_wkalrm, 0, sizeof(struct rtc_wkalrm));
10151250 cmos_read_alarm(dev, &cmos->saved_wkalrm);
10161251
10171252 dev_dbg(dev, "suspend%s, ctrl %02x\n",
....@@ -1056,10 +1291,13 @@
10561291 * ACK the rtc irq here
10571292 */
10581293 if (t_now >= cmos->alarm_expires && cmos_use_acpi_alarm()) {
1294
+ local_irq_disable();
10591295 cmos_interrupt(0, (void *)cmos->rtc);
1296
+ local_irq_enable();
10601297 return;
10611298 }
10621299
1300
+ memset(&current_alarm, 0, sizeof(struct rtc_wkalrm));
10631301 cmos_read_alarm(dev, &current_alarm);
10641302 t_current_expires = rtc_tm_to_time64(&current_alarm.time);
10651303 t_saved_expires = rtc_tm_to_time64(&cmos->saved_wkalrm.time);
....@@ -1068,9 +1306,6 @@
10681306 cmos_set_alarm(dev, &cmos->saved_wkalrm);
10691307 }
10701308 }
1071
-
1072
-static void cmos_check_acpi_rtc_status(struct device *dev,
1073
- unsigned char *rtc_control);
10741309
10751310 static int __maybe_unused cmos_resume(struct device *dev)
10761311 {
....@@ -1138,189 +1373,29 @@
11381373 * predate even PNPBIOS should set up platform_bus devices.
11391374 */
11401375
1141
-#ifdef CONFIG_ACPI
1142
-
1143
-#include <linux/acpi.h>
1144
-
1145
-static u32 rtc_handler(void *context)
1146
-{
1147
- struct device *dev = context;
1148
- struct cmos_rtc *cmos = dev_get_drvdata(dev);
1149
- unsigned char rtc_control = 0;
1150
- unsigned char rtc_intr;
1151
- unsigned long flags;
1152
-
1153
-
1154
- /*
1155
- * Always update rtc irq when ACPI is used as RTC Alarm.
1156
- * Or else, ACPI SCI is enabled during suspend/resume only,
1157
- * update rtc irq in that case.
1158
- */
1159
- if (cmos_use_acpi_alarm())
1160
- cmos_interrupt(0, (void *)cmos->rtc);
1161
- else {
1162
- /* Fix me: can we use cmos_interrupt() here as well? */
1163
- spin_lock_irqsave(&rtc_lock, flags);
1164
- if (cmos_rtc.suspend_ctrl)
1165
- rtc_control = CMOS_READ(RTC_CONTROL);
1166
- if (rtc_control & RTC_AIE) {
1167
- cmos_rtc.suspend_ctrl &= ~RTC_AIE;
1168
- CMOS_WRITE(rtc_control, RTC_CONTROL);
1169
- rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
1170
- rtc_update_irq(cmos->rtc, 1, rtc_intr);
1171
- }
1172
- spin_unlock_irqrestore(&rtc_lock, flags);
1173
- }
1174
-
1175
- pm_wakeup_hard_event(dev);
1176
- acpi_clear_event(ACPI_EVENT_RTC);
1177
- acpi_disable_event(ACPI_EVENT_RTC, 0);
1178
- return ACPI_INTERRUPT_HANDLED;
1179
-}
1180
-
1181
-static inline void rtc_wake_setup(struct device *dev)
1182
-{
1183
- acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, dev);
1184
- /*
1185
- * After the RTC handler is installed, the Fixed_RTC event should
1186
- * be disabled. Only when the RTC alarm is set will it be enabled.
1187
- */
1188
- acpi_clear_event(ACPI_EVENT_RTC);
1189
- acpi_disable_event(ACPI_EVENT_RTC, 0);
1190
-}
1191
-
1192
-static void rtc_wake_on(struct device *dev)
1193
-{
1194
- acpi_clear_event(ACPI_EVENT_RTC);
1195
- acpi_enable_event(ACPI_EVENT_RTC, 0);
1196
-}
1197
-
1198
-static void rtc_wake_off(struct device *dev)
1199
-{
1200
- acpi_disable_event(ACPI_EVENT_RTC, 0);
1201
-}
1202
-
1203
-#ifdef CONFIG_X86
1204
-/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
1205
-static void use_acpi_alarm_quirks(void)
1206
-{
1207
- int year;
1208
-
1209
- if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
1210
- return;
1211
-
1212
- if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0))
1213
- return;
1214
-
1215
- if (!is_hpet_enabled())
1216
- return;
1217
-
1218
- if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2015)
1219
- use_acpi_alarm = true;
1220
-}
1221
-#else
1222
-static inline void use_acpi_alarm_quirks(void) { }
1223
-#endif
1224
-
1225
-/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
1226
- * its device node and pass extra config data. This helps its driver use
1227
- * capabilities that the now-obsolete mc146818 didn't have, and informs it
1228
- * that this board's RTC is wakeup-capable (per ACPI spec).
1229
- */
1230
-static struct cmos_rtc_board_info acpi_rtc_info;
1231
-
1232
-static void cmos_wake_setup(struct device *dev)
1233
-{
1234
- if (acpi_disabled)
1235
- return;
1236
-
1237
- use_acpi_alarm_quirks();
1238
-
1239
- rtc_wake_setup(dev);
1240
- acpi_rtc_info.wake_on = rtc_wake_on;
1241
- acpi_rtc_info.wake_off = rtc_wake_off;
1242
-
1243
- /* workaround bug in some ACPI tables */
1244
- if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
1245
- dev_dbg(dev, "bogus FADT month_alarm (%d)\n",
1246
- acpi_gbl_FADT.month_alarm);
1247
- acpi_gbl_FADT.month_alarm = 0;
1248
- }
1249
-
1250
- acpi_rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
1251
- acpi_rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
1252
- acpi_rtc_info.rtc_century = acpi_gbl_FADT.century;
1253
-
1254
- /* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */
1255
- if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
1256
- dev_info(dev, "RTC can wake from S4\n");
1257
-
1258
- dev->platform_data = &acpi_rtc_info;
1259
-
1260
- /* RTC always wakes from S1/S2/S3, and often S4/STD */
1261
- device_init_wakeup(dev, 1);
1262
-}
1263
-
1264
-static void cmos_check_acpi_rtc_status(struct device *dev,
1265
- unsigned char *rtc_control)
1266
-{
1267
- struct cmos_rtc *cmos = dev_get_drvdata(dev);
1268
- acpi_event_status rtc_status;
1269
- acpi_status status;
1270
-
1271
- if (acpi_gbl_FADT.flags & ACPI_FADT_FIXED_RTC)
1272
- return;
1273
-
1274
- status = acpi_get_event_status(ACPI_EVENT_RTC, &rtc_status);
1275
- if (ACPI_FAILURE(status)) {
1276
- dev_err(dev, "Could not get RTC status\n");
1277
- } else if (rtc_status & ACPI_EVENT_FLAG_SET) {
1278
- unsigned char mask;
1279
- *rtc_control &= ~RTC_AIE;
1280
- CMOS_WRITE(*rtc_control, RTC_CONTROL);
1281
- mask = CMOS_READ(RTC_INTR_FLAGS);
1282
- rtc_update_irq(cmos->rtc, 1, mask);
1283
- }
1284
-}
1285
-
1286
-#else
1287
-
1288
-static void cmos_wake_setup(struct device *dev)
1289
-{
1290
-}
1291
-
1292
-static void cmos_check_acpi_rtc_status(struct device *dev,
1293
- unsigned char *rtc_control)
1294
-{
1295
-}
1296
-
1297
-#endif
1298
-
12991376 #ifdef CONFIG_PNP
13001377
13011378 #include <linux/pnp.h>
13021379
13031380 static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
13041381 {
1305
- cmos_wake_setup(&pnp->dev);
1382
+ int irq;
13061383
13071384 if (pnp_port_start(pnp, 0) == 0x70 && !pnp_irq_valid(pnp, 0)) {
1308
- unsigned int irq = 0;
1385
+ irq = 0;
13091386 #ifdef CONFIG_X86
13101387 /* Some machines contain a PNP entry for the RTC, but
13111388 * don't define the IRQ. It should always be safe to
13121389 * hardcode it on systems with a legacy PIC.
13131390 */
13141391 if (nr_legacy_irqs())
1315
- irq = 8;
1392
+ irq = RTC_IRQ;
13161393 #endif
1317
- return cmos_do_probe(&pnp->dev,
1318
- pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
13191394 } else {
1320
- return cmos_do_probe(&pnp->dev,
1321
- pnp_get_resource(pnp, IORESOURCE_IO, 0),
1322
- pnp_irq(pnp, 0));
1395
+ irq = pnp_irq(pnp, 0);
13231396 }
1397
+
1398
+ return cmos_do_probe(&pnp->dev, pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
13241399 }
13251400
13261401 static void cmos_pnp_remove(struct pnp_dev *pnp)
....@@ -1352,7 +1427,7 @@
13521427 MODULE_DEVICE_TABLE(pnp, rtc_ids);
13531428
13541429 static struct pnp_driver cmos_pnp_driver = {
1355
- .name = (char *) driver_name,
1430
+ .name = driver_name,
13561431 .id_table = rtc_ids,
13571432 .probe = cmos_pnp_probe,
13581433 .remove = cmos_pnp_remove,
....@@ -1407,7 +1482,6 @@
14071482 int irq;
14081483
14091484 cmos_of_init(pdev);
1410
- cmos_wake_setup(&pdev->dev);
14111485
14121486 if (RTC_IOMAPPED)
14131487 resource = platform_get_resource(pdev, IORESOURCE_IO, 0);