?? korg1212.c
字號:
if (monModeSet) { rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_MonitorOn, 0, 0, 0);#if K1212_DEBUG_LEVEL > 0 if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity - RC = %d [%s]\n", rc, stateName[korg1212->cardState]);#endif } spin_unlock_irqrestore(&korg1212->lock, flags); return 1;}static void snd_korg1212_OnDSPDownloadComplete(korg1212_t *korg1212){ int channel;#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is complete. [%s]\n", stateName[korg1212->cardState]);#endif // ---------------------------------------------------- // tell the card to boot // ---------------------------------------------------- rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_BootFromDSPPage4, 0, 0, 0, 0);#if K1212_DEBUG_LEVEL > 0 if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Boot from Page 4 - RC = %d [%s]\n", rc, stateName[korg1212->cardState]);#endif mdelay(DSP_BOOT_DELAY_IN_MS); // -------------------------------------------------------------------------------- // Let the card know where all the buffers are. // -------------------------------------------------------------------------------- rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_ConfigureBufferMemory, LowerWordSwap(korg1212->PlayDataPhy), LowerWordSwap(korg1212->RecDataPhy), ((kNumBuffers * kPlayBufferFrames) / 2), // size given to the card // is based on 2 buffers 0 );#if K1212_DEBUG_LEVEL > 0 if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Buffer Memory - RC = %d [%s]\n", rc, stateName[korg1212->cardState]);#endif udelay(INTERCOMMAND_DELAY); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_ConfigureMiscMemory, LowerWordSwap(korg1212->VolumeTablePhy), LowerWordSwap(korg1212->RoutingTablePhy), LowerWordSwap(korg1212->AdatTimeCodePhy), 0 );#if K1212_DEBUG_LEVEL > 0 if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Misc Memory - RC = %d [%s]\n", rc, stateName[korg1212->cardState]);#endif // -------------------------------------------------------------------------------- // Initialize the routing and volume tables, then update the card's state. // -------------------------------------------------------------------------------- udelay(INTERCOMMAND_DELAY); for (channel = 0; channel < kAudioChannels; channel++) { korg1212->sharedBufferPtr->volumeData[channel] = k1212MaxVolume; //korg1212->sharedBufferPtr->routeData[channel] = channel; korg1212->sharedBufferPtr->routeData[channel] = 8 + (channel & 1); } snd_korg1212_WriteADCSensitivity(korg1212); udelay(INTERCOMMAND_DELAY); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate, ClockSourceSelector[korg1212->clkSrcRate], 0, 0, 0);#if K1212_DEBUG_LEVEL > 0 if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", rc, stateName[korg1212->cardState]);#endif snd_korg1212_TurnOnIdleMonitor(korg1212); snd_korg1212_setCardState(korg1212, K1212_STATE_READY);#if K1212_DEBUG_LEVEL > 0 if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Set Monitor On - RC = %d [%s]\n", rc, stateName[korg1212->cardState]);#endif snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_COMPLETE);}static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs *regs){ u32 doorbellValue; korg1212_t *korg1212 = dev_id; if(irq != korg1212->irq) return IRQ_NONE; doorbellValue = readl(korg1212->inDoorbellPtr); if (!doorbellValue) return IRQ_NONE; spin_lock(&korg1212->lock); writel(doorbellValue, korg1212->inDoorbellPtr); korg1212->irqcount++; korg1212->inIRQ++; switch (doorbellValue) { case K1212_DB_DSPDownloadDone:#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]);#endif if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS) { korg1212->dsp_is_loaded = 1; wake_up(&korg1212->wait); } break; // ------------------------------------------------------------------------ // an error occurred - stop the card // ------------------------------------------------------------------------ case K1212_DB_DMAERROR:#if K1212_DEBUG_LEVEL > 1 K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]);#endif snd_printk(KERN_ERR "korg1212: DMA Error\n"); korg1212->errorcnt++; korg1212->totalerrorcnt++; korg1212->sharedBufferPtr->cardCommand = 0; snd_korg1212_setCardState(korg1212, K1212_STATE_ERRORSTOP); break; // ------------------------------------------------------------------------ // the card has stopped by our request. Clear the command word and signal // the semaphore in case someone is waiting for this. // ------------------------------------------------------------------------ case K1212_DB_CARDSTOPPED:#if K1212_DEBUG_LEVEL > 1 K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]);#endif korg1212->sharedBufferPtr->cardCommand = 0; break; default:#if K1212_DEBUG_LEVEL > 3 K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n", korg1212->irqcount, doorbellValue, korg1212->currentBuffer, stateName[korg1212->cardState]);#endif if ((korg1212->cardState > K1212_STATE_SETUP) || korg1212->idleMonitorOn) { korg1212->currentBuffer++; if (korg1212->currentBuffer >= kNumBuffers) korg1212->currentBuffer = 0; if (!korg1212->running) break; if (korg1212->capture_substream) { spin_unlock(&korg1212->lock); snd_pcm_period_elapsed(korg1212->capture_substream); spin_lock(&korg1212->lock); } if (korg1212->playback_substream) { spin_unlock(&korg1212->lock); snd_pcm_period_elapsed(korg1212->playback_substream); spin_lock(&korg1212->lock); } } break; } korg1212->inIRQ--; spin_unlock(&korg1212->lock); return IRQ_HANDLED;}static int snd_korg1212_downloadDSPCode(korg1212_t *korg1212){#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is starting... [%s]\n", stateName[korg1212->cardState]);#endif // --------------------------------------------------------------- // verify the state of the card before proceeding. // --------------------------------------------------------------- if (korg1212->cardState >= K1212_STATE_DSP_IN_PROCESS) { return 1; } snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_IN_PROCESS); memcpy(korg1212->dma_dsp.area, dspCode, korg1212->dspCodeSize); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_StartDSPDownload, UpperWordSwap(korg1212->dma_dsp.addr), 0, 0, 0);#if K1212_DEBUG_LEVEL > 0 if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n", rc, stateName[korg1212->cardState]);#endif korg1212->dsp_is_loaded = 0; wait_event_timeout(korg1212->wait, korg1212->dsp_is_loaded, HZ * CARD_BOOT_TIMEOUT); if (! korg1212->dsp_is_loaded ) return -EBUSY; /* timeout */ snd_korg1212_OnDSPDownloadComplete(korg1212); return 0;}static snd_pcm_hardware_t snd_korg1212_playback_info ={ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000), .rate_min = 44100, .rate_max = 48000, .channels_min = K1212_MIN_CHANNELS, .channels_max = K1212_MAX_CHANNELS, .buffer_bytes_max = K1212_MAX_BUF_SIZE, .period_bytes_min = K1212_MIN_CHANNELS * 2 * kPlayBufferFrames, .period_bytes_max = K1212_MAX_CHANNELS * 2 * kPlayBufferFrames, .periods_min = K1212_PERIODS, .periods_max = K1212_PERIODS, .fifo_size = 0,};static snd_pcm_hardware_t snd_korg1212_capture_info ={ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000), .rate_min = 44100, .rate_max = 48000, .channels_min = K1212_MIN_CHANNELS, .channels_max = K1212_MAX_CHANNELS, .buffer_bytes_max = K1212_MAX_BUF_SIZE, .period_bytes_min = K1212_MIN_CHANNELS * 2 * kPlayBufferFrames, .period_bytes_max = K1212_MAX_CHANNELS * 2 * kPlayBufferFrames, .periods_min = K1212_PERIODS, .periods_max = K1212_PERIODS, .fifo_size = 0,};static int snd_korg1212_silence(korg1212_t *korg1212, int pos, int count, int offset, int size){ KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; int i;#if K1212_DEBUG_LEVEL > 2 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n", pos, offset, size, count);#endif snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); for (i=0; i < count; i++) {#if K1212_DEBUG_LEVEL > 0 if ( (void *) dst < (void *) korg1212->playDataBufsPtr || (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n", dst, i); return -EFAULT; }#endif memset((void*) dst + offset, 0, size); dst++; } return 0;}static int snd_korg1212_copy_to(korg1212_t *korg1212, void __user *dst, int pos, int count, int offset, int size){ KorgAudioFrame * src = korg1212->recordDataBufsPtr[0].bufferData + pos; int i, rc;#if K1212_DEBUG_LEVEL > 2 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n", pos, offset, size);#endif snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); for (i=0; i < count; i++) {#if K1212_DEBUG_LEVEL > 0 if ( (void *) src < (void *) korg1212->recordDataBufsPtr || (void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData ) { K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); return -EFAULT; }#endif rc = copy_to_user(dst + offset, src, size); if (rc) {#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i);#endif return -EFAULT; } src++; dst += size; } return 0;}static int snd_korg1212_copy_from(korg1212_t *korg1212, void __user *src, int pos, int count, int offset, int size){ KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; int i, rc;#if K1212_DEBUG_LEVEL > 2 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n", pos, offset, size, count);#endif snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); for (i=0; i < count; i++) {#if K1212_DEBUG_LEVEL > 0 if ( (void *) dst < (void *) korg1212->playDataBufsPtr || (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); return -EFAULT; }#endif rc = copy_from_user((void*) dst + offset, src, size); if (rc) {#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i);#endif return -EFAULT; } dst++; src += size; } return 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -