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