#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nbppm.c,v 1.1 2011/08/06 03:53:40 kiyohara Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <machine/config_hook.h>
#include <arm/xscale/pxa2x0_gpio.h>
#include <hpcarm/dev/nbppconvar.h>
#include "locators.h"
struct nbppm_softc {
device_t sc_dev;
device_t sc_parent;
int sc_tag;
};
static int nbppm_match(device_t, cfdata_t, void *);
static void nbppm_attach(device_t, device_t, void *);
static int nbppm_critical_intr(void *);
static int nbppm_suspend_intr(void *);
CFATTACH_DECL_NEW(nbppm, sizeof(struct nbppm_softc),
nbppm_match, nbppm_attach, NULL, NULL);
static int
nbppm_match(device_t parent, cfdata_t match, void *aux)
{
struct nbppcon_attach_args *pcon = aux;
if (strcmp(pcon->aa_name, match->cf_name) ||
pcon->aa_tag == NBPPCONCF_TAG_DEFAULT)
return 0;
return 1;
}
static void
nbppm_attach(device_t parent, device_t self, void *aux)
{
struct nbppm_softc *sc = device_private(self);
struct nbppcon_attach_args *pcon = aux;
aprint_naive("\n");
aprint_normal("\n");
sc->sc_dev = self;
sc->sc_parent = parent;
sc->sc_tag = pcon->aa_tag;
pxa2x0_gpio_set_function(0, GPIO_IN);
if (pxa2x0_gpio_intr_establish(0, IST_EDGE_RISING, IPL_HIGH,
nbppm_critical_intr, sc) == NULL)
aprint_error_dev(self,
"unable to establish critical interrupt\n");
pxa2x0_gpio_set_function(1, GPIO_IN);
if (pxa2x0_gpio_intr_establish(1, IST_EDGE_BOTH, IPL_HIGH,
nbppm_suspend_intr, sc) == NULL)
aprint_error_dev(self,
"unable to establish suspend interrupt\n");
return;
}
static int
nbppm_critical_intr(void *arg)
{
struct nbppm_softc *sc = arg;
aprint_normal_dev(sc->sc_dev, "Battery Low\n");
return 0;
}
static int
nbppm_suspend_intr(void *arg)
{
struct nbppm_softc *sc = arg;
aprint_verbose_dev(sc->sc_dev, "lid closed\n");
return 0;
}