From 6431ede397dfca4866563a6c8ce0d8add56576e3 Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Mon, 5 Dec 2011 00:12:10 +0000 Subject: [PATCH] Add a devd notification for closing/opening the lid on PowerBooks and iBooks. Approved by: nwhitehorn (mentor) --- etc/devd/apple.conf | 10 ++++++++++ sys/powerpc/powermac/pmu.c | 14 ++++++++++++++ sys/powerpc/powermac/pmuvar.h | 1 + 3 files changed, 25 insertions(+) diff --git a/etc/devd/apple.conf b/etc/devd/apple.conf index a57a8e06a64..275d7378f88 100644 --- a/etc/devd/apple.conf +++ b/etc/devd/apple.conf @@ -11,6 +11,16 @@ notify 0 { }; +# Keyboard power key +notify 0 { + match "system" "PMU"; + match "subsystem" "lid"; + match "type" "close"; + match "notify" "0x0"; + action "shutdown -p now"; +}; + + # The next blocks enable volume hotkeys that can be found on Apple laptops notify 0 { match "system" "PMU"; diff --git a/sys/powerpc/powermac/pmu.c b/sys/powerpc/powermac/pmu.c index c478179da52..ebadbefec9a 100644 --- a/sys/powerpc/powermac/pmu.c +++ b/sys/powerpc/powermac/pmu.c @@ -701,6 +701,20 @@ pmu_intr(void *arg) adb_receive_raw_packet(sc->adb_bus,resp[1],resp[2], len - 3,&resp[3]); } + if (resp[1] & PMU_INT_ENVIRONMENT) { + // if the lid was just closed, notify devd. + if ((resp[2] & PMU_ENV_LID_CLOSED) && (!sc->lid_closed)) { + sc->lid_closed = 1; + if (devctl_process_running()) + devctl_notify("PMU", "lid", "close", NULL); + } + else if (!(resp[2] & PMU_ENV_LID_CLOSED) && (sc->lid_closed)) { + // if the lid was just opened, notify devd. + if (devctl_process_running()) + devctl_notify("PMU", "lid", "open", NULL); + sc->lid_closed = 0; + } + } } static u_int diff --git a/sys/powerpc/powermac/pmuvar.h b/sys/powerpc/powermac/pmuvar.h index d9cc1a0614c..25a85c7d77e 100644 --- a/sys/powerpc/powermac/pmuvar.h +++ b/sys/powerpc/powermac/pmuvar.h @@ -160,6 +160,7 @@ struct pmu_softc { volatile int sc_autopoll; int sc_batteries; struct cdev *sc_leddev; + int lid_closed; }; struct pmu_battstate {