On Thu, Nov 24, 2022 at 08:36:48PM +0100, Mark Kettenis wrote: > > Date: Thu, 24 Nov 2022 19:04:03 +0100 > > From: Tobias Heider <tobias.hei...@stusta.de> > > > > The diff below disables the screen backlight on apple silicon macs when the > > lid is closed. > > Can we distinguish lid close events from lid open events? Might make > more sense to base the decision to turn the display off based on that > instead of toggling a variable. > > > Normally, we suspend or hibernate depending on the value of > > machdep.lid_action. Since suspend doesn't work reliably yet I think > > this is a good intermediate solution to save some power while the > > laptop is idling. > > Even though acpibtn(4) documents 0 as "Do nothing", doesn't it make > sense to always turn off the display backlight when the lid gets > closed? > > Then we could actually implement 1 as suspend but just set lid_action > to 0?
Ok, so let's leave lid_action out of this for now and unconditionally blank/unblank on lid events. How do you like this? Index: arch/arm64/dev/aplsmc.c =================================================================== RCS file: /cvs/src/sys/arch/arm64/dev/aplsmc.c,v retrieving revision 1.18 diff -u -p -r1.18 aplsmc.c --- arch/arm64/dev/aplsmc.c 14 Nov 2022 11:11:17 -0000 1.18 +++ arch/arm64/dev/aplsmc.c 24 Nov 2022 22:24:13 -0000 @@ -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 } 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