xref: /netbsd-src/sys/arch/arm/iomd/vidcaudio.c (revision c7c727fae85036860d5bb848f2730ff419e2b060)
1 /*	$NetBSD: vidcaudio.c,v 1.51 2012/10/10 22:00:22 skrll 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.51 2012/10/10 22:00:22 skrll 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 	device_t	sc_dev;
110 
111 	irqhandler_t	sc_ih;
112 	int	sc_dma_intr;
113 
114 	int	sc_is16bit;
115 
116 	size_t	sc_pblksize;
117 	vm_offset_t	sc_poffset;
118 	vm_offset_t	sc_pbufsize;
119 	paddr_t	*sc_ppages;
120 	void	(*sc_pintr)(void *);
121 	void	*sc_parg;
122 	int	sc_pcountdown;
123 
124 	kmutex_t	sc_lock;
125 	kmutex_t	sc_intr_lock;
126 };
127 
128 static int  vidcaudio_probe(device_t , cfdata_t , void *);
129 static void vidcaudio_attach(device_t , device_t , void *);
130 static void vidcaudio_close(void *);
131 
132 static int vidcaudio_intr(void *);
133 static void vidcaudio_rate(int);
134 static void vidcaudio_ctrl(int);
135 static void vidcaudio_stereo(int, int);
136 static stream_filter_factory_t mulaw_to_vidc;
137 static stream_filter_factory_t mulaw_to_vidc_stereo;
138 static int mulaw_to_vidc_fetch_to(struct audio_softc *, stream_fetcher_t *,
139     audio_stream_t *, int);
140 static int mulaw_to_vidc_stereo_fetch_to(struct audio_softc *, stream_fetcher_t *,
141     audio_stream_t *, int);
142 
143 CFATTACH_DECL_NEW(vidcaudio, sizeof(struct vidcaudio_softc),
144     vidcaudio_probe, vidcaudio_attach, NULL, NULL);
145 
146 static int    vidcaudio_query_encoding(void *, struct audio_encoding *);
147 static int    vidcaudio_set_params(void *, int, int, audio_params_t *,
148     audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
149 static int    vidcaudio_round_blocksize(void *, int, int, const audio_params_t *);
150 static int    vidcaudio_trigger_output(void *, void *, void *, int,
151     void (*)(void *), void *, const audio_params_t *);
152 static int    vidcaudio_trigger_input(void *, void *, void *, int,
153     void (*)(void *), void *, const audio_params_t *);
154 static int    vidcaudio_halt_output(void *);
155 static int    vidcaudio_halt_input(void *);
156 static int    vidcaudio_getdev(void *, struct audio_device *);
157 static int    vidcaudio_set_port(void *, mixer_ctrl_t *);
158 static int    vidcaudio_get_port(void *, mixer_ctrl_t *);
159 static int    vidcaudio_query_devinfo(void *, mixer_devinfo_t *);
160 static int    vidcaudio_get_props(void *);
161 static void   vidcaudio_get_locks(void *, kmutex_t **, kmutex_t **);
162 
163 static struct audio_device vidcaudio_device = {
164 	"ARM VIDC",
165 	"",
166 	"vidcaudio"
167 };
168 
169 static const struct audio_hw_if vidcaudio_hw_if = {
170 	NULL,			/* open */
171 	vidcaudio_close,
172 	NULL,
173 	vidcaudio_query_encoding,
174 	vidcaudio_set_params,
175 	vidcaudio_round_blocksize,
176 	NULL,
177 	NULL,
178 	NULL,
179 	NULL,
180 	NULL,
181 	vidcaudio_halt_output,
182 	vidcaudio_halt_input,
183 	NULL,
184 	vidcaudio_getdev,
185 	NULL,
186 	vidcaudio_set_port,
187 	vidcaudio_get_port,
188 	vidcaudio_query_devinfo,
189 	NULL,
190 	NULL,
191 	NULL,
192 	NULL,
193 	vidcaudio_get_props,
194 	vidcaudio_trigger_output,
195 	vidcaudio_trigger_input,
196 	NULL,
197 	vidcaudio_get_locks,
198 };
199 
200 static int
201 vidcaudio_probe(device_t parent, cfdata_t cf, void *aux)
202 {
203 	int id;
204 
205 	id = IOMD_ID;
206 
207 	/* So far I only know about this IOMD */
208 	switch (id) {
209 	case RPC600_IOMD_ID:
210 	case ARM7500_IOC_ID:
211 	case ARM7500FE_IOC_ID:
212 		return 1;
213 	default:
214 		aprint_error("vidcaudio: Unknown IOMD id=%04x", id);
215 		return 0;
216 	}
217 }
218 
219 
220 static void
221 vidcaudio_attach(device_t parent, device_t self, void *aux)
222 {
223 	struct vidcaudio_softc *sc = device_private(self);
224 	device_t beepdev;
225 
226 	sc->sc_dev = self;
227 	switch (IOMD_ID) {
228 #ifndef EB7500ATX
229 	case RPC600_IOMD_ID:
230 		sc->sc_is16bit = (cmos_read(0xc4) >> 5) & 1;
231 		sc->sc_dma_intr = IRQ_DMASCH0;
232 		break;
233 #endif
234 	case ARM7500_IOC_ID:
235 	case ARM7500FE_IOC_ID:
236 		sc->sc_is16bit = true;
237 		sc->sc_dma_intr = IRQ_SDMA;
238 		break;
239 	default:
240 		aprint_error(": strange IOMD\n");
241 		return;
242 	}
243 
244 	if (sc->sc_is16bit)
245 		aprint_normal(": 16-bit external DAC\n");
246 	else
247 		aprint_normal(": 8-bit internal DAC\n");
248 
249 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
250 	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_AUDIO);
251 
252 	/* Install the irq handler for the DMA interrupt */
253 	sc->sc_ih.ih_func = vidcaudio_intr;
254 	sc->sc_ih.ih_arg = sc;
255 	sc->sc_ih.ih_level = IPL_AUDIO;
256 	sc->sc_ih.ih_name = device_xname(self);
257 
258 	if (irq_claim(sc->sc_dma_intr, &sc->sc_ih) != 0) {
259 		aprint_error("%s: couldn't claim IRQ %d\n",
260 		    device_xname(self), sc->sc_dma_intr);
261 		return;
262 	}
263 
264 	disable_irq(sc->sc_dma_intr);
265 
266 	beepdev = audio_attach_mi(&vidcaudio_hw_if, sc, self);
267 #if NPCKBD > 0
268 	pckbd_hookup_bell(audiobell, beepdev);
269 #endif
270 }
271 
272 static void
273 vidcaudio_close(void *addr)
274 {
275 	struct vidcaudio_softc *sc;
276 
277 	DPRINTF(("DEBUG: vidcaudio_close called\n"));
278 	sc = addr;
279 	/*
280 	 * We do this here rather than in vidcaudio_halt_output()
281 	 * because the latter can be called from interrupt context
282 	 * (audio_pint()->audio_clear()->vidcaudio_halt_output()).
283 	 */
284 	if (sc->sc_ppages != NULL) {
285 		free(sc->sc_ppages, M_DEVBUF);
286 		sc->sc_ppages = NULL;
287 	}
288 }
289 
290 /*
291  * Interface to the generic audio driver
292  */
293 
294 static int
295 vidcaudio_query_encoding(void *addr, struct audio_encoding *fp)
296 {
297 	struct vidcaudio_softc *sc;
298 
299 	sc = addr;
300 	switch (fp->index) {
301 	case 0:
302 		strcpy(fp->name, AudioEmulaw);
303 		fp->encoding = AUDIO_ENCODING_ULAW;
304 		fp->precision = 8;
305 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
306 		break;
307 
308 	case 1:
309 		if (sc->sc_is16bit) {
310 			strcpy(fp->name, AudioEslinear_le);
311 			fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
312 			fp->precision = 16;
313 			fp->flags = 0;
314 			break;
315 		}
316 		/* FALLTHROUGH */
317 	default:
318 		return EINVAL;
319 	}
320 	return 0;
321 }
322 
323 #define MULAW_TO_VIDC(m) (~((m) << 1 | (m) >> 7))
324 
325 static stream_filter_t *
326 mulaw_to_vidc(struct audio_softc *sc, const audio_params_t *from,
327 	      const audio_params_t *to)
328 {
329 
330 	return auconv_nocontext_filter_factory(mulaw_to_vidc_fetch_to);
331 }
332 
333 static int
334 mulaw_to_vidc_fetch_to(struct audio_softc *sc, stream_fetcher_t *self,
335 		       audio_stream_t *dst, int max_used)
336 {
337 	stream_filter_t *this;
338 	int m, err;
339 
340 	this = (stream_filter_t *)self;
341 	if ((err = this->prev->fetch_to(sc, this->prev, this->src, max_used)))
342 		return err;
343 	m = dst->end - dst->start;
344 	m = min(m, max_used);
345 	FILTER_LOOP_PROLOGUE(this->src, 1, dst, 1, m) {
346 		*d = MULAW_TO_VIDC(*s);
347 	} FILTER_LOOP_EPILOGUE(this->src, dst);
348 	return 0;
349 }
350 
351 static stream_filter_t *
352 mulaw_to_vidc_stereo(struct audio_softc *sc, const audio_params_t *from,
353 		     const audio_params_t *to)
354 {
355 
356 	return auconv_nocontext_filter_factory(mulaw_to_vidc_stereo_fetch_to);
357 }
358 
359 static int
360 mulaw_to_vidc_stereo_fetch_to(struct audio_softc *sc, stream_fetcher_t *self,
361 			      audio_stream_t *dst, int max_used)
362 {
363 	stream_filter_t *this;
364 	int m, err;
365 
366 	this = (stream_filter_t *)self;
367 	max_used = (max_used + 1) & ~1;
368 	if ((err = this->prev->fetch_to(sc, this->prev, this->src, max_used / 2)))
369 		return err;
370 	m = (dst->end - dst->start) & ~1;
371 	m = min(m, max_used);
372 	FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
373 		d[0] = d[1] = MULAW_TO_VIDC(*s);
374 	} FILTER_LOOP_EPILOGUE(this->src, dst);
375 	return 0;
376 }
377 
378 static int
379 vidcaudio_set_params(void *addr, int setmode, int usemode,
380     audio_params_t *p, audio_params_t *r,
381     stream_filter_list_t *pfil, stream_filter_list_t *rfil)
382 {
383 	audio_params_t hw;
384 	struct vidcaudio_softc *sc;
385 	int sample_period, ch;
386 
387 	if ((setmode & AUMODE_PLAY) == 0)
388 		return 0;
389 
390 	sc = addr;
391 	if (sc->sc_is16bit) {
392 		/* ARM7500ish, 16-bit, two-channel */
393 		hw = *p;
394 		if (p->encoding == AUDIO_ENCODING_ULAW && p->precision == 8) {
395 			hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
396 			hw.precision = hw.validbits = 16;
397 			pfil->append(pfil, mulaw_to_linear16, &hw);
398 		} else if (p->encoding != AUDIO_ENCODING_SLINEAR_LE ||
399 		    p->precision != 16)
400 			return EINVAL;
401 		sample_period = 705600 / 4 / p->sample_rate;
402 		if (sample_period < 3) sample_period = 3;
403 		vidcaudio_rate(sample_period - 2);
404 		vidcaudio_ctrl(SCR_SERIAL);
405 		hw.sample_rate = 705600 / 4 / sample_period;
406 		hw.channels = 2;
407 		pfil->prepend(pfil, aurateconv, &hw);
408 	} else {
409 		/* VIDC20ish, u-law, 8-channel */
410 		if (p->encoding != AUDIO_ENCODING_ULAW || p->precision != 8)
411 			return EINVAL;
412 		/*
413 		 * We always use two hardware channels, because using
414 		 * one at 8kHz gives a nasty whining sound from the
415 		 * speaker.  The aurateconv mechanism doesn't support
416 		 * ulaw, so we do the channel duplication ourselves,
417 		 * and don't try to do rate conversion.
418 		 */
419 		sample_period = 1000000 / 2 / p->sample_rate;
420 		if (sample_period < 3) sample_period = 3;
421 		p->sample_rate = 1000000 / 2 / sample_period;
422 		hw = *p;
423 		hw.encoding = AUDIO_ENCODING_NONE;
424 		hw.precision = 8;
425 		vidcaudio_rate(sample_period - 2);
426 		vidcaudio_ctrl(SCR_SDAC | SCR_CLKSEL);
427 		if (p->channels == 1) {
428 			pfil->append(pfil, mulaw_to_vidc_stereo, &hw);
429 			for (ch = 0; ch < 8; ch++)
430 				vidcaudio_stereo(ch, SIR_CENTRE);
431 		} else {
432 			pfil->append(pfil, mulaw_to_vidc, &hw);
433 			for (ch = 0; ch < 8; ch += 2)
434 				vidcaudio_stereo(ch, SIR_LEFT_100);
435 			for (ch = 1; ch < 8; ch += 2)
436 				vidcaudio_stereo(ch, SIR_RIGHT_100);
437 		}
438 	}
439 	return 0;
440 }
441 
442 static int
443 vidcaudio_round_blocksize(void *addr, int wantblk,
444 			  int mode, const audio_params_t *param)
445 {
446 	int blk;
447 
448 	/*
449 	 * Find the smallest power of two that's larger than the
450 	 * requested block size, but don't allow < 32 (DMA burst is 16
451 	 * bytes, and single bursts are tricky) or > PAGE_SIZE (DMA is
452 	 * confined to a page).
453 	 */
454 
455 	for (blk = 32; blk < PAGE_SIZE; blk <<= 1)
456 		if (blk >= wantblk)
457 			return blk;
458 	return blk;
459 }
460 
461 static int
462 vidcaudio_trigger_output(void *addr, void *start, void *end, int blksize,
463     void (*intr)(void *), void *arg, const audio_params_t *params)
464 {
465 	struct vidcaudio_softc *sc;
466 	size_t npages, i;
467 
468 	DPRINTF(("vidcaudio_trigger_output %p-%p/0x%x\n",
469 	    start, end, blksize));
470 
471 	sc = addr;
472 	KASSERT(blksize == vidcaudio_round_blocksize(addr, blksize, 0, NULL));
473 	KASSERT((vaddr_t)start % blksize == 0);
474 
475 	sc->sc_pblksize = blksize;
476 	sc->sc_pbufsize = (char *)end - (char *)start;
477 	npages = sc->sc_pbufsize >> PGSHIFT;
478 	if (sc->sc_ppages != NULL)
479 		free(sc->sc_ppages, M_DEVBUF);
480 	sc->sc_ppages = malloc(npages * sizeof(paddr_t), M_DEVBUF, M_WAITOK);
481 	if (sc->sc_ppages == NULL)
482 		return ENOMEM;
483 	for (i = 0; i < npages; i++)
484 		if (!pmap_extract(pmap_kernel(),
485 		    (vaddr_t)start + i * PAGE_SIZE, &sc->sc_ppages[i]))
486 			return EIO;
487 	sc->sc_poffset = 0;
488 	sc->sc_pintr = intr;
489 	sc->sc_parg = arg;
490 
491 	IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_CLEAR | IOMD_DMACR_QUADWORD);
492 	IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_ENABLE | IOMD_DMACR_QUADWORD);
493 
494 	/*
495 	 * Queue up the first two blocks, but don't tell audio code
496 	 * we're finished with them yet.
497 	 */
498 	sc->sc_pcountdown = 2;
499 
500 	enable_irq(sc->sc_dma_intr);
501 
502 	return 0;
503 }
504 
505 static int
506 vidcaudio_trigger_input(void *addr, void *start, void *end, int blksize,
507     void (*intr)(void *), void *arg, const audio_params_t *params)
508 {
509 
510 	return ENODEV;
511 }
512 
513 static int
514 vidcaudio_halt_output(void *addr)
515 {
516 	struct vidcaudio_softc *sc;
517 
518 	DPRINTF(("vidcaudio_halt_output\n"));
519 	sc = addr;
520 	disable_irq(sc->sc_dma_intr);
521 	IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_CLEAR | IOMD_DMACR_QUADWORD);
522 	return 0;
523 }
524 
525 static int
526 vidcaudio_halt_input(void *addr)
527 {
528 
529 	return ENODEV;
530 }
531 
532 static int
533 vidcaudio_getdev(void *addr, struct audio_device *retp)
534 {
535 
536 	*retp = vidcaudio_device;
537 	return 0;
538 }
539 
540 
541 static int
542 vidcaudio_set_port(void *addr, mixer_ctrl_t *cp)
543 {
544 
545 	return EINVAL;
546 }
547 
548 static int
549 vidcaudio_get_port(void *addr, mixer_ctrl_t *cp)
550 {
551 
552 	return EINVAL;
553 }
554 
555 static int
556 vidcaudio_query_devinfo(void *addr, mixer_devinfo_t *dip)
557 {
558 
559 	return ENXIO;
560 }
561 
562 static int
563 vidcaudio_get_props(void *addr)
564 {
565 
566 	return 0;
567 }
568 
569 static void
570 vidcaudio_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread)
571 {
572 	struct vidcaudio_softc *sc = opaque;
573 
574 	*intr = &sc->sc_intr_lock;
575 	*thread = &sc->sc_lock;
576 }
577 
578 static void
579 vidcaudio_rate(int rate)
580 {
581 
582 	WriteWord(vidc_base, VIDC_SFR | rate);
583 }
584 
585 static void
586 vidcaudio_ctrl(int ctrl)
587 {
588 
589 	WriteWord(vidc_base, VIDC_SCR | ctrl);
590 }
591 
592 static void
593 vidcaudio_stereo(int channel, int position)
594 {
595 
596 	channel = channel << 24 | VIDC_SIR0;
597 	WriteWord(vidc_base, channel | position);
598 }
599 
600 static int
601 vidcaudio_intr(void *arg)
602 {
603 	struct vidcaudio_softc *sc;
604 	int status;
605 	paddr_t pnext, pend;
606 
607 	sc = arg;
608 	mutex_spin_enter(&sc->sc_intr_lock);
609 
610 	status = IOMD_READ_BYTE(IOMD_SD0ST);
611 	DPRINTF(("I[%x]", status));
612 	if ((status & IOMD_DMAST_INT) == 0) {
613 		mutex_spin_exit(&sc->sc_intr_lock);
614 		return 0;
615 	}
616 
617 	pnext = sc->sc_ppages[sc->sc_poffset >> PGSHIFT] |
618 	    (sc->sc_poffset & PGOFSET);
619 	pend = (pnext + sc->sc_pblksize - 16) & IOMD_DMAEND_OFFSET;
620 
621 	switch (status &
622 	    (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKB)) {
623 
624 	case (IOMD_DMAST_INT | IOMD_DMAST_BANKA):
625 	case (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKB):
626 		DPRINTF(("B<0x%08lx,0x%03lx>", pnext, pend));
627 		IOMD_WRITE_WORD(IOMD_SD0CURB, pnext);
628 		IOMD_WRITE_WORD(IOMD_SD0ENDB, pend);
629 		break;
630 
631 	case (IOMD_DMAST_INT | IOMD_DMAST_BANKB):
632 	case (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKA):
633 		DPRINTF(("A<0x%08lx,0x%03lx>", pnext, pend));
634 		IOMD_WRITE_WORD(IOMD_SD0CURA, pnext);
635 		IOMD_WRITE_WORD(IOMD_SD0ENDA, pend);
636 		break;
637 	}
638 
639 	sc->sc_poffset += sc->sc_pblksize;
640 	if (sc->sc_poffset >= sc->sc_pbufsize)
641 		sc->sc_poffset = 0;
642 
643 	if (sc->sc_pcountdown > 0)
644 		sc->sc_pcountdown--;
645 	else
646 		(*sc->sc_pintr)(sc->sc_parg);
647 
648 	mutex_spin_exit(&sc->sc_intr_lock);
649 	return 1;
650 }
651