1 /* 2 * Auvia BeOS Driver for Via VT82xx Southbridge audio 3 * 4 * Copyright (c) 2003, Jerome Duval (jerome.duval@free.fr) 5 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Tyler C. Sarna 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the NetBSD 20 * Foundation, Inc. and its contributors. 21 * 4. Neither the name of The NetBSD Foundation nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 #include <KernelExport.h> 39 #include <PCI.h> 40 #include <string.h> 41 #include <stdio.h> 42 #include "auvia.h" 43 #include "debug.h" 44 #include "config.h" 45 #include "util.h" 46 #include "io.h" 47 #include <fcntl.h> 48 #include <unistd.h> 49 #include <malloc.h> 50 #include "ac97.h" 51 52 status_t init_hardware(void); 53 status_t init_driver(void); 54 void uninit_driver(void); 55 const char ** publish_devices(void); 56 device_hooks * find_device(const char *); 57 58 pci_module_info *pci; 59 60 int32 num_cards; 61 auvia_dev cards[NUM_CARDS]; 62 int32 num_names; 63 char * names[NUM_CARDS*20+1]; 64 65 extern device_hooks multi_hooks; 66 67 /* Auvia Memory management */ 68 69 static auvia_mem * 70 auvia_mem_new(auvia_dev *card, size_t size) 71 { 72 auvia_mem *mem; 73 74 if ((mem = malloc(sizeof(*mem))) == NULL) 75 return (NULL); 76 77 mem->area = alloc_mem(&mem->phy_base, &mem->log_base, size, "auvia buffer"); 78 mem->size = size; 79 if (mem->area < B_OK) { 80 free(mem); 81 return NULL; 82 } 83 return mem; 84 } 85 86 static void 87 auvia_mem_delete(auvia_mem *mem) 88 { 89 if(mem->area > B_OK) 90 delete_area(mem->area); 91 free(mem); 92 } 93 94 static void * 95 auvia_mem_alloc(auvia_dev *card, size_t size) 96 { 97 auvia_mem *mem; 98 99 mem = auvia_mem_new(card, size); 100 if (mem == NULL) 101 return (NULL); 102 103 LIST_INSERT_HEAD(&(card->mems), mem, next); 104 105 return mem; 106 } 107 108 static void 109 auvia_mem_free(auvia_dev *card, void *ptr) 110 { 111 auvia_mem *mem; 112 113 LIST_FOREACH(mem, &card->mems, next) { 114 if (mem->log_base != ptr) 115 continue; 116 LIST_REMOVE(mem, next); 117 118 auvia_mem_delete(mem); 119 break; 120 } 121 } 122 123 /* Auvia stream functions */ 124 125 status_t 126 auvia_stream_set_audioparms(auvia_stream *stream, uint8 channels, 127 uint8 b16, uint32 sample_rate) 128 { 129 uint8 sample_size, frame_size; 130 LOG(("auvia_stream_set_audioparms\n")); 131 132 if ((stream->channels == channels) && 133 (stream->b16 == b16) && 134 (stream->sample_rate == sample_rate)) 135 return B_OK; 136 137 if(stream->buffer) 138 auvia_mem_free(stream->card, stream->buffer->log_base); 139 140 stream->b16 = b16; 141 stream->sample_rate = sample_rate; 142 stream->channels = channels; 143 144 sample_size = stream->b16 + 1; 145 frame_size = sample_size * stream->channels; 146 147 stream->buffer = auvia_mem_alloc(stream->card, stream->bufframes * frame_size * stream->bufcount); 148 149 stream->trigblk = 0; /* This shouldn't be needed */ 150 stream->blkmod = stream->bufcount; 151 stream->blksize = stream->bufframes * frame_size; 152 153 return B_OK; 154 } 155 156 status_t 157 auvia_stream_commit_parms(auvia_stream *stream) 158 { 159 int i; 160 uint32 *page; 161 uint32 value; 162 LOG(("auvia_stream_commit_parms\n")); 163 164 page = stream->dmaops_log_base; 165 166 for(i=0; i<stream->bufcount; i++) { 167 page[2*i] = ((uint32)stream->buffer->phy_base) + 168 i * stream->blksize; 169 page[2*i + 1] = AUVIA_DMAOP_FLAG | stream->blksize; 170 } 171 172 page[2*stream->bufcount - 1] &= ~AUVIA_DMAOP_FLAG; 173 page[2*stream->bufcount - 1] |= AUVIA_DMAOP_EOL; 174 175 auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE, 176 (uint32)stream->dmaops_phy_base); 177 178 if(stream->use & AUVIA_USE_RECORD) 179 auvia_codec_write(&stream->card->config, AC97_PCM_LR_ADC_RATE, (uint16)stream->sample_rate); 180 else 181 auvia_codec_write(&stream->card->config, AC97_PCM_FRONT_DAC_RATE, (uint16)stream->sample_rate); 182 183 if(IS_8233(&stream->card->config)) { 184 if(stream->base != AUVIA_8233_MP_BASE) { 185 value = auvia_reg_read_32(&stream->card->config, stream->base + AUVIA_8233_RP_RATEFMT); 186 value &= ~(AUVIA_8233_RATEFMT_48K | AUVIA_8233_RATEFMT_STEREO | AUVIA_8233_RATEFMT_16BIT); 187 if(stream->use & AUVIA_USE_PLAY) 188 value |= AUVIA_8233_RATEFMT_48K * (stream->sample_rate / 20) / (48000 / 20); 189 value |= (stream->channels == 2 ? AUVIA_8233_RATEFMT_STEREO : 0) 190 | (stream->b16 ? AUVIA_8233_RATEFMT_16BIT : 0); 191 auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_8233_RP_RATEFMT, value); 192 } else { 193 static const uint32 slottab[7] = {0, 0xff000011, 0xff000021, 0xff000521, 194 0xff004321, 0xff054321, 0xff654321}; 195 value = (stream->b16 ? AUVIA_8233_MP_FORMAT_16BIT : AUVIA_8233_MP_FORMAT_8BIT) 196 | ((stream->channels << 4) & AUVIA_8233_MP_FORMAT_CHANNEL_MASK) ; 197 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_8233_OFF_MP_FORMAT, value); 198 auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_8233_OFF_MP_STOP, 199 slottab[stream->channels]); 200 } 201 } 202 //auvia_codec_write(&stream->card->config, AC97_SPDIF_CONTROL, (uint16)stream->sample_rate); 203 204 return B_OK; 205 } 206 207 status_t 208 auvia_stream_get_nth_buffer(auvia_stream *stream, uint8 chan, uint8 buf, 209 char** buffer, size_t *stride) 210 { 211 uint8 sample_size, frame_size; 212 LOG(("auvia_stream_get_nth_buffer\n")); 213 214 sample_size = stream->b16 + 1; 215 frame_size = sample_size * stream->channels; 216 217 *buffer = stream->buffer->log_base + (buf * stream->bufframes * frame_size) 218 + chan * sample_size; 219 *stride = frame_size; 220 221 return B_OK; 222 } 223 224 static uint32 225 auvia_stream_curaddr(auvia_stream *stream) 226 { 227 uint32 addr; 228 if(IS_8233(&stream->card->config)) { 229 addr = auvia_reg_read_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE); 230 TRACE(("stream_curaddr %p, phy_base %p\n", addr, (uint32)stream->dmaops_phy_base)); 231 return (addr - (uint32)stream->dmaops_phy_base - 4) / 8; 232 } else { 233 addr = auvia_reg_read_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE); 234 TRACE(("stream_curaddr %p, phy_base %p\n", addr, (uint32)stream->dmaops_phy_base)); 235 return (addr - (uint32)stream->dmaops_phy_base - 8) / 8; 236 } 237 } 238 239 void 240 auvia_stream_start(auvia_stream *stream, void (*inth) (void *), void *inthparam) 241 { 242 LOG(("auvia_stream_start\n")); 243 244 stream->inth = inth; 245 stream->inthparam = inthparam; 246 247 stream->state |= AUVIA_STATE_STARTED; 248 249 if(IS_8233(&stream->card->config)) { 250 if(stream->base != AUVIA_8233_MP_BASE) { 251 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_8233_RP_DXS_LVOL, 0); 252 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_8233_RP_DXS_RVOL, 0); 253 } 254 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_RP_CONTROL, 255 AUVIA_RPCTRL_START | AUVIA_RPCTRL_AUTOSTART | AUVIA_RPCTRL_STOP 256 | AUVIA_RPCTRL_EOL | AUVIA_RPCTRL_FLAG); 257 } else { 258 uint8 regvalue = (stream->channels > 1 ? AUVIA_RPMODE_STEREO : 0) 259 | (stream->b16 == 1 ? AUVIA_RPMODE_16BIT : 0) 260 | AUVIA_RPMODE_INTR_FLAG | AUVIA_RPMODE_INTR_EOL | AUVIA_RPMODE_AUTOSTART; 261 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_RP_MODE, regvalue); 262 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_RP_CONTROL, AUVIA_RPCTRL_START); 263 } 264 } 265 266 void 267 auvia_stream_halt(auvia_stream *stream) 268 { 269 LOG(("auvia_stream_halt\n")); 270 271 stream->state &= ~AUVIA_STATE_STARTED; 272 273 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_RP_CONTROL, AUVIA_RPCTRL_TERMINATE); 274 } 275 276 auvia_stream * 277 auvia_stream_new(auvia_dev *card, uint8 use, uint32 bufframes, uint8 bufcount) 278 { 279 auvia_stream *stream; 280 cpu_status status; 281 LOG(("auvia_stream_new\n")); 282 283 stream = malloc(sizeof(auvia_stream)); 284 if (stream == NULL) 285 return (NULL); 286 stream->card = card; 287 stream->use = use; 288 stream->state = !AUVIA_STATE_STARTED; 289 stream->b16 = 0; 290 stream->sample_rate = 0; 291 stream->channels = 0; 292 stream->bufframes = bufframes; 293 stream->bufcount = bufcount; 294 stream->inth = NULL; 295 stream->inthparam = NULL; 296 stream->buffer = NULL; 297 stream->blksize = 0; 298 stream->trigblk = 0; 299 stream->blkmod = 0; 300 301 if(use & AUVIA_USE_PLAY) { 302 if(IS_8233(&card->config)) 303 stream->base = AUVIA_8233_MP_BASE; 304 //stream->base = AUVIA_PLAY_BASE; 305 else 306 stream->base = AUVIA_PLAY_BASE; 307 } else { 308 if(IS_8233(&card->config)) 309 stream->base = AUVIA_8233_RECORD_BASE; 310 else 311 stream->base = AUVIA_RECORD_BASE; 312 } 313 314 stream->frames_count = 0; 315 stream->real_time = 0; 316 stream->update_needed = false; 317 318 /* allocate memory for our dma ops */ 319 stream->dmaops_area = alloc_mem(&stream->dmaops_phy_base, &stream->dmaops_log_base, 320 VIA_TABLE_SIZE, "auvia dmaops"); 321 322 if (stream->dmaops_area < B_OK) { 323 PRINT(("couldn't allocate memory\n")); 324 free(stream); 325 return NULL; 326 } 327 328 status = lock(); 329 LIST_INSERT_HEAD((&card->streams), stream, next); 330 unlock(status); 331 332 return stream; 333 } 334 335 void 336 auvia_stream_delete(auvia_stream *stream) 337 { 338 cpu_status status; 339 LOG(("auvia_stream_delete\n")); 340 341 auvia_stream_halt(stream); 342 343 auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE, 0); 344 345 if (stream->dmaops_area > B_OK) 346 delete_area(stream->dmaops_area); 347 348 if(stream->buffer) 349 auvia_mem_free(stream->card, stream->buffer->log_base); 350 351 status = lock(); 352 LIST_REMOVE(stream, next); 353 unlock(status); 354 355 free(stream); 356 } 357 358 /* Auvia interrupt */ 359 360 static int32 361 auvia_int(void *arg) 362 { 363 auvia_dev *card = arg; 364 bool gotone = false; 365 uint32 curblk; 366 auvia_stream *stream; 367 368 if(auvia_reg_read_32(&card->config, AUVIA_SGD_SHADOW) 369 & card->interrupt_mask) { 370 371 LIST_FOREACH(stream, &card->streams, next) 372 if(auvia_reg_read_8(&card->config, stream->base + AUVIA_RP_STAT) & AUVIA_RPSTAT_INTR) { 373 gotone = true; 374 //TRACE(("interrupt\n")); 375 376 curblk = auvia_stream_curaddr(stream); 377 TRACE(("RPSTAT_INTR at trigblk %lu, stream->trigblk %lu\n", curblk, stream->trigblk)); 378 if (curblk == stream->trigblk) { 379 //TRACE(("AUVIA_RPSTAT_INTR at trigblk %lu\n", curblk)); 380 381 if(stream->inth) 382 stream->inth(stream->inthparam); 383 384 stream->trigblk++; 385 stream->trigblk %= stream->blkmod; 386 } 387 388 auvia_reg_write_8(&card->config, stream->base + AUVIA_RP_STAT, AUVIA_RPSTAT_INTR); 389 } 390 } else { 391 TRACE(("SGD_SHADOW %x %x\n", card->interrupt_mask, auvia_reg_read_32(&card->config, AUVIA_SGD_SHADOW))); 392 } 393 394 if(gotone) 395 return B_INVOKE_SCHEDULER; 396 397 TRACE(("Got unhandled interrupt\n")); 398 return B_UNHANDLED_INTERRUPT; 399 } 400 401 /* Auvia driver functions */ 402 403 /* detect presence of our hardware */ 404 status_t 405 init_hardware(void) 406 { 407 int ix=0; 408 pci_info info; 409 status_t err = ENODEV; 410 411 LOG_CREATE(); 412 413 PRINT(("init_hardware()\n")); 414 415 if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci)) 416 return ENOSYS; 417 418 while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) { 419 if (info.vendor_id == VIATECH_VENDOR_ID && 420 (info.device_id == VIATECH_82C686_AC97_DEVICE_ID 421 || info.device_id == VIATECH_8233_AC97_DEVICE_ID 422 )) { 423 err = B_OK; 424 } 425 ix++; 426 } 427 428 put_module(B_PCI_MODULE_NAME); 429 430 return err; 431 } 432 433 static void 434 make_device_names( 435 auvia_dev * card) 436 { 437 sprintf(card->name, "audio/hmulti/auvia/%ld", card-cards+1); 438 names[num_names++] = card->name; 439 440 names[num_names] = NULL; 441 } 442 443 444 static status_t 445 auvia_init(auvia_dev * card) 446 { 447 uint32 pr; 448 449 pr = (*pci->read_pci_config)(card->info.bus, card->info.device, card->info.function, AUVIA_PCICONF_JUNK, 4); 450 PRINT(("AUVIA_PCICONF_JUNK before: %lx\n", pr)); 451 pr &= ~AUVIA_PCICONF_ENABLES; 452 pr |= AUVIA_PCICONF_ACLINKENAB | AUVIA_PCICONF_ACNOTRST | AUVIA_PCICONF_ACVSR | AUVIA_PCICONF_ACSGD; 453 pr &= ~(AUVIA_PCICONF_ACFM | AUVIA_PCICONF_ACSB); 454 (*pci->write_pci_config)(card->info.bus, card->info.device, card->info.function, AUVIA_PCICONF_JUNK, 4, pr ); 455 snooze(100); 456 pr = (*pci->read_pci_config)(card->info.bus, card->info.device, card->info.function, AUVIA_PCICONF_JUNK, 4); 457 PRINT(("AUVIA_PCICONF_JUNK after: %lx\n", pr)); 458 459 if(IS_8233(&card->config)) { 460 card->interrupt_mask = 461 AUVIA_8233_SGD_STAT_FLAG_EOL | 462 AUVIA_8233_SGD_STAT_FLAG_EOL << 4 | 463 AUVIA_8233_SGD_STAT_FLAG_EOL << 8 | 464 AUVIA_8233_SGD_STAT_FLAG_EOL << 12 | 465 AUVIA_8233_SGD_STAT_FLAG_EOL << 16 | 466 AUVIA_8233_SGD_STAT_FLAG_EOL << 24 | 467 AUVIA_8233_SGD_STAT_FLAG_EOL << 28; 468 } else { 469 card->interrupt_mask = AUVIA_SGD_STAT_ALL | (AUVIA_SGD_STAT_ALL << 4); 470 } 471 472 473 /* Init streams list */ 474 LIST_INIT(&(card->streams)); 475 476 /* Init mems list */ 477 LIST_INIT(&(card->mems)); 478 479 return B_OK; 480 } 481 482 static status_t 483 auvia_setup(auvia_dev * card) 484 { 485 status_t err = B_OK; 486 unsigned char cmd; 487 488 PRINT(("auvia_setup(%p)\n", card)); 489 490 make_device_names(card); 491 492 card->config.nabmbar = card->info.u.h0.base_registers[0]; 493 card->config.irq = card->info.u.h0.interrupt_line; 494 card->config.type = 0; 495 if(card->info.device_id == VIATECH_82C686_AC97_DEVICE_ID) 496 card->config.type |= TYPE_686; 497 if(card->info.device_id == VIATECH_8233_AC97_DEVICE_ID) 498 card->config.type |= TYPE_8233; 499 500 PRINT(("%s deviceid = %#04x chiprev = %x model = %x enhanced at %lx\n", card->name, card->info.device_id, 501 card->info.revision, card->info.u.h0.subsystem_id, card->config.nabmbar)); 502 503 cmd = (*pci->read_pci_config)(card->info.bus, card->info.device, card->info.function, PCI_command, 2); 504 PRINT(("PCI command before: %x\n", cmd)); 505 (*pci->write_pci_config)(card->info.bus, card->info.device, card->info.function, PCI_command, 2, cmd | PCI_command_io); 506 cmd = (*pci->read_pci_config)(card->info.bus, card->info.device, card->info.function, PCI_command, 2); 507 PRINT(("PCI command after: %x\n", cmd)); 508 509 /* reset the codec */ 510 PRINT(("codec reset\n")); 511 auvia_codec_write(&card->config, 0x00, 0x0000); 512 snooze(50000); // 50 ms 513 514 ac97_init(&card->config); 515 ac97_amp_enable(&card->config, true); 516 517 PRINT(("codec vendor id = %#08lx\n",ac97_get_vendor_id(&card->config))); 518 PRINT(("codec description = %s\n",ac97_get_vendor_id_description(&card->config))); 519 PRINT(("codec 3d enhancement = %s\n",ac97_get_3d_stereo_enhancement(&card->config))); 520 521 PRINT(("installing interrupt : %lx\n", card->config.irq)); 522 install_io_interrupt_handler(card->config.irq, auvia_int, card, 0); 523 524 /*PRINT(("codec master output = %#04x\n",auvia_codec_read(&card->config, 0x02))); 525 PRINT(("codec aux output = %#04x\n",auvia_codec_read(&card->config, 0x04))); 526 PRINT(("codec mono output = %#04x\n",auvia_codec_read(&card->config, 0x06))); 527 PRINT(("codec pcm output = %#04x\n",auvia_codec_read(&card->config, 0x18))); 528 PRINT(("codec line in = %#04x\n",auvia_codec_read(&card->config, 0x10))); 529 PRINT(("codec record line in= %#04x\n",auvia_codec_read(&card->config, 0x1a))); 530 PRINT(("codec record gain = %#04x\n",auvia_codec_read(&card->config, 0x1c)));*/ 531 532 PRINT(("writing codec registers\n")); 533 // TODO : to move with AC97 534 /* enable master output */ 535 auvia_codec_write(&card->config, AC97_MASTER_VOLUME, 0x0000); 536 /* enable aux output */ 537 auvia_codec_write(&card->config, AC97_AUX_OUT_VOLUME, 0x0000); 538 /* enable mono output */ 539 //auvia_codec_write(&card->config, AC97_MONO_VOLUME, 0x0004); 540 /* enable pcm output */ 541 auvia_codec_write(&card->config, AC97_PCM_OUT_VOLUME, 0x0808); 542 /* enable line in */ 543 //auvia_codec_write(&card->config, AC97_LINE_IN_VOLUME, 0x8808); 544 /* set record line in */ 545 auvia_codec_write(&card->config, AC97_RECORD_SELECT, 0x0404); 546 /* set record gain */ 547 //auvia_codec_write(&card->config, AC97_RECORD_GAIN, 0x0000); 548 549 PRINT(("codec master output = %#04x\n",auvia_codec_read(&card->config, AC97_MASTER_VOLUME))); 550 PRINT(("codec aux output = %#04x\n",auvia_codec_read(&card->config, AC97_AUX_OUT_VOLUME))); 551 PRINT(("codec mono output = %#04x\n",auvia_codec_read(&card->config, AC97_MONO_VOLUME))); 552 PRINT(("codec pcm output = %#04x\n",auvia_codec_read(&card->config, AC97_PCM_OUT_VOLUME))); 553 PRINT(("codec line in = %#04x\n",auvia_codec_read(&card->config, AC97_LINE_IN_VOLUME))); 554 PRINT(("codec record line in= %#04x\n",auvia_codec_read(&card->config, AC97_RECORD_SELECT))); 555 PRINT(("codec record gain = %#04x\n",auvia_codec_read(&card->config, AC97_RECORD_GAIN))); 556 557 if ((err = auvia_init(card))) 558 return (err); 559 560 PRINT(("init_driver done\n")); 561 562 return err; 563 } 564 565 566 status_t 567 init_driver(void) 568 { 569 pci_info info; 570 int ix = 0; 571 572 num_cards = 0; 573 574 PRINT(("init_driver()\n")); 575 576 if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci)) 577 return ENOSYS; 578 579 while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) { 580 if (info.vendor_id == VIATECH_VENDOR_ID && 581 (info.device_id == VIATECH_82C686_AC97_DEVICE_ID 582 || info.device_id == VIATECH_8233_AC97_DEVICE_ID 583 )) { 584 if (num_cards == NUM_CARDS) { 585 PRINT(("Too many auvia cards installed!\n")); 586 break; 587 } 588 memset(&cards[num_cards], 0, sizeof(auvia_dev)); 589 cards[num_cards].info = info; 590 if (auvia_setup(&cards[num_cards])) { 591 PRINT(("Setup of auvia %ld failed\n", num_cards+1)); 592 } 593 else { 594 num_cards++; 595 } 596 } 597 ix++; 598 } 599 if (!num_cards) { 600 PRINT(("no cards\n")); 601 put_module(B_PCI_MODULE_NAME); 602 PRINT(("no suitable cards found\n")); 603 return ENODEV; 604 } 605 606 607 #if DEBUG 608 //add_debugger_command("auvia", auvia_debug, "auvia [card# (1-n)]"); 609 #endif 610 return B_OK; 611 } 612 613 614 static void 615 auvia_shutdown(auvia_dev *card) 616 { 617 PRINT(("shutdown(%p)\n", card)); 618 remove_io_interrupt_handler(card->config.irq, auvia_int, card); 619 } 620 621 622 void 623 uninit_driver(void) 624 { 625 int ix, cnt = num_cards; 626 num_cards = 0; 627 628 PRINT(("uninit_driver()\n")); 629 //remove_debugger_command("auvia", auvia_debug); 630 631 for (ix=0; ix<cnt; ix++) { 632 auvia_shutdown(&cards[ix]); 633 } 634 memset(&cards, 0, sizeof(cards)); 635 put_module(B_PCI_MODULE_NAME); 636 } 637 638 639 const char ** 640 publish_devices(void) 641 { 642 int ix = 0; 643 PRINT(("publish_devices()\n")); 644 645 for (ix=0; names[ix]; ix++) { 646 PRINT(("publish %s\n", names[ix])); 647 } 648 return (const char **)names; 649 } 650 651 652 device_hooks * 653 find_device(const char * name) 654 { 655 int ix; 656 657 PRINT(("find_device(%s)\n", name)); 658 659 for (ix=0; ix<num_cards; ix++) { 660 if (!strcmp(cards[ix].name, name)) { 661 return &multi_hooks; 662 } 663 } 664 PRINT(("find_device(%s) failed\n", name)); 665 return NULL; 666 } 667 668 int32 api_version = B_CUR_DRIVER_API_VERSION; 669