1 /* 2 * Driver for Digigram VX soundcards 3 * 4 * Hardware core part 5 * 6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 #include <sound/driver.h> 24 #include <linux/delay.h> 25 #include <linux/slab.h> 26 #include <linux/interrupt.h> 27 #include <linux/init.h> 28 #include <linux/device.h> 29 #include <linux/firmware.h> 30 #include <sound/core.h> 31 #include <sound/pcm.h> 32 #include <sound/asoundef.h> 33 #include <sound/info.h> 34 #include <asm/io.h> 35 #include <sound/vx_core.h> 36 #include "vx_cmd.h" 37 38 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); 39 MODULE_DESCRIPTION("Common routines for Digigram VX drivers"); 40 MODULE_LICENSE("GPL"); 41 42 43 /* 44 * vx_check_reg_bit - wait for the specified bit is set/reset on a register 45 * @reg: register to check 46 * @mask: bit mask 47 * @bit: resultant bit to be checked 48 * @time: time-out of loop in msec 49 * 50 * returns zero if a bit matches, or a negative error code. 51 */ 52 int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int time) 53 { 54 unsigned long end_time = jiffies + (time * HZ + 999) / 1000; 55 #ifdef CONFIG_SND_DEBUG 56 static char *reg_names[VX_REG_MAX] = { 57 "ICR", "CVR", "ISR", "IVR", "RXH", "RXM", "RXL", 58 "DMA", "CDSP", "RFREQ", "RUER/V2", "DATA", "MEMIRQ", 59 "ACQ", "BIT0", "BIT1", "MIC0", "MIC1", "MIC2", 60 "MIC3", "INTCSR", "CNTRL", "GPIOC", 61 "LOFREQ", "HIFREQ", "CSUER", "RUER" 62 }; 63 #endif 64 do { 65 if ((snd_vx_inb(chip, reg) & mask) == bit) 66 return 0; 67 //msleep(10); 68 } while (time_after_eq(end_time, jiffies)); 69 snd_printd(KERN_DEBUG "vx_check_reg_bit: timeout, reg=%s, mask=0x%x, val=0x%x\n", reg_names[reg], mask, snd_vx_inb(chip, reg)); 70 return -EIO; 71 } 72 73 /* 74 * vx_send_irq_dsp - set command irq bit 75 * @num: the requested IRQ type, IRQ_XXX 76 * 77 * this triggers the specified IRQ request 78 * returns 0 if successful, or a negative error code. 79 * 80 */ 81 static int vx_send_irq_dsp(struct vx_core *chip, int num) 82 { 83 int nirq; 84 85 /* wait for Hc = 0 */ 86 if (snd_vx_check_reg_bit(chip, VX_CVR, CVR_HC, 0, 200) < 0) 87 return -EIO; 88 89 nirq = num; 90 if (vx_has_new_dsp(chip)) 91 nirq += VXP_IRQ_OFFSET; 92 vx_outb(chip, CVR, (nirq >> 1) | CVR_HC); 93 return 0; 94 } 95 96 97 /* 98 * vx_reset_chk - reset CHK bit on ISR 99 * 100 * returns 0 if successful, or a negative error code. 101 */ 102 static int vx_reset_chk(struct vx_core *chip) 103 { 104 /* Reset irq CHK */ 105 if (vx_send_irq_dsp(chip, IRQ_RESET_CHK) < 0) 106 return -EIO; 107 /* Wait until CHK = 0 */ 108 if (vx_check_isr(chip, ISR_CHK, 0, 200) < 0) 109 return -EIO; 110 return 0; 111 } 112 113 /* 114 * vx_transfer_end - terminate message transfer 115 * @cmd: IRQ message to send (IRQ_MESS_XXX_END) 116 * 117 * returns 0 if successful, or a negative error code. 118 * the error code can be VX-specific, retrieved via vx_get_error(). 119 * NB: call with spinlock held! 120 */ 121 static int vx_transfer_end(struct vx_core *chip, int cmd) 122 { 123 int err; 124 125 if ((err = vx_reset_chk(chip)) < 0) 126 return err; 127 128 /* irq MESS_READ/WRITE_END */ 129 if ((err = vx_send_irq_dsp(chip, cmd)) < 0) 130 return err; 131 132 /* Wait CHK = 1 */ 133 if ((err = vx_wait_isr_bit(chip, ISR_CHK)) < 0) 134 return err; 135 136 /* If error, Read RX */ 137 if ((err = vx_inb(chip, ISR)) & ISR_ERR) { 138 if ((err = vx_wait_for_rx_full(chip)) < 0) { 139 snd_printd(KERN_DEBUG "transfer_end: error in rx_full\n"); 140 return err; 141 } 142 err = vx_inb(chip, RXH) << 16; 143 err |= vx_inb(chip, RXM) << 8; 144 err |= vx_inb(chip, RXL); 145 snd_printd(KERN_DEBUG "transfer_end: error = 0x%x\n", err); 146 return -(VX_ERR_MASK | err); 147 } 148 return 0; 149 } 150 151 /* 152 * vx_read_status - return the status rmh 153 * @rmh: rmh record to store the status 154 * 155 * returns 0 if successful, or a negative error code. 156 * the error code can be VX-specific, retrieved via vx_get_error(). 157 * NB: call with spinlock held! 158 */ 159 static int vx_read_status(struct vx_core *chip, struct vx_rmh *rmh) 160 { 161 int i, err, val, size; 162 163 /* no read necessary? */ 164 if (rmh->DspStat == RMH_SSIZE_FIXED && rmh->LgStat == 0) 165 return 0; 166 167 /* Wait for RX full (with timeout protection) 168 * The first word of status is in RX 169 */ 170 err = vx_wait_for_rx_full(chip); 171 if (err < 0) 172 return err; 173 174 /* Read RX */ 175 val = vx_inb(chip, RXH) << 16; 176 val |= vx_inb(chip, RXM) << 8; 177 val |= vx_inb(chip, RXL); 178 179 /* If status given by DSP, let's decode its size */ 180 switch (rmh->DspStat) { 181 case RMH_SSIZE_ARG: 182 size = val & 0xff; 183 rmh->Stat[0] = val & 0xffff00; 184 rmh->LgStat = size + 1; 185 break; 186 case RMH_SSIZE_MASK: 187 /* Let's count the arg numbers from a mask */ 188 rmh->Stat[0] = val; 189 size = 0; 190 while (val) { 191 if (val & 0x01) 192 size++; 193 val >>= 1; 194 } 195 rmh->LgStat = size + 1; 196 break; 197 default: 198 /* else retrieve the status length given by the driver */ 199 size = rmh->LgStat; 200 rmh->Stat[0] = val; /* Val is the status 1st word */ 201 size--; /* hence adjust remaining length */ 202 break; 203 } 204 205 if (size < 1) 206 return 0; 207 snd_assert(size <= SIZE_MAX_STATUS, return -EINVAL); 208 209 for (i = 1; i <= size; i++) { 210 /* trigger an irq MESS_WRITE_NEXT */ 211 err = vx_send_irq_dsp(chip, IRQ_MESS_WRITE_NEXT); 212 if (err < 0) 213 return err; 214 /* Wait for RX full (with timeout protection) */ 215 err = vx_wait_for_rx_full(chip); 216 if (err < 0) 217 return err; 218 rmh->Stat[i] = vx_inb(chip, RXH) << 16; 219 rmh->Stat[i] |= vx_inb(chip, RXM) << 8; 220 rmh->Stat[i] |= vx_inb(chip, RXL); 221 } 222 223 return vx_transfer_end(chip, IRQ_MESS_WRITE_END); 224 } 225 226 227 #define MASK_MORE_THAN_1_WORD_COMMAND 0x00008000 228 #define MASK_1_WORD_COMMAND 0x00ff7fff 229 230 /* 231 * vx_send_msg_nolock - send a DSP message and read back the status 232 * @rmh: the rmh record to send and receive 233 * 234 * returns 0 if successful, or a negative error code. 235 * the error code can be VX-specific, retrieved via vx_get_error(). 236 * 237 * this function doesn't call spinlock at all. 238 */ 239 int vx_send_msg_nolock(struct vx_core *chip, struct vx_rmh *rmh) 240 { 241 int i, err; 242 243 if (chip->chip_status & VX_STAT_IS_STALE) 244 return -EBUSY; 245 246 if ((err = vx_reset_chk(chip)) < 0) { 247 snd_printd(KERN_DEBUG "vx_send_msg: vx_reset_chk error\n"); 248 return err; 249 } 250 251 #if 0 252 printk(KERN_DEBUG "rmh: cmd = 0x%06x, length = %d, stype = %d\n", 253 rmh->Cmd[0], rmh->LgCmd, rmh->DspStat); 254 if (rmh->LgCmd > 1) { 255 printk(KERN_DEBUG " "); 256 for (i = 1; i < rmh->LgCmd; i++) 257 printk("0x%06x ", rmh->Cmd[i]); 258 printk("\n"); 259 } 260 #endif 261 /* Check bit M is set according to length of the command */ 262 if (rmh->LgCmd > 1) 263 rmh->Cmd[0] |= MASK_MORE_THAN_1_WORD_COMMAND; 264 else 265 rmh->Cmd[0] &= MASK_1_WORD_COMMAND; 266 267 /* Wait for TX empty */ 268 if ((err = vx_wait_isr_bit(chip, ISR_TX_EMPTY)) < 0) { 269 snd_printd(KERN_DEBUG "vx_send_msg: wait tx empty error\n"); 270 return err; 271 } 272 273 /* Write Cmd[0] */ 274 vx_outb(chip, TXH, (rmh->Cmd[0] >> 16) & 0xff); 275 vx_outb(chip, TXM, (rmh->Cmd[0] >> 8) & 0xff); 276 vx_outb(chip, TXL, rmh->Cmd[0] & 0xff); 277 278 /* Trigger irq MESSAGE */ 279 if ((err = vx_send_irq_dsp(chip, IRQ_MESSAGE)) < 0) { 280 snd_printd(KERN_DEBUG "vx_send_msg: send IRQ_MESSAGE error\n"); 281 return err; 282 } 283 284 /* Wait for CHK = 1 */ 285 if ((err = vx_wait_isr_bit(chip, ISR_CHK)) < 0) 286 return err; 287 288 /* If error, get error value from RX */ 289 if (vx_inb(chip, ISR) & ISR_ERR) { 290 if ((err = vx_wait_for_rx_full(chip)) < 0) { 291 snd_printd(KERN_DEBUG "vx_send_msg: rx_full read error\n"); 292 return err; 293 } 294 err = vx_inb(chip, RXH) << 16; 295 err |= vx_inb(chip, RXM) << 8; 296 err |= vx_inb(chip, RXL); 297 snd_printd(KERN_DEBUG "msg got error = 0x%x at cmd[0]\n", err); 298 err = -(VX_ERR_MASK | err); 299 return err; 300 } 301 302 /* Send the other words */ 303 if (rmh->LgCmd > 1) { 304 for (i = 1; i < rmh->LgCmd; i++) { 305 /* Wait for TX ready */ 306 if ((err = vx_wait_isr_bit(chip, ISR_TX_READY)) < 0) { 307 snd_printd(KERN_DEBUG "vx_send_msg: tx_ready error\n"); 308 return err; 309 } 310 311 /* Write Cmd[i] */ 312 vx_outb(chip, TXH, (rmh->Cmd[i] >> 16) & 0xff); 313 vx_outb(chip, TXM, (rmh->Cmd[i] >> 8) & 0xff); 314 vx_outb(chip, TXL, rmh->Cmd[i] & 0xff); 315 316 /* Trigger irq MESS_READ_NEXT */ 317 if ((err = vx_send_irq_dsp(chip, IRQ_MESS_READ_NEXT)) < 0) { 318 snd_printd(KERN_DEBUG "vx_send_msg: IRQ_READ_NEXT error\n"); 319 return err; 320 } 321 } 322 /* Wait for TX empty */ 323 if ((err = vx_wait_isr_bit(chip, ISR_TX_READY)) < 0) { 324 snd_printd(KERN_DEBUG "vx_send_msg: TX_READY error\n"); 325 return err; 326 } 327 /* End of transfer */ 328 err = vx_transfer_end(chip, IRQ_MESS_READ_END); 329 if (err < 0) 330 return err; 331 } 332 333 return vx_read_status(chip, rmh); 334 } 335 336 337 /* 338 * vx_send_msg - send a DSP message with spinlock 339 * @rmh: the rmh record to send and receive 340 * 341 * returns 0 if successful, or a negative error code. 342 * see vx_send_msg_nolock(). 343 */ 344 int vx_send_msg(struct vx_core *chip, struct vx_rmh *rmh) 345 { 346 unsigned long flags; 347 int err; 348 349 spin_lock_irqsave(&chip->lock, flags); 350 err = vx_send_msg_nolock(chip, rmh); 351 spin_unlock_irqrestore(&chip->lock, flags); 352 return err; 353 } 354 355 356 /* 357 * vx_send_rih_nolock - send an RIH to xilinx 358 * @cmd: the command to send 359 * 360 * returns 0 if successful, or a negative error code. 361 * the error code can be VX-specific, retrieved via vx_get_error(). 362 * 363 * this function doesn't call spinlock at all. 364 * 365 * unlike RMH, no command is sent to DSP. 366 */ 367 int vx_send_rih_nolock(struct vx_core *chip, int cmd) 368 { 369 int err; 370 371 if (chip->chip_status & VX_STAT_IS_STALE) 372 return -EBUSY; 373 374 #if 0 375 printk(KERN_DEBUG "send_rih: cmd = 0x%x\n", cmd); 376 #endif 377 if ((err = vx_reset_chk(chip)) < 0) 378 return err; 379 /* send the IRQ */ 380 if ((err = vx_send_irq_dsp(chip, cmd)) < 0) 381 return err; 382 /* Wait CHK = 1 */ 383 if ((err = vx_wait_isr_bit(chip, ISR_CHK)) < 0) 384 return err; 385 /* If error, read RX */ 386 if (vx_inb(chip, ISR) & ISR_ERR) { 387 if ((err = vx_wait_for_rx_full(chip)) < 0) 388 return err; 389 err = vx_inb(chip, RXH) << 16; 390 err |= vx_inb(chip, RXM) << 8; 391 err |= vx_inb(chip, RXL); 392 return -(VX_ERR_MASK | err); 393 } 394 return 0; 395 } 396 397 398 /* 399 * vx_send_rih - send an RIH with spinlock 400 * @cmd: the command to send 401 * 402 * see vx_send_rih_nolock(). 403 */ 404 int vx_send_rih(struct vx_core *chip, int cmd) 405 { 406 unsigned long flags; 407 int err; 408 409 spin_lock_irqsave(&chip->lock, flags); 410 err = vx_send_rih_nolock(chip, cmd); 411 spin_unlock_irqrestore(&chip->lock, flags); 412 return err; 413 } 414 415 #define END_OF_RESET_WAIT_TIME 500 /* us */ 416 417 /** 418 * snd_vx_boot_xilinx - boot up the xilinx interface 419 * @boot: the boot record to load 420 */ 421 int snd_vx_load_boot_image(struct vx_core *chip, const struct firmware *boot) 422 { 423 unsigned int i; 424 int no_fillup = vx_has_new_dsp(chip); 425 426 /* check the length of boot image */ 427 snd_assert(boot->size > 0, return -EINVAL); 428 snd_assert(boot->size % 3 == 0, return -EINVAL); 429 #if 0 430 { 431 /* more strict check */ 432 unsigned int c = ((u32)boot->data[0] << 16) | ((u32)boot->data[1] << 8) | boot->data[2]; 433 snd_assert(boot->size == (c + 2) * 3, return -EINVAL); 434 } 435 #endif 436 437 /* reset dsp */ 438 vx_reset_dsp(chip); 439 440 udelay(END_OF_RESET_WAIT_TIME); /* another wait? */ 441 442 /* download boot strap */ 443 for (i = 0; i < 0x600; i += 3) { 444 if (i >= boot->size) { 445 if (no_fillup) 446 break; 447 if (vx_wait_isr_bit(chip, ISR_TX_EMPTY) < 0) { 448 snd_printk(KERN_ERR "dsp boot failed at %d\n", i); 449 return -EIO; 450 } 451 vx_outb(chip, TXH, 0); 452 vx_outb(chip, TXM, 0); 453 vx_outb(chip, TXL, 0); 454 } else { 455 unsigned char *image = boot->data + i; 456 if (vx_wait_isr_bit(chip, ISR_TX_EMPTY) < 0) { 457 snd_printk(KERN_ERR "dsp boot failed at %d\n", i); 458 return -EIO; 459 } 460 vx_outb(chip, TXH, image[0]); 461 vx_outb(chip, TXM, image[1]); 462 vx_outb(chip, TXL, image[2]); 463 } 464 } 465 return 0; 466 } 467 468 /* 469 * vx_test_irq_src - query the source of interrupts 470 * 471 * called from irq handler only 472 */ 473 static int vx_test_irq_src(struct vx_core *chip, unsigned int *ret) 474 { 475 int err; 476 477 vx_init_rmh(&chip->irq_rmh, CMD_TEST_IT); 478 spin_lock(&chip->lock); 479 err = vx_send_msg_nolock(chip, &chip->irq_rmh); 480 if (err < 0) 481 *ret = 0; 482 else 483 *ret = chip->irq_rmh.Stat[0]; 484 spin_unlock(&chip->lock); 485 return err; 486 } 487 488 489 /* 490 * vx_interrupt - soft irq handler 491 */ 492 static void vx_interrupt(unsigned long private_data) 493 { 494 struct vx_core *chip = (struct vx_core *) private_data; 495 unsigned int events; 496 497 if (chip->chip_status & VX_STAT_IS_STALE) 498 return; 499 500 if (vx_test_irq_src(chip, &events) < 0) 501 return; 502 503 #if 0 504 if (events & 0x000800) 505 printk(KERN_ERR "DSP Stream underrun ! IRQ events = 0x%x\n", events); 506 #endif 507 // printk(KERN_DEBUG "IRQ events = 0x%x\n", events); 508 509 /* We must prevent any application using this DSP 510 * and block any further request until the application 511 * either unregisters or reloads the DSP 512 */ 513 if (events & FATAL_DSP_ERROR) { 514 snd_printk(KERN_ERR "vx_core: fatal DSP error!!\n"); 515 return; 516 } 517 518 /* The start on time code conditions are filled (ie the time code 519 * received by the board is equal to one of those given to it). 520 */ 521 if (events & TIME_CODE_EVENT_PENDING) 522 ; /* so far, nothing to do yet */ 523 524 /* The frequency has changed on the board (UER mode). */ 525 if (events & FREQUENCY_CHANGE_EVENT_PENDING) 526 vx_change_frequency(chip); 527 528 /* update the pcm streams */ 529 vx_pcm_update_intr(chip, events); 530 } 531 532 533 /** 534 * snd_vx_irq_handler - interrupt handler 535 */ 536 irqreturn_t snd_vx_irq_handler(int irq, void *dev, struct pt_regs *regs) 537 { 538 struct vx_core *chip = dev; 539 540 if (! (chip->chip_status & VX_STAT_CHIP_INIT) || 541 (chip->chip_status & VX_STAT_IS_STALE)) 542 return IRQ_NONE; 543 if (! vx_test_and_ack(chip)) 544 tasklet_hi_schedule(&chip->tq); 545 return IRQ_HANDLED; 546 } 547 548 549 /* 550 */ 551 static void vx_reset_board(struct vx_core *chip, int cold_reset) 552 { 553 snd_assert(chip->ops->reset_board, return); 554 555 /* current source, later sync'ed with target */ 556 chip->audio_source = VX_AUDIO_SRC_LINE; 557 if (cold_reset) { 558 chip->audio_source_target = chip->audio_source; 559 chip->clock_source = INTERNAL_QUARTZ; 560 chip->clock_mode = VX_CLOCK_MODE_AUTO; 561 chip->freq = 48000; 562 chip->uer_detected = VX_UER_MODE_NOT_PRESENT; 563 chip->uer_bits = SNDRV_PCM_DEFAULT_CON_SPDIF; 564 } 565 566 chip->ops->reset_board(chip, cold_reset); 567 568 vx_reset_codec(chip, cold_reset); 569 570 vx_set_internal_clock(chip, chip->freq); 571 572 /* Reset the DSP */ 573 vx_reset_dsp(chip); 574 575 if (vx_is_pcmcia(chip)) { 576 /* Acknowledge any pending IRQ and reset the MEMIRQ flag. */ 577 vx_test_and_ack(chip); 578 vx_validate_irq(chip, 1); 579 } 580 581 /* init CBits */ 582 vx_set_iec958_status(chip, chip->uer_bits); 583 } 584 585 586 /* 587 * proc interface 588 */ 589 590 static void vx_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 591 { 592 struct vx_core *chip = entry->private_data; 593 static char *audio_src_vxp[] = { "Line", "Mic", "Digital" }; 594 static char *audio_src_vx2[] = { "Analog", "Analog", "Digital" }; 595 static char *clock_mode[] = { "Auto", "Internal", "External" }; 596 static char *clock_src[] = { "Internal", "External" }; 597 static char *uer_type[] = { "Consumer", "Professional", "Not Present" }; 598 599 snd_iprintf(buffer, "%s\n", chip->card->longname); 600 snd_iprintf(buffer, "Xilinx Firmware: %s\n", 601 chip->chip_status & VX_STAT_XILINX_LOADED ? "Loaded" : "No"); 602 snd_iprintf(buffer, "Device Initialized: %s\n", 603 chip->chip_status & VX_STAT_DEVICE_INIT ? "Yes" : "No"); 604 snd_iprintf(buffer, "DSP audio info:"); 605 if (chip->audio_info & VX_AUDIO_INFO_REAL_TIME) 606 snd_iprintf(buffer, " realtime"); 607 if (chip->audio_info & VX_AUDIO_INFO_OFFLINE) 608 snd_iprintf(buffer, " offline"); 609 if (chip->audio_info & VX_AUDIO_INFO_MPEG1) 610 snd_iprintf(buffer, " mpeg1"); 611 if (chip->audio_info & VX_AUDIO_INFO_MPEG2) 612 snd_iprintf(buffer, " mpeg2"); 613 if (chip->audio_info & VX_AUDIO_INFO_LINEAR_8) 614 snd_iprintf(buffer, " linear8"); 615 if (chip->audio_info & VX_AUDIO_INFO_LINEAR_16) 616 snd_iprintf(buffer, " linear16"); 617 if (chip->audio_info & VX_AUDIO_INFO_LINEAR_24) 618 snd_iprintf(buffer, " linear24"); 619 snd_iprintf(buffer, "\n"); 620 snd_iprintf(buffer, "Input Source: %s\n", vx_is_pcmcia(chip) ? 621 audio_src_vxp[chip->audio_source] : 622 audio_src_vx2[chip->audio_source]); 623 snd_iprintf(buffer, "Clock Mode: %s\n", clock_mode[chip->clock_mode]); 624 snd_iprintf(buffer, "Clock Source: %s\n", clock_src[chip->clock_source]); 625 snd_iprintf(buffer, "Frequency: %d\n", chip->freq); 626 snd_iprintf(buffer, "Detected Frequency: %d\n", chip->freq_detected); 627 snd_iprintf(buffer, "Detected UER type: %s\n", uer_type[chip->uer_detected]); 628 snd_iprintf(buffer, "Min/Max/Cur IBL: %d/%d/%d (granularity=%d)\n", 629 chip->ibl.min_size, chip->ibl.max_size, chip->ibl.size, 630 chip->ibl.granularity); 631 } 632 633 static void vx_proc_init(struct vx_core *chip) 634 { 635 struct snd_info_entry *entry; 636 637 if (! snd_card_proc_new(chip->card, "vx-status", &entry)) 638 snd_info_set_text_ops(entry, chip, 1024, vx_proc_read); 639 } 640 641 642 /** 643 * snd_vx_dsp_boot - load the DSP boot 644 */ 645 int snd_vx_dsp_boot(struct vx_core *chip, const struct firmware *boot) 646 { 647 int err; 648 int cold_reset = !(chip->chip_status & VX_STAT_DEVICE_INIT); 649 650 vx_reset_board(chip, cold_reset); 651 vx_validate_irq(chip, 0); 652 653 if ((err = snd_vx_load_boot_image(chip, boot)) < 0) 654 return err; 655 msleep(10); 656 657 return 0; 658 } 659 660 /** 661 * snd_vx_dsp_load - load the DSP image 662 */ 663 int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp) 664 { 665 unsigned int i; 666 int err; 667 unsigned int csum = 0; 668 unsigned char *image, *cptr; 669 670 snd_assert(dsp->size % 3 == 0, return -EINVAL); 671 672 vx_toggle_dac_mute(chip, 1); 673 674 /* Transfert data buffer from PC to DSP */ 675 for (i = 0; i < dsp->size; i += 3) { 676 image = dsp->data + i; 677 /* Wait DSP ready for a new read */ 678 if ((err = vx_wait_isr_bit(chip, ISR_TX_EMPTY)) < 0) { 679 printk("dsp loading error at position %d\n", i); 680 return err; 681 } 682 cptr = image; 683 csum ^= *cptr; 684 csum = (csum >> 24) | (csum << 8); 685 vx_outb(chip, TXH, *cptr++); 686 csum ^= *cptr; 687 csum = (csum >> 24) | (csum << 8); 688 vx_outb(chip, TXM, *cptr++); 689 csum ^= *cptr; 690 csum = (csum >> 24) | (csum << 8); 691 vx_outb(chip, TXL, *cptr++); 692 } 693 snd_printdd(KERN_DEBUG "checksum = 0x%08x\n", csum); 694 695 msleep(200); 696 697 if ((err = vx_wait_isr_bit(chip, ISR_CHK)) < 0) 698 return err; 699 700 vx_toggle_dac_mute(chip, 0); 701 702 vx_test_and_ack(chip); 703 vx_validate_irq(chip, 1); 704 705 return 0; 706 } 707 708 #ifdef CONFIG_PM 709 /* 710 * suspend 711 */ 712 int snd_vx_suspend(struct vx_core *chip, pm_message_t state) 713 { 714 unsigned int i; 715 716 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); 717 chip->chip_status |= VX_STAT_IN_SUSPEND; 718 for (i = 0; i < chip->hw->num_codecs; i++) 719 snd_pcm_suspend_all(chip->pcm[i]); 720 721 return 0; 722 } 723 724 /* 725 * resume 726 */ 727 int snd_vx_resume(struct vx_core *chip) 728 { 729 int i, err; 730 731 chip->chip_status &= ~VX_STAT_CHIP_INIT; 732 733 for (i = 0; i < 4; i++) { 734 if (! chip->firmware[i]) 735 continue; 736 err = chip->ops->load_dsp(chip, i, chip->firmware[i]); 737 if (err < 0) { 738 snd_printk(KERN_ERR "vx: firmware resume error at DSP %d\n", i); 739 return -EIO; 740 } 741 } 742 743 chip->chip_status |= VX_STAT_CHIP_INIT; 744 chip->chip_status &= ~VX_STAT_IN_SUSPEND; 745 746 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); 747 return 0; 748 } 749 750 #endif 751 752 /** 753 * snd_vx_create - constructor for struct vx_core 754 * @hw: hardware specific record 755 * 756 * this function allocates the instance and prepare for the hardware 757 * initialization. 758 * 759 * return the instance pointer if successful, NULL in error. 760 */ 761 struct vx_core *snd_vx_create(struct snd_card *card, struct snd_vx_hardware *hw, 762 struct snd_vx_ops *ops, 763 int extra_size) 764 { 765 struct vx_core *chip; 766 767 snd_assert(card && hw && ops, return NULL); 768 769 chip = kzalloc(sizeof(*chip) + extra_size, GFP_KERNEL); 770 if (! chip) { 771 snd_printk(KERN_ERR "vx_core: no memory\n"); 772 return NULL; 773 } 774 spin_lock_init(&chip->lock); 775 spin_lock_init(&chip->irq_lock); 776 chip->irq = -1; 777 chip->hw = hw; 778 chip->type = hw->type; 779 chip->ops = ops; 780 tasklet_init(&chip->tq, vx_interrupt, (unsigned long)chip); 781 mutex_init(&chip->mixer_mutex); 782 783 chip->card = card; 784 card->private_data = chip; 785 strcpy(card->driver, hw->name); 786 sprintf(card->shortname, "Digigram %s", hw->name); 787 788 vx_proc_init(chip); 789 790 return chip; 791 } 792 793 /* 794 * module entries 795 */ 796 static int __init alsa_vx_core_init(void) 797 { 798 return 0; 799 } 800 801 static void __exit alsa_vx_core_exit(void) 802 { 803 } 804 805 module_init(alsa_vx_core_init) 806 module_exit(alsa_vx_core_exit) 807 808 /* 809 * exports 810 */ 811 EXPORT_SYMBOL(snd_vx_check_reg_bit); 812 EXPORT_SYMBOL(snd_vx_create); 813 EXPORT_SYMBOL(snd_vx_setup_firmware); 814 EXPORT_SYMBOL(snd_vx_free_firmware); 815 EXPORT_SYMBOL(snd_vx_irq_handler); 816 EXPORT_SYMBOL(snd_vx_dsp_boot); 817 EXPORT_SYMBOL(snd_vx_dsp_load); 818 EXPORT_SYMBOL(snd_vx_load_boot_image); 819 #ifdef CONFIG_PM 820 EXPORT_SYMBOL(snd_vx_suspend); 821 EXPORT_SYMBOL(snd_vx_resume); 822 #endif 823