Add the ability to control the sleep LED with led(4). Adding this fairly

useless feature gives us a reasonably complete PMU implementation.
This commit is contained in:
Nathan Whitehorn 2008-12-09 01:01:02 +00:00
parent bce289fa28
commit a228f5cd36
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=185782
2 changed files with 29 additions and 5 deletions

View File

@ -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 <dev/ofw/ofw_bus.h>
#include <dev/ofw/openfirm.h>
#include <dev/led/led.h>
#include <machine/bus.h>
#include <machine/intr.h>
@ -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)
{

View File

@ -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 {