Disable screen backlight on Apple silicon laptops when lid is closed.
authortobhe <tobhe@openbsd.org>
Fri, 25 Nov 2022 20:33:11 +0000 (20:33 +0000)
committertobhe <tobhe@openbsd.org>
Fri, 25 Nov 2022 20:33:11 +0000 (20:33 +0000)
ok kettenis@

sys/arch/arm64/dev/aplsmc.c

index e3a82a7..449a4f7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: aplsmc.c,v 1.18 2022/11/14 11:11:17 kettenis Exp $    */
+/*     $OpenBSD: aplsmc.c,v 1.19 2022/11/25 20:33:11 tobhe Exp $       */
 /*
  * Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
  *
@@ -37,6 +37,8 @@
 
 #include "apm.h"
 
+extern void (*simplefb_burn_hook)(u_int);
+
 extern void (*cpuresetfn)(void);
 extern void (*powerdownfn)(void);
 
@@ -96,6 +98,10 @@ struct aplsmc_sensor {
 #define SMC_PWRBTN_TOUCHID     0x06
 #define SMC_PWRBTN_LONG                0xfe
 
+/* Lid events */
+#define SMC_LID_OPEN           0x00
+#define SMC_LID_CLOSE          0x01
+
 #define APLSMC_BE              (1 << 0)
 #define APLSMC_HIDDEN          (1 << 1)
 
@@ -372,7 +378,20 @@ aplsmc_handle_notification(struct aplsmc_softc *sc, uint64_t data)
                }
                break;
        case SMC_EV_TYPE_LID:
-               /* XXX Handle lid events. */
+               switch (SMC_EV_SUBTYPE(data)) {
+               case SMC_LID_OPEN:
+                       if (simplefb_burn_hook)
+                               simplefb_burn_hook(1);
+                       break;
+               case SMC_LID_CLOSE:
+                       if (simplefb_burn_hook)
+                               simplefb_burn_hook(0);
+                       break;
+               default:
+                       printf("%s: SMV_EV_TYPE_LID 0x%016llx\n",
+                              sc->sc_dev.dv_xname, data);
+                       break;
+               }
                break;
        default:
 #ifdef APLSMC_DEBUG