📄 ca0106_main.c
字号:
channel->use=1; //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); //channel->interrupt = snd_ca0106_pcm_channel_interrupt; channel->epcm=epcm; if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) return err; if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0) return err; return 0;}/* close callback */static int snd_ca0106_pcm_close_playback(snd_pcm_substream_t *substream){ ca0106_t *chip = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; ca0106_pcm_t *epcm = runtime->private_data; chip->playback_channels[epcm->channel_id].use=0;/* FIXME: maybe zero others */ return 0;}static int snd_ca0106_pcm_open_playback_front(snd_pcm_substream_t *substream){ return snd_ca0106_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);}static int snd_ca0106_pcm_open_playback_center_lfe(snd_pcm_substream_t *substream){ return snd_ca0106_pcm_open_playback_channel(substream, PCM_CENTER_LFE_CHANNEL);}static int snd_ca0106_pcm_open_playback_unknown(snd_pcm_substream_t *substream){ return snd_ca0106_pcm_open_playback_channel(substream, PCM_UNKNOWN_CHANNEL);}static int snd_ca0106_pcm_open_playback_rear(snd_pcm_substream_t *substream){ return snd_ca0106_pcm_open_playback_channel(substream, PCM_REAR_CHANNEL);}/* open_capture callback */static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t *substream, int channel_id){ ca0106_t *chip = snd_pcm_substream_chip(substream); ca0106_channel_t *channel = &(chip->capture_channels[channel_id]); ca0106_pcm_t *epcm; snd_pcm_runtime_t *runtime = substream->runtime; int err; epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); if (epcm == NULL) { snd_printk(KERN_ERR "open_capture_channel: failed epcm alloc\n"); return -ENOMEM; } epcm->emu = chip; epcm->substream = substream; epcm->channel_id=channel_id; runtime->private_data = epcm; runtime->private_free = snd_ca0106_pcm_free_substream; runtime->hw = snd_ca0106_capture_hw; channel->emu = chip; channel->number = channel_id; channel->use=1; //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); //channel->interrupt = snd_ca0106_pcm_channel_interrupt; channel->epcm=epcm; if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) return err; //snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_capture_period_sizes); if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0) return err; return 0;}/* close callback */static int snd_ca0106_pcm_close_capture(snd_pcm_substream_t *substream){ ca0106_t *chip = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; ca0106_pcm_t *epcm = runtime->private_data; chip->capture_channels[epcm->channel_id].use=0;/* FIXME: maybe zero others */ return 0;}static int snd_ca0106_pcm_open_0_capture(snd_pcm_substream_t *substream){ return snd_ca0106_pcm_open_capture_channel(substream, 0);}static int snd_ca0106_pcm_open_1_capture(snd_pcm_substream_t *substream){ return snd_ca0106_pcm_open_capture_channel(substream, 1);}static int snd_ca0106_pcm_open_2_capture(snd_pcm_substream_t *substream){ return snd_ca0106_pcm_open_capture_channel(substream, 2);}static int snd_ca0106_pcm_open_3_capture(snd_pcm_substream_t *substream){ return snd_ca0106_pcm_open_capture_channel(substream, 3);}/* hw_params callback */static int snd_ca0106_pcm_hw_params_playback(snd_pcm_substream_t *substream, snd_pcm_hw_params_t * hw_params){ return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));}/* hw_free callback */static int snd_ca0106_pcm_hw_free_playback(snd_pcm_substream_t *substream){ return snd_pcm_lib_free_pages(substream);}/* hw_params callback */static int snd_ca0106_pcm_hw_params_capture(snd_pcm_substream_t *substream, snd_pcm_hw_params_t * hw_params){ return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));}/* hw_free callback */static int snd_ca0106_pcm_hw_free_capture(snd_pcm_substream_t *substream){ return snd_pcm_lib_free_pages(substream);}/* prepare playback callback */static int snd_ca0106_pcm_prepare_playback(snd_pcm_substream_t *substream){ ca0106_t *emu = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; ca0106_pcm_t *epcm = runtime->private_data; int channel = epcm->channel_id; u32 *table_base = (u32 *)(emu->buffer.area+(8*16*channel)); u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size); u32 hcfg_mask = HCFG_PLAYBACK_S32_LE; u32 hcfg_set = 0x00000000; u32 hcfg; u32 reg40_mask = 0x30000 << (channel<<1); u32 reg40_set = 0; u32 reg40; /* FIXME: Depending on mixer selection of SPDIF out or not, select the spdif rate or the DAC rate. */ u32 reg71_mask = 0x03030000 ; /* Global. Set SPDIF rate. We only support 44100 to spdif, not to DAC. */ u32 reg71_set = 0; u32 reg71; int i; //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base); //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes); /* Rate can be set per channel. */ /* reg40 control host to fifo */ /* reg71 controls DAC rate. */ switch (runtime->rate) { case 44100: reg40_set = 0x10000 << (channel<<1); reg71_set = 0x01010000; break; case 48000: reg40_set = 0; reg71_set = 0; break; case 96000: reg40_set = 0x20000 << (channel<<1); reg71_set = 0x02020000; break; case 192000: reg40_set = 0x30000 << (channel<<1); reg71_set = 0x03030000; break; default: reg40_set = 0; reg71_set = 0; break; } /* Format is a global setting */ /* FIXME: Only let the first channel accessed set this. */ switch (runtime->format) { case SNDRV_PCM_FORMAT_S16_LE: hcfg_set = 0; break; case SNDRV_PCM_FORMAT_S32_LE: hcfg_set = HCFG_PLAYBACK_S32_LE; break; default: hcfg_set = 0; break; } hcfg = inl(emu->port + HCFG) ; hcfg = (hcfg & ~hcfg_mask) | hcfg_set; outl(hcfg, emu->port + HCFG); reg40 = snd_ca0106_ptr_read(emu, 0x40, 0); reg40 = (reg40 & ~reg40_mask) | reg40_set; snd_ca0106_ptr_write(emu, 0x40, 0, reg40); reg71 = snd_ca0106_ptr_read(emu, 0x71, 0); reg71 = (reg71 & ~reg71_mask) | reg71_set; snd_ca0106_ptr_write(emu, 0x71, 0, reg71); /* FIXME: Check emu->buffer.size before actually writing to it. */ for(i=0; i < runtime->periods; i++) { table_base[i*2]=runtime->dma_addr+(i*period_size_bytes); table_base[(i*2)+1]=period_size_bytes<<16; } snd_ca0106_ptr_write(emu, PLAYBACK_LIST_ADDR, channel, emu->buffer.addr+(8*16*channel)); snd_ca0106_ptr_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19); snd_ca0106_ptr_write(emu, PLAYBACK_LIST_PTR, channel, 0); snd_ca0106_ptr_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr); snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes /* FIXME test what 0 bytes does. */ snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, 0); // buffer size in bytes snd_ca0106_ptr_write(emu, PLAYBACK_POINTER, channel, 0); snd_ca0106_ptr_write(emu, 0x07, channel, 0x0); snd_ca0106_ptr_write(emu, 0x08, channel, 0); snd_ca0106_ptr_write(emu, PLAYBACK_MUTE, 0x0, 0x0); /* Unmute output */#if 0 snd_ca0106_ptr_write(emu, SPCS0, 0, SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT ); }#endif return 0;}/* prepare capture callback */static int snd_ca0106_pcm_prepare_capture(snd_pcm_substream_t *substream){ ca0106_t *emu = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; ca0106_pcm_t *epcm = runtime->private_data; int channel = epcm->channel_id; u32 hcfg_mask = HCFG_CAPTURE_S32_LE; u32 hcfg_set = 0x00000000; u32 hcfg; u32 over_sampling=0x2; u32 reg71_mask = 0x0000c000 ; /* Global. Set ADC rate. */ u32 reg71_set = 0; u32 reg71; //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base); //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes); /* reg71 controls ADC rate. */ switch (runtime->rate) { case 44100: reg71_set = 0x00004000; break; case 48000: reg71_set = 0; break; case 96000: reg71_set = 0x00008000; over_sampling=0xa; break; case 192000: reg71_set = 0x0000c000; over_sampling=0xa; break; default: reg71_set = 0; break; } /* Format is a global setting */ /* FIXME: Only let the first channel accessed set this. */ switch (runtime->format) { case SNDRV_PCM_FORMAT_S16_LE: hcfg_set = 0; break; case SNDRV_PCM_FORMAT_S32_LE: hcfg_set = HCFG_CAPTURE_S32_LE; break; default: hcfg_set = 0; break; } hcfg = inl(emu->port + HCFG) ; hcfg = (hcfg & ~hcfg_mask) | hcfg_set; outl(hcfg, emu->port + HCFG); reg71 = snd_ca0106_ptr_read(emu, 0x71, 0); reg71 = (reg71 & ~reg71_mask) | reg71_set; snd_ca0106_ptr_write(emu, 0x71, 0, reg71); if (emu->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */ snd_ca0106_i2c_write(emu, ADC_MASTER, over_sampling); /* Adjust the over sampler to better suit the capture rate. */ } //printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, frames_to_bytes(runtime, 1)); snd_ca0106_ptr_write(emu, 0x13, channel, 0); snd_ca0106_ptr_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr); snd_ca0106_ptr_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes snd_ca0106_ptr_write(emu, CAPTURE_POINTER, channel, 0); return 0;}/* trigger_playback callback */static int snd_ca0106_pcm_trigger_playback(snd_pcm_substream_t *substream, int cmd){ ca0106_t *emu = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime; ca0106_pcm_t *epcm; int channel; int result = 0; struct list_head *pos; snd_pcm_substream_t *s; u32 basic = 0; u32 extended = 0; int running=0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: running=1; break; case SNDRV_PCM_TRIGGER_STOP: default: running=0; break; } snd_pcm_group_for_each(pos, substream) { s = snd_pcm_group_substream_entry(pos); runtime = s->runtime; epcm = runtime->private_data; channel = epcm->channel_id; //snd_printk("channel=%d\n",channel); epcm->running = running; basic |= (0x1<<channel); extended |= (0x10<<channel); snd_pcm_trigger_done(s, substream); } //snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); switch (cmd) { case SNDRV_PCM_TRIGGER_START: snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (extended)); snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(basic)); break; case SNDRV_PCM_TRIGGER_STOP: snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(basic)); snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(extended)); break; default: result = -EINVAL; break; } return result;}/* trigger_capture callback */static int snd_ca0106_pcm_trigger_capture(snd_pcm_substream_t *substream, int cmd){ ca0106_t *emu = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; ca0106_pcm_t *epcm = runtime->private_data; int channel = epcm->channel_id; int result = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (0x110000<<channel)); snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(0x100<<channel)); epcm->running = 1; break; case SNDRV_PCM_TRIGGER_STOP: snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(0x100<<channel));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -