NetBSD/sys/dev/tc/bba.c

788 lines
19 KiB
C
Raw Normal View History

/* $NetBSD: bba.c,v 1.34 2008/04/28 20:23:58 martin Exp $ */
2000-05-02 10:43:05 +04:00
/*
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* maxine/alpha baseboard audio (bba) */
2001-11-13 09:26:09 +03:00
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bba.c,v 1.34 2008/04/28 20:23:58 martin Exp $");
2001-11-13 09:26:09 +03:00
2000-05-02 10:43:05 +04:00
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/bus.h>
2000-05-02 10:43:05 +04:00
#include <machine/autoconf.h>
#include <sys/cpu.h>
2000-05-02 10:43:05 +04:00
#include <sys/audioio.h>
#include <dev/audio_if.h>
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
#include <dev/auconv.h>
2000-05-02 10:43:05 +04:00
#include <dev/ic/am7930reg.h>
#include <dev/ic/am7930var.h>
#include <dev/tc/tcvar.h>
#include <dev/tc/ioasicreg.h>
#include <dev/tc/ioasicvar.h>
#ifdef AUDIO_DEBUG
#define DPRINTF(x) if (am7930debug) printf x
#else
#define DPRINTF(x)
#endif /* AUDIO_DEBUG */
#define BBA_MAX_DMA_SEGMENTS 16
#define BBA_DMABUF_SIZE (BBA_MAX_DMA_SEGMENTS*IOASIC_DMA_BLOCKSIZE)
#define BBA_DMABUF_ALIGN IOASIC_DMA_BLOCKSIZE
#define BBA_DMABUF_BOUNDARY 0
2000-05-02 10:43:05 +04:00
struct bba_mem {
2005-01-15 18:19:51 +03:00
struct bba_mem *next;
2000-05-02 10:43:05 +04:00
bus_addr_t addr;
bus_size_t size;
void *kva;
2000-05-02 10:43:05 +04:00
};
struct bba_dma_state {
2003-05-03 22:10:37 +04:00
bus_dmamap_t dmam; /* DMA map */
2000-05-02 10:43:05 +04:00
int active;
2003-05-03 22:10:37 +04:00
int curseg; /* current segment in DMA buffer */
2005-01-15 18:19:51 +03:00
void (*intr)(void *); /* higher-level audio handler */
2000-05-02 10:43:05 +04:00
void *intr_arg;
};
struct bba_softc {
struct am7930_softc sc_am7930; /* glue to MI code */
bus_space_tag_t sc_bst; /* IOASIC bus tag/handle */
bus_space_handle_t sc_bsh;
bus_dma_tag_t sc_dmat;
bus_space_handle_t sc_codec_bsh; /* codec bus space handle */
struct bba_mem *sc_mem_head; /* list of buffers */
struct bba_dma_state sc_tx_dma_state;
struct bba_dma_state sc_rx_dma_state;
};
2006-03-30 22:14:37 +04:00
static int bba_match(struct device *, struct cfdata *, void *);
static void bba_attach(struct device *, struct device *, void *);
2000-05-02 10:43:05 +04:00
2002-10-01 05:05:50 +04:00
CFATTACH_DECL(bba, sizeof(struct bba_softc),
2002-10-02 20:51:16 +04:00
bba_match, bba_attach, NULL, NULL);
2000-05-02 10:43:05 +04:00
/*
* Define our interface into the am7930 MI driver.
*/
2006-03-31 11:34:31 +04:00
static uint8_t bba_codec_iread(struct am7930_softc *, int);
2006-03-30 22:14:37 +04:00
static uint16_t bba_codec_iread16(struct am7930_softc *, int);
static void bba_codec_iwrite(struct am7930_softc *, int, uint8_t);
static void bba_codec_iwrite16(struct am7930_softc *, int, uint16_t);
static void bba_onopen(struct am7930_softc *);
static void bba_onclose(struct am7930_softc *);
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
static stream_filter_factory_t bba_output_conv;
static stream_filter_factory_t bba_input_conv;
2006-03-30 22:14:37 +04:00
static int bba_output_conv_fetch_to(stream_fetcher_t *, audio_stream_t *,
int);
static int bba_input_conv_fetch_to(stream_fetcher_t *, audio_stream_t *,
int);
2000-05-02 10:43:05 +04:00
struct am7930_glue bba_glue = {
bba_codec_iread,
bba_codec_iwrite,
bba_codec_iread16,
bba_codec_iwrite16,
bba_onopen,
bba_onclose,
4,
bba_input_conv,
bba_output_conv,
};
/*
* Define our interface to the higher level audio driver.
*/
2006-03-30 22:14:37 +04:00
static int bba_round_blocksize(void *, int, int, const audio_params_t *);
static int bba_halt_output(void *);
static int bba_halt_input(void *);
static int bba_getdev(void *, struct audio_device *);
static void *bba_allocm(void *, int, size_t, struct malloc_type *, int);
static void bba_freem(void *, void *, struct malloc_type *);
static size_t bba_round_buffersize(void *, int, size_t);
static int bba_get_props(void *);
static paddr_t bba_mappage(void *, void *, off_t, int);
static int bba_trigger_output(void *, void *, void *, int,
void (*)(void *), void *,
const audio_params_t *);
static int bba_trigger_input(void *, void *, void *, int,
void (*)(void *), void *,
const audio_params_t *);
static const struct audio_hw_if sa_hw_if = {
2000-05-02 10:43:05 +04:00
am7930_open,
am7930_close,
0,
am7930_query_encoding,
am7930_set_params,
bba_round_blocksize, /* md */
am7930_commit_settings,
0,
0,
0,
0,
bba_halt_output, /* md */
bba_halt_input, /* md */
0,
bba_getdev,
0,
am7930_set_port,
am7930_get_port,
am7930_query_devinfo,
bba_allocm, /* md */
bba_freem, /* md */
bba_round_buffersize, /* md */
bba_mappage,
bba_get_props,
2000-05-02 10:43:05 +04:00
bba_trigger_output, /* md */
bba_trigger_input, /* md */
0,
2000-05-02 10:43:05 +04:00
};
2006-03-30 22:14:37 +04:00
static struct audio_device bba_device = {
2000-05-02 10:43:05 +04:00
"am7930",
"x",
"bba"
};
2006-03-30 22:14:37 +04:00
static int bba_intr(void *);
static void bba_reset(struct bba_softc *, int);
static void bba_codec_dwrite(struct am7930_softc *, int, u_int8_t);
static uint8_t bba_codec_dread(struct am7930_softc *, int);
2000-05-02 10:43:05 +04:00
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_match(struct device *parent, struct cfdata *cf, void *aux)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct ioasicdev_attach_args *ia;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
ia = aux;
if (strcmp(ia->iada_modname, "isdn") != 0 &&
strcmp(ia->iada_modname, "AMD79c30") != 0)
return 0;
2000-05-02 10:43:05 +04:00
return 1;
}
2006-03-30 22:14:37 +04:00
static void
2005-01-15 18:19:51 +03:00
bba_attach(struct device *parent, struct device *self, void *aux)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct ioasicdev_attach_args *ia;
struct bba_softc *sc;
struct am7930_softc *asc;
2006-03-30 22:16:20 +04:00
struct ioasic_softc *iosc = device_private(parent);
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
ia = aux;
2006-03-30 20:09:28 +04:00
sc = device_private(self);
2005-01-15 18:19:51 +03:00
asc = &sc->sc_am7930;
2006-03-30 22:16:20 +04:00
sc->sc_bst = iosc->sc_bst;
sc->sc_bsh = iosc->sc_bsh;
sc->sc_dmat = iosc->sc_dmat;
2000-05-02 10:43:05 +04:00
/* get the bus space handle for codec */
if (bus_space_subregion(sc->sc_bst, sc->sc_bsh,
ia->iada_offset, 0, &sc->sc_codec_bsh)) {
2008-04-05 20:35:35 +04:00
aprint_error_dev(&asc->sc_dev, "unable to map device\n");
2000-05-02 10:43:05 +04:00
return;
}
printf("\n");
bba_reset(sc,1);
/*
* Set up glue for MI code early; we use some of it here.
*/
asc->sc_glue = &bba_glue;
/*
* MI initialisation. We will be doing DMA.
*/
am7930_init(asc, AUDIOAMD_DMA_MODE);
ioasic_intr_establish(parent, ia->iada_cookie, TC_IPL_NONE,
bba_intr, sc);
2000-05-02 10:43:05 +04:00
audio_attach_mi(&sa_hw_if, asc, &asc->sc_dev);
}
2006-03-30 22:14:37 +04:00
static void
2005-01-15 18:19:51 +03:00
bba_onopen(struct am7930_softc *sc)
2000-05-02 10:43:05 +04:00
{
}
2006-03-30 22:14:37 +04:00
static void
2005-01-15 18:19:51 +03:00
bba_onclose(struct am7930_softc *sc)
2000-05-02 10:43:05 +04:00
{
}
2006-03-30 22:14:37 +04:00
static void
2005-01-15 18:19:51 +03:00
bba_reset(struct bba_softc *sc, int reset)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
uint32_t ssr;
2000-05-02 10:43:05 +04:00
/* disable any DMA and reset the codec */
ssr = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR);
ssr &= ~(IOASIC_CSR_DMAEN_ISDN_T | IOASIC_CSR_DMAEN_ISDN_R);
if (reset)
ssr &= ~IOASIC_CSR_ISDN_ENABLE;
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
DELAY(10); /* 400ns required for codec to reset */
/* initialise DMA pointers */
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_X_DMAPTR, -1);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_X_NEXTPTR, -1);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_R_DMAPTR, -1);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_R_NEXTPTR, -1);
/* take out of reset state */
if (reset) {
ssr |= IOASIC_CSR_ISDN_ENABLE;
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
}
}
2006-03-30 22:14:37 +04:00
static void *
2005-01-15 18:19:51 +03:00
bba_allocm(void *addr, int direction, size_t size,
struct malloc_type *pool, int flags)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct am7930_softc *asc;
struct bba_softc *sc;
2000-05-02 10:43:05 +04:00
bus_dma_segment_t seg;
int rseg;
void *kva;
2000-05-02 10:43:05 +04:00
struct bba_mem *m;
int w;
2005-01-15 18:19:51 +03:00
int state;
2000-05-02 10:43:05 +04:00
DPRINTF(("bba_allocm: size = %zu\n", size));
2005-01-15 18:19:51 +03:00
asc = addr;
sc = addr;
state = 0;
w = (flags & M_NOWAIT) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
if (bus_dmamem_alloc(sc->sc_dmat, size, BBA_DMABUF_ALIGN,
BBA_DMABUF_BOUNDARY, &seg, 1, &rseg, w)) {
2008-04-05 20:35:35 +04:00
aprint_error_dev(&asc->sc_dev, "can't allocate DMA buffer\n");
2000-05-02 10:43:05 +04:00
goto bad;
}
state |= 1;
if (bus_dmamem_map(sc->sc_dmat, &seg, rseg, size,
&kva, w | BUS_DMA_COHERENT)) {
2008-04-05 20:35:35 +04:00
aprint_error_dev(&asc->sc_dev, "can't map DMA buffer\n");
2000-05-02 10:43:05 +04:00
goto bad;
}
state |= 2;
m = malloc(sizeof(struct bba_mem), pool, flags);
if (m == NULL)
goto bad;
m->addr = seg.ds_addr;
m->size = seg.ds_len;
2005-01-15 18:19:51 +03:00
m->kva = kva;
m->next = sc->sc_mem_head;
sc->sc_mem_head = m;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
return (void *)kva;
2000-05-02 10:43:05 +04:00
bad:
if (state & 2)
bus_dmamem_unmap(sc->sc_dmat, kva, size);
if (state & 1)
bus_dmamem_free(sc->sc_dmat, &seg, 1);
return NULL;
}
2006-03-30 22:14:37 +04:00
static void
2005-01-15 18:19:51 +03:00
bba_freem(void *addr, void *ptr, struct malloc_type *pool)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
struct bba_mem **mp, *m;
2000-05-02 10:43:05 +04:00
bus_dma_segment_t seg;
void *kva;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
sc = addr;
kva = (void *)addr;
2000-05-02 10:43:05 +04:00
for (mp = &sc->sc_mem_head; *mp && (*mp)->kva != kva;
mp = &(*mp)->next)
2005-01-15 18:19:51 +03:00
continue;
2000-05-02 10:43:05 +04:00
m = *mp;
if (m == NULL) {
printf("bba_freem: freeing unallocated memory\n");
2000-05-02 10:43:05 +04:00
return;
}
*mp = m->next;
bus_dmamem_unmap(sc->sc_dmat, kva, m->size);
2005-01-15 18:19:51 +03:00
seg.ds_addr = m->addr;
seg.ds_len = m->size;
2000-05-02 10:43:05 +04:00
bus_dmamem_free(sc->sc_dmat, &seg, 1);
2005-01-15 18:19:51 +03:00
free(m, pool);
2000-05-02 10:43:05 +04:00
}
2006-03-30 22:14:37 +04:00
static size_t
2005-01-15 18:19:51 +03:00
bba_round_buffersize(void *addr, int direction, size_t size)
2000-05-02 10:43:05 +04:00
{
DPRINTF(("bba_round_buffersize: size=%zu\n", size));
2005-01-15 18:19:51 +03:00
return size > BBA_DMABUF_SIZE ? BBA_DMABUF_SIZE :
roundup(size, IOASIC_DMA_BLOCKSIZE);
2000-05-02 10:43:05 +04:00
}
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_halt_output(void *addr)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
struct bba_dma_state *d;
uint32_t ssr;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
sc = addr;
d = &sc->sc_tx_dma_state;
2000-05-02 10:43:05 +04:00
/* disable any DMA */
ssr = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR);
ssr &= ~IOASIC_CSR_DMAEN_ISDN_T;
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_X_DMAPTR, -1);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_X_NEXTPTR, -1);
if (d->active) {
bus_dmamap_unload(sc->sc_dmat, d->dmam);
bus_dmamap_destroy(sc->sc_dmat, d->dmam);
d->active = 0;
}
return 0;
}
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_halt_input(void *addr)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
struct bba_dma_state *d;
uint32_t ssr;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
sc = addr;
d = &sc->sc_rx_dma_state;
2000-05-02 10:43:05 +04:00
/* disable any DMA */
ssr = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR);
ssr &= ~IOASIC_CSR_DMAEN_ISDN_R;
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_R_DMAPTR, -1);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_R_NEXTPTR, -1);
if (d->active) {
bus_dmamap_unload(sc->sc_dmat, d->dmam);
bus_dmamap_destroy(sc->sc_dmat, d->dmam);
d->active = 0;
}
return 0;
}
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_getdev(void *addr, struct audio_device *retp)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
2000-05-02 10:43:05 +04:00
*retp = bba_device;
return 0;
}
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_trigger_output(void *addr, void *start, void *end, int blksize,
void (*intr)(void *), void *arg,
const audio_params_t *param)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
struct bba_dma_state *d;
uint32_t ssr;
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
tc_addr_t phys, nphys;
2005-01-15 18:19:51 +03:00
int state;
2000-05-02 10:43:05 +04:00
DPRINTF(("bba_trigger_output: sc=%p start=%p end=%p blksize=%d intr=%p(%p)\n",
addr, start, end, blksize, intr, arg));
2005-01-15 18:19:51 +03:00
sc = addr;
d = &sc->sc_tx_dma_state;
state = 0;
/* disable any DMA */
ssr = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR);
ssr &= ~IOASIC_CSR_DMAEN_ISDN_T;
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
2000-05-02 10:43:05 +04:00
if (bus_dmamap_create(sc->sc_dmat, (char *)end - (char *)start,
BBA_MAX_DMA_SEGMENTS, IOASIC_DMA_BLOCKSIZE,
BBA_DMABUF_BOUNDARY, BUS_DMA_NOWAIT, &d->dmam)) {
2000-05-02 10:43:05 +04:00
printf("bba_trigger_output: can't create DMA map\n");
goto bad;
}
state |= 1;
if (bus_dmamap_load(sc->sc_dmat, d->dmam, start,
(char *)end - (char *)start, NULL, BUS_DMA_WRITE|BUS_DMA_NOWAIT)) {
printf("bba_trigger_output: can't load DMA map\n");
2000-05-02 10:43:05 +04:00
goto bad;
}
state |= 2;
d->intr = intr;
d->intr_arg = arg;
d->curseg = 1;
/* get physical address of buffer start */
phys = (tc_addr_t)d->dmam->dm_segs[0].ds_addr;
nphys = (tc_addr_t)d->dmam->dm_segs[1].ds_addr;
2000-05-02 10:43:05 +04:00
/* setup DMA pointer */
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_X_DMAPTR,
IOASIC_DMA_ADDR(phys));
2000-05-02 10:43:05 +04:00
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_X_NEXTPTR,
IOASIC_DMA_ADDR(nphys));
2000-05-02 10:43:05 +04:00
/* kick off DMA */
ssr |= IOASIC_CSR_DMAEN_ISDN_T;
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
d->active = 1;
return 0;
bad:
if (state & 2)
bus_dmamap_unload(sc->sc_dmat, d->dmam);
if (state & 1)
bus_dmamap_destroy(sc->sc_dmat, d->dmam);
return 1;
}
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_trigger_input(void *addr, void *start, void *end, int blksize,
void (*intr)(void *), void *arg, const audio_params_t *param)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
struct bba_dma_state *d;
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
tc_addr_t phys, nphys;
2000-05-02 10:43:05 +04:00
u_int32_t ssr;
int state = 0;
DPRINTF(("bba_trigger_input: sc=%p start=%p end=%p blksize=%d intr=%p(%p)\n",
addr, start, end, blksize, intr, arg));
2005-01-15 18:19:51 +03:00
sc = (struct bba_softc *)addr;
d = &sc->sc_rx_dma_state;
state = 0;
/* disable any DMA */
ssr = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR);
ssr &= ~IOASIC_CSR_DMAEN_ISDN_R;
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
2000-05-02 10:43:05 +04:00
if (bus_dmamap_create(sc->sc_dmat, (char *)end - (char *)start,
BBA_MAX_DMA_SEGMENTS, IOASIC_DMA_BLOCKSIZE,
BBA_DMABUF_BOUNDARY, BUS_DMA_NOWAIT, &d->dmam)) {
2000-05-02 10:43:05 +04:00
printf("bba_trigger_input: can't create DMA map\n");
goto bad;
}
state |= 1;
if (bus_dmamap_load(sc->sc_dmat, d->dmam, start,
(char *)end - (char *)start, NULL, BUS_DMA_READ|BUS_DMA_NOWAIT)) {
2000-05-02 10:43:05 +04:00
printf("bba_trigger_input: can't load DMA map\n");
goto bad;
}
state |= 2;
d->intr = intr;
d->intr_arg = arg;
d->curseg = 1;
/* get physical address of buffer start */
phys = (tc_addr_t)d->dmam->dm_segs[0].ds_addr;
nphys = (tc_addr_t)d->dmam->dm_segs[1].ds_addr;
2000-05-02 10:43:05 +04:00
/* setup DMA pointer */
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_R_DMAPTR,
IOASIC_DMA_ADDR(phys));
2000-05-02 10:43:05 +04:00
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_ISDN_R_NEXTPTR,
IOASIC_DMA_ADDR(nphys));
2000-05-02 10:43:05 +04:00
/* kick off DMA */
ssr |= IOASIC_CSR_DMAEN_ISDN_R;
bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
d->active = 1;
return 0;
bad:
if (state & 2)
bus_dmamap_unload(sc->sc_dmat, d->dmam);
if (state & 1)
bus_dmamap_destroy(sc->sc_dmat, d->dmam);
return 1;
}
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_intr(void *addr)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
2000-05-02 10:43:05 +04:00
struct bba_dma_state *d;
tc_addr_t nphys;
int s, mask;
2005-01-15 18:19:51 +03:00
sc = addr;
2000-05-02 10:43:05 +04:00
s = splaudio();
mask = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_INTR);
if (mask & IOASIC_INTR_ISDN_TXLOAD) {
d = &sc->sc_tx_dma_state;
d->curseg = (d->curseg+1) % d->dmam->dm_nsegs;
nphys = (tc_addr_t)d->dmam->dm_segs[d->curseg].ds_addr;
bus_space_write_4(sc->sc_bst, sc->sc_bsh,
IOASIC_ISDN_X_NEXTPTR, IOASIC_DMA_ADDR(nphys));
2000-05-02 10:43:05 +04:00
if (d->intr != NULL)
(*d->intr)(d->intr_arg);
}
if (mask & IOASIC_INTR_ISDN_RXLOAD) {
d = &sc->sc_rx_dma_state;
d->curseg = (d->curseg+1) % d->dmam->dm_nsegs;
nphys = (tc_addr_t)d->dmam->dm_segs[d->curseg].ds_addr;
bus_space_write_4(sc->sc_bst, sc->sc_bsh,
IOASIC_ISDN_R_NEXTPTR, IOASIC_DMA_ADDR(nphys));
2000-05-02 10:43:05 +04:00
if (d->intr != NULL)
(*d->intr)(d->intr_arg);
}
splx(s);
return 0;
}
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_get_props(void *addr)
{
2005-01-15 18:19:51 +03:00
return AUDIO_PROP_MMAP | am7930_get_props(addr);
}
2006-03-30 22:14:37 +04:00
static paddr_t
2005-01-15 18:19:51 +03:00
bba_mappage(void *addr, void *mem, off_t offset, int prot)
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
struct bba_mem **mp;
bus_dma_segment_t seg;
void *kva;
2005-01-15 18:19:51 +03:00
sc = addr;
kva = (void *)mem;
for (mp = &sc->sc_mem_head; *mp && (*mp)->kva != kva;
mp = &(*mp)->next)
2005-01-15 18:19:51 +03:00
continue;
if (*mp == NULL || offset < 0) {
return -1;
}
2005-01-15 18:19:51 +03:00
seg.ds_addr = (*mp)->addr;
seg.ds_len = (*mp)->size;
2005-01-15 18:19:51 +03:00
return bus_dmamem_mmap(sc->sc_dmat, &seg, 1, offset,
prot, BUS_DMA_WAITOK);
}
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
static stream_filter_t *
bba_input_conv(struct audio_softc *sc, const audio_params_t *from,
const audio_params_t *to)
2000-05-02 10:43:05 +04:00
{
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
return auconv_nocontext_filter_factory(bba_input_conv_fetch_to);
2000-05-02 10:43:05 +04:00
}
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
static int
bba_input_conv_fetch_to(stream_fetcher_t *self, audio_stream_t *dst,
int max_used)
2000-05-02 10:43:05 +04:00
{
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
stream_filter_t *this;
int m, err;
this = (stream_filter_t *)self;
if ((err = this->prev->fetch_to(this->prev, this->src, max_used * 4)))
return err;
m = dst->end - dst->start;
m = min(m, max_used);
FILTER_LOOP_PROLOGUE(this->src, 4, dst, 1, m) {
2005-06-01 20:17:40 +04:00
*d = ((*(const uint32_t *)s) >> 16) & 0xff;
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
} FILTER_LOOP_EPILOGUE(this->src, dst);
return 0;
}
2000-05-02 10:43:05 +04:00
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
static stream_filter_t *
bba_output_conv(struct audio_softc *sc, const audio_params_t *from,
const audio_params_t *to)
{
return auconv_nocontext_filter_factory(bba_output_conv_fetch_to);
}
2000-05-02 10:43:05 +04:00
merge kent-audio1 branch, which introduces audio filter pipeline to the MI audio framework Summary of changes: * struct audio_params - remove sw_code, factor, factor_denom, hw_sample_rate, hw_encoding ,hw_precision, and hw_channels. Conversion information is conveyed by stream_filter_list_t. - change the type of sample_rate: u_long -> u_int - add `validbits,' which represents the valid data size in precision bits. It is required in order to distinguish 24/32bit from 24/24bit or 32/32bit. * audio_hw_if - add two parameters to set_params() stream_filter_list_t *pfil, stream_filter_list *rfil A HW driver should set filter recipes for requested formats - constify audio_params parameters of trigger_output() and trigger_input(). They represent audio formats for the hardware. - make open() and close() optional - add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters to round_blocksize() * sw_code is replaced with stream_filter_t. stream_filer_t converts audio data in an input buffer and writes into another output buffer unlike sw_code, which converts data in single buffer. converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c, dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are reimplemented as stream_filter_t * MI audio - audiosetinfo() builds filter pipelines from stream_filter_list_t filled by audio_hw_if::set_params() - audiosetinfo() returns with EINVAL if mmapped and set_params() requests filters - audio_write(), audio_pint(), and audio_rint() invoke a filter pipeline. - ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS, AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for AUDIO_GETINFO handle values for a buffer nearest to userland. * add `struct device *' parameter to ac97_attach() * all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
static int
bba_output_conv_fetch_to(stream_fetcher_t *self, audio_stream_t *dst,
int max_used)
{
stream_filter_t *this;
int m, err;
this = (stream_filter_t *)self;
max_used = (max_used + 3) & ~3;
if ((err = this->prev->fetch_to(this->prev, this->src, max_used / 4)))
return err;
m = (dst->end - dst->start) & ~3;
m = min(m, max_used);
FILTER_LOOP_PROLOGUE(this->src, 1, dst, 4, m) {
*(uint32_t *)d = (*s << 16);
} FILTER_LOOP_EPILOGUE(this->src, dst);
return 0;
2000-05-02 10:43:05 +04:00
}
2006-03-30 22:14:37 +04:00
static int
2005-01-15 18:19:51 +03:00
bba_round_blocksize(void *addr, int blk, int mode, const audio_params_t *param)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
return IOASIC_DMA_BLOCKSIZE;
2000-05-02 10:43:05 +04:00
}
/* indirect write */
2006-03-30 22:14:37 +04:00
static void
2005-01-15 18:19:51 +03:00
bba_codec_iwrite(struct am7930_softc *sc, int reg, uint8_t val)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
DPRINTF(("bba_codec_iwrite(): sc=%p, reg=%d, val=%d\n", sc, reg, val));
2000-05-02 10:43:05 +04:00
bba_codec_dwrite(sc, AM7930_DREG_CR, reg);
bba_codec_dwrite(sc, AM7930_DREG_DR, val);
}
2006-03-30 22:14:37 +04:00
static void
2005-01-15 18:19:51 +03:00
bba_codec_iwrite16(struct am7930_softc *sc, int reg, uint16_t val)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
DPRINTF(("bba_codec_iwrite16(): sc=%p, reg=%d, val=%d\n", sc, reg, val));
2000-05-02 10:43:05 +04:00
bba_codec_dwrite(sc, AM7930_DREG_CR, reg);
bba_codec_dwrite(sc, AM7930_DREG_DR, val);
bba_codec_dwrite(sc, AM7930_DREG_DR, val>>8);
}
2006-03-30 22:14:37 +04:00
static uint16_t
2005-01-15 18:19:51 +03:00
bba_codec_iread16(struct am7930_softc *sc, int reg)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
uint16_t val;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
DPRINTF(("bba_codec_iread16(): sc=%p, reg=%d\n", sc, reg));
2000-05-02 10:43:05 +04:00
bba_codec_dwrite(sc, AM7930_DREG_CR, reg);
val = bba_codec_dread(sc, AM7930_DREG_DR) << 8;
val |= bba_codec_dread(sc, AM7930_DREG_DR);
return val;
}
/* indirect read */
2006-03-30 22:14:37 +04:00
static uint8_t
2005-01-15 18:19:51 +03:00
bba_codec_iread(struct am7930_softc *sc, int reg)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
uint8_t val;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
DPRINTF(("bba_codec_iread(): sc=%p, reg=%d\n", sc, reg));
2000-05-02 10:43:05 +04:00
bba_codec_dwrite(sc, AM7930_DREG_CR, reg);
val = bba_codec_dread(sc, AM7930_DREG_DR);
DPRINTF(("read 0x%x (%d)\n", val, val));
return val;
}
/* direct write */
2006-03-30 22:14:37 +04:00
static void
2005-01-15 18:19:51 +03:00
bba_codec_dwrite(struct am7930_softc *asc, int reg, uint8_t val)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
sc = (struct bba_softc *)asc;
DPRINTF(("bba_codec_dwrite(): sc=%p, reg=%d, val=%d\n", sc, reg, val));
2000-05-02 10:43:05 +04:00
#if defined(__alpha__)
bus_space_write_4(sc->sc_bst, sc->sc_codec_bsh,
reg << 2, val << 8);
#else
bus_space_write_4(sc->sc_bst, sc->sc_codec_bsh,
reg << 6, val);
#endif
2000-05-02 10:43:05 +04:00
}
/* direct read */
2006-03-30 22:14:37 +04:00
static uint8_t
2005-01-15 18:19:51 +03:00
bba_codec_dread(struct am7930_softc *asc, int reg)
2000-05-02 10:43:05 +04:00
{
2005-01-15 18:19:51 +03:00
struct bba_softc *sc;
2000-05-02 10:43:05 +04:00
2005-01-15 18:19:51 +03:00
sc = (struct bba_softc *)asc;
DPRINTF(("bba_codec_dread(): sc=%p, reg=%d\n", sc, reg));
2000-05-02 10:43:05 +04:00
#if defined(__alpha__)
return ((bus_space_read_4(sc->sc_bst, sc->sc_codec_bsh,
reg << 2) >> 8) & 0xff);
#else
return (bus_space_read_4(sc->sc_bst, sc->sc_codec_bsh,
reg << 6) & 0xff);
#endif
2000-05-02 10:43:05 +04:00
}