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_SUPPORTED_DEVICE("{{Echoaudio," ECHOCARD_NAME "}}");
14 MODULE_DEVICE_TABLE(pci, snd_echo_ids);
16 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
17 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
18 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
20 module_param_array(index, int, NULL, 0444);
21 MODULE_PARM_DESC(index, "Index value for " ECHOCARD_NAME " soundcard.");
22 module_param_array(id, charp, NULL, 0444);
23 MODULE_PARM_DESC(id, "ID string for " ECHOCARD_NAME " soundcard.");
24 module_param_array(enable, bool, NULL, 0444);
25 MODULE_PARM_DESC(enable, "Enable " ECHOCARD_NAME " soundcard.");
27 static const unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
28 static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1);
32 static int get_firmware(const struct firmware **fw_entry,
33 struct echoaudio *chip, const short fw_index)
38 #ifdef CONFIG_PM_SLEEP
39 if (chip->fw_cache[fw_index]) {
40 dev_dbg(chip->card->dev,
41 "firmware requested: %s is cached\n",
42 card_fw[fw_index].data);
43 *fw_entry = chip->fw_cache[fw_index];
48 dev_dbg(chip->card->dev,
49 "firmware requested: %s\n", card_fw[fw_index].data);
50 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data);
51 err = request_firmware(fw_entry, name, &chip->pci->dev);
53 dev_err(chip->card->dev,
54 "get_firmware(): Firmware not available (%d)\n", err);
55 #ifdef CONFIG_PM_SLEEP
57 chip->fw_cache[fw_index] = *fw_entry;
64 static void free_firmware(const struct firmware *fw_entry,
65 struct echoaudio *chip)
67 #ifdef CONFIG_PM_SLEEP
68 dev_dbg(chip->card->dev, "firmware not released (kept in cache)\n");
70 release_firmware(fw_entry);
76 static void free_firmware_cache(struct echoaudio *chip)
78 #ifdef CONFIG_PM_SLEEP
81 for (i = 0; i < 8 ; i++)
82 if (chip->fw_cache[i]) {
83 release_firmware(chip->fw_cache[i]);
84 dev_dbg(chip->card->dev, "release_firmware(%d)\n", i);
92 /******************************************************************************
94 ******************************************************************************/
96 static void audiopipe_free(struct snd_pcm_runtime *runtime)
98 struct audiopipe *pipe = runtime->private_data;
100 if (pipe->sgpage.area)
101 snd_dma_free_pages(&pipe->sgpage);
107 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
108 struct snd_pcm_hw_rule *rule)
110 struct snd_interval *c = hw_param_interval(params,
111 SNDRV_PCM_HW_PARAM_CHANNELS);
112 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
117 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
118 /* >=2 channels cannot be S32_BE */
120 fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
121 return snd_mask_refine(f, &fmt);
124 /* > 2 channels cannot be U8 and S32_BE */
126 fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
127 return snd_mask_refine(f, &fmt);
129 /* Mono is ok with any format */
135 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
136 struct snd_pcm_hw_rule *rule)
138 struct snd_interval *c = hw_param_interval(params,
139 SNDRV_PCM_HW_PARAM_CHANNELS);
140 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
141 struct snd_interval ch;
143 snd_interval_any(&ch);
145 /* S32_BE is mono (and stereo) only */
146 if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
148 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
154 return snd_interval_refine(c, &ch);
156 /* U8 can be only mono or stereo */
157 if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
161 return snd_interval_refine(c, &ch);
163 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
169 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
170 struct snd_pcm_hw_rule *rule)
172 struct snd_interval *c = hw_param_interval(params,
173 SNDRV_PCM_HW_PARAM_CHANNELS);
174 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
179 fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
181 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
183 fmask &= SNDRV_PCM_FMTBIT_S16_LE |
184 SNDRV_PCM_FMTBIT_S24_3LE |
185 SNDRV_PCM_FMTBIT_S32_LE;
186 /* 1 channel must be S32_BE or S32_LE */
187 } else if (c->max == 1)
188 fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
189 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
190 /* 2 channels cannot be S32_BE */
191 else if (c->min == 2 && c->max == 2)
192 fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
197 fmt.bits[0] &= (u32)fmask;
198 fmt.bits[1] &= (u32)(fmask >> 32);
199 return snd_mask_refine(f, &fmt);
204 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
205 struct snd_pcm_hw_rule *rule)
207 struct snd_interval *c = hw_param_interval(params,
208 SNDRV_PCM_HW_PARAM_CHANNELS);
209 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
210 struct snd_interval ch;
213 snd_interval_any(&ch);
215 fmask = f->bits[0] + ((u64)f->bits[1] << 32);
217 /* S32_BE is mono (and stereo) only */
218 if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
220 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
225 /* U8 is stereo only */
226 } else if (fmask == SNDRV_PCM_FMTBIT_U8)
228 /* S16_LE and S24_3LE must be at least stereo */
229 else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
230 SNDRV_PCM_FMTBIT_S24_3LE)))
235 return snd_interval_refine(c, &ch);
240 /* Since the sample rate is a global setting, do allow the user to change the
241 sample rate only if there is only one pcm device open. */
242 static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
243 struct snd_pcm_hw_rule *rule)
245 struct snd_interval *rate = hw_param_interval(params,
246 SNDRV_PCM_HW_PARAM_RATE);
247 struct echoaudio *chip = rule->private;
248 struct snd_interval fixed;
251 mutex_lock(&chip->mode_mutex);
253 if (chip->can_set_rate) {
256 snd_interval_any(&fixed);
257 fixed.min = fixed.max = chip->sample_rate;
258 err = snd_interval_refine(rate, &fixed);
261 mutex_unlock(&chip->mode_mutex);
266 static int pcm_open(struct snd_pcm_substream *substream,
267 signed char max_channels)
269 struct echoaudio *chip;
270 struct snd_pcm_runtime *runtime;
271 struct audiopipe *pipe;
274 if (max_channels <= 0)
277 chip = snd_pcm_substream_chip(substream);
278 runtime = substream->runtime;
280 pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
283 pipe->index = -1; /* Not configured yet */
285 /* Set up hw capabilities and contraints */
286 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
287 dev_dbg(chip->card->dev, "max_channels=%d\n", max_channels);
288 pipe->constr.list = channels_list;
289 pipe->constr.mask = 0;
290 for (i = 0; channels_list[i] <= max_channels; i++);
291 pipe->constr.count = i;
292 if (pipe->hw.channels_max > max_channels)
293 pipe->hw.channels_max = max_channels;
294 if (chip->digital_mode == DIGITAL_MODE_ADAT) {
295 pipe->hw.rate_max = 48000;
296 pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
299 runtime->hw = pipe->hw;
300 runtime->private_data = pipe;
301 runtime->private_free = audiopipe_free;
302 snd_pcm_set_sync(substream);
304 /* Only mono and any even number of channels are allowed */
305 if ((err = snd_pcm_hw_constraint_list(runtime, 0,
306 SNDRV_PCM_HW_PARAM_CHANNELS,
310 /* All periods should have the same size */
311 if ((err = snd_pcm_hw_constraint_integer(runtime,
312 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
315 /* The hw accesses memory in chunks 32 frames long and they should be
316 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
317 generated with a resolution of 32 frames. Thus we need the following */
318 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
319 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
322 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
323 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
327 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
328 SNDRV_PCM_HW_PARAM_RATE,
329 hw_rule_sample_rate, chip,
330 SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
333 /* Allocate a page for the scatter-gather list */
334 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
336 PAGE_SIZE, &pipe->sgpage)) < 0) {
337 dev_err(chip->card->dev, "s-g list allocation failed\n");
342 * Sole ownership required to set the rate
345 dev_dbg(chip->card->dev, "pcm_open opencount=%d can_set_rate=%d, rate_set=%d",
346 chip->opencount, chip->can_set_rate, chip->rate_set);
349 if (chip->opencount > 1 && chip->rate_set)
350 chip->can_set_rate = 0;
357 static int pcm_analog_in_open(struct snd_pcm_substream *substream)
359 struct echoaudio *chip = snd_pcm_substream_chip(substream);
362 if ((err = pcm_open(substream, num_analog_busses_in(chip) -
363 substream->number)) < 0)
365 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
366 SNDRV_PCM_HW_PARAM_CHANNELS,
367 hw_rule_capture_channels_by_format, NULL,
368 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
370 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
371 SNDRV_PCM_HW_PARAM_FORMAT,
372 hw_rule_capture_format_by_channels, NULL,
373 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
381 static int pcm_analog_out_open(struct snd_pcm_substream *substream)
383 struct echoaudio *chip = snd_pcm_substream_chip(substream);
384 int max_channels, err;
386 #ifdef ECHOCARD_HAS_VMIXER
387 max_channels = num_pipes_out(chip);
389 max_channels = num_analog_busses_out(chip);
391 if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
393 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
394 SNDRV_PCM_HW_PARAM_CHANNELS,
395 hw_rule_playback_channels_by_format,
397 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
399 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
400 SNDRV_PCM_HW_PARAM_FORMAT,
401 hw_rule_playback_format_by_channels,
403 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
411 #ifdef ECHOCARD_HAS_DIGITAL_IO
413 static int pcm_digital_in_open(struct snd_pcm_substream *substream)
415 struct echoaudio *chip = snd_pcm_substream_chip(substream);
416 int err, max_channels;
418 max_channels = num_digital_busses_in(chip) - substream->number;
419 mutex_lock(&chip->mode_mutex);
420 if (chip->digital_mode == DIGITAL_MODE_ADAT)
421 err = pcm_open(substream, max_channels);
422 else /* If the card has ADAT, subtract the 6 channels
423 * that S/PDIF doesn't have
425 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
430 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
431 SNDRV_PCM_HW_PARAM_CHANNELS,
432 hw_rule_capture_channels_by_format, NULL,
433 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
435 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
436 SNDRV_PCM_HW_PARAM_FORMAT,
437 hw_rule_capture_format_by_channels, NULL,
438 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
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 if ((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,
473 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
474 SNDRV_PCM_HW_PARAM_FORMAT,
475 hw_rule_playback_format_by_channels,
476 NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
481 mutex_unlock(&chip->mode_mutex);
485 #endif /* !ECHOCARD_HAS_VMIXER */
487 #endif /* ECHOCARD_HAS_DIGITAL_IO */
491 static int pcm_close(struct snd_pcm_substream *substream)
493 struct echoaudio *chip = snd_pcm_substream_chip(substream);
495 /* Nothing to do here. Audio is already off and pipe will be
496 * freed by its callback
499 mutex_lock(&chip->mode_mutex);
501 dev_dbg(chip->card->dev, "pcm_open opencount=%d can_set_rate=%d, rate_set=%d",
502 chip->opencount, chip->can_set_rate, chip->rate_set);
506 switch (chip->opencount) {
508 chip->can_set_rate = 1;
516 mutex_unlock(&chip->mode_mutex);
522 /* Channel allocation and scatter-gather list setup */
523 static int init_engine(struct snd_pcm_substream *substream,
524 struct snd_pcm_hw_params *hw_params,
525 int pipe_index, int interleave)
527 struct echoaudio *chip;
528 int err, per, rest, page, edge, offs;
529 struct audiopipe *pipe;
531 chip = snd_pcm_substream_chip(substream);
532 pipe = (struct audiopipe *) substream->runtime->private_data;
534 /* Sets up che hardware. If it's already initialized, reset and
535 * redo with the new parameters
537 spin_lock_irq(&chip->lock);
538 if (pipe->index >= 0) {
539 dev_dbg(chip->card->dev, "hwp_ie free(%d)\n", pipe->index);
540 err = free_pipes(chip, pipe);
542 chip->substream[pipe->index] = NULL;
545 err = allocate_pipes(chip, pipe, pipe_index, interleave);
547 spin_unlock_irq(&chip->lock);
548 dev_err(chip->card->dev, "allocate_pipes(%d) err=%d\n",
552 spin_unlock_irq(&chip->lock);
553 dev_dbg(chip->card->dev, "allocate_pipes()=%d\n", pipe_index);
555 dev_dbg(chip->card->dev,
556 "pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
557 params_buffer_bytes(hw_params), params_periods(hw_params),
558 params_period_bytes(hw_params));
560 sglist_init(chip, pipe);
562 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
564 rest = params_period_bytes(hw_params);
565 if (offs + rest > params_buffer_bytes(hw_params))
566 rest = params_buffer_bytes(hw_params) - offs;
569 addr = snd_pcm_sgbuf_get_addr(substream, offs);
570 if (rest <= edge - offs) {
571 sglist_add_mapping(chip, pipe, addr, rest);
572 sglist_add_irq(chip, pipe);
576 sglist_add_mapping(chip, pipe, addr,
588 /* Close the ring buffer */
589 sglist_wrap(chip, pipe);
591 /* This stuff is used by the irq handler, so it must be
592 * initialized before chip->substream
594 pipe->last_period = 0;
595 pipe->last_counter = 0;
598 chip->substream[pipe_index] = substream;
600 spin_lock_irq(&chip->lock);
601 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
602 spin_unlock_irq(&chip->lock);
608 static int pcm_analog_in_hw_params(struct snd_pcm_substream *substream,
609 struct snd_pcm_hw_params *hw_params)
611 struct echoaudio *chip = snd_pcm_substream_chip(substream);
613 return init_engine(substream, hw_params, px_analog_in(chip) +
614 substream->number, params_channels(hw_params));
619 static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream,
620 struct snd_pcm_hw_params *hw_params)
622 return init_engine(substream, hw_params, substream->number,
623 params_channels(hw_params));
628 #ifdef ECHOCARD_HAS_DIGITAL_IO
630 static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream,
631 struct snd_pcm_hw_params *hw_params)
633 struct echoaudio *chip = snd_pcm_substream_chip(substream);
635 return init_engine(substream, hw_params, px_digital_in(chip) +
636 substream->number, params_channels(hw_params));
641 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
642 static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream,
643 struct snd_pcm_hw_params *hw_params)
645 struct echoaudio *chip = snd_pcm_substream_chip(substream);
647 return init_engine(substream, hw_params, px_digital_out(chip) +
648 substream->number, params_channels(hw_params));
650 #endif /* !ECHOCARD_HAS_VMIXER */
652 #endif /* ECHOCARD_HAS_DIGITAL_IO */
656 static int pcm_hw_free(struct snd_pcm_substream *substream)
658 struct echoaudio *chip;
659 struct audiopipe *pipe;
661 chip = snd_pcm_substream_chip(substream);
662 pipe = (struct audiopipe *) substream->runtime->private_data;
664 spin_lock_irq(&chip->lock);
665 if (pipe->index >= 0) {
666 dev_dbg(chip->card->dev, "pcm_hw_free(%d)\n", pipe->index);
667 free_pipes(chip, pipe);
668 chip->substream[pipe->index] = NULL;
671 spin_unlock_irq(&chip->lock);
678 static int pcm_prepare(struct snd_pcm_substream *substream)
680 struct echoaudio *chip = snd_pcm_substream_chip(substream);
681 struct snd_pcm_runtime *runtime = substream->runtime;
682 struct audioformat format;
683 int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
685 dev_dbg(chip->card->dev, "Prepare rate=%d format=%d channels=%d\n",
686 runtime->rate, runtime->format, runtime->channels);
687 format.interleave = runtime->channels;
688 format.data_are_bigendian = 0;
689 format.mono_to_stereo = 0;
690 switch (runtime->format) {
691 case SNDRV_PCM_FORMAT_U8:
692 format.bits_per_sample = 8;
694 case SNDRV_PCM_FORMAT_S16_LE:
695 format.bits_per_sample = 16;
697 case SNDRV_PCM_FORMAT_S24_3LE:
698 format.bits_per_sample = 24;
700 case SNDRV_PCM_FORMAT_S32_BE:
701 format.data_are_bigendian = 1;
703 case SNDRV_PCM_FORMAT_S32_LE:
704 format.bits_per_sample = 32;
707 dev_err(chip->card->dev,
708 "Prepare error: unsupported format %d\n",
713 if (snd_BUG_ON(pipe_index >= px_num(chip)))
717 * We passed checks we can do independently; now take
721 spin_lock_irq(&chip->lock);
723 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index))) {
724 spin_unlock_irq(&chip->lock);
728 set_audio_format(chip, pipe_index, &format);
729 spin_unlock_irq(&chip->lock);
736 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
738 struct echoaudio *chip = snd_pcm_substream_chip(substream);
739 struct audiopipe *pipe;
742 struct snd_pcm_substream *s;
744 snd_pcm_group_for_each_entry(s, substream) {
745 for (i = 0; i < DSP_MAXPIPES; i++) {
746 if (s == chip->substream[i]) {
747 channelmask |= 1 << i;
748 snd_pcm_trigger_done(s, substream);
753 spin_lock(&chip->lock);
755 case SNDRV_PCM_TRIGGER_RESUME:
756 case SNDRV_PCM_TRIGGER_START:
757 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
758 for (i = 0; i < DSP_MAXPIPES; i++) {
759 if (channelmask & (1 << i)) {
760 pipe = chip->substream[i]->runtime->private_data;
761 switch (pipe->state) {
762 case PIPE_STATE_STOPPED:
763 pipe->last_period = 0;
764 pipe->last_counter = 0;
766 *pipe->dma_counter = 0;
768 case PIPE_STATE_PAUSED:
769 pipe->state = PIPE_STATE_STARTED;
771 case PIPE_STATE_STARTED:
776 err = start_transport(chip, channelmask,
777 chip->pipe_cyclic_mask);
779 case SNDRV_PCM_TRIGGER_SUSPEND:
780 case SNDRV_PCM_TRIGGER_STOP:
781 for (i = 0; i < DSP_MAXPIPES; i++) {
782 if (channelmask & (1 << i)) {
783 pipe = chip->substream[i]->runtime->private_data;
784 pipe->state = PIPE_STATE_STOPPED;
787 err = stop_transport(chip, channelmask);
789 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
790 for (i = 0; i < DSP_MAXPIPES; i++) {
791 if (channelmask & (1 << i)) {
792 pipe = chip->substream[i]->runtime->private_data;
793 pipe->state = PIPE_STATE_PAUSED;
796 err = pause_transport(chip, channelmask);
801 spin_unlock(&chip->lock);
807 static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
809 struct snd_pcm_runtime *runtime = substream->runtime;
810 struct audiopipe *pipe = runtime->private_data;
814 * IRQ handling runs concurrently. Do not share tracking of
815 * counter with it, which would race or require locking
818 counter = le32_to_cpu(*pipe->dma_counter); /* presumed atomic */
820 step = counter - pipe->last_counter; /* handles wrapping */
821 pipe->last_counter = counter;
823 /* counter doesn't neccessarily wrap on a multiple of
824 * buffer_size, so can't derive the position; must
827 pipe->position += step;
828 pipe->position %= frames_to_bytes(runtime, runtime->buffer_size); /* wrap */
830 return bytes_to_frames(runtime, pipe->position);
835 /* pcm *_ops structures */
836 static const struct snd_pcm_ops analog_playback_ops = {
837 .open = pcm_analog_out_open,
839 .hw_params = pcm_analog_out_hw_params,
840 .hw_free = pcm_hw_free,
841 .prepare = pcm_prepare,
842 .trigger = pcm_trigger,
843 .pointer = pcm_pointer,
845 static const struct snd_pcm_ops analog_capture_ops = {
846 .open = pcm_analog_in_open,
848 .hw_params = pcm_analog_in_hw_params,
849 .hw_free = pcm_hw_free,
850 .prepare = pcm_prepare,
851 .trigger = pcm_trigger,
852 .pointer = pcm_pointer,
854 #ifdef ECHOCARD_HAS_DIGITAL_IO
855 #ifndef ECHOCARD_HAS_VMIXER
856 static const struct snd_pcm_ops digital_playback_ops = {
857 .open = pcm_digital_out_open,
859 .hw_params = pcm_digital_out_hw_params,
860 .hw_free = pcm_hw_free,
861 .prepare = pcm_prepare,
862 .trigger = pcm_trigger,
863 .pointer = pcm_pointer,
865 #endif /* !ECHOCARD_HAS_VMIXER */
866 static const struct snd_pcm_ops digital_capture_ops = {
867 .open = pcm_digital_in_open,
869 .hw_params = pcm_digital_in_hw_params,
870 .hw_free = pcm_hw_free,
871 .prepare = pcm_prepare,
872 .trigger = pcm_trigger,
873 .pointer = pcm_pointer,
875 #endif /* ECHOCARD_HAS_DIGITAL_IO */
879 /* Preallocate memory only for the first substream because it's the most
882 static void snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev)
884 struct snd_pcm_substream *ss;
887 for (stream = 0; stream < 2; stream++)
888 for (ss = pcm->streams[stream].substream; ss; ss = ss->next)
889 snd_pcm_set_managed_buffer(ss, SNDRV_DMA_TYPE_DEV_SG,
891 ss->number ? 0 : 128<<10,
897 /*<--snd_echo_probe() */
898 static int snd_echo_new_pcm(struct echoaudio *chip)
903 #ifdef ECHOCARD_HAS_VMIXER
904 /* This card has a Vmixer, that is there is no direct mapping from PCM
905 streams to physical outputs. The user can mix the streams as he wishes
906 via control interface and it's possible to send any stream to any
907 output, thus it makes no sense to keep analog and digital outputs
910 /* PCM#0 Virtual outputs and analog inputs */
911 if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip),
912 num_analog_busses_in(chip), &pcm)) < 0)
914 pcm->private_data = chip;
915 chip->analog_pcm = pcm;
916 strcpy(pcm->name, chip->card->shortname);
917 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
918 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
919 snd_echo_preallocate_pages(pcm, &chip->pci->dev);
921 #ifdef ECHOCARD_HAS_DIGITAL_IO
922 /* PCM#1 Digital inputs, no outputs */
923 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0,
924 num_digital_busses_in(chip), &pcm)) < 0)
926 pcm->private_data = chip;
927 chip->digital_pcm = pcm;
928 strcpy(pcm->name, chip->card->shortname);
929 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
930 snd_echo_preallocate_pages(pcm, &chip->pci->dev);
931 #endif /* ECHOCARD_HAS_DIGITAL_IO */
933 #else /* ECHOCARD_HAS_VMIXER */
935 /* The card can manage substreams formed by analog and digital channels
936 at the same time, but I prefer to keep analog and digital channels
937 separated, because that mixed thing is confusing and useless. So we
938 register two PCM devices: */
940 /* PCM#0 Analog i/o */
941 if ((err = snd_pcm_new(chip->card, "Analog PCM", 0,
942 num_analog_busses_out(chip),
943 num_analog_busses_in(chip), &pcm)) < 0)
945 pcm->private_data = chip;
946 chip->analog_pcm = pcm;
947 strcpy(pcm->name, chip->card->shortname);
948 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
949 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
950 snd_echo_preallocate_pages(pcm, &chip->pci->dev);
952 #ifdef ECHOCARD_HAS_DIGITAL_IO
953 /* PCM#1 Digital i/o */
954 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1,
955 num_digital_busses_out(chip),
956 num_digital_busses_in(chip), &pcm)) < 0)
958 pcm->private_data = chip;
959 chip->digital_pcm = pcm;
960 strcpy(pcm->name, chip->card->shortname);
961 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops);
962 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
963 snd_echo_preallocate_pages(pcm, &chip->pci->dev);
964 #endif /* ECHOCARD_HAS_DIGITAL_IO */
966 #endif /* ECHOCARD_HAS_VMIXER */
974 /******************************************************************************
976 ******************************************************************************/
978 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
980 /******************* PCM output volume *******************/
981 static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
982 struct snd_ctl_elem_info *uinfo)
984 struct echoaudio *chip;
986 chip = snd_kcontrol_chip(kcontrol);
987 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
988 uinfo->count = num_busses_out(chip);
989 uinfo->value.integer.min = ECHOGAIN_MINOUT;
990 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
994 static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
995 struct snd_ctl_elem_value *ucontrol)
997 struct echoaudio *chip;
1000 chip = snd_kcontrol_chip(kcontrol);
1001 for (c = 0; c < num_busses_out(chip); c++)
1002 ucontrol->value.integer.value[c] = chip->output_gain[c];
1006 static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
1007 struct snd_ctl_elem_value *ucontrol)
1009 struct echoaudio *chip;
1010 int c, changed, gain;
1013 chip = snd_kcontrol_chip(kcontrol);
1014 spin_lock_irq(&chip->lock);
1015 for (c = 0; c < num_busses_out(chip); c++) {
1016 gain = ucontrol->value.integer.value[c];
1017 /* Ignore out of range values */
1018 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1020 if (chip->output_gain[c] != gain) {
1021 set_output_gain(chip, c, gain);
1026 update_output_line_level(chip);
1027 spin_unlock_irq(&chip->lock);
1031 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1032 /* On the Mia this one controls the line-out volume */
1033 static const struct snd_kcontrol_new snd_echo_line_output_gain = {
1034 .name = "Line Playback Volume",
1035 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1036 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1037 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1038 .info = snd_echo_output_gain_info,
1039 .get = snd_echo_output_gain_get,
1040 .put = snd_echo_output_gain_put,
1041 .tlv = {.p = db_scale_output_gain},
1044 static const struct snd_kcontrol_new snd_echo_pcm_output_gain = {
1045 .name = "PCM Playback Volume",
1046 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1047 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1048 .info = snd_echo_output_gain_info,
1049 .get = snd_echo_output_gain_get,
1050 .put = snd_echo_output_gain_put,
1051 .tlv = {.p = db_scale_output_gain},
1055 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1059 #ifdef ECHOCARD_HAS_INPUT_GAIN
1061 /******************* Analog input volume *******************/
1062 static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
1063 struct snd_ctl_elem_info *uinfo)
1065 struct echoaudio *chip;
1067 chip = snd_kcontrol_chip(kcontrol);
1068 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1069 uinfo->count = num_analog_busses_in(chip);
1070 uinfo->value.integer.min = ECHOGAIN_MININP;
1071 uinfo->value.integer.max = ECHOGAIN_MAXINP;
1075 static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
1076 struct snd_ctl_elem_value *ucontrol)
1078 struct echoaudio *chip;
1081 chip = snd_kcontrol_chip(kcontrol);
1082 for (c = 0; c < num_analog_busses_in(chip); c++)
1083 ucontrol->value.integer.value[c] = chip->input_gain[c];
1087 static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
1088 struct snd_ctl_elem_value *ucontrol)
1090 struct echoaudio *chip;
1091 int c, gain, changed;
1094 chip = snd_kcontrol_chip(kcontrol);
1095 spin_lock_irq(&chip->lock);
1096 for (c = 0; c < num_analog_busses_in(chip); c++) {
1097 gain = ucontrol->value.integer.value[c];
1098 /* Ignore out of range values */
1099 if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
1101 if (chip->input_gain[c] != gain) {
1102 set_input_gain(chip, c, gain);
1107 update_input_line_level(chip);
1108 spin_unlock_irq(&chip->lock);
1112 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain, -2500, 50, 0);
1114 static const struct snd_kcontrol_new snd_echo_line_input_gain = {
1115 .name = "Line Capture Volume",
1116 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1117 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1118 .info = snd_echo_input_gain_info,
1119 .get = snd_echo_input_gain_get,
1120 .put = snd_echo_input_gain_put,
1121 .tlv = {.p = db_scale_input_gain},
1124 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1128 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1130 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1131 static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
1132 struct snd_ctl_elem_info *uinfo)
1134 struct echoaudio *chip;
1136 chip = snd_kcontrol_chip(kcontrol);
1137 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1138 uinfo->count = num_analog_busses_out(chip);
1139 uinfo->value.integer.min = 0;
1140 uinfo->value.integer.max = 1;
1144 static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
1145 struct snd_ctl_elem_value *ucontrol)
1147 struct echoaudio *chip;
1150 chip = snd_kcontrol_chip(kcontrol);
1151 for (c = 0; c < num_analog_busses_out(chip); c++)
1152 ucontrol->value.integer.value[c] = chip->nominal_level[c];
1156 static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
1157 struct snd_ctl_elem_value *ucontrol)
1159 struct echoaudio *chip;
1163 chip = snd_kcontrol_chip(kcontrol);
1164 spin_lock_irq(&chip->lock);
1165 for (c = 0; c < num_analog_busses_out(chip); c++) {
1166 if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
1167 set_nominal_level(chip, c,
1168 ucontrol->value.integer.value[c]);
1173 update_output_line_level(chip);
1174 spin_unlock_irq(&chip->lock);
1178 static const struct snd_kcontrol_new snd_echo_output_nominal_level = {
1179 .name = "Line Playback Switch (-10dBV)",
1180 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1181 .info = snd_echo_output_nominal_info,
1182 .get = snd_echo_output_nominal_get,
1183 .put = snd_echo_output_nominal_put,
1186 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1190 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1192 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1193 static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
1194 struct snd_ctl_elem_info *uinfo)
1196 struct echoaudio *chip;
1198 chip = snd_kcontrol_chip(kcontrol);
1199 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1200 uinfo->count = num_analog_busses_in(chip);
1201 uinfo->value.integer.min = 0;
1202 uinfo->value.integer.max = 1;
1206 static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
1207 struct snd_ctl_elem_value *ucontrol)
1209 struct echoaudio *chip;
1212 chip = snd_kcontrol_chip(kcontrol);
1213 for (c = 0; c < num_analog_busses_in(chip); c++)
1214 ucontrol->value.integer.value[c] =
1215 chip->nominal_level[bx_analog_in(chip) + c];
1219 static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
1220 struct snd_ctl_elem_value *ucontrol)
1222 struct echoaudio *chip;
1226 chip = snd_kcontrol_chip(kcontrol);
1227 spin_lock_irq(&chip->lock);
1228 for (c = 0; c < num_analog_busses_in(chip); c++) {
1229 if (chip->nominal_level[bx_analog_in(chip) + c] !=
1230 ucontrol->value.integer.value[c]) {
1231 set_nominal_level(chip, bx_analog_in(chip) + c,
1232 ucontrol->value.integer.value[c]);
1237 update_output_line_level(chip); /* "Output" is not a mistake
1240 spin_unlock_irq(&chip->lock);
1244 static const struct snd_kcontrol_new snd_echo_intput_nominal_level = {
1245 .name = "Line Capture Switch (-10dBV)",
1246 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1247 .info = snd_echo_input_nominal_info,
1248 .get = snd_echo_input_nominal_get,
1249 .put = snd_echo_input_nominal_put,
1252 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1256 #ifdef ECHOCARD_HAS_MONITOR
1258 /******************* Monitor mixer *******************/
1259 static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1260 struct snd_ctl_elem_info *uinfo)
1262 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1264 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1265 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1269 static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1270 struct snd_ctl_elem_value *ucontrol)
1272 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1273 unsigned int out = ucontrol->id.index / num_busses_in(chip);
1274 unsigned int in = ucontrol->id.index % num_busses_in(chip);
1276 if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS)
1279 ucontrol->value.integer.value[0] = chip->monitor_gain[out][in];
1283 static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1284 struct snd_ctl_elem_value *ucontrol)
1286 struct echoaudio *chip;
1288 unsigned int out, in;
1291 chip = snd_kcontrol_chip(kcontrol);
1292 out = ucontrol->id.index / num_busses_in(chip);
1293 in = ucontrol->id.index % num_busses_in(chip);
1294 if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS)
1296 gain = ucontrol->value.integer.value[0];
1297 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1299 if (chip->monitor_gain[out][in] != gain) {
1300 spin_lock_irq(&chip->lock);
1301 set_monitor_gain(chip, out, in, gain);
1302 update_output_line_level(chip);
1303 spin_unlock_irq(&chip->lock);
1309 static struct snd_kcontrol_new snd_echo_monitor_mixer = {
1310 .name = "Monitor Mixer Volume",
1311 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1312 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1313 .info = snd_echo_mixer_info,
1314 .get = snd_echo_mixer_get,
1315 .put = snd_echo_mixer_put,
1316 .tlv = {.p = db_scale_output_gain},
1319 #endif /* ECHOCARD_HAS_MONITOR */
1323 #ifdef ECHOCARD_HAS_VMIXER
1325 /******************* Vmixer *******************/
1326 static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
1327 struct snd_ctl_elem_info *uinfo)
1329 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1331 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1332 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1336 static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
1337 struct snd_ctl_elem_value *ucontrol)
1339 struct echoaudio *chip;
1341 chip = snd_kcontrol_chip(kcontrol);
1342 ucontrol->value.integer.value[0] =
1343 chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
1344 [ucontrol->id.index % num_pipes_out(chip)];
1348 static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
1349 struct snd_ctl_elem_value *ucontrol)
1351 struct echoaudio *chip;
1356 chip = snd_kcontrol_chip(kcontrol);
1357 out = ucontrol->id.index / num_pipes_out(chip);
1358 vch = ucontrol->id.index % num_pipes_out(chip);
1359 gain = ucontrol->value.integer.value[0];
1360 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1362 if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
1363 spin_lock_irq(&chip->lock);
1364 set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
1365 update_vmixer_level(chip);
1366 spin_unlock_irq(&chip->lock);
1372 static struct snd_kcontrol_new snd_echo_vmixer = {
1373 .name = "VMixer Volume",
1374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1375 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1376 .info = snd_echo_vmixer_info,
1377 .get = snd_echo_vmixer_get,
1378 .put = snd_echo_vmixer_put,
1379 .tlv = {.p = db_scale_output_gain},
1382 #endif /* ECHOCARD_HAS_VMIXER */
1386 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1388 /******************* Digital mode switch *******************/
1389 static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1390 struct snd_ctl_elem_info *uinfo)
1392 static const char * const names[4] = {
1393 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1396 struct echoaudio *chip;
1398 chip = snd_kcontrol_chip(kcontrol);
1399 return snd_ctl_enum_info(uinfo, 1, chip->num_digital_modes, names);
1402 static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
1403 struct snd_ctl_elem_value *ucontrol)
1405 struct echoaudio *chip;
1408 chip = snd_kcontrol_chip(kcontrol);
1409 mode = chip->digital_mode;
1410 for (i = chip->num_digital_modes - 1; i >= 0; i--)
1411 if (mode == chip->digital_mode_list[i]) {
1412 ucontrol->value.enumerated.item[0] = i;
1418 static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1419 struct snd_ctl_elem_value *ucontrol)
1421 struct echoaudio *chip;
1423 unsigned short emode, dmode;
1426 chip = snd_kcontrol_chip(kcontrol);
1428 emode = ucontrol->value.enumerated.item[0];
1429 if (emode >= chip->num_digital_modes)
1431 dmode = chip->digital_mode_list[emode];
1433 if (dmode != chip->digital_mode) {
1434 /* mode_mutex is required to make this operation atomic wrt
1435 pcm_digital_*_open() and set_input_clock() functions. */
1436 mutex_lock(&chip->mode_mutex);
1438 /* Do not allow the user to change the digital mode when a pcm
1439 device is open because it also changes the number of channels
1440 and the allowed sample rates */
1441 if (chip->opencount) {
1444 changed = set_digital_mode(chip, dmode);
1445 /* If we had to change the clock source, report it */
1446 if (changed > 0 && chip->clock_src_ctl) {
1447 snd_ctl_notify(chip->card,
1448 SNDRV_CTL_EVENT_MASK_VALUE,
1449 &chip->clock_src_ctl->id);
1450 dev_dbg(chip->card->dev,
1451 "SDM() =%d\n", changed);
1454 changed = 1; /* No errors */
1456 mutex_unlock(&chip->mode_mutex);
1461 static const struct snd_kcontrol_new snd_echo_digital_mode_switch = {
1462 .name = "Digital mode Switch",
1463 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1464 .info = snd_echo_digital_mode_info,
1465 .get = snd_echo_digital_mode_get,
1466 .put = snd_echo_digital_mode_put,
1469 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1473 #ifdef ECHOCARD_HAS_DIGITAL_IO
1475 /******************* S/PDIF mode switch *******************/
1476 static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1477 struct snd_ctl_elem_info *uinfo)
1479 static const char * const names[2] = {"Consumer", "Professional"};
1481 return snd_ctl_enum_info(uinfo, 1, 2, names);
1484 static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
1485 struct snd_ctl_elem_value *ucontrol)
1487 struct echoaudio *chip;
1489 chip = snd_kcontrol_chip(kcontrol);
1490 ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
1494 static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
1495 struct snd_ctl_elem_value *ucontrol)
1497 struct echoaudio *chip;
1500 chip = snd_kcontrol_chip(kcontrol);
1501 mode = !!ucontrol->value.enumerated.item[0];
1502 if (mode != chip->professional_spdif) {
1503 spin_lock_irq(&chip->lock);
1504 set_professional_spdif(chip, mode);
1505 spin_unlock_irq(&chip->lock);
1511 static const struct snd_kcontrol_new snd_echo_spdif_mode_switch = {
1512 .name = "S/PDIF mode Switch",
1513 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1514 .info = snd_echo_spdif_mode_info,
1515 .get = snd_echo_spdif_mode_get,
1516 .put = snd_echo_spdif_mode_put,
1519 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1523 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1525 /******************* Select input clock source *******************/
1526 static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1527 struct snd_ctl_elem_info *uinfo)
1529 static const char * const names[8] = {
1530 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1533 struct echoaudio *chip;
1535 chip = snd_kcontrol_chip(kcontrol);
1536 return snd_ctl_enum_info(uinfo, 1, chip->num_clock_sources, names);
1539 static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
1540 struct snd_ctl_elem_value *ucontrol)
1542 struct echoaudio *chip;
1545 chip = snd_kcontrol_chip(kcontrol);
1546 clock = chip->input_clock;
1548 for (i = 0; i < chip->num_clock_sources; i++)
1549 if (clock == chip->clock_source_list[i])
1550 ucontrol->value.enumerated.item[0] = i;
1555 static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1556 struct snd_ctl_elem_value *ucontrol)
1558 struct echoaudio *chip;
1560 unsigned int eclock, dclock;
1563 chip = snd_kcontrol_chip(kcontrol);
1564 eclock = ucontrol->value.enumerated.item[0];
1565 if (eclock >= chip->input_clock_types)
1567 dclock = chip->clock_source_list[eclock];
1568 if (chip->input_clock != dclock) {
1569 mutex_lock(&chip->mode_mutex);
1570 spin_lock_irq(&chip->lock);
1571 if ((changed = set_input_clock(chip, dclock)) == 0)
1572 changed = 1; /* no errors */
1573 spin_unlock_irq(&chip->lock);
1574 mutex_unlock(&chip->mode_mutex);
1578 dev_dbg(chip->card->dev,
1579 "seticlk val%d err 0x%x\n", dclock, changed);
1584 static const struct snd_kcontrol_new snd_echo_clock_source_switch = {
1585 .name = "Sample Clock Source",
1586 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1587 .info = snd_echo_clock_source_info,
1588 .get = snd_echo_clock_source_get,
1589 .put = snd_echo_clock_source_put,
1592 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1596 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1598 /******************* Phantom power switch *******************/
1599 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1601 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1602 struct snd_ctl_elem_value *ucontrol)
1604 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1606 ucontrol->value.integer.value[0] = chip->phantom_power;
1610 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1611 struct snd_ctl_elem_value *ucontrol)
1613 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1614 int power, changed = 0;
1616 power = !!ucontrol->value.integer.value[0];
1617 if (chip->phantom_power != power) {
1618 spin_lock_irq(&chip->lock);
1619 changed = set_phantom_power(chip, power);
1620 spin_unlock_irq(&chip->lock);
1622 changed = 1; /* no errors */
1627 static const struct snd_kcontrol_new snd_echo_phantom_power_switch = {
1628 .name = "Phantom power Switch",
1629 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1630 .info = snd_echo_phantom_power_info,
1631 .get = snd_echo_phantom_power_get,
1632 .put = snd_echo_phantom_power_put,
1635 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1639 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1641 /******************* Digital input automute switch *******************/
1642 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1644 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1645 struct snd_ctl_elem_value *ucontrol)
1647 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1649 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1653 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1654 struct snd_ctl_elem_value *ucontrol)
1656 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1657 int automute, changed = 0;
1659 automute = !!ucontrol->value.integer.value[0];
1660 if (chip->digital_in_automute != automute) {
1661 spin_lock_irq(&chip->lock);
1662 changed = set_input_auto_mute(chip, automute);
1663 spin_unlock_irq(&chip->lock);
1665 changed = 1; /* no errors */
1670 static const struct snd_kcontrol_new snd_echo_automute_switch = {
1671 .name = "Digital Capture Switch (automute)",
1672 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1673 .info = snd_echo_automute_info,
1674 .get = snd_echo_automute_get,
1675 .put = snd_echo_automute_put,
1678 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1682 /******************* VU-meters switch *******************/
1683 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1685 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1686 struct snd_ctl_elem_value *ucontrol)
1688 struct echoaudio *chip;
1690 chip = snd_kcontrol_chip(kcontrol);
1691 spin_lock_irq(&chip->lock);
1692 set_meters_on(chip, ucontrol->value.integer.value[0]);
1693 spin_unlock_irq(&chip->lock);
1697 static const struct snd_kcontrol_new snd_echo_vumeters_switch = {
1698 .name = "VU-meters Switch",
1699 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1700 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1701 .info = snd_echo_vumeters_switch_info,
1702 .put = snd_echo_vumeters_switch_put,
1707 /***** Read VU-meters (input, output, analog and digital together) *****/
1708 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1709 struct snd_ctl_elem_info *uinfo)
1711 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1713 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1714 uinfo->value.integer.max = 0;
1718 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1719 struct snd_ctl_elem_value *ucontrol)
1721 struct echoaudio *chip;
1723 chip = snd_kcontrol_chip(kcontrol);
1724 get_audio_meters(chip, ucontrol->value.integer.value);
1728 static const struct snd_kcontrol_new snd_echo_vumeters = {
1729 .name = "VU-meters",
1730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1731 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1732 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
1733 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1734 .info = snd_echo_vumeters_info,
1735 .get = snd_echo_vumeters_get,
1736 .tlv = {.p = db_scale_output_gain},
1741 /*** Channels info - it exports informations about the number of channels ***/
1742 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1743 struct snd_ctl_elem_info *uinfo)
1745 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1747 uinfo->value.integer.min = 0;
1748 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1752 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1753 struct snd_ctl_elem_value *ucontrol)
1755 struct echoaudio *chip;
1756 int detected, clocks, bit, src;
1758 chip = snd_kcontrol_chip(kcontrol);
1759 ucontrol->value.integer.value[0] = num_busses_in(chip);
1760 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1761 ucontrol->value.integer.value[2] = num_busses_out(chip);
1762 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1763 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1765 /* Compute the bitmask of the currently valid input clocks */
1766 detected = detect_input_clocks(chip);
1768 src = chip->num_clock_sources - 1;
1769 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1770 if (detected & (1 << bit))
1771 for (; src >= 0; src--)
1772 if (bit == chip->clock_source_list[src]) {
1776 ucontrol->value.integer.value[5] = clocks;
1781 static const struct snd_kcontrol_new snd_echo_channels_info = {
1782 .name = "Channels info",
1783 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1784 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1785 .info = snd_echo_channels_info_info,
1786 .get = snd_echo_channels_info_get,
1792 /******************************************************************************
1794 ******************************************************************************/
1795 /* Check if a period has elapsed since last interrupt
1797 * Don't make any updates to state; PCM core handles this with the
1800 * \return true if a period has elapsed, otherwise false
1802 static bool period_has_elapsed(struct snd_pcm_substream *substream)
1804 struct snd_pcm_runtime *runtime = substream->runtime;
1805 struct audiopipe *pipe = runtime->private_data;
1807 size_t period_bytes;
1809 if (pipe->state != PIPE_STATE_STARTED)
1812 period_bytes = frames_to_bytes(runtime, runtime->period_size);
1814 counter = le32_to_cpu(*pipe->dma_counter); /* presumed atomic */
1816 step = counter - pipe->last_period; /* handles wrapping */
1817 step -= step % period_bytes; /* acknowledge whole periods only */
1820 return false; /* haven't advanced a whole period yet */
1822 pipe->last_period += step; /* used exclusively by us */
1826 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1828 struct echoaudio *chip = dev_id;
1831 spin_lock(&chip->lock);
1832 st = service_irq(chip);
1834 spin_unlock(&chip->lock);
1837 /* The hardware doesn't tell us which substream caused the irq,
1838 thus we have to check all running substreams. */
1839 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1840 struct snd_pcm_substream *substream;
1842 substream = chip->substream[ss];
1843 if (substream && period_has_elapsed(substream)) {
1844 spin_unlock(&chip->lock);
1845 snd_pcm_period_elapsed(substream);
1846 spin_lock(&chip->lock);
1849 spin_unlock(&chip->lock);
1851 #ifdef ECHOCARD_HAS_MIDI
1852 if (st > 0 && chip->midi_in) {
1853 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1854 dev_dbg(chip->card->dev, "rawmidi_iread=%d\n", st);
1863 /******************************************************************************
1864 Module construction / destruction
1865 ******************************************************************************/
1867 static int snd_echo_free(struct echoaudio *chip)
1869 if (chip->comm_page)
1870 rest_in_peace(chip);
1873 free_irq(chip->irq, chip);
1875 if (chip->comm_page)
1876 snd_dma_free_pages(&chip->commpage_dma_buf);
1878 iounmap(chip->dsp_registers);
1879 release_and_free_resource(chip->iores);
1880 pci_disable_device(chip->pci);
1882 /* release chip data */
1883 free_firmware_cache(chip);
1890 static int snd_echo_dev_free(struct snd_device *device)
1892 struct echoaudio *chip = device->device_data;
1894 return snd_echo_free(chip);
1899 /* <--snd_echo_probe() */
1900 static int snd_echo_create(struct snd_card *card,
1901 struct pci_dev *pci,
1902 struct echoaudio **rchip)
1904 struct echoaudio *chip;
1907 static const struct snd_device_ops ops = {
1908 .dev_free = snd_echo_dev_free,
1913 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1915 if ((err = pci_enable_device(pci)) < 0)
1917 pci_set_master(pci);
1919 /* Allocate chip if needed */
1921 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1923 pci_disable_device(pci);
1926 dev_dbg(card->dev, "chip=%p\n", chip);
1927 spin_lock_init(&chip->lock);
1931 chip->opencount = 0;
1932 mutex_init(&chip->mode_mutex);
1933 chip->can_set_rate = 1;
1935 /* If this was called from the resume function, chip is
1936 * already allocated and it contains current card settings.
1941 /* PCI resource allocation */
1942 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1943 sz = pci_resource_len(pci, 0);
1945 sz = PAGE_SIZE; /* We map only the required part */
1947 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1948 ECHOCARD_NAME)) == NULL) {
1949 dev_err(chip->card->dev, "cannot get memory region\n");
1950 snd_echo_free(chip);
1953 chip->dsp_registers = ioremap(chip->dsp_registers_phys, sz);
1954 if (!chip->dsp_registers) {
1955 dev_err(chip->card->dev, "ioremap failed\n");
1956 snd_echo_free(chip);
1960 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1961 KBUILD_MODNAME, chip)) {
1962 dev_err(chip->card->dev, "cannot grab irq\n");
1963 snd_echo_free(chip);
1966 chip->irq = pci->irq;
1967 card->sync_irq = chip->irq;
1968 dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n",
1969 chip->pci, chip->irq, chip->pci->subsystem_device);
1971 /* Create the DSP comm page - this is the area of memory used for most
1972 of the communication with the DSP, which accesses it via bus mastering */
1973 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
1974 sizeof(struct comm_page),
1975 &chip->commpage_dma_buf) < 0) {
1976 dev_err(chip->card->dev, "cannot allocate the comm page\n");
1977 snd_echo_free(chip);
1980 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1981 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1983 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1985 err = set_mixer_defaults(chip);
1987 dev_err(card->dev, "init_hw err=%d\n", err);
1988 snd_echo_free(chip);
1992 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1993 snd_echo_free(chip);
2004 static int snd_echo_probe(struct pci_dev *pci,
2005 const struct pci_device_id *pci_id)
2008 struct snd_card *card;
2009 struct echoaudio *chip;
2011 __maybe_unused int i;
2014 if (dev >= SNDRV_CARDS)
2022 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2027 chip = NULL; /* Tells snd_echo_create to allocate chip */
2028 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2029 snd_card_free(card);
2033 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
2034 strcpy(card->shortname, chip->card_name);
2037 if (pci_id->device == 0x3410)
2040 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2041 card->shortname, pci_id->subdevice & 0x000f, dsp,
2042 chip->dsp_registers_phys, chip->irq);
2044 if ((err = snd_echo_new_pcm(chip)) < 0) {
2045 dev_err(chip->card->dev, "new pcm error %d\n", err);
2046 snd_card_free(card);
2050 #ifdef ECHOCARD_HAS_MIDI
2051 if (chip->has_midi) { /* Some Mia's do not have midi */
2052 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2053 dev_err(chip->card->dev, "new midi error %d\n", err);
2054 snd_card_free(card);
2060 #ifdef ECHOCARD_HAS_VMIXER
2061 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2062 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2064 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2065 err = snd_ctl_add(chip->card,
2066 snd_ctl_new1(&snd_echo_line_output_gain, chip));
2070 #else /* ECHOCARD_HAS_VMIXER */
2071 err = snd_ctl_add(chip->card,
2072 snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
2075 #endif /* ECHOCARD_HAS_VMIXER */
2077 #ifdef ECHOCARD_HAS_INPUT_GAIN
2078 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2082 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2083 if (!chip->hasnt_input_nominal_level)
2084 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2088 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2089 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2093 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2096 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2099 #ifdef ECHOCARD_HAS_MONITOR
2100 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2101 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2105 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2106 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2110 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2113 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2114 /* Creates a list of available digital modes */
2115 chip->num_digital_modes = 0;
2116 for (i = 0; i < 6; i++)
2117 if (chip->digital_modes & (1 << i))
2118 chip->digital_mode_list[chip->num_digital_modes++] = i;
2120 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2122 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2124 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2125 /* Creates a list of available clock sources */
2126 chip->num_clock_sources = 0;
2127 for (i = 0; i < 10; i++)
2128 if (chip->input_clock_types & (1 << i))
2129 chip->clock_source_list[chip->num_clock_sources++] = i;
2131 if (chip->num_clock_sources > 1) {
2132 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2133 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2136 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2138 #ifdef ECHOCARD_HAS_DIGITAL_IO
2139 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2143 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2144 if (chip->has_phantom_power)
2145 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2149 err = snd_card_register(card);
2152 dev_info(card->dev, "Card registered: %s\n", card->longname);
2154 pci_set_drvdata(pci, chip);
2159 dev_err(card->dev, "new control error %d\n", err);
2160 snd_card_free(card);
2166 #if defined(CONFIG_PM_SLEEP)
2168 static int snd_echo_suspend(struct device *dev)
2170 struct echoaudio *chip = dev_get_drvdata(dev);
2172 #ifdef ECHOCARD_HAS_MIDI
2173 /* This call can sleep */
2175 snd_echo_midi_output_trigger(chip->midi_out, 0);
2177 spin_lock_irq(&chip->lock);
2178 if (wait_handshake(chip)) {
2179 spin_unlock_irq(&chip->lock);
2182 clear_handshake(chip);
2183 if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) {
2184 spin_unlock_irq(&chip->lock);
2187 spin_unlock_irq(&chip->lock);
2189 chip->dsp_code = NULL;
2190 free_irq(chip->irq, chip);
2192 chip->card->sync_irq = -1;
2198 static int snd_echo_resume(struct device *dev)
2200 struct pci_dev *pci = to_pci_dev(dev);
2201 struct echoaudio *chip = dev_get_drvdata(dev);
2202 struct comm_page *commpage, *commpage_bak;
2203 u32 pipe_alloc_mask;
2206 commpage = chip->comm_page;
2207 commpage_bak = kmemdup(commpage, sizeof(*commpage), GFP_KERNEL);
2208 if (commpage_bak == NULL)
2211 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
2213 kfree(commpage_bak);
2214 dev_err(dev, "resume init_hw err=%d\n", err);
2218 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2219 * restore_dsp_settings() fails.
2221 pipe_alloc_mask = chip->pipe_alloc_mask;
2222 chip->pipe_alloc_mask = 0;
2223 err = restore_dsp_rettings(chip);
2224 chip->pipe_alloc_mask = pipe_alloc_mask;
2226 kfree(commpage_bak);
2230 memcpy(&commpage->audio_format, &commpage_bak->audio_format,
2231 sizeof(commpage->audio_format));
2232 memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr,
2233 sizeof(commpage->sglist_addr));
2234 memcpy(&commpage->midi_output, &commpage_bak->midi_output,
2235 sizeof(commpage->midi_output));
2236 kfree(commpage_bak);
2238 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
2239 KBUILD_MODNAME, chip)) {
2240 dev_err(chip->card->dev, "cannot grab irq\n");
2243 chip->irq = pci->irq;
2244 chip->card->sync_irq = chip->irq;
2245 dev_dbg(dev, "resume irq=%d\n", chip->irq);
2247 #ifdef ECHOCARD_HAS_MIDI
2248 if (chip->midi_input_enabled)
2249 enable_midi_input(chip, true);
2251 snd_echo_midi_output_trigger(chip->midi_out, 1);
2257 static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume);
2258 #define SND_ECHO_PM_OPS &snd_echo_pm
2260 #define SND_ECHO_PM_OPS NULL
2261 #endif /* CONFIG_PM_SLEEP */
2264 static void snd_echo_remove(struct pci_dev *pci)
2266 struct echoaudio *chip;
2268 chip = pci_get_drvdata(pci);
2270 snd_card_free(chip->card);
2275 /******************************************************************************
2276 Everything starts and ends here
2277 ******************************************************************************/
2279 /* pci_driver definition */
2280 static struct pci_driver echo_driver = {
2281 .name = KBUILD_MODNAME,
2282 .id_table = snd_echo_ids,
2283 .probe = snd_echo_probe,
2284 .remove = snd_echo_remove,
2286 .pm = SND_ECHO_PM_OPS,
2290 module_pci_driver(echo_driver);