From 0f0a18ff385a40e92c6697f4e97d1ba683582a8c Mon Sep 17 00:00:00 2001 From: nwhitehorn Date: Tue, 9 Dec 2008 01:01:02 +0000 Subject: Add the ability to control the sleep LED with led(4). Adding this fairly useless feature gives us a reasonably complete PMU implementation. --- sys/powerpc/powermac/pmu.c | 29 +++++++++++++++++++++++++++-- sys/powerpc/powermac/pmuvar.h | 5 ++--- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'sys/powerpc') diff --git a/sys/powerpc/powermac/pmu.c b/sys/powerpc/powermac/pmu.c index 93e326e..593c2c4 100644 --- a/sys/powerpc/powermac/pmu.c +++ b/sys/powerpc/powermac/pmu.c @@ -11,8 +11,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -41,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -71,6 +70,7 @@ static u_int pmu_adb_send(device_t dev, u_char command_byte, int len, static u_int pmu_adb_autopoll(device_t dev, uint16_t mask); static void pmu_poll(device_t dev); +static void pmu_set_sleepled(void *xsc, int onoff); static int pmu_server_mode(SYSCTL_HANDLER_ARGS); static int pmu_query_battery(struct pmu_softc *sc, int batt, struct pmu_battstate *info); @@ -333,6 +333,9 @@ pmu_attach(device_t dev) } sc->sc_autopoll = 0; + sc->sc_batteries = 0; + sc->adb_bus = NULL; + sc->sc_leddev = NULL; /* Init PMU */ @@ -439,6 +442,12 @@ pmu_attach(device_t dev) } } + /* + * Set up LED interface + */ + + sc->sc_leddev = led_create(pmu_set_sleepled, sc, "sleepled"); + return (bus_generic_attach(dev)); } @@ -449,6 +458,9 @@ pmu_detach(device_t dev) sc = device_get_softc(dev); + if (sc->sc_leddev != NULL) + led_destroy(sc->sc_leddev); + bus_teardown_intr(dev, sc->sc_irq, sc->sc_ih); bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid, sc->sc_irq); bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_memrid, sc->sc_memr); @@ -711,6 +723,19 @@ pmu_adb_autopoll(device_t dev, uint16_t mask) return 0; } +static void +pmu_set_sleepled(void *xsc, int onoff) +{ + struct pmu_softc *sc = xsc; + uint8_t cmd[] = {4, 0, 0}; + + cmd[2] = onoff; + + mtx_lock(&sc->sc_mutex); + pmu_send(sc, PMU_SET_SLEEPLED, 3, cmd, 0, NULL); + mtx_unlock(&sc->sc_mutex); +} + static int pmu_server_mode(SYSCTL_HANDLER_ARGS) { diff --git a/sys/powerpc/powermac/pmuvar.h b/sys/powerpc/powermac/pmuvar.h index 8a5b8a3..d9cc1a0 100644 --- a/sys/powerpc/powermac/pmuvar.h +++ b/sys/powerpc/powermac/pmuvar.h @@ -11,9 +11,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -76,6 +73,7 @@ #define PMU_I2C_CMD 0x9a /* i2c commands */ #define PMU_GET_LID_STATE 0xdc /* Report lid state */ #define PMU_GET_VERSION 0xea /* Identify thyself */ +#define PMU_SET_SLEEPLED 0xee /* Set sleep LED on/off */ /* Bits in PMU interrupt and interrupt mask bytes */ #define PMU_INT_ADB_AUTO 0x04 /* ADB autopoll, when PMU_INT_ADB */ @@ -161,6 +159,7 @@ struct pmu_softc { device_t adb_bus; volatile int sc_autopoll; int sc_batteries; + struct cdev *sc_leddev; }; struct pmu_battstate { -- cgit v1.1