#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: spkr_pcppi.c,v 1.14 2022/09/25 17:09:36 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/errno.h>
#include <sys/device.h>
#include <sys/uio.h>
#include <sys/proc.h>
#include <sys/ioctl.h>
#include <sys/conf.h>
#include <sys/bus.h>
#include <dev/isa/pcppivar.h>
#include <dev/spkrvar.h>
#include <dev/spkrio.h>
struct spkr_pcppi_softc {
struct spkr_softc sc_spkr;
pcppi_tag_t sc_pcppicookie;
void (*sc_bell_func)(pcppi_tag_t, int, int, int);
};
static int spkr_pcppi_probe(device_t, cfdata_t, void *);
static void spkr_pcppi_attach(device_t, device_t, void *);
static int spkr_pcppi_detach(device_t, int);
static int spkr_pcppi_rescan(device_t, const char *, const int *);
static void spkr_pcppi_childdet(device_t, device_t);
CFATTACH_DECL3_NEW(spkr_pcppi, sizeof(struct spkr_pcppi_softc),
spkr_pcppi_probe, spkr_pcppi_attach, spkr_pcppi_detach, NULL,
spkr_pcppi_rescan, spkr_pcppi_childdet, 0);
static void
spkr_pcppi_tone(device_t self, u_int xhz, u_int ticks)
{
#ifdef SPKRDEBUG
device_printf(self, "%s: %u %u\n", __func__, xhz, ticks);
#endif
struct spkr_pcppi_softc *sc = device_private(self);
(*sc->sc_bell_func)(sc->sc_pcppicookie, xhz, ticks, PCPPI_BELL_SLEEP);
}
static int
spkr_pcppi_probe(device_t parent, cfdata_t cf, void *aux)
{
return 1;
}
static void
spkr_pcppi_attach(device_t parent, device_t self, void *aux)
{
struct pcppi_attach_args *pa = aux;
struct spkr_pcppi_softc *sc = device_private(self);
aprint_naive("\n");
aprint_normal(": PC Speaker\n");
sc->sc_pcppicookie = pa->pa_cookie;
sc->sc_bell_func = pa->pa_bell_func;
spkr_attach(self, spkr_pcppi_tone);
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "couldn't establish power handler\n");
}
static int
spkr_pcppi_detach(device_t self, int flags)
{
struct spkr_pcppi_softc *sc = device_private(self);
int error;
if ((error = spkr_detach(self, flags)) != 0)
return error;
sc->sc_pcppicookie = NULL;
pmf_device_deregister(self);
return 0;
}
static int
spkr_pcppi_rescan(device_t self, const char *iattr, const int *locators)
{
return spkr_rescan(self, iattr, locators);
}
static void
spkr_pcppi_childdet(device_t self, device_t child)
{
spkr_childdet(self, child);
}