vidcaudio.c revision 1.45.2.1       1 /*	$NetBSD: vidcaudio.c,v 1.45.2.1 2007/02/27 14:15:52 ad Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Melvin Tang-Richardson
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by the RiscBSD team.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*-
     33  * Copyright (c) 2003 Ben Harris
     34  * All rights reserved.
     35  *
     36  * Redistribution and use in source and binary forms, with or without
     37  * modification, are permitted provided that the following conditions
     38  * are met:
     39  * 1. Redistributions of source code must retain the above copyright
     40  *    notice, this list of conditions and the following disclaimer.
     41  * 2. Redistributions in binary form must reproduce the above copyright
     42  *    notice, this list of conditions and the following disclaimer in the
     43  *    documentation and/or other materials provided with the distribution.
     44  * 3. The name of the author may not be used to endorse or promote products
     45  *    derived from this software without specific prior written permission.
     46  *
     47  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     48  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     49  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     50  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     51  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     52  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     53  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     54  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     55  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     56  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     57  */
     58 
     59 /*
     60  * audio driver for the RiscPC 8/16 bit sound
     61  *
     62  * Interfaces with the NetBSD generic audio driver to provide SUN
     63  * /dev/audio (partial) compatibility.
     64  */
     65 
     66 #include <sys/param.h>	/* proc.h */
     67 
     68 __KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.45.2.1 2007/02/27 14:15:52 ad Exp $");
     69 
     70 #include <sys/audioio.h>
     71 #include <sys/conf.h>   /* autoconfig functions */
     72 #include <sys/device.h> /* device calls */
     73 #include <sys/errno.h>
     74 #include <sys/malloc.h>
     75 #include <sys/proc.h>	/* device calls */
     76 #include <sys/systm.h>
     77 
     78 #include <uvm/uvm_extern.h>
     79 
     80 #include <dev/audio_if.h>
     81 #include <dev/audiobellvar.h>
     82 #include <dev/auconv.h>
     83 #include <dev/mulaw.h>
     84 
     85 #include <machine/intr.h>
     86 #include <machine/machdep.h>
     87 #include <arm/arm32/katelib.h>
     88 
     89 #include <arm/iomd/vidcaudiovar.h>
     90 #include <arm/iomd/iomdreg.h>
     91 #include <arm/iomd/iomdvar.h>
     92 #include <arm/iomd/vidc.h>
     93 #include <arm/mainbus/mainbus.h>
     94 
     95 #include "pckbd.h"
     96 #if NPCKBD > 0
     97 #include <dev/pckbport/pckbdvar.h>
     98 #endif
     99 
    100 extern int *vidc_base;
    101 
    102 #ifdef VIDCAUDIO_DEBUG
    103 #define DPRINTF(x)	printf x
    104 #else
    105 #define DPRINTF(x)
    106 #endif
    107 
    108 struct vidcaudio_softc {
    109 	struct	device sc_dev;
    110 
    111 	irqhandler_t	sc_ih;
    112 	int	sc_dma_intr;
    113 	kmutex_t	sc_lock;
    114 
    115 	int	sc_is16bit;
    116 
    117 	size_t	sc_pblksize;
    118 	vm_offset_t	sc_poffset;
    119 	vm_offset_t	sc_pbufsize;
    120 	paddr_t	*sc_ppages;
    121 	void	(*sc_pintr)(void *);
    122 	void	*sc_parg;
    123 	int	sc_pcountdown;
    124 };
    125 
    126 static int  vidcaudio_probe(struct device *, struct cfdata *, void *);
    127 static void vidcaudio_attach(struct device *, struct device *, void *);
    128 static void vidcaudio_close(void *);
    129 
    130 static int vidcaudio_intr(void *);
    131 static void vidcaudio_rate(int);
    132 static void vidcaudio_ctrl(int);
    133 static void vidcaudio_stereo(int, int);
    134 static stream_filter_factory_t mulaw_to_vidc;
    135 static stream_filter_factory_t mulaw_to_vidc_stereo;
    136 static int mulaw_to_vidc_fetch_to(stream_fetcher_t *, audio_stream_t *, int);
    137 static int mulaw_to_vidc_stereo_fetch_to(stream_fetcher_t *,
    138     audio_stream_t *, int);
    139 
    140 CFATTACH_DECL(vidcaudio, sizeof(struct vidcaudio_softc),
    141     vidcaudio_probe, vidcaudio_attach, NULL, NULL);
    142 
    143 static int    vidcaudio_query_encoding(void *, struct audio_encoding *);
    144 static int    vidcaudio_set_params(void *, int, int, audio_params_t *,
    145     audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
    146 static int    vidcaudio_round_blocksize(void *, int, int, const audio_params_t *);
    147 static int    vidcaudio_trigger_output(void *, void *, void *, int,
    148     void (*)(void *), void *, const audio_params_t *);
    149 static int    vidcaudio_trigger_input(void *, void *, void *, int,
    150     void (*)(void *), void *, const audio_params_t *);
    151 static int    vidcaudio_halt_output(void *);
    152 static int    vidcaudio_halt_input(void *);
    153 static int    vidcaudio_getdev(void *, struct audio_device *);
    154 static int    vidcaudio_set_port(void *, mixer_ctrl_t *);
    155 static int    vidcaudio_get_port(void *, mixer_ctrl_t *);
    156 static int    vidcaudio_query_devinfo(void *, mixer_devinfo_t *);
    157 static int    vidcaudio_get_props(void *);
    158 
    159 static struct audio_device vidcaudio_device = {
    160 	"ARM VIDC",
    161 	"",
    162 	"vidcaudio"
    163 };
    164 
    165 static const struct audio_hw_if vidcaudio_hw_if = {
    166 	NULL,			/* open */
    167 	vidcaudio_close,
    168 	NULL,
    169 	vidcaudio_query_encoding,
    170 	vidcaudio_set_params,
    171 	vidcaudio_round_blocksize,
    172 	NULL,
    173 	NULL,
    174 	NULL,
    175 	NULL,
    176 	NULL,
    177 	vidcaudio_halt_output,
    178 	vidcaudio_halt_input,
    179 	NULL,
    180 	vidcaudio_getdev,
    181 	NULL,
    182 	vidcaudio_set_port,
    183 	vidcaudio_get_port,
    184 	vidcaudio_query_devinfo,
    185 	NULL,
    186 	NULL,
    187 	NULL,
    188 	NULL,
    189 	vidcaudio_get_props,
    190 	vidcaudio_trigger_output,
    191 	vidcaudio_trigger_input,
    192 	NULL,
    193 	vidcaudio_get_lock,
    194 };
    195 
    196 static int
    197 vidcaudio_probe(struct device *parent, struct cfdata *cf, void *aux)
    198 {
    199 	int id;
    200 
    201 	id = IOMD_ID;
    202 
    203 	/* So far I only know about this IOMD */
    204 	switch (id) {
    205 	case RPC600_IOMD_ID:
    206 	case ARM7500_IOC_ID:
    207 	case ARM7500FE_IOC_ID:
    208 		return 1;
    209 	default:
    210 		aprint_error("vidcaudio: Unknown IOMD id=%04x", id);
    211 		return 0;
    212 	}
    213 }
    214 
    215 
    216 static void
    217 vidcaudio_attach(struct device *parent, struct device *self, void *aux)
    218 {
    219 	struct vidcaudio_softc *sc;
    220 	struct device *beepdev;
    221 
    222 	sc  = (void *)self;
    223 	switch (IOMD_ID) {
    224 #ifndef EB7500ATX
    225 	case RPC600_IOMD_ID:
    226 		sc->sc_is16bit = (cmos_read(0xc4) >> 5) & 1;
    227 		sc->sc_dma_intr = IRQ_DMASCH0;
    228 		break;
    229 #endif
    230 	case ARM7500_IOC_ID:
    231 	case ARM7500FE_IOC_ID:
    232 		sc->sc_is16bit = true;
    233 		sc->sc_dma_intr = IRQ_SDMA;
    234 		break;
    235 	default:
    236 		aprint_error(": strange IOMD\n");
    237 		return;
    238 	}
    239 
    240 	if (sc->sc_is16bit)
    241 		aprint_normal(": 16-bit external DAC\n");
    242 	else
    243 		aprint_normal(": 8-bit internal DAC\n");
    244 
    245 	mutex_init(&sc->sc_lock, MUTEX_DRIVER, IPL_AUDIO);
    246 
    247 	/* Install the irq handler for the DMA interrupt */
    248 	sc->sc_ih.ih_func = vidcaudio_intr;
    249 	sc->sc_ih.ih_arg = sc;
    250 	sc->sc_ih.ih_level = IPL_AUDIO;
    251 	sc->sc_ih.ih_name = self->dv_xname;
    252 
    253 	if (irq_claim(sc->sc_dma_intr, &sc->sc_ih) != 0) {
    254 		aprint_error("%s: couldn't claim IRQ %d\n",
    255 		    self->dv_xname, sc->sc_dma_intr);
    256 		return;
    257 	}
    258 
    259 	disable_irq(sc->sc_dma_intr);
    260 
    261 	beepdev = audio_attach_mi(&vidcaudio_hw_if, sc, self);
    262 #if NPCKBD > 0
    263 	pckbd_hookup_bell(audiobell, beepdev);
    264 #endif
    265 }
    266 
    267 static void
    268 vidcaudio_close(void *addr)
    269 {
    270 	struct vidcaudio_softc *sc;
    271 	void *p;
    272 
    273 	DPRINTF(("DEBUG: vidcaudio_close called\n"));
    274 	sc = addr;
    275 	/*
    276 	 * We do this here rather than in vidcaudio_halt_output()
    277 	 * because the latter can be called from interrupt context
    278 	 * (audio_pint()->audio_clear()->vidcaudio_halt_output()).
    279 	 */
    280 	if (sc->sc_ppages != NULL) {
    281 		p = sc->sc_ppages;
    282 		sc->sc_ppages = NULL;
    283 		mutex_exit(&sc->sc_lock);
    284 		free(p, M_DEVBUF);
    285 		mutex_exit(&sc->sc_lock);
    286 	}
    287 }
    288 
    289 /*
    290  * Interface to the generic audio driver
    291  */
    292 
    293 static int
    294 vidcaudio_query_encoding(void *addr, struct audio_encoding *fp)
    295 {
    296 	struct vidcaudio_softc *sc;
    297 
    298 	sc = addr;
    299 	switch (fp->index) {
    300 	case 0:
    301 		strcpy(fp->name, AudioEmulaw);
    302 		fp->encoding = AUDIO_ENCODING_ULAW;
    303 		fp->precision = 8;
    304 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    305 		break;
    306 
    307 	case 1:
    308 		if (sc->sc_is16bit) {
    309 			strcpy(fp->name, AudioEslinear_le);
    310 			fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
    311 			fp->precision = 16;
    312 			fp->flags = 0;
    313 			break;
    314 		}
    315 		/* FALLTHROUGH */
    316 	default:
    317 		return EINVAL;
    318 	}
    319 	return 0;
    320 }
    321 
    322 #define MULAW_TO_VIDC(m) (~((m) << 1 | (m) >> 7))
    323 
    324 static stream_filter_t *
    325 mulaw_to_vidc(struct audio_softc *sc, const audio_params_t *from,
    326 	      const audio_params_t *to)
    327 {
    328 
    329 	return auconv_nocontext_filter_factory(mulaw_to_vidc_fetch_to);
    330 }
    331 
    332 static int
    333 mulaw_to_vidc_fetch_to(stream_fetcher_t *self, audio_stream_t *dst, int max_used)
    334 {
    335 	stream_filter_t *this;
    336 	int m, err;
    337 
    338 	this = (stream_filter_t *)self;
    339 	if ((err = this->prev->fetch_to(this->prev, this->src, max_used)))
    340 		return err;
    341 	m = dst->end - dst->start;
    342 	m = min(m, max_used);
    343 	FILTER_LOOP_PROLOGUE(this->src, 1, dst, 1, m) {
    344 		*d = MULAW_TO_VIDC(*s);
    345 	} FILTER_LOOP_EPILOGUE(this->src, dst);
    346 	return 0;
    347 }
    348 
    349 static stream_filter_t *
    350 mulaw_to_vidc_stereo(struct audio_softc *sc, const audio_params_t *from,
    351 		     const audio_params_t *to)
    352 {
    353 
    354 	return auconv_nocontext_filter_factory(mulaw_to_vidc_stereo_fetch_to);
    355 }
    356 
    357 static int
    358 mulaw_to_vidc_stereo_fetch_to(stream_fetcher_t *self, audio_stream_t *dst,
    359 			      int max_used)
    360 {
    361 	stream_filter_t *this;
    362 	int m, err;
    363 
    364 	this = (stream_filter_t *)self;
    365 	max_used = (max_used + 1) & ~1;
    366 	if ((err = this->prev->fetch_to(this->prev, this->src, max_used / 2)))
    367 		return err;
    368 	m = (dst->end - dst->start) & ~1;
    369 	m = min(m, max_used);
    370 	FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
    371 		d[0] = d[1] = MULAW_TO_VIDC(*s);
    372 	} FILTER_LOOP_EPILOGUE(this->src, dst);
    373 	return 0;
    374 }
    375 
    376 static int
    377 vidcaudio_set_params(void *addr, int setmode, int usemode,
    378     audio_params_t *p, audio_params_t *r,
    379     stream_filter_list_t *pfil, stream_filter_list_t *rfil)
    380 {
    381 	audio_params_t hw;
    382 	struct vidcaudio_softc *sc;
    383 	int sample_period, ch;
    384 
    385 	if ((setmode & AUMODE_PLAY) == 0)
    386 		return 0;
    387 
    388 	sc = addr;
    389 	if (sc->sc_is16bit) {
    390 		/* ARM7500ish, 16-bit, two-channel */
    391 		hw = *p;
    392 		if (p->encoding == AUDIO_ENCODING_ULAW && p->precision == 8) {
    393 			hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
    394 			hw.precision = hw.validbits = 16;
    395 			pfil->append(pfil, mulaw_to_linear16, &hw);
    396 		} else if (p->encoding != AUDIO_ENCODING_SLINEAR_LE ||
    397 		    p->precision != 16)
    398 			return EINVAL;
    399 		sample_period = 705600 / 4 / p->sample_rate;
    400 		if (sample_period < 3) sample_period = 3;
    401 		vidcaudio_rate(sample_period - 2);
    402 		vidcaudio_ctrl(SCR_SERIAL);
    403 		hw.sample_rate = 705600 / 4 / sample_period;
    404 		hw.channels = 2;
    405 		pfil->append(pfil, aurateconv, &hw);
    406 	} else {
    407 		/* VIDC20ish, u-law, 8-channel */
    408 		if (p->encoding != AUDIO_ENCODING_ULAW || p->precision != 8)
    409 			return EINVAL;
    410 		/*
    411 		 * We always use two hardware channels, because using
    412 		 * one at 8kHz gives a nasty whining sound from the
    413 		 * speaker.  The aurateconv mechanism doesn't support
    414 		 * ulaw, so we do the channel duplication ourselves,
    415 		 * and don't try to do rate conversion.
    416 		 */
    417 		sample_period = 1000000 / 2 / p->sample_rate;
    418 		if (sample_period < 3) sample_period = 3;
    419 		p->sample_rate = 1000000 / 2 / sample_period;
    420 		hw = *p;
    421 		hw.encoding = AUDIO_ENCODING_NONE;
    422 		hw.precision = 8;
    423 		vidcaudio_rate(sample_period - 2);
    424 		vidcaudio_ctrl(SCR_SDAC | SCR_CLKSEL);
    425 		if (p->channels == 1) {
    426 			pfil->append(pfil, mulaw_to_vidc_stereo, &hw);
    427 			for (ch = 0; ch < 8; ch++)
    428 				vidcaudio_stereo(ch, SIR_CENTRE);
    429 		} else {
    430 			pfil->append(pfil, mulaw_to_vidc, &hw);
    431 			for (ch = 0; ch < 8; ch += 2)
    432 				vidcaudio_stereo(ch, SIR_LEFT_100);
    433 			for (ch = 1; ch < 8; ch += 2)
    434 				vidcaudio_stereo(ch, SIR_RIGHT_100);
    435 		}
    436 	}
    437 	return 0;
    438 }
    439 
    440 static int
    441 vidcaudio_round_blocksize(void *addr, int wantblk,
    442 			  int mode, const audio_params_t *param)
    443 {
    444 	int blk;
    445 
    446 	/*
    447 	 * Find the smallest power of two that's larger than the
    448 	 * requested block size, but don't allow < 32 (DMA burst is 16
    449 	 * bytes, and single bursts are tricky) or > PAGE_SIZE (DMA is
    450 	 * confined to a page).
    451 	 */
    452 
    453 	for (blk = 32; blk < PAGE_SIZE; blk <<= 1)
    454 		if (blk >= wantblk)
    455 			return blk;
    456 	return blk;
    457 }
    458 
    459 static int
    460 vidcaudio_trigger_output(void *addr, void *start, void *end, int blksize,
    461     void (*intr)(void *), void *arg, const audio_params_t *params)
    462 {
    463 	struct vidcaudio_softc *sc;
    464 	size_t npages, i;
    465 
    466 	DPRINTF(("vidcaudio_trigger_output %p-%p/0x%x\n",
    467 	    start, end, blksize));
    468 
    469 	sc = addr;
    470 	KASSERT(blksize == vidcaudio_round_blocksize(addr, blksize, 0, NULL));
    471 	KASSERT((vaddr_t)start % blksize == 0);
    472 
    473 	sc->sc_pblksize = blksize;
    474 	sc->sc_pbufsize = (char *)end - (char *)start;
    475 	npages = sc->sc_pbufsize >> PGSHIFT;
    476 	if (sc->sc_ppages != NULL)
    477 		free(sc->sc_ppages, M_DEVBUF);
    478 	sc->sc_ppages = malloc(npages * sizeof(paddr_t), M_DEVBUF, M_WAITOK);
    479 	if (sc->sc_ppages == NULL) return ENOMEM;
    480 	for (i = 0; i < npages; i++)
    481 		if (!pmap_extract(pmap_kernel(),
    482 		    (vaddr_t)start + i * PAGE_SIZE, &sc->sc_ppages[i]))
    483 			return EIO;
    484 	sc->sc_poffset = 0;
    485 	sc->sc_pintr = intr;
    486 	sc->sc_parg = arg;
    487 
    488 	IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_CLEAR | IOMD_DMACR_QUADWORD);
    489 	IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_ENABLE | IOMD_DMACR_QUADWORD);
    490 
    491 	/*
    492 	 * Queue up the first two blocks, but don't tell audio code
    493 	 * we're finished with them yet.
    494 	 */
    495 	sc->sc_pcountdown = 2;
    496 
    497 	enable_irq(sc->sc_dma_intr);
    498 
    499 	return 0;
    500 }
    501 
    502 static int
    503 vidcaudio_trigger_input(void *addr, void *start, void *end, int blksize,
    504     void (*intr)(void *), void *arg, const audio_params_t *params)
    505 {
    506 
    507 	return ENODEV;
    508 }
    509 
    510 static int
    511 vidcaudio_halt_output(void *addr)
    512 {
    513 	struct vidcaudio_softc *sc;
    514 
    515 	DPRINTF(("vidcaudio_halt_output\n"));
    516 	sc = addr;
    517 	disable_irq(sc->sc_dma_intr);
    518 	IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_CLEAR | IOMD_DMACR_QUADWORD);
    519 	return 0;
    520 }
    521 
    522 static int
    523 vidcaudio_halt_input(void *addr)
    524 {
    525 
    526 	return ENODEV;
    527 }
    528 
    529 static int
    530 vidcaudio_getdev(void *addr, struct audio_device *retp)
    531 {
    532 
    533 	*retp = vidcaudio_device;
    534 	return 0;
    535 }
    536 
    537 
    538 static int
    539 vidcaudio_set_port(void *addr, mixer_ctrl_t *cp)
    540 {
    541 
    542 	return EINVAL;
    543 }
    544 
    545 static int
    546 vidcaudio_get_port(void *addr, mixer_ctrl_t *cp)
    547 {
    548 
    549 	return EINVAL;
    550 }
    551 
    552 static int
    553 vidcaudio_query_devinfo(void *addr, mixer_devinfo_t *dip)
    554 {
    555 
    556 	return ENXIO;
    557 }
    558 
    559 static int
    560 vidcaudio_get_props(void *addr)
    561 {
    562 
    563 	return 0;
    564 }
    565 
    566 static void
    567 vidcaudio_rate(int rate)
    568 {
    569 
    570 	WriteWord(vidc_base, VIDC_SFR | rate);
    571 }
    572 
    573 static void
    574 vidcaudio_ctrl(int ctrl)
    575 {
    576 
    577 	WriteWord(vidc_base, VIDC_SCR | ctrl);
    578 }
    579 
    580 static void
    581 vidcaudio_stereo(int channel, int position)
    582 {
    583 
    584 	channel = channel << 24 | VIDC_SIR0;
    585 	WriteWord(vidc_base, channel | position);
    586 }
    587 
    588 static int
    589 vidcaudio_intr(void *arg)
    590 {
    591 	struct vidcaudio_softc *sc;
    592 	int status;
    593 	paddr_t pnext, pend;
    594 
    595 	sc = arg;
    596 
    597 	mutex_enter(&sc->sc_lock);
    598 
    599 	status = IOMD_READ_BYTE(IOMD_SD0ST);
    600 	DPRINTF(("I[%x]", status));
    601 	if ((status & IOMD_DMAST_INT) == 0) {
    602 		mutex_exit(&sc->sc_lock);
    603 		return 0;
    604 	}
    605 
    606 	pnext = sc->sc_ppages[sc->sc_poffset >> PGSHIFT] |
    607 	    (sc->sc_poffset & PGOFSET);
    608 	pend = (pnext + sc->sc_pblksize - 16) & IOMD_DMAEND_OFFSET;
    609 
    610 	switch (status &
    611 	    (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKB)) {
    612 
    613 	case (IOMD_DMAST_INT | IOMD_DMAST_BANKA):
    614 	case (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKB):
    615 		DPRINTF(("B<0x%08lx,0x%03lx>", pnext, pend));
    616 		IOMD_WRITE_WORD(IOMD_SD0CURB, pnext);
    617 		IOMD_WRITE_WORD(IOMD_SD0ENDB, pend);
    618 		break;
    619 
    620 	case (IOMD_DMAST_INT | IOMD_DMAST_BANKB):
    621 	case (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKA):
    622 		DPRINTF(("A<0x%08lx,0x%03lx>", pnext, pend));
    623 		IOMD_WRITE_WORD(IOMD_SD0CURA, pnext);
    624 		IOMD_WRITE_WORD(IOMD_SD0ENDA, pend);
    625 		break;
    626 	}
    627 
    628 	sc->sc_poffset += sc->sc_pblksize;
    629 	if (sc->sc_poffset >= sc->sc_pbufsize)
    630 		sc->sc_poffset = 0;
    631 
    632 	if (sc->sc_pcountdown > 0)
    633 		sc->sc_pcountdown--;
    634 	else
    635 		(*sc->sc_pintr)(sc->sc_parg);
    636 
    637 	mutex_exit(&sc->sc_lock);
    638 
    639 	return 1;
    640 }
    641