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
)
46 snd_pcm_period_elapsed(epcm
->substream
);
49 static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1
*emu
,
52 snd_pcm_period_elapsed(emu
->pcm_capture_substream
);
55 static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1
*emu
,
58 snd_pcm_period_elapsed(emu
->pcm_capture_mic_substream
);
61 static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1
*emu
,
64 snd_pcm_period_elapsed(emu
->pcm_capture_efx_substream
);
67 static snd_pcm_uframes_t
snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream
*substream
)
69 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
70 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
71 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
76 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->voices
[0]->number
) & 0x00ffffff;
77 ptr
+= runtime
->buffer_size
;
78 ptr
-= epcm
->ccca_start_addr
;
79 ptr
%= runtime
->buffer_size
;
84 static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm
* epcm
, int voices
)
88 if (epcm
->voices
[1] != NULL
&& voices
< 2) {
89 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[1]);
90 epcm
->voices
[1] = NULL
;
92 for (i
= 0; i
< voices
; i
++) {
93 if (epcm
->voices
[i
] == NULL
)
97 return 0; /* already allocated */
99 for (i
= 0; i
< ARRAY_SIZE(epcm
->voices
); i
++) {
100 if (epcm
->voices
[i
]) {
101 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
102 epcm
->voices
[i
] = NULL
;
105 err
= snd_emu10k1_voice_alloc(epcm
->emu
,
106 epcm
->type
== PLAYBACK_EMUVOICE
? EMU10K1_PCM
: EMU10K1_EFX
,
112 epcm
->voices
[0]->epcm
= epcm
;
114 for (i
= 1; i
< voices
; i
++) {
115 epcm
->voices
[i
] = &epcm
->emu
->voices
[epcm
->voices
[0]->number
+ i
];
116 epcm
->voices
[i
]->epcm
= epcm
;
119 if (epcm
->extra
== NULL
) {
120 err
= snd_emu10k1_voice_alloc(epcm
->emu
,
121 epcm
->type
== PLAYBACK_EMUVOICE
? EMU10K1_PCM
: EMU10K1_EFX
,
126 printk(KERN_DEBUG "pcm_channel_alloc: "
127 "failed extra: voices=%d, frame=%d\n",
130 for (i
= 0; i
< voices
; i
++) {
131 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
132 epcm
->voices
[i
] = NULL
;
136 epcm
->extra
->epcm
= epcm
;
137 epcm
->extra
->interrupt
= snd_emu10k1_pcm_interrupt
;
142 static unsigned int capture_period_sizes
[31] = {
144 384*2, 448*2, 512*2, 640*2,
145 384*4, 448*4, 512*4, 640*4,
146 384*8, 448*8, 512*8, 640*8,
147 384*16, 448*16, 512*16, 640*16,
148 384*32, 448*32, 512*32, 640*32,
149 384*64, 448*64, 512*64, 640*64,
150 384*128,448*128,512*128
153 static struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes
= {
155 .list
= capture_period_sizes
,
159 static unsigned int capture_rates
[8] = {
160 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
163 static struct snd_pcm_hw_constraint_list hw_constraints_capture_rates
= {
165 .list
= capture_rates
,
169 static unsigned int snd_emu10k1_capture_rate_reg(unsigned int rate
)
172 case 8000: return ADCCR_SAMPLERATE_8
;
173 case 11025: return ADCCR_SAMPLERATE_11
;
174 case 16000: return ADCCR_SAMPLERATE_16
;
175 case 22050: return ADCCR_SAMPLERATE_22
;
176 case 24000: return ADCCR_SAMPLERATE_24
;
177 case 32000: return ADCCR_SAMPLERATE_32
;
178 case 44100: return ADCCR_SAMPLERATE_44
;
179 case 48000: return ADCCR_SAMPLERATE_48
;
182 return ADCCR_SAMPLERATE_8
;
186 static unsigned int snd_emu10k1_audigy_capture_rate_reg(unsigned int rate
)
189 case 8000: return A_ADCCR_SAMPLERATE_8
;
190 case 11025: return A_ADCCR_SAMPLERATE_11
;
191 case 12000: return A_ADCCR_SAMPLERATE_12
; /* really supported? */
192 case 16000: return ADCCR_SAMPLERATE_16
;
193 case 22050: return ADCCR_SAMPLERATE_22
;
194 case 24000: return ADCCR_SAMPLERATE_24
;
195 case 32000: return ADCCR_SAMPLERATE_32
;
196 case 44100: return ADCCR_SAMPLERATE_44
;
197 case 48000: return ADCCR_SAMPLERATE_48
;
200 return A_ADCCR_SAMPLERATE_8
;
204 static unsigned int emu10k1_calc_pitch_target(unsigned int rate
)
206 unsigned int pitch_target
;
208 pitch_target
= (rate
<< 8) / 375;
209 pitch_target
= (pitch_target
>> 1) + (pitch_target
& 1);
213 #define PITCH_48000 0x00004000
214 #define PITCH_96000 0x00008000
215 #define PITCH_85000 0x00007155
216 #define PITCH_80726 0x00006ba2
217 #define PITCH_67882 0x00005a82
218 #define PITCH_57081 0x00004c1c
220 static unsigned int emu10k1_select_interprom(unsigned int pitch_target
)
222 if (pitch_target
== PITCH_48000
)
223 return CCCA_INTERPROM_0
;
224 else if (pitch_target
< PITCH_48000
)
225 return CCCA_INTERPROM_1
;
226 else if (pitch_target
>= PITCH_96000
)
227 return CCCA_INTERPROM_0
;
228 else if (pitch_target
>= PITCH_85000
)
229 return CCCA_INTERPROM_6
;
230 else if (pitch_target
>= PITCH_80726
)
231 return CCCA_INTERPROM_5
;
232 else if (pitch_target
>= PITCH_67882
)
233 return CCCA_INTERPROM_4
;
234 else if (pitch_target
>= PITCH_57081
)
235 return CCCA_INTERPROM_3
;
237 return CCCA_INTERPROM_2
;
241 * calculate cache invalidate size
243 * stereo: channel is stereo
244 * w_16: using 16bit samples
246 * returns: cache invalidate size in samples
248 static inline int emu10k1_ccis(int stereo
, int w_16
)
251 return stereo
? 24 : 26;
253 return stereo
? 24*2 : 26*2;
257 static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1
*emu
,
258 int master
, int extra
,
259 struct snd_emu10k1_voice
*evoice
,
260 unsigned int start_addr
,
261 unsigned int end_addr
,
262 struct snd_emu10k1_pcm_mixer
*mix
)
264 struct snd_pcm_substream
*substream
= evoice
->epcm
->substream
;
265 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
266 unsigned int silent_page
, tmp
;
267 int voice
, stereo
, w_16
;
268 unsigned char attn
, send_amount
[8];
269 unsigned char send_routing
[8];
271 unsigned int pitch_target
;
274 voice
= evoice
->number
;
275 stereo
= runtime
->channels
== 2;
276 w_16
= snd_pcm_format_width(runtime
->format
) == 16;
278 if (!extra
&& stereo
) {
287 spin_lock_irqsave(&emu
->reg_lock
, flags
);
289 /* volume parameters */
292 memset(send_routing
, 0, sizeof(send_routing
));
297 memset(send_amount
, 0, sizeof(send_amount
));
299 /* mono, left, right (master voice = left) */
300 tmp
= stereo
? (master
? 1 : 2) : 0;
301 memcpy(send_routing
, &mix
->send_routing
[tmp
][0], 8);
302 memcpy(send_amount
, &mix
->send_volume
[tmp
][0], 8);
305 ccis
= emu10k1_ccis(stereo
, w_16
);
308 evoice
->epcm
->ccca_start_addr
= start_addr
+ ccis
;
311 end_addr
+= ccis
+ emu
->delay_pcm_irq
;
313 if (stereo
&& !extra
) {
314 snd_emu10k1_ptr_write(emu
, CPF
, voice
, CPF_STEREO_MASK
);
315 snd_emu10k1_ptr_write(emu
, CPF
, (voice
+ 1), CPF_STEREO_MASK
);
317 snd_emu10k1_ptr_write(emu
, CPF
, voice
, 0);
323 snd_emu10k1_ptr_write(emu
, A_FXRT1
, voice
,
324 snd_emu10k1_compose_audigy_fxrt1(send_routing
));
325 snd_emu10k1_ptr_write(emu
, A_FXRT2
, voice
,
326 snd_emu10k1_compose_audigy_fxrt2(send_routing
));
327 snd_emu10k1_ptr_write(emu
, A_SENDAMOUNTS
, voice
,
328 ((unsigned int)send_amount
[4] << 24) |
329 ((unsigned int)send_amount
[5] << 16) |
330 ((unsigned int)send_amount
[6] << 8) |
331 (unsigned int)send_amount
[7]);
333 snd_emu10k1_ptr_write(emu
, FXRT
, voice
,
334 snd_emu10k1_compose_send_routing(send_routing
));
336 /* Assumption that PT is already 0 so no harm overwriting */
337 snd_emu10k1_ptr_write(emu
, PTRX
, voice
, (send_amount
[0] << 8) | send_amount
[1]);
338 snd_emu10k1_ptr_write(emu
, DSL
, voice
, end_addr
| (send_amount
[3] << 24));
339 snd_emu10k1_ptr_write(emu
, PSST
, voice
,
340 (start_addr
+ (extra
? emu
->delay_pcm_irq
: 0)) |
341 (send_amount
[2] << 24));
342 if (emu
->card_capabilities
->emu_model
)
343 pitch_target
= PITCH_48000
; /* Disable interpolators on emu1010 card */
345 pitch_target
= emu10k1_calc_pitch_target(runtime
->rate
);
347 snd_emu10k1_ptr_write(emu
, CCCA
, voice
, start_addr
|
348 emu10k1_select_interprom(pitch_target
) |
349 (w_16
? 0 : CCCA_8BITSELECT
));
351 snd_emu10k1_ptr_write(emu
, CCCA
, voice
, (start_addr
+ ccis
) |
352 emu10k1_select_interprom(pitch_target
) |
353 (w_16
? 0 : CCCA_8BITSELECT
));
354 /* Clear filter delay memory */
355 snd_emu10k1_ptr_write(emu
, Z1
, voice
, 0);
356 snd_emu10k1_ptr_write(emu
, Z2
, voice
, 0);
357 /* invalidate maps */
358 silent_page
= ((unsigned int)emu
->silent_page
.addr
<< 1) | MAP_PTI_MASK
;
359 snd_emu10k1_ptr_write(emu
, MAPA
, voice
, silent_page
);
360 snd_emu10k1_ptr_write(emu
, MAPB
, voice
, silent_page
);
361 /* modulation envelope */
362 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, 0xffff);
363 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, 0xffff);
364 snd_emu10k1_ptr_write(emu
, ATKHLDM
, voice
, 0);
365 snd_emu10k1_ptr_write(emu
, DCYSUSM
, voice
, 0x007f);
366 snd_emu10k1_ptr_write(emu
, LFOVAL1
, voice
, 0x8000);
367 snd_emu10k1_ptr_write(emu
, LFOVAL2
, voice
, 0x8000);
368 snd_emu10k1_ptr_write(emu
, FMMOD
, voice
, 0);
369 snd_emu10k1_ptr_write(emu
, TREMFRQ
, voice
, 0);
370 snd_emu10k1_ptr_write(emu
, FM2FRQ2
, voice
, 0);
371 snd_emu10k1_ptr_write(emu
, ENVVAL
, voice
, 0x8000);
372 /* volume envelope */
373 snd_emu10k1_ptr_write(emu
, ATKHLDV
, voice
, 0x7f7f);
374 snd_emu10k1_ptr_write(emu
, ENVVOL
, voice
, 0x0000);
375 /* filter envelope */
376 snd_emu10k1_ptr_write(emu
, PEFE_FILTERAMOUNT
, voice
, 0x7f);
378 snd_emu10k1_ptr_write(emu
, PEFE_PITCHAMOUNT
, voice
, 0);
380 spin_unlock_irqrestore(&emu
->reg_lock
, flags
);
383 static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream
*substream
,
384 struct snd_pcm_hw_params
*hw_params
)
386 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
387 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
388 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
391 if ((err
= snd_emu10k1_pcm_channel_alloc(epcm
, params_channels(hw_params
))) < 0)
393 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
395 if (err
> 0) { /* change */
397 if (epcm
->memblk
!= NULL
)
398 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
399 epcm
->memblk
= snd_emu10k1_alloc_pages(emu
, substream
);
400 epcm
->start_addr
= 0;
403 mapped
= ((struct snd_emu10k1_memblk
*)epcm
->memblk
)->mapped_page
;
406 epcm
->start_addr
= mapped
<< PAGE_SHIFT
;
411 static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream
*substream
)
413 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
414 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
415 struct snd_emu10k1_pcm
*epcm
;
417 if (runtime
->private_data
== NULL
)
419 epcm
= runtime
->private_data
;
421 snd_emu10k1_voice_free(epcm
->emu
, epcm
->extra
);
424 if (epcm
->voices
[1]) {
425 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[1]);
426 epcm
->voices
[1] = NULL
;
428 if (epcm
->voices
[0]) {
429 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[0]);
430 epcm
->voices
[0] = NULL
;
433 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
435 epcm
->start_addr
= 0;
437 snd_pcm_lib_free_pages(substream
);
441 static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream
*substream
)
443 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
444 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
445 struct snd_emu10k1_pcm
*epcm
;
448 if (runtime
->private_data
== NULL
)
450 epcm
= runtime
->private_data
;
452 snd_emu10k1_voice_free(epcm
->emu
, epcm
->extra
);
455 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
456 if (epcm
->voices
[i
]) {
457 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
458 epcm
->voices
[i
] = NULL
;
462 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
464 epcm
->start_addr
= 0;
466 snd_pcm_lib_free_pages(substream
);
470 static int snd_emu10k1_playback_prepare(struct snd_pcm_substream
*substream
)
472 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
473 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
474 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
475 unsigned int start_addr
, end_addr
;
477 start_addr
= epcm
->start_addr
;
478 end_addr
= snd_pcm_lib_period_bytes(substream
);
479 if (runtime
->channels
== 2) {
483 end_addr
+= start_addr
;
484 snd_emu10k1_pcm_init_voice(emu
, 1, 1, epcm
->extra
,
485 start_addr
, end_addr
, NULL
);
486 start_addr
= epcm
->start_addr
;
487 end_addr
= epcm
->start_addr
+ snd_pcm_lib_buffer_bytes(substream
);
488 snd_emu10k1_pcm_init_voice(emu
, 1, 0, epcm
->voices
[0],
489 start_addr
, end_addr
,
490 &emu
->pcm_mixer
[substream
->number
]);
492 snd_emu10k1_pcm_init_voice(emu
, 0, 0, epcm
->voices
[1],
493 start_addr
, end_addr
,
494 &emu
->pcm_mixer
[substream
->number
]);
498 static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream
*substream
)
500 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
501 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
502 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
503 unsigned int start_addr
, end_addr
;
504 unsigned int channel_size
;
507 start_addr
= epcm
->start_addr
;
508 end_addr
= epcm
->start_addr
+ snd_pcm_lib_buffer_bytes(substream
);
511 * the kX driver leaves some space between voices
513 channel_size
= ( end_addr
- start_addr
) / NUM_EFX_PLAYBACK
;
515 snd_emu10k1_pcm_init_voice(emu
, 1, 1, epcm
->extra
,
516 start_addr
, start_addr
+ (channel_size
/ 2), NULL
);
518 /* only difference with the master voice is we use it for the pointer */
519 snd_emu10k1_pcm_init_voice(emu
, 1, 0, epcm
->voices
[0],
520 start_addr
, start_addr
+ channel_size
,
521 &emu
->efx_pcm_mixer
[0]);
523 start_addr
+= channel_size
;
524 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++) {
525 snd_emu10k1_pcm_init_voice(emu
, 0, 0, epcm
->voices
[i
],
526 start_addr
, start_addr
+ channel_size
,
527 &emu
->efx_pcm_mixer
[i
]);
528 start_addr
+= channel_size
;
534 static struct snd_pcm_hardware snd_emu10k1_efx_playback
=
536 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_NONINTERLEAVED
|
537 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
538 SNDRV_PCM_INFO_RESUME
|
539 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
),
540 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
541 .rates
= SNDRV_PCM_RATE_48000
,
544 .channels_min
= NUM_EFX_PLAYBACK
,
545 .channels_max
= NUM_EFX_PLAYBACK
,
546 .buffer_bytes_max
= (64*1024),
547 .period_bytes_min
= 64,
548 .period_bytes_max
= (64*1024),
554 static int snd_emu10k1_capture_hw_params(struct snd_pcm_substream
*substream
,
555 struct snd_pcm_hw_params
*hw_params
)
557 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
560 static int snd_emu10k1_capture_hw_free(struct snd_pcm_substream
*substream
)
562 return snd_pcm_lib_free_pages(substream
);
565 static int snd_emu10k1_capture_prepare(struct snd_pcm_substream
*substream
)
567 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
568 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
569 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
572 /* zeroing the buffer size will stop capture */
573 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, 0);
574 switch (epcm
->type
) {
575 case CAPTURE_AC97ADC
:
576 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, 0);
580 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, 0);
581 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, 0);
583 snd_emu10k1_ptr_write(emu
, FXWC
, 0, 0);
588 snd_emu10k1_ptr_write(emu
, epcm
->capture_ba_reg
, 0, runtime
->dma_addr
);
589 epcm
->capture_bufsize
= snd_pcm_lib_buffer_bytes(substream
);
590 epcm
->capture_bs_val
= 0;
591 for (idx
= 0; idx
< 31; idx
++) {
592 if (capture_period_sizes
[idx
] == epcm
->capture_bufsize
) {
593 epcm
->capture_bs_val
= idx
+ 1;
597 if (epcm
->capture_bs_val
== 0) {
599 epcm
->capture_bs_val
++;
601 if (epcm
->type
== CAPTURE_AC97ADC
) {
602 epcm
->capture_cr_val
= emu
->audigy
? A_ADCCR_LCHANENABLE
: ADCCR_LCHANENABLE
;
603 if (runtime
->channels
> 1)
604 epcm
->capture_cr_val
|= emu
->audigy
? A_ADCCR_RCHANENABLE
: ADCCR_RCHANENABLE
;
605 epcm
->capture_cr_val
|= emu
->audigy
?
606 snd_emu10k1_audigy_capture_rate_reg(runtime
->rate
) :
607 snd_emu10k1_capture_rate_reg(runtime
->rate
);
612 static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1
*emu
, int extra
, struct snd_emu10k1_voice
*evoice
)
614 struct snd_pcm_runtime
*runtime
;
615 unsigned int voice
, stereo
, i
, ccis
, cra
= 64, cs
, sample
;
619 runtime
= evoice
->epcm
->substream
->runtime
;
620 voice
= evoice
->number
;
621 stereo
= (!extra
&& runtime
->channels
== 2);
622 sample
= snd_pcm_format_width(runtime
->format
) == 16 ? 0 : 0x80808080;
623 ccis
= emu10k1_ccis(stereo
, sample
== 0);
624 /* set cs to 2 * number of cache registers beside the invalidated */
625 cs
= (sample
== 0) ? (32-ccis
) : (64-ccis
+1) >> 1;
626 if (cs
> 16) cs
= 16;
627 for (i
= 0; i
< cs
; i
++) {
628 snd_emu10k1_ptr_write(emu
, CD0
+ i
, voice
, sample
);
630 snd_emu10k1_ptr_write(emu
, CD0
+ i
, voice
+ 1, sample
);
634 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
, 0);
635 snd_emu10k1_ptr_write(emu
, CCR_READADDRESS
, voice
, cra
);
637 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
+ 1, 0);
638 snd_emu10k1_ptr_write(emu
, CCR_READADDRESS
, voice
+ 1, cra
);
641 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
, ccis
);
643 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
+1, ccis
);
647 static void snd_emu10k1_playback_prepare_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
,
648 int master
, int extra
,
649 struct snd_emu10k1_pcm_mixer
*mix
)
651 struct snd_pcm_substream
*substream
;
652 struct snd_pcm_runtime
*runtime
;
653 unsigned int attn
, vattn
;
654 unsigned int voice
, tmp
;
656 if (evoice
== NULL
) /* skip second voice for mono */
658 substream
= evoice
->epcm
->substream
;
659 runtime
= substream
->runtime
;
660 voice
= evoice
->number
;
662 attn
= extra
? 0 : 0x00ff;
663 tmp
= runtime
->channels
== 2 ? (master
? 1 : 2) : 0;
664 vattn
= mix
!= NULL
? (mix
->attn
[tmp
] << 16) : 0;
665 snd_emu10k1_ptr_write(emu
, IFATN
, voice
, attn
);
666 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, vattn
| 0xffff);
667 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, vattn
| 0xffff);
668 snd_emu10k1_ptr_write(emu
, DCYSUSV
, voice
, 0x7f7f);
669 snd_emu10k1_voice_clear_loop_stop(emu
, voice
);
672 static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
, int master
, int extra
)
674 struct snd_pcm_substream
*substream
;
675 struct snd_pcm_runtime
*runtime
;
676 unsigned int voice
, pitch
, pitch_target
;
678 if (evoice
== NULL
) /* skip second voice for mono */
680 substream
= evoice
->epcm
->substream
;
681 runtime
= substream
->runtime
;
682 voice
= evoice
->number
;
684 pitch
= snd_emu10k1_rate_to_pitch(runtime
->rate
) >> 8;
685 if (emu
->card_capabilities
->emu_model
)
686 pitch_target
= PITCH_48000
; /* Disable interpolators on emu1010 card */
688 pitch_target
= emu10k1_calc_pitch_target(runtime
->rate
);
689 snd_emu10k1_ptr_write(emu
, PTRX_PITCHTARGET
, voice
, pitch_target
);
690 if (master
|| evoice
->epcm
->type
== PLAYBACK_EFX
)
691 snd_emu10k1_ptr_write(emu
, CPF_CURRENTPITCH
, voice
, pitch_target
);
692 snd_emu10k1_ptr_write(emu
, IP
, voice
, pitch
);
694 snd_emu10k1_voice_intr_enable(emu
, voice
);
697 static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
)
703 voice
= evoice
->number
;
704 snd_emu10k1_voice_intr_disable(emu
, voice
);
705 snd_emu10k1_ptr_write(emu
, PTRX_PITCHTARGET
, voice
, 0);
706 snd_emu10k1_ptr_write(emu
, CPF_CURRENTPITCH
, voice
, 0);
707 snd_emu10k1_ptr_write(emu
, IFATN
, voice
, 0xffff);
708 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, 0xffff);
709 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, 0xffff);
710 snd_emu10k1_ptr_write(emu
, IP
, voice
, 0);
713 static inline void snd_emu10k1_playback_mangle_extra(struct snd_emu10k1
*emu
,
714 struct snd_emu10k1_pcm
*epcm
,
715 struct snd_pcm_substream
*substream
,
716 struct snd_pcm_runtime
*runtime
)
718 unsigned int ptr
, period_pos
;
720 /* try to sychronize the current position for the interrupt
722 period_pos
= runtime
->status
->hw_ptr
- runtime
->hw_ptr_interrupt
;
723 period_pos
%= runtime
->period_size
;
724 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->extra
->number
);
726 ptr
|= epcm
->ccca_start_addr
+ period_pos
;
727 snd_emu10k1_ptr_write(emu
, CCCA
, epcm
->extra
->number
, ptr
);
730 static int snd_emu10k1_playback_trigger(struct snd_pcm_substream
*substream
,
733 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
734 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
735 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
736 struct snd_emu10k1_pcm_mixer
*mix
;
740 printk(KERN_DEBUG "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
741 (int)emu, cmd, substream->ops->pointer(substream))
743 spin_lock(&emu
->reg_lock
);
745 case SNDRV_PCM_TRIGGER_START
:
746 snd_emu10k1_playback_invalidate_cache(emu
, 1, epcm
->extra
); /* do we need this? */
747 snd_emu10k1_playback_invalidate_cache(emu
, 0, epcm
->voices
[0]);
749 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
750 case SNDRV_PCM_TRIGGER_RESUME
:
751 if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_RELEASE
)
752 snd_emu10k1_playback_mangle_extra(emu
, epcm
, substream
, runtime
);
753 mix
= &emu
->pcm_mixer
[substream
->number
];
754 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[0], 1, 0, mix
);
755 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[1], 0, 0, mix
);
756 snd_emu10k1_playback_prepare_voice(emu
, epcm
->extra
, 1, 1, NULL
);
757 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[0], 1, 0);
758 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[1], 0, 0);
759 snd_emu10k1_playback_trigger_voice(emu
, epcm
->extra
, 1, 1);
762 case SNDRV_PCM_TRIGGER_STOP
:
763 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
764 case SNDRV_PCM_TRIGGER_SUSPEND
:
766 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[0]);
767 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[1]);
768 snd_emu10k1_playback_stop_voice(emu
, epcm
->extra
);
774 spin_unlock(&emu
->reg_lock
);
778 static int snd_emu10k1_capture_trigger(struct snd_pcm_substream
*substream
,
781 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
782 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
783 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
786 spin_lock(&emu
->reg_lock
);
788 case SNDRV_PCM_TRIGGER_START
:
789 case SNDRV_PCM_TRIGGER_RESUME
:
790 /* hmm this should cause full and half full interrupt to be raised? */
791 outl(epcm
->capture_ipr
, emu
->port
+ IPR
);
792 snd_emu10k1_intr_enable(emu
, epcm
->capture_inte
);
794 printk(KERN_DEBUG "adccr = 0x%x, adcbs = 0x%x\n",
795 epcm->adccr, epcm->adcbs);
797 switch (epcm
->type
) {
798 case CAPTURE_AC97ADC
:
799 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, epcm
->capture_cr_val
);
803 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, epcm
->capture_cr_val
);
804 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, epcm
->capture_cr_val2
);
805 snd_printdd("cr_val=0x%x, cr_val2=0x%x\n", epcm
->capture_cr_val
, epcm
->capture_cr_val2
);
807 snd_emu10k1_ptr_write(emu
, FXWC
, 0, epcm
->capture_cr_val
);
812 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, epcm
->capture_bs_val
);
816 case SNDRV_PCM_TRIGGER_STOP
:
817 case SNDRV_PCM_TRIGGER_SUSPEND
:
819 snd_emu10k1_intr_disable(emu
, epcm
->capture_inte
);
820 outl(epcm
->capture_ipr
, emu
->port
+ IPR
);
821 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, 0);
822 switch (epcm
->type
) {
823 case CAPTURE_AC97ADC
:
824 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, 0);
828 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, 0);
829 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, 0);
831 snd_emu10k1_ptr_write(emu
, FXWC
, 0, 0);
840 spin_unlock(&emu
->reg_lock
);
844 static snd_pcm_uframes_t
snd_emu10k1_playback_pointer(struct snd_pcm_substream
*substream
)
846 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
847 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
848 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
853 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->voices
[0]->number
) & 0x00ffffff;
854 if (ptr
< epcm
->ccca_start_addr
)
855 ptr
+= runtime
->buffer_size
- epcm
->ccca_start_addr
;
857 ptr
-= epcm
->ccca_start_addr
;
858 if (ptr
>= runtime
->buffer_size
)
859 ptr
-= runtime
->buffer_size
;
863 "ptr = 0x%lx, buffer_size = 0x%lx, period_size = 0x%lx\n",
864 (long)ptr, (long)runtime->buffer_size,
865 (long)runtime->period_size);
871 static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream
*substream
,
874 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
875 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
876 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
880 spin_lock(&emu
->reg_lock
);
882 case SNDRV_PCM_TRIGGER_START
:
884 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
885 snd_emu10k1_playback_invalidate_cache(emu
, 0, epcm
->voices
[i
]);
887 snd_emu10k1_playback_invalidate_cache(emu
, 1, epcm
->extra
);
890 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
891 case SNDRV_PCM_TRIGGER_RESUME
:
892 snd_emu10k1_playback_prepare_voice(emu
, epcm
->extra
, 1, 1, NULL
);
893 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[0], 0, 0,
894 &emu
->efx_pcm_mixer
[0]);
895 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++)
896 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[i
], 0, 0,
897 &emu
->efx_pcm_mixer
[i
]);
898 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[0], 0, 0);
899 snd_emu10k1_playback_trigger_voice(emu
, epcm
->extra
, 1, 1);
900 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++)
901 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[i
], 0, 0);
904 case SNDRV_PCM_TRIGGER_SUSPEND
:
905 case SNDRV_PCM_TRIGGER_STOP
:
906 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
908 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
909 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[i
]);
911 snd_emu10k1_playback_stop_voice(emu
, epcm
->extra
);
917 spin_unlock(&emu
->reg_lock
);
922 static snd_pcm_uframes_t
snd_emu10k1_capture_pointer(struct snd_pcm_substream
*substream
)
924 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
925 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
926 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
931 if (epcm
->first_ptr
) {
932 udelay(50); /* hack, it takes awhile until capture is started */
935 ptr
= snd_emu10k1_ptr_read(emu
, epcm
->capture_idx_reg
, 0) & 0x0000ffff;
936 return bytes_to_frames(runtime
, ptr
);
940 * Playback support device description
943 static struct snd_pcm_hardware snd_emu10k1_playback
=
945 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
946 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
947 SNDRV_PCM_INFO_RESUME
|
948 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
),
949 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
950 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_96000
,
955 .buffer_bytes_max
= (128*1024),
956 .period_bytes_min
= 64,
957 .period_bytes_max
= (128*1024),
964 * Capture support device description
967 static struct snd_pcm_hardware snd_emu10k1_capture
=
969 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
970 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
971 SNDRV_PCM_INFO_RESUME
|
972 SNDRV_PCM_INFO_MMAP_VALID
),
973 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
974 .rates
= SNDRV_PCM_RATE_8000_48000
,
979 .buffer_bytes_max
= (64*1024),
980 .period_bytes_min
= 384,
981 .period_bytes_max
= (64*1024),
987 static struct snd_pcm_hardware snd_emu10k1_capture_efx
=
989 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
990 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
991 SNDRV_PCM_INFO_RESUME
|
992 SNDRV_PCM_INFO_MMAP_VALID
),
993 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
994 .rates
= SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
|
995 SNDRV_PCM_RATE_88200
| SNDRV_PCM_RATE_96000
|
996 SNDRV_PCM_RATE_176400
| SNDRV_PCM_RATE_192000
,
1001 .buffer_bytes_max
= (64*1024),
1002 .period_bytes_min
= 384,
1003 .period_bytes_max
= (64*1024),
1013 static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1
*emu
, struct snd_kcontrol
*kctl
, int idx
, int activate
)
1015 struct snd_ctl_elem_id id
;
1020 kctl
->vd
[idx
].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1022 kctl
->vd
[idx
].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1023 snd_ctl_notify(emu
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1024 SNDRV_CTL_EVENT_MASK_INFO
,
1025 snd_ctl_build_ioff(&id
, kctl
, idx
));
1028 static void snd_emu10k1_pcm_mixer_notify(struct snd_emu10k1
*emu
, int idx
, int activate
)
1030 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_send_routing
, idx
, activate
);
1031 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_send_volume
, idx
, activate
);
1032 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_attn
, idx
, activate
);
1035 static void snd_emu10k1_pcm_efx_mixer_notify(struct snd_emu10k1
*emu
, int idx
, int activate
)
1037 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_send_routing
, idx
, activate
);
1038 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_send_volume
, idx
, activate
);
1039 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_attn
, idx
, activate
);
1042 static void snd_emu10k1_pcm_free_substream(struct snd_pcm_runtime
*runtime
)
1044 kfree(runtime
->private_data
);
1047 static int snd_emu10k1_efx_playback_close(struct snd_pcm_substream
*substream
)
1049 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1050 struct snd_emu10k1_pcm_mixer
*mix
;
1053 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
1054 mix
= &emu
->efx_pcm_mixer
[i
];
1056 snd_emu10k1_pcm_efx_mixer_notify(emu
, i
, 0);
1061 static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream
*substream
)
1063 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1064 struct snd_emu10k1_pcm
*epcm
;
1065 struct snd_emu10k1_pcm_mixer
*mix
;
1066 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1069 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1073 epcm
->type
= PLAYBACK_EFX
;
1074 epcm
->substream
= substream
;
1076 emu
->pcm_playback_efx_substream
= substream
;
1078 runtime
->private_data
= epcm
;
1079 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1080 runtime
->hw
= snd_emu10k1_efx_playback
;
1082 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
1083 mix
= &emu
->efx_pcm_mixer
[i
];
1084 mix
->send_routing
[0][0] = i
;
1085 memset(&mix
->send_volume
, 0, sizeof(mix
->send_volume
));
1086 mix
->send_volume
[0][0] = 255;
1087 mix
->attn
[0] = 0xffff;
1089 snd_emu10k1_pcm_efx_mixer_notify(emu
, i
, 1);
1094 static int snd_emu10k1_playback_open(struct snd_pcm_substream
*substream
)
1096 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1097 struct snd_emu10k1_pcm
*epcm
;
1098 struct snd_emu10k1_pcm_mixer
*mix
;
1099 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1102 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1106 epcm
->type
= PLAYBACK_EMUVOICE
;
1107 epcm
->substream
= substream
;
1108 runtime
->private_data
= epcm
;
1109 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1110 runtime
->hw
= snd_emu10k1_playback
;
1111 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0) {
1115 if ((err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 256, UINT_MAX
)) < 0) {
1119 mix
= &emu
->pcm_mixer
[substream
->number
];
1120 for (i
= 0; i
< 4; i
++)
1121 mix
->send_routing
[0][i
] = mix
->send_routing
[1][i
] = mix
->send_routing
[2][i
] = i
;
1122 memset(&mix
->send_volume
, 0, sizeof(mix
->send_volume
));
1123 mix
->send_volume
[0][0] = mix
->send_volume
[0][1] =
1124 mix
->send_volume
[1][0] = mix
->send_volume
[2][1] = 255;
1125 mix
->attn
[0] = mix
->attn
[1] = mix
->attn
[2] = 0xffff;
1127 snd_emu10k1_pcm_mixer_notify(emu
, substream
->number
, 1);
1131 static int snd_emu10k1_playback_close(struct snd_pcm_substream
*substream
)
1133 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1134 struct snd_emu10k1_pcm_mixer
*mix
= &emu
->pcm_mixer
[substream
->number
];
1137 snd_emu10k1_pcm_mixer_notify(emu
, substream
->number
, 0);
1141 static int snd_emu10k1_capture_open(struct snd_pcm_substream
*substream
)
1143 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1144 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1145 struct snd_emu10k1_pcm
*epcm
;
1147 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1151 epcm
->type
= CAPTURE_AC97ADC
;
1152 epcm
->substream
= substream
;
1153 epcm
->capture_ipr
= IPR_ADCBUFFULL
|IPR_ADCBUFHALFFULL
;
1154 epcm
->capture_inte
= INTE_ADCBUFENABLE
;
1155 epcm
->capture_ba_reg
= ADCBA
;
1156 epcm
->capture_bs_reg
= ADCBS
;
1157 epcm
->capture_idx_reg
= emu
->audigy
? A_ADCIDX
: ADCIDX
;
1158 runtime
->private_data
= epcm
;
1159 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1160 runtime
->hw
= snd_emu10k1_capture
;
1161 emu
->capture_interrupt
= snd_emu10k1_pcm_ac97adc_interrupt
;
1162 emu
->pcm_capture_substream
= substream
;
1163 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1164 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_capture_rates
);
1168 static int snd_emu10k1_capture_close(struct snd_pcm_substream
*substream
)
1170 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1172 emu
->capture_interrupt
= NULL
;
1173 emu
->pcm_capture_substream
= NULL
;
1177 static int snd_emu10k1_capture_mic_open(struct snd_pcm_substream
*substream
)
1179 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1180 struct snd_emu10k1_pcm
*epcm
;
1181 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1183 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1187 epcm
->type
= CAPTURE_AC97MIC
;
1188 epcm
->substream
= substream
;
1189 epcm
->capture_ipr
= IPR_MICBUFFULL
|IPR_MICBUFHALFFULL
;
1190 epcm
->capture_inte
= INTE_MICBUFENABLE
;
1191 epcm
->capture_ba_reg
= MICBA
;
1192 epcm
->capture_bs_reg
= MICBS
;
1193 epcm
->capture_idx_reg
= emu
->audigy
? A_MICIDX
: MICIDX
;
1194 substream
->runtime
->private_data
= epcm
;
1195 substream
->runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1196 runtime
->hw
= snd_emu10k1_capture
;
1197 runtime
->hw
.rates
= SNDRV_PCM_RATE_8000
;
1198 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 8000;
1199 runtime
->hw
.channels_min
= 1;
1200 emu
->capture_mic_interrupt
= snd_emu10k1_pcm_ac97mic_interrupt
;
1201 emu
->pcm_capture_mic_substream
= substream
;
1202 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1206 static int snd_emu10k1_capture_mic_close(struct snd_pcm_substream
*substream
)
1208 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1210 emu
->capture_interrupt
= NULL
;
1211 emu
->pcm_capture_mic_substream
= NULL
;
1215 static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream
*substream
)
1217 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1218 struct snd_emu10k1_pcm
*epcm
;
1219 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1220 int nefx
= emu
->audigy
? 64 : 32;
1223 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1227 epcm
->type
= CAPTURE_EFX
;
1228 epcm
->substream
= substream
;
1229 epcm
->capture_ipr
= IPR_EFXBUFFULL
|IPR_EFXBUFHALFFULL
;
1230 epcm
->capture_inte
= INTE_EFXBUFENABLE
;
1231 epcm
->capture_ba_reg
= FXBA
;
1232 epcm
->capture_bs_reg
= FXBS
;
1233 epcm
->capture_idx_reg
= FXIDX
;
1234 substream
->runtime
->private_data
= epcm
;
1235 substream
->runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1236 runtime
->hw
= snd_emu10k1_capture_efx
;
1237 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
1238 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 48000;
1239 spin_lock_irq(&emu
->reg_lock
);
1240 if (emu
->card_capabilities
->emu_model
) {
1241 /* Nb. of channels has been increased to 16 */
1243 * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE
1244 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
1245 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
1246 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000
1248 * rate_max = 192000,
1249 * channels_min = 16,
1250 * channels_max = 16,
1251 * Need to add mixer control to fix sample rate
1253 * There are 32 mono channels of 16bits each.
1254 * 24bit Audio uses 2x channels over 16bit
1255 * 96kHz uses 2x channels over 48kHz
1256 * 192kHz uses 4x channels over 48kHz
1257 * So, for 48kHz 24bit, one has 16 channels
1258 * for 96kHz 24bit, one has 8 channels
1259 * for 192kHz 24bit, one has 4 channels
1262 switch (emu
->emu1010
.internal_clock
) {
1265 runtime
->hw
.rates
= SNDRV_PCM_RATE_44100
;
1266 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 44100;
1267 runtime
->hw
.channels_min
=
1268 runtime
->hw
.channels_max
= 16;
1272 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
1273 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 48000;
1274 runtime
->hw
.channels_min
=
1275 runtime
->hw
.channels_max
= 16;
1278 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S32_LE
;
1279 /* efx_voices_mask[0] is expected to be zero
1280 * efx_voices_mask[1] is expected to have 32bits set
1283 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 0;
1284 for (idx
= 0; idx
< nefx
; idx
++) {
1285 if (emu
->efx_voices_mask
[idx
/32] & (1 << (idx
%32))) {
1286 runtime
->hw
.channels_min
++;
1287 runtime
->hw
.channels_max
++;
1291 epcm
->capture_cr_val
= emu
->efx_voices_mask
[0];
1292 epcm
->capture_cr_val2
= emu
->efx_voices_mask
[1];
1293 spin_unlock_irq(&emu
->reg_lock
);
1294 emu
->capture_efx_interrupt
= snd_emu10k1_pcm_efx_interrupt
;
1295 emu
->pcm_capture_efx_substream
= substream
;
1296 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1300 static int snd_emu10k1_capture_efx_close(struct snd_pcm_substream
*substream
)
1302 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1304 emu
->capture_interrupt
= NULL
;
1305 emu
->pcm_capture_efx_substream
= NULL
;
1309 static struct snd_pcm_ops snd_emu10k1_playback_ops
= {
1310 .open
= snd_emu10k1_playback_open
,
1311 .close
= snd_emu10k1_playback_close
,
1312 .ioctl
= snd_pcm_lib_ioctl
,
1313 .hw_params
= snd_emu10k1_playback_hw_params
,
1314 .hw_free
= snd_emu10k1_playback_hw_free
,
1315 .prepare
= snd_emu10k1_playback_prepare
,
1316 .trigger
= snd_emu10k1_playback_trigger
,
1317 .pointer
= snd_emu10k1_playback_pointer
,
1318 .page
= snd_pcm_sgbuf_ops_page
,
1321 static struct snd_pcm_ops snd_emu10k1_capture_ops
= {
1322 .open
= snd_emu10k1_capture_open
,
1323 .close
= snd_emu10k1_capture_close
,
1324 .ioctl
= snd_pcm_lib_ioctl
,
1325 .hw_params
= snd_emu10k1_capture_hw_params
,
1326 .hw_free
= snd_emu10k1_capture_hw_free
,
1327 .prepare
= snd_emu10k1_capture_prepare
,
1328 .trigger
= snd_emu10k1_capture_trigger
,
1329 .pointer
= snd_emu10k1_capture_pointer
,
1333 static struct snd_pcm_ops snd_emu10k1_efx_playback_ops
= {
1334 .open
= snd_emu10k1_efx_playback_open
,
1335 .close
= snd_emu10k1_efx_playback_close
,
1336 .ioctl
= snd_pcm_lib_ioctl
,
1337 .hw_params
= snd_emu10k1_playback_hw_params
,
1338 .hw_free
= snd_emu10k1_efx_playback_hw_free
,
1339 .prepare
= snd_emu10k1_efx_playback_prepare
,
1340 .trigger
= snd_emu10k1_efx_playback_trigger
,
1341 .pointer
= snd_emu10k1_efx_playback_pointer
,
1342 .page
= snd_pcm_sgbuf_ops_page
,
1345 int __devinit
snd_emu10k1_pcm(struct snd_emu10k1
* emu
, int device
, struct snd_pcm
** rpcm
)
1347 struct snd_pcm
*pcm
;
1348 struct snd_pcm_substream
*substream
;
1354 if ((err
= snd_pcm_new(emu
->card
, "emu10k1", device
, 32, 1, &pcm
)) < 0)
1357 pcm
->private_data
= emu
;
1359 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_playback_ops
);
1360 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_ops
);
1362 pcm
->info_flags
= 0;
1363 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1364 strcpy(pcm
->name
, "ADC Capture/Standard PCM Playback");
1367 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
1368 if ((err
= snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024)) < 0)
1371 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
; substream
; substream
= substream
->next
)
1372 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);
1380 int __devinit
snd_emu10k1_pcm_multi(struct snd_emu10k1
* emu
, int device
, struct snd_pcm
** rpcm
)
1382 struct snd_pcm
*pcm
;
1383 struct snd_pcm_substream
*substream
;
1389 if ((err
= snd_pcm_new(emu
->card
, "emu10k1", device
, 1, 0, &pcm
)) < 0)
1392 pcm
->private_data
= emu
;
1394 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_efx_playback_ops
);
1396 pcm
->info_flags
= 0;
1397 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1398 strcpy(pcm
->name
, "Multichannel Playback");
1399 emu
->pcm_multi
= pcm
;
1401 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
1402 if ((err
= snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024)) < 0)
1412 static struct snd_pcm_ops snd_emu10k1_capture_mic_ops
= {
1413 .open
= snd_emu10k1_capture_mic_open
,
1414 .close
= snd_emu10k1_capture_mic_close
,
1415 .ioctl
= snd_pcm_lib_ioctl
,
1416 .hw_params
= snd_emu10k1_capture_hw_params
,
1417 .hw_free
= snd_emu10k1_capture_hw_free
,
1418 .prepare
= snd_emu10k1_capture_prepare
,
1419 .trigger
= snd_emu10k1_capture_trigger
,
1420 .pointer
= snd_emu10k1_capture_pointer
,
1423 int __devinit
snd_emu10k1_pcm_mic(struct snd_emu10k1
* emu
, int device
, struct snd_pcm
** rpcm
)
1425 struct snd_pcm
*pcm
;
1431 if ((err
= snd_pcm_new(emu
->card
, "emu10k1 mic", device
, 0, 1, &pcm
)) < 0)
1434 pcm
->private_data
= emu
;
1436 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_mic_ops
);
1438 pcm
->info_flags
= 0;
1439 strcpy(pcm
->name
, "Mic Capture");
1442 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);
1449 static int snd_emu10k1_pcm_efx_voices_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1451 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1452 int nefx
= emu
->audigy
? 64 : 32;
1453 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1454 uinfo
->count
= nefx
;
1455 uinfo
->value
.integer
.min
= 0;
1456 uinfo
->value
.integer
.max
= 1;
1460 static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1462 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1463 int nefx
= emu
->audigy
? 64 : 32;
1466 spin_lock_irq(&emu
->reg_lock
);
1467 for (idx
= 0; idx
< nefx
; idx
++)
1468 ucontrol
->value
.integer
.value
[idx
] = (emu
->efx_voices_mask
[idx
/ 32] & (1 << (idx
% 32))) ? 1 : 0;
1469 spin_unlock_irq(&emu
->reg_lock
);
1473 static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1475 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1476 unsigned int nval
[2], bits
;
1477 int nefx
= emu
->audigy
? 64 : 32;
1478 int nefxb
= emu
->audigy
? 7 : 6;
1481 nval
[0] = nval
[1] = 0;
1482 for (idx
= 0, bits
= 0; idx
< nefx
; idx
++)
1483 if (ucontrol
->value
.integer
.value
[idx
]) {
1484 nval
[idx
/ 32] |= 1 << (idx
% 32);
1488 for (idx
= 0; idx
< nefxb
; idx
++)
1489 if (1 << idx
== bits
)
1495 spin_lock_irq(&emu
->reg_lock
);
1496 change
= (nval
[0] != emu
->efx_voices_mask
[0]) ||
1497 (nval
[1] != emu
->efx_voices_mask
[1]);
1498 emu
->efx_voices_mask
[0] = nval
[0];
1499 emu
->efx_voices_mask
[1] = nval
[1];
1500 spin_unlock_irq(&emu
->reg_lock
);
1504 static struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask
= {
1505 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1506 .name
= "Captured FX8010 Outputs",
1507 .info
= snd_emu10k1_pcm_efx_voices_mask_info
,
1508 .get
= snd_emu10k1_pcm_efx_voices_mask_get
,
1509 .put
= snd_emu10k1_pcm_efx_voices_mask_put
1512 static struct snd_pcm_ops snd_emu10k1_capture_efx_ops
= {
1513 .open
= snd_emu10k1_capture_efx_open
,
1514 .close
= snd_emu10k1_capture_efx_close
,
1515 .ioctl
= snd_pcm_lib_ioctl
,
1516 .hw_params
= snd_emu10k1_capture_hw_params
,
1517 .hw_free
= snd_emu10k1_capture_hw_free
,
1518 .prepare
= snd_emu10k1_capture_prepare
,
1519 .trigger
= snd_emu10k1_capture_trigger
,
1520 .pointer
= snd_emu10k1_capture_pointer
,
1526 #define INITIAL_TRAM_SHIFT 14
1527 #define INITIAL_TRAM_POS(size) ((((size) / 2) - INITIAL_TRAM_SHIFT) - 1)
1529 static void snd_emu10k1_fx8010_playback_irq(struct snd_emu10k1
*emu
, void *private_data
)
1531 struct snd_pcm_substream
*substream
= private_data
;
1532 snd_pcm_period_elapsed(substream
);
1535 static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left
,
1536 unsigned short *dst_right
,
1537 unsigned short *src
,
1539 unsigned int tram_shift
)
1542 printk(KERN_DEBUG "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
1543 "src = 0x%p, count = 0x%x\n",
1544 dst_left, dst_right, src, count);
1546 if ((tram_shift
& 1) == 0) {
1548 *dst_left
-- = *src
++;
1549 *dst_right
-- = *src
++;
1553 *dst_right
-- = *src
++;
1554 *dst_left
-- = *src
++;
1559 static void fx8010_pb_trans_copy(struct snd_pcm_substream
*substream
,
1560 struct snd_pcm_indirect
*rec
, size_t bytes
)
1562 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1563 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1564 unsigned int tram_size
= pcm
->buffer_size
;
1565 unsigned short *src
= (unsigned short *)(substream
->runtime
->dma_area
+ rec
->sw_data
);
1566 unsigned int frames
= bytes
>> 2, count
;
1567 unsigned int tram_pos
= pcm
->tram_pos
;
1568 unsigned int tram_shift
= pcm
->tram_shift
;
1570 while (frames
> tram_pos
) {
1571 count
= tram_pos
+ 1;
1572 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
,
1573 (unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
+ tram_size
/ 2,
1574 src
, count
, tram_shift
);
1577 tram_pos
= (tram_size
/ 2) - 1;
1580 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
,
1581 (unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
+ tram_size
/ 2,
1582 src
, frames
, tram_shift
);
1584 pcm
->tram_pos
= tram_pos
;
1585 pcm
->tram_shift
= tram_shift
;
1588 static int snd_emu10k1_fx8010_playback_transfer(struct snd_pcm_substream
*substream
)
1590 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1591 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1593 snd_pcm_indirect_playback_transfer(substream
, &pcm
->pcm_rec
, fx8010_pb_trans_copy
);
1597 static int snd_emu10k1_fx8010_playback_hw_params(struct snd_pcm_substream
*substream
,
1598 struct snd_pcm_hw_params
*hw_params
)
1600 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
1603 static int snd_emu10k1_fx8010_playback_hw_free(struct snd_pcm_substream
*substream
)
1605 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1606 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1609 for (i
= 0; i
< pcm
->channels
; i
++)
1610 snd_emu10k1_ptr_write(emu
, TANKMEMADDRREGBASE
+ 0x80 + pcm
->etram
[i
], 0, 0);
1611 snd_pcm_lib_free_pages(substream
);
1615 static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream
*substream
)
1617 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1618 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1619 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1623 printk(KERN_DEBUG "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
1624 "buffer_size = 0x%x (0x%x)\n",
1625 emu->fx8010.etram_pages, runtime->dma_area,
1626 runtime->buffer_size, runtime->buffer_size << 2);
1628 memset(&pcm
->pcm_rec
, 0, sizeof(pcm
->pcm_rec
));
1629 pcm
->pcm_rec
.hw_buffer_size
= pcm
->buffer_size
* 2; /* byte size */
1630 pcm
->pcm_rec
.sw_buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
1631 pcm
->tram_pos
= INITIAL_TRAM_POS(pcm
->buffer_size
);
1632 pcm
->tram_shift
= 0;
1633 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_running
, 0, 0); /* reset */
1634 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 0); /* reset */
1635 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_size
, 0, runtime
->buffer_size
);
1636 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_ptr
, 0, 0); /* reset ptr number */
1637 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_count
, 0, runtime
->period_size
);
1638 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_tmpcount
, 0, runtime
->period_size
);
1639 for (i
= 0; i
< pcm
->channels
; i
++)
1640 snd_emu10k1_ptr_write(emu
, TANKMEMADDRREGBASE
+ 0x80 + pcm
->etram
[i
], 0, (TANKMEMADDRREG_READ
|TANKMEMADDRREG_ALIGN
) + i
* (runtime
->buffer_size
/ pcm
->channels
));
1644 static int snd_emu10k1_fx8010_playback_trigger(struct snd_pcm_substream
*substream
, int cmd
)
1646 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1647 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1650 spin_lock(&emu
->reg_lock
);
1652 case SNDRV_PCM_TRIGGER_START
:
1654 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1655 case SNDRV_PCM_TRIGGER_RESUME
:
1656 #ifdef EMU10K1_SET_AC3_IEC958
1659 for (i
= 0; i
< 3; i
++) {
1661 bits
= SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
1662 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
| SPCS_GENERATIONSTATUS
|
1663 0x00001200 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
| SPCS_NOTAUDIODATA
;
1664 snd_emu10k1_ptr_write(emu
, SPCS0
+ i
, 0, bits
);
1668 result
= snd_emu10k1_fx8010_register_irq_handler(emu
, snd_emu10k1_fx8010_playback_irq
, pcm
->gpr_running
, substream
, &pcm
->irq
);
1671 snd_emu10k1_fx8010_playback_transfer(substream
); /* roll the ball */
1672 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 1);
1674 case SNDRV_PCM_TRIGGER_STOP
:
1675 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1676 case SNDRV_PCM_TRIGGER_SUSPEND
:
1677 snd_emu10k1_fx8010_unregister_irq_handler(emu
, pcm
->irq
); pcm
->irq
= NULL
;
1678 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 0);
1679 pcm
->tram_pos
= INITIAL_TRAM_POS(pcm
->buffer_size
);
1680 pcm
->tram_shift
= 0;
1687 spin_unlock(&emu
->reg_lock
);
1691 static snd_pcm_uframes_t
snd_emu10k1_fx8010_playback_pointer(struct snd_pcm_substream
*substream
)
1693 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1694 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1695 size_t ptr
; /* byte pointer */
1697 if (!snd_emu10k1_ptr_read(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0))
1699 ptr
= snd_emu10k1_ptr_read(emu
, emu
->gpr_base
+ pcm
->gpr_ptr
, 0) << 2;
1700 return snd_pcm_indirect_playback_pointer(substream
, &pcm
->pcm_rec
, ptr
);
1703 static struct snd_pcm_hardware snd_emu10k1_fx8010_playback
=
1705 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1706 SNDRV_PCM_INFO_RESUME
|
1707 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE
),
1708 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
1709 .rates
= SNDRV_PCM_RATE_48000
,
1714 .buffer_bytes_max
= (128*1024),
1715 .period_bytes_min
= 1024,
1716 .period_bytes_max
= (128*1024),
1718 .periods_max
= 1024,
1722 static int snd_emu10k1_fx8010_playback_open(struct snd_pcm_substream
*substream
)
1724 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1725 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1726 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1728 runtime
->hw
= snd_emu10k1_fx8010_playback
;
1729 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= pcm
->channels
;
1730 runtime
->hw
.period_bytes_max
= (pcm
->buffer_size
* 2) / 2;
1731 spin_lock_irq(&emu
->reg_lock
);
1732 if (pcm
->valid
== 0) {
1733 spin_unlock_irq(&emu
->reg_lock
);
1737 spin_unlock_irq(&emu
->reg_lock
);
1741 static int snd_emu10k1_fx8010_playback_close(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
];
1746 spin_lock_irq(&emu
->reg_lock
);
1748 spin_unlock_irq(&emu
->reg_lock
);
1752 static struct snd_pcm_ops snd_emu10k1_fx8010_playback_ops
= {
1753 .open
= snd_emu10k1_fx8010_playback_open
,
1754 .close
= snd_emu10k1_fx8010_playback_close
,
1755 .ioctl
= snd_pcm_lib_ioctl
,
1756 .hw_params
= snd_emu10k1_fx8010_playback_hw_params
,
1757 .hw_free
= snd_emu10k1_fx8010_playback_hw_free
,
1758 .prepare
= snd_emu10k1_fx8010_playback_prepare
,
1759 .trigger
= snd_emu10k1_fx8010_playback_trigger
,
1760 .pointer
= snd_emu10k1_fx8010_playback_pointer
,
1761 .ack
= snd_emu10k1_fx8010_playback_transfer
,
1764 int __devinit
snd_emu10k1_pcm_efx(struct snd_emu10k1
* emu
, int device
, struct snd_pcm
** rpcm
)
1766 struct snd_pcm
*pcm
;
1767 struct snd_kcontrol
*kctl
;
1773 if ((err
= snd_pcm_new(emu
->card
, "emu10k1 efx", device
, 8, 1, &pcm
)) < 0)
1776 pcm
->private_data
= emu
;
1778 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_fx8010_playback_ops
);
1779 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_efx_ops
);
1781 pcm
->info_flags
= 0;
1782 strcpy(pcm
->name
, "Multichannel Capture/PT Playback");
1787 /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs
1791 /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */
1793 emu
->efx_voices_mask
[0] = 0;
1794 if (emu
->card_capabilities
->emu_model
)
1795 /* Pavel Hofman - 32 voices will be used for
1796 * capture (write mode) -
1797 * each bit = corresponding voice
1799 emu
->efx_voices_mask
[1] = 0xffffffff;
1801 emu
->efx_voices_mask
[1] = 0xffff;
1803 emu
->efx_voices_mask
[0] = 0xffff0000;
1804 emu
->efx_voices_mask
[1] = 0;
1806 /* For emu1010, the control has to set 32 upper bits (voices)
1807 * out of the 64 bits (voices) to true for the 16-channels capture
1808 * to work correctly. Correct A_FXWC2 initial value (0xffffffff)
1809 * is already defined but the snd_emu10k1_pcm_efx_voices_mask
1810 * control can override this register's value.
1812 kctl
= snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask
, emu
);
1815 kctl
->id
.device
= device
;
1816 snd_ctl_add(emu
->card
, kctl
);
1818 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);