2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 * Routines for control of EMU10K1 chips / PCM routines
5 * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <linux/pci.h>
30 #include <linux/delay.h>
31 #include <linux/slab.h>
32 #include <linux/time.h>
33 #include <linux/init.h>
34 #include <sound/core.h>
35 #include <sound/emu10k1.h>
37 static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1 *emu,
38 struct snd_emu10k1_voice *voice)
40 struct snd_emu10k1_pcm *epcm;
42 if ((epcm = voice->epcm) == NULL)
44 if (epcm->substream == NULL)
47 dev_dbg(emu->card->dev,
48 "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
49 epcm->substream->runtime->hw->pointer(emu, epcm->substream),
50 snd_pcm_lib_period_bytes(epcm->substream),
51 snd_pcm_lib_buffer_bytes(epcm->substream));
53 snd_pcm_period_elapsed(epcm->substream);
56 static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1 *emu,
60 if (status & IPR_ADCBUFHALFFULL) {
61 if (emu->pcm_capture_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
65 snd_pcm_period_elapsed(emu->pcm_capture_substream);
68 static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1 *emu,
72 if (status & IPR_MICBUFHALFFULL) {
73 if (emu->pcm_capture_mic_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
77 snd_pcm_period_elapsed(emu->pcm_capture_mic_substream);
80 static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1 *emu,
84 if (status & IPR_EFXBUFHALFFULL) {
85 if (emu->pcm_capture_efx_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
89 snd_pcm_period_elapsed(emu->pcm_capture_efx_substream);
92 static snd_pcm_uframes_t snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream *substream)
94 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
95 struct snd_pcm_runtime *runtime = substream->runtime;
96 struct snd_emu10k1_pcm *epcm = runtime->private_data;
101 ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
102 ptr += runtime->buffer_size;
103 ptr -= epcm->ccca_start_addr;
104 ptr %= runtime->buffer_size;
109 static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voices)
113 if (epcm->voices[1] != NULL && voices < 2) {
114 snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
115 epcm->voices[1] = NULL;
117 for (i = 0; i < voices; i++) {
118 if (epcm->voices[i] == NULL)
122 return 0; /* already allocated */
124 for (i = 0; i < ARRAY_SIZE(epcm->voices); i++) {
125 if (epcm->voices[i]) {
126 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
127 epcm->voices[i] = NULL;
130 err = snd_emu10k1_voice_alloc(epcm->emu,
131 epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
137 epcm->voices[0]->epcm = epcm;
139 for (i = 1; i < voices; i++) {
140 epcm->voices[i] = &epcm->emu->voices[epcm->voices[0]->number + i];
141 epcm->voices[i]->epcm = epcm;
144 if (epcm->extra == NULL) {
145 err = snd_emu10k1_voice_alloc(epcm->emu,
146 epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
151 dev_dbg(emu->card->dev, "pcm_channel_alloc: "
152 "failed extra: voices=%d, frame=%d\n",
155 for (i = 0; i < voices; i++) {
156 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
157 epcm->voices[i] = NULL;
161 epcm->extra->epcm = epcm;
162 epcm->extra->interrupt = snd_emu10k1_pcm_interrupt;
167 static const unsigned int capture_period_sizes[31] = {
169 384*2, 448*2, 512*2, 640*2,
170 384*4, 448*4, 512*4, 640*4,
171 384*8, 448*8, 512*8, 640*8,
172 384*16, 448*16, 512*16, 640*16,
173 384*32, 448*32, 512*32, 640*32,
174 384*64, 448*64, 512*64, 640*64,
175 384*128,448*128,512*128
178 static const struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes = {
180 .list = capture_period_sizes,
184 static const unsigned int capture_rates[8] = {
185 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
188 static const struct snd_pcm_hw_constraint_list hw_constraints_capture_rates = {
190 .list = capture_rates,
194 static unsigned int snd_emu10k1_capture_rate_reg(unsigned int rate)
197 case 8000: return ADCCR_SAMPLERATE_8;
198 case 11025: return ADCCR_SAMPLERATE_11;
199 case 16000: return ADCCR_SAMPLERATE_16;
200 case 22050: return ADCCR_SAMPLERATE_22;
201 case 24000: return ADCCR_SAMPLERATE_24;
202 case 32000: return ADCCR_SAMPLERATE_32;
203 case 44100: return ADCCR_SAMPLERATE_44;
204 case 48000: return ADCCR_SAMPLERATE_48;
207 return ADCCR_SAMPLERATE_8;
211 static unsigned int snd_emu10k1_audigy_capture_rate_reg(unsigned int rate)
214 case 8000: return A_ADCCR_SAMPLERATE_8;
215 case 11025: return A_ADCCR_SAMPLERATE_11;
216 case 12000: return A_ADCCR_SAMPLERATE_12; /* really supported? */
217 case 16000: return ADCCR_SAMPLERATE_16;
218 case 22050: return ADCCR_SAMPLERATE_22;
219 case 24000: return ADCCR_SAMPLERATE_24;
220 case 32000: return ADCCR_SAMPLERATE_32;
221 case 44100: return ADCCR_SAMPLERATE_44;
222 case 48000: return ADCCR_SAMPLERATE_48;
225 return A_ADCCR_SAMPLERATE_8;
229 static unsigned int emu10k1_calc_pitch_target(unsigned int rate)
231 unsigned int pitch_target;
233 pitch_target = (rate << 8) / 375;
234 pitch_target = (pitch_target >> 1) + (pitch_target & 1);
238 #define PITCH_48000 0x00004000
239 #define PITCH_96000 0x00008000
240 #define PITCH_85000 0x00007155
241 #define PITCH_80726 0x00006ba2
242 #define PITCH_67882 0x00005a82
243 #define PITCH_57081 0x00004c1c
245 static unsigned int emu10k1_select_interprom(unsigned int pitch_target)
247 if (pitch_target == PITCH_48000)
248 return CCCA_INTERPROM_0;
249 else if (pitch_target < PITCH_48000)
250 return CCCA_INTERPROM_1;
251 else if (pitch_target >= PITCH_96000)
252 return CCCA_INTERPROM_0;
253 else if (pitch_target >= PITCH_85000)
254 return CCCA_INTERPROM_6;
255 else if (pitch_target >= PITCH_80726)
256 return CCCA_INTERPROM_5;
257 else if (pitch_target >= PITCH_67882)
258 return CCCA_INTERPROM_4;
259 else if (pitch_target >= PITCH_57081)
260 return CCCA_INTERPROM_3;
262 return CCCA_INTERPROM_2;
266 * calculate cache invalidate size
268 * stereo: channel is stereo
269 * w_16: using 16bit samples
271 * returns: cache invalidate size in samples
273 static inline int emu10k1_ccis(int stereo, int w_16)
276 return stereo ? 24 : 26;
278 return stereo ? 24*2 : 26*2;
282 static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu,
283 int master, int extra,
284 struct snd_emu10k1_voice *evoice,
285 unsigned int start_addr,
286 unsigned int end_addr,
287 struct snd_emu10k1_pcm_mixer *mix)
289 struct snd_pcm_substream *substream = evoice->epcm->substream;
290 struct snd_pcm_runtime *runtime = substream->runtime;
291 unsigned int silent_page, tmp;
292 int voice, stereo, w_16;
293 unsigned char attn, send_amount[8];
294 unsigned char send_routing[8];
296 unsigned int pitch_target;
299 voice = evoice->number;
300 stereo = runtime->channels == 2;
301 w_16 = snd_pcm_format_width(runtime->format) == 16;
303 if (!extra && stereo) {
312 spin_lock_irqsave(&emu->reg_lock, flags);
314 /* volume parameters */
317 memset(send_routing, 0, sizeof(send_routing));
322 memset(send_amount, 0, sizeof(send_amount));
324 /* mono, left, right (master voice = left) */
325 tmp = stereo ? (master ? 1 : 2) : 0;
326 memcpy(send_routing, &mix->send_routing[tmp][0], 8);
327 memcpy(send_amount, &mix->send_volume[tmp][0], 8);
330 ccis = emu10k1_ccis(stereo, w_16);
333 evoice->epcm->ccca_start_addr = start_addr + ccis;
336 end_addr += ccis + emu->delay_pcm_irq;
338 if (stereo && !extra) {
339 snd_emu10k1_ptr_write(emu, CPF, voice, CPF_STEREO_MASK);
340 snd_emu10k1_ptr_write(emu, CPF, (voice + 1), CPF_STEREO_MASK);
342 snd_emu10k1_ptr_write(emu, CPF, voice, 0);
348 snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
349 snd_emu10k1_compose_audigy_fxrt1(send_routing));
350 snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
351 snd_emu10k1_compose_audigy_fxrt2(send_routing));
352 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice,
353 ((unsigned int)send_amount[4] << 24) |
354 ((unsigned int)send_amount[5] << 16) |
355 ((unsigned int)send_amount[6] << 8) |
356 (unsigned int)send_amount[7]);
358 snd_emu10k1_ptr_write(emu, FXRT, voice,
359 snd_emu10k1_compose_send_routing(send_routing));
361 /* Assumption that PT is already 0 so no harm overwriting */
362 snd_emu10k1_ptr_write(emu, PTRX, voice, (send_amount[0] << 8) | send_amount[1]);
363 snd_emu10k1_ptr_write(emu, DSL, voice, end_addr | (send_amount[3] << 24));
364 snd_emu10k1_ptr_write(emu, PSST, voice,
365 (start_addr + (extra ? emu->delay_pcm_irq : 0)) |
366 (send_amount[2] << 24));
367 if (emu->card_capabilities->emu_model)
368 pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */
370 pitch_target = emu10k1_calc_pitch_target(runtime->rate);
372 snd_emu10k1_ptr_write(emu, CCCA, voice, start_addr |
373 emu10k1_select_interprom(pitch_target) |
374 (w_16 ? 0 : CCCA_8BITSELECT));
376 snd_emu10k1_ptr_write(emu, CCCA, voice, (start_addr + ccis) |
377 emu10k1_select_interprom(pitch_target) |
378 (w_16 ? 0 : CCCA_8BITSELECT));
379 /* Clear filter delay memory */
380 snd_emu10k1_ptr_write(emu, Z1, voice, 0);
381 snd_emu10k1_ptr_write(emu, Z2, voice, 0);
382 /* invalidate maps */
383 silent_page = ((unsigned int)emu->silent_page.addr << emu->address_mode) | (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
384 snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page);
385 snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page);
386 /* modulation envelope */
387 snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff);
388 snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff);
389 snd_emu10k1_ptr_write(emu, ATKHLDM, voice, 0);
390 snd_emu10k1_ptr_write(emu, DCYSUSM, voice, 0x007f);
391 snd_emu10k1_ptr_write(emu, LFOVAL1, voice, 0x8000);
392 snd_emu10k1_ptr_write(emu, LFOVAL2, voice, 0x8000);
393 snd_emu10k1_ptr_write(emu, FMMOD, voice, 0);
394 snd_emu10k1_ptr_write(emu, TREMFRQ, voice, 0);
395 snd_emu10k1_ptr_write(emu, FM2FRQ2, voice, 0);
396 snd_emu10k1_ptr_write(emu, ENVVAL, voice, 0x8000);
397 /* volume envelope */
398 snd_emu10k1_ptr_write(emu, ATKHLDV, voice, 0x7f7f);
399 snd_emu10k1_ptr_write(emu, ENVVOL, voice, 0x0000);
400 /* filter envelope */
401 snd_emu10k1_ptr_write(emu, PEFE_FILTERAMOUNT, voice, 0x7f);
403 snd_emu10k1_ptr_write(emu, PEFE_PITCHAMOUNT, voice, 0);
405 spin_unlock_irqrestore(&emu->reg_lock, flags);
408 static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream *substream,
409 struct snd_pcm_hw_params *hw_params)
411 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
412 struct snd_pcm_runtime *runtime = substream->runtime;
413 struct snd_emu10k1_pcm *epcm = runtime->private_data;
417 if ((err = snd_emu10k1_pcm_channel_alloc(epcm, params_channels(hw_params))) < 0)
420 alloc_size = params_buffer_bytes(hw_params);
421 if (emu->iommu_workaround)
422 alloc_size += EMUPAGESIZE;
423 err = snd_pcm_lib_malloc_pages(substream, alloc_size);
426 if (emu->iommu_workaround && runtime->dma_bytes >= EMUPAGESIZE)
427 runtime->dma_bytes -= EMUPAGESIZE;
428 if (err > 0) { /* change */
430 if (epcm->memblk != NULL)
431 snd_emu10k1_free_pages(emu, epcm->memblk);
432 epcm->memblk = snd_emu10k1_alloc_pages(emu, substream);
433 epcm->start_addr = 0;
436 mapped = ((struct snd_emu10k1_memblk *)epcm->memblk)->mapped_page;
439 epcm->start_addr = mapped << PAGE_SHIFT;
444 static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream *substream)
446 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
447 struct snd_pcm_runtime *runtime = substream->runtime;
448 struct snd_emu10k1_pcm *epcm;
450 if (runtime->private_data == NULL)
452 epcm = runtime->private_data;
454 snd_emu10k1_voice_free(epcm->emu, epcm->extra);
457 if (epcm->voices[1]) {
458 snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
459 epcm->voices[1] = NULL;
461 if (epcm->voices[0]) {
462 snd_emu10k1_voice_free(epcm->emu, epcm->voices[0]);
463 epcm->voices[0] = NULL;
466 snd_emu10k1_free_pages(emu, epcm->memblk);
468 epcm->start_addr = 0;
470 snd_pcm_lib_free_pages(substream);
474 static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream *substream)
476 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
477 struct snd_pcm_runtime *runtime = substream->runtime;
478 struct snd_emu10k1_pcm *epcm;
481 if (runtime->private_data == NULL)
483 epcm = runtime->private_data;
485 snd_emu10k1_voice_free(epcm->emu, epcm->extra);
488 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
489 if (epcm->voices[i]) {
490 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
491 epcm->voices[i] = NULL;
495 snd_emu10k1_free_pages(emu, epcm->memblk);
497 epcm->start_addr = 0;
499 snd_pcm_lib_free_pages(substream);
503 static int snd_emu10k1_playback_prepare(struct snd_pcm_substream *substream)
505 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
506 struct snd_pcm_runtime *runtime = substream->runtime;
507 struct snd_emu10k1_pcm *epcm = runtime->private_data;
508 unsigned int start_addr, end_addr;
510 start_addr = epcm->start_addr;
511 end_addr = snd_pcm_lib_period_bytes(substream);
512 if (runtime->channels == 2) {
516 end_addr += start_addr;
517 snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
518 start_addr, end_addr, NULL);
519 start_addr = epcm->start_addr;
520 end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
521 snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
522 start_addr, end_addr,
523 &emu->pcm_mixer[substream->number]);
525 snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[1],
526 start_addr, end_addr,
527 &emu->pcm_mixer[substream->number]);
531 static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream *substream)
533 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
534 struct snd_pcm_runtime *runtime = substream->runtime;
535 struct snd_emu10k1_pcm *epcm = runtime->private_data;
536 unsigned int start_addr, end_addr;
537 unsigned int channel_size;
540 start_addr = epcm->start_addr;
541 end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
544 * the kX driver leaves some space between voices
546 channel_size = ( end_addr - start_addr ) / NUM_EFX_PLAYBACK;
548 snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
549 start_addr, start_addr + (channel_size / 2), NULL);
551 /* only difference with the master voice is we use it for the pointer */
552 snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
553 start_addr, start_addr + channel_size,
554 &emu->efx_pcm_mixer[0]);
556 start_addr += channel_size;
557 for (i = 1; i < NUM_EFX_PLAYBACK; i++) {
558 snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[i],
559 start_addr, start_addr + channel_size,
560 &emu->efx_pcm_mixer[i]);
561 start_addr += channel_size;
567 static const struct snd_pcm_hardware snd_emu10k1_efx_playback =
569 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_NONINTERLEAVED |
570 SNDRV_PCM_INFO_BLOCK_TRANSFER |
571 SNDRV_PCM_INFO_RESUME |
572 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
573 .formats = SNDRV_PCM_FMTBIT_S16_LE,
574 .rates = SNDRV_PCM_RATE_48000,
577 .channels_min = NUM_EFX_PLAYBACK,
578 .channels_max = NUM_EFX_PLAYBACK,
579 .buffer_bytes_max = (64*1024),
580 .period_bytes_min = 64,
581 .period_bytes_max = (64*1024),
587 static int snd_emu10k1_capture_hw_params(struct snd_pcm_substream *substream,
588 struct snd_pcm_hw_params *hw_params)
590 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
593 static int snd_emu10k1_capture_hw_free(struct snd_pcm_substream *substream)
595 return snd_pcm_lib_free_pages(substream);
598 static int snd_emu10k1_capture_prepare(struct snd_pcm_substream *substream)
600 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
601 struct snd_pcm_runtime *runtime = substream->runtime;
602 struct snd_emu10k1_pcm *epcm = runtime->private_data;
605 /* zeroing the buffer size will stop capture */
606 snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0);
607 switch (epcm->type) {
608 case CAPTURE_AC97ADC:
609 snd_emu10k1_ptr_write(emu, ADCCR, 0, 0);
613 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0);
614 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0);
616 snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
621 snd_emu10k1_ptr_write(emu, epcm->capture_ba_reg, 0, runtime->dma_addr);
622 epcm->capture_bufsize = snd_pcm_lib_buffer_bytes(substream);
623 epcm->capture_bs_val = 0;
624 for (idx = 0; idx < 31; idx++) {
625 if (capture_period_sizes[idx] == epcm->capture_bufsize) {
626 epcm->capture_bs_val = idx + 1;
630 if (epcm->capture_bs_val == 0) {
632 epcm->capture_bs_val++;
634 if (epcm->type == CAPTURE_AC97ADC) {
635 epcm->capture_cr_val = emu->audigy ? A_ADCCR_LCHANENABLE : ADCCR_LCHANENABLE;
636 if (runtime->channels > 1)
637 epcm->capture_cr_val |= emu->audigy ? A_ADCCR_RCHANENABLE : ADCCR_RCHANENABLE;
638 epcm->capture_cr_val |= emu->audigy ?
639 snd_emu10k1_audigy_capture_rate_reg(runtime->rate) :
640 snd_emu10k1_capture_rate_reg(runtime->rate);
645 static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1 *emu, int extra, struct snd_emu10k1_voice *evoice)
647 struct snd_pcm_runtime *runtime;
648 unsigned int voice, stereo, i, ccis, cra = 64, cs, sample;
652 runtime = evoice->epcm->substream->runtime;
653 voice = evoice->number;
654 stereo = (!extra && runtime->channels == 2);
655 sample = snd_pcm_format_width(runtime->format) == 16 ? 0 : 0x80808080;
656 ccis = emu10k1_ccis(stereo, sample == 0);
657 /* set cs to 2 * number of cache registers beside the invalidated */
658 cs = (sample == 0) ? (32-ccis) : (64-ccis+1) >> 1;
659 if (cs > 16) cs = 16;
660 for (i = 0; i < cs; i++) {
661 snd_emu10k1_ptr_write(emu, CD0 + i, voice, sample);
663 snd_emu10k1_ptr_write(emu, CD0 + i, voice + 1, sample);
667 snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, 0);
668 snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice, cra);
670 snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice + 1, 0);
671 snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice + 1, cra);
674 snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, ccis);
676 snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice+1, ccis);
680 static void snd_emu10k1_playback_prepare_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice,
681 int master, int extra,
682 struct snd_emu10k1_pcm_mixer *mix)
684 struct snd_pcm_substream *substream;
685 struct snd_pcm_runtime *runtime;
686 unsigned int attn, vattn;
687 unsigned int voice, tmp;
689 if (evoice == NULL) /* skip second voice for mono */
691 substream = evoice->epcm->substream;
692 runtime = substream->runtime;
693 voice = evoice->number;
695 attn = extra ? 0 : 0x00ff;
696 tmp = runtime->channels == 2 ? (master ? 1 : 2) : 0;
697 vattn = mix != NULL ? (mix->attn[tmp] << 16) : 0;
698 snd_emu10k1_ptr_write(emu, IFATN, voice, attn);
699 snd_emu10k1_ptr_write(emu, VTFT, voice, vattn | 0xffff);
700 snd_emu10k1_ptr_write(emu, CVCF, voice, vattn | 0xffff);
701 snd_emu10k1_ptr_write(emu, DCYSUSV, voice, 0x7f7f);
702 snd_emu10k1_voice_clear_loop_stop(emu, voice);
705 static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice, int master, int extra)
707 struct snd_pcm_substream *substream;
708 struct snd_pcm_runtime *runtime;
709 unsigned int voice, pitch, pitch_target;
711 if (evoice == NULL) /* skip second voice for mono */
713 substream = evoice->epcm->substream;
714 runtime = substream->runtime;
715 voice = evoice->number;
717 pitch = snd_emu10k1_rate_to_pitch(runtime->rate) >> 8;
718 if (emu->card_capabilities->emu_model)
719 pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */
721 pitch_target = emu10k1_calc_pitch_target(runtime->rate);
722 snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, pitch_target);
723 if (master || evoice->epcm->type == PLAYBACK_EFX)
724 snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, pitch_target);
725 snd_emu10k1_ptr_write(emu, IP, voice, pitch);
727 snd_emu10k1_voice_intr_enable(emu, voice);
730 static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice)
736 voice = evoice->number;
737 snd_emu10k1_voice_intr_disable(emu, voice);
738 snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, 0);
739 snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, 0);
740 snd_emu10k1_ptr_write(emu, IFATN, voice, 0xffff);
741 snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff);
742 snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff);
743 snd_emu10k1_ptr_write(emu, IP, voice, 0);
746 static inline void snd_emu10k1_playback_mangle_extra(struct snd_emu10k1 *emu,
747 struct snd_emu10k1_pcm *epcm,
748 struct snd_pcm_substream *substream,
749 struct snd_pcm_runtime *runtime)
751 unsigned int ptr, period_pos;
753 /* try to sychronize the current position for the interrupt
755 period_pos = runtime->status->hw_ptr - runtime->hw_ptr_interrupt;
756 period_pos %= runtime->period_size;
757 ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->extra->number);
759 ptr |= epcm->ccca_start_addr + period_pos;
760 snd_emu10k1_ptr_write(emu, CCCA, epcm->extra->number, ptr);
763 static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream,
766 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
767 struct snd_pcm_runtime *runtime = substream->runtime;
768 struct snd_emu10k1_pcm *epcm = runtime->private_data;
769 struct snd_emu10k1_pcm_mixer *mix;
773 dev_dbg(emu->card->dev,
774 "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
775 (int)emu, cmd, substream->ops->pointer(substream))
777 spin_lock(&emu->reg_lock);
779 case SNDRV_PCM_TRIGGER_START:
780 snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra); /* do we need this? */
781 snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[0]);
783 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
784 case SNDRV_PCM_TRIGGER_RESUME:
785 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE)
786 snd_emu10k1_playback_mangle_extra(emu, epcm, substream, runtime);
787 mix = &emu->pcm_mixer[substream->number];
788 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 1, 0, mix);
789 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[1], 0, 0, mix);
790 snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL);
791 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 1, 0);
792 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[1], 0, 0);
793 snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
796 case SNDRV_PCM_TRIGGER_STOP:
797 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
798 case SNDRV_PCM_TRIGGER_SUSPEND:
800 snd_emu10k1_playback_stop_voice(emu, epcm->voices[0]);
801 snd_emu10k1_playback_stop_voice(emu, epcm->voices[1]);
802 snd_emu10k1_playback_stop_voice(emu, epcm->extra);
808 spin_unlock(&emu->reg_lock);
812 static int snd_emu10k1_capture_trigger(struct snd_pcm_substream *substream,
815 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
816 struct snd_pcm_runtime *runtime = substream->runtime;
817 struct snd_emu10k1_pcm *epcm = runtime->private_data;
820 spin_lock(&emu->reg_lock);
822 case SNDRV_PCM_TRIGGER_START:
823 case SNDRV_PCM_TRIGGER_RESUME:
824 /* hmm this should cause full and half full interrupt to be raised? */
825 outl(epcm->capture_ipr, emu->port + IPR);
826 snd_emu10k1_intr_enable(emu, epcm->capture_inte);
828 dev_dbg(emu->card->dev, "adccr = 0x%x, adcbs = 0x%x\n",
829 epcm->adccr, epcm->adcbs);
831 switch (epcm->type) {
832 case CAPTURE_AC97ADC:
833 snd_emu10k1_ptr_write(emu, ADCCR, 0, epcm->capture_cr_val);
837 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val);
838 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2);
839 dev_dbg(emu->card->dev,
840 "cr_val=0x%x, cr_val2=0x%x\n",
841 epcm->capture_cr_val,
842 epcm->capture_cr_val2);
844 snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val);
849 snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, epcm->capture_bs_val);
853 case SNDRV_PCM_TRIGGER_STOP:
854 case SNDRV_PCM_TRIGGER_SUSPEND:
856 snd_emu10k1_intr_disable(emu, epcm->capture_inte);
857 outl(epcm->capture_ipr, emu->port + IPR);
858 snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0);
859 switch (epcm->type) {
860 case CAPTURE_AC97ADC:
861 snd_emu10k1_ptr_write(emu, ADCCR, 0, 0);
865 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0);
866 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0);
868 snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
877 spin_unlock(&emu->reg_lock);
881 static snd_pcm_uframes_t snd_emu10k1_playback_pointer(struct snd_pcm_substream *substream)
883 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
884 struct snd_pcm_runtime *runtime = substream->runtime;
885 struct snd_emu10k1_pcm *epcm = runtime->private_data;
890 ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
891 #if 0 /* Perex's code */
892 ptr += runtime->buffer_size;
893 ptr -= epcm->ccca_start_addr;
894 ptr %= runtime->buffer_size;
895 #else /* EMU10K1 Open Source code from Creative */
896 if (ptr < epcm->ccca_start_addr)
897 ptr += runtime->buffer_size - epcm->ccca_start_addr;
899 ptr -= epcm->ccca_start_addr;
900 if (ptr >= runtime->buffer_size)
901 ptr -= runtime->buffer_size;
905 dev_dbg(emu->card->dev,
906 "ptr = 0x%lx, buffer_size = 0x%lx, period_size = 0x%lx\n",
907 (long)ptr, (long)runtime->buffer_size,
908 (long)runtime->period_size);
914 static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream *substream,
917 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
918 struct snd_pcm_runtime *runtime = substream->runtime;
919 struct snd_emu10k1_pcm *epcm = runtime->private_data;
923 spin_lock(&emu->reg_lock);
925 case SNDRV_PCM_TRIGGER_START:
927 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
928 snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[i]);
930 snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);
933 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
934 case SNDRV_PCM_TRIGGER_RESUME:
935 snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL);
936 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 0, 0,
937 &emu->efx_pcm_mixer[0]);
938 for (i = 1; i < NUM_EFX_PLAYBACK; i++)
939 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[i], 0, 0,
940 &emu->efx_pcm_mixer[i]);
941 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 0, 0);
942 snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
943 for (i = 1; i < NUM_EFX_PLAYBACK; i++)
944 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[i], 0, 0);
947 case SNDRV_PCM_TRIGGER_SUSPEND:
948 case SNDRV_PCM_TRIGGER_STOP:
949 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
951 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
952 snd_emu10k1_playback_stop_voice(emu, epcm->voices[i]);
954 snd_emu10k1_playback_stop_voice(emu, epcm->extra);
960 spin_unlock(&emu->reg_lock);
965 static snd_pcm_uframes_t snd_emu10k1_capture_pointer(struct snd_pcm_substream *substream)
967 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
968 struct snd_pcm_runtime *runtime = substream->runtime;
969 struct snd_emu10k1_pcm *epcm = runtime->private_data;
974 if (epcm->first_ptr) {
975 udelay(50); /* hack, it takes awhile until capture is started */
978 ptr = snd_emu10k1_ptr_read(emu, epcm->capture_idx_reg, 0) & 0x0000ffff;
979 return bytes_to_frames(runtime, ptr);
983 * Playback support device description
986 static const struct snd_pcm_hardware snd_emu10k1_playback =
988 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
989 SNDRV_PCM_INFO_BLOCK_TRANSFER |
990 SNDRV_PCM_INFO_RESUME |
991 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
992 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
993 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_96000,
998 .buffer_bytes_max = (128*1024),
999 .period_bytes_min = 64,
1000 .period_bytes_max = (128*1024),
1002 .periods_max = 1024,
1007 * Capture support device description
1010 static const struct snd_pcm_hardware snd_emu10k1_capture =
1012 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1013 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1014 SNDRV_PCM_INFO_RESUME |
1015 SNDRV_PCM_INFO_MMAP_VALID),
1016 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1017 .rates = SNDRV_PCM_RATE_8000_48000,
1022 .buffer_bytes_max = (64*1024),
1023 .period_bytes_min = 384,
1024 .period_bytes_max = (64*1024),
1030 static const struct snd_pcm_hardware snd_emu10k1_capture_efx =
1032 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1033 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1034 SNDRV_PCM_INFO_RESUME |
1035 SNDRV_PCM_INFO_MMAP_VALID),
1036 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1037 .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
1038 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
1039 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000,
1044 .buffer_bytes_max = (64*1024),
1045 .period_bytes_min = 384,
1046 .period_bytes_max = (64*1024),
1056 static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1 *emu, struct snd_kcontrol *kctl, int idx, int activate)
1058 struct snd_ctl_elem_id id;
1063 kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1065 kctl->vd[idx].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1066 snd_ctl_notify(emu->card, SNDRV_CTL_EVENT_MASK_VALUE |
1067 SNDRV_CTL_EVENT_MASK_INFO,
1068 snd_ctl_build_ioff(&id, kctl, idx));
1071 static void snd_emu10k1_pcm_mixer_notify(struct snd_emu10k1 *emu, int idx, int activate)
1073 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_routing, idx, activate);
1074 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_volume, idx, activate);
1075 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_attn, idx, activate);
1078 static void snd_emu10k1_pcm_efx_mixer_notify(struct snd_emu10k1 *emu, int idx, int activate)
1080 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_routing, idx, activate);
1081 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_volume, idx, activate);
1082 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_attn, idx, activate);
1085 static void snd_emu10k1_pcm_free_substream(struct snd_pcm_runtime *runtime)
1087 kfree(runtime->private_data);
1090 static int snd_emu10k1_efx_playback_close(struct snd_pcm_substream *substream)
1092 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1093 struct snd_emu10k1_pcm_mixer *mix;
1096 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
1097 mix = &emu->efx_pcm_mixer[i];
1099 snd_emu10k1_pcm_efx_mixer_notify(emu, i, 0);
1104 static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream *substream)
1106 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1107 struct snd_emu10k1_pcm *epcm;
1108 struct snd_emu10k1_pcm_mixer *mix;
1109 struct snd_pcm_runtime *runtime = substream->runtime;
1112 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
1116 epcm->type = PLAYBACK_EFX;
1117 epcm->substream = substream;
1119 emu->pcm_playback_efx_substream = substream;
1121 runtime->private_data = epcm;
1122 runtime->private_free = snd_emu10k1_pcm_free_substream;
1123 runtime->hw = snd_emu10k1_efx_playback;
1125 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
1126 mix = &emu->efx_pcm_mixer[i];
1127 mix->send_routing[0][0] = i;
1128 memset(&mix->send_volume, 0, sizeof(mix->send_volume));
1129 mix->send_volume[0][0] = 255;
1130 mix->attn[0] = 0xffff;
1132 snd_emu10k1_pcm_efx_mixer_notify(emu, i, 1);
1137 static int snd_emu10k1_playback_open(struct snd_pcm_substream *substream)
1139 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1140 struct snd_emu10k1_pcm *epcm;
1141 struct snd_emu10k1_pcm_mixer *mix;
1142 struct snd_pcm_runtime *runtime = substream->runtime;
1143 int i, err, sample_rate;
1145 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
1149 epcm->type = PLAYBACK_EMUVOICE;
1150 epcm->substream = substream;
1151 runtime->private_data = epcm;
1152 runtime->private_free = snd_emu10k1_pcm_free_substream;
1153 runtime->hw = snd_emu10k1_playback;
1154 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) {
1158 if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) {
1162 if (emu->card_capabilities->emu_model && emu->emu1010.internal_clock == 0)
1163 sample_rate = 44100;
1165 sample_rate = 48000;
1166 err = snd_pcm_hw_rule_noresample(runtime, sample_rate);
1171 mix = &emu->pcm_mixer[substream->number];
1172 for (i = 0; i < 4; i++)
1173 mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i;
1174 memset(&mix->send_volume, 0, sizeof(mix->send_volume));
1175 mix->send_volume[0][0] = mix->send_volume[0][1] =
1176 mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
1177 mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
1179 snd_emu10k1_pcm_mixer_notify(emu, substream->number, 1);
1183 static int snd_emu10k1_playback_close(struct snd_pcm_substream *substream)
1185 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1186 struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[substream->number];
1189 snd_emu10k1_pcm_mixer_notify(emu, substream->number, 0);
1193 static int snd_emu10k1_capture_open(struct snd_pcm_substream *substream)
1195 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1196 struct snd_pcm_runtime *runtime = substream->runtime;
1197 struct snd_emu10k1_pcm *epcm;
1199 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
1203 epcm->type = CAPTURE_AC97ADC;
1204 epcm->substream = substream;
1205 epcm->capture_ipr = IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL;
1206 epcm->capture_inte = INTE_ADCBUFENABLE;
1207 epcm->capture_ba_reg = ADCBA;
1208 epcm->capture_bs_reg = ADCBS;
1209 epcm->capture_idx_reg = emu->audigy ? A_ADCIDX : ADCIDX;
1210 runtime->private_data = epcm;
1211 runtime->private_free = snd_emu10k1_pcm_free_substream;
1212 runtime->hw = snd_emu10k1_capture;
1213 emu->capture_interrupt = snd_emu10k1_pcm_ac97adc_interrupt;
1214 emu->pcm_capture_substream = substream;
1215 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
1216 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_capture_rates);
1220 static int snd_emu10k1_capture_close(struct snd_pcm_substream *substream)
1222 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1224 emu->capture_interrupt = NULL;
1225 emu->pcm_capture_substream = NULL;
1229 static int snd_emu10k1_capture_mic_open(struct snd_pcm_substream *substream)
1231 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1232 struct snd_emu10k1_pcm *epcm;
1233 struct snd_pcm_runtime *runtime = substream->runtime;
1235 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
1239 epcm->type = CAPTURE_AC97MIC;
1240 epcm->substream = substream;
1241 epcm->capture_ipr = IPR_MICBUFFULL|IPR_MICBUFHALFFULL;
1242 epcm->capture_inte = INTE_MICBUFENABLE;
1243 epcm->capture_ba_reg = MICBA;
1244 epcm->capture_bs_reg = MICBS;
1245 epcm->capture_idx_reg = emu->audigy ? A_MICIDX : MICIDX;
1246 substream->runtime->private_data = epcm;
1247 substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
1248 runtime->hw = snd_emu10k1_capture;
1249 runtime->hw.rates = SNDRV_PCM_RATE_8000;
1250 runtime->hw.rate_min = runtime->hw.rate_max = 8000;
1251 runtime->hw.channels_min = 1;
1252 emu->capture_mic_interrupt = snd_emu10k1_pcm_ac97mic_interrupt;
1253 emu->pcm_capture_mic_substream = substream;
1254 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
1258 static int snd_emu10k1_capture_mic_close(struct snd_pcm_substream *substream)
1260 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1262 emu->capture_interrupt = NULL;
1263 emu->pcm_capture_mic_substream = NULL;
1267 static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream *substream)
1269 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1270 struct snd_emu10k1_pcm *epcm;
1271 struct snd_pcm_runtime *runtime = substream->runtime;
1272 int nefx = emu->audigy ? 64 : 32;
1275 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
1279 epcm->type = CAPTURE_EFX;
1280 epcm->substream = substream;
1281 epcm->capture_ipr = IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL;
1282 epcm->capture_inte = INTE_EFXBUFENABLE;
1283 epcm->capture_ba_reg = FXBA;
1284 epcm->capture_bs_reg = FXBS;
1285 epcm->capture_idx_reg = FXIDX;
1286 substream->runtime->private_data = epcm;
1287 substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
1288 runtime->hw = snd_emu10k1_capture_efx;
1289 runtime->hw.rates = SNDRV_PCM_RATE_48000;
1290 runtime->hw.rate_min = runtime->hw.rate_max = 48000;
1291 spin_lock_irq(&emu->reg_lock);
1292 if (emu->card_capabilities->emu_model) {
1293 /* Nb. of channels has been increased to 16 */
1295 * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE
1296 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
1297 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
1298 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000
1300 * rate_max = 192000,
1301 * channels_min = 16,
1302 * channels_max = 16,
1303 * Need to add mixer control to fix sample rate
1305 * There are 32 mono channels of 16bits each.
1306 * 24bit Audio uses 2x channels over 16bit
1307 * 96kHz uses 2x channels over 48kHz
1308 * 192kHz uses 4x channels over 48kHz
1309 * So, for 48kHz 24bit, one has 16 channels
1310 * for 96kHz 24bit, one has 8 channels
1311 * for 192kHz 24bit, one has 4 channels
1315 switch (emu->emu1010.internal_clock) {
1318 runtime->hw.rates = SNDRV_PCM_RATE_44100;
1319 runtime->hw.rate_min = runtime->hw.rate_max = 44100;
1320 runtime->hw.channels_min =
1321 runtime->hw.channels_max = 16;
1325 runtime->hw.rates = SNDRV_PCM_RATE_48000;
1326 runtime->hw.rate_min = runtime->hw.rate_max = 48000;
1327 runtime->hw.channels_min =
1328 runtime->hw.channels_max = 16;
1334 runtime->hw.rates = SNDRV_PCM_RATE_96000;
1335 runtime->hw.rate_min = runtime->hw.rate_max = 96000;
1336 runtime->hw.channels_min = runtime->hw.channels_max = 4;
1340 runtime->hw.rates = SNDRV_PCM_RATE_192000;
1341 runtime->hw.rate_min = runtime->hw.rate_max = 192000;
1342 runtime->hw.channels_min = runtime->hw.channels_max = 2;
1344 runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;
1345 /* efx_voices_mask[0] is expected to be zero
1346 * efx_voices_mask[1] is expected to have 32bits set
1349 runtime->hw.channels_min = runtime->hw.channels_max = 0;
1350 for (idx = 0; idx < nefx; idx++) {
1351 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) {
1352 runtime->hw.channels_min++;
1353 runtime->hw.channels_max++;
1357 epcm->capture_cr_val = emu->efx_voices_mask[0];
1358 epcm->capture_cr_val2 = emu->efx_voices_mask[1];
1359 spin_unlock_irq(&emu->reg_lock);
1360 emu->capture_efx_interrupt = snd_emu10k1_pcm_efx_interrupt;
1361 emu->pcm_capture_efx_substream = substream;
1362 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
1366 static int snd_emu10k1_capture_efx_close(struct snd_pcm_substream *substream)
1368 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1370 emu->capture_interrupt = NULL;
1371 emu->pcm_capture_efx_substream = NULL;
1375 static const struct snd_pcm_ops snd_emu10k1_playback_ops = {
1376 .open = snd_emu10k1_playback_open,
1377 .close = snd_emu10k1_playback_close,
1378 .ioctl = snd_pcm_lib_ioctl,
1379 .hw_params = snd_emu10k1_playback_hw_params,
1380 .hw_free = snd_emu10k1_playback_hw_free,
1381 .prepare = snd_emu10k1_playback_prepare,
1382 .trigger = snd_emu10k1_playback_trigger,
1383 .pointer = snd_emu10k1_playback_pointer,
1384 .page = snd_pcm_sgbuf_ops_page,
1387 static const struct snd_pcm_ops snd_emu10k1_capture_ops = {
1388 .open = snd_emu10k1_capture_open,
1389 .close = snd_emu10k1_capture_close,
1390 .ioctl = snd_pcm_lib_ioctl,
1391 .hw_params = snd_emu10k1_capture_hw_params,
1392 .hw_free = snd_emu10k1_capture_hw_free,
1393 .prepare = snd_emu10k1_capture_prepare,
1394 .trigger = snd_emu10k1_capture_trigger,
1395 .pointer = snd_emu10k1_capture_pointer,
1399 static const struct snd_pcm_ops snd_emu10k1_efx_playback_ops = {
1400 .open = snd_emu10k1_efx_playback_open,
1401 .close = snd_emu10k1_efx_playback_close,
1402 .ioctl = snd_pcm_lib_ioctl,
1403 .hw_params = snd_emu10k1_playback_hw_params,
1404 .hw_free = snd_emu10k1_efx_playback_hw_free,
1405 .prepare = snd_emu10k1_efx_playback_prepare,
1406 .trigger = snd_emu10k1_efx_playback_trigger,
1407 .pointer = snd_emu10k1_efx_playback_pointer,
1408 .page = snd_pcm_sgbuf_ops_page,
1411 int snd_emu10k1_pcm(struct snd_emu10k1 *emu, int device)
1413 struct snd_pcm *pcm;
1414 struct snd_pcm_substream *substream;
1417 if ((err = snd_pcm_new(emu->card, "emu10k1", device, 32, 1, &pcm)) < 0)
1420 pcm->private_data = emu;
1422 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_playback_ops);
1423 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_ops);
1425 pcm->info_flags = 0;
1426 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
1427 strcpy(pcm->name, "ADC Capture/Standard PCM Playback");
1430 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
1431 if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0)
1434 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next)
1435 snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
1440 int snd_emu10k1_pcm_multi(struct snd_emu10k1 *emu, int device)
1442 struct snd_pcm *pcm;
1443 struct snd_pcm_substream *substream;
1446 if ((err = snd_pcm_new(emu->card, "emu10k1", device, 1, 0, &pcm)) < 0)
1449 pcm->private_data = emu;
1451 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_efx_playback_ops);
1453 pcm->info_flags = 0;
1454 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
1455 strcpy(pcm->name, "Multichannel Playback");
1456 emu->pcm_multi = pcm;
1458 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
1459 if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0)
1466 static const struct snd_pcm_ops snd_emu10k1_capture_mic_ops = {
1467 .open = snd_emu10k1_capture_mic_open,
1468 .close = snd_emu10k1_capture_mic_close,
1469 .ioctl = snd_pcm_lib_ioctl,
1470 .hw_params = snd_emu10k1_capture_hw_params,
1471 .hw_free = snd_emu10k1_capture_hw_free,
1472 .prepare = snd_emu10k1_capture_prepare,
1473 .trigger = snd_emu10k1_capture_trigger,
1474 .pointer = snd_emu10k1_capture_pointer,
1477 int snd_emu10k1_pcm_mic(struct snd_emu10k1 *emu, int device)
1479 struct snd_pcm *pcm;
1482 if ((err = snd_pcm_new(emu->card, "emu10k1 mic", device, 0, 1, &pcm)) < 0)
1485 pcm->private_data = emu;
1487 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_mic_ops);
1489 pcm->info_flags = 0;
1490 strcpy(pcm->name, "Mic Capture");
1493 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
1498 static int snd_emu10k1_pcm_efx_voices_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1500 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1501 int nefx = emu->audigy ? 64 : 32;
1502 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1503 uinfo->count = nefx;
1504 uinfo->value.integer.min = 0;
1505 uinfo->value.integer.max = 1;
1509 static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1511 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1512 int nefx = emu->audigy ? 64 : 32;
1515 spin_lock_irq(&emu->reg_lock);
1516 for (idx = 0; idx < nefx; idx++)
1517 ucontrol->value.integer.value[idx] = (emu->efx_voices_mask[idx / 32] & (1 << (idx % 32))) ? 1 : 0;
1518 spin_unlock_irq(&emu->reg_lock);
1522 static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1524 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1525 unsigned int nval[2], bits;
1526 int nefx = emu->audigy ? 64 : 32;
1527 int nefxb = emu->audigy ? 7 : 6;
1530 nval[0] = nval[1] = 0;
1531 for (idx = 0, bits = 0; idx < nefx; idx++)
1532 if (ucontrol->value.integer.value[idx]) {
1533 nval[idx / 32] |= 1 << (idx % 32);
1537 for (idx = 0; idx < nefxb; idx++)
1538 if (1 << idx == bits)
1544 spin_lock_irq(&emu->reg_lock);
1545 change = (nval[0] != emu->efx_voices_mask[0]) ||
1546 (nval[1] != emu->efx_voices_mask[1]);
1547 emu->efx_voices_mask[0] = nval[0];
1548 emu->efx_voices_mask[1] = nval[1];
1549 spin_unlock_irq(&emu->reg_lock);
1553 static const struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask = {
1554 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1555 .name = "Captured FX8010 Outputs",
1556 .info = snd_emu10k1_pcm_efx_voices_mask_info,
1557 .get = snd_emu10k1_pcm_efx_voices_mask_get,
1558 .put = snd_emu10k1_pcm_efx_voices_mask_put
1561 static const struct snd_pcm_ops snd_emu10k1_capture_efx_ops = {
1562 .open = snd_emu10k1_capture_efx_open,
1563 .close = snd_emu10k1_capture_efx_close,
1564 .ioctl = snd_pcm_lib_ioctl,
1565 .hw_params = snd_emu10k1_capture_hw_params,
1566 .hw_free = snd_emu10k1_capture_hw_free,
1567 .prepare = snd_emu10k1_capture_prepare,
1568 .trigger = snd_emu10k1_capture_trigger,
1569 .pointer = snd_emu10k1_capture_pointer,
1575 #define INITIAL_TRAM_SHIFT 14
1576 #define INITIAL_TRAM_POS(size) ((((size) / 2) - INITIAL_TRAM_SHIFT) - 1)
1578 static void snd_emu10k1_fx8010_playback_irq(struct snd_emu10k1 *emu, void *private_data)
1580 struct snd_pcm_substream *substream = private_data;
1581 snd_pcm_period_elapsed(substream);
1584 static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left,
1585 unsigned short *dst_right,
1586 unsigned short *src,
1588 unsigned int tram_shift)
1591 dev_dbg(emu->card->dev,
1592 "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
1593 "src = 0x%p, count = 0x%x\n",
1594 dst_left, dst_right, src, count);
1596 if ((tram_shift & 1) == 0) {
1598 *dst_left-- = *src++;
1599 *dst_right-- = *src++;
1603 *dst_right-- = *src++;
1604 *dst_left-- = *src++;
1609 static void fx8010_pb_trans_copy(struct snd_pcm_substream *substream,
1610 struct snd_pcm_indirect *rec, size_t bytes)
1612 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1613 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1614 unsigned int tram_size = pcm->buffer_size;
1615 unsigned short *src = (unsigned short *)(substream->runtime->dma_area + rec->sw_data);
1616 unsigned int frames = bytes >> 2, count;
1617 unsigned int tram_pos = pcm->tram_pos;
1618 unsigned int tram_shift = pcm->tram_shift;
1620 while (frames > tram_pos) {
1621 count = tram_pos + 1;
1622 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
1623 (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
1624 src, count, tram_shift);
1627 tram_pos = (tram_size / 2) - 1;
1630 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
1631 (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
1632 src, frames, tram_shift);
1634 pcm->tram_pos = tram_pos;
1635 pcm->tram_shift = tram_shift;
1638 static int snd_emu10k1_fx8010_playback_transfer(struct snd_pcm_substream *substream)
1640 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1641 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1643 return snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec,
1644 fx8010_pb_trans_copy);
1647 static int snd_emu10k1_fx8010_playback_hw_params(struct snd_pcm_substream *substream,
1648 struct snd_pcm_hw_params *hw_params)
1650 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1653 static int snd_emu10k1_fx8010_playback_hw_free(struct snd_pcm_substream *substream)
1655 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1656 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1659 for (i = 0; i < pcm->channels; i++)
1660 snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, 0);
1661 snd_pcm_lib_free_pages(substream);
1665 static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream *substream)
1667 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1668 struct snd_pcm_runtime *runtime = substream->runtime;
1669 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1673 dev_dbg(emu->card->dev, "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
1674 "buffer_size = 0x%x (0x%x)\n",
1675 emu->fx8010.etram_pages, runtime->dma_area,
1676 runtime->buffer_size, runtime->buffer_size << 2);
1678 memset(&pcm->pcm_rec, 0, sizeof(pcm->pcm_rec));
1679 pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2; /* byte size */
1680 pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
1681 pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
1682 pcm->tram_shift = 0;
1683 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_running, 0, 0); /* reset */
1684 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0); /* reset */
1685 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_size, 0, runtime->buffer_size);
1686 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_ptr, 0, 0); /* reset ptr number */
1687 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_count, 0, runtime->period_size);
1688 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_tmpcount, 0, runtime->period_size);
1689 for (i = 0; i < pcm->channels; i++)
1690 snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, (TANKMEMADDRREG_READ|TANKMEMADDRREG_ALIGN) + i * (runtime->buffer_size / pcm->channels));
1694 static int snd_emu10k1_fx8010_playback_trigger(struct snd_pcm_substream *substream, int cmd)
1696 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1697 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1700 spin_lock(&emu->reg_lock);
1702 case SNDRV_PCM_TRIGGER_START:
1704 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1705 case SNDRV_PCM_TRIGGER_RESUME:
1706 #ifdef EMU10K1_SET_AC3_IEC958
1709 for (i = 0; i < 3; i++) {
1711 bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1712 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS |
1713 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT | SPCS_NOTAUDIODATA;
1714 snd_emu10k1_ptr_write(emu, SPCS0 + i, 0, bits);
1718 result = snd_emu10k1_fx8010_register_irq_handler(emu, snd_emu10k1_fx8010_playback_irq, pcm->gpr_running, substream, &pcm->irq);
1721 snd_emu10k1_fx8010_playback_transfer(substream); /* roll the ball */
1722 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 1);
1724 case SNDRV_PCM_TRIGGER_STOP:
1725 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1726 case SNDRV_PCM_TRIGGER_SUSPEND:
1727 snd_emu10k1_fx8010_unregister_irq_handler(emu, pcm->irq); pcm->irq = NULL;
1728 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0);
1729 pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
1730 pcm->tram_shift = 0;
1737 spin_unlock(&emu->reg_lock);
1741 static snd_pcm_uframes_t snd_emu10k1_fx8010_playback_pointer(struct snd_pcm_substream *substream)
1743 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1744 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1745 size_t ptr; /* byte pointer */
1747 if (!snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_trigger, 0))
1749 ptr = snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_ptr, 0) << 2;
1750 return snd_pcm_indirect_playback_pointer(substream, &pcm->pcm_rec, ptr);
1753 static const struct snd_pcm_hardware snd_emu10k1_fx8010_playback =
1755 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1756 SNDRV_PCM_INFO_RESUME |
1757 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE),
1758 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
1759 .rates = SNDRV_PCM_RATE_48000,
1764 .buffer_bytes_max = (128*1024),
1765 .period_bytes_min = 1024,
1766 .period_bytes_max = (128*1024),
1768 .periods_max = 1024,
1772 static int snd_emu10k1_fx8010_playback_open(struct snd_pcm_substream *substream)
1774 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1775 struct snd_pcm_runtime *runtime = substream->runtime;
1776 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1778 runtime->hw = snd_emu10k1_fx8010_playback;
1779 runtime->hw.channels_min = runtime->hw.channels_max = pcm->channels;
1780 runtime->hw.period_bytes_max = (pcm->buffer_size * 2) / 2;
1781 spin_lock_irq(&emu->reg_lock);
1782 if (pcm->valid == 0) {
1783 spin_unlock_irq(&emu->reg_lock);
1787 spin_unlock_irq(&emu->reg_lock);
1791 static int snd_emu10k1_fx8010_playback_close(struct snd_pcm_substream *substream)
1793 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
1794 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1796 spin_lock_irq(&emu->reg_lock);
1798 spin_unlock_irq(&emu->reg_lock);
1802 static const struct snd_pcm_ops snd_emu10k1_fx8010_playback_ops = {
1803 .open = snd_emu10k1_fx8010_playback_open,
1804 .close = snd_emu10k1_fx8010_playback_close,
1805 .ioctl = snd_pcm_lib_ioctl,
1806 .hw_params = snd_emu10k1_fx8010_playback_hw_params,
1807 .hw_free = snd_emu10k1_fx8010_playback_hw_free,
1808 .prepare = snd_emu10k1_fx8010_playback_prepare,
1809 .trigger = snd_emu10k1_fx8010_playback_trigger,
1810 .pointer = snd_emu10k1_fx8010_playback_pointer,
1811 .ack = snd_emu10k1_fx8010_playback_transfer,
1814 int snd_emu10k1_pcm_efx(struct snd_emu10k1 *emu, int device)
1816 struct snd_pcm *pcm;
1817 struct snd_kcontrol *kctl;
1820 if ((err = snd_pcm_new(emu->card, "emu10k1 efx", device, 8, 1, &pcm)) < 0)
1823 pcm->private_data = emu;
1825 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_fx8010_playback_ops);
1826 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_efx_ops);
1828 pcm->info_flags = 0;
1829 strcpy(pcm->name, "Multichannel Capture/PT Playback");
1832 /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs
1836 /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */
1838 emu->efx_voices_mask[0] = 0;
1839 if (emu->card_capabilities->emu_model)
1840 /* Pavel Hofman - 32 voices will be used for
1841 * capture (write mode) -
1842 * each bit = corresponding voice
1844 emu->efx_voices_mask[1] = 0xffffffff;
1846 emu->efx_voices_mask[1] = 0xffff;
1848 emu->efx_voices_mask[0] = 0xffff0000;
1849 emu->efx_voices_mask[1] = 0;
1851 /* For emu1010, the control has to set 32 upper bits (voices)
1852 * out of the 64 bits (voices) to true for the 16-channels capture
1853 * to work correctly. Correct A_FXWC2 initial value (0xffffffff)
1854 * is already defined but the snd_emu10k1_pcm_efx_voices_mask
1855 * control can override this register's value.
1857 kctl = snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask, emu);
1860 kctl->id.device = device;
1861 snd_ctl_add(emu->card, kctl);
1863 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);