@@ -744,8 +744,155 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
744
744
return IRQ_NONE ;
745
745
}
746
746
747
- static inline void rtc_wake_setup (struct device * dev );
748
- static void cmos_wake_setup (struct device * dev );
747
+ #ifdef CONFIG_ACPI
748
+
749
+ #include <linux/acpi.h>
750
+
751
+ static u32 rtc_handler (void * context )
752
+ {
753
+ struct device * dev = context ;
754
+ struct cmos_rtc * cmos = dev_get_drvdata (dev );
755
+ unsigned char rtc_control = 0 ;
756
+ unsigned char rtc_intr ;
757
+ unsigned long flags ;
758
+
759
+
760
+ /*
761
+ * Always update rtc irq when ACPI is used as RTC Alarm.
762
+ * Or else, ACPI SCI is enabled during suspend/resume only,
763
+ * update rtc irq in that case.
764
+ */
765
+ if (cmos_use_acpi_alarm ())
766
+ cmos_interrupt (0 , (void * )cmos -> rtc );
767
+ else {
768
+ /* Fix me: can we use cmos_interrupt() here as well? */
769
+ spin_lock_irqsave (& rtc_lock , flags );
770
+ if (cmos_rtc .suspend_ctrl )
771
+ rtc_control = CMOS_READ (RTC_CONTROL );
772
+ if (rtc_control & RTC_AIE ) {
773
+ cmos_rtc .suspend_ctrl &= ~RTC_AIE ;
774
+ CMOS_WRITE (rtc_control , RTC_CONTROL );
775
+ rtc_intr = CMOS_READ (RTC_INTR_FLAGS );
776
+ rtc_update_irq (cmos -> rtc , 1 , rtc_intr );
777
+ }
778
+ spin_unlock_irqrestore (& rtc_lock , flags );
779
+ }
780
+
781
+ pm_wakeup_hard_event (dev );
782
+ acpi_clear_event (ACPI_EVENT_RTC );
783
+ acpi_disable_event (ACPI_EVENT_RTC , 0 );
784
+ return ACPI_INTERRUPT_HANDLED ;
785
+ }
786
+
787
+ static void rtc_wake_setup (struct device * dev )
788
+ {
789
+ if (acpi_disabled )
790
+ return ;
791
+
792
+ acpi_install_fixed_event_handler (ACPI_EVENT_RTC , rtc_handler , dev );
793
+ /*
794
+ * After the RTC handler is installed, the Fixed_RTC event should
795
+ * be disabled. Only when the RTC alarm is set will it be enabled.
796
+ */
797
+ acpi_clear_event (ACPI_EVENT_RTC );
798
+ acpi_disable_event (ACPI_EVENT_RTC , 0 );
799
+ }
800
+
801
+ static void rtc_wake_on (struct device * dev )
802
+ {
803
+ acpi_clear_event (ACPI_EVENT_RTC );
804
+ acpi_enable_event (ACPI_EVENT_RTC , 0 );
805
+ }
806
+
807
+ static void rtc_wake_off (struct device * dev )
808
+ {
809
+ acpi_disable_event (ACPI_EVENT_RTC , 0 );
810
+ }
811
+
812
+ #ifdef CONFIG_X86
813
+ /* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
814
+ static void use_acpi_alarm_quirks (void )
815
+ {
816
+ if (boot_cpu_data .x86_vendor != X86_VENDOR_INTEL )
817
+ return ;
818
+
819
+ if (!is_hpet_enabled ())
820
+ return ;
821
+
822
+ if (dmi_get_bios_year () < 2015 )
823
+ return ;
824
+
825
+ use_acpi_alarm = true;
826
+ }
827
+ #else
828
+ static inline void use_acpi_alarm_quirks (void ) { }
829
+ #endif
830
+
831
+ static void cmos_wake_setup (struct device * dev )
832
+ {
833
+ if (acpi_disabled )
834
+ return ;
835
+
836
+ use_acpi_alarm_quirks ();
837
+
838
+ cmos_rtc .wake_on = rtc_wake_on ;
839
+ cmos_rtc .wake_off = rtc_wake_off ;
840
+
841
+ /* ACPI tables bug workaround. */
842
+ if (acpi_gbl_FADT .month_alarm && !acpi_gbl_FADT .day_alarm ) {
843
+ dev_dbg (dev , "bogus FADT month_alarm (%d)\n" ,
844
+ acpi_gbl_FADT .month_alarm );
845
+ acpi_gbl_FADT .month_alarm = 0 ;
846
+ }
847
+
848
+ cmos_rtc .day_alrm = acpi_gbl_FADT .day_alarm ;
849
+ cmos_rtc .mon_alrm = acpi_gbl_FADT .month_alarm ;
850
+ cmos_rtc .century = acpi_gbl_FADT .century ;
851
+
852
+ if (acpi_gbl_FADT .flags & ACPI_FADT_S4_RTC_WAKE )
853
+ dev_info (dev , "RTC can wake from S4\n" );
854
+
855
+ /* RTC always wakes from S1/S2/S3, and often S4/STD */
856
+ device_init_wakeup (dev , 1 );
857
+ }
858
+
859
+ static void cmos_check_acpi_rtc_status (struct device * dev ,
860
+ unsigned char * rtc_control )
861
+ {
862
+ struct cmos_rtc * cmos = dev_get_drvdata (dev );
863
+ acpi_event_status rtc_status ;
864
+ acpi_status status ;
865
+
866
+ if (acpi_gbl_FADT .flags & ACPI_FADT_FIXED_RTC )
867
+ return ;
868
+
869
+ status = acpi_get_event_status (ACPI_EVENT_RTC , & rtc_status );
870
+ if (ACPI_FAILURE (status )) {
871
+ dev_err (dev , "Could not get RTC status\n" );
872
+ } else if (rtc_status & ACPI_EVENT_FLAG_SET ) {
873
+ unsigned char mask ;
874
+ * rtc_control &= ~RTC_AIE ;
875
+ CMOS_WRITE (* rtc_control , RTC_CONTROL );
876
+ mask = CMOS_READ (RTC_INTR_FLAGS );
877
+ rtc_update_irq (cmos -> rtc , 1 , mask );
878
+ }
879
+ }
880
+
881
+ #else /* !CONFIG_ACPI */
882
+
883
+ static inline void rtc_wake_setup (struct device * dev )
884
+ {
885
+ }
886
+
887
+ static inline void cmos_wake_setup (struct device * dev )
888
+ {
889
+ }
890
+
891
+ static inline void cmos_check_acpi_rtc_status (struct device * dev ,
892
+ unsigned char * rtc_control )
893
+ {
894
+ }
895
+ #endif /* CONFIG_ACPI */
749
896
750
897
#ifdef CONFIG_PNP
751
898
#define INITSECTION
@@ -1140,9 +1287,6 @@ static void cmos_check_wkalrm(struct device *dev)
1140
1287
}
1141
1288
}
1142
1289
1143
- static void cmos_check_acpi_rtc_status (struct device * dev ,
1144
- unsigned char * rtc_control );
1145
-
1146
1290
static int __maybe_unused cmos_resume (struct device * dev )
1147
1291
{
1148
1292
struct cmos_rtc * cmos = dev_get_drvdata (dev );
@@ -1209,156 +1353,6 @@ static SIMPLE_DEV_PM_OPS(cmos_pm_ops, cmos_suspend, cmos_resume);
1209
1353
* predate even PNPBIOS should set up platform_bus devices.
1210
1354
*/
1211
1355
1212
- #ifdef CONFIG_ACPI
1213
-
1214
- #include <linux/acpi.h>
1215
-
1216
- static u32 rtc_handler (void * context )
1217
- {
1218
- struct device * dev = context ;
1219
- struct cmos_rtc * cmos = dev_get_drvdata (dev );
1220
- unsigned char rtc_control = 0 ;
1221
- unsigned char rtc_intr ;
1222
- unsigned long flags ;
1223
-
1224
-
1225
- /*
1226
- * Always update rtc irq when ACPI is used as RTC Alarm.
1227
- * Or else, ACPI SCI is enabled during suspend/resume only,
1228
- * update rtc irq in that case.
1229
- */
1230
- if (cmos_use_acpi_alarm ())
1231
- cmos_interrupt (0 , (void * )cmos -> rtc );
1232
- else {
1233
- /* Fix me: can we use cmos_interrupt() here as well? */
1234
- spin_lock_irqsave (& rtc_lock , flags );
1235
- if (cmos_rtc .suspend_ctrl )
1236
- rtc_control = CMOS_READ (RTC_CONTROL );
1237
- if (rtc_control & RTC_AIE ) {
1238
- cmos_rtc .suspend_ctrl &= ~RTC_AIE ;
1239
- CMOS_WRITE (rtc_control , RTC_CONTROL );
1240
- rtc_intr = CMOS_READ (RTC_INTR_FLAGS );
1241
- rtc_update_irq (cmos -> rtc , 1 , rtc_intr );
1242
- }
1243
- spin_unlock_irqrestore (& rtc_lock , flags );
1244
- }
1245
-
1246
- pm_wakeup_hard_event (dev );
1247
- acpi_clear_event (ACPI_EVENT_RTC );
1248
- acpi_disable_event (ACPI_EVENT_RTC , 0 );
1249
- return ACPI_INTERRUPT_HANDLED ;
1250
- }
1251
-
1252
- static inline void rtc_wake_setup (struct device * dev )
1253
- {
1254
- if (acpi_disabled )
1255
- return ;
1256
-
1257
- acpi_install_fixed_event_handler (ACPI_EVENT_RTC , rtc_handler , dev );
1258
- /*
1259
- * After the RTC handler is installed, the Fixed_RTC event should
1260
- * be disabled. Only when the RTC alarm is set will it be enabled.
1261
- */
1262
- acpi_clear_event (ACPI_EVENT_RTC );
1263
- acpi_disable_event (ACPI_EVENT_RTC , 0 );
1264
- }
1265
-
1266
- static void rtc_wake_on (struct device * dev )
1267
- {
1268
- acpi_clear_event (ACPI_EVENT_RTC );
1269
- acpi_enable_event (ACPI_EVENT_RTC , 0 );
1270
- }
1271
-
1272
- static void rtc_wake_off (struct device * dev )
1273
- {
1274
- acpi_disable_event (ACPI_EVENT_RTC , 0 );
1275
- }
1276
-
1277
- #ifdef CONFIG_X86
1278
- /* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
1279
- static void use_acpi_alarm_quirks (void )
1280
- {
1281
- if (boot_cpu_data .x86_vendor != X86_VENDOR_INTEL )
1282
- return ;
1283
-
1284
- if (!is_hpet_enabled ())
1285
- return ;
1286
-
1287
- if (dmi_get_bios_year () < 2015 )
1288
- return ;
1289
-
1290
- use_acpi_alarm = true;
1291
- }
1292
- #else
1293
- static inline void use_acpi_alarm_quirks (void ) { }
1294
- #endif
1295
-
1296
- static void cmos_wake_setup (struct device * dev )
1297
- {
1298
- if (acpi_disabled )
1299
- return ;
1300
-
1301
- use_acpi_alarm_quirks ();
1302
-
1303
- cmos_rtc .wake_on = rtc_wake_on ;
1304
- cmos_rtc .wake_off = rtc_wake_off ;
1305
-
1306
- /* ACPI tables bug workaround. */
1307
- if (acpi_gbl_FADT .month_alarm && !acpi_gbl_FADT .day_alarm ) {
1308
- dev_dbg (dev , "bogus FADT month_alarm (%d)\n" ,
1309
- acpi_gbl_FADT .month_alarm );
1310
- acpi_gbl_FADT .month_alarm = 0 ;
1311
- }
1312
-
1313
- cmos_rtc .day_alrm = acpi_gbl_FADT .day_alarm ;
1314
- cmos_rtc .mon_alrm = acpi_gbl_FADT .month_alarm ;
1315
- cmos_rtc .century = acpi_gbl_FADT .century ;
1316
-
1317
- if (acpi_gbl_FADT .flags & ACPI_FADT_S4_RTC_WAKE )
1318
- dev_info (dev , "RTC can wake from S4\n" );
1319
-
1320
- /* RTC always wakes from S1/S2/S3, and often S4/STD */
1321
- device_init_wakeup (dev , 1 );
1322
- }
1323
-
1324
- static void cmos_check_acpi_rtc_status (struct device * dev ,
1325
- unsigned char * rtc_control )
1326
- {
1327
- struct cmos_rtc * cmos = dev_get_drvdata (dev );
1328
- acpi_event_status rtc_status ;
1329
- acpi_status status ;
1330
-
1331
- if (acpi_gbl_FADT .flags & ACPI_FADT_FIXED_RTC )
1332
- return ;
1333
-
1334
- status = acpi_get_event_status (ACPI_EVENT_RTC , & rtc_status );
1335
- if (ACPI_FAILURE (status )) {
1336
- dev_err (dev , "Could not get RTC status\n" );
1337
- } else if (rtc_status & ACPI_EVENT_FLAG_SET ) {
1338
- unsigned char mask ;
1339
- * rtc_control &= ~RTC_AIE ;
1340
- CMOS_WRITE (* rtc_control , RTC_CONTROL );
1341
- mask = CMOS_READ (RTC_INTR_FLAGS );
1342
- rtc_update_irq (cmos -> rtc , 1 , mask );
1343
- }
1344
- }
1345
-
1346
- #else
1347
-
1348
- static void cmos_wake_setup (struct device * dev )
1349
- {
1350
- }
1351
-
1352
- static void cmos_check_acpi_rtc_status (struct device * dev ,
1353
- unsigned char * rtc_control )
1354
- {
1355
- }
1356
-
1357
- static void rtc_wake_setup (struct device * dev )
1358
- {
1359
- }
1360
- #endif
1361
-
1362
1356
#ifdef CONFIG_PNP
1363
1357
1364
1358
#include <linux/pnp.h>
0 commit comments