29 #include <linux/pci.h>
31 #include <linux/slab.h>
32 #include <linux/time.h>
37 static void snd_emu10k1_pcm_interrupt(
struct snd_emu10k1 *
emu,
38 struct snd_emu10k1_voice *
voice)
42 if ((epcm = voice->epcm) ==
NULL)
44 if (epcm->substream ==
NULL)
48 epcm->substream->runtime->hw->pointer(emu, epcm->substream),
49 snd_pcm_lib_period_bytes(epcm->substream),
50 snd_pcm_lib_buffer_bytes(epcm->substream));
55 static void snd_emu10k1_pcm_ac97adc_interrupt(
struct snd_emu10k1 *emu,
59 if (status & IPR_ADCBUFHALFFULL) {
60 if (emu->pcm_capture_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
67 static void snd_emu10k1_pcm_ac97mic_interrupt(
struct snd_emu10k1 *emu,
71 if (status & IPR_MICBUFHALFFULL) {
72 if (emu->pcm_capture_mic_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
79 static void snd_emu10k1_pcm_efx_interrupt(
struct snd_emu10k1 *emu,
83 if (status & IPR_EFXBUFHALFFULL) {
84 if (emu->pcm_capture_efx_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
102 ptr -= epcm->ccca_start_addr;
108 static int snd_emu10k1_pcm_channel_alloc(
struct snd_emu10k1_pcm * epcm,
int voices)
112 if (epcm->voices[1] !=
NULL && voices < 2) {
114 epcm->voices[1] =
NULL;
116 for (i = 0; i < voices; i++) {
117 if (epcm->voices[i] ==
NULL)
123 for (i = 0; i <
ARRAY_SIZE(epcm->voices); i++) {
124 if (epcm->voices[i]) {
126 epcm->voices[
i] =
NULL;
130 epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
136 epcm->voices[0]->epcm = epcm;
138 for (i = 1; i < voices; i++) {
139 epcm->voices[
i] = &epcm->emu->voices[epcm->voices[0]->number +
i];
140 epcm->voices[
i]->epcm = epcm;
143 if (epcm->extra ==
NULL) {
145 epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
154 for (i = 0; i < voices; i++) {
156 epcm->voices[
i] =
NULL;
160 epcm->extra->epcm = epcm;
161 epcm->extra->interrupt = snd_emu10k1_pcm_interrupt;
166 static unsigned int capture_period_sizes[31] = {
168 384*2, 448*2, 512*2, 640*2,
169 384*4, 448*4, 512*4, 640*4,
170 384*8, 448*8, 512*8, 640*8,
171 384*16, 448*16, 512*16, 640*16,
172 384*32, 448*32, 512*32, 640*32,
173 384*64, 448*64, 512*64, 640*64,
174 384*128,448*128,512*128
179 .list = capture_period_sizes,
183 static unsigned int capture_rates[8] = {
184 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
189 .list = capture_rates,
193 static unsigned int snd_emu10k1_capture_rate_reg(
unsigned int rate)
196 case 8000:
return ADCCR_SAMPLERATE_8;
197 case 11025:
return ADCCR_SAMPLERATE_11;
198 case 16000:
return ADCCR_SAMPLERATE_16;
199 case 22050:
return ADCCR_SAMPLERATE_22;
200 case 24000:
return ADCCR_SAMPLERATE_24;
201 case 32000:
return ADCCR_SAMPLERATE_32;
202 case 44100:
return ADCCR_SAMPLERATE_44;
203 case 48000:
return ADCCR_SAMPLERATE_48;
206 return ADCCR_SAMPLERATE_8;
210 static unsigned int snd_emu10k1_audigy_capture_rate_reg(
unsigned int rate)
213 case 8000:
return A_ADCCR_SAMPLERATE_8;
214 case 11025:
return A_ADCCR_SAMPLERATE_11;
215 case 12000:
return A_ADCCR_SAMPLERATE_12;
216 case 16000:
return ADCCR_SAMPLERATE_16;
217 case 22050:
return ADCCR_SAMPLERATE_22;
218 case 24000:
return ADCCR_SAMPLERATE_24;
219 case 32000:
return ADCCR_SAMPLERATE_32;
220 case 44100:
return ADCCR_SAMPLERATE_44;
221 case 48000:
return ADCCR_SAMPLERATE_48;
224 return A_ADCCR_SAMPLERATE_8;
228 static unsigned int emu10k1_calc_pitch_target(
unsigned int rate)
230 unsigned int pitch_target;
232 pitch_target = (rate << 8) / 375;
233 pitch_target = (pitch_target >> 1) + (pitch_target & 1);
237 #define PITCH_48000 0x00004000
238 #define PITCH_96000 0x00008000
239 #define PITCH_85000 0x00007155
240 #define PITCH_80726 0x00006ba2
241 #define PITCH_67882 0x00005a82
242 #define PITCH_57081 0x00004c1c
244 static unsigned int emu10k1_select_interprom(
unsigned int pitch_target)
247 return CCCA_INTERPROM_0;
249 return CCCA_INTERPROM_1;
251 return CCCA_INTERPROM_0;
253 return CCCA_INTERPROM_6;
255 return CCCA_INTERPROM_5;
257 return CCCA_INTERPROM_4;
259 return CCCA_INTERPROM_3;
261 return CCCA_INTERPROM_2;
272 static inline int emu10k1_ccis(
int stereo,
int w_16)
275 return stereo ? 24 : 26;
277 return stereo ? 24*2 : 26*2;
281 static void snd_emu10k1_pcm_init_voice(
struct snd_emu10k1 *emu,
282 int master,
int extra,
283 struct snd_emu10k1_voice *evoice,
285 unsigned int end_addr,
286 struct snd_emu10k1_pcm_mixer *
mix)
290 unsigned int silent_page,
tmp;
291 int voice, stereo, w_16;
292 unsigned char attn, send_amount[8];
293 unsigned char send_routing[8];
295 unsigned int pitch_target;
298 voice = evoice->number;
302 if (!extra && stereo) {
316 memset(send_routing, 0,
sizeof(send_routing));
321 memset(send_amount, 0,
sizeof(send_amount));
324 tmp = stereo ? (master ? 1 : 2) : 0;
325 memcpy(send_routing, &mix->send_routing[tmp][0], 8);
326 memcpy(send_amount, &mix->send_volume[tmp][0], 8);
329 ccis = emu10k1_ccis(stereo, w_16);
332 evoice->epcm->ccca_start_addr = start_addr + ccis;
335 end_addr += ccis + emu->delay_pcm_irq;
337 if (stereo && !extra) {
348 snd_emu10k1_compose_audigy_fxrt1(send_routing));
350 snd_emu10k1_compose_audigy_fxrt2(send_routing));
352 ((
unsigned int)send_amount[4] << 24) |
353 ((
unsigned int)send_amount[5] << 16) |
354 ((
unsigned int)send_amount[6] << 8) |
355 (
unsigned int)send_amount[7]);
358 snd_emu10k1_compose_send_routing(send_routing));
364 (start_addr + (extra ? emu->delay_pcm_irq : 0)) |
365 (send_amount[2] << 24));
366 if (emu->card_capabilities->emu_model)
369 pitch_target = emu10k1_calc_pitch_target(runtime->
rate);
372 emu10k1_select_interprom(pitch_target) |
373 (w_16 ? 0 : CCCA_8BITSELECT));
376 emu10k1_select_interprom(pitch_target) |
377 (w_16 ? 0 : CCCA_8BITSELECT));
382 silent_page = ((
unsigned int)emu->silent_page.addr << 1) | MAP_PTI_MASK;
404 spin_unlock_irqrestore(&emu->reg_lock, flags);
415 if ((err = snd_emu10k1_pcm_channel_alloc(epcm,
params_channels(hw_params))) < 0)
421 if (epcm->memblk !=
NULL)
424 epcm->start_addr = 0;
427 mapped = ((
struct snd_emu10k1_memblk *)epcm->memblk)->mapped_page;
448 if (epcm->voices[1]) {
450 epcm->voices[1] =
NULL;
452 if (epcm->voices[0]) {
454 epcm->voices[0] =
NULL;
459 epcm->start_addr = 0;
479 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
480 if (epcm->voices[i]) {
482 epcm->voices[
i] =
NULL;
488 epcm->start_addr = 0;
501 start_addr = epcm->start_addr;
502 end_addr = snd_pcm_lib_period_bytes(substream);
508 snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
509 start_addr, end_addr,
NULL);
510 start_addr = epcm->start_addr;
511 end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
512 snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
513 start_addr, end_addr,
514 &emu->pcm_mixer[substream->
number]);
516 snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[1],
517 start_addr, end_addr,
518 &emu->pcm_mixer[substream->
number]);
528 unsigned int channel_size;
531 start_addr = epcm->start_addr;
532 end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
537 channel_size = ( end_addr -
start_addr ) / NUM_EFX_PLAYBACK;
539 snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
540 start_addr, start_addr + (channel_size / 2),
NULL);
543 snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
544 start_addr, start_addr + channel_size,
545 &emu->efx_pcm_mixer[0]);
547 start_addr += channel_size;
548 for (i = 1; i < NUM_EFX_PLAYBACK; i++) {
549 snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[i],
550 start_addr, start_addr + channel_size,
551 &emu->efx_pcm_mixer[i]);
552 start_addr += channel_size;
571 .period_bytes_min = 64,
572 .period_bytes_max = (64*1024),
598 switch (epcm->type) {
599 case CAPTURE_AC97ADC:
613 epcm->capture_bufsize = snd_pcm_lib_buffer_bytes(substream);
614 epcm->capture_bs_val = 0;
615 for (idx = 0; idx < 31; idx++) {
616 if (capture_period_sizes[idx] == epcm->capture_bufsize) {
617 epcm->capture_bs_val = idx + 1;
621 if (epcm->capture_bs_val == 0) {
623 epcm->capture_bs_val++;
625 if (epcm->type == CAPTURE_AC97ADC) {
626 epcm->capture_cr_val = emu->audigy ? A_ADCCR_LCHANENABLE : ADCCR_LCHANENABLE;
628 epcm->capture_cr_val |= emu->audigy ? A_ADCCR_RCHANENABLE : ADCCR_RCHANENABLE;
629 epcm->capture_cr_val |= emu->audigy ?
630 snd_emu10k1_audigy_capture_rate_reg(runtime->
rate) :
631 snd_emu10k1_capture_rate_reg(runtime->rate);
636 static void snd_emu10k1_playback_invalidate_cache(
struct snd_emu10k1 *emu,
int extra,
struct snd_emu10k1_voice *evoice)
639 unsigned int voice, stereo,
i, ccis, cra = 64,
cs,
sample;
643 runtime = evoice->epcm->substream->runtime;
644 voice = evoice->number;
645 stereo = (!extra && runtime->
channels == 2);
647 ccis = emu10k1_ccis(stereo, sample == 0);
649 cs = (sample == 0) ? (32-ccis) : (64-ccis+1) >> 1;
650 if (
cs > 16)
cs = 16;
651 for (i = 0; i <
cs; i++) {
671 static void snd_emu10k1_playback_prepare_voice(
struct snd_emu10k1 *emu,
struct snd_emu10k1_voice *evoice,
672 int master,
int extra,
673 struct snd_emu10k1_pcm_mixer *mix)
677 unsigned int attn, vattn;
678 unsigned int voice,
tmp;
682 substream = evoice->epcm->substream;
684 voice = evoice->number;
686 attn = extra ? 0 : 0x00ff;
687 tmp = runtime->
channels == 2 ? (master ? 1 : 2) : 0;
688 vattn = mix !=
NULL ? (mix->attn[
tmp] << 16) : 0;
696 static void snd_emu10k1_playback_trigger_voice(
struct snd_emu10k1 *emu,
struct snd_emu10k1_voice *evoice,
int master,
int extra)
700 unsigned int voice, pitch, pitch_target;
704 substream = evoice->epcm->substream;
706 voice = evoice->number;
709 if (emu->card_capabilities->emu_model)
712 pitch_target = emu10k1_calc_pitch_target(runtime->
rate);
714 if (master || evoice->epcm->type == PLAYBACK_EFX)
721 static void snd_emu10k1_playback_stop_voice(
struct snd_emu10k1 *emu,
struct snd_emu10k1_voice *evoice)
727 voice = evoice->number;
737 static inline void snd_emu10k1_playback_mangle_extra(
struct snd_emu10k1 *emu,
742 unsigned int ptr, period_pos;
750 ptr |= epcm->ccca_start_addr + period_pos;
760 struct snd_emu10k1_pcm_mixer *
mix;
767 spin_lock(&emu->reg_lock);
770 snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);
771 snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[0]);
776 snd_emu10k1_playback_mangle_extra(emu, epcm, substream, runtime);
777 mix = &emu->pcm_mixer[substream->
number];
778 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 1, 0, mix);
779 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[1], 0, 0, mix);
780 snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1,
NULL);
781 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 1, 0);
782 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[1], 0, 0);
783 snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
790 snd_emu10k1_playback_stop_voice(emu, epcm->voices[0]);
791 snd_emu10k1_playback_stop_voice(emu, epcm->voices[1]);
792 snd_emu10k1_playback_stop_voice(emu, epcm->extra);
798 spin_unlock(&emu->reg_lock);
810 spin_lock(&emu->reg_lock);
815 outl(epcm->capture_ipr, emu->port +
IPR);
821 switch (epcm->type) {
822 case CAPTURE_AC97ADC:
829 snd_printdd(
"cr_val=0x%x, cr_val2=0x%x\n", epcm->capture_cr_val, epcm->capture_cr_val2);
844 outl(epcm->capture_ipr, emu->port +
IPR);
846 switch (epcm->type) {
847 case CAPTURE_AC97ADC:
864 spin_unlock(&emu->reg_lock);
880 ptr -= epcm->ccca_start_addr;
883 if (ptr < epcm->ccca_start_addr)
884 ptr += runtime->
buffer_size - epcm->ccca_start_addr;
886 ptr -= epcm->ccca_start_addr;
910 spin_lock(&emu->reg_lock);
914 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
915 snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[i]);
917 snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);
922 snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1,
NULL);
923 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 0, 0,
924 &emu->efx_pcm_mixer[0]);
925 for (i = 1; i < NUM_EFX_PLAYBACK; i++)
926 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[i], 0, 0,
927 &emu->efx_pcm_mixer[i]);
928 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 0, 0);
929 snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
930 for (i = 1; i < NUM_EFX_PLAYBACK; i++)
931 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[i], 0, 0);
938 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
939 snd_emu10k1_playback_stop_voice(emu, epcm->voices[i]);
941 snd_emu10k1_playback_stop_voice(emu, epcm->extra);
947 spin_unlock(&emu->reg_lock);
961 if (epcm->first_ptr) {
966 return bytes_to_frames(runtime, ptr);
986 .period_bytes_min = 64,
987 .period_bytes_max = (128*1024),
1010 .period_bytes_min = 384,
1011 .period_bytes_max = (64*1024),
1032 .period_bytes_min = 384,
1033 .period_bytes_max = (64*1024),
1043 static void snd_emu10k1_pcm_mixer_notify1(
struct snd_emu10k1 *emu,
struct snd_kcontrol *kctl,
int idx,
int activate)
1055 snd_ctl_build_ioff(&
id, kctl, idx));
1058 static void snd_emu10k1_pcm_mixer_notify(
struct snd_emu10k1 *emu,
int idx,
int activate)
1060 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_routing, idx, activate);
1061 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_volume, idx, activate);
1062 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_attn, idx, activate);
1065 static void snd_emu10k1_pcm_efx_mixer_notify(
struct snd_emu10k1 *emu,
int idx,
int activate)
1067 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_routing, idx, activate);
1068 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_volume, idx, activate);
1069 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_attn, idx, activate);
1072 static void snd_emu10k1_pcm_free_substream(
struct snd_pcm_runtime *runtime)
1080 struct snd_emu10k1_pcm_mixer *
mix;
1083 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
1084 mix = &emu->efx_pcm_mixer[
i];
1086 snd_emu10k1_pcm_efx_mixer_notify(emu, i, 0);
1095 struct snd_emu10k1_pcm_mixer *
mix;
1103 epcm->type = PLAYBACK_EFX;
1104 epcm->substream = substream;
1106 emu->pcm_playback_efx_substream = substream;
1109 runtime->
private_free = snd_emu10k1_pcm_free_substream;
1110 runtime->
hw = snd_emu10k1_efx_playback;
1112 for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
1113 mix = &emu->efx_pcm_mixer[
i];
1114 mix->send_routing[0][0] =
i;
1115 memset(&mix->send_volume, 0,
sizeof(mix->send_volume));
1116 mix->send_volume[0][0] = 255;
1117 mix->attn[0] = 0xffff;
1119 snd_emu10k1_pcm_efx_mixer_notify(emu, i, 1);
1128 struct snd_emu10k1_pcm_mixer *
mix;
1136 epcm->type = PLAYBACK_EMUVOICE;
1137 epcm->substream = substream;
1139 runtime->
private_free = snd_emu10k1_pcm_free_substream;
1140 runtime->
hw = snd_emu10k1_playback;
1154 mix = &emu->pcm_mixer[substream->
number];
1155 for (i = 0; i < 4; i++)
1156 mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i;
1157 memset(&mix->send_volume, 0,
sizeof(mix->send_volume));
1158 mix->send_volume[0][0] = mix->send_volume[0][1] =
1159 mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
1160 mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
1162 snd_emu10k1_pcm_mixer_notify(emu, substream->
number, 1);
1169 struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[substream->
number];
1172 snd_emu10k1_pcm_mixer_notify(emu, substream->
number, 0);
1186 epcm->type = CAPTURE_AC97ADC;
1187 epcm->substream = substream;
1188 epcm->capture_ipr = IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL;
1189 epcm->capture_inte = INTE_ADCBUFENABLE;
1190 epcm->capture_ba_reg = ADCBA;
1191 epcm->capture_bs_reg = ADCBS;
1192 epcm->capture_idx_reg = emu->audigy ? A_ADCIDX : ADCIDX;
1194 runtime->
private_free = snd_emu10k1_pcm_free_substream;
1195 runtime->
hw = snd_emu10k1_capture;
1196 emu->capture_interrupt = snd_emu10k1_pcm_ac97adc_interrupt;
1197 emu->pcm_capture_substream = substream;
1207 emu->capture_interrupt =
NULL;
1208 emu->pcm_capture_substream =
NULL;
1222 epcm->type = CAPTURE_AC97MIC;
1223 epcm->substream = substream;
1224 epcm->capture_ipr = IPR_MICBUFFULL|IPR_MICBUFHALFFULL;
1225 epcm->capture_inte = INTE_MICBUFENABLE;
1226 epcm->capture_ba_reg = MICBA;
1227 epcm->capture_bs_reg = MICBS;
1228 epcm->capture_idx_reg = emu->audigy ? A_MICIDX : MICIDX;
1229 substream->
runtime->private_data = epcm;
1230 substream->
runtime->private_free = snd_emu10k1_pcm_free_substream;
1231 runtime->
hw = snd_emu10k1_capture;
1233 runtime->
hw.rate_min = runtime->
hw.rate_max = 8000;
1234 runtime->
hw.channels_min = 1;
1235 emu->capture_mic_interrupt = snd_emu10k1_pcm_ac97mic_interrupt;
1236 emu->pcm_capture_mic_substream = substream;
1245 emu->capture_interrupt =
NULL;
1246 emu->pcm_capture_mic_substream =
NULL;
1255 int nefx = emu->audigy ? 64 : 32;
1262 epcm->type = CAPTURE_EFX;
1263 epcm->substream = substream;
1264 epcm->capture_ipr = IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL;
1265 epcm->capture_inte = INTE_EFXBUFENABLE;
1266 epcm->capture_ba_reg = FXBA;
1267 epcm->capture_bs_reg = FXBS;
1268 epcm->capture_idx_reg = FXIDX;
1269 substream->
runtime->private_data = epcm;
1270 substream->
runtime->private_free = snd_emu10k1_pcm_free_substream;
1271 runtime->
hw = snd_emu10k1_capture_efx;
1273 runtime->
hw.rate_min = runtime->
hw.rate_max = 48000;
1274 spin_lock_irq(&emu->reg_lock);
1275 if (emu->card_capabilities->emu_model) {
1298 switch (emu->emu1010.internal_clock) {
1302 runtime->
hw.rate_min = runtime->
hw.rate_max = 44100;
1303 runtime->
hw.channels_min =
1304 runtime->
hw.channels_max = 16;
1309 runtime->
hw.rate_min = runtime->
hw.rate_max = 48000;
1310 runtime->
hw.channels_min =
1311 runtime->
hw.channels_max = 16;
1318 runtime->
hw.rate_min = runtime->
hw.rate_max = 96000;
1319 runtime->
hw.channels_min = runtime->
hw.channels_max = 4;
1324 runtime->
hw.rate_min = runtime->
hw.rate_max = 192000;
1325 runtime->
hw.channels_min = runtime->
hw.channels_max = 2;
1332 runtime->
hw.channels_min = runtime->
hw.channels_max = 0;
1333 for (idx = 0; idx < nefx; idx++) {
1334 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) {
1335 runtime->
hw.channels_min++;
1336 runtime->
hw.channels_max++;
1340 epcm->capture_cr_val = emu->efx_voices_mask[0];
1341 epcm->capture_cr_val2 = emu->efx_voices_mask[1];
1342 spin_unlock_irq(&emu->reg_lock);
1343 emu->capture_efx_interrupt = snd_emu10k1_pcm_efx_interrupt;
1344 emu->pcm_capture_efx_substream = substream;
1353 emu->capture_interrupt =
NULL;
1354 emu->pcm_capture_efx_substream =
NULL;
1358 static struct snd_pcm_ops snd_emu10k1_playback_ops = {
1359 .open = snd_emu10k1_playback_open,
1360 .close = snd_emu10k1_playback_close,
1362 .hw_params = snd_emu10k1_playback_hw_params,
1363 .hw_free = snd_emu10k1_playback_hw_free,
1364 .prepare = snd_emu10k1_playback_prepare,
1365 .trigger = snd_emu10k1_playback_trigger,
1366 .pointer = snd_emu10k1_playback_pointer,
1370 static struct snd_pcm_ops snd_emu10k1_capture_ops = {
1371 .open = snd_emu10k1_capture_open,
1372 .close = snd_emu10k1_capture_close,
1374 .hw_params = snd_emu10k1_capture_hw_params,
1375 .hw_free = snd_emu10k1_capture_hw_free,
1376 .prepare = snd_emu10k1_capture_prepare,
1377 .trigger = snd_emu10k1_capture_trigger,
1378 .pointer = snd_emu10k1_capture_pointer,
1382 static struct snd_pcm_ops snd_emu10k1_efx_playback_ops = {
1383 .open = snd_emu10k1_efx_playback_open,
1384 .close = snd_emu10k1_efx_playback_close,
1386 .hw_params = snd_emu10k1_playback_hw_params,
1387 .hw_free = snd_emu10k1_efx_playback_hw_free,
1388 .prepare = snd_emu10k1_efx_playback_prepare,
1389 .trigger = snd_emu10k1_efx_playback_trigger,
1390 .pointer = snd_emu10k1_efx_playback_pointer,
1403 if ((err =
snd_pcm_new(emu->card,
"emu10k1", device, 32, 1, &pcm)) < 0)
1413 strcpy(pcm->
name,
"ADC Capture/Standard PCM Playback");
1438 if ((err =
snd_pcm_new(emu->card,
"emu10k1", device, 1, 0, &pcm)) < 0)
1448 emu->pcm_multi =
pcm;
1461 static struct snd_pcm_ops snd_emu10k1_capture_mic_ops = {
1462 .open = snd_emu10k1_capture_mic_open,
1463 .close = snd_emu10k1_capture_mic_close,
1465 .hw_params = snd_emu10k1_capture_hw_params,
1466 .hw_free = snd_emu10k1_capture_hw_free,
1467 .prepare = snd_emu10k1_capture_prepare,
1468 .trigger = snd_emu10k1_capture_trigger,
1469 .pointer = snd_emu10k1_capture_pointer,
1480 if ((err =
snd_pcm_new(emu->card,
"emu10k1 mic", device, 0, 1, &pcm)) < 0)
1501 int nefx = emu->audigy ? 64 : 32;
1503 uinfo->
count = nefx;
1512 int nefx = emu->audigy ? 64 : 32;
1515 spin_lock_irq(&emu->reg_lock);
1516 for (idx = 0; idx < nefx; idx++)
1517 ucontrol->
value.integer.value[idx] = (emu->efx_voices_mask[idx / 32] & (1 << (idx % 32))) ? 1 : 0;
1518 spin_unlock_irq(&emu->reg_lock);
1525 unsigned int nval[2],
bits;
1526 int nefx = emu->audigy ? 64 : 32;
1527 int nefxb = emu->audigy ? 7 : 6;
1530 nval[0] = nval[1] = 0;
1531 for (idx = 0, bits = 0; idx < nefx; idx++)
1532 if (ucontrol->
value.integer.value[idx]) {
1533 nval[idx / 32] |= 1 << (idx % 32);
1537 for (idx = 0; idx < nefxb; idx++)
1538 if (1 << idx == bits)
1544 spin_lock_irq(&emu->reg_lock);
1545 change = (nval[0] != emu->efx_voices_mask[0]) ||
1546 (nval[1] != emu->efx_voices_mask[1]);
1547 emu->efx_voices_mask[0] = nval[0];
1548 emu->efx_voices_mask[1] = nval[1];
1549 spin_unlock_irq(&emu->reg_lock);
1555 .name =
"Captured FX8010 Outputs",
1556 .info = snd_emu10k1_pcm_efx_voices_mask_info,
1557 .get = snd_emu10k1_pcm_efx_voices_mask_get,
1558 .put = snd_emu10k1_pcm_efx_voices_mask_put
1561 static struct snd_pcm_ops snd_emu10k1_capture_efx_ops = {
1562 .open = snd_emu10k1_capture_efx_open,
1563 .close = snd_emu10k1_capture_efx_close,
1565 .hw_params = snd_emu10k1_capture_hw_params,
1566 .hw_free = snd_emu10k1_capture_hw_free,
1567 .prepare = snd_emu10k1_capture_prepare,
1568 .trigger = snd_emu10k1_capture_trigger,
1569 .pointer = snd_emu10k1_capture_pointer,
1575 #define INITIAL_TRAM_SHIFT 14
1576 #define INITIAL_TRAM_POS(size) ((((size) / 2) - INITIAL_TRAM_SHIFT) - 1)
1578 static void snd_emu10k1_fx8010_playback_irq(
struct snd_emu10k1 *emu,
void *
private_data)
1584 static void snd_emu10k1_fx8010_playback_tram_poke1(
unsigned short *dst_left,
1585 unsigned short *dst_right,
1586 unsigned short *
src,
1588 unsigned int tram_shift)
1595 if ((tram_shift & 1) == 0) {
1597 *dst_left-- = *src++;
1598 *dst_right-- = *src++;
1602 *dst_right-- = *src++;
1603 *dst_left-- = *src++;
1612 struct snd_emu10k1_fx8010_pcm *
pcm = &emu->fx8010.pcm[substream->
number];
1613 unsigned int tram_size = pcm->buffer_size;
1614 unsigned short *src = (
unsigned short *)(substream->
runtime->dma_area + rec->
sw_data);
1615 unsigned int frames = bytes >> 2,
count;
1616 unsigned int tram_pos = pcm->tram_pos;
1617 unsigned int tram_shift = pcm->tram_shift;
1619 while (frames > tram_pos) {
1620 count = tram_pos + 1;
1621 snd_emu10k1_fx8010_playback_tram_poke1((
unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
1622 (
unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
1623 src, count, tram_shift);
1626 tram_pos = (tram_size / 2) - 1;
1629 snd_emu10k1_fx8010_playback_tram_poke1((
unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
1630 (
unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
1631 src, frames, tram_shift);
1633 pcm->tram_pos = tram_pos;
1634 pcm->tram_shift = tram_shift;
1637 static int snd_emu10k1_fx8010_playback_transfer(
struct snd_pcm_substream *substream)
1640 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->
number];
1642 snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec, fx8010_pb_trans_copy);
1646 static int snd_emu10k1_fx8010_playback_hw_params(
struct snd_pcm_substream *substream,
1652 static int snd_emu10k1_fx8010_playback_hw_free(
struct snd_pcm_substream *substream)
1655 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->
number];
1658 for (i = 0; i < pcm->channels; i++)
1664 static int snd_emu10k1_fx8010_playback_prepare(
struct snd_pcm_substream *substream)
1668 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->
number];
1677 memset(&pcm->pcm_rec, 0,
sizeof(pcm->pcm_rec));
1678 pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2;
1679 pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
1681 pcm->tram_shift = 0;
1688 for (i = 0; i < pcm->channels; i++)
1693 static int snd_emu10k1_fx8010_playback_trigger(
struct snd_pcm_substream *substream,
int cmd)
1696 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->
number];
1699 spin_lock(&emu->reg_lock);
1705 #ifdef EMU10K1_SET_AC3_IEC958
1708 for (i = 0; i < 3; i++) {
1720 snd_emu10k1_fx8010_playback_transfer(substream);
1729 pcm->tram_shift = 0;
1736 spin_unlock(&emu->reg_lock);
1743 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->
number];
1749 return snd_pcm_indirect_playback_pointer(substream, &pcm->pcm_rec, ptr);
1764 .period_bytes_min = 1024,
1765 .period_bytes_max = (128*1024),
1771 static int snd_emu10k1_fx8010_playback_open(
struct snd_pcm_substream *substream)
1775 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->
number];
1777 runtime->
hw = snd_emu10k1_fx8010_playback;
1778 runtime->
hw.channels_min = runtime->
hw.channels_max = pcm->channels;
1779 runtime->
hw.period_bytes_max = (pcm->buffer_size * 2) / 2;
1780 spin_lock_irq(&emu->reg_lock);
1781 if (pcm->valid == 0) {
1782 spin_unlock_irq(&emu->reg_lock);
1786 spin_unlock_irq(&emu->reg_lock);
1790 static int snd_emu10k1_fx8010_playback_close(
struct snd_pcm_substream *substream)
1793 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->
number];
1795 spin_lock_irq(&emu->reg_lock);
1797 spin_unlock_irq(&emu->reg_lock);
1801 static struct snd_pcm_ops snd_emu10k1_fx8010_playback_ops = {
1802 .open = snd_emu10k1_fx8010_playback_open,
1803 .close = snd_emu10k1_fx8010_playback_close,
1805 .hw_params = snd_emu10k1_fx8010_playback_hw_params,
1806 .hw_free = snd_emu10k1_fx8010_playback_hw_free,
1807 .prepare = snd_emu10k1_fx8010_playback_prepare,
1808 .trigger = snd_emu10k1_fx8010_playback_trigger,
1809 .pointer = snd_emu10k1_fx8010_playback_pointer,
1810 .ack = snd_emu10k1_fx8010_playback_transfer,
1822 if ((err =
snd_pcm_new(emu->card,
"emu10k1 efx", device, 8, 1, &pcm)) < 0)
1831 strcpy(pcm->
name,
"Multichannel Capture/PT Playback");
1842 emu->efx_voices_mask[0] = 0;
1843 if (emu->card_capabilities->emu_model)
1848 emu->efx_voices_mask[1] = 0xffffffff;
1850 emu->efx_voices_mask[1] = 0xffff;
1852 emu->efx_voices_mask[0] = 0xffff0000;
1853 emu->efx_voices_mask[1] = 0;
1861 kctl =
snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask, emu);
1864 kctl->
id.device = device;