sbc.c revision 74395
1/*- 2 * Copyright (c) 1999 Seigo Tanimura 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/dev/sound/isa/sbc.c 74395 2001-03-17 16:04:25Z cg $ 27 */ 28 29#include <dev/sound/chip.h> 30#include <dev/sound/pcm/sound.h> 31#include <dev/sound/isa/sb.h> 32 33#define IO_MAX 3 34#define IRQ_MAX 1 35#define DRQ_MAX 2 36#define INTR_MAX 2 37 38struct sbc_ihl { 39 driver_intr_t *intr[INTR_MAX]; 40 void *intr_arg[INTR_MAX]; 41}; 42 43/* Here is the parameter structure per a device. */ 44struct sbc_softc { 45 device_t dev; /* device */ 46 device_t child_pcm, child_midi1, child_midi2; 47 48 int io_rid[IO_MAX]; /* io port rids */ 49 struct resource *io[IO_MAX]; /* io port resources */ 50 int io_alloced[IO_MAX]; /* io port alloc flag */ 51 52 int irq_rid[IRQ_MAX]; /* irq rids */ 53 struct resource *irq[IRQ_MAX]; /* irq resources */ 54 int irq_alloced[IRQ_MAX]; /* irq alloc flag */ 55 56 int drq_rid[DRQ_MAX]; /* drq rids */ 57 struct resource *drq[DRQ_MAX]; /* drq resources */ 58 int drq_alloced[DRQ_MAX]; /* drq alloc flag */ 59 60 struct sbc_ihl ihl[IRQ_MAX]; 61 62 void *ih[IRQ_MAX]; 63 64 u_int32_t bd_ver; 65}; 66 67static int sbc_probe(device_t dev); 68static int sbc_attach(device_t dev); 69static void sbc_intr(void *p); 70 71static struct resource *sbc_alloc_resource(device_t bus, device_t child, int type, int *rid, 72 u_long start, u_long end, u_long count, u_int flags); 73static int sbc_release_resource(device_t bus, device_t child, int type, int rid, 74 struct resource *r); 75static int sbc_setup_intr(device_t dev, device_t child, struct resource *irq, 76 int flags, driver_intr_t *intr, void *arg, 77 void **cookiep); 78static int sbc_teardown_intr(device_t dev, device_t child, struct resource *irq, 79 void *cookie); 80 81static int alloc_resource(struct sbc_softc *scp); 82static int release_resource(struct sbc_softc *scp); 83 84static devclass_t sbc_devclass; 85 86static int io_range[3] = {0x10, 0x2, 0x4}; 87 88#ifdef PC98 /* I/O address table for PC98 */ 89static bus_addr_t pcm_iat[] = { 90 0x000, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 91 0x800, 0x900, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00, 0xf00 92}; 93static bus_addr_t midi_iat[] = { 94 0x000, 0x100 95}; 96static bus_addr_t opl_iat[] = { 97 0x000, 0x100, 0x200, 0x300 98}; 99static bus_addr_t *sb_iat[] = { pcm_iat, midi_iat, opl_iat }; 100#endif 101 102static int sb_rd(struct resource *io, int reg); 103static void sb_wr(struct resource *io, int reg, u_int8_t val); 104static int sb_dspready(struct resource *io); 105static int sb_cmd(struct resource *io, u_char val); 106static u_int sb_get_byte(struct resource *io); 107static void sb_setmixer(struct resource *io, u_int port, u_int value); 108 109static int 110sb_rd(struct resource *io, int reg) 111{ 112 return bus_space_read_1(rman_get_bustag(io), 113 rman_get_bushandle(io), 114 reg); 115} 116 117static void 118sb_wr(struct resource *io, int reg, u_int8_t val) 119{ 120 return bus_space_write_1(rman_get_bustag(io), 121 rman_get_bushandle(io), 122 reg, val); 123} 124 125static int 126sb_dspready(struct resource *io) 127{ 128 return ((sb_rd(io, SBDSP_STATUS) & 0x80) == 0); 129} 130 131static int 132sb_dspwr(struct resource *io, u_char val) 133{ 134 int i; 135 136 for (i = 0; i < 1000; i++) { 137 if (sb_dspready(io)) { 138 sb_wr(io, SBDSP_CMD, val); 139 return 1; 140 } 141 if (i > 10) DELAY((i > 100)? 1000 : 10); 142 } 143 printf("sb_dspwr(0x%02x) timed out.\n", val); 144 return 0; 145} 146 147static int 148sb_cmd(struct resource *io, u_char val) 149{ 150 return sb_dspwr(io, val); 151} 152 153static void 154sb_setmixer(struct resource *io, u_int port, u_int value) 155{ 156 u_long flags; 157 158 flags = spltty(); 159 sb_wr(io, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */ 160 DELAY(10); 161 sb_wr(io, SB_MIX_DATA, (u_char) (value & 0xff)); 162 DELAY(10); 163 splx(flags); 164} 165 166static u_int 167sb_get_byte(struct resource *io) 168{ 169 int i; 170 171 for (i = 1000; i > 0; i--) { 172 if (sb_rd(io, DSP_DATA_AVAIL) & 0x80) 173 return sb_rd(io, DSP_READ); 174 else 175 DELAY(20); 176 } 177 return 0xffff; 178} 179 180static int 181sb_reset_dsp(struct resource *io) 182{ 183 sb_wr(io, SBDSP_RST, 3); 184 DELAY(100); 185 sb_wr(io, SBDSP_RST, 0); 186 return (sb_get_byte(io) == 0xAA)? 0 : ENXIO; 187} 188 189static int 190sb_identify_board(struct resource *io) 191{ 192 int ver, essver, rev; 193 194 sb_cmd(io, DSP_CMD_GETVER); /* Get version */ 195 ver = (sb_get_byte(io) << 8) | sb_get_byte(io); 196 if (ver < 0x100 || ver > 0x4ff) return 0; 197 if (ver == 0x0301) { 198 /* Try to detect ESS chips. */ 199 sb_cmd(io, DSP_CMD_GETID); /* Return ident. bytes. */ 200 essver = (sb_get_byte(io) << 8) | sb_get_byte(io); 201 rev = essver & 0x000f; 202 essver &= 0xfff0; 203 if (essver == 0x4880) ver |= 0x1000; 204 else if (essver == 0x6880) ver = 0x0500 | rev; 205 } 206 return ver; 207} 208 209static struct isa_pnp_id sbc_ids[] = { 210 {0x01008c0e, "Creative ViBRA16C"}, /* CTL0001 */ 211 {0x31008c0e, "Creative SB16/SB32"}, /* CTL0031 */ 212 {0x41008c0e, "Creative SB16/SB32"}, /* CTL0041 */ 213 {0x42008c0e, "Creative SB AWE64"}, /* CTL0042 */ 214 {0x43008c0e, "Creative ViBRA16X"}, /* CTL0043 */ 215 {0x44008c0e, "Creative SB AWE64 Gold"}, /* CTL0044 */ 216 {0x45008c0e, "Creative SB AWE64"}, /* CTL0045 */ 217 218 {0x01000000, "Avance Logic ALS100+"}, /* @@@0001 - ViBRA16X clone */ 219 {0x01100000, "Avance Asound 110"}, /* @@@1001 */ 220 {0x01200000, "Avance Logic ALS120"}, /* @@@2001 - ViBRA16X clone */ 221 222 {0x81167316, "ESS ES1681"}, /* ESS1681 */ 223 {0x02017316, "ESS ES1688"}, /* ESS1688 */ 224 {0x68187316, "ESS ES1868"}, /* ESS1868 */ 225 {0x03007316, "ESS ES1869"}, /* ESS1869 */ 226 {0x69187316, "ESS ES1869"}, /* ESS1869 */ 227 {0xabb0110e, "ESS ES1869 (Compaq OEM)"}, /* CPQb0ab */ 228 {0xacb0110e, "ESS ES1869 (Compaq OEM)"}, /* CPQb0ac */ 229 {0x78187316, "ESS ES1878"}, /* ESS1878 */ 230 {0x79187316, "ESS ES1879"}, /* ESS1879 */ 231 {0x88187316, "ESS ES1888"}, /* ESS1888 */ 232 {0x07017316, "ESS ES1888 (DEC OEM)"}, /* ESS0107 */ 233 {0x06017316, "ESS ES1888 (Dell OEM)"}, /* ESS0106 */ 234 {0} 235}; 236 237static int 238sbc_probe(device_t dev) 239{ 240 char *s = NULL; 241 u_int32_t lid, vid; 242 243 lid = isa_get_logicalid(dev); 244 vid = isa_get_vendorid(dev); 245 if (lid) { 246 if (lid == 0x01000000 && vid != 0x01009305) /* ALS0001 */ 247 return ENXIO; 248 /* Check pnp ids */ 249 return ISA_PNP_PROBE(device_get_parent(dev), dev, sbc_ids); 250 } else { 251 int rid = 0, ver; 252 struct resource *io; 253 254#ifdef PC98 255 io = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, 256 pcm_iat, 16, RF_ACTIVE); 257#else 258 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 259 0, ~0, 16, RF_ACTIVE); 260#endif 261 if (!io) goto bad; 262#ifdef PC98 263 isa_load_resourcev(io, pcm_iat, 16); 264#endif 265 if (sb_reset_dsp(io)) goto bad2; 266 ver = sb_identify_board(io); 267 if (ver == 0) goto bad2; 268 switch ((ver & 0x00000f00) >> 8) { 269 case 1: 270 device_set_desc(dev, "SoundBlaster 1.0 (not supported)"); 271 s = NULL; 272 break; 273 274 case 2: 275 s = "SoundBlaster 2.0"; 276 break; 277 278 case 3: 279 s = (ver & 0x0000f000)? "ESS 488" : "SoundBlaster Pro"; 280 break; 281 282 case 4: 283 s = "SoundBlaster 16"; 284 break; 285 286 case 5: 287 s = (ver & 0x00000008)? "ESS 688" : "ESS 1688"; 288 break; 289 } 290 if (s) device_set_desc(dev, s); 291bad2: bus_release_resource(dev, SYS_RES_IOPORT, rid, io); 292bad: return s? 0 : ENXIO; 293 } 294} 295 296static int 297sbc_attach(device_t dev) 298{ 299 char *err = NULL; 300 struct sbc_softc *scp; 301 struct sndcard_func *func; 302 u_int32_t logical_id = isa_get_logicalid(dev); 303 int flags = device_get_flags(dev); 304 int f, dh, dl, x, irq, i; 305 306 if (!logical_id && (flags & DV_F_DUAL_DMA)) { 307 bus_set_resource(dev, SYS_RES_DRQ, 1, 308 flags & DV_F_DRQ_MASK, 1); 309 } 310 311 scp = device_get_softc(dev); 312 bzero(scp, sizeof(*scp)); 313 scp->dev = dev; 314 err = "alloc_resource"; 315 if (alloc_resource(scp)) goto bad; 316 317 err = "sb_reset_dsp"; 318 if (sb_reset_dsp(scp->io[0])) goto bad; 319 err = "sb_identify_board"; 320 scp->bd_ver = sb_identify_board(scp->io[0]) & 0x00000fff; 321 if (scp->bd_ver == 0) goto bad; 322 f = 0; 323 if (logical_id == 0x01200000 && scp->bd_ver < 0x0400) scp->bd_ver = 0x0499; 324 switch ((scp->bd_ver & 0x0f00) >> 8) { 325 case 1: /* old sound blaster has nothing... */ 326 break; 327 328 case 2: 329 f |= BD_F_DUP_MIDI; 330 if (scp->bd_ver > 0x200) f |= BD_F_MIX_CT1335; 331 break; 332 333 case 5: 334 f |= BD_F_ESS; 335 scp->bd_ver = 0x0301; 336 case 3: 337 f |= BD_F_DUP_MIDI | BD_F_MIX_CT1345; 338 break; 339 340 case 4: 341 f |= BD_F_SB16 | BD_F_MIX_CT1745; 342 if (scp->drq[0]) dl = rman_get_start(scp->drq[0]); else dl = -1; 343 if (scp->drq[1]) dh = rman_get_start(scp->drq[1]); else dh = dl; 344 if (!logical_id && (dh < dl)) { 345 struct resource *r; 346 r = scp->drq[0]; 347 scp->drq[0] = scp->drq[1]; 348 scp->drq[1] = r; 349 dl = rman_get_start(scp->drq[0]); 350 dh = rman_get_start(scp->drq[1]); 351 } 352 /* soft irq/dma configuration */ 353 x = -1; 354 irq = rman_get_start(scp->irq[0]); 355#ifdef PC98 356 /* SB16 in PC98 use different IRQ table */ 357 if (irq == 3) x = 1; 358 else if (irq == 5) x = 8; 359 else if (irq == 10) x = 2; 360 else if (irq == 12) x = 4; 361 if (x == -1) { 362 err = "bad irq (3/5/10/12 valid)"; 363 goto bad; 364 } 365 else sb_setmixer(scp->io[0], IRQ_NR, x); 366 /* SB16 in PC98 use different dma setting */ 367 sb_setmixer(scp->io[0], DMA_NR, dh == 0 ? 1 : 2); 368#else 369 if (irq == 5) x = 2; 370 else if (irq == 7) x = 4; 371 else if (irq == 9) x = 1; 372 else if (irq == 10) x = 8; 373 if (x == -1) { 374 err = "bad irq (5/7/9/10 valid)"; 375 goto bad; 376 } 377 else sb_setmixer(scp->io[0], IRQ_NR, x); 378 sb_setmixer(scp->io[0], DMA_NR, (1 << dh) | (1 << dl)); 379#endif 380 if (bootverbose) { 381 device_printf(dev, "setting card to irq %d, drq %d", irq, dl); 382 if (dl != dh) printf(", %d", dh); 383 printf("\n"); 384 } 385 break; 386 } 387 388 switch (logical_id) { 389 case 0x43008c0e: /* CTL0043 */ 390 case 0x01200000: 391 case 0x01000000: 392 f |= BD_F_SB16X; 393 break; 394 } 395 scp->bd_ver |= f << 16; 396 397 err = "setup_intr"; 398 for (i = 0; i < IRQ_MAX; i++) { 399 if (bus_setup_intr(dev, scp->irq[i], INTR_TYPE_TTY, sbc_intr, &scp->ihl[i], &scp->ih[i])) 400 goto bad; 401 } 402 403 /* PCM Audio */ 404 func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT); 405 if (func == NULL) goto bad; 406 bzero(func, sizeof(*func)); 407 func->func = SCF_PCM; 408 scp->child_pcm = device_add_child(dev, "pcm", -1); 409 device_set_ivars(scp->child_pcm, func); 410 411 /* Midi Interface */ 412 func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT); 413 if (func == NULL) goto bad; 414 bzero(func, sizeof(*func)); 415 func->func = SCF_MIDI; 416 scp->child_midi1 = device_add_child(dev, "midi", -1); 417 device_set_ivars(scp->child_midi1, func); 418 419 /* OPL FM Synthesizer */ 420 func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT); 421 if (func == NULL) goto bad; 422 bzero(func, sizeof(*func)); 423 func->func = SCF_SYNTH; 424 scp->child_midi2 = device_add_child(dev, "midi", -1); 425 device_set_ivars(scp->child_midi2, func); 426 427 /* probe/attach kids */ 428 bus_generic_attach(dev); 429 430 return (0); 431 432bad: if (err) device_printf(dev, "%s\n", err); 433 release_resource(scp); 434 return (ENXIO); 435} 436 437static int 438sbc_detach(device_t dev) 439{ 440 struct sbc_softc *scp = device_get_softc(dev); 441 442 device_delete_child(dev, scp->child_midi2); 443 device_delete_child(dev, scp->child_midi1); 444 device_delete_child(dev, scp->child_pcm); 445 release_resource(scp); 446 return bus_generic_detach(dev); 447} 448 449static void 450sbc_intr(void *p) 451{ 452 struct sbc_ihl *ihl = p; 453 int i; 454 455 i = 0; 456 while (i < INTR_MAX) { 457 if (ihl->intr[i] != NULL) ihl->intr[i](ihl->intr_arg[i]); 458 i++; 459 } 460} 461 462static int 463sbc_setup_intr(device_t dev, device_t child, struct resource *irq, 464 int flags, driver_intr_t *intr, void *arg, 465 void **cookiep) 466{ 467 struct sbc_softc *scp = device_get_softc(dev); 468 struct sbc_ihl *ihl = NULL; 469 int i; 470 471 i = 0; 472 while (i < IRQ_MAX) { 473 if (irq == scp->irq[i]) ihl = &scp->ihl[i]; 474 i++; 475 } 476 if (ihl == NULL) return (EINVAL); 477 i = 0; 478 while (i < INTR_MAX) { 479 if (ihl->intr[i] == NULL) { 480 ihl->intr[i] = intr; 481 ihl->intr_arg[i] = arg; 482 *cookiep = &ihl->intr[i]; 483 return 0; 484 } else i++; 485 } 486 return (EINVAL); 487} 488 489static int 490sbc_teardown_intr(device_t dev, device_t child, struct resource *irq, 491 void *cookie) 492{ 493 struct sbc_softc *scp = device_get_softc(dev); 494 struct sbc_ihl *ihl = NULL; 495 int i; 496 497 i = 0; 498 while (i < IRQ_MAX) { 499 if (irq == scp->irq[i]) ihl = &scp->ihl[i]; 500 i++; 501 } 502 if (ihl == NULL) return (EINVAL); 503 i = 0; 504 while (i < INTR_MAX) { 505 if (cookie == &ihl->intr[i]) { 506 ihl->intr[i] = NULL; 507 ihl->intr_arg[i] = NULL; 508 return 0; 509 } else i++; 510 } 511 return (EINVAL); 512} 513 514static struct resource * 515sbc_alloc_resource(device_t bus, device_t child, int type, int *rid, 516 u_long start, u_long end, u_long count, u_int flags) 517{ 518 struct sbc_softc *scp; 519 int *alloced, rid_max, alloced_max; 520 struct resource **res; 521#ifdef PC98 522 int i; 523#endif 524 525 scp = device_get_softc(bus); 526 switch (type) { 527 case SYS_RES_IOPORT: 528 alloced = scp->io_alloced; 529 res = scp->io; 530#ifdef PC98 531 rid_max = 0; 532 for (i = 0; i < IO_MAX; i++) 533 rid_max += io_range[i]; 534#else 535 rid_max = IO_MAX - 1; 536#endif 537 alloced_max = 1; 538 break; 539 case SYS_RES_DRQ: 540 alloced = scp->drq_alloced; 541 res = scp->drq; 542 rid_max = DRQ_MAX - 1; 543 alloced_max = 1; 544 break; 545 case SYS_RES_IRQ: 546 alloced = scp->irq_alloced; 547 res = scp->irq; 548 rid_max = IRQ_MAX - 1; 549 alloced_max = INTR_MAX; /* pcm and mpu may share the irq. */ 550 break; 551 default: 552 return (NULL); 553 } 554 555 if (*rid > rid_max || alloced[*rid] == alloced_max) 556 return (NULL); 557 558 alloced[*rid]++; 559 return (res[*rid]); 560} 561 562static int 563sbc_release_resource(device_t bus, device_t child, int type, int rid, 564 struct resource *r) 565{ 566 struct sbc_softc *scp; 567 int *alloced, rid_max; 568 569 scp = device_get_softc(bus); 570 switch (type) { 571 case SYS_RES_IOPORT: 572 alloced = scp->io_alloced; 573 rid_max = IO_MAX - 1; 574 break; 575 case SYS_RES_DRQ: 576 alloced = scp->drq_alloced; 577 rid_max = DRQ_MAX - 1; 578 break; 579 case SYS_RES_IRQ: 580 alloced = scp->irq_alloced; 581 rid_max = IRQ_MAX - 1; 582 break; 583 default: 584 return (1); 585 } 586 587 if (rid > rid_max || alloced[rid] == 0) 588 return (1); 589 590 alloced[rid]--; 591 return (0); 592} 593 594static int 595sbc_read_ivar(device_t bus, device_t dev, int index, uintptr_t * result) 596{ 597 struct sbc_softc *scp = device_get_softc(bus); 598 struct sndcard_func *func = device_get_ivars(dev); 599 600 switch (index) { 601 case 0: 602 *result = func->func; 603 break; 604 605 case 1: 606 *result = scp->bd_ver; 607 break; 608 609 default: 610 return ENOENT; 611 } 612 613 return 0; 614} 615 616static int 617sbc_write_ivar(device_t bus, device_t dev, 618 int index, uintptr_t value) 619{ 620 switch (index) { 621 case 0: 622 case 1: 623 return EINVAL; 624 625 default: 626 return (ENOENT); 627 } 628} 629 630static int 631alloc_resource(struct sbc_softc *scp) 632{ 633 int i; 634 635 for (i = 0 ; i < IO_MAX ; i++) { 636 if (scp->io[i] == NULL) { 637#ifdef PC98 638 scp->io_rid[i] = i > 0 ? 639 scp->io_rid[i - 1] + io_range[i - 1] : 0; 640 scp->io[i] = isa_alloc_resourcev(scp->dev, 641 SYS_RES_IOPORT, 642 &scp->io_rid[i], 643 sb_iat[i], 644 io_range[i], 645 RF_ACTIVE); 646 if (scp->io[i] != NULL) 647 isa_load_resourcev(scp->io[i], sb_iat[i], 648 io_range[i]); 649#else 650 scp->io_rid[i] = i; 651 scp->io[i] = bus_alloc_resource(scp->dev, SYS_RES_IOPORT, &scp->io_rid[i], 652 0, ~0, io_range[i], RF_ACTIVE); 653#endif 654 if (i == 0 && scp->io[i] == NULL) 655 return (1); 656 scp->io_alloced[i] = 0; 657 } 658 } 659 for (i = 0 ; i < DRQ_MAX ; i++) { 660 if (scp->drq[i] == NULL) { 661 scp->drq_rid[i] = i; 662 scp->drq[i] = bus_alloc_resource(scp->dev, SYS_RES_DRQ, &scp->drq_rid[i], 663 0, ~0, 1, RF_ACTIVE); 664 if (i == 0 && scp->drq[i] == NULL) 665 return (1); 666 scp->drq_alloced[i] = 0; 667 } 668 } 669 for (i = 0 ; i < IRQ_MAX ; i++) { 670 if (scp->irq[i] == NULL) { 671 scp->irq_rid[i] = i; 672 scp->irq[i] = bus_alloc_resource(scp->dev, SYS_RES_IRQ, &scp->irq_rid[i], 673 0, ~0, 1, RF_ACTIVE); 674 if (i == 0 && scp->irq[i] == NULL) 675 return (1); 676 scp->irq_alloced[i] = 0; 677 } 678 } 679 return (0); 680} 681 682static int 683release_resource(struct sbc_softc *scp) 684{ 685 int i; 686 687 for (i = 0 ; i < IO_MAX ; i++) { 688 if (scp->io[i] != NULL) { 689 bus_release_resource(scp->dev, SYS_RES_IOPORT, scp->io_rid[i], scp->io[i]); 690 scp->io[i] = NULL; 691 } 692 } 693 for (i = 0 ; i < DRQ_MAX ; i++) { 694 if (scp->drq[i] != NULL) { 695 bus_release_resource(scp->dev, SYS_RES_DRQ, scp->drq_rid[i], scp->drq[i]); 696 scp->drq[i] = NULL; 697 } 698 } 699 for (i = 0 ; i < IRQ_MAX ; i++) { 700 if (scp->irq[i] != NULL) { 701 if (scp->ih[i] != NULL) 702 bus_teardown_intr(scp->dev, scp->irq[i], scp->ih[i]); 703 scp->ih[i] = NULL; 704 bus_release_resource(scp->dev, SYS_RES_IRQ, scp->irq_rid[i], scp->irq[i]); 705 scp->irq[i] = NULL; 706 } 707 } 708 return (0); 709} 710 711static device_method_t sbc_methods[] = { 712 /* Device interface */ 713 DEVMETHOD(device_probe, sbc_probe), 714 DEVMETHOD(device_attach, sbc_attach), 715 DEVMETHOD(device_detach, sbc_detach), 716 DEVMETHOD(device_shutdown, bus_generic_shutdown), 717 DEVMETHOD(device_suspend, bus_generic_suspend), 718 DEVMETHOD(device_resume, bus_generic_resume), 719 720 /* Bus interface */ 721 DEVMETHOD(bus_read_ivar, sbc_read_ivar), 722 DEVMETHOD(bus_write_ivar, sbc_write_ivar), 723 DEVMETHOD(bus_print_child, bus_generic_print_child), 724 DEVMETHOD(bus_alloc_resource, sbc_alloc_resource), 725 DEVMETHOD(bus_release_resource, sbc_release_resource), 726 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 727 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 728 DEVMETHOD(bus_setup_intr, sbc_setup_intr), 729 DEVMETHOD(bus_teardown_intr, sbc_teardown_intr), 730 731 { 0, 0 } 732}; 733 734static driver_t sbc_driver = { 735 "sbc", 736 sbc_methods, 737 sizeof(struct sbc_softc), 738}; 739 740/* sbc can be attached to an isa bus. */ 741DRIVER_MODULE(snd_sbc, isa, sbc_driver, sbc_devclass, 0, 0); 742MODULE_DEPEND(snd_sbc, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER); 743MODULE_VERSION(snd_sbc, 1); 744