2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 * Routines for control of EMU10K1 chips / PCM routines
5 * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <linux/pci.h>
30 #include <linux/delay.h>
31 #include <linux/slab.h>
32 #include <linux/time.h>
33 #include <linux/init.h>
34 #include <sound/core.h>
35 #include <sound/emu10k1.h>
37 static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1
*emu
,
38 struct snd_emu10k1_voice
*voice
)
40 struct snd_emu10k1_pcm
*epcm
;
42 if ((epcm
= voice
->epcm
) == NULL
)
44 if (epcm
->substream
== NULL
)
47 dev_dbg(emu
->card
->dev
,
48 "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
49 epcm
->substream
->runtime
->hw
->pointer(emu
, epcm
->substream
),
50 snd_pcm_lib_period_bytes(epcm
->substream
),
51 snd_pcm_lib_buffer_bytes(epcm
->substream
));
53 snd_pcm_period_elapsed(epcm
->substream
);
56 static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1
*emu
,
60 if (status
& IPR_ADCBUFHALFFULL
) {
61 if (emu
->pcm_capture_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
65 snd_pcm_period_elapsed(emu
->pcm_capture_substream
);
68 static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1
*emu
,
72 if (status
& IPR_MICBUFHALFFULL
) {
73 if (emu
->pcm_capture_mic_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
77 snd_pcm_period_elapsed(emu
->pcm_capture_mic_substream
);
80 static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1
*emu
,
84 if (status
& IPR_EFXBUFHALFFULL
) {
85 if (emu
->pcm_capture_efx_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
89 snd_pcm_period_elapsed(emu
->pcm_capture_efx_substream
);
92 static snd_pcm_uframes_t
snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream
*substream
)
94 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
95 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
96 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
101 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->voices
[0]->number
) & 0x00ffffff;
102 ptr
+= runtime
->buffer_size
;
103 ptr
-= epcm
->ccca_start_addr
;
104 ptr
%= runtime
->buffer_size
;
109 static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm
* epcm
, int voices
)
113 if (epcm
->voices
[1] != NULL
&& voices
< 2) {
114 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[1]);
115 epcm
->voices
[1] = NULL
;
117 for (i
= 0; i
< voices
; i
++) {
118 if (epcm
->voices
[i
] == NULL
)
122 return 0; /* already allocated */
124 for (i
= 0; i
< ARRAY_SIZE(epcm
->voices
); i
++) {
125 if (epcm
->voices
[i
]) {
126 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
127 epcm
->voices
[i
] = NULL
;
130 err
= snd_emu10k1_voice_alloc(epcm
->emu
,
131 epcm
->type
== PLAYBACK_EMUVOICE
? EMU10K1_PCM
: EMU10K1_EFX
,
137 epcm
->voices
[0]->epcm
= epcm
;
139 for (i
= 1; i
< voices
; i
++) {
140 epcm
->voices
[i
] = &epcm
->emu
->voices
[epcm
->voices
[0]->number
+ i
];
141 epcm
->voices
[i
]->epcm
= epcm
;
144 if (epcm
->extra
== NULL
) {
145 err
= snd_emu10k1_voice_alloc(epcm
->emu
,
146 epcm
->type
== PLAYBACK_EMUVOICE
? EMU10K1_PCM
: EMU10K1_EFX
,
151 dev_dbg(emu->card->dev, "pcm_channel_alloc: "
152 "failed extra: voices=%d, frame=%d\n",
155 for (i
= 0; i
< voices
; i
++) {
156 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
157 epcm
->voices
[i
] = NULL
;
161 epcm
->extra
->epcm
= epcm
;
162 epcm
->extra
->interrupt
= snd_emu10k1_pcm_interrupt
;
167 static unsigned int capture_period_sizes
[31] = {
169 384*2, 448*2, 512*2, 640*2,
170 384*4, 448*4, 512*4, 640*4,
171 384*8, 448*8, 512*8, 640*8,
172 384*16, 448*16, 512*16, 640*16,
173 384*32, 448*32, 512*32, 640*32,
174 384*64, 448*64, 512*64, 640*64,
175 384*128,448*128,512*128
178 static struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes
= {
180 .list
= capture_period_sizes
,
184 static unsigned int capture_rates
[8] = {
185 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
188 static struct snd_pcm_hw_constraint_list hw_constraints_capture_rates
= {
190 .list
= capture_rates
,
194 static unsigned int snd_emu10k1_capture_rate_reg(unsigned int rate
)
197 case 8000: return ADCCR_SAMPLERATE_8
;
198 case 11025: return ADCCR_SAMPLERATE_11
;
199 case 16000: return ADCCR_SAMPLERATE_16
;
200 case 22050: return ADCCR_SAMPLERATE_22
;
201 case 24000: return ADCCR_SAMPLERATE_24
;
202 case 32000: return ADCCR_SAMPLERATE_32
;
203 case 44100: return ADCCR_SAMPLERATE_44
;
204 case 48000: return ADCCR_SAMPLERATE_48
;
207 return ADCCR_SAMPLERATE_8
;
211 static unsigned int snd_emu10k1_audigy_capture_rate_reg(unsigned int rate
)
214 case 8000: return A_ADCCR_SAMPLERATE_8
;
215 case 11025: return A_ADCCR_SAMPLERATE_11
;
216 case 12000: return A_ADCCR_SAMPLERATE_12
; /* really supported? */
217 case 16000: return ADCCR_SAMPLERATE_16
;
218 case 22050: return ADCCR_SAMPLERATE_22
;
219 case 24000: return ADCCR_SAMPLERATE_24
;
220 case 32000: return ADCCR_SAMPLERATE_32
;
221 case 44100: return ADCCR_SAMPLERATE_44
;
222 case 48000: return ADCCR_SAMPLERATE_48
;
225 return A_ADCCR_SAMPLERATE_8
;
229 static unsigned int emu10k1_calc_pitch_target(unsigned int rate
)
231 unsigned int pitch_target
;
233 pitch_target
= (rate
<< 8) / 375;
234 pitch_target
= (pitch_target
>> 1) + (pitch_target
& 1);
238 #define PITCH_48000 0x00004000
239 #define PITCH_96000 0x00008000
240 #define PITCH_85000 0x00007155
241 #define PITCH_80726 0x00006ba2
242 #define PITCH_67882 0x00005a82
243 #define PITCH_57081 0x00004c1c
245 static unsigned int emu10k1_select_interprom(unsigned int pitch_target
)
247 if (pitch_target
== PITCH_48000
)
248 return CCCA_INTERPROM_0
;
249 else if (pitch_target
< PITCH_48000
)
250 return CCCA_INTERPROM_1
;
251 else if (pitch_target
>= PITCH_96000
)
252 return CCCA_INTERPROM_0
;
253 else if (pitch_target
>= PITCH_85000
)
254 return CCCA_INTERPROM_6
;
255 else if (pitch_target
>= PITCH_80726
)
256 return CCCA_INTERPROM_5
;
257 else if (pitch_target
>= PITCH_67882
)
258 return CCCA_INTERPROM_4
;
259 else if (pitch_target
>= PITCH_57081
)
260 return CCCA_INTERPROM_3
;
262 return CCCA_INTERPROM_2
;
266 * calculate cache invalidate size
268 * stereo: channel is stereo
269 * w_16: using 16bit samples
271 * returns: cache invalidate size in samples
273 static inline int emu10k1_ccis(int stereo
, int w_16
)
276 return stereo
? 24 : 26;
278 return stereo
? 24*2 : 26*2;
282 static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1
*emu
,
283 int master
, int extra
,
284 struct snd_emu10k1_voice
*evoice
,
285 unsigned int start_addr
,
286 unsigned int end_addr
,
287 struct snd_emu10k1_pcm_mixer
*mix
)
289 struct snd_pcm_substream
*substream
= evoice
->epcm
->substream
;
290 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
291 unsigned int silent_page
, tmp
;
292 int voice
, stereo
, w_16
;
293 unsigned char attn
, send_amount
[8];
294 unsigned char send_routing
[8];
296 unsigned int pitch_target
;
299 voice
= evoice
->number
;
300 stereo
= runtime
->channels
== 2;
301 w_16
= snd_pcm_format_width(runtime
->format
) == 16;
303 if (!extra
&& stereo
) {
312 spin_lock_irqsave(&emu
->reg_lock
, flags
);
314 /* volume parameters */
317 memset(send_routing
, 0, sizeof(send_routing
));
322 memset(send_amount
, 0, sizeof(send_amount
));
324 /* mono, left, right (master voice = left) */
325 tmp
= stereo
? (master
? 1 : 2) : 0;
326 memcpy(send_routing
, &mix
->send_routing
[tmp
][0], 8);
327 memcpy(send_amount
, &mix
->send_volume
[tmp
][0], 8);
330 ccis
= emu10k1_ccis(stereo
, w_16
);
333 evoice
->epcm
->ccca_start_addr
= start_addr
+ ccis
;
336 end_addr
+= ccis
+ emu
->delay_pcm_irq
;
338 if (stereo
&& !extra
) {
339 snd_emu10k1_ptr_write(emu
, CPF
, voice
, CPF_STEREO_MASK
);
340 snd_emu10k1_ptr_write(emu
, CPF
, (voice
+ 1), CPF_STEREO_MASK
);
342 snd_emu10k1_ptr_write(emu
, CPF
, voice
, 0);
348 snd_emu10k1_ptr_write(emu
, A_FXRT1
, voice
,
349 snd_emu10k1_compose_audigy_fxrt1(send_routing
));
350 snd_emu10k1_ptr_write(emu
, A_FXRT2
, voice
,
351 snd_emu10k1_compose_audigy_fxrt2(send_routing
));
352 snd_emu10k1_ptr_write(emu
, A_SENDAMOUNTS
, voice
,
353 ((unsigned int)send_amount
[4] << 24) |
354 ((unsigned int)send_amount
[5] << 16) |
355 ((unsigned int)send_amount
[6] << 8) |
356 (unsigned int)send_amount
[7]);
358 snd_emu10k1_ptr_write(emu
, FXRT
, voice
,
359 snd_emu10k1_compose_send_routing(send_routing
));
361 /* Assumption that PT is already 0 so no harm overwriting */
362 snd_emu10k1_ptr_write(emu
, PTRX
, voice
, (send_amount
[0] << 8) | send_amount
[1]);
363 snd_emu10k1_ptr_write(emu
, DSL
, voice
, end_addr
| (send_amount
[3] << 24));
364 snd_emu10k1_ptr_write(emu
, PSST
, voice
,
365 (start_addr
+ (extra
? emu
->delay_pcm_irq
: 0)) |
366 (send_amount
[2] << 24));
367 if (emu
->card_capabilities
->emu_model
)
368 pitch_target
= PITCH_48000
; /* Disable interpolators on emu1010 card */
370 pitch_target
= emu10k1_calc_pitch_target(runtime
->rate
);
372 snd_emu10k1_ptr_write(emu
, CCCA
, voice
, start_addr
|
373 emu10k1_select_interprom(pitch_target
) |
374 (w_16
? 0 : CCCA_8BITSELECT
));
376 snd_emu10k1_ptr_write(emu
, CCCA
, voice
, (start_addr
+ ccis
) |
377 emu10k1_select_interprom(pitch_target
) |
378 (w_16
? 0 : CCCA_8BITSELECT
));
379 /* Clear filter delay memory */
380 snd_emu10k1_ptr_write(emu
, Z1
, voice
, 0);
381 snd_emu10k1_ptr_write(emu
, Z2
, voice
, 0);
382 /* invalidate maps */
383 silent_page
= ((unsigned int)emu
->silent_page
.addr
<< emu
->address_mode
) | (emu
->address_mode
? MAP_PTI_MASK1
: MAP_PTI_MASK0
);
384 snd_emu10k1_ptr_write(emu
, MAPA
, voice
, silent_page
);
385 snd_emu10k1_ptr_write(emu
, MAPB
, voice
, silent_page
);
386 /* modulation envelope */
387 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, 0xffff);
388 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, 0xffff);
389 snd_emu10k1_ptr_write(emu
, ATKHLDM
, voice
, 0);
390 snd_emu10k1_ptr_write(emu
, DCYSUSM
, voice
, 0x007f);
391 snd_emu10k1_ptr_write(emu
, LFOVAL1
, voice
, 0x8000);
392 snd_emu10k1_ptr_write(emu
, LFOVAL2
, voice
, 0x8000);
393 snd_emu10k1_ptr_write(emu
, FMMOD
, voice
, 0);
394 snd_emu10k1_ptr_write(emu
, TREMFRQ
, voice
, 0);
395 snd_emu10k1_ptr_write(emu
, FM2FRQ2
, voice
, 0);
396 snd_emu10k1_ptr_write(emu
, ENVVAL
, voice
, 0x8000);
397 /* volume envelope */
398 snd_emu10k1_ptr_write(emu
, ATKHLDV
, voice
, 0x7f7f);
399 snd_emu10k1_ptr_write(emu
, ENVVOL
, voice
, 0x0000);
400 /* filter envelope */
401 snd_emu10k1_ptr_write(emu
, PEFE_FILTERAMOUNT
, voice
, 0x7f);
403 snd_emu10k1_ptr_write(emu
, PEFE_PITCHAMOUNT
, voice
, 0);
405 spin_unlock_irqrestore(&emu
->reg_lock
, flags
);
408 static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream
*substream
,
409 struct snd_pcm_hw_params
*hw_params
)
411 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
412 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
413 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
416 if ((err
= snd_emu10k1_pcm_channel_alloc(epcm
, params_channels(hw_params
))) < 0)
418 if ((err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
))) < 0)
420 if (err
> 0) { /* change */
422 if (epcm
->memblk
!= NULL
)
423 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
424 epcm
->memblk
= snd_emu10k1_alloc_pages(emu
, substream
);
425 epcm
->start_addr
= 0;
428 mapped
= ((struct snd_emu10k1_memblk
*)epcm
->memblk
)->mapped_page
;
431 epcm
->start_addr
= mapped
<< PAGE_SHIFT
;
436 static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream
*substream
)
438 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
439 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
440 struct snd_emu10k1_pcm
*epcm
;
442 if (runtime
->private_data
== NULL
)
444 epcm
= runtime
->private_data
;
446 snd_emu10k1_voice_free(epcm
->emu
, epcm
->extra
);
449 if (epcm
->voices
[1]) {
450 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[1]);
451 epcm
->voices
[1] = NULL
;
453 if (epcm
->voices
[0]) {
454 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[0]);
455 epcm
->voices
[0] = NULL
;
458 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
460 epcm
->start_addr
= 0;
462 snd_pcm_lib_free_pages(substream
);
466 static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream
*substream
)
468 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
469 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
470 struct snd_emu10k1_pcm
*epcm
;
473 if (runtime
->private_data
== NULL
)
475 epcm
= runtime
->private_data
;
477 snd_emu10k1_voice_free(epcm
->emu
, epcm
->extra
);
480 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
481 if (epcm
->voices
[i
]) {
482 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
483 epcm
->voices
[i
] = NULL
;
487 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
489 epcm
->start_addr
= 0;
491 snd_pcm_lib_free_pages(substream
);
495 static int snd_emu10k1_playback_prepare(struct snd_pcm_substream
*substream
)
497 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
498 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
499 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
500 unsigned int start_addr
, end_addr
;
502 start_addr
= epcm
->start_addr
;
503 end_addr
= snd_pcm_lib_period_bytes(substream
);
504 if (runtime
->channels
== 2) {
508 end_addr
+= start_addr
;
509 snd_emu10k1_pcm_init_voice(emu
, 1, 1, epcm
->extra
,
510 start_addr
, end_addr
, NULL
);
511 start_addr
= epcm
->start_addr
;
512 end_addr
= epcm
->start_addr
+ snd_pcm_lib_buffer_bytes(substream
);
513 snd_emu10k1_pcm_init_voice(emu
, 1, 0, epcm
->voices
[0],
514 start_addr
, end_addr
,
515 &emu
->pcm_mixer
[substream
->number
]);
517 snd_emu10k1_pcm_init_voice(emu
, 0, 0, epcm
->voices
[1],
518 start_addr
, end_addr
,
519 &emu
->pcm_mixer
[substream
->number
]);
523 static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream
*substream
)
525 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
526 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
527 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
528 unsigned int start_addr
, end_addr
;
529 unsigned int channel_size
;
532 start_addr
= epcm
->start_addr
;
533 end_addr
= epcm
->start_addr
+ snd_pcm_lib_buffer_bytes(substream
);
536 * the kX driver leaves some space between voices
538 channel_size
= ( end_addr
- start_addr
) / NUM_EFX_PLAYBACK
;
540 snd_emu10k1_pcm_init_voice(emu
, 1, 1, epcm
->extra
,
541 start_addr
, start_addr
+ (channel_size
/ 2), NULL
);
543 /* only difference with the master voice is we use it for the pointer */
544 snd_emu10k1_pcm_init_voice(emu
, 1, 0, epcm
->voices
[0],
545 start_addr
, start_addr
+ channel_size
,
546 &emu
->efx_pcm_mixer
[0]);
548 start_addr
+= channel_size
;
549 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++) {
550 snd_emu10k1_pcm_init_voice(emu
, 0, 0, epcm
->voices
[i
],
551 start_addr
, start_addr
+ channel_size
,
552 &emu
->efx_pcm_mixer
[i
]);
553 start_addr
+= channel_size
;
559 static struct snd_pcm_hardware snd_emu10k1_efx_playback
=
561 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_NONINTERLEAVED
|
562 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
563 SNDRV_PCM_INFO_RESUME
|
564 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
),
565 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
566 .rates
= SNDRV_PCM_RATE_48000
,
569 .channels_min
= NUM_EFX_PLAYBACK
,
570 .channels_max
= NUM_EFX_PLAYBACK
,
571 .buffer_bytes_max
= (64*1024),
572 .period_bytes_min
= 64,
573 .period_bytes_max
= (64*1024),
579 static int snd_emu10k1_capture_hw_params(struct snd_pcm_substream
*substream
,
580 struct snd_pcm_hw_params
*hw_params
)
582 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
585 static int snd_emu10k1_capture_hw_free(struct snd_pcm_substream
*substream
)
587 return snd_pcm_lib_free_pages(substream
);
590 static int snd_emu10k1_capture_prepare(struct snd_pcm_substream
*substream
)
592 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
593 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
594 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
597 /* zeroing the buffer size will stop capture */
598 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, 0);
599 switch (epcm
->type
) {
600 case CAPTURE_AC97ADC
:
601 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, 0);
605 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, 0);
606 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, 0);
608 snd_emu10k1_ptr_write(emu
, FXWC
, 0, 0);
613 snd_emu10k1_ptr_write(emu
, epcm
->capture_ba_reg
, 0, runtime
->dma_addr
);
614 epcm
->capture_bufsize
= snd_pcm_lib_buffer_bytes(substream
);
615 epcm
->capture_bs_val
= 0;
616 for (idx
= 0; idx
< 31; idx
++) {
617 if (capture_period_sizes
[idx
] == epcm
->capture_bufsize
) {
618 epcm
->capture_bs_val
= idx
+ 1;
622 if (epcm
->capture_bs_val
== 0) {
624 epcm
->capture_bs_val
++;
626 if (epcm
->type
== CAPTURE_AC97ADC
) {
627 epcm
->capture_cr_val
= emu
->audigy
? A_ADCCR_LCHANENABLE
: ADCCR_LCHANENABLE
;
628 if (runtime
->channels
> 1)
629 epcm
->capture_cr_val
|= emu
->audigy
? A_ADCCR_RCHANENABLE
: ADCCR_RCHANENABLE
;
630 epcm
->capture_cr_val
|= emu
->audigy
?
631 snd_emu10k1_audigy_capture_rate_reg(runtime
->rate
) :
632 snd_emu10k1_capture_rate_reg(runtime
->rate
);
637 static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1
*emu
, int extra
, struct snd_emu10k1_voice
*evoice
)
639 struct snd_pcm_runtime
*runtime
;
640 unsigned int voice
, stereo
, i
, ccis
, cra
= 64, cs
, sample
;
644 runtime
= evoice
->epcm
->substream
->runtime
;
645 voice
= evoice
->number
;
646 stereo
= (!extra
&& runtime
->channels
== 2);
647 sample
= snd_pcm_format_width(runtime
->format
) == 16 ? 0 : 0x80808080;
648 ccis
= emu10k1_ccis(stereo
, sample
== 0);
649 /* set cs to 2 * number of cache registers beside the invalidated */
650 cs
= (sample
== 0) ? (32-ccis
) : (64-ccis
+1) >> 1;
651 if (cs
> 16) cs
= 16;
652 for (i
= 0; i
< cs
; i
++) {
653 snd_emu10k1_ptr_write(emu
, CD0
+ i
, voice
, sample
);
655 snd_emu10k1_ptr_write(emu
, CD0
+ i
, voice
+ 1, sample
);
659 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
, 0);
660 snd_emu10k1_ptr_write(emu
, CCR_READADDRESS
, voice
, cra
);
662 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
+ 1, 0);
663 snd_emu10k1_ptr_write(emu
, CCR_READADDRESS
, voice
+ 1, cra
);
666 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
, ccis
);
668 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
+1, ccis
);
672 static void snd_emu10k1_playback_prepare_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
,
673 int master
, int extra
,
674 struct snd_emu10k1_pcm_mixer
*mix
)
676 struct snd_pcm_substream
*substream
;
677 struct snd_pcm_runtime
*runtime
;
678 unsigned int attn
, vattn
;
679 unsigned int voice
, tmp
;
681 if (evoice
== NULL
) /* skip second voice for mono */
683 substream
= evoice
->epcm
->substream
;
684 runtime
= substream
->runtime
;
685 voice
= evoice
->number
;
687 attn
= extra
? 0 : 0x00ff;
688 tmp
= runtime
->channels
== 2 ? (master
? 1 : 2) : 0;
689 vattn
= mix
!= NULL
? (mix
->attn
[tmp
] << 16) : 0;
690 snd_emu10k1_ptr_write(emu
, IFATN
, voice
, attn
);
691 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, vattn
| 0xffff);
692 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, vattn
| 0xffff);
693 snd_emu10k1_ptr_write(emu
, DCYSUSV
, voice
, 0x7f7f);
694 snd_emu10k1_voice_clear_loop_stop(emu
, voice
);
697 static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
, int master
, int extra
)
699 struct snd_pcm_substream
*substream
;
700 struct snd_pcm_runtime
*runtime
;
701 unsigned int voice
, pitch
, pitch_target
;
703 if (evoice
== NULL
) /* skip second voice for mono */
705 substream
= evoice
->epcm
->substream
;
706 runtime
= substream
->runtime
;
707 voice
= evoice
->number
;
709 pitch
= snd_emu10k1_rate_to_pitch(runtime
->rate
) >> 8;
710 if (emu
->card_capabilities
->emu_model
)
711 pitch_target
= PITCH_48000
; /* Disable interpolators on emu1010 card */
713 pitch_target
= emu10k1_calc_pitch_target(runtime
->rate
);
714 snd_emu10k1_ptr_write(emu
, PTRX_PITCHTARGET
, voice
, pitch_target
);
715 if (master
|| evoice
->epcm
->type
== PLAYBACK_EFX
)
716 snd_emu10k1_ptr_write(emu
, CPF_CURRENTPITCH
, voice
, pitch_target
);
717 snd_emu10k1_ptr_write(emu
, IP
, voice
, pitch
);
719 snd_emu10k1_voice_intr_enable(emu
, voice
);
722 static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
)
728 voice
= evoice
->number
;
729 snd_emu10k1_voice_intr_disable(emu
, voice
);
730 snd_emu10k1_ptr_write(emu
, PTRX_PITCHTARGET
, voice
, 0);
731 snd_emu10k1_ptr_write(emu
, CPF_CURRENTPITCH
, voice
, 0);
732 snd_emu10k1_ptr_write(emu
, IFATN
, voice
, 0xffff);
733 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, 0xffff);
734 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, 0xffff);
735 snd_emu10k1_ptr_write(emu
, IP
, voice
, 0);
738 static inline void snd_emu10k1_playback_mangle_extra(struct snd_emu10k1
*emu
,
739 struct snd_emu10k1_pcm
*epcm
,
740 struct snd_pcm_substream
*substream
,
741 struct snd_pcm_runtime
*runtime
)
743 unsigned int ptr
, period_pos
;
745 /* try to sychronize the current position for the interrupt
747 period_pos
= runtime
->status
->hw_ptr
- runtime
->hw_ptr_interrupt
;
748 period_pos
%= runtime
->period_size
;
749 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->extra
->number
);
751 ptr
|= epcm
->ccca_start_addr
+ period_pos
;
752 snd_emu10k1_ptr_write(emu
, CCCA
, epcm
->extra
->number
, ptr
);
755 static int snd_emu10k1_playback_trigger(struct snd_pcm_substream
*substream
,
758 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
759 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
760 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
761 struct snd_emu10k1_pcm_mixer
*mix
;
765 dev_dbg(emu->card->dev,
766 "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
767 (int)emu, cmd, substream->ops->pointer(substream))
769 spin_lock(&emu
->reg_lock
);
771 case SNDRV_PCM_TRIGGER_START
:
772 snd_emu10k1_playback_invalidate_cache(emu
, 1, epcm
->extra
); /* do we need this? */
773 snd_emu10k1_playback_invalidate_cache(emu
, 0, epcm
->voices
[0]);
775 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
776 case SNDRV_PCM_TRIGGER_RESUME
:
777 if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_RELEASE
)
778 snd_emu10k1_playback_mangle_extra(emu
, epcm
, substream
, runtime
);
779 mix
= &emu
->pcm_mixer
[substream
->number
];
780 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[0], 1, 0, mix
);
781 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[1], 0, 0, mix
);
782 snd_emu10k1_playback_prepare_voice(emu
, epcm
->extra
, 1, 1, NULL
);
783 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[0], 1, 0);
784 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[1], 0, 0);
785 snd_emu10k1_playback_trigger_voice(emu
, epcm
->extra
, 1, 1);
788 case SNDRV_PCM_TRIGGER_STOP
:
789 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
790 case SNDRV_PCM_TRIGGER_SUSPEND
:
792 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[0]);
793 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[1]);
794 snd_emu10k1_playback_stop_voice(emu
, epcm
->extra
);
800 spin_unlock(&emu
->reg_lock
);
804 static int snd_emu10k1_capture_trigger(struct snd_pcm_substream
*substream
,
807 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
808 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
809 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
812 spin_lock(&emu
->reg_lock
);
814 case SNDRV_PCM_TRIGGER_START
:
815 case SNDRV_PCM_TRIGGER_RESUME
:
816 /* hmm this should cause full and half full interrupt to be raised? */
817 outl(epcm
->capture_ipr
, emu
->port
+ IPR
);
818 snd_emu10k1_intr_enable(emu
, epcm
->capture_inte
);
820 dev_dbg(emu->card->dev, "adccr = 0x%x, adcbs = 0x%x\n",
821 epcm->adccr, epcm->adcbs);
823 switch (epcm
->type
) {
824 case CAPTURE_AC97ADC
:
825 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, epcm
->capture_cr_val
);
829 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, epcm
->capture_cr_val
);
830 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, epcm
->capture_cr_val2
);
831 dev_dbg(emu
->card
->dev
,
832 "cr_val=0x%x, cr_val2=0x%x\n",
833 epcm
->capture_cr_val
,
834 epcm
->capture_cr_val2
);
836 snd_emu10k1_ptr_write(emu
, FXWC
, 0, epcm
->capture_cr_val
);
841 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, epcm
->capture_bs_val
);
845 case SNDRV_PCM_TRIGGER_STOP
:
846 case SNDRV_PCM_TRIGGER_SUSPEND
:
848 snd_emu10k1_intr_disable(emu
, epcm
->capture_inte
);
849 outl(epcm
->capture_ipr
, emu
->port
+ IPR
);
850 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, 0);
851 switch (epcm
->type
) {
852 case CAPTURE_AC97ADC
:
853 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, 0);
857 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, 0);
858 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, 0);
860 snd_emu10k1_ptr_write(emu
, FXWC
, 0, 0);
869 spin_unlock(&emu
->reg_lock
);
873 static snd_pcm_uframes_t
snd_emu10k1_playback_pointer(struct snd_pcm_substream
*substream
)
875 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
876 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
877 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
882 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->voices
[0]->number
) & 0x00ffffff;
883 #if 0 /* Perex's code */
884 ptr
+= runtime
->buffer_size
;
885 ptr
-= epcm
->ccca_start_addr
;
886 ptr
%= runtime
->buffer_size
;
887 #else /* EMU10K1 Open Source code from Creative */
888 if (ptr
< epcm
->ccca_start_addr
)
889 ptr
+= runtime
->buffer_size
- epcm
->ccca_start_addr
;
891 ptr
-= epcm
->ccca_start_addr
;
892 if (ptr
>= runtime
->buffer_size
)
893 ptr
-= runtime
->buffer_size
;
897 dev_dbg(emu->card->dev,
898 "ptr = 0x%lx, buffer_size = 0x%lx, period_size = 0x%lx\n",
899 (long)ptr, (long)runtime->buffer_size,
900 (long)runtime->period_size);
906 static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream
*substream
,
909 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
910 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
911 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
915 spin_lock(&emu
->reg_lock
);
917 case SNDRV_PCM_TRIGGER_START
:
919 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
920 snd_emu10k1_playback_invalidate_cache(emu
, 0, epcm
->voices
[i
]);
922 snd_emu10k1_playback_invalidate_cache(emu
, 1, epcm
->extra
);
925 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
926 case SNDRV_PCM_TRIGGER_RESUME
:
927 snd_emu10k1_playback_prepare_voice(emu
, epcm
->extra
, 1, 1, NULL
);
928 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[0], 0, 0,
929 &emu
->efx_pcm_mixer
[0]);
930 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++)
931 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[i
], 0, 0,
932 &emu
->efx_pcm_mixer
[i
]);
933 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[0], 0, 0);
934 snd_emu10k1_playback_trigger_voice(emu
, epcm
->extra
, 1, 1);
935 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++)
936 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[i
], 0, 0);
939 case SNDRV_PCM_TRIGGER_SUSPEND
:
940 case SNDRV_PCM_TRIGGER_STOP
:
941 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
943 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
944 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[i
]);
946 snd_emu10k1_playback_stop_voice(emu
, epcm
->extra
);
952 spin_unlock(&emu
->reg_lock
);
957 static snd_pcm_uframes_t
snd_emu10k1_capture_pointer(struct snd_pcm_substream
*substream
)
959 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
960 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
961 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
966 if (epcm
->first_ptr
) {
967 udelay(50); /* hack, it takes awhile until capture is started */
970 ptr
= snd_emu10k1_ptr_read(emu
, epcm
->capture_idx_reg
, 0) & 0x0000ffff;
971 return bytes_to_frames(runtime
, ptr
);
975 * Playback support device description
978 static struct snd_pcm_hardware snd_emu10k1_playback
=
980 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
981 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
982 SNDRV_PCM_INFO_RESUME
|
983 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
),
984 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
985 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_96000
,
990 .buffer_bytes_max
= (128*1024),
991 .period_bytes_min
= 64,
992 .period_bytes_max
= (128*1024),
999 * Capture support device description
1002 static struct snd_pcm_hardware snd_emu10k1_capture
=
1004 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1005 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1006 SNDRV_PCM_INFO_RESUME
|
1007 SNDRV_PCM_INFO_MMAP_VALID
),
1008 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1009 .rates
= SNDRV_PCM_RATE_8000_48000
,
1014 .buffer_bytes_max
= (64*1024),
1015 .period_bytes_min
= 384,
1016 .period_bytes_max
= (64*1024),
1022 static struct snd_pcm_hardware snd_emu10k1_capture_efx
=
1024 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1025 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1026 SNDRV_PCM_INFO_RESUME
|
1027 SNDRV_PCM_INFO_MMAP_VALID
),
1028 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1029 .rates
= SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
|
1030 SNDRV_PCM_RATE_88200
| SNDRV_PCM_RATE_96000
|
1031 SNDRV_PCM_RATE_176400
| SNDRV_PCM_RATE_192000
,
1036 .buffer_bytes_max
= (64*1024),
1037 .period_bytes_min
= 384,
1038 .period_bytes_max
= (64*1024),
1048 static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1
*emu
, struct snd_kcontrol
*kctl
, int idx
, int activate
)
1050 struct snd_ctl_elem_id id
;
1055 kctl
->vd
[idx
].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1057 kctl
->vd
[idx
].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1058 snd_ctl_notify(emu
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1059 SNDRV_CTL_EVENT_MASK_INFO
,
1060 snd_ctl_build_ioff(&id
, kctl
, idx
));
1063 static void snd_emu10k1_pcm_mixer_notify(struct snd_emu10k1
*emu
, int idx
, int activate
)
1065 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_send_routing
, idx
, activate
);
1066 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_send_volume
, idx
, activate
);
1067 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_attn
, idx
, activate
);
1070 static void snd_emu10k1_pcm_efx_mixer_notify(struct snd_emu10k1
*emu
, int idx
, int activate
)
1072 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_send_routing
, idx
, activate
);
1073 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_send_volume
, idx
, activate
);
1074 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_attn
, idx
, activate
);
1077 static void snd_emu10k1_pcm_free_substream(struct snd_pcm_runtime
*runtime
)
1079 kfree(runtime
->private_data
);
1082 static int snd_emu10k1_efx_playback_close(struct snd_pcm_substream
*substream
)
1084 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1085 struct snd_emu10k1_pcm_mixer
*mix
;
1088 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
1089 mix
= &emu
->efx_pcm_mixer
[i
];
1091 snd_emu10k1_pcm_efx_mixer_notify(emu
, i
, 0);
1096 static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream
*substream
)
1098 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1099 struct snd_emu10k1_pcm
*epcm
;
1100 struct snd_emu10k1_pcm_mixer
*mix
;
1101 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1104 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1108 epcm
->type
= PLAYBACK_EFX
;
1109 epcm
->substream
= substream
;
1111 emu
->pcm_playback_efx_substream
= substream
;
1113 runtime
->private_data
= epcm
;
1114 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1115 runtime
->hw
= snd_emu10k1_efx_playback
;
1117 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
1118 mix
= &emu
->efx_pcm_mixer
[i
];
1119 mix
->send_routing
[0][0] = i
;
1120 memset(&mix
->send_volume
, 0, sizeof(mix
->send_volume
));
1121 mix
->send_volume
[0][0] = 255;
1122 mix
->attn
[0] = 0xffff;
1124 snd_emu10k1_pcm_efx_mixer_notify(emu
, i
, 1);
1129 static int snd_emu10k1_playback_open(struct snd_pcm_substream
*substream
)
1131 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1132 struct snd_emu10k1_pcm
*epcm
;
1133 struct snd_emu10k1_pcm_mixer
*mix
;
1134 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1135 int i
, err
, sample_rate
;
1137 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1141 epcm
->type
= PLAYBACK_EMUVOICE
;
1142 epcm
->substream
= substream
;
1143 runtime
->private_data
= epcm
;
1144 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1145 runtime
->hw
= snd_emu10k1_playback
;
1146 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0) {
1150 if ((err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 256, UINT_MAX
)) < 0) {
1154 if (emu
->card_capabilities
->emu_model
&& emu
->emu1010
.internal_clock
== 0)
1155 sample_rate
= 44100;
1157 sample_rate
= 48000;
1158 err
= snd_pcm_hw_rule_noresample(runtime
, sample_rate
);
1163 mix
= &emu
->pcm_mixer
[substream
->number
];
1164 for (i
= 0; i
< 4; i
++)
1165 mix
->send_routing
[0][i
] = mix
->send_routing
[1][i
] = mix
->send_routing
[2][i
] = i
;
1166 memset(&mix
->send_volume
, 0, sizeof(mix
->send_volume
));
1167 mix
->send_volume
[0][0] = mix
->send_volume
[0][1] =
1168 mix
->send_volume
[1][0] = mix
->send_volume
[2][1] = 255;
1169 mix
->attn
[0] = mix
->attn
[1] = mix
->attn
[2] = 0xffff;
1171 snd_emu10k1_pcm_mixer_notify(emu
, substream
->number
, 1);
1175 static int snd_emu10k1_playback_close(struct snd_pcm_substream
*substream
)
1177 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1178 struct snd_emu10k1_pcm_mixer
*mix
= &emu
->pcm_mixer
[substream
->number
];
1181 snd_emu10k1_pcm_mixer_notify(emu
, substream
->number
, 0);
1185 static int snd_emu10k1_capture_open(struct snd_pcm_substream
*substream
)
1187 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1188 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1189 struct snd_emu10k1_pcm
*epcm
;
1191 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1195 epcm
->type
= CAPTURE_AC97ADC
;
1196 epcm
->substream
= substream
;
1197 epcm
->capture_ipr
= IPR_ADCBUFFULL
|IPR_ADCBUFHALFFULL
;
1198 epcm
->capture_inte
= INTE_ADCBUFENABLE
;
1199 epcm
->capture_ba_reg
= ADCBA
;
1200 epcm
->capture_bs_reg
= ADCBS
;
1201 epcm
->capture_idx_reg
= emu
->audigy
? A_ADCIDX
: ADCIDX
;
1202 runtime
->private_data
= epcm
;
1203 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1204 runtime
->hw
= snd_emu10k1_capture
;
1205 emu
->capture_interrupt
= snd_emu10k1_pcm_ac97adc_interrupt
;
1206 emu
->pcm_capture_substream
= substream
;
1207 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1208 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_capture_rates
);
1212 static int snd_emu10k1_capture_close(struct snd_pcm_substream
*substream
)
1214 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1216 emu
->capture_interrupt
= NULL
;
1217 emu
->pcm_capture_substream
= NULL
;
1221 static int snd_emu10k1_capture_mic_open(struct snd_pcm_substream
*substream
)
1223 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1224 struct snd_emu10k1_pcm
*epcm
;
1225 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1227 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1231 epcm
->type
= CAPTURE_AC97MIC
;
1232 epcm
->substream
= substream
;
1233 epcm
->capture_ipr
= IPR_MICBUFFULL
|IPR_MICBUFHALFFULL
;
1234 epcm
->capture_inte
= INTE_MICBUFENABLE
;
1235 epcm
->capture_ba_reg
= MICBA
;
1236 epcm
->capture_bs_reg
= MICBS
;
1237 epcm
->capture_idx_reg
= emu
->audigy
? A_MICIDX
: MICIDX
;
1238 substream
->runtime
->private_data
= epcm
;
1239 substream
->runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1240 runtime
->hw
= snd_emu10k1_capture
;
1241 runtime
->hw
.rates
= SNDRV_PCM_RATE_8000
;
1242 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 8000;
1243 runtime
->hw
.channels_min
= 1;
1244 emu
->capture_mic_interrupt
= snd_emu10k1_pcm_ac97mic_interrupt
;
1245 emu
->pcm_capture_mic_substream
= substream
;
1246 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1250 static int snd_emu10k1_capture_mic_close(struct snd_pcm_substream
*substream
)
1252 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1254 emu
->capture_interrupt
= NULL
;
1255 emu
->pcm_capture_mic_substream
= NULL
;
1259 static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream
*substream
)
1261 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1262 struct snd_emu10k1_pcm
*epcm
;
1263 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1264 int nefx
= emu
->audigy
? 64 : 32;
1267 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1271 epcm
->type
= CAPTURE_EFX
;
1272 epcm
->substream
= substream
;
1273 epcm
->capture_ipr
= IPR_EFXBUFFULL
|IPR_EFXBUFHALFFULL
;
1274 epcm
->capture_inte
= INTE_EFXBUFENABLE
;
1275 epcm
->capture_ba_reg
= FXBA
;
1276 epcm
->capture_bs_reg
= FXBS
;
1277 epcm
->capture_idx_reg
= FXIDX
;
1278 substream
->runtime
->private_data
= epcm
;
1279 substream
->runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1280 runtime
->hw
= snd_emu10k1_capture_efx
;
1281 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
1282 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 48000;
1283 spin_lock_irq(&emu
->reg_lock
);
1284 if (emu
->card_capabilities
->emu_model
) {
1285 /* Nb. of channels has been increased to 16 */
1287 * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE
1288 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
1289 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
1290 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000
1292 * rate_max = 192000,
1293 * channels_min = 16,
1294 * channels_max = 16,
1295 * Need to add mixer control to fix sample rate
1297 * There are 32 mono channels of 16bits each.
1298 * 24bit Audio uses 2x channels over 16bit
1299 * 96kHz uses 2x channels over 48kHz
1300 * 192kHz uses 4x channels over 48kHz
1301 * So, for 48kHz 24bit, one has 16 channels
1302 * for 96kHz 24bit, one has 8 channels
1303 * for 192kHz 24bit, one has 4 channels
1307 switch (emu
->emu1010
.internal_clock
) {
1310 runtime
->hw
.rates
= SNDRV_PCM_RATE_44100
;
1311 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 44100;
1312 runtime
->hw
.channels_min
=
1313 runtime
->hw
.channels_max
= 16;
1317 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
1318 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 48000;
1319 runtime
->hw
.channels_min
=
1320 runtime
->hw
.channels_max
= 16;
1326 runtime
->hw
.rates
= SNDRV_PCM_RATE_96000
;
1327 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 96000;
1328 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 4;
1332 runtime
->hw
.rates
= SNDRV_PCM_RATE_192000
;
1333 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 192000;
1334 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 2;
1336 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S32_LE
;
1337 /* efx_voices_mask[0] is expected to be zero
1338 * efx_voices_mask[1] is expected to have 32bits set
1341 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 0;
1342 for (idx
= 0; idx
< nefx
; idx
++) {
1343 if (emu
->efx_voices_mask
[idx
/32] & (1 << (idx
%32))) {
1344 runtime
->hw
.channels_min
++;
1345 runtime
->hw
.channels_max
++;
1349 epcm
->capture_cr_val
= emu
->efx_voices_mask
[0];
1350 epcm
->capture_cr_val2
= emu
->efx_voices_mask
[1];
1351 spin_unlock_irq(&emu
->reg_lock
);
1352 emu
->capture_efx_interrupt
= snd_emu10k1_pcm_efx_interrupt
;
1353 emu
->pcm_capture_efx_substream
= substream
;
1354 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1358 static int snd_emu10k1_capture_efx_close(struct snd_pcm_substream
*substream
)
1360 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1362 emu
->capture_interrupt
= NULL
;
1363 emu
->pcm_capture_efx_substream
= NULL
;
1367 static struct snd_pcm_ops snd_emu10k1_playback_ops
= {
1368 .open
= snd_emu10k1_playback_open
,
1369 .close
= snd_emu10k1_playback_close
,
1370 .ioctl
= snd_pcm_lib_ioctl
,
1371 .hw_params
= snd_emu10k1_playback_hw_params
,
1372 .hw_free
= snd_emu10k1_playback_hw_free
,
1373 .prepare
= snd_emu10k1_playback_prepare
,
1374 .trigger
= snd_emu10k1_playback_trigger
,
1375 .pointer
= snd_emu10k1_playback_pointer
,
1376 .page
= snd_pcm_sgbuf_ops_page
,
1379 static struct snd_pcm_ops snd_emu10k1_capture_ops
= {
1380 .open
= snd_emu10k1_capture_open
,
1381 .close
= snd_emu10k1_capture_close
,
1382 .ioctl
= snd_pcm_lib_ioctl
,
1383 .hw_params
= snd_emu10k1_capture_hw_params
,
1384 .hw_free
= snd_emu10k1_capture_hw_free
,
1385 .prepare
= snd_emu10k1_capture_prepare
,
1386 .trigger
= snd_emu10k1_capture_trigger
,
1387 .pointer
= snd_emu10k1_capture_pointer
,
1391 static struct snd_pcm_ops snd_emu10k1_efx_playback_ops
= {
1392 .open
= snd_emu10k1_efx_playback_open
,
1393 .close
= snd_emu10k1_efx_playback_close
,
1394 .ioctl
= snd_pcm_lib_ioctl
,
1395 .hw_params
= snd_emu10k1_playback_hw_params
,
1396 .hw_free
= snd_emu10k1_efx_playback_hw_free
,
1397 .prepare
= snd_emu10k1_efx_playback_prepare
,
1398 .trigger
= snd_emu10k1_efx_playback_trigger
,
1399 .pointer
= snd_emu10k1_efx_playback_pointer
,
1400 .page
= snd_pcm_sgbuf_ops_page
,
1403 int snd_emu10k1_pcm(struct snd_emu10k1
*emu
, int device
)
1405 struct snd_pcm
*pcm
;
1406 struct snd_pcm_substream
*substream
;
1409 if ((err
= snd_pcm_new(emu
->card
, "emu10k1", device
, 32, 1, &pcm
)) < 0)
1412 pcm
->private_data
= emu
;
1414 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_playback_ops
);
1415 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_ops
);
1417 pcm
->info_flags
= 0;
1418 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1419 strcpy(pcm
->name
, "ADC Capture/Standard PCM Playback");
1422 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
1423 if ((err
= snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024)) < 0)
1426 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
; substream
; substream
= substream
->next
)
1427 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);
1432 int snd_emu10k1_pcm_multi(struct snd_emu10k1
*emu
, int device
)
1434 struct snd_pcm
*pcm
;
1435 struct snd_pcm_substream
*substream
;
1438 if ((err
= snd_pcm_new(emu
->card
, "emu10k1", device
, 1, 0, &pcm
)) < 0)
1441 pcm
->private_data
= emu
;
1443 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_efx_playback_ops
);
1445 pcm
->info_flags
= 0;
1446 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1447 strcpy(pcm
->name
, "Multichannel Playback");
1448 emu
->pcm_multi
= pcm
;
1450 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
1451 if ((err
= snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024)) < 0)
1458 static struct snd_pcm_ops snd_emu10k1_capture_mic_ops
= {
1459 .open
= snd_emu10k1_capture_mic_open
,
1460 .close
= snd_emu10k1_capture_mic_close
,
1461 .ioctl
= snd_pcm_lib_ioctl
,
1462 .hw_params
= snd_emu10k1_capture_hw_params
,
1463 .hw_free
= snd_emu10k1_capture_hw_free
,
1464 .prepare
= snd_emu10k1_capture_prepare
,
1465 .trigger
= snd_emu10k1_capture_trigger
,
1466 .pointer
= snd_emu10k1_capture_pointer
,
1469 int snd_emu10k1_pcm_mic(struct snd_emu10k1
*emu
, int device
)
1471 struct snd_pcm
*pcm
;
1474 if ((err
= snd_pcm_new(emu
->card
, "emu10k1 mic", device
, 0, 1, &pcm
)) < 0)
1477 pcm
->private_data
= emu
;
1479 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_mic_ops
);
1481 pcm
->info_flags
= 0;
1482 strcpy(pcm
->name
, "Mic Capture");
1485 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);
1490 static int snd_emu10k1_pcm_efx_voices_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1492 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1493 int nefx
= emu
->audigy
? 64 : 32;
1494 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1495 uinfo
->count
= nefx
;
1496 uinfo
->value
.integer
.min
= 0;
1497 uinfo
->value
.integer
.max
= 1;
1501 static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1503 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1504 int nefx
= emu
->audigy
? 64 : 32;
1507 spin_lock_irq(&emu
->reg_lock
);
1508 for (idx
= 0; idx
< nefx
; idx
++)
1509 ucontrol
->value
.integer
.value
[idx
] = (emu
->efx_voices_mask
[idx
/ 32] & (1 << (idx
% 32))) ? 1 : 0;
1510 spin_unlock_irq(&emu
->reg_lock
);
1514 static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1516 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1517 unsigned int nval
[2], bits
;
1518 int nefx
= emu
->audigy
? 64 : 32;
1519 int nefxb
= emu
->audigy
? 7 : 6;
1522 nval
[0] = nval
[1] = 0;
1523 for (idx
= 0, bits
= 0; idx
< nefx
; idx
++)
1524 if (ucontrol
->value
.integer
.value
[idx
]) {
1525 nval
[idx
/ 32] |= 1 << (idx
% 32);
1529 for (idx
= 0; idx
< nefxb
; idx
++)
1530 if (1 << idx
== bits
)
1536 spin_lock_irq(&emu
->reg_lock
);
1537 change
= (nval
[0] != emu
->efx_voices_mask
[0]) ||
1538 (nval
[1] != emu
->efx_voices_mask
[1]);
1539 emu
->efx_voices_mask
[0] = nval
[0];
1540 emu
->efx_voices_mask
[1] = nval
[1];
1541 spin_unlock_irq(&emu
->reg_lock
);
1545 static struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask
= {
1546 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1547 .name
= "Captured FX8010 Outputs",
1548 .info
= snd_emu10k1_pcm_efx_voices_mask_info
,
1549 .get
= snd_emu10k1_pcm_efx_voices_mask_get
,
1550 .put
= snd_emu10k1_pcm_efx_voices_mask_put
1553 static struct snd_pcm_ops snd_emu10k1_capture_efx_ops
= {
1554 .open
= snd_emu10k1_capture_efx_open
,
1555 .close
= snd_emu10k1_capture_efx_close
,
1556 .ioctl
= snd_pcm_lib_ioctl
,
1557 .hw_params
= snd_emu10k1_capture_hw_params
,
1558 .hw_free
= snd_emu10k1_capture_hw_free
,
1559 .prepare
= snd_emu10k1_capture_prepare
,
1560 .trigger
= snd_emu10k1_capture_trigger
,
1561 .pointer
= snd_emu10k1_capture_pointer
,
1567 #define INITIAL_TRAM_SHIFT 14
1568 #define INITIAL_TRAM_POS(size) ((((size) / 2) - INITIAL_TRAM_SHIFT) - 1)
1570 static void snd_emu10k1_fx8010_playback_irq(struct snd_emu10k1
*emu
, void *private_data
)
1572 struct snd_pcm_substream
*substream
= private_data
;
1573 snd_pcm_period_elapsed(substream
);
1576 static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left
,
1577 unsigned short *dst_right
,
1578 unsigned short *src
,
1580 unsigned int tram_shift
)
1583 dev_dbg(emu->card->dev,
1584 "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
1585 "src = 0x%p, count = 0x%x\n",
1586 dst_left, dst_right, src, count);
1588 if ((tram_shift
& 1) == 0) {
1590 *dst_left
-- = *src
++;
1591 *dst_right
-- = *src
++;
1595 *dst_right
-- = *src
++;
1596 *dst_left
-- = *src
++;
1601 static void fx8010_pb_trans_copy(struct snd_pcm_substream
*substream
,
1602 struct snd_pcm_indirect
*rec
, size_t bytes
)
1604 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1605 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1606 unsigned int tram_size
= pcm
->buffer_size
;
1607 unsigned short *src
= (unsigned short *)(substream
->runtime
->dma_area
+ rec
->sw_data
);
1608 unsigned int frames
= bytes
>> 2, count
;
1609 unsigned int tram_pos
= pcm
->tram_pos
;
1610 unsigned int tram_shift
= pcm
->tram_shift
;
1612 while (frames
> tram_pos
) {
1613 count
= tram_pos
+ 1;
1614 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
,
1615 (unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
+ tram_size
/ 2,
1616 src
, count
, tram_shift
);
1619 tram_pos
= (tram_size
/ 2) - 1;
1622 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
,
1623 (unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
+ tram_size
/ 2,
1624 src
, frames
, tram_shift
);
1626 pcm
->tram_pos
= tram_pos
;
1627 pcm
->tram_shift
= tram_shift
;
1630 static int snd_emu10k1_fx8010_playback_transfer(struct snd_pcm_substream
*substream
)
1632 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1633 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1635 snd_pcm_indirect_playback_transfer(substream
, &pcm
->pcm_rec
, fx8010_pb_trans_copy
);
1639 static int snd_emu10k1_fx8010_playback_hw_params(struct snd_pcm_substream
*substream
,
1640 struct snd_pcm_hw_params
*hw_params
)
1642 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
1645 static int snd_emu10k1_fx8010_playback_hw_free(struct snd_pcm_substream
*substream
)
1647 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1648 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1651 for (i
= 0; i
< pcm
->channels
; i
++)
1652 snd_emu10k1_ptr_write(emu
, TANKMEMADDRREGBASE
+ 0x80 + pcm
->etram
[i
], 0, 0);
1653 snd_pcm_lib_free_pages(substream
);
1657 static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream
*substream
)
1659 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1660 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1661 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1665 dev_dbg(emu->card->dev, "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
1666 "buffer_size = 0x%x (0x%x)\n",
1667 emu->fx8010.etram_pages, runtime->dma_area,
1668 runtime->buffer_size, runtime->buffer_size << 2);
1670 memset(&pcm
->pcm_rec
, 0, sizeof(pcm
->pcm_rec
));
1671 pcm
->pcm_rec
.hw_buffer_size
= pcm
->buffer_size
* 2; /* byte size */
1672 pcm
->pcm_rec
.sw_buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
1673 pcm
->tram_pos
= INITIAL_TRAM_POS(pcm
->buffer_size
);
1674 pcm
->tram_shift
= 0;
1675 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_running
, 0, 0); /* reset */
1676 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 0); /* reset */
1677 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_size
, 0, runtime
->buffer_size
);
1678 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_ptr
, 0, 0); /* reset ptr number */
1679 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_count
, 0, runtime
->period_size
);
1680 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_tmpcount
, 0, runtime
->period_size
);
1681 for (i
= 0; i
< pcm
->channels
; i
++)
1682 snd_emu10k1_ptr_write(emu
, TANKMEMADDRREGBASE
+ 0x80 + pcm
->etram
[i
], 0, (TANKMEMADDRREG_READ
|TANKMEMADDRREG_ALIGN
) + i
* (runtime
->buffer_size
/ pcm
->channels
));
1686 static int snd_emu10k1_fx8010_playback_trigger(struct snd_pcm_substream
*substream
, int cmd
)
1688 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1689 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1692 spin_lock(&emu
->reg_lock
);
1694 case SNDRV_PCM_TRIGGER_START
:
1696 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1697 case SNDRV_PCM_TRIGGER_RESUME
:
1698 #ifdef EMU10K1_SET_AC3_IEC958
1701 for (i
= 0; i
< 3; i
++) {
1703 bits
= SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
1704 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
| SPCS_GENERATIONSTATUS
|
1705 0x00001200 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
| SPCS_NOTAUDIODATA
;
1706 snd_emu10k1_ptr_write(emu
, SPCS0
+ i
, 0, bits
);
1710 result
= snd_emu10k1_fx8010_register_irq_handler(emu
, snd_emu10k1_fx8010_playback_irq
, pcm
->gpr_running
, substream
, &pcm
->irq
);
1713 snd_emu10k1_fx8010_playback_transfer(substream
); /* roll the ball */
1714 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 1);
1716 case SNDRV_PCM_TRIGGER_STOP
:
1717 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1718 case SNDRV_PCM_TRIGGER_SUSPEND
:
1719 snd_emu10k1_fx8010_unregister_irq_handler(emu
, pcm
->irq
); pcm
->irq
= NULL
;
1720 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 0);
1721 pcm
->tram_pos
= INITIAL_TRAM_POS(pcm
->buffer_size
);
1722 pcm
->tram_shift
= 0;
1729 spin_unlock(&emu
->reg_lock
);
1733 static snd_pcm_uframes_t
snd_emu10k1_fx8010_playback_pointer(struct snd_pcm_substream
*substream
)
1735 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1736 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1737 size_t ptr
; /* byte pointer */
1739 if (!snd_emu10k1_ptr_read(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0))
1741 ptr
= snd_emu10k1_ptr_read(emu
, emu
->gpr_base
+ pcm
->gpr_ptr
, 0) << 2;
1742 return snd_pcm_indirect_playback_pointer(substream
, &pcm
->pcm_rec
, ptr
);
1745 static struct snd_pcm_hardware snd_emu10k1_fx8010_playback
=
1747 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1748 SNDRV_PCM_INFO_RESUME
|
1749 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE
),
1750 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
1751 .rates
= SNDRV_PCM_RATE_48000
,
1756 .buffer_bytes_max
= (128*1024),
1757 .period_bytes_min
= 1024,
1758 .period_bytes_max
= (128*1024),
1760 .periods_max
= 1024,
1764 static int snd_emu10k1_fx8010_playback_open(struct snd_pcm_substream
*substream
)
1766 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1767 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1768 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1770 runtime
->hw
= snd_emu10k1_fx8010_playback
;
1771 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= pcm
->channels
;
1772 runtime
->hw
.period_bytes_max
= (pcm
->buffer_size
* 2) / 2;
1773 spin_lock_irq(&emu
->reg_lock
);
1774 if (pcm
->valid
== 0) {
1775 spin_unlock_irq(&emu
->reg_lock
);
1779 spin_unlock_irq(&emu
->reg_lock
);
1783 static int snd_emu10k1_fx8010_playback_close(struct snd_pcm_substream
*substream
)
1785 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1786 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1788 spin_lock_irq(&emu
->reg_lock
);
1790 spin_unlock_irq(&emu
->reg_lock
);
1794 static struct snd_pcm_ops snd_emu10k1_fx8010_playback_ops
= {
1795 .open
= snd_emu10k1_fx8010_playback_open
,
1796 .close
= snd_emu10k1_fx8010_playback_close
,
1797 .ioctl
= snd_pcm_lib_ioctl
,
1798 .hw_params
= snd_emu10k1_fx8010_playback_hw_params
,
1799 .hw_free
= snd_emu10k1_fx8010_playback_hw_free
,
1800 .prepare
= snd_emu10k1_fx8010_playback_prepare
,
1801 .trigger
= snd_emu10k1_fx8010_playback_trigger
,
1802 .pointer
= snd_emu10k1_fx8010_playback_pointer
,
1803 .ack
= snd_emu10k1_fx8010_playback_transfer
,
1806 int snd_emu10k1_pcm_efx(struct snd_emu10k1
*emu
, int device
)
1808 struct snd_pcm
*pcm
;
1809 struct snd_kcontrol
*kctl
;
1812 if ((err
= snd_pcm_new(emu
->card
, "emu10k1 efx", device
, 8, 1, &pcm
)) < 0)
1815 pcm
->private_data
= emu
;
1817 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_fx8010_playback_ops
);
1818 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_efx_ops
);
1820 pcm
->info_flags
= 0;
1821 strcpy(pcm
->name
, "Multichannel Capture/PT Playback");
1824 /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs
1828 /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */
1830 emu
->efx_voices_mask
[0] = 0;
1831 if (emu
->card_capabilities
->emu_model
)
1832 /* Pavel Hofman - 32 voices will be used for
1833 * capture (write mode) -
1834 * each bit = corresponding voice
1836 emu
->efx_voices_mask
[1] = 0xffffffff;
1838 emu
->efx_voices_mask
[1] = 0xffff;
1840 emu
->efx_voices_mask
[0] = 0xffff0000;
1841 emu
->efx_voices_mask
[1] = 0;
1843 /* For emu1010, the control has to set 32 upper bits (voices)
1844 * out of the 64 bits (voices) to true for the 16-channels capture
1845 * to work correctly. Correct A_FXWC2 initial value (0xffffffff)
1846 * is already defined but the snd_emu10k1_pcm_efx_voices_mask
1847 * control can override this register's value.
1849 kctl
= snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask
, emu
);
1852 kctl
->id
.device
= device
;
1853 snd_ctl_add(emu
->card
, kctl
);
1855 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(emu
->pci
), 64*1024, 64*1024);