Formerly "Prevent Hot Backpack" diff. This puts the machine back to
sleep (or hibernate, if that's where you came from) if the lid is
still closed on resume. Stops the machine from staying awake if the
lid flexes or slightly opens while in your bag, triggering an 
unwanted wake event. Note - the machine will wake, then go back to
sleep using this diff. So it will take a few seconds (or longer
when using ZZZ).

There are some unhandled cases:
1. softraid crypto hibernate - this diff won't work in that scenario
as the machine will be sitting at the passphrase prompt.

2. machines with lids closed in docks, that are awakened by pressing
the power button instead of opening the lid.

Testers welcome.

-ml

Index: dev/acpi/acpi.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.272
diff -u -p -a -u -r1.272 acpi.c
--- dev/acpi/acpi.c     26 Sep 2014 09:25:38 -0000      1.272
+++ dev/acpi/acpi.c     12 Oct 2014 18:46:42 -0000
@@ -2252,6 +2252,12 @@ fail_alloc:
        acpi_record_event(sc, APM_NORMAL_RESUME);
        acpi_indicator(sc, ACPI_SST_WORKING);
 
+       /*
+        * If we woke up but the lid is closed, go back to sleep
+        */
+       if (!acpibtn_checklidopen())
+               acpi_addtask(sc, acpi_sleep_task, sc, state);
+
 fail_tts:
        return (error);
 }
Index: dev/acpi/acpibtn.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpibtn.c,v
retrieving revision 1.37
diff -u -p -a -u -r1.37 acpibtn.c
--- dev/acpi/acpibtn.c  16 Oct 2014 17:46:06 -0000      1.37
+++ dev/acpi/acpibtn.c  6 Nov 2014 03:01:01 -0000
@@ -76,6 +76,25 @@ struct cfdriver acpibtn_cd = {
 const char *acpibtn_hids[] = { ACPI_DEV_LD, ACPI_DEV_PBD, ACPI_DEV_SBD, 0 };
 
 int
+acpibtn_checklidopen(void)
+{
+       int64_t val, status;
+       struct acpi_lid *lid;
+
+       status = 0;
+
+       /* Check if any of the lid(s) are open */
+       SLIST_FOREACH(lid, &acpibtn_lids, abl_link)
+               if (!aml_evalinteger(lid->abl_softc->sc_acpi,
+                   lid->abl_softc->sc_devnode, "_LID", 0, NULL, &val))
+                       status |= val;
+               else
+                       return (0);
+
+       return (status);
+}
+
+int
 acpibtn_setpsw(struct acpibtn_softc *sc, int psw)
 {
        struct aml_value        val;
Index: dev/acpi/acpidev.h
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpidev.h,v
retrieving revision 1.34
diff -u -p -a -u -r1.34 acpidev.h
--- dev/acpi/acpidev.h  23 May 2014 19:17:39 -0000      1.34
+++ dev/acpi/acpidev.h  12 Oct 2014 18:47:22 -0000
@@ -337,4 +337,5 @@ struct acpiec_softc {
 
 void           acpibtn_disable_psw(void);
 void           acpibtn_enable_psw(void);
+int            acpibtn_checklidopen(void);
 #endif /* __DEV_ACPI_ACPIDEV_H__ */


Reply via email to