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 static char pci_name[] = B_PCI_MODULE_NAME; 59 static pci_module_info *pci; 60 61 int32 num_cards; 62 auvia_dev cards[NUM_CARDS]; 63 int32 num_names; 64 char * names[NUM_CARDS*20+1]; 65 66 extern device_hooks multi_hooks; 67 68 /* Auvia Memory management */ 69 70 static auvia_mem * 71 auvia_mem_new(auvia_dev *card, size_t size) 72 { 73 auvia_mem *mem; 74 75 if ((mem = malloc(sizeof(*mem))) == NULL) 76 return (NULL); 77 78 mem->area = alloc_mem(&mem->phy_base, &mem->log_base, size, "auvia buffer"); 79 mem->size = size; 80 if (mem->area < B_OK) { 81 free(mem); 82 return NULL; 83 } 84 return mem; 85 } 86 87 static void 88 auvia_mem_delete(auvia_mem *mem) 89 { 90 if(mem->area > B_OK) 91 delete_area(mem->area); 92 free(mem); 93 } 94 95 void * 96 auvia_mem_alloc(auvia_dev *card, size_t size) 97 { 98 auvia_mem *mem; 99 100 mem = auvia_mem_new(card, size); 101 if (mem == NULL) 102 return (NULL); 103 104 LIST_INSERT_HEAD(&(card->mems), mem, next); 105 106 return mem; 107 } 108 109 void 110 auvia_mem_free(auvia_dev *card, void *ptr) 111 { 112 auvia_mem *mem; 113 114 LIST_FOREACH(mem, &card->mems, next) { 115 if (mem->log_base != ptr) 116 continue; 117 LIST_REMOVE(mem, next); 118 119 auvia_mem_delete(mem); 120 break; 121 } 122 } 123 124 /* Auvia stream functions */ 125 126 status_t 127 auvia_stream_set_audioparms(auvia_stream *stream, uint8 channels, 128 uint8 b16, uint32 sample_rate) 129 { 130 uint8 sample_size, frame_size; 131 LOG(("auvia_stream_set_audioparms\n")); 132 133 if ((stream->channels == channels) && 134 (stream->b16 == b16) && 135 (stream->sample_rate == sample_rate)) 136 return B_OK; 137 138 if(stream->buffer) 139 auvia_mem_free(stream->card, stream->buffer->log_base); 140 141 stream->b16 = b16; 142 stream->sample_rate = sample_rate; 143 stream->channels = channels; 144 145 sample_size = stream->b16 + 1; 146 frame_size = sample_size * stream->channels; 147 148 stream->buffer = auvia_mem_alloc(stream->card, stream->bufframes * frame_size * stream->bufcount); 149 150 stream->trigblk = 0; /* This shouldn't be needed */ 151 stream->blkmod = stream->bufcount; 152 stream->blksize = stream->bufframes * frame_size; 153 154 return B_OK; 155 } 156 157 status_t 158 auvia_stream_commit_parms(auvia_stream *stream) 159 { 160 int i; 161 uint32 *page; 162 uint32 value; 163 LOG(("auvia_stream_commit_parms\n")); 164 165 page = stream->dmaops_log_base; 166 167 for(i=0; i<stream->bufcount; i++) { 168 page[2*i] = ((uint32)stream->buffer->phy_base) + 169 i * stream->blksize; 170 page[2*i + 1] = AUVIA_DMAOP_FLAG | stream->blksize; 171 } 172 173 page[2*stream->bufcount - 1] &= ~AUVIA_DMAOP_FLAG; 174 page[2*stream->bufcount - 1] |= AUVIA_DMAOP_EOL; 175 176 auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE, 177 (uint32)stream->dmaops_phy_base); 178 179 if(stream->use & AUVIA_USE_RECORD) 180 auvia_codec_write(&stream->card->config, AC97_PCM_LR_ADC_RATE, (uint16)stream->sample_rate); 181 else 182 auvia_codec_write(&stream->card->config, AC97_PCM_FRONT_DAC_RATE, (uint16)stream->sample_rate); 183 184 if(IS_8233(&stream->card->config)) { 185 if(stream->base != AUVIA_8233_MP_BASE) { 186 value = auvia_reg_read_32(&stream->card->config, stream->base + AUVIA_8233_RP_RATEFMT); 187 value &= ~(AUVIA_8233_RATEFMT_48K | AUVIA_8233_RATEFMT_STEREO | AUVIA_8233_RATEFMT_16BIT); 188 if(stream->use & AUVIA_USE_PLAY) 189 value |= AUVIA_8233_RATEFMT_48K * (stream->sample_rate / 20) / (48000 / 20); 190 value |= (stream->channels == 2 ? AUVIA_8233_RATEFMT_STEREO : 0) 191 | (stream->b16 ? AUVIA_8233_RATEFMT_16BIT : 0); 192 auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_8233_RP_RATEFMT, value); 193 } else { 194 static const uint32 slottab[7] = {0, 0xff000011, 0xff000021, 0xff000521, 195 0xff004321, 0xff054321, 0xff654321}; 196 value = (stream->b16 ? AUVIA_8233_MP_FORMAT_16BIT : AUVIA_8233_MP_FORMAT_8BIT) 197 | ((stream->channels << 4) & AUVIA_8233_MP_FORMAT_CHANNEL_MASK) ; 198 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_8233_OFF_MP_FORMAT, value); 199 auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_8233_OFF_MP_STOP, 200 slottab[stream->channels]); 201 } 202 } 203 //auvia_codec_write(&stream->card->config, AC97_SPDIF_CONTROL, (uint16)stream->sample_rate); 204 205 return B_OK; 206 } 207 208 status_t 209 auvia_stream_get_nth_buffer(auvia_stream *stream, uint8 chan, uint8 buf, 210 char** buffer, size_t *stride) 211 { 212 uint8 sample_size, frame_size; 213 LOG(("auvia_stream_get_nth_buffer\n")); 214 215 sample_size = stream->b16 + 1; 216 frame_size = sample_size * stream->channels; 217 218 *buffer = stream->buffer->log_base + (buf * stream->bufframes * frame_size) 219 + chan * sample_size; 220 *stride = frame_size; 221 222 return B_OK; 223 } 224 225 static uint32 226 auvia_stream_curaddr(auvia_stream *stream) 227 { 228 uint32 addr; 229 if(IS_8233(&stream->card->config)) { 230 addr = auvia_reg_read_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE); 231 TRACE(("stream_curaddr %p, phy_base %p\n", addr, (uint32)stream->dmaops_phy_base)); 232 return (addr - (uint32)stream->dmaops_phy_base - 4) / 8; 233 } else { 234 addr = auvia_reg_read_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE); 235 TRACE(("stream_curaddr %p, phy_base %p\n", addr, (uint32)stream->dmaops_phy_base)); 236 return (addr - (uint32)stream->dmaops_phy_base - 8) / 8; 237 } 238 } 239 240 void 241 auvia_stream_start(auvia_stream *stream, void (*inth) (void *), void *inthparam) 242 { 243 LOG(("auvia_stream_start\n")); 244 245 stream->inth = inth; 246 stream->inthparam = inthparam; 247 248 stream->state |= AUVIA_STATE_STARTED; 249 250 if(IS_8233(&stream->card->config)) { 251 if(stream->base != AUVIA_8233_MP_BASE) { 252 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_8233_RP_DXS_LVOL, 0); 253 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_8233_RP_DXS_RVOL, 0); 254 } 255 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_RP_CONTROL, 256 AUVIA_RPCTRL_START | AUVIA_RPCTRL_AUTOSTART | AUVIA_RPCTRL_STOP 257 | AUVIA_RPCTRL_EOL | AUVIA_RPCTRL_FLAG); 258 } else { 259 uint8 regvalue = (stream->channels > 1 ? AUVIA_RPMODE_STEREO : 0) 260 | (stream->b16 == 1 ? AUVIA_RPMODE_16BIT : 0) 261 | AUVIA_RPMODE_INTR_FLAG | AUVIA_RPMODE_INTR_EOL | AUVIA_RPMODE_AUTOSTART; 262 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_RP_MODE, regvalue); 263 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_RP_CONTROL, AUVIA_RPCTRL_START); 264 } 265 } 266 267 void 268 auvia_stream_halt(auvia_stream *stream) 269 { 270 LOG(("auvia_stream_halt\n")); 271 272 stream->state &= ~AUVIA_STATE_STARTED; 273 274 auvia_reg_write_8(&stream->card->config, stream->base + AUVIA_RP_CONTROL, AUVIA_RPCTRL_TERMINATE); 275 } 276 277 auvia_stream * 278 auvia_stream_new(auvia_dev *card, uint8 use, uint32 bufframes, uint8 bufcount) 279 { 280 auvia_stream *stream; 281 cpu_status status; 282 LOG(("auvia_stream_new\n")); 283 284 stream = malloc(sizeof(auvia_stream)); 285 if (stream == NULL) 286 return (NULL); 287 stream->card = card; 288 stream->use = use; 289 stream->state = !AUVIA_STATE_STARTED; 290 stream->b16 = 0; 291 stream->sample_rate = 0; 292 stream->channels = 0; 293 stream->bufframes = bufframes; 294 stream->bufcount = bufcount; 295 stream->inth = NULL; 296 stream->inthparam = NULL; 297 stream->buffer = NULL; 298 stream->blksize = 0; 299 stream->trigblk = 0; 300 stream->blkmod = 0; 301 302 if(use & AUVIA_USE_PLAY) { 303 if(IS_8233(&card->config)) 304 stream->base = AUVIA_8233_MP_BASE; 305 //stream->base = AUVIA_PLAY_BASE; 306 else 307 stream->base = AUVIA_PLAY_BASE; 308 } else { 309 if(IS_8233(&card->config)) 310 stream->base = AUVIA_8233_RECORD_BASE; 311 else 312 stream->base = AUVIA_RECORD_BASE; 313 } 314 315 stream->frames_count = 0; 316 stream->real_time = 0; 317 stream->update_needed = false; 318 319 /* allocate memory for our dma ops */ 320 stream->dmaops_area = alloc_mem(&stream->dmaops_phy_base, &stream->dmaops_log_base, 321 VIA_TABLE_SIZE, "auvia dmaops"); 322 323 if (stream->dmaops_area < B_OK) { 324 PRINT(("couldn't allocate memory\n")); 325 free(stream); 326 return NULL; 327 } 328 329 status = lock(); 330 LIST_INSERT_HEAD((&card->streams), stream, next); 331 unlock(status); 332 333 return stream; 334 } 335 336 void 337 auvia_stream_delete(auvia_stream *stream) 338 { 339 cpu_status status; 340 LOG(("auvia_stream_delete\n")); 341 342 auvia_stream_halt(stream); 343 344 auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE, 0); 345 346 if (stream->dmaops_area > B_OK) 347 delete_area(stream->dmaops_area); 348 349 if(stream->buffer) 350 auvia_mem_free(stream->card, stream->buffer->log_base); 351 352 status = lock(); 353 LIST_REMOVE(stream, next); 354 unlock(status); 355 356 free(stream); 357 } 358 359 /* Auvia interrupt */ 360 361 int32 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_HANDLED_INTERRUPT; 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(pci_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(pci_name); 429 430 return err; 431 } 432 433 static void 434 make_device_names( 435 auvia_dev * card) 436 { 437 sprintf(card->name, "audio/multi/auvia/%ld", card-cards+1); 438 names[num_names++] = card->name; 439 440 names[num_names] = NULL; 441 } 442 443 444 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: %x\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: %x\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 %x\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 = %#08x\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 : %x\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 int ix=0; 570 571 pci_info info; 572 num_cards = 0; 573 574 PRINT(("init_driver()\n")); 575 load_driver_symbols("auvia"); 576 577 if (get_module(pci_name, (module_info **) &pci)) 578 return ENOSYS; 579 580 while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) { 581 if (info.vendor_id == VIATECH_VENDOR_ID && 582 (info.device_id == VIATECH_82C686_AC97_DEVICE_ID 583 || info.device_id == VIATECH_8233_AC97_DEVICE_ID 584 )) { 585 if (num_cards == NUM_CARDS) { 586 PRINT(("Too many auvia cards installed!\n")); 587 break; 588 } 589 memset(&cards[num_cards], 0, sizeof(auvia_dev)); 590 cards[num_cards].info = info; 591 if (auvia_setup(&cards[num_cards])) { 592 PRINT(("Setup of auvia %ld failed\n", num_cards+1)); 593 } 594 else { 595 num_cards++; 596 } 597 } 598 ix++; 599 } 600 if (!num_cards) { 601 PRINT(("no cards\n")); 602 put_module(pci_name); 603 PRINT(("no suitable cards found\n")); 604 return ENODEV; 605 } 606 607 608 #if DEBUG 609 //add_debugger_command("auvia", auvia_debug, "auvia [card# (1-n)]"); 610 #endif 611 return B_OK; 612 } 613 614 615 static void 616 auvia_shutdown(auvia_dev *card) 617 { 618 PRINT(("shutdown(%p)\n", card)); 619 remove_io_interrupt_handler(card->config.irq, auvia_int, card); 620 } 621 622 623 void 624 uninit_driver(void) 625 { 626 int ix, cnt = num_cards; 627 num_cards = 0; 628 629 PRINT(("uninit_driver()\n")); 630 //remove_debugger_command("auvia", auvia_debug); 631 632 for (ix=0; ix<cnt; ix++) { 633 auvia_shutdown(&cards[ix]); 634 } 635 memset(&cards, 0, sizeof(cards)); 636 put_module(pci_name); 637 } 638 639 640 const char ** 641 publish_devices(void) 642 { 643 int ix = 0; 644 PRINT(("publish_devices()\n")); 645 646 for (ix=0; names[ix]; ix++) { 647 PRINT(("publish %s\n", names[ix])); 648 } 649 return (const char **)names; 650 } 651 652 653 device_hooks * 654 find_device(const char * name) 655 { 656 int ix; 657 658 PRINT(("find_device(%s)\n", name)); 659 660 for (ix=0; ix<num_cards; ix++) { 661 if (!strcmp(cards[ix].name, name)) { 662 return &multi_hooks; 663 } 664 } 665 PRINT(("find_device(%s) failed\n", name)); 666 return NULL; 667 } 668 669 int32 api_version = B_CUR_DRIVER_API_VERSION; 670