NetBSD/sys/dev/isa/sb.c

284 lines
7.1 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: sb.c,v 1.79 2005/01/10 22:01:37 kent Exp $ */
1994-10-27 07:14:23 +03:00
/*
* Copyright (c) 1991-1993 Regents of the University of California.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
*/
2001-11-13 11:01:09 +03: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: sb.c,v 1.79 2005/01/10 22:01:37 kent Exp $");
2001-11-13 11:01:09 +03:00
#include "midi.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>
1994-03-29 08:35:37 +04:00
#include <sys/device.h>
#include <sys/proc.h>
#include <machine/cpu.h>
1996-05-13 03:51:23 +04:00
#include <machine/intr.h>
#include <machine/bus.h>
#include <sys/audioio.h>
#include <dev/audio_if.h>
#include <dev/midi_if.h>
#include <dev/midi_if.h>
#include <dev/isa/isavar.h>
#include <dev/isa/isadmavar.h>
1995-04-17 19:48:20 +04:00
#include <dev/isa/sbreg.h>
#include <dev/isa/sbvar.h>
#include <dev/isa/sbdspvar.h>
#if NMPU > 0
const struct midi_hw_if sb_midi_hw_if = {
sbdsp_midi_open,
sbdsp_midi_close,
sbdsp_midi_output,
sbdsp_midi_getinfo,
0, /* ioctl */
};
#endif
int sb_getdev __P((void *, struct audio_device *));
/*
* Define our interface to the higher level audio driver.
*/
const struct audio_hw_if sb_hw_if = {
sbdsp_open,
sbdsp_close,
0,
sbdsp_query_encoding,
sbdsp_set_params,
sbdsp_round_blocksize,
0,
0,
0,
0,
0,
sbdsp_halt_output,
sbdsp_halt_input,
sbdsp_speaker_ctl,
sb_getdev,
0,
sbdsp_mixer_set_port,
sbdsp_mixer_get_port,
sbdsp_mixer_query_devinfo,
sb_malloc,
sb_free,
sb_round_buffersize,
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
sb_mappage,
sbdsp_get_props,
sbdsp_trigger_output,
sbdsp_trigger_input,
0,
1994-03-29 08:35:37 +04:00
};
/*
* Probe / attach routines.
*/
int
sbmatch(sc)
struct sbdsp_softc *sc;
{
2003-09-29 07:22:58 +04:00
static const u_char drq_conf[8] = {
0x01, 0x02, -1, 0x08, -1, 0x20, 0x40, 0x80
};
2003-09-29 07:22:58 +04:00
static const u_char irq_conf[11] = {
-1, -1, 0x01, -1, -1, 0x02, -1, 0x04, -1, 0x01, 0x08
1995-03-08 21:27:35 +03:00
};
1997-04-02 07:58:25 +04:00
if (sbdsp_probe(sc) == 0)
1994-03-29 08:35:37 +04:00
return 0;
/*
* Cannot auto-discover DMA channel.
*/
1995-07-07 06:19:48 +04:00
if (ISSBPROCLASS(sc)) {
if (!SBP_DRQ_VALID(sc->sc_drq8)) {
2003-05-03 22:10:37 +04:00
printf("%s: configured DMA chan %d invalid\n",
sc->sc_dev.dv_xname, sc->sc_drq8);
return 0;
}
} else {
if (!SB_DRQ_VALID(sc->sc_drq8)) {
2003-05-03 22:10:37 +04:00
printf("%s: configured DMA chan %d invalid\n",
sc->sc_dev.dv_xname, sc->sc_drq8);
return 0;
}
}
if (0 <= sc->sc_drq16 && sc->sc_drq16 <= 3)
/*
* XXX Some ViBRA16 cards seem to have two 8 bit DMA
* channels. I've no clue how to use them, so ignore
* one of them for now. -- augustss@NetBSD.org
*/
sc->sc_drq16 = -1;
if (ISSB16CLASS(sc)) {
if (sc->sc_drq16 == -1)
sc->sc_drq16 = sc->sc_drq8;
if (!SB16_DRQ_VALID(sc->sc_drq16)) {
2003-05-03 22:10:37 +04:00
printf("%s: configured DMA chan %d invalid\n",
sc->sc_dev.dv_xname, sc->sc_drq16);
return 0;
}
} else
sc->sc_drq16 = sc->sc_drq8;
1995-07-07 06:19:48 +04:00
if (ISSBPROCLASS(sc)) {
if (!SBP_IRQ_VALID(sc->sc_irq)) {
printf("%s: configured irq %d invalid\n",
sc->sc_dev.dv_xname, sc->sc_irq);
return 0;
}
} else {
if (!SB_IRQ_VALID(sc->sc_irq)) {
printf("%s: configured irq %d invalid\n",
sc->sc_dev.dv_xname, sc->sc_irq);
return 0;
}
}
if (ISSB16CLASS(sc) && !(sc->sc_quirks & SB_QUIRK_NO_INIT_DRQ)) {
int w, r;
#if 0
printf("%s: old drq conf %02x\n", sc->sc_dev.dv_xname,
sbdsp_mix_read(sc, SBP_SET_DRQ));
printf("%s: try drq conf %02x\n", sc->sc_dev.dv_xname,
drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
#endif
w = drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8];
sbdsp_mix_write(sc, SBP_SET_DRQ, w);
r = sbdsp_mix_read(sc, SBP_SET_DRQ) & 0xeb;
if (r != w) {
printf("%s: setting drq mask %02x failed, got %02x\n",
sc->sc_dev.dv_xname, w, r);
return 0;
}
#if 0
printf("%s: new drq conf %02x\n", sc->sc_dev.dv_xname,
sbdsp_mix_read(sc, SBP_SET_DRQ));
#endif
#if 0
printf("%s: old irq conf %02x\n", sc->sc_dev.dv_xname,
sbdsp_mix_read(sc, SBP_SET_IRQ));
printf("%s: try irq conf %02x\n", sc->sc_dev.dv_xname,
irq_conf[sc->sc_irq]);
#endif
w = irq_conf[sc->sc_irq];
sbdsp_mix_write(sc, SBP_SET_IRQ, w);
r = sbdsp_mix_read(sc, SBP_SET_IRQ) & 0x0f;
if (r != w) {
printf("%s: setting irq mask %02x failed, got %02x\n",
sc->sc_dev.dv_xname, w, r);
return 0;
}
#if 0
printf("%s: new irq conf %02x\n", sc->sc_dev.dv_xname,
sbdsp_mix_read(sc, SBP_SET_IRQ));
#endif
}
1994-03-29 08:35:37 +04:00
return 1;
}
void
sbattach(sc)
struct sbdsp_softc *sc;
{
struct audio_attach_args arg;
sbdsp_attach(sc);
audio_attach_mi(&sb_hw_if, sc, &sc->sc_dev);
#if NMPU > 0
if (sc->sc_hasmpu) {
arg.type = AUDIODEV_TYPE_MPU;
arg.hwif = 0;
arg.hdl = 0;
sc->sc_mpudev = config_found(&sc->sc_dev, &arg, audioprint);
Several things: * Rearrange the speed mapping table and adjust the code so that the highest rate can actually be used. Previously we ended up rounding up slightly lower speeds and then losing because set_params couldn't set the mode back to the current one. * Allow 260 as a valid I/O address, since the SB1 can be jumpered to this. * Change the MPU-401 code so it can be attached as a separate device. (XXX Really, the SB code ought to just attach a subdevice itself.) * Do not attach an OPL on the SB1. Writing to the OPL registers at SB_base+0 on this card wedges my machine. (XXX Should we access it at 388 instead? The Creative web site claims that this board *does* have an OPL2, but I haven't played with this extensively.) * Allocate the SB DMA channels at open time, rather than attach time, so that a single DRQ can be used for multiple cards (if only one is in use at a given time). (XXX Let me tell you why this is a horrible hack. If the ISA DMA code tries to allocate a bounce buffer after boot time, it will generally fail, because there is no contiguous memory below 16MB and the code to allocate contiguous pages doesn't know how to move things around. Now, we shouldn't ever be using bounce buffers here, because we use isa_dmamem_alloc(). So we just turn off BUS_DMA_ALLOCNOW and we don't actually try to. That's cool, and it even works, but isa_dmamem_alloc() has the same problem. It just happens that we allocate the ring buffers at boot time, and whenever we reallocate them (due to the buffer size changing), we just deallocated the previous (contiguous) buffer, so we get lucky. This is absolutely disgusting and needs to be fixed.)
1999-03-22 10:37:35 +03:00
} else {
midi_attach_mi(&sb_midi_hw_if, sc, &sc->sc_dev);
}
1994-03-29 08:35:37 +04:00
#endif
Several things: * Rearrange the speed mapping table and adjust the code so that the highest rate can actually be used. Previously we ended up rounding up slightly lower speeds and then losing because set_params couldn't set the mode back to the current one. * Allow 260 as a valid I/O address, since the SB1 can be jumpered to this. * Change the MPU-401 code so it can be attached as a separate device. (XXX Really, the SB code ought to just attach a subdevice itself.) * Do not attach an OPL on the SB1. Writing to the OPL registers at SB_base+0 on this card wedges my machine. (XXX Should we access it at 388 instead? The Creative web site claims that this board *does* have an OPL2, but I haven't played with this extensively.) * Allocate the SB DMA channels at open time, rather than attach time, so that a single DRQ can be used for multiple cards (if only one is in use at a given time). (XXX Let me tell you why this is a horrible hack. If the ISA DMA code tries to allocate a bounce buffer after boot time, it will generally fail, because there is no contiguous memory below 16MB and the code to allocate contiguous pages doesn't know how to move things around. Now, we shouldn't ever be using bounce buffers here, because we use isa_dmamem_alloc(). So we just turn off BUS_DMA_ALLOCNOW and we don't actually try to. That's cool, and it even works, but isa_dmamem_alloc() has the same problem. It just happens that we allocate the ring buffers at boot time, and whenever we reallocate them (due to the buffer size changing), we just deallocated the previous (contiguous) buffer, so we get lucky. This is absolutely disgusting and needs to be fixed.)
1999-03-22 10:37:35 +03:00
if (sc->sc_model >= SB_20) {
arg.type = AUDIODEV_TYPE_OPL;
arg.hwif = 0;
arg.hdl = 0;
(void)config_found(&sc->sc_dev, &arg, audioprint);
}
}
/*
* Various routines to interface to higher level audio driver
*/
int
sb_getdev(addr, retp)
void *addr;
struct audio_device *retp;
{
struct sbdsp_softc *sc = addr;
2003-09-29 07:22:58 +04:00
static const char * const names[] = SB_NAMES;
const char *config;
if (sc->sc_model == SB_JAZZ)
2004-04-22 04:17:10 +04:00
strlcpy(retp->name, "MV Jazz16", sizeof(retp->name));
else
2004-04-22 04:17:10 +04:00
strlcpy(retp->name, "SoundBlaster", sizeof(retp->name));
snprintf(retp->version, sizeof(retp->version), "%d.%02d",
SBVER_MAJOR(sc->sc_version), SBVER_MINOR(sc->sc_version));
if (0 <= sc->sc_model && sc->sc_model < sizeof names / sizeof names[0])
config = names[sc->sc_model];
else
config = "??";
2004-04-22 04:17:10 +04:00
strlcpy(retp->config, config, sizeof(retp->config));
1994-03-29 08:35:37 +04:00
return 0;
}