NetBSD/sys/arch/x68k/dev/vs.c

791 lines
19 KiB
C
Raw Normal View History

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
/* $NetBSD: vs.c,v 1.27 2005/01/10 22:01:36 kent Exp $ */
2001-05-02 17:00:19 +04:00
/*
* Copyright (c) 2001 Tetsuya Isaki. 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.
2003-09-07 08:24:05 +04:00
* 3. The name of the author may not be used to endorse or promote products
2001-05-02 17:00:19 +04:00
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* VS - OKI MSM6258 ADPCM voice synthesizer device driver.
*/
2003-07-15 05:44:50 +04:00
#include <sys/cdefs.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
__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.27 2005/01/10 22:01:36 kent Exp $");
2003-07-15 05:44:50 +04:00
2001-05-02 17:00:19 +04:00
#include "audio.h"
#include "vs.h"
#if NAUDIO > 0 && NVS > 0
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#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/mulaw.h>
2001-05-02 17:00:19 +04:00
#include <machine/bus.h>
#include <machine/cpu.h>
#include <dev/ic/msm6258var.h>
#include <arch/x68k/dev/dmacvar.h>
#include <arch/x68k/dev/intiovar.h>
#include <arch/x68k/dev/opmvar.h>
2001-05-02 17:00:19 +04:00
#include <arch/x68k/dev/vsvar.h>
#ifdef VS_DEBUG
#define DPRINTF(y,x) if(vs_debug>=(y))printf x
static int vs_debug;
2001-05-02 17:00:19 +04:00
#ifdef AUDIO_DEBUG
extern int audiodebug;
#endif
#else
#define DPRINTF(y,x)
2001-05-02 17:00:19 +04:00
#endif
static int vs_match __P((struct device *, struct cfdata *, void *));
static void vs_attach __P((struct device *, struct device *, void *));
static int vs_dmaintr __P((void *));
static int vs_dmaerrintr __P((void *));
/* MI audio layer interface */
static int vs_open __P((void *, int));
static void vs_close __P((void *));
static int vs_query_encoding __P((void *, struct audio_encoding *));
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 vs_set_params __P((void *, int, int, audio_params_t *,
audio_params_t *, stream_filter_list_t *, stream_filter_list_t *));
2001-05-02 17:00:19 +04:00
static int vs_trigger_output __P((void *, void *, void *, int,
void (*)(void *), void *,
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
const audio_params_t *));
2001-05-02 17:00:19 +04:00
static int vs_trigger_input __P((void *, void *, void *, int,
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
void (*)(void *), void *,
const audio_params_t *));
2001-05-02 17:00:19 +04:00
static int vs_halt_output __P((void *));
static int vs_halt_input __P((void *));
static int vs_allocmem __P((struct vs_softc *, size_t, size_t, size_t, int,
struct vs_dma *));
static void vs_freemem __P((struct vs_dma *));
static int vs_getdev __P((void *, struct audio_device *));
static int vs_set_port __P((void *, mixer_ctrl_t *));
static int vs_get_port __P((void *, mixer_ctrl_t *));
static int vs_query_devinfo __P((void *, mixer_devinfo_t *));
static void *vs_allocm __P((void *, int, size_t, struct malloc_type *, int));
static void vs_freem __P((void *, void *, struct malloc_type *));
2001-05-02 17:00:19 +04:00
static size_t vs_round_buffersize __P((void *, int, size_t));
static int vs_get_props __P((void *));
/* lower functions */
2001-05-03 06:09:11 +04:00
static int vs_round_sr(u_long);
static void vs_set_sr(struct vs_softc *sc, int);
2001-05-02 17:00:19 +04:00
static inline void vs_set_po(struct vs_softc *sc, u_long);
2002-11-24 16:33:45 +03:00
extern struct cfdriver vs_cd;
2001-05-02 17:00:19 +04:00
2002-10-01 08:43:01 +04:00
CFATTACH_DECL(vs, sizeof(struct vs_softc),
2002-10-02 20:02:08 +04:00
vs_match, vs_attach, NULL, NULL);
2001-05-02 17:00:19 +04:00
static int vs_attached;
static const struct audio_hw_if vs_hw_if = {
2001-05-02 17:00:19 +04:00
vs_open,
vs_close,
NULL, /* drain */
vs_query_encoding,
vs_set_params,
NULL, /* round_blocksize */
NULL, /* commit_settings */
NULL, /* init_output */
NULL, /* init_input */
NULL, /* start_output */
NULL, /* start_input */
vs_halt_output,
vs_halt_input,
NULL, /* speaker_ctl */
vs_getdev,
NULL, /* setfd */
vs_set_port,
vs_get_port,
vs_query_devinfo,
vs_allocm,
vs_freem,
vs_round_buffersize,
NULL, /* mappage */
vs_get_props,
vs_trigger_output,
vs_trigger_input,
NULL,
2001-05-02 17:00:19 +04:00
};
static struct audio_device vs_device = {
"OKI MSM6258",
"",
"vs"
};
struct {
u_long rate;
u_char clk;
u_char den;
} vs_l2r[] = {
2001-05-03 06:09:11 +04:00
{ VS_RATE_15K, VS_CLK_8MHZ, VS_SRATE_512 },
{ VS_RATE_10K, VS_CLK_8MHZ, VS_SRATE_768 },
{ VS_RATE_7K, VS_CLK_8MHZ, VS_SRATE_1024},
{ VS_RATE_5K, VS_CLK_4MHZ, VS_SRATE_768 },
{ VS_RATE_3K, VS_CLK_4MHZ, VS_SRATE_1024}
2001-05-02 17:00:19 +04:00
};
2001-05-03 06:09:11 +04:00
#define NUM_RATE (sizeof(vs_l2r)/sizeof(vs_l2r[0]))
2001-05-02 17:00:19 +04:00
struct {
char *name;
int encoding;
int precision;
} vs_encodings[] = {
{AudioEadpcm, AUDIO_ENCODING_ADPCM, 4},
{AudioEslinear, AUDIO_ENCODING_SLINEAR, 8},
{AudioEulinear, AUDIO_ENCODING_ULINEAR, 8},
{AudioEmulaw, AUDIO_ENCODING_ULAW, 8},
{AudioEslinear_be, AUDIO_ENCODING_SLINEAR_BE, 16},
{AudioEslinear_le, AUDIO_ENCODING_SLINEAR_LE, 16},
};
2001-05-02 17:00:19 +04:00
static int
vs_match(struct device *parent, struct cfdata *cf, void *aux)
{
struct intio_attach_args *ia = aux;
if (strcmp(ia->ia_name, "vs") || vs_attached)
2001-05-02 17:00:19 +04:00
return 0;
if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
ia->ia_addr = VS_ADDR;
if (ia->ia_dma == INTIOCF_DMA_DEFAULT)
ia->ia_dma = VS_DMA;
if (ia->ia_dmaintr == INTIOCF_DMAINTR_DEFAULT)
ia->ia_dmaintr = VS_DMAINTR;
/* fixed parameters */
if (ia->ia_addr != VS_ADDR)
return 0;
if (ia->ia_dma != VS_DMA)
return 0;
if (ia->ia_dmaintr != VS_DMAINTR)
return 0;
#ifdef VS_DEBUG
vs_debug = 1;
2001-05-02 17:00:19 +04:00
#ifdef AUDIO_DEBUG
audiodebug = 2;
#endif
2001-05-02 17:00:19 +04:00
#endif
return 1;
}
static void
vs_attach(struct device *parent, struct device *self, void *aux)
{
struct vs_softc *sc = (struct vs_softc *)self;
bus_space_tag_t iot;
bus_space_handle_t ioh;
struct intio_attach_args *ia = aux;
vs_attached = 1;
2001-05-02 17:00:19 +04:00
printf("\n");
/* Re-map the I/O space */
iot = ia->ia_bst;
bus_space_map(iot, ia->ia_addr, 0x2000, BUS_SPACE_MAP_SHIFTED, &ioh);
/* Initialize sc */
sc->sc_iot = iot;
sc->sc_ioh = ioh;
sc->sc_hw_if = &vs_hw_if;
sc->sc_addr = (caddr_t) ia->ia_addr;
sc->sc_dmas = NULL;
/* XXX */
bus_space_map(iot, PPI_ADDR, PPI_MAPSIZE, BUS_SPACE_MAP_SHIFTED,
&sc->sc_ppi);
/* Initialize DMAC */
sc->sc_dmat = ia->ia_dmat;
sc->sc_dma_ch = dmac_alloc_channel(parent, ia->ia_dma, "vs",
ia->ia_dmaintr, vs_dmaintr, sc,
ia->ia_dmaintr+1, vs_dmaerrintr, sc);
printf("%s: MSM6258V ADPCM voice synthesizer\n", sc->sc_dev.dv_xname);
audio_attach_mi(&vs_hw_if, sc, &sc->sc_dev);
}
/*
* vs interrupt handler
*/
static int
vs_dmaintr(void *hdl)
{
struct vs_softc *sc = hdl;
DPRINTF(2, ("vs_dmaintr\n"));
2001-05-02 17:00:19 +04:00
if (sc->sc_pintr) {
/* start next transfer */
2001-05-03 06:09:11 +04:00
sc->sc_current.dmap += sc->sc_current.blksize;
if (sc->sc_current.dmap + sc->sc_current.blksize
2002-10-13 14:00:08 +04:00
> sc->sc_current.bufsize)
2001-05-02 17:00:19 +04:00
sc->sc_current.dmap -= sc->sc_current.bufsize;
2002-10-13 14:00:08 +04:00
dmac_start_xfer_offset(sc->sc_dma_ch->ch_softc,
2001-05-02 17:00:19 +04:00
sc->sc_current.xfer,
sc->sc_current.dmap,
2001-05-03 06:09:11 +04:00
sc->sc_current.blksize);
2001-05-02 17:00:19 +04:00
sc->sc_pintr(sc->sc_parg);
} else if (sc->sc_rintr) {
/* start next transfer */
2001-05-03 06:09:11 +04:00
sc->sc_current.dmap += sc->sc_current.blksize;
if (sc->sc_current.dmap + sc->sc_current.blksize
2002-10-13 14:00:08 +04:00
> sc->sc_current.bufsize)
sc->sc_current.dmap -= sc->sc_current.bufsize;
2002-10-13 14:00:08 +04:00
dmac_start_xfer_offset(sc->sc_dma_ch->ch_softc,
2001-05-02 17:00:19 +04:00
sc->sc_current.xfer,
sc->sc_current.dmap,
2001-05-03 06:09:11 +04:00
sc->sc_current.blksize);
2001-05-02 17:00:19 +04:00
sc->sc_rintr(sc->sc_rarg);
} else {
2002-10-13 14:00:08 +04:00
printf("vs_dmaintr: spurious interrupt\n");
2001-05-02 17:00:19 +04:00
}
return 1;
}
static int
vs_dmaerrintr(void *hdl)
{
struct vs_softc *sc = hdl;
DPRINTF(1, ("%s: DMA transfer error.\n", sc->sc_dev.dv_xname));
2001-05-02 17:00:19 +04:00
/* XXX */
vs_dmaintr(sc);
2001-05-02 17:00:19 +04:00
return 1;
}
/*
* audio MD layer interfaces
*/
static int
vs_open(void *hdl, int flags)
{
struct vs_softc *sc = hdl;
DPRINTF(1, ("vs_open: flags=%d\n", flags));
2001-05-02 17:00:19 +04:00
sc->sc_pintr = NULL;
sc->sc_rintr = NULL;
return 0;
}
static void
vs_close(void *hdl)
{
DPRINTF(1, ("vs_close\n"));
2001-05-02 17:00:19 +04:00
}
static int
vs_query_encoding(void *hdl, struct audio_encoding *fp)
{
DPRINTF(1, ("vs_query_encoding\n"));
if (fp->index >= sizeof(vs_encodings) / sizeof(vs_encodings[0]))
2001-05-02 17:00:19 +04:00
return EINVAL;
strcpy(fp->name, vs_encodings[fp->index].name);
fp->encoding = vs_encodings[fp->index].encoding;
fp->precision = vs_encodings[fp->index].precision;
if (fp->encoding == AUDIO_ENCODING_ADPCM)
fp->flags = 0;
else
fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
2001-05-02 17:00:19 +04:00
return 0;
}
2001-05-03 06:09:11 +04:00
static int
2001-05-02 17:00:19 +04:00
vs_round_sr(u_long rate)
{
int i;
2001-05-03 06:09:11 +04:00
int diff = rate;
int nearest = 0;
for (i = 0; i < NUM_RATE; i++) {
if (rate >= vs_l2r[i].rate) {
if (rate - vs_l2r[i].rate < diff) {
diff = rate - vs_l2r[i].rate;
nearest = i;
}
} else {
if (vs_l2r[i].rate - rate < diff) {
diff = vs_l2r[i].rate - rate;
nearest = i;
}
}
2001-05-02 17:00:19 +04:00
}
2001-05-03 06:09:11 +04:00
if (diff * 100 / rate > 15)
return -1;
else
return nearest;
2001-05-02 17:00:19 +04:00
}
static int
vs_set_params(void *hdl, int setmode, int usemode,
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
audio_params_t *play, audio_params_t *rec,
stream_filter_list_t *pfil, stream_filter_list_t *rfil)
2001-05-02 17:00:19 +04:00
{
struct vs_softc *sc = hdl;
struct audio_params *p;
int mode;
2001-05-03 06:09:11 +04:00
int rate;
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_factory_t *pswcode;
stream_filter_factory_t *rswcode;
audio_params_t hw;
int matched;
2001-05-02 17:00:19 +04:00
2002-10-13 14:00:08 +04:00
DPRINTF(1, ("vs_set_params: setmode=%d, usemode=%d\n",
setmode, usemode));
2001-05-02 17:00:19 +04:00
/* set first record info, then play info */
for (mode = AUMODE_RECORD; mode != -1;
mode = (mode == AUMODE_RECORD) ? AUMODE_PLAY : -1) {
if ((setmode & mode) == 0)
continue;
p = (mode == AUMODE_PLAY) ? play : rec;
if (p->channels != 1)
return (EINVAL);
2001-05-03 06:09:11 +04:00
rate = p->sample_rate;
pswcode = NULL;
rswcode = NULL;
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
hw = *p;
hw.encoding = AUDIO_ENCODING_ADPCM;
hw.precision = hw.validbits = 4;
DPRINTF(1, ("vs_set_params: encoding=%d, precision=%d\n",
p->encoding, p->precision));
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
matched = 0;
switch (p->precision) {
case 4:
if (p->encoding == AUDIO_ENCODING_ADPCM)
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
matched = 1;
2001-05-02 17:00:19 +04:00
break;
case 8:
switch (p->encoding) {
case AUDIO_ENCODING_ULAW:
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
matched = 1;
hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
hw.precision = hw.validbits = 8;
pfil->prepend(pfil, mulaw_to_linear8, &hw);
hw.encoding = AUDIO_ENCODING_ADPCM;
hw.precision = hw.validbits = 4;
pfil->prepend(pfil, msm6258_linear8_to_adpcm, &hw);
rfil->append(rfil, msm6258_adpcm_to_linear8, &hw);
hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
hw.precision = hw.validbits = 8;
rfil->append(rfil, linear8_to_mulaw, &hw);
break;
case AUDIO_ENCODING_SLINEAR:
case AUDIO_ENCODING_SLINEAR_LE:
case AUDIO_ENCODING_SLINEAR_BE:
case AUDIO_ENCODING_ULINEAR:
case AUDIO_ENCODING_ULINEAR_LE:
case AUDIO_ENCODING_ULINEAR_BE:
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
matched = 1;
pfil->append(pfil, msm6258_linear8_to_adpcm, &hw);
rfil->append(rfil, msm6258_adpcm_to_linear8, &hw);
break;
}
2001-05-02 17:00:19 +04:00
break;
case 16:
switch (p->encoding) {
case AUDIO_ENCODING_SLINEAR_LE:
case AUDIO_ENCODING_SLINEAR_BE:
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
matched = 1;
pfil->append(pfil, msm6258_slinear16_to_adpcm, &hw);
rfil->append(rfil, msm6258_adpcm_to_slinear16, &hw);
break;
}
2001-05-02 17:00:19 +04:00
break;
}
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
if (matched == 0) {
DPRINTF(1, ("vs_set_params: mode=%d, encoding=%d\n",
2001-05-02 17:00:19 +04:00
mode, p->encoding));
return EINVAL;
2001-05-02 17:00:19 +04:00
}
DPRINTF(1, ("vs_set_params: rate=%d -> ", rate));
2001-05-03 06:09:11 +04:00
rate = vs_round_sr(rate);
DPRINTF(1, ("%d\n", rate));
2001-05-03 06:09:11 +04:00
if (rate < 0)
return (EINVAL);
if (mode == AUMODE_PLAY) {
2001-05-03 06:09:11 +04:00
sc->sc_current.prate = rate;
} else {
2001-05-03 06:09:11 +04:00
sc->sc_current.rrate = rate;
}
2001-05-02 17:00:19 +04:00
}
return 0;
}
static void
2001-05-03 06:09:11 +04:00
vs_set_sr(struct vs_softc *sc, int rate)
2001-05-02 17:00:19 +04:00
{
DPRINTF(1, ("setting sample rate to %d, %d\n",
2001-05-03 06:09:11 +04:00
rate, (int)vs_l2r[rate].rate));
bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
(bus_space_read_1 (sc->sc_iot, sc->sc_ppi,
PPI_PORTC) & 0xf0)
| vs_l2r[rate].den);
adpcm_chgclk(vs_l2r[rate].clk);
2001-05-02 17:00:19 +04:00
}
static inline void
vs_set_po(struct vs_softc *sc, u_long po)
{
bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
(bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC)
& 0xfc) | po);
}
static int
vs_trigger_output(void *hdl, void *start, void *end, int bsize,
void (*intr)(void *), void *arg,
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
const audio_params_t *p)
2001-05-02 17:00:19 +04:00
{
struct vs_softc *sc = hdl;
struct vs_dma *vd;
struct dmac_dma_xfer *xf;
struct dmac_channel_stat *chan = sc->sc_dma_ch;
DPRINTF(2, ("vs_trigger_output: start=%p, bsize=%d, intr=%p, arg=%p\n",
2001-05-02 17:00:19 +04:00
start, bsize, intr, arg));
sc->sc_pintr = intr;
sc->sc_parg = arg;
2001-05-03 06:09:11 +04:00
sc->sc_current.blksize = bsize;
2001-05-02 17:00:19 +04:00
sc->sc_current.bufsize = (char*)end - (char*)start;
sc->sc_current.dmap = 0;
/* Find DMA buffer. */
for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
vd = vd->vd_next)
;
if (vd == NULL) {
printf("%s: trigger_output: bad addr %p\n",
sc->sc_dev.dv_xname, start);
return (EINVAL);
}
2001-05-03 06:09:11 +04:00
vs_set_sr(sc, sc->sc_current.prate);
2001-05-02 17:00:19 +04:00
vs_set_po(sc, VS_PANOUT_LR);
2001-05-03 06:09:11 +04:00
2002-10-13 14:00:08 +04:00
xf = dmac_alloc_xfer(chan, sc->sc_dmat, vd->vd_map);
2001-05-02 17:00:19 +04:00
sc->sc_current.xfer = xf;
chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
DMAC_DCR_OPS_8BIT);
chan->ch_ocr = DMAC_OCR_REQG_EXTERNAL;
xf->dx_ocr = DMAC_OCR_DIR_MTD;
xf->dx_scr = DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT;
xf->dx_device = sc->sc_addr + MSM6258_DATA*2 + 1;
2001-05-03 06:09:11 +04:00
2002-10-13 14:00:08 +04:00
dmac_load_xfer(chan->ch_softc, xf);
dmac_start_xfer_offset(chan->ch_softc, xf, 0, sc->sc_current.blksize);
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 2);
2001-05-02 17:00:19 +04:00
return 0;
}
static int
vs_trigger_input(void *hdl, void *start, void *end, int bsize,
void (*intr)(void *), void *arg,
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
const audio_params_t *p)
2001-05-02 17:00:19 +04:00
{
struct vs_softc *sc = hdl;
struct vs_dma *vd;
2001-05-03 06:09:11 +04:00
struct dmac_dma_xfer *xf;
struct dmac_channel_stat *chan = sc->sc_dma_ch;
2001-05-02 17:00:19 +04:00
DPRINTF(2, ("vs_trigger_input: start=%p, bsize=%d, intr=%p, arg=%p\n",
2001-05-02 17:00:19 +04:00
start, bsize, intr, arg));
sc->sc_rintr = intr;
sc->sc_rarg = arg;
2001-05-03 06:09:11 +04:00
sc->sc_current.blksize = bsize;
2001-05-02 17:00:19 +04:00
sc->sc_current.bufsize = (char*)end - (char*)start;
sc->sc_current.dmap = 0;
/* Find DMA buffer. */
for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
vd = vd->vd_next)
;
if (vd == NULL) {
printf("%s: trigger_output: bad addr %p\n",
sc->sc_dev.dv_xname, start);
return (EINVAL);
}
2001-05-03 06:09:11 +04:00
vs_set_sr(sc, sc->sc_current.rrate);
2002-10-13 14:00:08 +04:00
xf = dmac_alloc_xfer(chan, sc->sc_dmat, vd->vd_map);
2001-05-03 06:09:11 +04:00
sc->sc_current.xfer = xf;
chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
DMAC_DCR_OPS_8BIT);
chan->ch_ocr = DMAC_OCR_REQG_EXTERNAL;
xf->dx_ocr = DMAC_OCR_DIR_DTM;
xf->dx_scr = DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT;
xf->dx_device = sc->sc_addr + MSM6258_DATA*2 + 1;
2002-10-13 14:00:08 +04:00
dmac_load_xfer(chan->ch_softc, xf);
dmac_start_xfer_offset(chan->ch_softc, xf, 0, sc->sc_current.blksize);
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 4);
2001-05-02 17:00:19 +04:00
return 0;
}
static int
vs_halt_output(void *hdl)
{
struct vs_softc *sc = hdl;
DPRINTF(1, ("vs_halt_output\n"));
2001-05-02 17:00:19 +04:00
/* stop ADPCM play */
dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
2002-10-13 14:00:08 +04:00
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
2001-05-02 17:00:19 +04:00
return 0;
}
static int
vs_halt_input(void *hdl)
{
struct vs_softc *sc = hdl;
DPRINTF(1, ("vs_halt_input\n"));
2001-05-02 17:00:19 +04:00
/* stop ADPCM recoding */
dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
2002-10-13 14:00:08 +04:00
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
2001-05-02 17:00:19 +04:00
return 0;
}
static int
2002-10-13 14:00:08 +04:00
vs_allocmem(struct vs_softc *sc, size_t size, size_t align, size_t boundary,
int flags, struct vs_dma *vd)
2001-05-02 17:00:19 +04:00
{
int error, wait;
#ifdef DIAGNOSTIC
if (size > DMAC_MAXSEGSZ)
panic ("vs_allocmem: maximum size exceeded, %d", (int) size);
#endif
wait = (flags & M_NOWAIT) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
vd->vd_size = size;
error = bus_dmamem_alloc(vd->vd_dmat, vd->vd_size, align, boundary,
vd->vd_segs,
sizeof (vd->vd_segs) / sizeof (vd->vd_segs[0]),
&vd->vd_nsegs, wait);
if (error)
goto out;
error = bus_dmamem_map(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs,
vd->vd_size, &vd->vd_addr,
wait | BUS_DMA_COHERENT);
if (error)
goto free;
error = bus_dmamap_create(vd->vd_dmat, vd->vd_size, 1, DMAC_MAXSEGSZ,
0, wait, &vd->vd_map);
if (error)
goto unmap;
error = bus_dmamap_load(vd->vd_dmat, vd->vd_map, vd->vd_addr,
vd->vd_size, NULL, wait);
if (error)
goto destroy;
return (0);
destroy:
bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
unmap:
bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
free:
bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
out:
return (error);
}
static void
2002-10-13 14:00:08 +04:00
vs_freemem(struct vs_dma *vd)
2001-05-02 17:00:19 +04:00
{
bus_dmamap_unload(vd->vd_dmat, vd->vd_map);
bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
}
static int
vs_getdev(void *hdl, struct audio_device *retp)
{
DPRINTF(1, ("vs_getdev\n"));
2001-05-02 17:00:19 +04:00
*retp = vs_device;
return 0;
}
static int
vs_set_port(void *hdl, mixer_ctrl_t *cp)
{
DPRINTF(1, ("vs_set_port\n"));
2001-05-02 17:00:19 +04:00
return 0;
}
static int
vs_get_port(void *hdl, mixer_ctrl_t *cp)
{
DPRINTF(1, ("vs_get_port\n"));
2001-05-02 17:00:19 +04:00
return 0;
}
static int
vs_query_devinfo(void *hdl, mixer_devinfo_t *mi)
{
DPRINTF(1, ("vs_query_devinfo\n"));
2001-05-02 17:00:19 +04:00
switch (mi->index) {
default:
return EINVAL;
}
return 0;
}
static void *
vs_allocm(void *hdl, int direction, size_t size, struct malloc_type *type,
int flags)
2001-05-02 17:00:19 +04:00
{
struct vs_softc *sc = hdl;
struct vs_dma *vd;
int error;
if ((vd = malloc(size, type, flags)) == NULL)
return (NULL);
vd->vd_dmat = sc->sc_dmat;
error = vs_allocmem(sc, size, 32, 0, flags, vd);
if (error) {
free(vd, type);
return (NULL);
}
vd->vd_next = sc->sc_dmas;
sc->sc_dmas = vd;
return (KVADDR(vd));
}
static void
vs_freem(void *hdl, void *addr, struct malloc_type *type)
2001-05-02 17:00:19 +04:00
{
struct vs_softc *sc = hdl;
struct vs_dma *p, **pp;
for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->vd_next) {
if (KVADDR(p) == addr) {
vs_freemem(p);
*pp = p->vd_next;
free(p, type);
return;
}
}
}
static size_t
vs_round_buffersize(void *hdl, int direction, size_t bufsize)
{
if (bufsize > DMAC_MAXSEGSZ)
bufsize = DMAC_MAXSEGSZ;
return bufsize;
}
#if 0
paddr_t
2002-10-13 14:00:08 +04:00
vs_mappage(void *addr, void *mem, off_t off, int prot)
2001-05-02 17:00:19 +04:00
{
struct vs_softc *sc = addr;
struct vs_dma *p;
if (off < 0)
return (-1);
for (p = sc->sc_dmas; p != NULL && KVADDR(p) != mem;
p = p->vd_next)
;
if (p == NULL) {
printf("%s: mappage: bad addr %p\n",
sc->sc_dev.dv_xname, start);
return (-1);
}
return (bus_dmamem_mmap(sc->sc_dmat, p->vd_segs, p->vd_nsegs,
off, prot, BUS_DMA_WAITOK));
}
#endif
static int
vs_get_props(void *hdl)
{
DPRINTF(1, ("vs_get_props\n"));
2001-05-02 17:00:19 +04:00
return 0 /* | dependent | half duplex | no mmap */;
}
#endif /* NAUDIO > 0 && NVS > 0*/