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 printk("IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
48 epcm
->substream
->runtime
->hw
->pointer(emu
, epcm
->substream
),
49 snd_pcm_lib_period_bytes(epcm
->substream
),
50 snd_pcm_lib_buffer_bytes(epcm
->substream
));
52 snd_pcm_period_elapsed(epcm
->substream
);
55 static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1
*emu
,
59 if (status
& IPR_ADCBUFHALFFULL
) {
60 if (emu
->pcm_capture_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
64 snd_pcm_period_elapsed(emu
->pcm_capture_substream
);
67 static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1
*emu
,
71 if (status
& IPR_MICBUFHALFFULL
) {
72 if (emu
->pcm_capture_mic_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
76 snd_pcm_period_elapsed(emu
->pcm_capture_mic_substream
);
79 static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1
*emu
,
83 if (status
& IPR_EFXBUFHALFFULL
) {
84 if (emu
->pcm_capture_efx_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
88 snd_pcm_period_elapsed(emu
->pcm_capture_efx_substream
);
91 static snd_pcm_uframes_t
snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream
*substream
)
93 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
94 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
95 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
100 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->voices
[0]->number
) & 0x00ffffff;
101 ptr
+= runtime
->buffer_size
;
102 ptr
-= epcm
->ccca_start_addr
;
103 ptr
%= runtime
->buffer_size
;
108 static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm
* epcm
, int voices
)
112 if (epcm
->voices
[1] != NULL
&& voices
< 2) {
113 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[1]);
114 epcm
->voices
[1] = NULL
;
116 for (i
= 0; i
< voices
; i
++) {
117 if (epcm
->voices
[i
] == NULL
)
121 return 0; /* already allocated */
123 for (i
= 0; i
< ARRAY_SIZE(epcm
->voices
); i
++) {
124 if (epcm
->voices
[i
]) {
125 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
126 epcm
->voices
[i
] = NULL
;
129 err
= snd_emu10k1_voice_alloc(epcm
->emu
,
130 epcm
->type
== PLAYBACK_EMUVOICE
? EMU10K1_PCM
: EMU10K1_EFX
,
136 epcm
->voices
[0]->epcm
= epcm
;
138 for (i
= 1; i
< voices
; i
++) {
139 epcm
->voices
[i
] = &epcm
->emu
->voices
[epcm
->voices
[0]->number
+ i
];
140 epcm
->voices
[i
]->epcm
= epcm
;
143 if (epcm
->extra
== NULL
) {
144 err
= snd_emu10k1_voice_alloc(epcm
->emu
,
145 epcm
->type
== PLAYBACK_EMUVOICE
? EMU10K1_PCM
: EMU10K1_EFX
,
149 /* printk("pcm_channel_alloc: failed extra: voices=%d, frame=%d\n", voices, frame); */
150 for (i
= 0; i
< voices
; i
++) {
151 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
152 epcm
->voices
[i
] = NULL
;
156 epcm
->extra
->epcm
= epcm
;
157 epcm
->extra
->interrupt
= snd_emu10k1_pcm_interrupt
;
162 static unsigned int capture_period_sizes
[31] = {
164 384*2, 448*2, 512*2, 640*2,
165 384*4, 448*4, 512*4, 640*4,
166 384*8, 448*8, 512*8, 640*8,
167 384*16, 448*16, 512*16, 640*16,
168 384*32, 448*32, 512*32, 640*32,
169 384*64, 448*64, 512*64, 640*64,
170 384*128,448*128,512*128
173 static struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes
= {
175 .list
= capture_period_sizes
,
179 static unsigned int capture_rates
[8] = {
180 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
183 static struct snd_pcm_hw_constraint_list hw_constraints_capture_rates
= {
185 .list
= capture_rates
,
189 static unsigned int snd_emu10k1_capture_rate_reg(unsigned int rate
)
192 case 8000: return ADCCR_SAMPLERATE_8
;
193 case 11025: return ADCCR_SAMPLERATE_11
;
194 case 16000: return ADCCR_SAMPLERATE_16
;
195 case 22050: return ADCCR_SAMPLERATE_22
;
196 case 24000: return ADCCR_SAMPLERATE_24
;
197 case 32000: return ADCCR_SAMPLERATE_32
;
198 case 44100: return ADCCR_SAMPLERATE_44
;
199 case 48000: return ADCCR_SAMPLERATE_48
;
202 return ADCCR_SAMPLERATE_8
;
206 static unsigned int snd_emu10k1_audigy_capture_rate_reg(unsigned int rate
)
209 case 8000: return A_ADCCR_SAMPLERATE_8
;
210 case 11025: return A_ADCCR_SAMPLERATE_11
;
211 case 12000: return A_ADCCR_SAMPLERATE_12
; /* really supported? */
212 case 16000: return ADCCR_SAMPLERATE_16
;
213 case 22050: return ADCCR_SAMPLERATE_22
;
214 case 24000: return ADCCR_SAMPLERATE_24
;
215 case 32000: return ADCCR_SAMPLERATE_32
;
216 case 44100: return ADCCR_SAMPLERATE_44
;
217 case 48000: return ADCCR_SAMPLERATE_48
;
220 return A_ADCCR_SAMPLERATE_8
;
224 static unsigned int emu10k1_calc_pitch_target(unsigned int rate
)
226 unsigned int pitch_target
;
228 pitch_target
= (rate
<< 8) / 375;
229 pitch_target
= (pitch_target
>> 1) + (pitch_target
& 1);
233 #define PITCH_48000 0x00004000
234 #define PITCH_96000 0x00008000
235 #define PITCH_85000 0x00007155
236 #define PITCH_80726 0x00006ba2
237 #define PITCH_67882 0x00005a82
238 #define PITCH_57081 0x00004c1c
240 static unsigned int emu10k1_select_interprom(unsigned int pitch_target
)
242 if (pitch_target
== PITCH_48000
)
243 return CCCA_INTERPROM_0
;
244 else if (pitch_target
< PITCH_48000
)
245 return CCCA_INTERPROM_1
;
246 else if (pitch_target
>= PITCH_96000
)
247 return CCCA_INTERPROM_0
;
248 else if (pitch_target
>= PITCH_85000
)
249 return CCCA_INTERPROM_6
;
250 else if (pitch_target
>= PITCH_80726
)
251 return CCCA_INTERPROM_5
;
252 else if (pitch_target
>= PITCH_67882
)
253 return CCCA_INTERPROM_4
;
254 else if (pitch_target
>= PITCH_57081
)
255 return CCCA_INTERPROM_3
;
257 return CCCA_INTERPROM_2
;
261 * calculate cache invalidate size
263 * stereo: channel is stereo
264 * w_16: using 16bit samples
266 * returns: cache invalidate size in samples
268 static inline int emu10k1_ccis(int stereo
, int w_16
)
271 return stereo
? 24 : 26;
273 return stereo
? 24*2 : 26*2;
277 static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1
*emu
,
278 int master
, int extra
,
279 struct snd_emu10k1_voice
*evoice
,
280 unsigned int start_addr
,
281 unsigned int end_addr
,
282 struct snd_emu10k1_pcm_mixer
*mix
)
284 struct snd_pcm_substream
*substream
= evoice
->epcm
->substream
;
285 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
286 unsigned int silent_page
, tmp
;
287 int voice
, stereo
, w_16
;
288 unsigned char attn
, send_amount
[8];
289 unsigned char send_routing
[8];
291 unsigned int pitch_target
;
294 voice
= evoice
->number
;
295 stereo
= runtime
->channels
== 2;
296 w_16
= snd_pcm_format_width(runtime
->format
) == 16;
298 if (!extra
&& stereo
) {
307 spin_lock_irqsave(&emu
->reg_lock
, flags
);
309 /* volume parameters */
312 memset(send_routing
, 0, sizeof(send_routing
));
317 memset(send_amount
, 0, sizeof(send_amount
));
319 /* mono, left, right (master voice = left) */
320 tmp
= stereo
? (master
? 1 : 2) : 0;
321 memcpy(send_routing
, &mix
->send_routing
[tmp
][0], 8);
322 memcpy(send_amount
, &mix
->send_volume
[tmp
][0], 8);
325 ccis
= emu10k1_ccis(stereo
, w_16
);
328 evoice
->epcm
->ccca_start_addr
= start_addr
+ ccis
;
333 if (stereo
&& !extra
) {
334 snd_emu10k1_ptr_write(emu
, CPF
, voice
, CPF_STEREO_MASK
);
335 snd_emu10k1_ptr_write(emu
, CPF
, (voice
+ 1), CPF_STEREO_MASK
);
337 snd_emu10k1_ptr_write(emu
, CPF
, voice
, 0);
343 snd_emu10k1_ptr_write(emu
, A_FXRT1
, voice
,
344 snd_emu10k1_compose_audigy_fxrt1(send_routing
));
345 snd_emu10k1_ptr_write(emu
, A_FXRT2
, voice
,
346 snd_emu10k1_compose_audigy_fxrt2(send_routing
));
347 snd_emu10k1_ptr_write(emu
, A_SENDAMOUNTS
, voice
,
348 ((unsigned int)send_amount
[4] << 24) |
349 ((unsigned int)send_amount
[5] << 16) |
350 ((unsigned int)send_amount
[6] << 8) |
351 (unsigned int)send_amount
[7]);
353 snd_emu10k1_ptr_write(emu
, FXRT
, voice
,
354 snd_emu10k1_compose_send_routing(send_routing
));
356 /* Assumption that PT is already 0 so no harm overwriting */
357 snd_emu10k1_ptr_write(emu
, PTRX
, voice
, (send_amount
[0] << 8) | send_amount
[1]);
358 snd_emu10k1_ptr_write(emu
, DSL
, voice
, end_addr
| (send_amount
[3] << 24));
359 snd_emu10k1_ptr_write(emu
, PSST
, voice
, start_addr
| (send_amount
[2] << 24));
360 if (emu
->card_capabilities
->emu_model
)
361 pitch_target
= PITCH_48000
; /* Disable interpolators on emu1010 card */
363 pitch_target
= emu10k1_calc_pitch_target(runtime
->rate
);
365 snd_emu10k1_ptr_write(emu
, CCCA
, voice
, start_addr
|
366 emu10k1_select_interprom(pitch_target
) |
367 (w_16
? 0 : CCCA_8BITSELECT
));
369 snd_emu10k1_ptr_write(emu
, CCCA
, voice
, (start_addr
+ ccis
) |
370 emu10k1_select_interprom(pitch_target
) |
371 (w_16
? 0 : CCCA_8BITSELECT
));
372 /* Clear filter delay memory */
373 snd_emu10k1_ptr_write(emu
, Z1
, voice
, 0);
374 snd_emu10k1_ptr_write(emu
, Z2
, voice
, 0);
375 /* invalidate maps */
376 silent_page
= ((unsigned int)emu
->silent_page
.addr
<< 1) | MAP_PTI_MASK
;
377 snd_emu10k1_ptr_write(emu
, MAPA
, voice
, silent_page
);
378 snd_emu10k1_ptr_write(emu
, MAPB
, voice
, silent_page
);
379 /* modulation envelope */
380 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, 0xffff);
381 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, 0xffff);
382 snd_emu10k1_ptr_write(emu
, ATKHLDM
, voice
, 0);
383 snd_emu10k1_ptr_write(emu
, DCYSUSM
, voice
, 0x007f);
384 snd_emu10k1_ptr_write(emu
, LFOVAL1
, voice
, 0x8000);
385 snd_emu10k1_ptr_write(emu
, LFOVAL2
, voice
, 0x8000);
386 snd_emu10k1_ptr_write(emu
, FMMOD
, voice
, 0);
387 snd_emu10k1_ptr_write(emu
, TREMFRQ
, voice
, 0);
388 snd_emu10k1_ptr_write(emu
, FM2FRQ2
, voice
, 0);
389 snd_emu10k1_ptr_write(emu
, ENVVAL
, voice
, 0x8000);
390 /* volume envelope */
391 snd_emu10k1_ptr_write(emu
, ATKHLDV
, voice
, 0x7f7f);
392 snd_emu10k1_ptr_write(emu
, ENVVOL
, voice
, 0x0000);
393 /* filter envelope */
394 snd_emu10k1_ptr_write(emu
, PEFE_FILTERAMOUNT
, voice
, 0x7f);
396 snd_emu10k1_ptr_write(emu
, PEFE_PITCHAMOUNT
, voice
, 0);
398 spin_unlock_irqrestore(&emu
->reg_lock
, flags
);
401 static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream
*substream
,
402 struct snd_pcm_hw_params
*hw_params
)
404 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
405 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
406 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
409 if ((err
= snd_emu10k1_pcm_channel_alloc(epcm
, params_channels(hw_params
))) < 0)
411 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
413 if (err
> 0) { /* change */
415 if (epcm
->memblk
!= NULL
)
416 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
417 epcm
->memblk
= snd_emu10k1_alloc_pages(emu
, substream
);
418 epcm
->start_addr
= 0;
421 mapped
= ((struct snd_emu10k1_memblk
*)epcm
->memblk
)->mapped_page
;
424 epcm
->start_addr
= mapped
<< PAGE_SHIFT
;
429 static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream
*substream
)
431 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
432 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
433 struct snd_emu10k1_pcm
*epcm
;
435 if (runtime
->private_data
== NULL
)
437 epcm
= runtime
->private_data
;
439 snd_emu10k1_voice_free(epcm
->emu
, epcm
->extra
);
442 if (epcm
->voices
[1]) {
443 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[1]);
444 epcm
->voices
[1] = NULL
;
446 if (epcm
->voices
[0]) {
447 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[0]);
448 epcm
->voices
[0] = NULL
;
451 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
453 epcm
->start_addr
= 0;
455 snd_pcm_lib_free_pages(substream
);
459 static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream
*substream
)
461 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
462 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
463 struct snd_emu10k1_pcm
*epcm
;
466 if (runtime
->private_data
== NULL
)
468 epcm
= runtime
->private_data
;
470 snd_emu10k1_voice_free(epcm
->emu
, epcm
->extra
);
473 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
474 if (epcm
->voices
[i
]) {
475 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
476 epcm
->voices
[i
] = NULL
;
480 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
482 epcm
->start_addr
= 0;
484 snd_pcm_lib_free_pages(substream
);
488 static int snd_emu10k1_playback_prepare(struct snd_pcm_substream
*substream
)
490 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
491 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
492 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
493 unsigned int start_addr
, end_addr
;
495 start_addr
= epcm
->start_addr
;
496 end_addr
= snd_pcm_lib_period_bytes(substream
);
497 if (runtime
->channels
== 2) {
501 end_addr
+= start_addr
;
502 snd_emu10k1_pcm_init_voice(emu
, 1, 1, epcm
->extra
,
503 start_addr
, end_addr
, NULL
);
504 start_addr
= epcm
->start_addr
;
505 end_addr
= epcm
->start_addr
+ snd_pcm_lib_buffer_bytes(substream
);
506 snd_emu10k1_pcm_init_voice(emu
, 1, 0, epcm
->voices
[0],
507 start_addr
, end_addr
,
508 &emu
->pcm_mixer
[substream
->number
]);
510 snd_emu10k1_pcm_init_voice(emu
, 0, 0, epcm
->voices
[1],
511 start_addr
, end_addr
,
512 &emu
->pcm_mixer
[substream
->number
]);
516 static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream
*substream
)
518 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
519 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
520 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
521 unsigned int start_addr
, end_addr
;
522 unsigned int channel_size
;
525 start_addr
= epcm
->start_addr
;
526 end_addr
= epcm
->start_addr
+ snd_pcm_lib_buffer_bytes(substream
);
529 * the kX driver leaves some space between voices
531 channel_size
= ( end_addr
- start_addr
) / NUM_EFX_PLAYBACK
;
533 snd_emu10k1_pcm_init_voice(emu
, 1, 1, epcm
->extra
,
534 start_addr
, start_addr
+ (channel_size
/ 2), NULL
);
536 /* only difference with the master voice is we use it for the pointer */
537 snd_emu10k1_pcm_init_voice(emu
, 1, 0, epcm
->voices
[0],
538 start_addr
, start_addr
+ channel_size
,
539 &emu
->efx_pcm_mixer
[0]);
541 start_addr
+= channel_size
;
542 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++) {
543 snd_emu10k1_pcm_init_voice(emu
, 0, 0, epcm
->voices
[i
],
544 start_addr
, start_addr
+ channel_size
,
545 &emu
->efx_pcm_mixer
[i
]);
546 start_addr
+= channel_size
;
552 static struct snd_pcm_hardware snd_emu10k1_efx_playback
=
554 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_NONINTERLEAVED
|
555 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
556 SNDRV_PCM_INFO_RESUME
|
557 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
),
558 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
559 .rates
= SNDRV_PCM_RATE_48000
,
562 .channels_min
= NUM_EFX_PLAYBACK
,
563 .channels_max
= NUM_EFX_PLAYBACK
,
564 .buffer_bytes_max
= (64*1024),
565 .period_bytes_min
= 64,
566 .period_bytes_max
= (64*1024),
572 static int snd_emu10k1_capture_hw_params(struct snd_pcm_substream
*substream
,
573 struct snd_pcm_hw_params
*hw_params
)
575 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
578 static int snd_emu10k1_capture_hw_free(struct snd_pcm_substream
*substream
)
580 return snd_pcm_lib_free_pages(substream
);
583 static int snd_emu10k1_capture_prepare(struct snd_pcm_substream
*substream
)
585 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
586 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
587 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
590 /* zeroing the buffer size will stop capture */
591 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, 0);
592 switch (epcm
->type
) {
593 case CAPTURE_AC97ADC
:
594 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, 0);
598 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, 0);
599 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, 0);
601 snd_emu10k1_ptr_write(emu
, FXWC
, 0, 0);
606 snd_emu10k1_ptr_write(emu
, epcm
->capture_ba_reg
, 0, runtime
->dma_addr
);
607 epcm
->capture_bufsize
= snd_pcm_lib_buffer_bytes(substream
);
608 epcm
->capture_bs_val
= 0;
609 for (idx
= 0; idx
< 31; idx
++) {
610 if (capture_period_sizes
[idx
] == epcm
->capture_bufsize
) {
611 epcm
->capture_bs_val
= idx
+ 1;
615 if (epcm
->capture_bs_val
== 0) {
617 epcm
->capture_bs_val
++;
619 if (epcm
->type
== CAPTURE_AC97ADC
) {
620 epcm
->capture_cr_val
= emu
->audigy
? A_ADCCR_LCHANENABLE
: ADCCR_LCHANENABLE
;
621 if (runtime
->channels
> 1)
622 epcm
->capture_cr_val
|= emu
->audigy
? A_ADCCR_RCHANENABLE
: ADCCR_RCHANENABLE
;
623 epcm
->capture_cr_val
|= emu
->audigy
?
624 snd_emu10k1_audigy_capture_rate_reg(runtime
->rate
) :
625 snd_emu10k1_capture_rate_reg(runtime
->rate
);
630 static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1
*emu
, int extra
, struct snd_emu10k1_voice
*evoice
)
632 struct snd_pcm_runtime
*runtime
;
633 unsigned int voice
, stereo
, i
, ccis
, cra
= 64, cs
, sample
;
637 runtime
= evoice
->epcm
->substream
->runtime
;
638 voice
= evoice
->number
;
639 stereo
= (!extra
&& runtime
->channels
== 2);
640 sample
= snd_pcm_format_width(runtime
->format
) == 16 ? 0 : 0x80808080;
641 ccis
= emu10k1_ccis(stereo
, sample
== 0);
642 /* set cs to 2 * number of cache registers beside the invalidated */
643 cs
= (sample
== 0) ? (32-ccis
) : (64-ccis
+1) >> 1;
644 if (cs
> 16) cs
= 16;
645 for (i
= 0; i
< cs
; i
++) {
646 snd_emu10k1_ptr_write(emu
, CD0
+ i
, voice
, sample
);
648 snd_emu10k1_ptr_write(emu
, CD0
+ i
, voice
+ 1, sample
);
652 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
, 0);
653 snd_emu10k1_ptr_write(emu
, CCR_READADDRESS
, voice
, cra
);
655 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
+ 1, 0);
656 snd_emu10k1_ptr_write(emu
, CCR_READADDRESS
, voice
+ 1, cra
);
659 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
, ccis
);
661 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
+1, ccis
);
665 static void snd_emu10k1_playback_prepare_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
,
666 int master
, int extra
,
667 struct snd_emu10k1_pcm_mixer
*mix
)
669 struct snd_pcm_substream
*substream
;
670 struct snd_pcm_runtime
*runtime
;
671 unsigned int attn
, vattn
;
672 unsigned int voice
, tmp
;
674 if (evoice
== NULL
) /* skip second voice for mono */
676 substream
= evoice
->epcm
->substream
;
677 runtime
= substream
->runtime
;
678 voice
= evoice
->number
;
680 attn
= extra
? 0 : 0x00ff;
681 tmp
= runtime
->channels
== 2 ? (master
? 1 : 2) : 0;
682 vattn
= mix
!= NULL
? (mix
->attn
[tmp
] << 16) : 0;
683 snd_emu10k1_ptr_write(emu
, IFATN
, voice
, attn
);
684 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, vattn
| 0xffff);
685 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, vattn
| 0xffff);
686 snd_emu10k1_ptr_write(emu
, DCYSUSV
, voice
, 0x7f7f);
687 snd_emu10k1_voice_clear_loop_stop(emu
, voice
);
690 static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
, int master
, int extra
)
692 struct snd_pcm_substream
*substream
;
693 struct snd_pcm_runtime
*runtime
;
694 unsigned int voice
, pitch
, pitch_target
;
696 if (evoice
== NULL
) /* skip second voice for mono */
698 substream
= evoice
->epcm
->substream
;
699 runtime
= substream
->runtime
;
700 voice
= evoice
->number
;
702 pitch
= snd_emu10k1_rate_to_pitch(runtime
->rate
) >> 8;
703 if (emu
->card_capabilities
->emu_model
)
704 pitch_target
= PITCH_48000
; /* Disable interpolators on emu1010 card */
706 pitch_target
= emu10k1_calc_pitch_target(runtime
->rate
);
707 snd_emu10k1_ptr_write(emu
, PTRX_PITCHTARGET
, voice
, pitch_target
);
708 if (master
|| evoice
->epcm
->type
== PLAYBACK_EFX
)
709 snd_emu10k1_ptr_write(emu
, CPF_CURRENTPITCH
, voice
, pitch_target
);
710 snd_emu10k1_ptr_write(emu
, IP
, voice
, pitch
);
712 snd_emu10k1_voice_intr_enable(emu
, voice
);
715 static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
)
721 voice
= evoice
->number
;
722 snd_emu10k1_voice_intr_disable(emu
, voice
);
723 snd_emu10k1_ptr_write(emu
, PTRX_PITCHTARGET
, voice
, 0);
724 snd_emu10k1_ptr_write(emu
, CPF_CURRENTPITCH
, voice
, 0);
725 snd_emu10k1_ptr_write(emu
, IFATN
, voice
, 0xffff);
726 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, 0xffff);
727 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, 0xffff);
728 snd_emu10k1_ptr_write(emu
, IP
, voice
, 0);
731 static int snd_emu10k1_playback_trigger(struct snd_pcm_substream
*substream
,
734 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
735 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
736 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
737 struct snd_emu10k1_pcm_mixer
*mix
;
740 /* printk("trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n", (int)emu, cmd, substream->ops->pointer(substream)); */
741 spin_lock(&emu
->reg_lock
);
743 case SNDRV_PCM_TRIGGER_START
:
744 snd_emu10k1_playback_invalidate_cache(emu
, 1, epcm
->extra
); /* do we need this? */
745 snd_emu10k1_playback_invalidate_cache(emu
, 0, epcm
->voices
[0]);
747 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
748 case SNDRV_PCM_TRIGGER_RESUME
:
749 mix
= &emu
->pcm_mixer
[substream
->number
];
750 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[0], 1, 0, mix
);
751 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[1], 0, 0, mix
);
752 snd_emu10k1_playback_prepare_voice(emu
, epcm
->extra
, 1, 1, NULL
);
753 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[0], 1, 0);
754 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[1], 0, 0);
755 snd_emu10k1_playback_trigger_voice(emu
, epcm
->extra
, 1, 1);
758 case SNDRV_PCM_TRIGGER_STOP
:
759 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
760 case SNDRV_PCM_TRIGGER_SUSPEND
:
762 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[0]);
763 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[1]);
764 snd_emu10k1_playback_stop_voice(emu
, epcm
->extra
);
770 spin_unlock(&emu
->reg_lock
);
774 static int snd_emu10k1_capture_trigger(struct snd_pcm_substream
*substream
,
777 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
778 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
779 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
782 spin_lock(&emu
->reg_lock
);
784 case SNDRV_PCM_TRIGGER_START
:
785 case SNDRV_PCM_TRIGGER_RESUME
:
786 /* hmm this should cause full and half full interrupt to be raised? */
787 outl(epcm
->capture_ipr
, emu
->port
+ IPR
);
788 snd_emu10k1_intr_enable(emu
, epcm
->capture_inte
);
789 /* printk("adccr = 0x%x, adcbs = 0x%x\n", epcm->adccr, epcm->adcbs); */
790 switch (epcm
->type
) {
791 case CAPTURE_AC97ADC
:
792 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, epcm
->capture_cr_val
);
796 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, epcm
->capture_cr_val
);
797 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, epcm
->capture_cr_val2
);
798 snd_printdd("cr_val=0x%x, cr_val2=0x%x\n", epcm
->capture_cr_val
, epcm
->capture_cr_val2
);
800 snd_emu10k1_ptr_write(emu
, FXWC
, 0, epcm
->capture_cr_val
);
805 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, epcm
->capture_bs_val
);
809 case SNDRV_PCM_TRIGGER_STOP
:
810 case SNDRV_PCM_TRIGGER_SUSPEND
:
812 snd_emu10k1_intr_disable(emu
, epcm
->capture_inte
);
813 outl(epcm
->capture_ipr
, emu
->port
+ IPR
);
814 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, 0);
815 switch (epcm
->type
) {
816 case CAPTURE_AC97ADC
:
817 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, 0);
821 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, 0);
822 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, 0);
824 snd_emu10k1_ptr_write(emu
, FXWC
, 0, 0);
833 spin_unlock(&emu
->reg_lock
);
837 static snd_pcm_uframes_t
snd_emu10k1_playback_pointer(struct snd_pcm_substream
*substream
)
839 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
840 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
841 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
846 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->voices
[0]->number
) & 0x00ffffff;
847 #if 0 /* Perex's code */
848 ptr
+= runtime
->buffer_size
;
849 ptr
-= epcm
->ccca_start_addr
;
850 ptr
%= runtime
->buffer_size
;
851 #else /* EMU10K1 Open Source code from Creative */
852 if (ptr
< epcm
->ccca_start_addr
)
853 ptr
+= runtime
->buffer_size
- epcm
->ccca_start_addr
;
855 ptr
-= epcm
->ccca_start_addr
;
856 if (ptr
>= runtime
->buffer_size
)
857 ptr
-= runtime
->buffer_size
;
860 /* printk("ptr = 0x%x, buffer_size = 0x%x, period_size = 0x%x\n", ptr, runtime->buffer_size, runtime->period_size); */
865 static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream
*substream
,
868 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
869 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
870 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
874 spin_lock(&emu
->reg_lock
);
876 case SNDRV_PCM_TRIGGER_START
:
878 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
879 snd_emu10k1_playback_invalidate_cache(emu
, 0, epcm
->voices
[i
]);
881 snd_emu10k1_playback_invalidate_cache(emu
, 1, epcm
->extra
);
884 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
885 case SNDRV_PCM_TRIGGER_RESUME
:
886 snd_emu10k1_playback_prepare_voice(emu
, epcm
->extra
, 1, 1, NULL
);
887 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[0], 0, 0,
888 &emu
->efx_pcm_mixer
[0]);
889 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++)
890 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[i
], 0, 0,
891 &emu
->efx_pcm_mixer
[i
]);
892 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[0], 0, 0);
893 snd_emu10k1_playback_trigger_voice(emu
, epcm
->extra
, 1, 1);
894 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++)
895 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[i
], 0, 0);
898 case SNDRV_PCM_TRIGGER_SUSPEND
:
899 case SNDRV_PCM_TRIGGER_STOP
:
900 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
902 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
903 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[i
]);
905 snd_emu10k1_playback_stop_voice(emu
, epcm
->extra
);
911 spin_unlock(&emu
->reg_lock
);
916 static snd_pcm_uframes_t
snd_emu10k1_capture_pointer(struct snd_pcm_substream
*substream
)
918 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
919 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
920 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
925 if (epcm
->first_ptr
) {
926 udelay(50); /* hack, it takes awhile until capture is started */
929 ptr
= snd_emu10k1_ptr_read(emu
, epcm
->capture_idx_reg
, 0) & 0x0000ffff;
930 return bytes_to_frames(runtime
, ptr
);
934 * Playback support device description
937 static struct snd_pcm_hardware snd_emu10k1_playback
=
939 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
940 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
941 SNDRV_PCM_INFO_RESUME
|
942 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
),
943 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
944 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_96000
,
949 .buffer_bytes_max
= (128*1024),
950 .period_bytes_min
= 64,
951 .period_bytes_max
= (128*1024),
958 * Capture support device description
961 static struct snd_pcm_hardware snd_emu10k1_capture
=
963 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
964 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
965 SNDRV_PCM_INFO_RESUME
|
966 SNDRV_PCM_INFO_MMAP_VALID
),
967 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
968 .rates
= SNDRV_PCM_RATE_8000_48000
,
973 .buffer_bytes_max
= (64*1024),
974 .period_bytes_min
= 384,
975 .period_bytes_max
= (64*1024),
981 static struct snd_pcm_hardware snd_emu10k1_capture_efx
=
983 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
984 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
985 SNDRV_PCM_INFO_RESUME
|
986 SNDRV_PCM_INFO_MMAP_VALID
),
987 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
988 .rates
= SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
|
989 SNDRV_PCM_RATE_88200
| SNDRV_PCM_RATE_96000
|
990 SNDRV_PCM_RATE_176400
| SNDRV_PCM_RATE_192000
,
995 .buffer_bytes_max
= (64*1024),
996 .period_bytes_min
= 384,
997 .period_bytes_max
= (64*1024),
1007 static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1
*emu
, struct snd_kcontrol
*kctl
, int idx
, int activate
)
1009 struct snd_ctl_elem_id id
;
1014 kctl
->vd
[idx
].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1016 kctl
->vd
[idx
].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1017 snd_ctl_notify(emu
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1018 SNDRV_CTL_EVENT_MASK_INFO
,
1019 snd_ctl_build_ioff(&id
, kctl
, idx
));
1022 static void snd_emu10k1_pcm_mixer_notify(struct snd_emu10k1
*emu
, int idx
, int activate
)
1024 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_send_routing
, idx
, activate
);
1025 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_send_volume
, idx
, activate
);
1026 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_attn
, idx
, activate
);
1029 static void snd_emu10k1_pcm_efx_mixer_notify(struct snd_emu10k1
*emu
, int idx
, int activate
)
1031 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_send_routing
, idx
, activate
);
1032 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_send_volume
, idx
, activate
);
1033 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_attn
, idx
, activate
);
1036 static void snd_emu10k1_pcm_free_substream(struct snd_pcm_runtime
*runtime
)
1038 kfree(runtime
->private_data
);
1041 static int snd_emu10k1_efx_playback_close(struct snd_pcm_substream
*substream
)
1043 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1044 struct snd_emu10k1_pcm_mixer
*mix
;
1047 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
1048 mix
= &emu
->efx_pcm_mixer
[i
];
1050 snd_emu10k1_pcm_efx_mixer_notify(emu
, i
, 0);
1055 static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream
*substream
)
1057 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1058 struct snd_emu10k1_pcm
*epcm
;
1059 struct snd_emu10k1_pcm_mixer
*mix
;
1060 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1063 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1067 epcm
->type
= PLAYBACK_EFX
;
1068 epcm
->substream
= substream
;
1070 emu
->pcm_playback_efx_substream
= substream
;
1072 runtime
->private_data
= epcm
;
1073 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1074 runtime
->hw
= snd_emu10k1_efx_playback
;
1076 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
1077 mix
= &emu
->efx_pcm_mixer
[i
];
1078 mix
->send_routing
[0][0] = i
;
1079 memset(&mix
->send_volume
, 0, sizeof(mix
->send_volume
));
1080 mix
->send_volume
[0][0] = 255;
1081 mix
->attn
[0] = 0xffff;
1083 snd_emu10k1_pcm_efx_mixer_notify(emu
, i
, 1);
1088 static int snd_emu10k1_playback_open(struct snd_pcm_substream
*substream
)
1090 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1091 struct snd_emu10k1_pcm
*epcm
;
1092 struct snd_emu10k1_pcm_mixer
*mix
;
1093 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1096 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1100 epcm
->type
= PLAYBACK_EMUVOICE
;
1101 epcm
->substream
= substream
;
1102 runtime
->private_data
= epcm
;
1103 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1104 runtime
->hw
= snd_emu10k1_playback
;
1105 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0) {
1109 if ((err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 256, UINT_MAX
)) < 0) {
1113 mix
= &emu
->pcm_mixer
[substream
->number
];
1114 for (i
= 0; i
< 4; i
++)
1115 mix
->send_routing
[0][i
] = mix
->send_routing
[1][i
] = mix
->send_routing
[2][i
] = i
;
1116 memset(&mix
->send_volume
, 0, sizeof(mix
->send_volume
));
1117 mix
->send_volume
[0][0] = mix
->send_volume
[0][1] =
1118 mix
->send_volume
[1][0] = mix
->send_volume
[2][1] = 255;
1119 mix
->attn
[0] = mix
->attn
[1] = mix
->attn
[2] = 0xffff;
1121 snd_emu10k1_pcm_mixer_notify(emu
, substream
->number
, 1);
1125 static int snd_emu10k1_playback_close(struct snd_pcm_substream
*substream
)
1127 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1128 struct snd_emu10k1_pcm_mixer
*mix
= &emu
->pcm_mixer
[substream
->number
];
1131 snd_emu10k1_pcm_mixer_notify(emu
, substream
->number
, 0);
1135 static int snd_emu10k1_capture_open(struct snd_pcm_substream
*substream
)
1137 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1138 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1139 struct snd_emu10k1_pcm
*epcm
;
1141 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1145 epcm
->type
= CAPTURE_AC97ADC
;
1146 epcm
->substream
= substream
;
1147 epcm
->capture_ipr
= IPR_ADCBUFFULL
|IPR_ADCBUFHALFFULL
;
1148 epcm
->capture_inte
= INTE_ADCBUFENABLE
;
1149 epcm
->capture_ba_reg
= ADCBA
;
1150 epcm
->capture_bs_reg
= ADCBS
;
1151 epcm
->capture_idx_reg
= emu
->audigy
? A_ADCIDX
: ADCIDX
;
1152 runtime
->private_data
= epcm
;
1153 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1154 runtime
->hw
= snd_emu10k1_capture
;
1155 emu
->capture_interrupt
= snd_emu10k1_pcm_ac97adc_interrupt
;
1156 emu
->pcm_capture_substream
= substream
;
1157 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1158 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_capture_rates
);
1162 static int snd_emu10k1_capture_close(struct snd_pcm_substream
*substream
)
1164 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1166 emu
->capture_interrupt
= NULL
;
1167 emu
->pcm_capture_substream
= NULL
;
1171 static int snd_emu10k1_capture_mic_open(struct snd_pcm_substream
*substream
)
1173 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1174 struct snd_emu10k1_pcm
*epcm
;
1175 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1177 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1181 epcm
->type
= CAPTURE_AC97MIC
;
1182 epcm
->substream
= substream
;
1183 epcm
->capture_ipr
= IPR_MICBUFFULL
|IPR_MICBUFHALFFULL
;
1184 epcm
->capture_inte
= INTE_MICBUFENABLE
;
1185 epcm
->capture_ba_reg
= MICBA
;
1186 epcm
->capture_bs_reg
= MICBS
;
1187 epcm
->capture_idx_reg
= emu
->audigy
? A_MICIDX
: MICIDX
;
1188 substream
->runtime
->private_data
= epcm
;
1189 substream
->runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1190 runtime
->hw
= snd_emu10k1_capture
;
1191 runtime
->hw
.rates
= SNDRV_PCM_RATE_8000
;
1192 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 8000;
1193 runtime
->hw
.channels_min
= 1;
1194 emu
->capture_mic_interrupt
= snd_emu10k1_pcm_ac97mic_interrupt
;
1195 emu
->pcm_capture_mic_substream
= substream
;
1196 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1200 static int snd_emu10k1_capture_mic_close(struct snd_pcm_substream
*substream
)
1202 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1204 emu
->capture_interrupt
= NULL
;
1205 emu
->pcm_capture_mic_substream
= NULL
;
1209 static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream
*substream
)
1211 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1212 struct snd_emu10k1_pcm
*epcm
;
1213 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1214 int nefx
= emu
->audigy
? 64 : 32;
1217 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1221 epcm
->type
= CAPTURE_EFX
;
1222 epcm
->substream
= substream
;
1223 epcm
->capture_ipr
= IPR_EFXBUFFULL
|IPR_EFXBUFHALFFULL
;
1224 epcm
->capture_inte
= INTE_EFXBUFENABLE
;
1225 epcm
->capture_ba_reg
= FXBA
;
1226 epcm
->capture_bs_reg
= FXBS
;
1227 epcm
->capture_idx_reg
= FXIDX
;
1228 substream
->runtime
->private_data
= epcm
;
1229 substream
->runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1230 runtime
->hw
= snd_emu10k1_capture_efx
;
1231 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
1232 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 48000;
1233 spin_lock_irq(&emu
->reg_lock
);
1234 if (emu
->card_capabilities
->emu_model
) {
1235 /* Nb. of channels has been increased to 16 */
1237 * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE
1238 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
1239 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
1240 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000
1242 * rate_max = 192000,
1243 * channels_min = 16,
1244 * channels_max = 16,
1245 * Need to add mixer control to fix sample rate
1247 * There are 32 mono channels of 16bits each.
1248 * 24bit Audio uses 2x channels over 16bit
1249 * 96kHz uses 2x channels over 48kHz
1250 * 192kHz uses 4x channels over 48kHz
1251 * So, for 48kHz 24bit, one has 16 channels
1252 * for 96kHz 24bit, one has 8 channels
1253 * for 192kHz 24bit, one has 4 channels
1257 switch (emu
->emu1010
.internal_clock
) {
1260 runtime
->hw
.rates
= SNDRV_PCM_RATE_44100
;
1261 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 44100;
1262 runtime
->hw
.channels_min
=
1263 runtime
->hw
.channels_max
= 16;
1267 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
1268 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 48000;
1269 runtime
->hw
.channels_min
=
1270 runtime
->hw
.channels_max
= 16;
1276 runtime
->hw
.rates
= SNDRV_PCM_RATE_96000
;
1277 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 96000;
1278 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 4;
1282 runtime
->hw
.rates
= SNDRV_PCM_RATE_192000
;
1283 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 192000;
1284 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 2;
1286 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S32_LE
;
1287 /* efx_voices_mask[0] is expected to be zero
1288 * efx_voices_mask[1] is expected to have 32bits set
1291 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 0;
1292 for (idx
= 0; idx
< nefx
; idx
++) {
1293 if (emu
->efx_voices_mask
[idx
/32] & (1 << (idx
%32))) {
1294 runtime
->hw
.channels_min
++;
1295 runtime
->hw
.channels_max
++;
1299 epcm
->capture_cr_val
= emu
->efx_voices_mask
[0];
1300 epcm
->capture_cr_val2
= emu
->efx_voices_mask
[1];
1301 spin_unlock_irq(&emu
->reg_lock
);
1302 emu
->capture_efx_interrupt
= snd_emu10k1_pcm_efx_interrupt
;
1303 emu
->pcm_capture_efx_substream
= substream
;
1304 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1308 static int snd_emu10k1_capture_efx_close(struct snd_pcm_substream
*substream
)
1310 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1312 emu
->capture_interrupt
= NULL
;
1313 emu
->pcm_capture_efx_substream
= NULL
;
1317 static struct snd_pcm_ops snd_emu10k1_playback_ops
= {
1318 .open
= snd_emu10k1_playback_open
,
1319 .close
= snd_emu10k1_playback_close
,
1320 .ioctl
= snd_pcm_lib_ioctl
,
1321 .hw_params
= snd_emu10k1_playback_hw_params
,
1322 .hw_free
= snd_emu10k1_playback_hw_free
,
1323 .prepare
= snd_emu10k1_playback_prepare
,
1324 .trigger
= snd_emu10k1_playback_trigger
,
1325 .pointer
= snd_emu10k1_playback_pointer
,
1326 .page
= snd_pcm_sgbuf_ops_page
,
1329 static struct snd_pcm_ops snd_emu10k1_capture_ops
= {
1330 .open
= snd_emu10k1_capture_open
,
1331 .close
= snd_emu10k1_capture_close
,
1332 .ioctl
= snd_pcm_lib_ioctl
,
1333 .hw_params
= snd_emu10k1_capture_hw_params
,
1334 .hw_free
= snd_emu10k1_capture_hw_free
,
1335 .prepare
= snd_emu10k1_capture_prepare
,
1336 .trigger
= snd_emu10k1_capture_trigger
,
1337 .pointer
= snd_emu10k1_capture_pointer
,
1341 static struct snd_pcm_ops snd_emu10k1_efx_playback_ops
= {
1342 .open
= snd_emu10k1_efx_playback_open
,
1343 .close
= snd_emu10k1_efx_playback_close
,
1344 .ioctl
= snd_pcm_lib_ioctl
,
1345 .hw_params
= snd_emu10k1_playback_hw_params
,
1346 .hw_free
= snd_emu10k1_efx_playback_hw_free
,
1347 .prepare
= snd_emu10k1_efx_playback_prepare
,
1348 .trigger
= snd_emu10k1_efx_playback_trigger
,
1349 .pointer
= snd_emu10k1_efx_playback_pointer
,
1350 .page
= snd_pcm_sgbuf_ops_page
,
1353 int __devinit
snd_emu10k1_pcm(struct snd_emu10k1
* emu
, int device
, struct snd_pcm
** rpcm
)
1355 struct snd_pcm
*pcm
;
1356 struct snd_pcm_substream
*substream
;
1362 if ((err
= snd_pcm_new(emu
->card
, "emu10k1", device
, 32, 1, &pcm
)) < 0)
1365 pcm
->private_data
= emu
;
1367 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_playback_ops
);
1368 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_ops
);
1370 pcm
->info_flags
= 0;
1371 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1372 strcpy(pcm
->name
, "ADC Capture/Standard PCM Playback");
1375 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
1376 if ((err
= snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024)) < 0)
1379 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
; substream
; substream
= substream
->next
)
1380 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);
1388 int __devinit
snd_emu10k1_pcm_multi(struct snd_emu10k1
* emu
, int device
, struct snd_pcm
** rpcm
)
1390 struct snd_pcm
*pcm
;
1391 struct snd_pcm_substream
*substream
;
1397 if ((err
= snd_pcm_new(emu
->card
, "emu10k1", device
, 1, 0, &pcm
)) < 0)
1400 pcm
->private_data
= emu
;
1402 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_efx_playback_ops
);
1404 pcm
->info_flags
= 0;
1405 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1406 strcpy(pcm
->name
, "Multichannel Playback");
1407 emu
->pcm_multi
= pcm
;
1409 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
1410 if ((err
= snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024)) < 0)
1420 static struct snd_pcm_ops snd_emu10k1_capture_mic_ops
= {
1421 .open
= snd_emu10k1_capture_mic_open
,
1422 .close
= snd_emu10k1_capture_mic_close
,
1423 .ioctl
= snd_pcm_lib_ioctl
,
1424 .hw_params
= snd_emu10k1_capture_hw_params
,
1425 .hw_free
= snd_emu10k1_capture_hw_free
,
1426 .prepare
= snd_emu10k1_capture_prepare
,
1427 .trigger
= snd_emu10k1_capture_trigger
,
1428 .pointer
= snd_emu10k1_capture_pointer
,
1431 int __devinit
snd_emu10k1_pcm_mic(struct snd_emu10k1
* emu
, int device
, struct snd_pcm
** rpcm
)
1433 struct snd_pcm
*pcm
;
1439 if ((err
= snd_pcm_new(emu
->card
, "emu10k1 mic", device
, 0, 1, &pcm
)) < 0)
1442 pcm
->private_data
= emu
;
1444 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_mic_ops
);
1446 pcm
->info_flags
= 0;
1447 strcpy(pcm
->name
, "Mic Capture");
1450 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);
1457 static int snd_emu10k1_pcm_efx_voices_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1459 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1460 int nefx
= emu
->audigy
? 64 : 32;
1461 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1462 uinfo
->count
= nefx
;
1463 uinfo
->value
.integer
.min
= 0;
1464 uinfo
->value
.integer
.max
= 1;
1468 static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1470 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1471 int nefx
= emu
->audigy
? 64 : 32;
1474 spin_lock_irq(&emu
->reg_lock
);
1475 for (idx
= 0; idx
< nefx
; idx
++)
1476 ucontrol
->value
.integer
.value
[idx
] = (emu
->efx_voices_mask
[idx
/ 32] & (1 << (idx
% 32))) ? 1 : 0;
1477 spin_unlock_irq(&emu
->reg_lock
);
1481 static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1483 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1484 unsigned int nval
[2], bits
;
1485 int nefx
= emu
->audigy
? 64 : 32;
1486 int nefxb
= emu
->audigy
? 7 : 6;
1489 nval
[0] = nval
[1] = 0;
1490 for (idx
= 0, bits
= 0; idx
< nefx
; idx
++)
1491 if (ucontrol
->value
.integer
.value
[idx
]) {
1492 nval
[idx
/ 32] |= 1 << (idx
% 32);
1496 for (idx
= 0; idx
< nefxb
; idx
++)
1497 if (1 << idx
== bits
)
1503 spin_lock_irq(&emu
->reg_lock
);
1504 change
= (nval
[0] != emu
->efx_voices_mask
[0]) ||
1505 (nval
[1] != emu
->efx_voices_mask
[1]);
1506 emu
->efx_voices_mask
[0] = nval
[0];
1507 emu
->efx_voices_mask
[1] = nval
[1];
1508 spin_unlock_irq(&emu
->reg_lock
);
1512 static struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask
= {
1513 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1514 .name
= "Captured FX8010 Outputs",
1515 .info
= snd_emu10k1_pcm_efx_voices_mask_info
,
1516 .get
= snd_emu10k1_pcm_efx_voices_mask_get
,
1517 .put
= snd_emu10k1_pcm_efx_voices_mask_put
1520 static struct snd_pcm_ops snd_emu10k1_capture_efx_ops
= {
1521 .open
= snd_emu10k1_capture_efx_open
,
1522 .close
= snd_emu10k1_capture_efx_close
,
1523 .ioctl
= snd_pcm_lib_ioctl
,
1524 .hw_params
= snd_emu10k1_capture_hw_params
,
1525 .hw_free
= snd_emu10k1_capture_hw_free
,
1526 .prepare
= snd_emu10k1_capture_prepare
,
1527 .trigger
= snd_emu10k1_capture_trigger
,
1528 .pointer
= snd_emu10k1_capture_pointer
,
1534 #define INITIAL_TRAM_SHIFT 14
1535 #define INITIAL_TRAM_POS(size) ((((size) / 2) - INITIAL_TRAM_SHIFT) - 1)
1537 static void snd_emu10k1_fx8010_playback_irq(struct snd_emu10k1
*emu
, void *private_data
)
1539 struct snd_pcm_substream
*substream
= private_data
;
1540 snd_pcm_period_elapsed(substream
);
1543 static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left
,
1544 unsigned short *dst_right
,
1545 unsigned short *src
,
1547 unsigned int tram_shift
)
1549 /* printk("tram_poke1: dst_left = 0x%p, dst_right = 0x%p, src = 0x%p, count = 0x%x\n", dst_left, dst_right, src, count); */
1550 if ((tram_shift
& 1) == 0) {
1552 *dst_left
-- = *src
++;
1553 *dst_right
-- = *src
++;
1557 *dst_right
-- = *src
++;
1558 *dst_left
-- = *src
++;
1563 static void fx8010_pb_trans_copy(struct snd_pcm_substream
*substream
,
1564 struct snd_pcm_indirect
*rec
, size_t bytes
)
1566 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1567 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1568 unsigned int tram_size
= pcm
->buffer_size
;
1569 unsigned short *src
= (unsigned short *)(substream
->runtime
->dma_area
+ rec
->sw_data
);
1570 unsigned int frames
= bytes
>> 2, count
;
1571 unsigned int tram_pos
= pcm
->tram_pos
;
1572 unsigned int tram_shift
= pcm
->tram_shift
;
1574 while (frames
> tram_pos
) {
1575 count
= tram_pos
+ 1;
1576 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
,
1577 (unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
+ tram_size
/ 2,
1578 src
, count
, tram_shift
);
1581 tram_pos
= (tram_size
/ 2) - 1;
1584 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
,
1585 (unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
+ tram_size
/ 2,
1586 src
, frames
, tram_shift
);
1588 pcm
->tram_pos
= tram_pos
;
1589 pcm
->tram_shift
= tram_shift
;
1592 static int snd_emu10k1_fx8010_playback_transfer(struct snd_pcm_substream
*substream
)
1594 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1595 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1597 snd_pcm_indirect_playback_transfer(substream
, &pcm
->pcm_rec
, fx8010_pb_trans_copy
);
1601 static int snd_emu10k1_fx8010_playback_hw_params(struct snd_pcm_substream
*substream
,
1602 struct snd_pcm_hw_params
*hw_params
)
1604 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
1607 static int snd_emu10k1_fx8010_playback_hw_free(struct snd_pcm_substream
*substream
)
1609 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1610 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1613 for (i
= 0; i
< pcm
->channels
; i
++)
1614 snd_emu10k1_ptr_write(emu
, TANKMEMADDRREGBASE
+ 0x80 + pcm
->etram
[i
], 0, 0);
1615 snd_pcm_lib_free_pages(substream
);
1619 static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream
*substream
)
1621 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1622 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1623 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1626 /* printk("prepare: etram_pages = 0x%p, dma_area = 0x%x, buffer_size = 0x%x (0x%x)\n", emu->fx8010.etram_pages, runtime->dma_area, runtime->buffer_size, runtime->buffer_size << 2); */
1627 memset(&pcm
->pcm_rec
, 0, sizeof(pcm
->pcm_rec
));
1628 pcm
->pcm_rec
.hw_buffer_size
= pcm
->buffer_size
* 2; /* byte size */
1629 pcm
->pcm_rec
.sw_buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
1630 pcm
->tram_pos
= INITIAL_TRAM_POS(pcm
->buffer_size
);
1631 pcm
->tram_shift
= 0;
1632 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_running
, 0, 0); /* reset */
1633 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 0); /* reset */
1634 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_size
, 0, runtime
->buffer_size
);
1635 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_ptr
, 0, 0); /* reset ptr number */
1636 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_count
, 0, runtime
->period_size
);
1637 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_tmpcount
, 0, runtime
->period_size
);
1638 for (i
= 0; i
< pcm
->channels
; i
++)
1639 snd_emu10k1_ptr_write(emu
, TANKMEMADDRREGBASE
+ 0x80 + pcm
->etram
[i
], 0, (TANKMEMADDRREG_READ
|TANKMEMADDRREG_ALIGN
) + i
* (runtime
->buffer_size
/ pcm
->channels
));
1643 static int snd_emu10k1_fx8010_playback_trigger(struct snd_pcm_substream
*substream
, int cmd
)
1645 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1646 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1649 spin_lock(&emu
->reg_lock
);
1651 case SNDRV_PCM_TRIGGER_START
:
1653 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1654 case SNDRV_PCM_TRIGGER_RESUME
:
1655 #ifdef EMU10K1_SET_AC3_IEC958
1658 for (i
= 0; i
< 3; i
++) {
1660 bits
= SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
1661 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
| SPCS_GENERATIONSTATUS
|
1662 0x00001200 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
| SPCS_NOTAUDIODATA
;
1663 snd_emu10k1_ptr_write(emu
, SPCS0
+ i
, 0, bits
);
1667 result
= snd_emu10k1_fx8010_register_irq_handler(emu
, snd_emu10k1_fx8010_playback_irq
, pcm
->gpr_running
, substream
, &pcm
->irq
);
1670 snd_emu10k1_fx8010_playback_transfer(substream
); /* roll the ball */
1671 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 1);
1673 case SNDRV_PCM_TRIGGER_STOP
:
1674 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1675 case SNDRV_PCM_TRIGGER_SUSPEND
:
1676 snd_emu10k1_fx8010_unregister_irq_handler(emu
, pcm
->irq
); pcm
->irq
= NULL
;
1677 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 0);
1678 pcm
->tram_pos
= INITIAL_TRAM_POS(pcm
->buffer_size
);
1679 pcm
->tram_shift
= 0;
1686 spin_unlock(&emu
->reg_lock
);
1690 static snd_pcm_uframes_t
snd_emu10k1_fx8010_playback_pointer(struct snd_pcm_substream
*substream
)
1692 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1693 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1694 size_t ptr
; /* byte pointer */
1696 if (!snd_emu10k1_ptr_read(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0))
1698 ptr
= snd_emu10k1_ptr_read(emu
, emu
->gpr_base
+ pcm
->gpr_ptr
, 0) << 2;
1699 return snd_pcm_indirect_playback_pointer(substream
, &pcm
->pcm_rec
, ptr
);
1702 static struct snd_pcm_hardware snd_emu10k1_fx8010_playback
=
1704 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1705 SNDRV_PCM_INFO_RESUME
|
1706 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE
),
1707 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
1708 .rates
= SNDRV_PCM_RATE_48000
,
1713 .buffer_bytes_max
= (128*1024),
1714 .period_bytes_min
= 1024,
1715 .period_bytes_max
= (128*1024),
1717 .periods_max
= 1024,
1721 static int snd_emu10k1_fx8010_playback_open(struct snd_pcm_substream
*substream
)
1723 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1724 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1725 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1727 runtime
->hw
= snd_emu10k1_fx8010_playback
;
1728 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= pcm
->channels
;
1729 runtime
->hw
.period_bytes_max
= (pcm
->buffer_size
* 2) / 2;
1730 spin_lock_irq(&emu
->reg_lock
);
1731 if (pcm
->valid
== 0) {
1732 spin_unlock_irq(&emu
->reg_lock
);
1736 spin_unlock_irq(&emu
->reg_lock
);
1740 static int snd_emu10k1_fx8010_playback_close(struct snd_pcm_substream
*substream
)
1742 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1743 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1745 spin_lock_irq(&emu
->reg_lock
);
1747 spin_unlock_irq(&emu
->reg_lock
);
1751 static struct snd_pcm_ops snd_emu10k1_fx8010_playback_ops
= {
1752 .open
= snd_emu10k1_fx8010_playback_open
,
1753 .close
= snd_emu10k1_fx8010_playback_close
,
1754 .ioctl
= snd_pcm_lib_ioctl
,
1755 .hw_params
= snd_emu10k1_fx8010_playback_hw_params
,
1756 .hw_free
= snd_emu10k1_fx8010_playback_hw_free
,
1757 .prepare
= snd_emu10k1_fx8010_playback_prepare
,
1758 .trigger
= snd_emu10k1_fx8010_playback_trigger
,
1759 .pointer
= snd_emu10k1_fx8010_playback_pointer
,
1760 .ack
= snd_emu10k1_fx8010_playback_transfer
,
1763 int __devinit
snd_emu10k1_pcm_efx(struct snd_emu10k1
* emu
, int device
, struct snd_pcm
** rpcm
)
1765 struct snd_pcm
*pcm
;
1766 struct snd_kcontrol
*kctl
;
1772 if ((err
= snd_pcm_new(emu
->card
, "emu10k1 efx", device
, 8, 1, &pcm
)) < 0)
1775 pcm
->private_data
= emu
;
1777 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_fx8010_playback_ops
);
1778 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_efx_ops
);
1780 pcm
->info_flags
= 0;
1781 strcpy(pcm
->name
, "Multichannel Capture/PT Playback");
1786 /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs
1790 /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */
1792 emu
->efx_voices_mask
[0] = 0;
1793 if (emu
->card_capabilities
->emu_model
)
1794 /* Pavel Hofman - 32 voices will be used for
1795 * capture (write mode) -
1796 * each bit = corresponding voice
1798 emu
->efx_voices_mask
[1] = 0xffffffff;
1800 emu
->efx_voices_mask
[1] = 0xffff;
1802 emu
->efx_voices_mask
[0] = 0xffff0000;
1803 emu
->efx_voices_mask
[1] = 0;
1805 /* For emu1010, the control has to set 32 upper bits (voices)
1806 * out of the 64 bits (voices) to true for the 16-channels capture
1807 * to work correctly. Correct A_FXWC2 initial value (0xffffffff)
1808 * is already defined but the snd_emu10k1_pcm_efx_voices_mask
1809 * control can override this register's value.
1811 kctl
= snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask
, emu
);
1814 kctl
->id
.device
= device
;
1815 snd_ctl_add(emu
->card
, kctl
);
1817 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);