Wakeup machine when lid is opened on laptops that have acpibtn _LID.
authormarco <marco@openbsd.org>
Thu, 5 Aug 2010 19:23:06 +0000 (19:23 +0000)
committermarco <marco@openbsd.org>
Thu, 5 Aug 2010 19:23:06 +0000 (19:23 +0000)
initial diff from me, this version pruned by deraadt

ok deraadt

sys/dev/acpi/acpibtn.c

index 9c9e66b..028f5fc 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpibtn.c,v 1.28 2010/08/05 17:26:57 deraadt Exp $ */
+/* $OpenBSD: acpibtn.c,v 1.29 2010/08/05 19:23:06 marco Exp $ */
 /*
  * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
  *
@@ -84,9 +84,17 @@ acpibtn_attach(struct device *parent, struct device *self, void *aux)
        sc->sc_acpi = (struct acpi_softc *)parent;
        sc->sc_devnode = aa->aaa_node;
 
-       if (!strcmp(aa->aaa_dev, ACPI_DEV_LD))
+       if (!strcmp(aa->aaa_dev, ACPI_DEV_LD)) {
+               struct aml_value        val;
+
                sc->sc_btn_type = ACPIBTN_LID;
-       else if (!strcmp(aa->aaa_dev, ACPI_DEV_PBD))
+               bzero(&val, sizeof val);
+               val.type = AML_OBJTYPE_INTEGER;
+               val.v_integer = 1;
+               val.length = 1;
+               (void) aml_evalname(sc->sc_acpi, sc->sc_devnode, "_PSW",
+                   1, &val, NULL);
+       } else if (!strcmp(aa->aaa_dev, ACPI_DEV_PBD))
                sc->sc_btn_type = ACPIBTN_POWER;
        else if (!strcmp(aa->aaa_dev, ACPI_DEV_SBD))
                sc->sc_btn_type = ACPIBTN_SLEEP;
@@ -135,15 +143,13 @@ acpibtn_notify(struct aml_node *node, int notify_type, void *arg)
                 * _LID method.  0 means the lid is closed and we
                 * should go to sleep.
                 */
+               if (acpi_lid_suspend)
+                       break;
                if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode,
                    "_LID", 0, NULL, &lid))
                        return (0);
-               if (acpi_lid_suspend && lid == 0) {
-                       if (acpi_record_event(sc->sc_acpi, APM_USER_SUSPEND_REQ)) {
-                               sc->sc_acpi->sc_sleepmode = ACPI_STATE_S3;
-                               acpi_wakeup(sc->sc_acpi);
-                       }
-               }
+               if (lid == 0)
+                       goto sleep;
 #endif /* SMALL_KERNEL */
                break;
        case ACPIBTN_SLEEP:
@@ -153,6 +159,7 @@ acpibtn_notify(struct aml_node *node, int notify_type, void *arg)
                        /* "something" has been taken care of by the system */
                        break;
                case 0x80:
+sleep:
                        /* Request to go to sleep */
                        if (acpi_record_event(sc->sc_acpi, APM_USER_SUSPEND_REQ)) {
                                sc->sc_acpi->sc_sleepmode = ACPI_STATE_S3;