From 714306e33c83e4ac6fa661cbd519d474797d0708 Mon Sep 17 00:00:00 2001 From: macallan Date: Tue, 14 Sep 2010 04:40:35 +0000 Subject: [PATCH] report lid open/close events to sysmon --- sys/arch/macppc/dev/pmu.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sys/arch/macppc/dev/pmu.c b/sys/arch/macppc/dev/pmu.c index 6267c50248f6..2ad696278eed 100644 --- a/sys/arch/macppc/dev/pmu.c +++ b/sys/arch/macppc/dev/pmu.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmu.c,v 1.17 2009/12/12 14:44:09 tsutsui Exp $ */ +/* $NetBSD: pmu.c,v 1.18 2010/09/14 04:40:35 macallan Exp $ */ /*- * Copyright (c) 2006 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.17 2009/12/12 14:44:09 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.18 2010/09/14 04:40:35 macallan Exp $"); #include #include @@ -42,6 +42,8 @@ __KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.17 2009/12/12 14:44:09 tsutsui Exp $"); #include #include +#include + #include #include #include @@ -75,6 +77,7 @@ struct pmu_softc { struct adb_bus_accessops sc_adbops; struct i2c_controller sc_i2c; struct pmu_ops sc_pmu_ops; + struct sysmon_pswitch sc_lidswitch; bus_space_tag_t sc_memt; bus_space_handle_t sc_memh; uint32_t sc_flags; @@ -86,6 +89,7 @@ struct pmu_softc { int sc_pending_eject; int sc_brightness, sc_brightness_wanted; int sc_volume, sc_volume_wanted; + int sc_lid_closed; /* deferred processing */ lwp_t *sc_thread; /* signalling the event thread */ @@ -279,6 +283,7 @@ pmu_attach(struct device *parent, struct device *dev, void *aux) sc->sc_volume = sc->sc_volume_wanted = 0x80; sc->sc_flags = 0; sc->sc_callback = NULL; + sc->sc_lid_closed = 0; if (bus_space_map(sc->sc_memt, ca->ca_reg[0] + ca->ca_baseaddr, ca->ca_reg[1], 0, &sc->sc_memh) != 0) { @@ -401,6 +406,12 @@ bat_done: "%s", "pmu") != 0) { printf("pmu: unable to create event kthread"); } + + sc->sc_lidswitch.smpsw_name = "Lid switch"; + sc->sc_lidswitch.smpsw_type = PSWITCH_TYPE_LID; + if (sysmon_pswitch_register(&sc->sc_lidswitch) != 0) + printf("%s: unable to register lid switch with sysmon\n", + device_xname(dev)); } static void @@ -640,6 +651,7 @@ pmu_intr(void *arg) goto done; } if (resp[1] & PMU_INT_ENVIRONMENT) { + int closed; #ifdef PMU_VERBOSE /* deal with environment messages */ printf("environment:"); @@ -647,6 +659,13 @@ pmu_intr(void *arg) printf(" %02x", resp[i]); printf("\n"); #endif + closed = (resp[2] & PMU_ENV_LID_CLOSED) != 0; + if (closed != sc->sc_lid_closed) { + sc->sc_lid_closed = closed; + sysmon_pswitch_event(&sc->sc_lidswitch, + closed ? PSWITCH_EVENT_PRESSED : + PSWITCH_EVENT_RELEASED); + } goto done; } if (resp[1] & PMU_INT_TICK) {