1 // SPDX-License-Identifier: GPL-2.0-only
3 * ALSA driver for Echoaudio soundcards.
4 * Copyright (C) 2003-2004 Giuliano Pochini <pochini@shiny.it>
5 * Copyright (C) 2020 Mark Hills <mark@xwax.org>
8 #include <linux/module.h>
10 MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>");
11 MODULE_LICENSE("GPL v2");
12 MODULE_DESCRIPTION("Echoaudio " ECHOCARD_NAME
" soundcards driver");
13 MODULE_DEVICE_TABLE(pci
, snd_echo_ids
);
15 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
16 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
17 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
19 module_param_array(index
, int, NULL
, 0444);
20 MODULE_PARM_DESC(index
, "Index value for " ECHOCARD_NAME
" soundcard.");
21 module_param_array(id
, charp
, NULL
, 0444);
22 MODULE_PARM_DESC(id
, "ID string for " ECHOCARD_NAME
" soundcard.");
23 module_param_array(enable
, bool, NULL
, 0444);
24 MODULE_PARM_DESC(enable
, "Enable " ECHOCARD_NAME
" soundcard.");
26 static const unsigned int channels_list
[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
27 static const DECLARE_TLV_DB_SCALE(db_scale_output_gain
, -12800, 100, 1);
31 static int get_firmware(const struct firmware
**fw_entry
,
32 struct echoaudio
*chip
, const short fw_index
)
37 if (chip
->fw_cache
[fw_index
]) {
38 dev_dbg(chip
->card
->dev
,
39 "firmware requested: %s is cached\n",
40 card_fw
[fw_index
].data
);
41 *fw_entry
= chip
->fw_cache
[fw_index
];
45 dev_dbg(chip
->card
->dev
,
46 "firmware requested: %s\n", card_fw
[fw_index
].data
);
47 snprintf(name
, sizeof(name
), "ea/%s", card_fw
[fw_index
].data
);
48 err
= request_firmware(fw_entry
, name
, &chip
->pci
->dev
);
50 dev_err(chip
->card
->dev
,
51 "get_firmware(): Firmware not available (%d)\n", err
);
53 chip
->fw_cache
[fw_index
] = *fw_entry
;
59 static void free_firmware(const struct firmware
*fw_entry
,
60 struct echoaudio
*chip
)
62 dev_dbg(chip
->card
->dev
, "firmware not released (kept in cache)\n");
67 static void free_firmware_cache(struct echoaudio
*chip
)
71 for (i
= 0; i
< 8 ; i
++)
72 if (chip
->fw_cache
[i
]) {
73 release_firmware(chip
->fw_cache
[i
]);
74 dev_dbg(chip
->card
->dev
, "release_firmware(%d)\n", i
);
80 /******************************************************************************
82 ******************************************************************************/
84 static void audiopipe_free(struct snd_pcm_runtime
*runtime
)
86 struct audiopipe
*pipe
= runtime
->private_data
;
88 if (pipe
->sgpage
.area
)
89 snd_dma_free_pages(&pipe
->sgpage
);
95 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params
*params
,
96 struct snd_pcm_hw_rule
*rule
)
98 struct snd_interval
*c
= hw_param_interval(params
,
99 SNDRV_PCM_HW_PARAM_CHANNELS
);
100 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
105 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
106 /* >=2 channels cannot be S32_BE */
108 fmt
.bits
[0] &= ~SNDRV_PCM_FMTBIT_S32_BE
;
109 return snd_mask_refine(f
, &fmt
);
112 /* > 2 channels cannot be U8 and S32_BE */
114 fmt
.bits
[0] &= ~(SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S32_BE
);
115 return snd_mask_refine(f
, &fmt
);
117 /* Mono is ok with any format */
123 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params
*params
,
124 struct snd_pcm_hw_rule
*rule
)
126 struct snd_interval
*c
= hw_param_interval(params
,
127 SNDRV_PCM_HW_PARAM_CHANNELS
);
128 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
129 struct snd_interval ch
;
131 snd_interval_any(&ch
);
133 /* S32_BE is mono (and stereo) only */
134 if (f
->bits
[0] == SNDRV_PCM_FMTBIT_S32_BE
) {
136 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
142 return snd_interval_refine(c
, &ch
);
144 /* U8 can be only mono or stereo */
145 if (f
->bits
[0] == SNDRV_PCM_FMTBIT_U8
) {
149 return snd_interval_refine(c
, &ch
);
151 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
157 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params
*params
,
158 struct snd_pcm_hw_rule
*rule
)
160 struct snd_interval
*c
= hw_param_interval(params
,
161 SNDRV_PCM_HW_PARAM_CHANNELS
);
162 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
167 fmask
= fmt
.bits
[0] + ((u64
)fmt
.bits
[1] << 32);
169 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
171 fmask
&= SNDRV_PCM_FMTBIT_S16_LE
|
172 SNDRV_PCM_FMTBIT_S24_3LE
|
173 SNDRV_PCM_FMTBIT_S32_LE
;
174 /* 1 channel must be S32_BE or S32_LE */
175 } else if (c
->max
== 1)
176 fmask
&= SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
;
177 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
178 /* 2 channels cannot be S32_BE */
179 else if (c
->min
== 2 && c
->max
== 2)
180 fmask
&= ~SNDRV_PCM_FMTBIT_S32_BE
;
185 fmt
.bits
[0] &= (u32
)fmask
;
186 fmt
.bits
[1] &= (u32
)(fmask
>> 32);
187 return snd_mask_refine(f
, &fmt
);
192 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params
*params
,
193 struct snd_pcm_hw_rule
*rule
)
195 struct snd_interval
*c
= hw_param_interval(params
,
196 SNDRV_PCM_HW_PARAM_CHANNELS
);
197 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
198 struct snd_interval ch
;
201 snd_interval_any(&ch
);
203 fmask
= f
->bits
[0] + ((u64
)f
->bits
[1] << 32);
205 /* S32_BE is mono (and stereo) only */
206 if (fmask
== SNDRV_PCM_FMTBIT_S32_BE
) {
208 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
213 /* U8 is stereo only */
214 } else if (fmask
== SNDRV_PCM_FMTBIT_U8
)
216 /* S16_LE and S24_3LE must be at least stereo */
217 else if (!(fmask
& ~(SNDRV_PCM_FMTBIT_S16_LE
|
218 SNDRV_PCM_FMTBIT_S24_3LE
)))
223 return snd_interval_refine(c
, &ch
);
228 /* Since the sample rate is a global setting, do allow the user to change the
229 sample rate only if there is only one pcm device open. */
230 static int hw_rule_sample_rate(struct snd_pcm_hw_params
*params
,
231 struct snd_pcm_hw_rule
*rule
)
233 struct snd_interval
*rate
= hw_param_interval(params
,
234 SNDRV_PCM_HW_PARAM_RATE
);
235 struct echoaudio
*chip
= rule
->private;
236 struct snd_interval fixed
;
239 mutex_lock(&chip
->mode_mutex
);
241 if (chip
->can_set_rate
) {
244 snd_interval_any(&fixed
);
245 fixed
.min
= fixed
.max
= chip
->sample_rate
;
246 err
= snd_interval_refine(rate
, &fixed
);
249 mutex_unlock(&chip
->mode_mutex
);
254 static int pcm_open(struct snd_pcm_substream
*substream
,
255 signed char max_channels
)
257 struct echoaudio
*chip
;
258 struct snd_pcm_runtime
*runtime
;
259 struct audiopipe
*pipe
;
262 if (max_channels
<= 0)
265 chip
= snd_pcm_substream_chip(substream
);
266 runtime
= substream
->runtime
;
268 pipe
= kzalloc(sizeof(struct audiopipe
), GFP_KERNEL
);
271 pipe
->index
= -1; /* Not configured yet */
273 /* Set up hw capabilities and contraints */
274 memcpy(&pipe
->hw
, &pcm_hardware_skel
, sizeof(struct snd_pcm_hardware
));
275 dev_dbg(chip
->card
->dev
, "max_channels=%d\n", max_channels
);
276 pipe
->constr
.list
= channels_list
;
277 pipe
->constr
.mask
= 0;
278 for (i
= 0; channels_list
[i
] <= max_channels
; i
++);
279 pipe
->constr
.count
= i
;
280 if (pipe
->hw
.channels_max
> max_channels
)
281 pipe
->hw
.channels_max
= max_channels
;
282 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
) {
283 pipe
->hw
.rate_max
= 48000;
284 pipe
->hw
.rates
&= SNDRV_PCM_RATE_8000_48000
;
287 runtime
->hw
= pipe
->hw
;
288 runtime
->private_data
= pipe
;
289 runtime
->private_free
= audiopipe_free
;
290 snd_pcm_set_sync(substream
);
292 /* Only mono and any even number of channels are allowed */
293 err
= snd_pcm_hw_constraint_list(runtime
, 0,
294 SNDRV_PCM_HW_PARAM_CHANNELS
,
299 /* All periods should have the same size */
300 err
= snd_pcm_hw_constraint_integer(runtime
,
301 SNDRV_PCM_HW_PARAM_PERIODS
);
305 /* The hw accesses memory in chunks 32 frames long and they should be
306 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
307 generated with a resolution of 32 frames. Thus we need the following */
308 err
= snd_pcm_hw_constraint_step(runtime
, 0,
309 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, 32);
312 err
= snd_pcm_hw_constraint_step(runtime
, 0,
313 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, 32);
317 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
318 SNDRV_PCM_HW_PARAM_RATE
,
319 hw_rule_sample_rate
, chip
,
320 SNDRV_PCM_HW_PARAM_RATE
, -1);
324 /* Allocate a page for the scatter-gather list */
325 err
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
,
327 PAGE_SIZE
, &pipe
->sgpage
);
329 dev_err(chip
->card
->dev
, "s-g list allocation failed\n");
334 * Sole ownership required to set the rate
337 dev_dbg(chip
->card
->dev
, "pcm_open opencount=%d can_set_rate=%d, rate_set=%d",
338 chip
->opencount
, chip
->can_set_rate
, chip
->rate_set
);
341 if (chip
->opencount
> 1 && chip
->rate_set
)
342 chip
->can_set_rate
= 0;
349 static int pcm_analog_in_open(struct snd_pcm_substream
*substream
)
351 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
354 err
= pcm_open(substream
,
355 num_analog_busses_in(chip
) - substream
->number
);
358 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
359 SNDRV_PCM_HW_PARAM_CHANNELS
,
360 hw_rule_capture_channels_by_format
, NULL
,
361 SNDRV_PCM_HW_PARAM_FORMAT
, -1);
364 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
365 SNDRV_PCM_HW_PARAM_FORMAT
,
366 hw_rule_capture_format_by_channels
, NULL
,
367 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
376 static int pcm_analog_out_open(struct snd_pcm_substream
*substream
)
378 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
379 int max_channels
, err
;
381 #ifdef ECHOCARD_HAS_VMIXER
382 max_channels
= num_pipes_out(chip
);
384 max_channels
= num_analog_busses_out(chip
);
386 err
= pcm_open(substream
, max_channels
- substream
->number
);
389 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
390 SNDRV_PCM_HW_PARAM_CHANNELS
,
391 hw_rule_playback_channels_by_format
,
393 SNDRV_PCM_HW_PARAM_FORMAT
, -1);
396 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
397 SNDRV_PCM_HW_PARAM_FORMAT
,
398 hw_rule_playback_format_by_channels
,
400 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
409 #ifdef ECHOCARD_HAS_DIGITAL_IO
411 static int pcm_digital_in_open(struct snd_pcm_substream
*substream
)
413 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
414 int err
, max_channels
;
416 max_channels
= num_digital_busses_in(chip
) - substream
->number
;
417 mutex_lock(&chip
->mode_mutex
);
418 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
)
419 err
= pcm_open(substream
, max_channels
);
420 else /* If the card has ADAT, subtract the 6 channels
421 * that S/PDIF doesn't have
423 err
= pcm_open(substream
, max_channels
- ECHOCARD_HAS_ADAT
);
428 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
429 SNDRV_PCM_HW_PARAM_CHANNELS
,
430 hw_rule_capture_channels_by_format
, NULL
,
431 SNDRV_PCM_HW_PARAM_FORMAT
, -1);
434 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
435 SNDRV_PCM_HW_PARAM_FORMAT
,
436 hw_rule_capture_format_by_channels
, NULL
,
437 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
442 mutex_unlock(&chip
->mode_mutex
);
448 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
450 static int pcm_digital_out_open(struct snd_pcm_substream
*substream
)
452 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
453 int err
, max_channels
;
455 max_channels
= num_digital_busses_out(chip
) - substream
->number
;
456 mutex_lock(&chip
->mode_mutex
);
457 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
)
458 err
= pcm_open(substream
, max_channels
);
459 else /* If the card has ADAT, subtract the 6 channels
460 * that S/PDIF doesn't have
462 err
= pcm_open(substream
, max_channels
- ECHOCARD_HAS_ADAT
);
467 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
468 SNDRV_PCM_HW_PARAM_CHANNELS
,
469 hw_rule_playback_channels_by_format
,
470 NULL
, SNDRV_PCM_HW_PARAM_FORMAT
,
474 err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
475 SNDRV_PCM_HW_PARAM_FORMAT
,
476 hw_rule_playback_format_by_channels
,
477 NULL
, SNDRV_PCM_HW_PARAM_CHANNELS
,
483 mutex_unlock(&chip
->mode_mutex
);
487 #endif /* !ECHOCARD_HAS_VMIXER */
489 #endif /* ECHOCARD_HAS_DIGITAL_IO */
493 static int pcm_close(struct snd_pcm_substream
*substream
)
495 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
497 /* Nothing to do here. Audio is already off and pipe will be
498 * freed by its callback
501 mutex_lock(&chip
->mode_mutex
);
503 dev_dbg(chip
->card
->dev
, "pcm_open opencount=%d can_set_rate=%d, rate_set=%d",
504 chip
->opencount
, chip
->can_set_rate
, chip
->rate_set
);
508 switch (chip
->opencount
) {
510 chip
->can_set_rate
= 1;
518 mutex_unlock(&chip
->mode_mutex
);
524 /* Channel allocation and scatter-gather list setup */
525 static int init_engine(struct snd_pcm_substream
*substream
,
526 struct snd_pcm_hw_params
*hw_params
,
527 int pipe_index
, int interleave
)
529 struct echoaudio
*chip
;
530 int err
, per
, rest
, page
, edge
, offs
;
531 struct audiopipe
*pipe
;
533 chip
= snd_pcm_substream_chip(substream
);
534 pipe
= (struct audiopipe
*) substream
->runtime
->private_data
;
536 /* Sets up che hardware. If it's already initialized, reset and
537 * redo with the new parameters
539 spin_lock_irq(&chip
->lock
);
540 if (pipe
->index
>= 0) {
541 dev_dbg(chip
->card
->dev
, "hwp_ie free(%d)\n", pipe
->index
);
542 err
= free_pipes(chip
, pipe
);
544 chip
->substream
[pipe
->index
] = NULL
;
547 err
= allocate_pipes(chip
, pipe
, pipe_index
, interleave
);
549 spin_unlock_irq(&chip
->lock
);
550 dev_err(chip
->card
->dev
, "allocate_pipes(%d) err=%d\n",
554 spin_unlock_irq(&chip
->lock
);
555 dev_dbg(chip
->card
->dev
, "allocate_pipes()=%d\n", pipe_index
);
557 dev_dbg(chip
->card
->dev
,
558 "pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
559 params_buffer_bytes(hw_params
), params_periods(hw_params
),
560 params_period_bytes(hw_params
));
562 sglist_init(chip
, pipe
);
564 for (offs
= page
= per
= 0; offs
< params_buffer_bytes(hw_params
);
566 rest
= params_period_bytes(hw_params
);
567 if (offs
+ rest
> params_buffer_bytes(hw_params
))
568 rest
= params_buffer_bytes(hw_params
) - offs
;
571 addr
= snd_pcm_sgbuf_get_addr(substream
, offs
);
572 if (rest
<= edge
- offs
) {
573 sglist_add_mapping(chip
, pipe
, addr
, rest
);
574 sglist_add_irq(chip
, pipe
);
578 sglist_add_mapping(chip
, pipe
, addr
,
590 /* Close the ring buffer */
591 sglist_wrap(chip
, pipe
);
593 /* This stuff is used by the irq handler, so it must be
594 * initialized before chip->substream
596 pipe
->last_period
= 0;
597 pipe
->last_counter
= 0;
600 chip
->substream
[pipe_index
] = substream
;
602 spin_lock_irq(&chip
->lock
);
603 set_sample_rate(chip
, hw_params
->rate_num
/ hw_params
->rate_den
);
604 spin_unlock_irq(&chip
->lock
);
610 static int pcm_analog_in_hw_params(struct snd_pcm_substream
*substream
,
611 struct snd_pcm_hw_params
*hw_params
)
613 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
615 return init_engine(substream
, hw_params
, px_analog_in(chip
) +
616 substream
->number
, params_channels(hw_params
));
621 static int pcm_analog_out_hw_params(struct snd_pcm_substream
*substream
,
622 struct snd_pcm_hw_params
*hw_params
)
624 return init_engine(substream
, hw_params
, substream
->number
,
625 params_channels(hw_params
));
630 #ifdef ECHOCARD_HAS_DIGITAL_IO
632 static int pcm_digital_in_hw_params(struct snd_pcm_substream
*substream
,
633 struct snd_pcm_hw_params
*hw_params
)
635 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
637 return init_engine(substream
, hw_params
, px_digital_in(chip
) +
638 substream
->number
, params_channels(hw_params
));
643 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
644 static int pcm_digital_out_hw_params(struct snd_pcm_substream
*substream
,
645 struct snd_pcm_hw_params
*hw_params
)
647 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
649 return init_engine(substream
, hw_params
, px_digital_out(chip
) +
650 substream
->number
, params_channels(hw_params
));
652 #endif /* !ECHOCARD_HAS_VMIXER */
654 #endif /* ECHOCARD_HAS_DIGITAL_IO */
658 static int pcm_hw_free(struct snd_pcm_substream
*substream
)
660 struct echoaudio
*chip
;
661 struct audiopipe
*pipe
;
663 chip
= snd_pcm_substream_chip(substream
);
664 pipe
= (struct audiopipe
*) substream
->runtime
->private_data
;
666 spin_lock_irq(&chip
->lock
);
667 if (pipe
->index
>= 0) {
668 dev_dbg(chip
->card
->dev
, "pcm_hw_free(%d)\n", pipe
->index
);
669 free_pipes(chip
, pipe
);
670 chip
->substream
[pipe
->index
] = NULL
;
673 spin_unlock_irq(&chip
->lock
);
680 static int pcm_prepare(struct snd_pcm_substream
*substream
)
682 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
683 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
684 struct audioformat format
;
685 int pipe_index
= ((struct audiopipe
*)runtime
->private_data
)->index
;
687 dev_dbg(chip
->card
->dev
, "Prepare rate=%d format=%d channels=%d\n",
688 runtime
->rate
, runtime
->format
, runtime
->channels
);
689 format
.interleave
= runtime
->channels
;
690 format
.data_are_bigendian
= 0;
691 format
.mono_to_stereo
= 0;
692 switch (runtime
->format
) {
693 case SNDRV_PCM_FORMAT_U8
:
694 format
.bits_per_sample
= 8;
696 case SNDRV_PCM_FORMAT_S16_LE
:
697 format
.bits_per_sample
= 16;
699 case SNDRV_PCM_FORMAT_S24_3LE
:
700 format
.bits_per_sample
= 24;
702 case SNDRV_PCM_FORMAT_S32_BE
:
703 format
.data_are_bigendian
= 1;
705 case SNDRV_PCM_FORMAT_S32_LE
:
706 format
.bits_per_sample
= 32;
709 dev_err(chip
->card
->dev
,
710 "Prepare error: unsupported format %d\n",
715 if (snd_BUG_ON(pipe_index
>= px_num(chip
)))
719 * We passed checks we can do independently; now take
723 spin_lock_irq(&chip
->lock
);
725 if (snd_BUG_ON(!is_pipe_allocated(chip
, pipe_index
))) {
726 spin_unlock_irq(&chip
->lock
);
730 set_audio_format(chip
, pipe_index
, &format
);
731 spin_unlock_irq(&chip
->lock
);
738 static int pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
740 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
741 struct audiopipe
*pipe
;
744 struct snd_pcm_substream
*s
;
746 snd_pcm_group_for_each_entry(s
, substream
) {
747 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
748 if (s
== chip
->substream
[i
]) {
749 channelmask
|= 1 << i
;
750 snd_pcm_trigger_done(s
, substream
);
755 spin_lock(&chip
->lock
);
757 case SNDRV_PCM_TRIGGER_RESUME
:
758 case SNDRV_PCM_TRIGGER_START
:
759 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
760 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
761 if (channelmask
& (1 << i
)) {
762 pipe
= chip
->substream
[i
]->runtime
->private_data
;
763 switch (pipe
->state
) {
764 case PIPE_STATE_STOPPED
:
765 pipe
->last_period
= 0;
766 pipe
->last_counter
= 0;
768 *pipe
->dma_counter
= 0;
770 case PIPE_STATE_PAUSED
:
771 pipe
->state
= PIPE_STATE_STARTED
;
773 case PIPE_STATE_STARTED
:
778 err
= start_transport(chip
, channelmask
,
779 chip
->pipe_cyclic_mask
);
781 case SNDRV_PCM_TRIGGER_SUSPEND
:
782 case SNDRV_PCM_TRIGGER_STOP
:
783 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
784 if (channelmask
& (1 << i
)) {
785 pipe
= chip
->substream
[i
]->runtime
->private_data
;
786 pipe
->state
= PIPE_STATE_STOPPED
;
789 err
= stop_transport(chip
, channelmask
);
791 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
792 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
793 if (channelmask
& (1 << i
)) {
794 pipe
= chip
->substream
[i
]->runtime
->private_data
;
795 pipe
->state
= PIPE_STATE_PAUSED
;
798 err
= pause_transport(chip
, channelmask
);
803 spin_unlock(&chip
->lock
);
809 static snd_pcm_uframes_t
pcm_pointer(struct snd_pcm_substream
*substream
)
811 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
812 struct audiopipe
*pipe
= runtime
->private_data
;
816 * IRQ handling runs concurrently. Do not share tracking of
817 * counter with it, which would race or require locking
820 counter
= le32_to_cpu(*pipe
->dma_counter
); /* presumed atomic */
822 step
= counter
- pipe
->last_counter
; /* handles wrapping */
823 pipe
->last_counter
= counter
;
825 /* counter doesn't neccessarily wrap on a multiple of
826 * buffer_size, so can't derive the position; must
829 pipe
->position
+= step
;
830 pipe
->position
%= frames_to_bytes(runtime
, runtime
->buffer_size
); /* wrap */
832 return bytes_to_frames(runtime
, pipe
->position
);
837 /* pcm *_ops structures */
838 static const struct snd_pcm_ops analog_playback_ops
= {
839 .open
= pcm_analog_out_open
,
841 .hw_params
= pcm_analog_out_hw_params
,
842 .hw_free
= pcm_hw_free
,
843 .prepare
= pcm_prepare
,
844 .trigger
= pcm_trigger
,
845 .pointer
= pcm_pointer
,
847 static const struct snd_pcm_ops analog_capture_ops
= {
848 .open
= pcm_analog_in_open
,
850 .hw_params
= pcm_analog_in_hw_params
,
851 .hw_free
= pcm_hw_free
,
852 .prepare
= pcm_prepare
,
853 .trigger
= pcm_trigger
,
854 .pointer
= pcm_pointer
,
856 #ifdef ECHOCARD_HAS_DIGITAL_IO
857 #ifndef ECHOCARD_HAS_VMIXER
858 static const struct snd_pcm_ops digital_playback_ops
= {
859 .open
= pcm_digital_out_open
,
861 .hw_params
= pcm_digital_out_hw_params
,
862 .hw_free
= pcm_hw_free
,
863 .prepare
= pcm_prepare
,
864 .trigger
= pcm_trigger
,
865 .pointer
= pcm_pointer
,
867 #endif /* !ECHOCARD_HAS_VMIXER */
868 static const struct snd_pcm_ops digital_capture_ops
= {
869 .open
= pcm_digital_in_open
,
871 .hw_params
= pcm_digital_in_hw_params
,
872 .hw_free
= pcm_hw_free
,
873 .prepare
= pcm_prepare
,
874 .trigger
= pcm_trigger
,
875 .pointer
= pcm_pointer
,
877 #endif /* ECHOCARD_HAS_DIGITAL_IO */
881 /* Preallocate memory only for the first substream because it's the most
884 static void snd_echo_preallocate_pages(struct snd_pcm
*pcm
, struct device
*dev
)
886 struct snd_pcm_substream
*ss
;
889 for (stream
= 0; stream
< 2; stream
++)
890 for (ss
= pcm
->streams
[stream
].substream
; ss
; ss
= ss
->next
)
891 snd_pcm_set_managed_buffer(ss
, SNDRV_DMA_TYPE_DEV_SG
,
893 ss
->number
? 0 : 128<<10,
899 /*<--snd_echo_probe() */
900 static int snd_echo_new_pcm(struct echoaudio
*chip
)
905 #ifdef ECHOCARD_HAS_VMIXER
906 /* This card has a Vmixer, that is there is no direct mapping from PCM
907 streams to physical outputs. The user can mix the streams as he wishes
908 via control interface and it's possible to send any stream to any
909 output, thus it makes no sense to keep analog and digital outputs
912 /* PCM#0 Virtual outputs and analog inputs */
913 err
= snd_pcm_new(chip
->card
, "PCM", 0, num_pipes_out(chip
),
914 num_analog_busses_in(chip
), &pcm
);
917 pcm
->private_data
= chip
;
918 chip
->analog_pcm
= pcm
;
919 strcpy(pcm
->name
, chip
->card
->shortname
);
920 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &analog_playback_ops
);
921 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &analog_capture_ops
);
922 snd_echo_preallocate_pages(pcm
, &chip
->pci
->dev
);
924 #ifdef ECHOCARD_HAS_DIGITAL_IO
925 /* PCM#1 Digital inputs, no outputs */
926 err
= snd_pcm_new(chip
->card
, "Digital PCM", 1, 0,
927 num_digital_busses_in(chip
), &pcm
);
930 pcm
->private_data
= chip
;
931 chip
->digital_pcm
= pcm
;
932 strcpy(pcm
->name
, chip
->card
->shortname
);
933 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &digital_capture_ops
);
934 snd_echo_preallocate_pages(pcm
, &chip
->pci
->dev
);
935 #endif /* ECHOCARD_HAS_DIGITAL_IO */
937 #else /* ECHOCARD_HAS_VMIXER */
939 /* The card can manage substreams formed by analog and digital channels
940 at the same time, but I prefer to keep analog and digital channels
941 separated, because that mixed thing is confusing and useless. So we
942 register two PCM devices: */
944 /* PCM#0 Analog i/o */
945 err
= snd_pcm_new(chip
->card
, "Analog PCM", 0,
946 num_analog_busses_out(chip
),
947 num_analog_busses_in(chip
), &pcm
);
950 pcm
->private_data
= chip
;
951 chip
->analog_pcm
= pcm
;
952 strcpy(pcm
->name
, chip
->card
->shortname
);
953 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &analog_playback_ops
);
954 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &analog_capture_ops
);
955 snd_echo_preallocate_pages(pcm
, &chip
->pci
->dev
);
957 #ifdef ECHOCARD_HAS_DIGITAL_IO
958 /* PCM#1 Digital i/o */
959 err
= snd_pcm_new(chip
->card
, "Digital PCM", 1,
960 num_digital_busses_out(chip
),
961 num_digital_busses_in(chip
), &pcm
);
964 pcm
->private_data
= chip
;
965 chip
->digital_pcm
= pcm
;
966 strcpy(pcm
->name
, chip
->card
->shortname
);
967 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &digital_playback_ops
);
968 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &digital_capture_ops
);
969 snd_echo_preallocate_pages(pcm
, &chip
->pci
->dev
);
970 #endif /* ECHOCARD_HAS_DIGITAL_IO */
972 #endif /* ECHOCARD_HAS_VMIXER */
980 /******************************************************************************
982 ******************************************************************************/
984 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
986 /******************* PCM output volume *******************/
987 static int snd_echo_output_gain_info(struct snd_kcontrol
*kcontrol
,
988 struct snd_ctl_elem_info
*uinfo
)
990 struct echoaudio
*chip
;
992 chip
= snd_kcontrol_chip(kcontrol
);
993 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
994 uinfo
->count
= num_busses_out(chip
);
995 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
996 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1000 static int snd_echo_output_gain_get(struct snd_kcontrol
*kcontrol
,
1001 struct snd_ctl_elem_value
*ucontrol
)
1003 struct echoaudio
*chip
;
1006 chip
= snd_kcontrol_chip(kcontrol
);
1007 for (c
= 0; c
< num_busses_out(chip
); c
++)
1008 ucontrol
->value
.integer
.value
[c
] = chip
->output_gain
[c
];
1012 static int snd_echo_output_gain_put(struct snd_kcontrol
*kcontrol
,
1013 struct snd_ctl_elem_value
*ucontrol
)
1015 struct echoaudio
*chip
;
1016 int c
, changed
, gain
;
1019 chip
= snd_kcontrol_chip(kcontrol
);
1020 spin_lock_irq(&chip
->lock
);
1021 for (c
= 0; c
< num_busses_out(chip
); c
++) {
1022 gain
= ucontrol
->value
.integer
.value
[c
];
1023 /* Ignore out of range values */
1024 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1026 if (chip
->output_gain
[c
] != gain
) {
1027 set_output_gain(chip
, c
, gain
);
1032 update_output_line_level(chip
);
1033 spin_unlock_irq(&chip
->lock
);
1037 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1038 /* On the Mia this one controls the line-out volume */
1039 static const struct snd_kcontrol_new snd_echo_line_output_gain
= {
1040 .name
= "Line Playback Volume",
1041 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1042 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1043 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1044 .info
= snd_echo_output_gain_info
,
1045 .get
= snd_echo_output_gain_get
,
1046 .put
= snd_echo_output_gain_put
,
1047 .tlv
= {.p
= db_scale_output_gain
},
1050 static const struct snd_kcontrol_new snd_echo_pcm_output_gain
= {
1051 .name
= "PCM Playback Volume",
1052 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1053 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1054 .info
= snd_echo_output_gain_info
,
1055 .get
= snd_echo_output_gain_get
,
1056 .put
= snd_echo_output_gain_put
,
1057 .tlv
= {.p
= db_scale_output_gain
},
1061 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1065 #ifdef ECHOCARD_HAS_INPUT_GAIN
1067 /******************* Analog input volume *******************/
1068 static int snd_echo_input_gain_info(struct snd_kcontrol
*kcontrol
,
1069 struct snd_ctl_elem_info
*uinfo
)
1071 struct echoaudio
*chip
;
1073 chip
= snd_kcontrol_chip(kcontrol
);
1074 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1075 uinfo
->count
= num_analog_busses_in(chip
);
1076 uinfo
->value
.integer
.min
= ECHOGAIN_MININP
;
1077 uinfo
->value
.integer
.max
= ECHOGAIN_MAXINP
;
1081 static int snd_echo_input_gain_get(struct snd_kcontrol
*kcontrol
,
1082 struct snd_ctl_elem_value
*ucontrol
)
1084 struct echoaudio
*chip
;
1087 chip
= snd_kcontrol_chip(kcontrol
);
1088 for (c
= 0; c
< num_analog_busses_in(chip
); c
++)
1089 ucontrol
->value
.integer
.value
[c
] = chip
->input_gain
[c
];
1093 static int snd_echo_input_gain_put(struct snd_kcontrol
*kcontrol
,
1094 struct snd_ctl_elem_value
*ucontrol
)
1096 struct echoaudio
*chip
;
1097 int c
, gain
, changed
;
1100 chip
= snd_kcontrol_chip(kcontrol
);
1101 spin_lock_irq(&chip
->lock
);
1102 for (c
= 0; c
< num_analog_busses_in(chip
); c
++) {
1103 gain
= ucontrol
->value
.integer
.value
[c
];
1104 /* Ignore out of range values */
1105 if (gain
< ECHOGAIN_MININP
|| gain
> ECHOGAIN_MAXINP
)
1107 if (chip
->input_gain
[c
] != gain
) {
1108 set_input_gain(chip
, c
, gain
);
1113 update_input_line_level(chip
);
1114 spin_unlock_irq(&chip
->lock
);
1118 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain
, -2500, 50, 0);
1120 static const struct snd_kcontrol_new snd_echo_line_input_gain
= {
1121 .name
= "Line Capture Volume",
1122 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1123 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1124 .info
= snd_echo_input_gain_info
,
1125 .get
= snd_echo_input_gain_get
,
1126 .put
= snd_echo_input_gain_put
,
1127 .tlv
= {.p
= db_scale_input_gain
},
1130 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1134 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1136 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1137 static int snd_echo_output_nominal_info (struct snd_kcontrol
*kcontrol
,
1138 struct snd_ctl_elem_info
*uinfo
)
1140 struct echoaudio
*chip
;
1142 chip
= snd_kcontrol_chip(kcontrol
);
1143 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1144 uinfo
->count
= num_analog_busses_out(chip
);
1145 uinfo
->value
.integer
.min
= 0;
1146 uinfo
->value
.integer
.max
= 1;
1150 static int snd_echo_output_nominal_get(struct snd_kcontrol
*kcontrol
,
1151 struct snd_ctl_elem_value
*ucontrol
)
1153 struct echoaudio
*chip
;
1156 chip
= snd_kcontrol_chip(kcontrol
);
1157 for (c
= 0; c
< num_analog_busses_out(chip
); c
++)
1158 ucontrol
->value
.integer
.value
[c
] = chip
->nominal_level
[c
];
1162 static int snd_echo_output_nominal_put(struct snd_kcontrol
*kcontrol
,
1163 struct snd_ctl_elem_value
*ucontrol
)
1165 struct echoaudio
*chip
;
1169 chip
= snd_kcontrol_chip(kcontrol
);
1170 spin_lock_irq(&chip
->lock
);
1171 for (c
= 0; c
< num_analog_busses_out(chip
); c
++) {
1172 if (chip
->nominal_level
[c
] != ucontrol
->value
.integer
.value
[c
]) {
1173 set_nominal_level(chip
, c
,
1174 ucontrol
->value
.integer
.value
[c
]);
1179 update_output_line_level(chip
);
1180 spin_unlock_irq(&chip
->lock
);
1184 static const struct snd_kcontrol_new snd_echo_output_nominal_level
= {
1185 .name
= "Line Playback Switch (-10dBV)",
1186 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1187 .info
= snd_echo_output_nominal_info
,
1188 .get
= snd_echo_output_nominal_get
,
1189 .put
= snd_echo_output_nominal_put
,
1192 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1196 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1198 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1199 static int snd_echo_input_nominal_info(struct snd_kcontrol
*kcontrol
,
1200 struct snd_ctl_elem_info
*uinfo
)
1202 struct echoaudio
*chip
;
1204 chip
= snd_kcontrol_chip(kcontrol
);
1205 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1206 uinfo
->count
= num_analog_busses_in(chip
);
1207 uinfo
->value
.integer
.min
= 0;
1208 uinfo
->value
.integer
.max
= 1;
1212 static int snd_echo_input_nominal_get(struct snd_kcontrol
*kcontrol
,
1213 struct snd_ctl_elem_value
*ucontrol
)
1215 struct echoaudio
*chip
;
1218 chip
= snd_kcontrol_chip(kcontrol
);
1219 for (c
= 0; c
< num_analog_busses_in(chip
); c
++)
1220 ucontrol
->value
.integer
.value
[c
] =
1221 chip
->nominal_level
[bx_analog_in(chip
) + c
];
1225 static int snd_echo_input_nominal_put(struct snd_kcontrol
*kcontrol
,
1226 struct snd_ctl_elem_value
*ucontrol
)
1228 struct echoaudio
*chip
;
1232 chip
= snd_kcontrol_chip(kcontrol
);
1233 spin_lock_irq(&chip
->lock
);
1234 for (c
= 0; c
< num_analog_busses_in(chip
); c
++) {
1235 if (chip
->nominal_level
[bx_analog_in(chip
) + c
] !=
1236 ucontrol
->value
.integer
.value
[c
]) {
1237 set_nominal_level(chip
, bx_analog_in(chip
) + c
,
1238 ucontrol
->value
.integer
.value
[c
]);
1243 update_output_line_level(chip
); /* "Output" is not a mistake
1246 spin_unlock_irq(&chip
->lock
);
1250 static const struct snd_kcontrol_new snd_echo_intput_nominal_level
= {
1251 .name
= "Line Capture Switch (-10dBV)",
1252 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1253 .info
= snd_echo_input_nominal_info
,
1254 .get
= snd_echo_input_nominal_get
,
1255 .put
= snd_echo_input_nominal_put
,
1258 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1262 #ifdef ECHOCARD_HAS_MONITOR
1264 /******************* Monitor mixer *******************/
1265 static int snd_echo_mixer_info(struct snd_kcontrol
*kcontrol
,
1266 struct snd_ctl_elem_info
*uinfo
)
1268 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1270 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1271 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1275 static int snd_echo_mixer_get(struct snd_kcontrol
*kcontrol
,
1276 struct snd_ctl_elem_value
*ucontrol
)
1278 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1279 unsigned int out
= ucontrol
->id
.index
/ num_busses_in(chip
);
1280 unsigned int in
= ucontrol
->id
.index
% num_busses_in(chip
);
1282 if (out
>= ECHO_MAXAUDIOOUTPUTS
|| in
>= ECHO_MAXAUDIOINPUTS
)
1285 ucontrol
->value
.integer
.value
[0] = chip
->monitor_gain
[out
][in
];
1289 static int snd_echo_mixer_put(struct snd_kcontrol
*kcontrol
,
1290 struct snd_ctl_elem_value
*ucontrol
)
1292 struct echoaudio
*chip
;
1294 unsigned int out
, in
;
1297 chip
= snd_kcontrol_chip(kcontrol
);
1298 out
= ucontrol
->id
.index
/ num_busses_in(chip
);
1299 in
= ucontrol
->id
.index
% num_busses_in(chip
);
1300 if (out
>= ECHO_MAXAUDIOOUTPUTS
|| in
>= ECHO_MAXAUDIOINPUTS
)
1302 gain
= ucontrol
->value
.integer
.value
[0];
1303 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1305 if (chip
->monitor_gain
[out
][in
] != gain
) {
1306 spin_lock_irq(&chip
->lock
);
1307 set_monitor_gain(chip
, out
, in
, gain
);
1308 update_output_line_level(chip
);
1309 spin_unlock_irq(&chip
->lock
);
1315 static struct snd_kcontrol_new snd_echo_monitor_mixer
= {
1316 .name
= "Monitor Mixer Volume",
1317 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1318 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1319 .info
= snd_echo_mixer_info
,
1320 .get
= snd_echo_mixer_get
,
1321 .put
= snd_echo_mixer_put
,
1322 .tlv
= {.p
= db_scale_output_gain
},
1325 #endif /* ECHOCARD_HAS_MONITOR */
1329 #ifdef ECHOCARD_HAS_VMIXER
1331 /******************* Vmixer *******************/
1332 static int snd_echo_vmixer_info(struct snd_kcontrol
*kcontrol
,
1333 struct snd_ctl_elem_info
*uinfo
)
1335 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1337 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1338 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1342 static int snd_echo_vmixer_get(struct snd_kcontrol
*kcontrol
,
1343 struct snd_ctl_elem_value
*ucontrol
)
1345 struct echoaudio
*chip
;
1347 chip
= snd_kcontrol_chip(kcontrol
);
1348 ucontrol
->value
.integer
.value
[0] =
1349 chip
->vmixer_gain
[ucontrol
->id
.index
/ num_pipes_out(chip
)]
1350 [ucontrol
->id
.index
% num_pipes_out(chip
)];
1354 static int snd_echo_vmixer_put(struct snd_kcontrol
*kcontrol
,
1355 struct snd_ctl_elem_value
*ucontrol
)
1357 struct echoaudio
*chip
;
1362 chip
= snd_kcontrol_chip(kcontrol
);
1363 out
= ucontrol
->id
.index
/ num_pipes_out(chip
);
1364 vch
= ucontrol
->id
.index
% num_pipes_out(chip
);
1365 gain
= ucontrol
->value
.integer
.value
[0];
1366 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1368 if (chip
->vmixer_gain
[out
][vch
] != ucontrol
->value
.integer
.value
[0]) {
1369 spin_lock_irq(&chip
->lock
);
1370 set_vmixer_gain(chip
, out
, vch
, ucontrol
->value
.integer
.value
[0]);
1371 update_vmixer_level(chip
);
1372 spin_unlock_irq(&chip
->lock
);
1378 static struct snd_kcontrol_new snd_echo_vmixer
= {
1379 .name
= "VMixer Volume",
1380 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1381 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1382 .info
= snd_echo_vmixer_info
,
1383 .get
= snd_echo_vmixer_get
,
1384 .put
= snd_echo_vmixer_put
,
1385 .tlv
= {.p
= db_scale_output_gain
},
1388 #endif /* ECHOCARD_HAS_VMIXER */
1392 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1394 /******************* Digital mode switch *******************/
1395 static int snd_echo_digital_mode_info(struct snd_kcontrol
*kcontrol
,
1396 struct snd_ctl_elem_info
*uinfo
)
1398 static const char * const names
[4] = {
1399 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1402 struct echoaudio
*chip
;
1404 chip
= snd_kcontrol_chip(kcontrol
);
1405 return snd_ctl_enum_info(uinfo
, 1, chip
->num_digital_modes
, names
);
1408 static int snd_echo_digital_mode_get(struct snd_kcontrol
*kcontrol
,
1409 struct snd_ctl_elem_value
*ucontrol
)
1411 struct echoaudio
*chip
;
1414 chip
= snd_kcontrol_chip(kcontrol
);
1415 mode
= chip
->digital_mode
;
1416 for (i
= chip
->num_digital_modes
- 1; i
>= 0; i
--)
1417 if (mode
== chip
->digital_mode_list
[i
]) {
1418 ucontrol
->value
.enumerated
.item
[0] = i
;
1424 static int snd_echo_digital_mode_put(struct snd_kcontrol
*kcontrol
,
1425 struct snd_ctl_elem_value
*ucontrol
)
1427 struct echoaudio
*chip
;
1429 unsigned short emode
, dmode
;
1432 chip
= snd_kcontrol_chip(kcontrol
);
1434 emode
= ucontrol
->value
.enumerated
.item
[0];
1435 if (emode
>= chip
->num_digital_modes
)
1437 dmode
= chip
->digital_mode_list
[emode
];
1439 if (dmode
!= chip
->digital_mode
) {
1440 /* mode_mutex is required to make this operation atomic wrt
1441 pcm_digital_*_open() and set_input_clock() functions. */
1442 mutex_lock(&chip
->mode_mutex
);
1444 /* Do not allow the user to change the digital mode when a pcm
1445 device is open because it also changes the number of channels
1446 and the allowed sample rates */
1447 if (chip
->opencount
) {
1450 changed
= set_digital_mode(chip
, dmode
);
1451 /* If we had to change the clock source, report it */
1452 if (changed
> 0 && chip
->clock_src_ctl
) {
1453 snd_ctl_notify(chip
->card
,
1454 SNDRV_CTL_EVENT_MASK_VALUE
,
1455 &chip
->clock_src_ctl
->id
);
1456 dev_dbg(chip
->card
->dev
,
1457 "SDM() =%d\n", changed
);
1460 changed
= 1; /* No errors */
1462 mutex_unlock(&chip
->mode_mutex
);
1467 static const struct snd_kcontrol_new snd_echo_digital_mode_switch
= {
1468 .name
= "Digital mode Switch",
1469 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1470 .info
= snd_echo_digital_mode_info
,
1471 .get
= snd_echo_digital_mode_get
,
1472 .put
= snd_echo_digital_mode_put
,
1475 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1479 #ifdef ECHOCARD_HAS_DIGITAL_IO
1481 /******************* S/PDIF mode switch *******************/
1482 static int snd_echo_spdif_mode_info(struct snd_kcontrol
*kcontrol
,
1483 struct snd_ctl_elem_info
*uinfo
)
1485 static const char * const names
[2] = {"Consumer", "Professional"};
1487 return snd_ctl_enum_info(uinfo
, 1, 2, names
);
1490 static int snd_echo_spdif_mode_get(struct snd_kcontrol
*kcontrol
,
1491 struct snd_ctl_elem_value
*ucontrol
)
1493 struct echoaudio
*chip
;
1495 chip
= snd_kcontrol_chip(kcontrol
);
1496 ucontrol
->value
.enumerated
.item
[0] = !!chip
->professional_spdif
;
1500 static int snd_echo_spdif_mode_put(struct snd_kcontrol
*kcontrol
,
1501 struct snd_ctl_elem_value
*ucontrol
)
1503 struct echoaudio
*chip
;
1506 chip
= snd_kcontrol_chip(kcontrol
);
1507 mode
= !!ucontrol
->value
.enumerated
.item
[0];
1508 if (mode
!= chip
->professional_spdif
) {
1509 spin_lock_irq(&chip
->lock
);
1510 set_professional_spdif(chip
, mode
);
1511 spin_unlock_irq(&chip
->lock
);
1517 static const struct snd_kcontrol_new snd_echo_spdif_mode_switch
= {
1518 .name
= "S/PDIF mode Switch",
1519 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1520 .info
= snd_echo_spdif_mode_info
,
1521 .get
= snd_echo_spdif_mode_get
,
1522 .put
= snd_echo_spdif_mode_put
,
1525 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1529 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1531 /******************* Select input clock source *******************/
1532 static int snd_echo_clock_source_info(struct snd_kcontrol
*kcontrol
,
1533 struct snd_ctl_elem_info
*uinfo
)
1535 static const char * const names
[8] = {
1536 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1539 struct echoaudio
*chip
;
1541 chip
= snd_kcontrol_chip(kcontrol
);
1542 return snd_ctl_enum_info(uinfo
, 1, chip
->num_clock_sources
, names
);
1545 static int snd_echo_clock_source_get(struct snd_kcontrol
*kcontrol
,
1546 struct snd_ctl_elem_value
*ucontrol
)
1548 struct echoaudio
*chip
;
1551 chip
= snd_kcontrol_chip(kcontrol
);
1552 clock
= chip
->input_clock
;
1554 for (i
= 0; i
< chip
->num_clock_sources
; i
++)
1555 if (clock
== chip
->clock_source_list
[i
])
1556 ucontrol
->value
.enumerated
.item
[0] = i
;
1561 static int snd_echo_clock_source_put(struct snd_kcontrol
*kcontrol
,
1562 struct snd_ctl_elem_value
*ucontrol
)
1564 struct echoaudio
*chip
;
1566 unsigned int eclock
, dclock
;
1569 chip
= snd_kcontrol_chip(kcontrol
);
1570 eclock
= ucontrol
->value
.enumerated
.item
[0];
1571 if (eclock
>= chip
->input_clock_types
)
1573 dclock
= chip
->clock_source_list
[eclock
];
1574 if (chip
->input_clock
!= dclock
) {
1575 mutex_lock(&chip
->mode_mutex
);
1576 spin_lock_irq(&chip
->lock
);
1577 changed
= set_input_clock(chip
, dclock
);
1579 changed
= 1; /* no errors */
1580 spin_unlock_irq(&chip
->lock
);
1581 mutex_unlock(&chip
->mode_mutex
);
1585 dev_dbg(chip
->card
->dev
,
1586 "seticlk val%d err 0x%x\n", dclock
, changed
);
1591 static const struct snd_kcontrol_new snd_echo_clock_source_switch
= {
1592 .name
= "Sample Clock Source",
1593 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1594 .info
= snd_echo_clock_source_info
,
1595 .get
= snd_echo_clock_source_get
,
1596 .put
= snd_echo_clock_source_put
,
1599 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1603 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1605 /******************* Phantom power switch *******************/
1606 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1608 static int snd_echo_phantom_power_get(struct snd_kcontrol
*kcontrol
,
1609 struct snd_ctl_elem_value
*ucontrol
)
1611 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1613 ucontrol
->value
.integer
.value
[0] = chip
->phantom_power
;
1617 static int snd_echo_phantom_power_put(struct snd_kcontrol
*kcontrol
,
1618 struct snd_ctl_elem_value
*ucontrol
)
1620 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1621 int power
, changed
= 0;
1623 power
= !!ucontrol
->value
.integer
.value
[0];
1624 if (chip
->phantom_power
!= power
) {
1625 spin_lock_irq(&chip
->lock
);
1626 changed
= set_phantom_power(chip
, power
);
1627 spin_unlock_irq(&chip
->lock
);
1629 changed
= 1; /* no errors */
1634 static const struct snd_kcontrol_new snd_echo_phantom_power_switch
= {
1635 .name
= "Phantom power Switch",
1636 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1637 .info
= snd_echo_phantom_power_info
,
1638 .get
= snd_echo_phantom_power_get
,
1639 .put
= snd_echo_phantom_power_put
,
1642 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1646 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1648 /******************* Digital input automute switch *******************/
1649 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1651 static int snd_echo_automute_get(struct snd_kcontrol
*kcontrol
,
1652 struct snd_ctl_elem_value
*ucontrol
)
1654 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1656 ucontrol
->value
.integer
.value
[0] = chip
->digital_in_automute
;
1660 static int snd_echo_automute_put(struct snd_kcontrol
*kcontrol
,
1661 struct snd_ctl_elem_value
*ucontrol
)
1663 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1664 int automute
, changed
= 0;
1666 automute
= !!ucontrol
->value
.integer
.value
[0];
1667 if (chip
->digital_in_automute
!= automute
) {
1668 spin_lock_irq(&chip
->lock
);
1669 changed
= set_input_auto_mute(chip
, automute
);
1670 spin_unlock_irq(&chip
->lock
);
1672 changed
= 1; /* no errors */
1677 static const struct snd_kcontrol_new snd_echo_automute_switch
= {
1678 .name
= "Digital Capture Switch (automute)",
1679 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1680 .info
= snd_echo_automute_info
,
1681 .get
= snd_echo_automute_get
,
1682 .put
= snd_echo_automute_put
,
1685 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1689 /******************* VU-meters switch *******************/
1690 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1692 static int snd_echo_vumeters_switch_put(struct snd_kcontrol
*kcontrol
,
1693 struct snd_ctl_elem_value
*ucontrol
)
1695 struct echoaudio
*chip
;
1697 chip
= snd_kcontrol_chip(kcontrol
);
1698 spin_lock_irq(&chip
->lock
);
1699 set_meters_on(chip
, ucontrol
->value
.integer
.value
[0]);
1700 spin_unlock_irq(&chip
->lock
);
1704 static const struct snd_kcontrol_new snd_echo_vumeters_switch
= {
1705 .name
= "VU-meters Switch",
1706 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1707 .access
= SNDRV_CTL_ELEM_ACCESS_WRITE
,
1708 .info
= snd_echo_vumeters_switch_info
,
1709 .put
= snd_echo_vumeters_switch_put
,
1714 /***** Read VU-meters (input, output, analog and digital together) *****/
1715 static int snd_echo_vumeters_info(struct snd_kcontrol
*kcontrol
,
1716 struct snd_ctl_elem_info
*uinfo
)
1718 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1720 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1721 uinfo
->value
.integer
.max
= 0;
1725 static int snd_echo_vumeters_get(struct snd_kcontrol
*kcontrol
,
1726 struct snd_ctl_elem_value
*ucontrol
)
1728 struct echoaudio
*chip
;
1730 chip
= snd_kcontrol_chip(kcontrol
);
1731 get_audio_meters(chip
, ucontrol
->value
.integer
.value
);
1735 static const struct snd_kcontrol_new snd_echo_vumeters
= {
1736 .name
= "VU-meters",
1737 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1738 .access
= SNDRV_CTL_ELEM_ACCESS_READ
|
1739 SNDRV_CTL_ELEM_ACCESS_VOLATILE
|
1740 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1741 .info
= snd_echo_vumeters_info
,
1742 .get
= snd_echo_vumeters_get
,
1743 .tlv
= {.p
= db_scale_output_gain
},
1748 /*** Channels info - it exports informations about the number of channels ***/
1749 static int snd_echo_channels_info_info(struct snd_kcontrol
*kcontrol
,
1750 struct snd_ctl_elem_info
*uinfo
)
1752 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1754 uinfo
->value
.integer
.min
= 0;
1755 uinfo
->value
.integer
.max
= 1 << ECHO_CLOCK_NUMBER
;
1759 static int snd_echo_channels_info_get(struct snd_kcontrol
*kcontrol
,
1760 struct snd_ctl_elem_value
*ucontrol
)
1762 struct echoaudio
*chip
;
1763 int detected
, clocks
, bit
, src
;
1765 chip
= snd_kcontrol_chip(kcontrol
);
1766 ucontrol
->value
.integer
.value
[0] = num_busses_in(chip
);
1767 ucontrol
->value
.integer
.value
[1] = num_analog_busses_in(chip
);
1768 ucontrol
->value
.integer
.value
[2] = num_busses_out(chip
);
1769 ucontrol
->value
.integer
.value
[3] = num_analog_busses_out(chip
);
1770 ucontrol
->value
.integer
.value
[4] = num_pipes_out(chip
);
1772 /* Compute the bitmask of the currently valid input clocks */
1773 detected
= detect_input_clocks(chip
);
1775 src
= chip
->num_clock_sources
- 1;
1776 for (bit
= ECHO_CLOCK_NUMBER
- 1; bit
>= 0; bit
--)
1777 if (detected
& (1 << bit
))
1778 for (; src
>= 0; src
--)
1779 if (bit
== chip
->clock_source_list
[src
]) {
1783 ucontrol
->value
.integer
.value
[5] = clocks
;
1788 static const struct snd_kcontrol_new snd_echo_channels_info
= {
1789 .name
= "Channels info",
1790 .iface
= SNDRV_CTL_ELEM_IFACE_HWDEP
,
1791 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
1792 .info
= snd_echo_channels_info_info
,
1793 .get
= snd_echo_channels_info_get
,
1799 /******************************************************************************
1801 ******************************************************************************/
1802 /* Check if a period has elapsed since last interrupt
1804 * Don't make any updates to state; PCM core handles this with the
1807 * \return true if a period has elapsed, otherwise false
1809 static bool period_has_elapsed(struct snd_pcm_substream
*substream
)
1811 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1812 struct audiopipe
*pipe
= runtime
->private_data
;
1814 size_t period_bytes
;
1816 if (pipe
->state
!= PIPE_STATE_STARTED
)
1819 period_bytes
= frames_to_bytes(runtime
, runtime
->period_size
);
1821 counter
= le32_to_cpu(*pipe
->dma_counter
); /* presumed atomic */
1823 step
= counter
- pipe
->last_period
; /* handles wrapping */
1824 step
-= step
% period_bytes
; /* acknowledge whole periods only */
1827 return false; /* haven't advanced a whole period yet */
1829 pipe
->last_period
+= step
; /* used exclusively by us */
1833 static irqreturn_t
snd_echo_interrupt(int irq
, void *dev_id
)
1835 struct echoaudio
*chip
= dev_id
;
1838 spin_lock(&chip
->lock
);
1839 st
= service_irq(chip
);
1841 spin_unlock(&chip
->lock
);
1844 /* The hardware doesn't tell us which substream caused the irq,
1845 thus we have to check all running substreams. */
1846 for (ss
= 0; ss
< DSP_MAXPIPES
; ss
++) {
1847 struct snd_pcm_substream
*substream
;
1849 substream
= chip
->substream
[ss
];
1850 if (substream
&& period_has_elapsed(substream
)) {
1851 spin_unlock(&chip
->lock
);
1852 snd_pcm_period_elapsed(substream
);
1853 spin_lock(&chip
->lock
);
1856 spin_unlock(&chip
->lock
);
1858 #ifdef ECHOCARD_HAS_MIDI
1859 if (st
> 0 && chip
->midi_in
) {
1860 snd_rawmidi_receive(chip
->midi_in
, chip
->midi_buffer
, st
);
1861 dev_dbg(chip
->card
->dev
, "rawmidi_iread=%d\n", st
);
1870 /******************************************************************************
1871 Module construction / destruction
1872 ******************************************************************************/
1874 static void snd_echo_free(struct snd_card
*card
)
1876 struct echoaudio
*chip
= card
->private_data
;
1878 if (chip
->comm_page
)
1879 rest_in_peace(chip
);
1882 free_irq(chip
->irq
, chip
);
1884 /* release chip data */
1885 free_firmware_cache(chip
);
1888 /* <--snd_echo_probe() */
1889 static int snd_echo_create(struct snd_card
*card
,
1890 struct pci_dev
*pci
)
1892 struct echoaudio
*chip
= card
->private_data
;
1896 pci_write_config_byte(pci
, PCI_LATENCY_TIMER
, 0xC0);
1898 err
= pcim_enable_device(pci
);
1901 pci_set_master(pci
);
1903 /* Allocate chip if needed */
1904 spin_lock_init(&chip
->lock
);
1908 chip
->opencount
= 0;
1909 mutex_init(&chip
->mode_mutex
);
1910 chip
->can_set_rate
= 1;
1912 /* PCI resource allocation */
1913 err
= pci_request_regions(pci
, ECHOCARD_NAME
);
1917 chip
->dsp_registers_phys
= pci_resource_start(pci
, 0);
1918 sz
= pci_resource_len(pci
, 0);
1920 sz
= PAGE_SIZE
; /* We map only the required part */
1922 chip
->dsp_registers
= devm_ioremap(&pci
->dev
, chip
->dsp_registers_phys
, sz
);
1923 if (!chip
->dsp_registers
) {
1924 dev_err(chip
->card
->dev
, "ioremap failed\n");
1928 if (request_irq(pci
->irq
, snd_echo_interrupt
, IRQF_SHARED
,
1929 KBUILD_MODNAME
, chip
)) {
1930 dev_err(chip
->card
->dev
, "cannot grab irq\n");
1933 chip
->irq
= pci
->irq
;
1934 card
->sync_irq
= chip
->irq
;
1935 dev_dbg(card
->dev
, "pci=%p irq=%d subdev=%04x Init hardware...\n",
1936 chip
->pci
, chip
->irq
, chip
->pci
->subsystem_device
);
1938 card
->private_free
= snd_echo_free
;
1940 /* Create the DSP comm page - this is the area of memory used for most
1941 of the communication with the DSP, which accesses it via bus mastering */
1942 chip
->commpage_dma_buf
=
1943 snd_devm_alloc_pages(&pci
->dev
, SNDRV_DMA_TYPE_DEV
,
1944 sizeof(struct comm_page
));
1945 if (!chip
->commpage_dma_buf
)
1947 chip
->comm_page_phys
= chip
->commpage_dma_buf
->addr
;
1948 chip
->comm_page
= (struct comm_page
*)chip
->commpage_dma_buf
->area
;
1950 err
= init_hw(chip
, chip
->pci
->device
, chip
->pci
->subsystem_device
);
1952 err
= set_mixer_defaults(chip
);
1954 dev_err(card
->dev
, "init_hw err=%d\n", err
);
1962 static int __snd_echo_probe(struct pci_dev
*pci
,
1963 const struct pci_device_id
*pci_id
)
1966 struct snd_card
*card
;
1967 struct echoaudio
*chip
;
1969 __maybe_unused
int i
;
1972 if (dev
>= SNDRV_CARDS
)
1980 err
= snd_devm_card_new(&pci
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
1981 sizeof(*chip
), &card
);
1984 chip
= card
->private_data
;
1986 err
= snd_echo_create(card
, pci
);
1990 strcpy(card
->driver
, "Echo_" ECHOCARD_NAME
);
1991 strcpy(card
->shortname
, chip
->card_name
);
1994 if (pci_id
->device
== 0x3410)
1997 sprintf(card
->longname
, "%s rev.%d (DSP%s) at 0x%lx irq %i",
1998 card
->shortname
, pci_id
->subdevice
& 0x000f, dsp
,
1999 chip
->dsp_registers_phys
, chip
->irq
);
2001 err
= snd_echo_new_pcm(chip
);
2003 dev_err(chip
->card
->dev
, "new pcm error %d\n", err
);
2007 #ifdef ECHOCARD_HAS_MIDI
2008 if (chip
->has_midi
) { /* Some Mia's do not have midi */
2009 err
= snd_echo_midi_create(card
, chip
);
2011 dev_err(chip
->card
->dev
, "new midi error %d\n", err
);
2017 #ifdef ECHOCARD_HAS_VMIXER
2018 snd_echo_vmixer
.count
= num_pipes_out(chip
) * num_busses_out(chip
);
2019 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vmixer
, chip
));
2022 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2023 err
= snd_ctl_add(chip
->card
,
2024 snd_ctl_new1(&snd_echo_line_output_gain
, chip
));
2028 #else /* ECHOCARD_HAS_VMIXER */
2029 err
= snd_ctl_add(chip
->card
,
2030 snd_ctl_new1(&snd_echo_pcm_output_gain
, chip
));
2033 #endif /* ECHOCARD_HAS_VMIXER */
2035 #ifdef ECHOCARD_HAS_INPUT_GAIN
2036 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_line_input_gain
, chip
));
2041 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2042 if (!chip
->hasnt_input_nominal_level
) {
2043 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_intput_nominal_level
, chip
));
2049 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2050 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_output_nominal_level
, chip
));
2055 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vumeters_switch
, chip
));
2059 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vumeters
, chip
));
2063 #ifdef ECHOCARD_HAS_MONITOR
2064 snd_echo_monitor_mixer
.count
= num_busses_in(chip
) * num_busses_out(chip
);
2065 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_monitor_mixer
, chip
));
2070 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2071 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_automute_switch
, chip
));
2076 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_channels_info
, chip
));
2080 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2081 /* Creates a list of available digital modes */
2082 chip
->num_digital_modes
= 0;
2083 for (i
= 0; i
< 6; i
++)
2084 if (chip
->digital_modes
& (1 << i
))
2085 chip
->digital_mode_list
[chip
->num_digital_modes
++] = i
;
2087 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_digital_mode_switch
, chip
));
2090 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2092 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2093 /* Creates a list of available clock sources */
2094 chip
->num_clock_sources
= 0;
2095 for (i
= 0; i
< 10; i
++)
2096 if (chip
->input_clock_types
& (1 << i
))
2097 chip
->clock_source_list
[chip
->num_clock_sources
++] = i
;
2099 if (chip
->num_clock_sources
> 1) {
2100 chip
->clock_src_ctl
= snd_ctl_new1(&snd_echo_clock_source_switch
, chip
);
2101 err
= snd_ctl_add(chip
->card
, chip
->clock_src_ctl
);
2105 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2107 #ifdef ECHOCARD_HAS_DIGITAL_IO
2108 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_spdif_mode_switch
, chip
));
2113 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2114 if (chip
->has_phantom_power
) {
2115 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_phantom_power_switch
, chip
));
2121 err
= snd_card_register(card
);
2124 dev_info(card
->dev
, "Card registered: %s\n", card
->longname
);
2126 pci_set_drvdata(pci
, chip
);
2131 static int snd_echo_probe(struct pci_dev
*pci
,
2132 const struct pci_device_id
*pci_id
)
2134 return snd_card_free_on_error(&pci
->dev
, __snd_echo_probe(pci
, pci_id
));
2138 static int snd_echo_suspend(struct device
*dev
)
2140 struct echoaudio
*chip
= dev_get_drvdata(dev
);
2142 #ifdef ECHOCARD_HAS_MIDI
2143 /* This call can sleep */
2145 snd_echo_midi_output_trigger(chip
->midi_out
, 0);
2147 spin_lock_irq(&chip
->lock
);
2148 if (wait_handshake(chip
)) {
2149 spin_unlock_irq(&chip
->lock
);
2152 clear_handshake(chip
);
2153 if (send_vector(chip
, DSP_VC_GO_COMATOSE
) < 0) {
2154 spin_unlock_irq(&chip
->lock
);
2157 spin_unlock_irq(&chip
->lock
);
2159 chip
->dsp_code
= NULL
;
2160 free_irq(chip
->irq
, chip
);
2162 chip
->card
->sync_irq
= -1;
2168 static int snd_echo_resume(struct device
*dev
)
2170 struct pci_dev
*pci
= to_pci_dev(dev
);
2171 struct echoaudio
*chip
= dev_get_drvdata(dev
);
2172 struct comm_page
*commpage
, *commpage_bak
;
2173 u32 pipe_alloc_mask
;
2176 commpage
= chip
->comm_page
;
2177 commpage_bak
= kmemdup(commpage
, sizeof(*commpage
), GFP_KERNEL
);
2178 if (commpage_bak
== NULL
)
2181 err
= init_hw(chip
, chip
->pci
->device
, chip
->pci
->subsystem_device
);
2183 kfree(commpage_bak
);
2184 dev_err(dev
, "resume init_hw err=%d\n", err
);
2188 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2189 * restore_dsp_settings() fails.
2191 pipe_alloc_mask
= chip
->pipe_alloc_mask
;
2192 chip
->pipe_alloc_mask
= 0;
2193 err
= restore_dsp_rettings(chip
);
2194 chip
->pipe_alloc_mask
= pipe_alloc_mask
;
2196 kfree(commpage_bak
);
2200 memcpy(&commpage
->audio_format
, &commpage_bak
->audio_format
,
2201 sizeof(commpage
->audio_format
));
2202 memcpy(&commpage
->sglist_addr
, &commpage_bak
->sglist_addr
,
2203 sizeof(commpage
->sglist_addr
));
2204 memcpy(&commpage
->midi_output
, &commpage_bak
->midi_output
,
2205 sizeof(commpage
->midi_output
));
2206 kfree(commpage_bak
);
2208 if (request_irq(pci
->irq
, snd_echo_interrupt
, IRQF_SHARED
,
2209 KBUILD_MODNAME
, chip
)) {
2210 dev_err(chip
->card
->dev
, "cannot grab irq\n");
2213 chip
->irq
= pci
->irq
;
2214 chip
->card
->sync_irq
= chip
->irq
;
2215 dev_dbg(dev
, "resume irq=%d\n", chip
->irq
);
2217 #ifdef ECHOCARD_HAS_MIDI
2218 if (chip
->midi_input_enabled
)
2219 enable_midi_input(chip
, true);
2221 snd_echo_midi_output_trigger(chip
->midi_out
, 1);
2227 static DEFINE_SIMPLE_DEV_PM_OPS(snd_echo_pm
, snd_echo_suspend
, snd_echo_resume
);
2229 /******************************************************************************
2230 Everything starts and ends here
2231 ******************************************************************************/
2233 /* pci_driver definition */
2234 static struct pci_driver echo_driver
= {
2235 .name
= KBUILD_MODNAME
,
2236 .id_table
= snd_echo_ids
,
2237 .probe
= snd_echo_probe
,
2243 module_pci_driver(echo_driver
);