summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormickey <mickey@openbsd.org>2000-12-27 02:50:07 +0000
committermickey <mickey@openbsd.org>2000-12-27 02:50:07 +0000
commitfde24895072068b356fddb36c4d768d84110dfdc (patch)
tree91d8b634bc8c0e2d3c8c1c983cc9f335ff276f5e
parentalways read new byte from rng, then decide wheather to start a new cycle (diff)
downloadwireguard-openbsd-fde24895072068b356fddb36c4d768d84110dfdc.tar.xz
wireguard-openbsd-fde24895072068b356fddb36c4d768d84110dfdc.zip
behave nicely w/ fixed rate codecs; from netbsd; testing by Igor Lulic <il11@mail.csuchico.edu>
-rw-r--r--sys/dev/pci/auvia.c87
-rw-r--r--sys/dev/pci/auviavar.h5
2 files changed, 53 insertions, 39 deletions
diff --git a/sys/dev/pci/auvia.c b/sys/dev/pci/auvia.c
index 4aff10183eb..83e1f640507 100644
--- a/sys/dev/pci/auvia.c
+++ b/sys/dev/pci/auvia.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: auvia.c,v 1.2 2000/10/14 18:04:07 aaron Exp $ */
-/* $NetBSD: auvia.c,v 1.3.4.1 2000/06/30 16:27:49 simonb Exp $ */
+/* $OpenBSD: auvia.c,v 1.3 2000/12/27 02:50:07 mickey Exp $ */
+/* $NetBSD: auvia.c,v 1.7 2000/11/15 21:06:33 jdolecek Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -53,6 +53,8 @@
#include <sys/device.h>
#include <sys/audioio.h>
+#include <vm/vm.h>
+
#include <dev/pci/pcidevs.h>
#include <dev/pci/pcivar.h>
@@ -81,6 +83,9 @@ struct auvia_dma_op {
#define AUVIA_DMAOP_COUNT(x) ((x)&0x00FFFFFF)
};
+/* rev. H and later seem to support only fixed rate 44.1 kHz */
+#define AUVIA_FIXED_RATE 44100
+
int auvia_match(struct device *, void *, void *);
void auvia_attach(struct device *, struct device *, void *);
int auvia_open(void *, int);
@@ -218,14 +223,14 @@ auvia_attach(struct device *parent, struct device *self, void *aux)
{
struct pci_attach_args *pa = aux;
struct auvia_softc *sc = (struct auvia_softc *) self;
- const char *intrstr = NULL;
+ const char *intrstr = NULL;
struct mixer_ctrl ctl;
pci_chipset_tag_t pc = pa->pa_pc;
- pcitag_t pt = pa->pa_tag;
- pci_intr_handle_t ih;
+ pcitag_t pt = pa->pa_tag;
+ pci_intr_handle_t ih;
pcireg_t pr;
u_int16_t v;
- int r, i;
+ int r, i;
r = PCI_REVISION(pa->pa_class);
sc->sc_revision[1] = '\0';
@@ -264,7 +269,7 @@ auvia_attach(struct device *parent, struct device *self, void *aux)
printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0, &sc->sc_iot,
- &sc->sc_ioh, &sc->sc_ioaddr, &sc->sc_iosize)) {
+ &sc->sc_ioh, &sc->sc_ioaddr, &sc->sc_iosize)) {
printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
return;
}
@@ -294,17 +299,20 @@ auvia_attach(struct device *parent, struct device *self, void *aux)
return;
}
+ /*
+ * Print a warning if the codec doesn't support hardware variable
+ * rate audio.
+ */
if (auvia_read_codec(sc, AC97_REG_EXT_AUDIO_ID, &v)
- || !(v & AC97_CODEC_DOES_VRA)) {
- /* XXX */
-
- printf("%s: codec must support AC'97 2.0 Variable Rate Audio\n",
+ || !(v & AC97_CODEC_DOES_VRA)) {
+ printf("%s: warning: codec doesn't support hardware AC'97 2.0 Variable Rate Audio\n",
sc->sc_dev.dv_xname);
- return;
+ sc->sc_fixed_rate = AUVIA_FIXED_RATE;
} else {
/* enable VRA */
auvia_write_codec(sc, AC97_REG_EXT_AUDIO_STAT,
AC97_ENAB_VRA | AC97_ENAB_MICVRA);
+ sc->sc_fixed_rate = 0;
}
/* disable mutes */
@@ -317,7 +325,7 @@ auvia_attach(struct device *parent, struct device *self, void *aux)
{ AudioCinputs, AudioNcd},
{ AudioCrecord, AudioNvolume},
};
-
+
ctl.type = AUDIO_MIXER_ENUM;
ctl.un.ord = 0;
@@ -336,8 +344,8 @@ auvia_attach(struct device *parent, struct device *self, void *aux)
ctl.dev = sc->codec_if->vtbl->get_portnum_by_name(sc->codec_if,
AudioCoutputs, AudioNmaster, NULL);
auvia_set_port(sc, &ctl);
-
- audio_attach_mi(&auvia_hw_if, sc, &sc->sc_dev);
+
+ audio_attach_mi(&auvia_hw_if, sc, &sc->sc_dev);
}
@@ -461,7 +469,7 @@ void
auvia_close(void *addr)
{
struct auvia_softc *sc = addr;
-
+
auvia_halt_output(sc);
auvia_halt_input(sc);
@@ -538,7 +546,7 @@ auvia_set_params(void *addr, int setmode, int usemode,
int reg, mode;
/* for mode in (RECORD, PLAY) */
- for (mode = AUMODE_RECORD; mode != -1;
+ for (mode = AUMODE_RECORD; mode != -1;
mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
if ((setmode & mode) == 0)
continue;
@@ -553,9 +561,12 @@ auvia_set_params(void *addr, int setmode, int usemode,
reg = mode == AUMODE_PLAY ?
AC97_REG_EXT_DAC_RATE : AC97_REG_EXT_ADC_RATE;
- auvia_write_codec(sc, reg, (u_int16_t) p->sample_rate);
- auvia_read_codec(sc, reg, &regval);
- p->sample_rate = regval;
+ if (!sc->sc_fixed_rate) {
+ auvia_write_codec(sc, reg, (u_int16_t) p->sample_rate);
+ auvia_read_codec(sc, reg, &regval);
+ p->sample_rate = regval;
+ } else
+ p->sample_rate = sc->sc_fixed_rate;
p->factor = 1;
p->sw_code = 0;
@@ -627,7 +638,7 @@ auvia_round_blocksize(void *addr, int blk)
int
auvia_halt_output(void *addr)
{
- struct auvia_softc *sc = addr;
+ struct auvia_softc *sc = addr;
bus_space_write_1(sc->sc_iot, sc->sc_ioh, AUVIA_PLAY_CONTROL,
AUVIA_RPCTRL_TERMINATE);
@@ -639,7 +650,7 @@ auvia_halt_output(void *addr)
int
auvia_halt_input(void *addr)
{
- struct auvia_softc *sc = addr;
+ struct auvia_softc *sc = addr;
bus_space_write_1(sc->sc_iot, sc->sc_ioh, AUVIA_RECORD_CONTROL,
AUVIA_RPCTRL_TERMINATE);
@@ -651,7 +662,7 @@ auvia_halt_input(void *addr)
int
auvia_getdev(void *addr, struct audio_device *retp)
{
- struct auvia_softc *sc = addr;
+ struct auvia_softc *sc = addr;
if (retp) {
strncpy(retp->name, "VIA VT82C686A", sizeof(retp->name));
@@ -703,31 +714,31 @@ auvia_malloc(void *addr, int direction, size_t size, int pool, int flags)
return 0;
p->size = size;
- if ((error = bus_dmamem_alloc(sc->sc_dmat, size, NBPG, 0, &p->seg, 1,
- &rseg, BUS_DMA_NOWAIT)) != 0) {
- printf("%s: unable to allocate dma, error = %d\n",
- sc->sc_dev.dv_xname, error);
+ if ((error = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0, &p->seg,
+ 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
+ printf("%s: unable to allocate dma, error = %d\n",
+ sc->sc_dev.dv_xname, error);
goto fail_alloc;
}
if ((error = bus_dmamem_map(sc->sc_dmat, &p->seg, rseg, size, &p->addr,
- BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
- printf("%s: unable to map dma, error = %d\n",
- sc->sc_dev.dv_xname, error);
+ BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
+ printf("%s: unable to map dma, error = %d\n",
+ sc->sc_dev.dv_xname, error);
goto fail_map;
}
- if ((error = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
- BUS_DMA_NOWAIT, &p->map)) != 0) {
+ if ((error = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
+ BUS_DMA_NOWAIT, &p->map)) != 0) {
printf("%s: unable to create dma map, error = %d\n",
- sc->sc_dev.dv_xname, error);
+ sc->sc_dev.dv_xname, error);
goto fail_create;
}
if ((error = bus_dmamap_load(sc->sc_dmat, p->map, p->addr, size, NULL,
- BUS_DMA_NOWAIT)) != 0) {
+ BUS_DMA_NOWAIT)) != 0) {
printf("%s: unable to load dma map, error = %d\n",
- sc->sc_dev.dv_xname, error);
+ sc->sc_dev.dv_xname, error);
goto fail_load;
}
@@ -761,7 +772,7 @@ auvia_free(void *addr, void *ptr, int pool)
bus_dmamap_destroy(sc->sc_dmat, p->map);
bus_dmamem_unmap(sc->sc_dmat, p->addr, p->size);
bus_dmamem_free(sc->sc_dmat, &p->seg, 1);
-
+
*pp = p->next;
free(p, pool);
return;
@@ -793,8 +804,8 @@ auvia_mappage(void *addr, void *mem, int off, int prot)
if (!p)
return -1;
- return bus_dmamem_mmap(sc->sc_dmat, &p->seg, 1, off, prot,
- BUS_DMA_WAITOK);
+ return bus_dmamem_mmap(sc->sc_dmat, &p->seg, 1, off, prot,
+ BUS_DMA_WAITOK);
}
diff --git a/sys/dev/pci/auviavar.h b/sys/dev/pci/auviavar.h
index 414e3c702f1..0ea7fab5513 100644
--- a/sys/dev/pci/auviavar.h
+++ b/sys/dev/pci/auviavar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: auviavar.h,v 1.2 2000/10/14 18:04:07 aaron Exp $ */
+/* $OpenBSD: auviavar.h,v 1.3 2000/12/27 02:50:07 mickey Exp $ */
/* $NetBSD: auviavar.h,v 1.1 2000/03/31 04:45:29 tsarna Exp $ */
/*-
@@ -55,6 +55,9 @@ struct auvia_softc {
struct device sc_dev;
char sc_revision[8];
+ u_long sc_fixed_rate; /* if codec doesn't support variable
+ * rate audio, set to the fixed rate
+ * it uses */
void *sc_ih; /* interrupt handle */