1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5 * Routines for control of EMU10K1 chips / PCM routines
6 * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
15 #include <linux/pci.h>
16 #include <linux/delay.h>
17 #include <linux/slab.h>
18 #include <linux/time.h>
19 #include <linux/init.h>
20 #include <sound/core.h>
21 #include <sound/emu10k1.h>
23 static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1
*emu
,
24 struct snd_emu10k1_voice
*voice
)
26 struct snd_emu10k1_pcm
*epcm
;
28 if ((epcm
= voice
->epcm
) == NULL
)
30 if (epcm
->substream
== NULL
)
33 dev_dbg(emu
->card
->dev
,
34 "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
35 epcm
->substream
->runtime
->hw
->pointer(emu
, epcm
->substream
),
36 snd_pcm_lib_period_bytes(epcm
->substream
),
37 snd_pcm_lib_buffer_bytes(epcm
->substream
));
39 snd_pcm_period_elapsed(epcm
->substream
);
42 static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1
*emu
,
46 if (status
& IPR_ADCBUFHALFFULL
) {
47 if (emu
->pcm_capture_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
51 snd_pcm_period_elapsed(emu
->pcm_capture_substream
);
54 static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1
*emu
,
58 if (status
& IPR_MICBUFHALFFULL
) {
59 if (emu
->pcm_capture_mic_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
63 snd_pcm_period_elapsed(emu
->pcm_capture_mic_substream
);
66 static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1
*emu
,
70 if (status
& IPR_EFXBUFHALFFULL
) {
71 if (emu
->pcm_capture_efx_substream
->runtime
->mode
== SNDRV_PCM_MODE_FRAME
)
75 snd_pcm_period_elapsed(emu
->pcm_capture_efx_substream
);
78 static snd_pcm_uframes_t
snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream
*substream
)
80 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
81 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
82 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
87 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->voices
[0]->number
) & 0x00ffffff;
88 ptr
+= runtime
->buffer_size
;
89 ptr
-= epcm
->ccca_start_addr
;
90 ptr
%= runtime
->buffer_size
;
95 static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm
* epcm
, int voices
)
99 if (epcm
->voices
[1] != NULL
&& voices
< 2) {
100 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[1]);
101 epcm
->voices
[1] = NULL
;
103 for (i
= 0; i
< voices
; i
++) {
104 if (epcm
->voices
[i
] == NULL
)
108 return 0; /* already allocated */
110 for (i
= 0; i
< ARRAY_SIZE(epcm
->voices
); i
++) {
111 if (epcm
->voices
[i
]) {
112 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
113 epcm
->voices
[i
] = NULL
;
116 err
= snd_emu10k1_voice_alloc(epcm
->emu
,
117 epcm
->type
== PLAYBACK_EMUVOICE
? EMU10K1_PCM
: EMU10K1_EFX
,
123 epcm
->voices
[0]->epcm
= epcm
;
125 for (i
= 1; i
< voices
; i
++) {
126 epcm
->voices
[i
] = &epcm
->emu
->voices
[epcm
->voices
[0]->number
+ i
];
127 epcm
->voices
[i
]->epcm
= epcm
;
130 if (epcm
->extra
== NULL
) {
131 err
= snd_emu10k1_voice_alloc(epcm
->emu
,
132 epcm
->type
== PLAYBACK_EMUVOICE
? EMU10K1_PCM
: EMU10K1_EFX
,
137 dev_dbg(emu->card->dev, "pcm_channel_alloc: "
138 "failed extra: voices=%d, frame=%d\n",
141 for (i
= 0; i
< voices
; i
++) {
142 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
143 epcm
->voices
[i
] = NULL
;
147 epcm
->extra
->epcm
= epcm
;
148 epcm
->extra
->interrupt
= snd_emu10k1_pcm_interrupt
;
153 static const unsigned int capture_period_sizes
[31] = {
155 384*2, 448*2, 512*2, 640*2,
156 384*4, 448*4, 512*4, 640*4,
157 384*8, 448*8, 512*8, 640*8,
158 384*16, 448*16, 512*16, 640*16,
159 384*32, 448*32, 512*32, 640*32,
160 384*64, 448*64, 512*64, 640*64,
161 384*128,448*128,512*128
164 static const struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes
= {
166 .list
= capture_period_sizes
,
170 static const unsigned int capture_rates
[8] = {
171 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
174 static const struct snd_pcm_hw_constraint_list hw_constraints_capture_rates
= {
176 .list
= capture_rates
,
180 static unsigned int snd_emu10k1_capture_rate_reg(unsigned int rate
)
183 case 8000: return ADCCR_SAMPLERATE_8
;
184 case 11025: return ADCCR_SAMPLERATE_11
;
185 case 16000: return ADCCR_SAMPLERATE_16
;
186 case 22050: return ADCCR_SAMPLERATE_22
;
187 case 24000: return ADCCR_SAMPLERATE_24
;
188 case 32000: return ADCCR_SAMPLERATE_32
;
189 case 44100: return ADCCR_SAMPLERATE_44
;
190 case 48000: return ADCCR_SAMPLERATE_48
;
193 return ADCCR_SAMPLERATE_8
;
197 static unsigned int snd_emu10k1_audigy_capture_rate_reg(unsigned int rate
)
200 case 8000: return A_ADCCR_SAMPLERATE_8
;
201 case 11025: return A_ADCCR_SAMPLERATE_11
;
202 case 12000: return A_ADCCR_SAMPLERATE_12
; /* really supported? */
203 case 16000: return ADCCR_SAMPLERATE_16
;
204 case 22050: return ADCCR_SAMPLERATE_22
;
205 case 24000: return ADCCR_SAMPLERATE_24
;
206 case 32000: return ADCCR_SAMPLERATE_32
;
207 case 44100: return ADCCR_SAMPLERATE_44
;
208 case 48000: return ADCCR_SAMPLERATE_48
;
211 return A_ADCCR_SAMPLERATE_8
;
215 static unsigned int emu10k1_calc_pitch_target(unsigned int rate
)
217 unsigned int pitch_target
;
219 pitch_target
= (rate
<< 8) / 375;
220 pitch_target
= (pitch_target
>> 1) + (pitch_target
& 1);
224 #define PITCH_48000 0x00004000
225 #define PITCH_96000 0x00008000
226 #define PITCH_85000 0x00007155
227 #define PITCH_80726 0x00006ba2
228 #define PITCH_67882 0x00005a82
229 #define PITCH_57081 0x00004c1c
231 static unsigned int emu10k1_select_interprom(unsigned int pitch_target
)
233 if (pitch_target
== PITCH_48000
)
234 return CCCA_INTERPROM_0
;
235 else if (pitch_target
< PITCH_48000
)
236 return CCCA_INTERPROM_1
;
237 else if (pitch_target
>= PITCH_96000
)
238 return CCCA_INTERPROM_0
;
239 else if (pitch_target
>= PITCH_85000
)
240 return CCCA_INTERPROM_6
;
241 else if (pitch_target
>= PITCH_80726
)
242 return CCCA_INTERPROM_5
;
243 else if (pitch_target
>= PITCH_67882
)
244 return CCCA_INTERPROM_4
;
245 else if (pitch_target
>= PITCH_57081
)
246 return CCCA_INTERPROM_3
;
248 return CCCA_INTERPROM_2
;
252 * calculate cache invalidate size
254 * stereo: channel is stereo
255 * w_16: using 16bit samples
257 * returns: cache invalidate size in samples
259 static inline int emu10k1_ccis(int stereo
, int w_16
)
262 return stereo
? 24 : 26;
264 return stereo
? 24*2 : 26*2;
268 static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1
*emu
,
269 int master
, int extra
,
270 struct snd_emu10k1_voice
*evoice
,
271 unsigned int start_addr
,
272 unsigned int end_addr
,
273 struct snd_emu10k1_pcm_mixer
*mix
)
275 struct snd_pcm_substream
*substream
= evoice
->epcm
->substream
;
276 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
277 unsigned int silent_page
, tmp
;
278 int voice
, stereo
, w_16
;
279 unsigned char send_amount
[8];
280 unsigned char send_routing
[8];
282 unsigned int pitch_target
;
285 voice
= evoice
->number
;
286 stereo
= runtime
->channels
== 2;
287 w_16
= snd_pcm_format_width(runtime
->format
) == 16;
289 if (!extra
&& stereo
) {
298 spin_lock_irqsave(&emu
->reg_lock
, flags
);
300 /* volume parameters */
302 memset(send_routing
, 0, sizeof(send_routing
));
307 memset(send_amount
, 0, sizeof(send_amount
));
309 /* mono, left, right (master voice = left) */
310 tmp
= stereo
? (master
? 1 : 2) : 0;
311 memcpy(send_routing
, &mix
->send_routing
[tmp
][0], 8);
312 memcpy(send_amount
, &mix
->send_volume
[tmp
][0], 8);
315 ccis
= emu10k1_ccis(stereo
, w_16
);
318 evoice
->epcm
->ccca_start_addr
= start_addr
+ ccis
;
321 end_addr
+= ccis
+ emu
->delay_pcm_irq
;
323 if (stereo
&& !extra
) {
324 snd_emu10k1_ptr_write(emu
, CPF
, voice
, CPF_STEREO_MASK
);
325 snd_emu10k1_ptr_write(emu
, CPF
, (voice
+ 1), CPF_STEREO_MASK
);
327 snd_emu10k1_ptr_write(emu
, CPF
, voice
, 0);
333 snd_emu10k1_ptr_write(emu
, A_FXRT1
, voice
,
334 snd_emu10k1_compose_audigy_fxrt1(send_routing
));
335 snd_emu10k1_ptr_write(emu
, A_FXRT2
, voice
,
336 snd_emu10k1_compose_audigy_fxrt2(send_routing
));
337 snd_emu10k1_ptr_write(emu
, A_SENDAMOUNTS
, voice
,
338 ((unsigned int)send_amount
[4] << 24) |
339 ((unsigned int)send_amount
[5] << 16) |
340 ((unsigned int)send_amount
[6] << 8) |
341 (unsigned int)send_amount
[7]);
343 snd_emu10k1_ptr_write(emu
, FXRT
, voice
,
344 snd_emu10k1_compose_send_routing(send_routing
));
346 /* Assumption that PT is already 0 so no harm overwriting */
347 snd_emu10k1_ptr_write(emu
, PTRX
, voice
, (send_amount
[0] << 8) | send_amount
[1]);
348 snd_emu10k1_ptr_write(emu
, DSL
, voice
, end_addr
| (send_amount
[3] << 24));
349 snd_emu10k1_ptr_write(emu
, PSST
, voice
,
350 (start_addr
+ (extra
? emu
->delay_pcm_irq
: 0)) |
351 (send_amount
[2] << 24));
352 if (emu
->card_capabilities
->emu_model
)
353 pitch_target
= PITCH_48000
; /* Disable interpolators on emu1010 card */
355 pitch_target
= emu10k1_calc_pitch_target(runtime
->rate
);
357 snd_emu10k1_ptr_write(emu
, CCCA
, voice
, start_addr
|
358 emu10k1_select_interprom(pitch_target
) |
359 (w_16
? 0 : CCCA_8BITSELECT
));
361 snd_emu10k1_ptr_write(emu
, CCCA
, voice
, (start_addr
+ ccis
) |
362 emu10k1_select_interprom(pitch_target
) |
363 (w_16
? 0 : CCCA_8BITSELECT
));
364 /* Clear filter delay memory */
365 snd_emu10k1_ptr_write(emu
, Z1
, voice
, 0);
366 snd_emu10k1_ptr_write(emu
, Z2
, voice
, 0);
367 /* invalidate maps */
368 silent_page
= ((unsigned int)emu
->silent_page
.addr
<< emu
->address_mode
) | (emu
->address_mode
? MAP_PTI_MASK1
: MAP_PTI_MASK0
);
369 snd_emu10k1_ptr_write(emu
, MAPA
, voice
, silent_page
);
370 snd_emu10k1_ptr_write(emu
, MAPB
, voice
, silent_page
);
371 /* modulation envelope */
372 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, 0xffff);
373 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, 0xffff);
374 snd_emu10k1_ptr_write(emu
, ATKHLDM
, voice
, 0);
375 snd_emu10k1_ptr_write(emu
, DCYSUSM
, voice
, 0x007f);
376 snd_emu10k1_ptr_write(emu
, LFOVAL1
, voice
, 0x8000);
377 snd_emu10k1_ptr_write(emu
, LFOVAL2
, voice
, 0x8000);
378 snd_emu10k1_ptr_write(emu
, FMMOD
, voice
, 0);
379 snd_emu10k1_ptr_write(emu
, TREMFRQ
, voice
, 0);
380 snd_emu10k1_ptr_write(emu
, FM2FRQ2
, voice
, 0);
381 snd_emu10k1_ptr_write(emu
, ENVVAL
, voice
, 0x8000);
382 /* volume envelope */
383 snd_emu10k1_ptr_write(emu
, ATKHLDV
, voice
, 0x7f7f);
384 snd_emu10k1_ptr_write(emu
, ENVVOL
, voice
, 0x0000);
385 /* filter envelope */
386 snd_emu10k1_ptr_write(emu
, PEFE_FILTERAMOUNT
, voice
, 0x7f);
388 snd_emu10k1_ptr_write(emu
, PEFE_PITCHAMOUNT
, voice
, 0);
390 spin_unlock_irqrestore(&emu
->reg_lock
, flags
);
393 static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream
*substream
,
394 struct snd_pcm_hw_params
*hw_params
)
396 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
397 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
398 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
402 if ((err
= snd_emu10k1_pcm_channel_alloc(epcm
, params_channels(hw_params
))) < 0)
405 alloc_size
= params_buffer_bytes(hw_params
);
406 if (emu
->iommu_workaround
)
407 alloc_size
+= EMUPAGESIZE
;
408 err
= snd_pcm_lib_malloc_pages(substream
, alloc_size
);
411 if (emu
->iommu_workaround
&& runtime
->dma_bytes
>= EMUPAGESIZE
)
412 runtime
->dma_bytes
-= EMUPAGESIZE
;
413 if (err
> 0) { /* change */
415 if (epcm
->memblk
!= NULL
)
416 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
417 epcm
->memblk
= snd_emu10k1_alloc_pages(emu
, substream
);
418 epcm
->start_addr
= 0;
421 mapped
= ((struct snd_emu10k1_memblk
*)epcm
->memblk
)->mapped_page
;
424 epcm
->start_addr
= mapped
<< PAGE_SHIFT
;
429 static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream
*substream
)
431 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
432 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
433 struct snd_emu10k1_pcm
*epcm
;
435 if (runtime
->private_data
== NULL
)
437 epcm
= runtime
->private_data
;
439 snd_emu10k1_voice_free(epcm
->emu
, epcm
->extra
);
442 if (epcm
->voices
[1]) {
443 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[1]);
444 epcm
->voices
[1] = NULL
;
446 if (epcm
->voices
[0]) {
447 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[0]);
448 epcm
->voices
[0] = NULL
;
451 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
453 epcm
->start_addr
= 0;
455 snd_pcm_lib_free_pages(substream
);
459 static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream
*substream
)
461 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
462 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
463 struct snd_emu10k1_pcm
*epcm
;
466 if (runtime
->private_data
== NULL
)
468 epcm
= runtime
->private_data
;
470 snd_emu10k1_voice_free(epcm
->emu
, epcm
->extra
);
473 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
474 if (epcm
->voices
[i
]) {
475 snd_emu10k1_voice_free(epcm
->emu
, epcm
->voices
[i
]);
476 epcm
->voices
[i
] = NULL
;
480 snd_emu10k1_free_pages(emu
, epcm
->memblk
);
482 epcm
->start_addr
= 0;
484 snd_pcm_lib_free_pages(substream
);
488 static int snd_emu10k1_playback_prepare(struct snd_pcm_substream
*substream
)
490 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
491 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
492 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
493 unsigned int start_addr
, end_addr
;
495 start_addr
= epcm
->start_addr
;
496 end_addr
= snd_pcm_lib_period_bytes(substream
);
497 if (runtime
->channels
== 2) {
501 end_addr
+= start_addr
;
502 snd_emu10k1_pcm_init_voice(emu
, 1, 1, epcm
->extra
,
503 start_addr
, end_addr
, NULL
);
504 start_addr
= epcm
->start_addr
;
505 end_addr
= epcm
->start_addr
+ snd_pcm_lib_buffer_bytes(substream
);
506 snd_emu10k1_pcm_init_voice(emu
, 1, 0, epcm
->voices
[0],
507 start_addr
, end_addr
,
508 &emu
->pcm_mixer
[substream
->number
]);
510 snd_emu10k1_pcm_init_voice(emu
, 0, 0, epcm
->voices
[1],
511 start_addr
, end_addr
,
512 &emu
->pcm_mixer
[substream
->number
]);
516 static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream
*substream
)
518 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
519 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
520 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
521 unsigned int start_addr
, end_addr
;
522 unsigned int channel_size
;
525 start_addr
= epcm
->start_addr
;
526 end_addr
= epcm
->start_addr
+ snd_pcm_lib_buffer_bytes(substream
);
529 * the kX driver leaves some space between voices
531 channel_size
= ( end_addr
- start_addr
) / NUM_EFX_PLAYBACK
;
533 snd_emu10k1_pcm_init_voice(emu
, 1, 1, epcm
->extra
,
534 start_addr
, start_addr
+ (channel_size
/ 2), NULL
);
536 /* only difference with the master voice is we use it for the pointer */
537 snd_emu10k1_pcm_init_voice(emu
, 1, 0, epcm
->voices
[0],
538 start_addr
, start_addr
+ channel_size
,
539 &emu
->efx_pcm_mixer
[0]);
541 start_addr
+= channel_size
;
542 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++) {
543 snd_emu10k1_pcm_init_voice(emu
, 0, 0, epcm
->voices
[i
],
544 start_addr
, start_addr
+ channel_size
,
545 &emu
->efx_pcm_mixer
[i
]);
546 start_addr
+= channel_size
;
552 static const struct snd_pcm_hardware snd_emu10k1_efx_playback
=
554 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_NONINTERLEAVED
|
555 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
556 SNDRV_PCM_INFO_RESUME
|
557 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
),
558 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
559 .rates
= SNDRV_PCM_RATE_48000
,
562 .channels_min
= NUM_EFX_PLAYBACK
,
563 .channels_max
= NUM_EFX_PLAYBACK
,
564 .buffer_bytes_max
= (64*1024),
565 .period_bytes_min
= 64,
566 .period_bytes_max
= (64*1024),
572 static int snd_emu10k1_capture_hw_params(struct snd_pcm_substream
*substream
,
573 struct snd_pcm_hw_params
*hw_params
)
575 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
578 static int snd_emu10k1_capture_hw_free(struct snd_pcm_substream
*substream
)
580 return snd_pcm_lib_free_pages(substream
);
583 static int snd_emu10k1_capture_prepare(struct snd_pcm_substream
*substream
)
585 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
586 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
587 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
590 /* zeroing the buffer size will stop capture */
591 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, 0);
592 switch (epcm
->type
) {
593 case CAPTURE_AC97ADC
:
594 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, 0);
598 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, 0);
599 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, 0);
601 snd_emu10k1_ptr_write(emu
, FXWC
, 0, 0);
606 snd_emu10k1_ptr_write(emu
, epcm
->capture_ba_reg
, 0, runtime
->dma_addr
);
607 epcm
->capture_bufsize
= snd_pcm_lib_buffer_bytes(substream
);
608 epcm
->capture_bs_val
= 0;
609 for (idx
= 0; idx
< 31; idx
++) {
610 if (capture_period_sizes
[idx
] == epcm
->capture_bufsize
) {
611 epcm
->capture_bs_val
= idx
+ 1;
615 if (epcm
->capture_bs_val
== 0) {
617 epcm
->capture_bs_val
++;
619 if (epcm
->type
== CAPTURE_AC97ADC
) {
620 epcm
->capture_cr_val
= emu
->audigy
? A_ADCCR_LCHANENABLE
: ADCCR_LCHANENABLE
;
621 if (runtime
->channels
> 1)
622 epcm
->capture_cr_val
|= emu
->audigy
? A_ADCCR_RCHANENABLE
: ADCCR_RCHANENABLE
;
623 epcm
->capture_cr_val
|= emu
->audigy
?
624 snd_emu10k1_audigy_capture_rate_reg(runtime
->rate
) :
625 snd_emu10k1_capture_rate_reg(runtime
->rate
);
630 static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1
*emu
, int extra
, struct snd_emu10k1_voice
*evoice
)
632 struct snd_pcm_runtime
*runtime
;
633 unsigned int voice
, stereo
, i
, ccis
, cra
= 64, cs
, sample
;
637 runtime
= evoice
->epcm
->substream
->runtime
;
638 voice
= evoice
->number
;
639 stereo
= (!extra
&& runtime
->channels
== 2);
640 sample
= snd_pcm_format_width(runtime
->format
) == 16 ? 0 : 0x80808080;
641 ccis
= emu10k1_ccis(stereo
, sample
== 0);
642 /* set cs to 2 * number of cache registers beside the invalidated */
643 cs
= (sample
== 0) ? (32-ccis
) : (64-ccis
+1) >> 1;
644 if (cs
> 16) cs
= 16;
645 for (i
= 0; i
< cs
; i
++) {
646 snd_emu10k1_ptr_write(emu
, CD0
+ i
, voice
, sample
);
648 snd_emu10k1_ptr_write(emu
, CD0
+ i
, voice
+ 1, sample
);
652 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
, 0);
653 snd_emu10k1_ptr_write(emu
, CCR_READADDRESS
, voice
, cra
);
655 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
+ 1, 0);
656 snd_emu10k1_ptr_write(emu
, CCR_READADDRESS
, voice
+ 1, cra
);
659 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
, ccis
);
661 snd_emu10k1_ptr_write(emu
, CCR_CACHEINVALIDSIZE
, voice
+1, ccis
);
665 static void snd_emu10k1_playback_prepare_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
,
666 int master
, int extra
,
667 struct snd_emu10k1_pcm_mixer
*mix
)
669 struct snd_pcm_substream
*substream
;
670 struct snd_pcm_runtime
*runtime
;
671 unsigned int attn
, vattn
;
672 unsigned int voice
, tmp
;
674 if (evoice
== NULL
) /* skip second voice for mono */
676 substream
= evoice
->epcm
->substream
;
677 runtime
= substream
->runtime
;
678 voice
= evoice
->number
;
680 attn
= extra
? 0 : 0x00ff;
681 tmp
= runtime
->channels
== 2 ? (master
? 1 : 2) : 0;
682 vattn
= mix
!= NULL
? (mix
->attn
[tmp
] << 16) : 0;
683 snd_emu10k1_ptr_write(emu
, IFATN
, voice
, attn
);
684 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, vattn
| 0xffff);
685 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, vattn
| 0xffff);
686 snd_emu10k1_ptr_write(emu
, DCYSUSV
, voice
, 0x7f7f);
687 snd_emu10k1_voice_clear_loop_stop(emu
, voice
);
690 static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
, int master
, int extra
)
692 struct snd_pcm_substream
*substream
;
693 struct snd_pcm_runtime
*runtime
;
694 unsigned int voice
, pitch
, pitch_target
;
696 if (evoice
== NULL
) /* skip second voice for mono */
698 substream
= evoice
->epcm
->substream
;
699 runtime
= substream
->runtime
;
700 voice
= evoice
->number
;
702 pitch
= snd_emu10k1_rate_to_pitch(runtime
->rate
) >> 8;
703 if (emu
->card_capabilities
->emu_model
)
704 pitch_target
= PITCH_48000
; /* Disable interpolators on emu1010 card */
706 pitch_target
= emu10k1_calc_pitch_target(runtime
->rate
);
707 snd_emu10k1_ptr_write(emu
, PTRX_PITCHTARGET
, voice
, pitch_target
);
708 if (master
|| evoice
->epcm
->type
== PLAYBACK_EFX
)
709 snd_emu10k1_ptr_write(emu
, CPF_CURRENTPITCH
, voice
, pitch_target
);
710 snd_emu10k1_ptr_write(emu
, IP
, voice
, pitch
);
712 snd_emu10k1_voice_intr_enable(emu
, voice
);
715 static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1
*emu
, struct snd_emu10k1_voice
*evoice
)
721 voice
= evoice
->number
;
722 snd_emu10k1_voice_intr_disable(emu
, voice
);
723 snd_emu10k1_ptr_write(emu
, PTRX_PITCHTARGET
, voice
, 0);
724 snd_emu10k1_ptr_write(emu
, CPF_CURRENTPITCH
, voice
, 0);
725 snd_emu10k1_ptr_write(emu
, IFATN
, voice
, 0xffff);
726 snd_emu10k1_ptr_write(emu
, VTFT
, voice
, 0xffff);
727 snd_emu10k1_ptr_write(emu
, CVCF
, voice
, 0xffff);
728 snd_emu10k1_ptr_write(emu
, IP
, voice
, 0);
731 static inline void snd_emu10k1_playback_mangle_extra(struct snd_emu10k1
*emu
,
732 struct snd_emu10k1_pcm
*epcm
,
733 struct snd_pcm_substream
*substream
,
734 struct snd_pcm_runtime
*runtime
)
736 unsigned int ptr
, period_pos
;
738 /* try to sychronize the current position for the interrupt
740 period_pos
= runtime
->status
->hw_ptr
- runtime
->hw_ptr_interrupt
;
741 period_pos
%= runtime
->period_size
;
742 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->extra
->number
);
744 ptr
|= epcm
->ccca_start_addr
+ period_pos
;
745 snd_emu10k1_ptr_write(emu
, CCCA
, epcm
->extra
->number
, ptr
);
748 static int snd_emu10k1_playback_trigger(struct snd_pcm_substream
*substream
,
751 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
752 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
753 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
754 struct snd_emu10k1_pcm_mixer
*mix
;
758 dev_dbg(emu->card->dev,
759 "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
760 (int)emu, cmd, substream->ops->pointer(substream))
762 spin_lock(&emu
->reg_lock
);
764 case SNDRV_PCM_TRIGGER_START
:
765 snd_emu10k1_playback_invalidate_cache(emu
, 1, epcm
->extra
); /* do we need this? */
766 snd_emu10k1_playback_invalidate_cache(emu
, 0, epcm
->voices
[0]);
768 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
769 case SNDRV_PCM_TRIGGER_RESUME
:
770 if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_RELEASE
)
771 snd_emu10k1_playback_mangle_extra(emu
, epcm
, substream
, runtime
);
772 mix
= &emu
->pcm_mixer
[substream
->number
];
773 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[0], 1, 0, mix
);
774 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[1], 0, 0, mix
);
775 snd_emu10k1_playback_prepare_voice(emu
, epcm
->extra
, 1, 1, NULL
);
776 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[0], 1, 0);
777 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[1], 0, 0);
778 snd_emu10k1_playback_trigger_voice(emu
, epcm
->extra
, 1, 1);
781 case SNDRV_PCM_TRIGGER_STOP
:
782 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
783 case SNDRV_PCM_TRIGGER_SUSPEND
:
785 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[0]);
786 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[1]);
787 snd_emu10k1_playback_stop_voice(emu
, epcm
->extra
);
793 spin_unlock(&emu
->reg_lock
);
797 static int snd_emu10k1_capture_trigger(struct snd_pcm_substream
*substream
,
800 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
801 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
802 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
805 spin_lock(&emu
->reg_lock
);
807 case SNDRV_PCM_TRIGGER_START
:
808 case SNDRV_PCM_TRIGGER_RESUME
:
809 /* hmm this should cause full and half full interrupt to be raised? */
810 outl(epcm
->capture_ipr
, emu
->port
+ IPR
);
811 snd_emu10k1_intr_enable(emu
, epcm
->capture_inte
);
813 dev_dbg(emu->card->dev, "adccr = 0x%x, adcbs = 0x%x\n",
814 epcm->adccr, epcm->adcbs);
816 switch (epcm
->type
) {
817 case CAPTURE_AC97ADC
:
818 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, epcm
->capture_cr_val
);
822 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, epcm
->capture_cr_val
);
823 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, epcm
->capture_cr_val2
);
824 dev_dbg(emu
->card
->dev
,
825 "cr_val=0x%x, cr_val2=0x%x\n",
826 epcm
->capture_cr_val
,
827 epcm
->capture_cr_val2
);
829 snd_emu10k1_ptr_write(emu
, FXWC
, 0, epcm
->capture_cr_val
);
834 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, epcm
->capture_bs_val
);
838 case SNDRV_PCM_TRIGGER_STOP
:
839 case SNDRV_PCM_TRIGGER_SUSPEND
:
841 snd_emu10k1_intr_disable(emu
, epcm
->capture_inte
);
842 outl(epcm
->capture_ipr
, emu
->port
+ IPR
);
843 snd_emu10k1_ptr_write(emu
, epcm
->capture_bs_reg
, 0, 0);
844 switch (epcm
->type
) {
845 case CAPTURE_AC97ADC
:
846 snd_emu10k1_ptr_write(emu
, ADCCR
, 0, 0);
850 snd_emu10k1_ptr_write(emu
, A_FXWC1
, 0, 0);
851 snd_emu10k1_ptr_write(emu
, A_FXWC2
, 0, 0);
853 snd_emu10k1_ptr_write(emu
, FXWC
, 0, 0);
862 spin_unlock(&emu
->reg_lock
);
866 static snd_pcm_uframes_t
snd_emu10k1_playback_pointer(struct snd_pcm_substream
*substream
)
868 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
869 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
870 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
875 ptr
= snd_emu10k1_ptr_read(emu
, CCCA
, epcm
->voices
[0]->number
) & 0x00ffffff;
876 #if 0 /* Perex's code */
877 ptr
+= runtime
->buffer_size
;
878 ptr
-= epcm
->ccca_start_addr
;
879 ptr
%= runtime
->buffer_size
;
880 #else /* EMU10K1 Open Source code from Creative */
881 if (ptr
< epcm
->ccca_start_addr
)
882 ptr
+= runtime
->buffer_size
- epcm
->ccca_start_addr
;
884 ptr
-= epcm
->ccca_start_addr
;
885 if (ptr
>= runtime
->buffer_size
)
886 ptr
-= runtime
->buffer_size
;
890 dev_dbg(emu->card->dev,
891 "ptr = 0x%lx, buffer_size = 0x%lx, period_size = 0x%lx\n",
892 (long)ptr, (long)runtime->buffer_size,
893 (long)runtime->period_size);
899 static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream
*substream
,
902 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
903 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
904 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
908 spin_lock(&emu
->reg_lock
);
910 case SNDRV_PCM_TRIGGER_START
:
912 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
913 snd_emu10k1_playback_invalidate_cache(emu
, 0, epcm
->voices
[i
]);
915 snd_emu10k1_playback_invalidate_cache(emu
, 1, epcm
->extra
);
918 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
919 case SNDRV_PCM_TRIGGER_RESUME
:
920 snd_emu10k1_playback_prepare_voice(emu
, epcm
->extra
, 1, 1, NULL
);
921 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[0], 0, 0,
922 &emu
->efx_pcm_mixer
[0]);
923 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++)
924 snd_emu10k1_playback_prepare_voice(emu
, epcm
->voices
[i
], 0, 0,
925 &emu
->efx_pcm_mixer
[i
]);
926 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[0], 0, 0);
927 snd_emu10k1_playback_trigger_voice(emu
, epcm
->extra
, 1, 1);
928 for (i
= 1; i
< NUM_EFX_PLAYBACK
; i
++)
929 snd_emu10k1_playback_trigger_voice(emu
, epcm
->voices
[i
], 0, 0);
932 case SNDRV_PCM_TRIGGER_SUSPEND
:
933 case SNDRV_PCM_TRIGGER_STOP
:
934 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
936 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
937 snd_emu10k1_playback_stop_voice(emu
, epcm
->voices
[i
]);
939 snd_emu10k1_playback_stop_voice(emu
, epcm
->extra
);
945 spin_unlock(&emu
->reg_lock
);
950 static snd_pcm_uframes_t
snd_emu10k1_capture_pointer(struct snd_pcm_substream
*substream
)
952 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
953 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
954 struct snd_emu10k1_pcm
*epcm
= runtime
->private_data
;
959 if (epcm
->first_ptr
) {
960 udelay(50); /* hack, it takes awhile until capture is started */
963 ptr
= snd_emu10k1_ptr_read(emu
, epcm
->capture_idx_reg
, 0) & 0x0000ffff;
964 return bytes_to_frames(runtime
, ptr
);
968 * Playback support device description
971 static const struct snd_pcm_hardware snd_emu10k1_playback
=
973 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
974 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
975 SNDRV_PCM_INFO_RESUME
|
976 SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE
),
977 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
978 .rates
= SNDRV_PCM_RATE_CONTINUOUS
| SNDRV_PCM_RATE_8000_96000
,
983 .buffer_bytes_max
= (128*1024),
984 .period_bytes_min
= 64,
985 .period_bytes_max
= (128*1024),
992 * Capture support device description
995 static const struct snd_pcm_hardware snd_emu10k1_capture
=
997 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
998 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
999 SNDRV_PCM_INFO_RESUME
|
1000 SNDRV_PCM_INFO_MMAP_VALID
),
1001 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1002 .rates
= SNDRV_PCM_RATE_8000_48000
,
1007 .buffer_bytes_max
= (64*1024),
1008 .period_bytes_min
= 384,
1009 .period_bytes_max
= (64*1024),
1015 static const struct snd_pcm_hardware snd_emu10k1_capture_efx
=
1017 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1018 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1019 SNDRV_PCM_INFO_RESUME
|
1020 SNDRV_PCM_INFO_MMAP_VALID
),
1021 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1022 .rates
= SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
|
1023 SNDRV_PCM_RATE_88200
| SNDRV_PCM_RATE_96000
|
1024 SNDRV_PCM_RATE_176400
| SNDRV_PCM_RATE_192000
,
1029 .buffer_bytes_max
= (64*1024),
1030 .period_bytes_min
= 384,
1031 .period_bytes_max
= (64*1024),
1041 static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1
*emu
, struct snd_kcontrol
*kctl
, int idx
, int activate
)
1043 struct snd_ctl_elem_id id
;
1048 kctl
->vd
[idx
].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1050 kctl
->vd
[idx
].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1051 snd_ctl_notify(emu
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1052 SNDRV_CTL_EVENT_MASK_INFO
,
1053 snd_ctl_build_ioff(&id
, kctl
, idx
));
1056 static void snd_emu10k1_pcm_mixer_notify(struct snd_emu10k1
*emu
, int idx
, int activate
)
1058 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_send_routing
, idx
, activate
);
1059 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_send_volume
, idx
, activate
);
1060 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_attn
, idx
, activate
);
1063 static void snd_emu10k1_pcm_efx_mixer_notify(struct snd_emu10k1
*emu
, int idx
, int activate
)
1065 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_send_routing
, idx
, activate
);
1066 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_send_volume
, idx
, activate
);
1067 snd_emu10k1_pcm_mixer_notify1(emu
, emu
->ctl_efx_attn
, idx
, activate
);
1070 static void snd_emu10k1_pcm_free_substream(struct snd_pcm_runtime
*runtime
)
1072 kfree(runtime
->private_data
);
1075 static int snd_emu10k1_efx_playback_close(struct snd_pcm_substream
*substream
)
1077 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1078 struct snd_emu10k1_pcm_mixer
*mix
;
1081 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
1082 mix
= &emu
->efx_pcm_mixer
[i
];
1084 snd_emu10k1_pcm_efx_mixer_notify(emu
, i
, 0);
1089 static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream
*substream
)
1091 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1092 struct snd_emu10k1_pcm
*epcm
;
1093 struct snd_emu10k1_pcm_mixer
*mix
;
1094 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1097 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1101 epcm
->type
= PLAYBACK_EFX
;
1102 epcm
->substream
= substream
;
1104 emu
->pcm_playback_efx_substream
= substream
;
1106 runtime
->private_data
= epcm
;
1107 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1108 runtime
->hw
= snd_emu10k1_efx_playback
;
1110 for (i
= 0; i
< NUM_EFX_PLAYBACK
; i
++) {
1111 mix
= &emu
->efx_pcm_mixer
[i
];
1112 mix
->send_routing
[0][0] = i
;
1113 memset(&mix
->send_volume
, 0, sizeof(mix
->send_volume
));
1114 mix
->send_volume
[0][0] = 255;
1115 mix
->attn
[0] = 0xffff;
1117 snd_emu10k1_pcm_efx_mixer_notify(emu
, i
, 1);
1122 static int snd_emu10k1_playback_open(struct snd_pcm_substream
*substream
)
1124 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1125 struct snd_emu10k1_pcm
*epcm
;
1126 struct snd_emu10k1_pcm_mixer
*mix
;
1127 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1128 int i
, err
, sample_rate
;
1130 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1134 epcm
->type
= PLAYBACK_EMUVOICE
;
1135 epcm
->substream
= substream
;
1136 runtime
->private_data
= epcm
;
1137 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1138 runtime
->hw
= snd_emu10k1_playback
;
1139 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0) {
1143 if ((err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 256, UINT_MAX
)) < 0) {
1147 if (emu
->card_capabilities
->emu_model
&& emu
->emu1010
.internal_clock
== 0)
1148 sample_rate
= 44100;
1150 sample_rate
= 48000;
1151 err
= snd_pcm_hw_rule_noresample(runtime
, sample_rate
);
1156 mix
= &emu
->pcm_mixer
[substream
->number
];
1157 for (i
= 0; i
< 4; i
++)
1158 mix
->send_routing
[0][i
] = mix
->send_routing
[1][i
] = mix
->send_routing
[2][i
] = i
;
1159 memset(&mix
->send_volume
, 0, sizeof(mix
->send_volume
));
1160 mix
->send_volume
[0][0] = mix
->send_volume
[0][1] =
1161 mix
->send_volume
[1][0] = mix
->send_volume
[2][1] = 255;
1162 mix
->attn
[0] = mix
->attn
[1] = mix
->attn
[2] = 0xffff;
1164 snd_emu10k1_pcm_mixer_notify(emu
, substream
->number
, 1);
1168 static int snd_emu10k1_playback_close(struct snd_pcm_substream
*substream
)
1170 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1171 struct snd_emu10k1_pcm_mixer
*mix
= &emu
->pcm_mixer
[substream
->number
];
1174 snd_emu10k1_pcm_mixer_notify(emu
, substream
->number
, 0);
1178 static int snd_emu10k1_capture_open(struct snd_pcm_substream
*substream
)
1180 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1181 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1182 struct snd_emu10k1_pcm
*epcm
;
1184 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1188 epcm
->type
= CAPTURE_AC97ADC
;
1189 epcm
->substream
= substream
;
1190 epcm
->capture_ipr
= IPR_ADCBUFFULL
|IPR_ADCBUFHALFFULL
;
1191 epcm
->capture_inte
= INTE_ADCBUFENABLE
;
1192 epcm
->capture_ba_reg
= ADCBA
;
1193 epcm
->capture_bs_reg
= ADCBS
;
1194 epcm
->capture_idx_reg
= emu
->audigy
? A_ADCIDX
: ADCIDX
;
1195 runtime
->private_data
= epcm
;
1196 runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1197 runtime
->hw
= snd_emu10k1_capture
;
1198 emu
->capture_interrupt
= snd_emu10k1_pcm_ac97adc_interrupt
;
1199 emu
->pcm_capture_substream
= substream
;
1200 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1201 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_capture_rates
);
1205 static int snd_emu10k1_capture_close(struct snd_pcm_substream
*substream
)
1207 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1209 emu
->capture_interrupt
= NULL
;
1210 emu
->pcm_capture_substream
= NULL
;
1214 static int snd_emu10k1_capture_mic_open(struct snd_pcm_substream
*substream
)
1216 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1217 struct snd_emu10k1_pcm
*epcm
;
1218 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1220 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1224 epcm
->type
= CAPTURE_AC97MIC
;
1225 epcm
->substream
= substream
;
1226 epcm
->capture_ipr
= IPR_MICBUFFULL
|IPR_MICBUFHALFFULL
;
1227 epcm
->capture_inte
= INTE_MICBUFENABLE
;
1228 epcm
->capture_ba_reg
= MICBA
;
1229 epcm
->capture_bs_reg
= MICBS
;
1230 epcm
->capture_idx_reg
= emu
->audigy
? A_MICIDX
: MICIDX
;
1231 substream
->runtime
->private_data
= epcm
;
1232 substream
->runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1233 runtime
->hw
= snd_emu10k1_capture
;
1234 runtime
->hw
.rates
= SNDRV_PCM_RATE_8000
;
1235 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 8000;
1236 runtime
->hw
.channels_min
= 1;
1237 emu
->capture_mic_interrupt
= snd_emu10k1_pcm_ac97mic_interrupt
;
1238 emu
->pcm_capture_mic_substream
= substream
;
1239 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1243 static int snd_emu10k1_capture_mic_close(struct snd_pcm_substream
*substream
)
1245 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1247 emu
->capture_interrupt
= NULL
;
1248 emu
->pcm_capture_mic_substream
= NULL
;
1252 static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream
*substream
)
1254 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1255 struct snd_emu10k1_pcm
*epcm
;
1256 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1257 int nefx
= emu
->audigy
? 64 : 32;
1260 epcm
= kzalloc(sizeof(*epcm
), GFP_KERNEL
);
1264 epcm
->type
= CAPTURE_EFX
;
1265 epcm
->substream
= substream
;
1266 epcm
->capture_ipr
= IPR_EFXBUFFULL
|IPR_EFXBUFHALFFULL
;
1267 epcm
->capture_inte
= INTE_EFXBUFENABLE
;
1268 epcm
->capture_ba_reg
= FXBA
;
1269 epcm
->capture_bs_reg
= FXBS
;
1270 epcm
->capture_idx_reg
= FXIDX
;
1271 substream
->runtime
->private_data
= epcm
;
1272 substream
->runtime
->private_free
= snd_emu10k1_pcm_free_substream
;
1273 runtime
->hw
= snd_emu10k1_capture_efx
;
1274 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
1275 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 48000;
1276 spin_lock_irq(&emu
->reg_lock
);
1277 if (emu
->card_capabilities
->emu_model
) {
1278 /* Nb. of channels has been increased to 16 */
1280 * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE
1281 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
1282 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
1283 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000
1285 * rate_max = 192000,
1286 * channels_min = 16,
1287 * channels_max = 16,
1288 * Need to add mixer control to fix sample rate
1290 * There are 32 mono channels of 16bits each.
1291 * 24bit Audio uses 2x channels over 16bit
1292 * 96kHz uses 2x channels over 48kHz
1293 * 192kHz uses 4x channels over 48kHz
1294 * So, for 48kHz 24bit, one has 16 channels
1295 * for 96kHz 24bit, one has 8 channels
1296 * for 192kHz 24bit, one has 4 channels
1300 switch (emu
->emu1010
.internal_clock
) {
1303 runtime
->hw
.rates
= SNDRV_PCM_RATE_44100
;
1304 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 44100;
1305 runtime
->hw
.channels_min
=
1306 runtime
->hw
.channels_max
= 16;
1310 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
1311 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 48000;
1312 runtime
->hw
.channels_min
=
1313 runtime
->hw
.channels_max
= 16;
1319 runtime
->hw
.rates
= SNDRV_PCM_RATE_96000
;
1320 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 96000;
1321 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 4;
1325 runtime
->hw
.rates
= SNDRV_PCM_RATE_192000
;
1326 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= 192000;
1327 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 2;
1329 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S32_LE
;
1330 /* efx_voices_mask[0] is expected to be zero
1331 * efx_voices_mask[1] is expected to have 32bits set
1334 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= 0;
1335 for (idx
= 0; idx
< nefx
; idx
++) {
1336 if (emu
->efx_voices_mask
[idx
/32] & (1 << (idx
%32))) {
1337 runtime
->hw
.channels_min
++;
1338 runtime
->hw
.channels_max
++;
1342 epcm
->capture_cr_val
= emu
->efx_voices_mask
[0];
1343 epcm
->capture_cr_val2
= emu
->efx_voices_mask
[1];
1344 spin_unlock_irq(&emu
->reg_lock
);
1345 emu
->capture_efx_interrupt
= snd_emu10k1_pcm_efx_interrupt
;
1346 emu
->pcm_capture_efx_substream
= substream
;
1347 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, &hw_constraints_capture_period_sizes
);
1351 static int snd_emu10k1_capture_efx_close(struct snd_pcm_substream
*substream
)
1353 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1355 emu
->capture_interrupt
= NULL
;
1356 emu
->pcm_capture_efx_substream
= NULL
;
1360 static const struct snd_pcm_ops snd_emu10k1_playback_ops
= {
1361 .open
= snd_emu10k1_playback_open
,
1362 .close
= snd_emu10k1_playback_close
,
1363 .ioctl
= snd_pcm_lib_ioctl
,
1364 .hw_params
= snd_emu10k1_playback_hw_params
,
1365 .hw_free
= snd_emu10k1_playback_hw_free
,
1366 .prepare
= snd_emu10k1_playback_prepare
,
1367 .trigger
= snd_emu10k1_playback_trigger
,
1368 .pointer
= snd_emu10k1_playback_pointer
,
1369 .page
= snd_pcm_sgbuf_ops_page
,
1372 static const struct snd_pcm_ops snd_emu10k1_capture_ops
= {
1373 .open
= snd_emu10k1_capture_open
,
1374 .close
= snd_emu10k1_capture_close
,
1375 .ioctl
= snd_pcm_lib_ioctl
,
1376 .hw_params
= snd_emu10k1_capture_hw_params
,
1377 .hw_free
= snd_emu10k1_capture_hw_free
,
1378 .prepare
= snd_emu10k1_capture_prepare
,
1379 .trigger
= snd_emu10k1_capture_trigger
,
1380 .pointer
= snd_emu10k1_capture_pointer
,
1384 static const struct snd_pcm_ops snd_emu10k1_efx_playback_ops
= {
1385 .open
= snd_emu10k1_efx_playback_open
,
1386 .close
= snd_emu10k1_efx_playback_close
,
1387 .ioctl
= snd_pcm_lib_ioctl
,
1388 .hw_params
= snd_emu10k1_playback_hw_params
,
1389 .hw_free
= snd_emu10k1_efx_playback_hw_free
,
1390 .prepare
= snd_emu10k1_efx_playback_prepare
,
1391 .trigger
= snd_emu10k1_efx_playback_trigger
,
1392 .pointer
= snd_emu10k1_efx_playback_pointer
,
1393 .page
= snd_pcm_sgbuf_ops_page
,
1396 int snd_emu10k1_pcm(struct snd_emu10k1
*emu
, int device
)
1398 struct snd_pcm
*pcm
;
1399 struct snd_pcm_substream
*substream
;
1402 if ((err
= snd_pcm_new(emu
->card
, "emu10k1", device
, 32, 1, &pcm
)) < 0)
1405 pcm
->private_data
= emu
;
1407 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_playback_ops
);
1408 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_ops
);
1410 pcm
->info_flags
= 0;
1411 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1412 strcpy(pcm
->name
, "ADC Capture/Standard PCM Playback");
1415 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
1416 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
,
1417 snd_dma_pci_data(emu
->pci
),
1420 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
; substream
; substream
= substream
->next
)
1421 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV
,
1422 snd_dma_pci_data(emu
->pci
),
1428 int snd_emu10k1_pcm_multi(struct snd_emu10k1
*emu
, int device
)
1430 struct snd_pcm
*pcm
;
1431 struct snd_pcm_substream
*substream
;
1434 if ((err
= snd_pcm_new(emu
->card
, "emu10k1", device
, 1, 0, &pcm
)) < 0)
1437 pcm
->private_data
= emu
;
1439 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_emu10k1_efx_playback_ops
);
1441 pcm
->info_flags
= 0;
1442 pcm
->dev_subclass
= SNDRV_PCM_SUBCLASS_GENERIC_MIX
;
1443 strcpy(pcm
->name
, "Multichannel Playback");
1444 emu
->pcm_multi
= pcm
;
1446 for (substream
= pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
; substream
; substream
= substream
->next
)
1447 snd_pcm_lib_preallocate_pages(substream
, SNDRV_DMA_TYPE_DEV_SG
,
1448 snd_dma_pci_data(emu
->pci
),
1455 static const struct snd_pcm_ops snd_emu10k1_capture_mic_ops
= {
1456 .open
= snd_emu10k1_capture_mic_open
,
1457 .close
= snd_emu10k1_capture_mic_close
,
1458 .ioctl
= snd_pcm_lib_ioctl
,
1459 .hw_params
= snd_emu10k1_capture_hw_params
,
1460 .hw_free
= snd_emu10k1_capture_hw_free
,
1461 .prepare
= snd_emu10k1_capture_prepare
,
1462 .trigger
= snd_emu10k1_capture_trigger
,
1463 .pointer
= snd_emu10k1_capture_pointer
,
1466 int snd_emu10k1_pcm_mic(struct snd_emu10k1
*emu
, int device
)
1468 struct snd_pcm
*pcm
;
1471 if ((err
= snd_pcm_new(emu
->card
, "emu10k1 mic", device
, 0, 1, &pcm
)) < 0)
1474 pcm
->private_data
= emu
;
1476 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_emu10k1_capture_mic_ops
);
1478 pcm
->info_flags
= 0;
1479 strcpy(pcm
->name
, "Mic Capture");
1482 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1483 snd_dma_pci_data(emu
->pci
),
1489 static int snd_emu10k1_pcm_efx_voices_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1491 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1492 int nefx
= emu
->audigy
? 64 : 32;
1493 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1494 uinfo
->count
= nefx
;
1495 uinfo
->value
.integer
.min
= 0;
1496 uinfo
->value
.integer
.max
= 1;
1500 static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1502 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1503 int nefx
= emu
->audigy
? 64 : 32;
1506 spin_lock_irq(&emu
->reg_lock
);
1507 for (idx
= 0; idx
< nefx
; idx
++)
1508 ucontrol
->value
.integer
.value
[idx
] = (emu
->efx_voices_mask
[idx
/ 32] & (1 << (idx
% 32))) ? 1 : 0;
1509 spin_unlock_irq(&emu
->reg_lock
);
1513 static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1515 struct snd_emu10k1
*emu
= snd_kcontrol_chip(kcontrol
);
1516 unsigned int nval
[2], bits
;
1517 int nefx
= emu
->audigy
? 64 : 32;
1518 int nefxb
= emu
->audigy
? 7 : 6;
1521 nval
[0] = nval
[1] = 0;
1522 for (idx
= 0, bits
= 0; idx
< nefx
; idx
++)
1523 if (ucontrol
->value
.integer
.value
[idx
]) {
1524 nval
[idx
/ 32] |= 1 << (idx
% 32);
1528 for (idx
= 0; idx
< nefxb
; idx
++)
1529 if (1 << idx
== bits
)
1535 spin_lock_irq(&emu
->reg_lock
);
1536 change
= (nval
[0] != emu
->efx_voices_mask
[0]) ||
1537 (nval
[1] != emu
->efx_voices_mask
[1]);
1538 emu
->efx_voices_mask
[0] = nval
[0];
1539 emu
->efx_voices_mask
[1] = nval
[1];
1540 spin_unlock_irq(&emu
->reg_lock
);
1544 static const struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask
= {
1545 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1546 .name
= "Captured FX8010 Outputs",
1547 .info
= snd_emu10k1_pcm_efx_voices_mask_info
,
1548 .get
= snd_emu10k1_pcm_efx_voices_mask_get
,
1549 .put
= snd_emu10k1_pcm_efx_voices_mask_put
1552 static const struct snd_pcm_ops snd_emu10k1_capture_efx_ops
= {
1553 .open
= snd_emu10k1_capture_efx_open
,
1554 .close
= snd_emu10k1_capture_efx_close
,
1555 .ioctl
= snd_pcm_lib_ioctl
,
1556 .hw_params
= snd_emu10k1_capture_hw_params
,
1557 .hw_free
= snd_emu10k1_capture_hw_free
,
1558 .prepare
= snd_emu10k1_capture_prepare
,
1559 .trigger
= snd_emu10k1_capture_trigger
,
1560 .pointer
= snd_emu10k1_capture_pointer
,
1566 #define INITIAL_TRAM_SHIFT 14
1567 #define INITIAL_TRAM_POS(size) ((((size) / 2) - INITIAL_TRAM_SHIFT) - 1)
1569 static void snd_emu10k1_fx8010_playback_irq(struct snd_emu10k1
*emu
, void *private_data
)
1571 struct snd_pcm_substream
*substream
= private_data
;
1572 snd_pcm_period_elapsed(substream
);
1575 static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left
,
1576 unsigned short *dst_right
,
1577 unsigned short *src
,
1579 unsigned int tram_shift
)
1582 dev_dbg(emu->card->dev,
1583 "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
1584 "src = 0x%p, count = 0x%x\n",
1585 dst_left, dst_right, src, count);
1587 if ((tram_shift
& 1) == 0) {
1589 *dst_left
-- = *src
++;
1590 *dst_right
-- = *src
++;
1594 *dst_right
-- = *src
++;
1595 *dst_left
-- = *src
++;
1600 static void fx8010_pb_trans_copy(struct snd_pcm_substream
*substream
,
1601 struct snd_pcm_indirect
*rec
, size_t bytes
)
1603 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1604 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1605 unsigned int tram_size
= pcm
->buffer_size
;
1606 unsigned short *src
= (unsigned short *)(substream
->runtime
->dma_area
+ rec
->sw_data
);
1607 unsigned int frames
= bytes
>> 2, count
;
1608 unsigned int tram_pos
= pcm
->tram_pos
;
1609 unsigned int tram_shift
= pcm
->tram_shift
;
1611 while (frames
> tram_pos
) {
1612 count
= tram_pos
+ 1;
1613 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
,
1614 (unsigned short *)emu
->fx8010
.etram_pages
.area
+ tram_pos
+ tram_size
/ 2,
1615 src
, count
, tram_shift
);
1618 tram_pos
= (tram_size
/ 2) - 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
, frames
, tram_shift
);
1625 pcm
->tram_pos
= tram_pos
;
1626 pcm
->tram_shift
= tram_shift
;
1629 static int snd_emu10k1_fx8010_playback_transfer(struct snd_pcm_substream
*substream
)
1631 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1632 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1634 return snd_pcm_indirect_playback_transfer(substream
, &pcm
->pcm_rec
,
1635 fx8010_pb_trans_copy
);
1638 static int snd_emu10k1_fx8010_playback_hw_params(struct snd_pcm_substream
*substream
,
1639 struct snd_pcm_hw_params
*hw_params
)
1641 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
1644 static int snd_emu10k1_fx8010_playback_hw_free(struct snd_pcm_substream
*substream
)
1646 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1647 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1650 for (i
= 0; i
< pcm
->channels
; i
++)
1651 snd_emu10k1_ptr_write(emu
, TANKMEMADDRREGBASE
+ 0x80 + pcm
->etram
[i
], 0, 0);
1652 snd_pcm_lib_free_pages(substream
);
1656 static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream
*substream
)
1658 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1659 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1660 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1664 dev_dbg(emu->card->dev, "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
1665 "buffer_size = 0x%x (0x%x)\n",
1666 emu->fx8010.etram_pages, runtime->dma_area,
1667 runtime->buffer_size, runtime->buffer_size << 2);
1669 memset(&pcm
->pcm_rec
, 0, sizeof(pcm
->pcm_rec
));
1670 pcm
->pcm_rec
.hw_buffer_size
= pcm
->buffer_size
* 2; /* byte size */
1671 pcm
->pcm_rec
.sw_buffer_size
= snd_pcm_lib_buffer_bytes(substream
);
1672 pcm
->tram_pos
= INITIAL_TRAM_POS(pcm
->buffer_size
);
1673 pcm
->tram_shift
= 0;
1674 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_running
, 0, 0); /* reset */
1675 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 0); /* reset */
1676 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_size
, 0, runtime
->buffer_size
);
1677 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_ptr
, 0, 0); /* reset ptr number */
1678 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_count
, 0, runtime
->period_size
);
1679 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_tmpcount
, 0, runtime
->period_size
);
1680 for (i
= 0; i
< pcm
->channels
; i
++)
1681 snd_emu10k1_ptr_write(emu
, TANKMEMADDRREGBASE
+ 0x80 + pcm
->etram
[i
], 0, (TANKMEMADDRREG_READ
|TANKMEMADDRREG_ALIGN
) + i
* (runtime
->buffer_size
/ pcm
->channels
));
1685 static int snd_emu10k1_fx8010_playback_trigger(struct snd_pcm_substream
*substream
, int cmd
)
1687 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1688 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1691 spin_lock(&emu
->reg_lock
);
1693 case SNDRV_PCM_TRIGGER_START
:
1695 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1696 case SNDRV_PCM_TRIGGER_RESUME
:
1697 #ifdef EMU10K1_SET_AC3_IEC958
1700 for (i
= 0; i
< 3; i
++) {
1702 bits
= SPCS_CLKACCY_1000PPM
| SPCS_SAMPLERATE_48
|
1703 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
| SPCS_GENERATIONSTATUS
|
1704 0x00001200 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
| SPCS_NOTAUDIODATA
;
1705 snd_emu10k1_ptr_write(emu
, SPCS0
+ i
, 0, bits
);
1709 result
= snd_emu10k1_fx8010_register_irq_handler(emu
, snd_emu10k1_fx8010_playback_irq
, pcm
->gpr_running
, substream
, &pcm
->irq
);
1712 snd_emu10k1_fx8010_playback_transfer(substream
); /* roll the ball */
1713 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 1);
1715 case SNDRV_PCM_TRIGGER_STOP
:
1716 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1717 case SNDRV_PCM_TRIGGER_SUSPEND
:
1718 snd_emu10k1_fx8010_unregister_irq_handler(emu
, &pcm
->irq
);
1719 snd_emu10k1_ptr_write(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0, 0);
1720 pcm
->tram_pos
= INITIAL_TRAM_POS(pcm
->buffer_size
);
1721 pcm
->tram_shift
= 0;
1728 spin_unlock(&emu
->reg_lock
);
1732 static snd_pcm_uframes_t
snd_emu10k1_fx8010_playback_pointer(struct snd_pcm_substream
*substream
)
1734 struct snd_emu10k1
*emu
= snd_pcm_substream_chip(substream
);
1735 struct snd_emu10k1_fx8010_pcm
*pcm
= &emu
->fx8010
.pcm
[substream
->number
];
1736 size_t ptr
; /* byte pointer */
1738 if (!snd_emu10k1_ptr_read(emu
, emu
->gpr_base
+ pcm
->gpr_trigger
, 0))
1740 ptr
= snd_emu10k1_ptr_read(emu
, emu
->gpr_base
+ pcm
->gpr_ptr
, 0) << 2;
1741 return snd_pcm_indirect_playback_pointer(substream
, &pcm
->pcm_rec
, ptr
);
1744 static const struct snd_pcm_hardware snd_emu10k1_fx8010_playback
=
1746 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1747 SNDRV_PCM_INFO_RESUME
|
1748 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE
|
1749 SNDRV_PCM_INFO_SYNC_APPLPTR
),
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 const 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 err
= snd_ctl_add(emu
->card
, kctl
);
1857 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1858 snd_dma_pci_data(emu
->pci
),