Make pcppi(4) use attimer(4) to set the pitch of the bell.
In case you don't configure an attimer(4) device in your kernel config, you will simply lose the ability to set the pitch. It will still beep.
This commit is contained in:
parent
f0c491ff32
commit
d2d1a8c05c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pcppi.c,v 1.15 2005/03/21 14:05:18 xtraeme Exp $ */
|
||||
/* $NetBSD: pcppi.c,v 1.16 2005/03/25 23:09:00 cube Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Carnegie-Mellon University.
|
||||
|
@ -28,7 +28,9 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.15 2005/03/21 14:05:18 xtraeme Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.16 2005/03/25 23:09:00 cube Exp $");
|
||||
|
||||
#include "attimer.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -40,13 +42,13 @@ __KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.15 2005/03/21 14:05:18 xtraeme Exp $");
|
|||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <dev/ic/attimervar.h>
|
||||
|
||||
#include <dev/isa/isareg.h>
|
||||
#include <dev/isa/isavar.h>
|
||||
#include <dev/isa/pcppireg.h>
|
||||
#include <dev/isa/pcppivar.h>
|
||||
|
||||
#include <dev/ic/i8253reg.h>
|
||||
|
||||
#include "pckbd.h"
|
||||
#if NPCKBD > 0
|
||||
#include <dev/pckbport/pckbdvar.h>
|
||||
|
@ -62,14 +64,18 @@ CFATTACH_DECL(pcppi, sizeof(struct pcppi_softc),
|
|||
|
||||
static void pcppi_bell_stop(void*);
|
||||
|
||||
#if NATTIMER > 0
|
||||
static void pcppi_attach_speaker(struct device *);
|
||||
#endif
|
||||
|
||||
#define PCPPIPRI (PZERO - 1)
|
||||
|
||||
int
|
||||
pcppi_match(struct device *parent, struct cfdata *match, void *aux)
|
||||
{
|
||||
struct isa_attach_args *ia = aux;
|
||||
bus_space_handle_t ppi_ioh, pit1_ioh;
|
||||
int have_pit1, have_ppi, rv;
|
||||
bus_space_handle_t ppi_ioh;
|
||||
int have_ppi, rv;
|
||||
u_int8_t v, nv;
|
||||
|
||||
if (ISA_DIRECT_CONFIG(ia))
|
||||
|
@ -94,11 +100,8 @@ pcppi_match(struct device *parent, struct cfdata *match, void *aux)
|
|||
return (0);
|
||||
|
||||
rv = 0;
|
||||
have_pit1 = have_ppi = 0;
|
||||
have_ppi = 0;
|
||||
|
||||
if (bus_space_map(ia->ia_iot, IO_TIMER1, 4, 0, &pit1_ioh))
|
||||
goto lose;
|
||||
have_pit1 = 1;
|
||||
if (bus_space_map(ia->ia_iot, IO_PPI, 1, 0, &ppi_ioh))
|
||||
goto lose;
|
||||
have_ppi = 1;
|
||||
|
@ -131,8 +134,6 @@ pcppi_match(struct device *parent, struct cfdata *match, void *aux)
|
|||
*/
|
||||
|
||||
lose:
|
||||
if (have_pit1)
|
||||
bus_space_unmap(ia->ia_iot, pit1_ioh, 4);
|
||||
if (have_ppi)
|
||||
bus_space_unmap(ia->ia_iot, ppi_ioh, 1);
|
||||
if (rv) {
|
||||
|
@ -156,8 +157,7 @@ pcppi_isa_attach(struct device *parent, struct device *self, void *aux)
|
|||
|
||||
sc->sc_iot = iot = ia->ia_iot;
|
||||
|
||||
if (bus_space_map(iot, IO_TIMER1, 4, 0, &sc->sc_pit1_ioh) ||
|
||||
bus_space_map(iot, IO_PPI, 1, 0, &sc->sc_ppi_ioh))
|
||||
if (bus_space_map(iot, IO_PPI, 1, 0, &sc->sc_ppi_ioh))
|
||||
panic("pcppi_attach: couldn't map");
|
||||
|
||||
printf("\n");
|
||||
|
@ -178,18 +178,36 @@ pcppi_attach(struct pcppi_softc *sc)
|
|||
/* Provide a beeper for the PC Keyboard, if there isn't one already. */
|
||||
pckbd_hookup_bell(pcppi_pckbd_bell, sc);
|
||||
#endif
|
||||
#if NATTIMER > 0
|
||||
config_defer((struct device *)sc, pcppi_attach_speaker);
|
||||
#endif
|
||||
|
||||
pa.pa_cookie = sc;
|
||||
while (config_found((struct device *)sc, &pa, 0));
|
||||
}
|
||||
|
||||
#if NATTIMER > 0
|
||||
static void
|
||||
pcppi_attach_speaker(struct device *self)
|
||||
{
|
||||
struct pcppi_softc *sc = (struct pcppi_softc *)self;
|
||||
|
||||
if ((sc->sc_timer = attimer_attach_speaker()) == NULL)
|
||||
aprint_error("%s: could not find any available timer\n",
|
||||
sc->sc_dv.dv_xname);
|
||||
else
|
||||
aprint_normal("%s: attached to %s\n", sc->sc_dv.dv_xname,
|
||||
sc->sc_timer->sc_dev.dv_xname);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
pcppi_bell(pcppi_tag_t self, int pitch, int period, int slp)
|
||||
{
|
||||
struct pcppi_softc *sc = self;
|
||||
int s1, s2;
|
||||
int s;
|
||||
|
||||
s1 = spltty(); /* ??? */
|
||||
s = spltty(); /* ??? */
|
||||
if (sc->sc_bellactive) {
|
||||
if (sc->sc_timeout) {
|
||||
sc->sc_timeout = 0;
|
||||
|
@ -201,18 +219,14 @@ pcppi_bell(pcppi_tag_t self, int pitch, int period, int slp)
|
|||
if (pitch == 0 || period == 0) {
|
||||
pcppi_bell_stop(sc);
|
||||
sc->sc_bellpitch = 0;
|
||||
splx(s1);
|
||||
splx(s);
|
||||
return;
|
||||
}
|
||||
if (!sc->sc_bellactive || sc->sc_bellpitch != pitch) {
|
||||
s2 = splhigh();
|
||||
bus_space_write_1(sc->sc_iot, sc->sc_pit1_ioh, TIMER_MODE,
|
||||
TIMER_SEL2 | TIMER_16BIT | TIMER_SQWAVE);
|
||||
bus_space_write_1(sc->sc_iot, sc->sc_pit1_ioh, TIMER_CNTR2,
|
||||
TIMER_DIV(pitch) % 256);
|
||||
bus_space_write_1(sc->sc_iot, sc->sc_pit1_ioh, TIMER_CNTR2,
|
||||
TIMER_DIV(pitch) / 256);
|
||||
splx(s2);
|
||||
#if NATTIMER > 0
|
||||
if (sc->sc_timer != NULL)
|
||||
attimer_set_pitch(sc->sc_timer, pitch);
|
||||
#endif
|
||||
/* enable speaker */
|
||||
bus_space_write_1(sc->sc_iot, sc->sc_ppi_ioh, 0,
|
||||
bus_space_read_1(sc->sc_iot, sc->sc_ppi_ioh, 0)
|
||||
|
@ -233,7 +247,7 @@ pcppi_bell(pcppi_tag_t self, int pitch, int period, int slp)
|
|||
sc->sc_slp = 0;
|
||||
}
|
||||
}
|
||||
splx(s1);
|
||||
splx(s);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pcppivar.h,v 1.5 2005/03/21 14:05:18 xtraeme Exp $ */
|
||||
/* $NetBSD: pcppivar.h,v 1.6 2005/03/25 23:09:00 cube Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Carnegie-Mellon University.
|
||||
|
@ -40,7 +40,8 @@ struct pcppi_softc {
|
|||
struct device sc_dv;
|
||||
|
||||
bus_space_tag_t sc_iot;
|
||||
bus_space_handle_t sc_ppi_ioh, sc_pit1_ioh;
|
||||
bus_space_handle_t sc_ppi_ioh;
|
||||
struct attimer_softc *sc_timer;
|
||||
|
||||
struct callout sc_bell_ch;
|
||||
|
||||
|
|
Loading…
Reference in New Issue