1 // SPDX-License-Identifier: GPL-2.0-only
3 * ALSA driver for Echoaudio soundcards.
4 * Copyright (C) 2003-2004 Giuliano Pochini <pochini@shiny.it>
7 #include <linux/module.h>
9 MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>");
10 MODULE_LICENSE("GPL v2");
11 MODULE_DESCRIPTION("Echoaudio " ECHOCARD_NAME " soundcards driver");
12 MODULE_SUPPORTED_DEVICE("{{Echoaudio," ECHOCARD_NAME "}}");
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 #ifdef CONFIG_PM_SLEEP
38 if (chip->fw_cache[fw_index]) {
39 dev_dbg(chip->card->dev,
40 "firmware requested: %s is cached\n",
41 card_fw[fw_index].data);
42 *fw_entry = chip->fw_cache[fw_index];
47 dev_dbg(chip->card->dev,
48 "firmware requested: %s\n", card_fw[fw_index].data);
49 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data);
50 err = request_firmware(fw_entry, name, &chip->pci->dev);
52 dev_err(chip->card->dev,
53 "get_firmware(): Firmware not available (%d)\n", err);
54 #ifdef CONFIG_PM_SLEEP
56 chip->fw_cache[fw_index] = *fw_entry;
63 static void free_firmware(const struct firmware *fw_entry,
64 struct echoaudio *chip)
66 #ifdef CONFIG_PM_SLEEP
67 dev_dbg(chip->card->dev, "firmware not released (kept in cache)\n");
69 release_firmware(fw_entry);
75 static void free_firmware_cache(struct echoaudio *chip)
77 #ifdef CONFIG_PM_SLEEP
80 for (i = 0; i < 8 ; i++)
81 if (chip->fw_cache[i]) {
82 release_firmware(chip->fw_cache[i]);
83 dev_dbg(chip->card->dev, "release_firmware(%d)\n", i);
91 /******************************************************************************
93 ******************************************************************************/
95 static void audiopipe_free(struct snd_pcm_runtime *runtime)
97 struct audiopipe *pipe = runtime->private_data;
99 if (pipe->sgpage.area)
100 snd_dma_free_pages(&pipe->sgpage);
106 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
107 struct snd_pcm_hw_rule *rule)
109 struct snd_interval *c = hw_param_interval(params,
110 SNDRV_PCM_HW_PARAM_CHANNELS);
111 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
116 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
117 /* >=2 channels cannot be S32_BE */
119 fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
120 return snd_mask_refine(f, &fmt);
123 /* > 2 channels cannot be U8 and S32_BE */
125 fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
126 return snd_mask_refine(f, &fmt);
128 /* Mono is ok with any format */
134 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
135 struct snd_pcm_hw_rule *rule)
137 struct snd_interval *c = hw_param_interval(params,
138 SNDRV_PCM_HW_PARAM_CHANNELS);
139 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
140 struct snd_interval ch;
142 snd_interval_any(&ch);
144 /* S32_BE is mono (and stereo) only */
145 if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
147 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
153 return snd_interval_refine(c, &ch);
155 /* U8 can be only mono or stereo */
156 if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
160 return snd_interval_refine(c, &ch);
162 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
168 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
169 struct snd_pcm_hw_rule *rule)
171 struct snd_interval *c = hw_param_interval(params,
172 SNDRV_PCM_HW_PARAM_CHANNELS);
173 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
178 fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
180 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
182 fmask &= SNDRV_PCM_FMTBIT_S16_LE |
183 SNDRV_PCM_FMTBIT_S24_3LE |
184 SNDRV_PCM_FMTBIT_S32_LE;
185 /* 1 channel must be S32_BE or S32_LE */
186 } else if (c->max == 1)
187 fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
188 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
189 /* 2 channels cannot be S32_BE */
190 else if (c->min == 2 && c->max == 2)
191 fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
196 fmt.bits[0] &= (u32)fmask;
197 fmt.bits[1] &= (u32)(fmask >> 32);
198 return snd_mask_refine(f, &fmt);
203 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
204 struct snd_pcm_hw_rule *rule)
206 struct snd_interval *c = hw_param_interval(params,
207 SNDRV_PCM_HW_PARAM_CHANNELS);
208 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
209 struct snd_interval ch;
212 snd_interval_any(&ch);
214 fmask = f->bits[0] + ((u64)f->bits[1] << 32);
216 /* S32_BE is mono (and stereo) only */
217 if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
219 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
224 /* U8 is stereo only */
225 } else if (fmask == SNDRV_PCM_FMTBIT_U8)
227 /* S16_LE and S24_3LE must be at least stereo */
228 else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
229 SNDRV_PCM_FMTBIT_S24_3LE)))
234 return snd_interval_refine(c, &ch);
239 /* Since the sample rate is a global setting, do allow the user to change the
240 sample rate only if there is only one pcm device open. */
241 static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
242 struct snd_pcm_hw_rule *rule)
244 struct snd_interval *rate = hw_param_interval(params,
245 SNDRV_PCM_HW_PARAM_RATE);
246 struct echoaudio *chip = rule->private;
247 struct snd_interval fixed;
249 if (!chip->can_set_rate) {
250 snd_interval_any(&fixed);
251 fixed.min = fixed.max = chip->sample_rate;
252 return snd_interval_refine(rate, &fixed);
258 static int pcm_open(struct snd_pcm_substream *substream,
259 signed char max_channels)
261 struct echoaudio *chip;
262 struct snd_pcm_runtime *runtime;
263 struct audiopipe *pipe;
266 if (max_channels <= 0)
269 chip = snd_pcm_substream_chip(substream);
270 runtime = substream->runtime;
272 pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
275 pipe->index = -1; /* Not configured yet */
277 /* Set up hw capabilities and contraints */
278 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
279 dev_dbg(chip->card->dev, "max_channels=%d\n", max_channels);
280 pipe->constr.list = channels_list;
281 pipe->constr.mask = 0;
282 for (i = 0; channels_list[i] <= max_channels; i++);
283 pipe->constr.count = i;
284 if (pipe->hw.channels_max > max_channels)
285 pipe->hw.channels_max = max_channels;
286 if (chip->digital_mode == DIGITAL_MODE_ADAT) {
287 pipe->hw.rate_max = 48000;
288 pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
291 runtime->hw = pipe->hw;
292 runtime->private_data = pipe;
293 runtime->private_free = audiopipe_free;
294 snd_pcm_set_sync(substream);
296 /* Only mono and any even number of channels are allowed */
297 if ((err = snd_pcm_hw_constraint_list(runtime, 0,
298 SNDRV_PCM_HW_PARAM_CHANNELS,
302 /* All periods should have the same size */
303 if ((err = snd_pcm_hw_constraint_integer(runtime,
304 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
307 /* The hw accesses memory in chunks 32 frames long and they should be
308 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
309 generated with a resolution of 32 frames. Thus we need the following */
310 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
311 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
314 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
315 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
319 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
320 SNDRV_PCM_HW_PARAM_RATE,
321 hw_rule_sample_rate, chip,
322 SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
325 /* Finally allocate a page for the scatter-gather list */
326 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
328 PAGE_SIZE, &pipe->sgpage)) < 0) {
329 dev_err(chip->card->dev, "s-g list allocation failed\n");
338 static int pcm_analog_in_open(struct snd_pcm_substream *substream)
340 struct echoaudio *chip = snd_pcm_substream_chip(substream);
343 if ((err = pcm_open(substream, num_analog_busses_in(chip) -
344 substream->number)) < 0)
346 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
347 SNDRV_PCM_HW_PARAM_CHANNELS,
348 hw_rule_capture_channels_by_format, NULL,
349 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
351 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
352 SNDRV_PCM_HW_PARAM_FORMAT,
353 hw_rule_capture_format_by_channels, NULL,
354 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
356 atomic_inc(&chip->opencount);
357 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
358 chip->can_set_rate=0;
359 dev_dbg(chip->card->dev, "pcm_analog_in_open cs=%d oc=%d r=%d\n",
360 chip->can_set_rate, atomic_read(&chip->opencount),
367 static int pcm_analog_out_open(struct snd_pcm_substream *substream)
369 struct echoaudio *chip = snd_pcm_substream_chip(substream);
370 int max_channels, err;
372 #ifdef ECHOCARD_HAS_VMIXER
373 max_channels = num_pipes_out(chip);
375 max_channels = num_analog_busses_out(chip);
377 if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
379 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
380 SNDRV_PCM_HW_PARAM_CHANNELS,
381 hw_rule_playback_channels_by_format,
383 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
385 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
386 SNDRV_PCM_HW_PARAM_FORMAT,
387 hw_rule_playback_format_by_channels,
389 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
391 atomic_inc(&chip->opencount);
392 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
393 chip->can_set_rate=0;
394 dev_dbg(chip->card->dev, "pcm_analog_out_open cs=%d oc=%d r=%d\n",
395 chip->can_set_rate, atomic_read(&chip->opencount),
402 #ifdef ECHOCARD_HAS_DIGITAL_IO
404 static int pcm_digital_in_open(struct snd_pcm_substream *substream)
406 struct echoaudio *chip = snd_pcm_substream_chip(substream);
407 int err, max_channels;
409 max_channels = num_digital_busses_in(chip) - substream->number;
410 mutex_lock(&chip->mode_mutex);
411 if (chip->digital_mode == DIGITAL_MODE_ADAT)
412 err = pcm_open(substream, max_channels);
413 else /* If the card has ADAT, subtract the 6 channels
414 * that S/PDIF doesn't have
416 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
421 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
422 SNDRV_PCM_HW_PARAM_CHANNELS,
423 hw_rule_capture_channels_by_format, NULL,
424 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
426 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
427 SNDRV_PCM_HW_PARAM_FORMAT,
428 hw_rule_capture_format_by_channels, NULL,
429 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
432 atomic_inc(&chip->opencount);
433 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
434 chip->can_set_rate=0;
437 mutex_unlock(&chip->mode_mutex);
443 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
445 static int pcm_digital_out_open(struct snd_pcm_substream *substream)
447 struct echoaudio *chip = snd_pcm_substream_chip(substream);
448 int err, max_channels;
450 max_channels = num_digital_busses_out(chip) - substream->number;
451 mutex_lock(&chip->mode_mutex);
452 if (chip->digital_mode == DIGITAL_MODE_ADAT)
453 err = pcm_open(substream, max_channels);
454 else /* If the card has ADAT, subtract the 6 channels
455 * that S/PDIF doesn't have
457 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
462 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
463 SNDRV_PCM_HW_PARAM_CHANNELS,
464 hw_rule_playback_channels_by_format,
465 NULL, SNDRV_PCM_HW_PARAM_FORMAT,
468 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
469 SNDRV_PCM_HW_PARAM_FORMAT,
470 hw_rule_playback_format_by_channels,
471 NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
474 atomic_inc(&chip->opencount);
475 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
476 chip->can_set_rate=0;
478 mutex_unlock(&chip->mode_mutex);
482 #endif /* !ECHOCARD_HAS_VMIXER */
484 #endif /* ECHOCARD_HAS_DIGITAL_IO */
488 static int pcm_close(struct snd_pcm_substream *substream)
490 struct echoaudio *chip = snd_pcm_substream_chip(substream);
493 /* Nothing to do here. Audio is already off and pipe will be
494 * freed by its callback
497 atomic_dec(&chip->opencount);
498 oc = atomic_read(&chip->opencount);
499 dev_dbg(chip->card->dev, "pcm_close oc=%d cs=%d rs=%d\n", oc,
500 chip->can_set_rate, chip->rate_set);
502 chip->can_set_rate = 1;
505 dev_dbg(chip->card->dev, "pcm_close2 oc=%d cs=%d rs=%d\n", oc,
506 chip->can_set_rate, chip->rate_set);
513 /* Channel allocation and scatter-gather list setup */
514 static int init_engine(struct snd_pcm_substream *substream,
515 struct snd_pcm_hw_params *hw_params,
516 int pipe_index, int interleave)
518 struct echoaudio *chip;
519 int err, per, rest, page, edge, offs;
520 struct audiopipe *pipe;
522 chip = snd_pcm_substream_chip(substream);
523 pipe = (struct audiopipe *) substream->runtime->private_data;
525 /* Sets up che hardware. If it's already initialized, reset and
526 * redo with the new parameters
528 spin_lock_irq(&chip->lock);
529 if (pipe->index >= 0) {
530 dev_dbg(chip->card->dev, "hwp_ie free(%d)\n", pipe->index);
531 err = free_pipes(chip, pipe);
533 chip->substream[pipe->index] = NULL;
536 err = allocate_pipes(chip, pipe, pipe_index, interleave);
538 spin_unlock_irq(&chip->lock);
539 dev_err(chip->card->dev, "allocate_pipes(%d) err=%d\n",
543 spin_unlock_irq(&chip->lock);
544 dev_dbg(chip->card->dev, "allocate_pipes()=%d\n", pipe_index);
546 dev_dbg(chip->card->dev,
547 "pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
548 params_buffer_bytes(hw_params), params_periods(hw_params),
549 params_period_bytes(hw_params));
551 sglist_init(chip, pipe);
553 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
555 rest = params_period_bytes(hw_params);
556 if (offs + rest > params_buffer_bytes(hw_params))
557 rest = params_buffer_bytes(hw_params) - offs;
560 addr = snd_pcm_sgbuf_get_addr(substream, offs);
561 if (rest <= edge - offs) {
562 sglist_add_mapping(chip, pipe, addr, rest);
563 sglist_add_irq(chip, pipe);
567 sglist_add_mapping(chip, pipe, addr,
579 /* Close the ring buffer */
580 sglist_wrap(chip, pipe);
582 /* This stuff is used by the irq handler, so it must be
583 * initialized before chip->substream
585 chip->last_period[pipe_index] = 0;
586 pipe->last_counter = 0;
589 chip->substream[pipe_index] = substream;
591 spin_lock_irq(&chip->lock);
592 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
593 spin_unlock_irq(&chip->lock);
599 static int pcm_analog_in_hw_params(struct snd_pcm_substream *substream,
600 struct snd_pcm_hw_params *hw_params)
602 struct echoaudio *chip = snd_pcm_substream_chip(substream);
604 return init_engine(substream, hw_params, px_analog_in(chip) +
605 substream->number, params_channels(hw_params));
610 static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream,
611 struct snd_pcm_hw_params *hw_params)
613 return init_engine(substream, hw_params, substream->number,
614 params_channels(hw_params));
619 #ifdef ECHOCARD_HAS_DIGITAL_IO
621 static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream,
622 struct snd_pcm_hw_params *hw_params)
624 struct echoaudio *chip = snd_pcm_substream_chip(substream);
626 return init_engine(substream, hw_params, px_digital_in(chip) +
627 substream->number, params_channels(hw_params));
632 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
633 static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream,
634 struct snd_pcm_hw_params *hw_params)
636 struct echoaudio *chip = snd_pcm_substream_chip(substream);
638 return init_engine(substream, hw_params, px_digital_out(chip) +
639 substream->number, params_channels(hw_params));
641 #endif /* !ECHOCARD_HAS_VMIXER */
643 #endif /* ECHOCARD_HAS_DIGITAL_IO */
647 static int pcm_hw_free(struct snd_pcm_substream *substream)
649 struct echoaudio *chip;
650 struct audiopipe *pipe;
652 chip = snd_pcm_substream_chip(substream);
653 pipe = (struct audiopipe *) substream->runtime->private_data;
655 spin_lock_irq(&chip->lock);
656 if (pipe->index >= 0) {
657 dev_dbg(chip->card->dev, "pcm_hw_free(%d)\n", pipe->index);
658 free_pipes(chip, pipe);
659 chip->substream[pipe->index] = NULL;
662 spin_unlock_irq(&chip->lock);
669 static int pcm_prepare(struct snd_pcm_substream *substream)
671 struct echoaudio *chip = snd_pcm_substream_chip(substream);
672 struct snd_pcm_runtime *runtime = substream->runtime;
673 struct audioformat format;
674 int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
676 dev_dbg(chip->card->dev, "Prepare rate=%d format=%d channels=%d\n",
677 runtime->rate, runtime->format, runtime->channels);
678 format.interleave = runtime->channels;
679 format.data_are_bigendian = 0;
680 format.mono_to_stereo = 0;
681 switch (runtime->format) {
682 case SNDRV_PCM_FORMAT_U8:
683 format.bits_per_sample = 8;
685 case SNDRV_PCM_FORMAT_S16_LE:
686 format.bits_per_sample = 16;
688 case SNDRV_PCM_FORMAT_S24_3LE:
689 format.bits_per_sample = 24;
691 case SNDRV_PCM_FORMAT_S32_BE:
692 format.data_are_bigendian = 1;
694 case SNDRV_PCM_FORMAT_S32_LE:
695 format.bits_per_sample = 32;
698 dev_err(chip->card->dev,
699 "Prepare error: unsupported format %d\n",
704 if (snd_BUG_ON(pipe_index >= px_num(chip)))
706 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
708 set_audio_format(chip, pipe_index, &format);
714 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
716 struct echoaudio *chip = snd_pcm_substream_chip(substream);
717 struct audiopipe *pipe;
720 struct snd_pcm_substream *s;
722 snd_pcm_group_for_each_entry(s, substream) {
723 for (i = 0; i < DSP_MAXPIPES; i++) {
724 if (s == chip->substream[i]) {
725 channelmask |= 1 << i;
726 snd_pcm_trigger_done(s, substream);
731 spin_lock(&chip->lock);
733 case SNDRV_PCM_TRIGGER_RESUME:
734 case SNDRV_PCM_TRIGGER_START:
735 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
736 for (i = 0; i < DSP_MAXPIPES; i++) {
737 if (channelmask & (1 << i)) {
738 pipe = chip->substream[i]->runtime->private_data;
739 switch (pipe->state) {
740 case PIPE_STATE_STOPPED:
741 chip->last_period[i] = 0;
742 pipe->last_counter = 0;
744 *pipe->dma_counter = 0;
746 case PIPE_STATE_PAUSED:
747 pipe->state = PIPE_STATE_STARTED;
749 case PIPE_STATE_STARTED:
754 err = start_transport(chip, channelmask,
755 chip->pipe_cyclic_mask);
757 case SNDRV_PCM_TRIGGER_SUSPEND:
758 case SNDRV_PCM_TRIGGER_STOP:
759 for (i = 0; i < DSP_MAXPIPES; i++) {
760 if (channelmask & (1 << i)) {
761 pipe = chip->substream[i]->runtime->private_data;
762 pipe->state = PIPE_STATE_STOPPED;
765 err = stop_transport(chip, channelmask);
767 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
768 for (i = 0; i < DSP_MAXPIPES; i++) {
769 if (channelmask & (1 << i)) {
770 pipe = chip->substream[i]->runtime->private_data;
771 pipe->state = PIPE_STATE_PAUSED;
774 err = pause_transport(chip, channelmask);
779 spin_unlock(&chip->lock);
785 static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
787 struct snd_pcm_runtime *runtime = substream->runtime;
788 struct audiopipe *pipe = runtime->private_data;
789 size_t cnt, bufsize, pos;
791 cnt = le32_to_cpu(*pipe->dma_counter);
792 pipe->position += cnt - pipe->last_counter;
793 pipe->last_counter = cnt;
794 bufsize = substream->runtime->buffer_size;
795 pos = bytes_to_frames(substream->runtime, pipe->position);
797 while (pos >= bufsize) {
798 pipe->position -= frames_to_bytes(substream->runtime, bufsize);
806 /* pcm *_ops structures */
807 static const struct snd_pcm_ops analog_playback_ops = {
808 .open = pcm_analog_out_open,
810 .hw_params = pcm_analog_out_hw_params,
811 .hw_free = pcm_hw_free,
812 .prepare = pcm_prepare,
813 .trigger = pcm_trigger,
814 .pointer = pcm_pointer,
816 static const struct snd_pcm_ops analog_capture_ops = {
817 .open = pcm_analog_in_open,
819 .hw_params = pcm_analog_in_hw_params,
820 .hw_free = pcm_hw_free,
821 .prepare = pcm_prepare,
822 .trigger = pcm_trigger,
823 .pointer = pcm_pointer,
825 #ifdef ECHOCARD_HAS_DIGITAL_IO
826 #ifndef ECHOCARD_HAS_VMIXER
827 static const struct snd_pcm_ops digital_playback_ops = {
828 .open = pcm_digital_out_open,
830 .hw_params = pcm_digital_out_hw_params,
831 .hw_free = pcm_hw_free,
832 .prepare = pcm_prepare,
833 .trigger = pcm_trigger,
834 .pointer = pcm_pointer,
836 #endif /* !ECHOCARD_HAS_VMIXER */
837 static const struct snd_pcm_ops digital_capture_ops = {
838 .open = pcm_digital_in_open,
840 .hw_params = pcm_digital_in_hw_params,
841 .hw_free = pcm_hw_free,
842 .prepare = pcm_prepare,
843 .trigger = pcm_trigger,
844 .pointer = pcm_pointer,
846 #endif /* ECHOCARD_HAS_DIGITAL_IO */
850 /* Preallocate memory only for the first substream because it's the most
853 static void snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev)
855 struct snd_pcm_substream *ss;
858 for (stream = 0; stream < 2; stream++)
859 for (ss = pcm->streams[stream].substream; ss; ss = ss->next)
860 snd_pcm_set_managed_buffer(ss, SNDRV_DMA_TYPE_DEV_SG,
862 ss->number ? 0 : 128<<10,
868 /*<--snd_echo_probe() */
869 static int snd_echo_new_pcm(struct echoaudio *chip)
874 #ifdef ECHOCARD_HAS_VMIXER
875 /* This card has a Vmixer, that is there is no direct mapping from PCM
876 streams to physical outputs. The user can mix the streams as he wishes
877 via control interface and it's possible to send any stream to any
878 output, thus it makes no sense to keep analog and digital outputs
881 /* PCM#0 Virtual outputs and analog inputs */
882 if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip),
883 num_analog_busses_in(chip), &pcm)) < 0)
885 pcm->private_data = chip;
886 chip->analog_pcm = pcm;
887 strcpy(pcm->name, chip->card->shortname);
888 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
889 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
890 snd_echo_preallocate_pages(pcm, &chip->pci->dev);
892 #ifdef ECHOCARD_HAS_DIGITAL_IO
893 /* PCM#1 Digital inputs, no outputs */
894 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0,
895 num_digital_busses_in(chip), &pcm)) < 0)
897 pcm->private_data = chip;
898 chip->digital_pcm = pcm;
899 strcpy(pcm->name, chip->card->shortname);
900 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
901 snd_echo_preallocate_pages(pcm, &chip->pci->dev);
902 #endif /* ECHOCARD_HAS_DIGITAL_IO */
904 #else /* ECHOCARD_HAS_VMIXER */
906 /* The card can manage substreams formed by analog and digital channels
907 at the same time, but I prefer to keep analog and digital channels
908 separated, because that mixed thing is confusing and useless. So we
909 register two PCM devices: */
911 /* PCM#0 Analog i/o */
912 if ((err = snd_pcm_new(chip->card, "Analog PCM", 0,
913 num_analog_busses_out(chip),
914 num_analog_busses_in(chip), &pcm)) < 0)
916 pcm->private_data = chip;
917 chip->analog_pcm = pcm;
918 strcpy(pcm->name, chip->card->shortname);
919 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
920 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
921 snd_echo_preallocate_pages(pcm, &chip->pci->dev);
923 #ifdef ECHOCARD_HAS_DIGITAL_IO
924 /* PCM#1 Digital i/o */
925 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1,
926 num_digital_busses_out(chip),
927 num_digital_busses_in(chip), &pcm)) < 0)
929 pcm->private_data = chip;
930 chip->digital_pcm = pcm;
931 strcpy(pcm->name, chip->card->shortname);
932 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops);
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 #endif /* ECHOCARD_HAS_VMIXER */
945 /******************************************************************************
947 ******************************************************************************/
949 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
951 /******************* PCM output volume *******************/
952 static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
953 struct snd_ctl_elem_info *uinfo)
955 struct echoaudio *chip;
957 chip = snd_kcontrol_chip(kcontrol);
958 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
959 uinfo->count = num_busses_out(chip);
960 uinfo->value.integer.min = ECHOGAIN_MINOUT;
961 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
965 static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
966 struct snd_ctl_elem_value *ucontrol)
968 struct echoaudio *chip;
971 chip = snd_kcontrol_chip(kcontrol);
972 for (c = 0; c < num_busses_out(chip); c++)
973 ucontrol->value.integer.value[c] = chip->output_gain[c];
977 static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
978 struct snd_ctl_elem_value *ucontrol)
980 struct echoaudio *chip;
981 int c, changed, gain;
984 chip = snd_kcontrol_chip(kcontrol);
985 spin_lock_irq(&chip->lock);
986 for (c = 0; c < num_busses_out(chip); c++) {
987 gain = ucontrol->value.integer.value[c];
988 /* Ignore out of range values */
989 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
991 if (chip->output_gain[c] != gain) {
992 set_output_gain(chip, c, gain);
997 update_output_line_level(chip);
998 spin_unlock_irq(&chip->lock);
1002 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1003 /* On the Mia this one controls the line-out volume */
1004 static const struct snd_kcontrol_new snd_echo_line_output_gain = {
1005 .name = "Line Playback Volume",
1006 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1007 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1008 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1009 .info = snd_echo_output_gain_info,
1010 .get = snd_echo_output_gain_get,
1011 .put = snd_echo_output_gain_put,
1012 .tlv = {.p = db_scale_output_gain},
1015 static const struct snd_kcontrol_new snd_echo_pcm_output_gain = {
1016 .name = "PCM Playback Volume",
1017 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1018 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1019 .info = snd_echo_output_gain_info,
1020 .get = snd_echo_output_gain_get,
1021 .put = snd_echo_output_gain_put,
1022 .tlv = {.p = db_scale_output_gain},
1026 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1030 #ifdef ECHOCARD_HAS_INPUT_GAIN
1032 /******************* Analog input volume *******************/
1033 static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
1034 struct snd_ctl_elem_info *uinfo)
1036 struct echoaudio *chip;
1038 chip = snd_kcontrol_chip(kcontrol);
1039 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1040 uinfo->count = num_analog_busses_in(chip);
1041 uinfo->value.integer.min = ECHOGAIN_MININP;
1042 uinfo->value.integer.max = ECHOGAIN_MAXINP;
1046 static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
1047 struct snd_ctl_elem_value *ucontrol)
1049 struct echoaudio *chip;
1052 chip = snd_kcontrol_chip(kcontrol);
1053 for (c = 0; c < num_analog_busses_in(chip); c++)
1054 ucontrol->value.integer.value[c] = chip->input_gain[c];
1058 static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
1059 struct snd_ctl_elem_value *ucontrol)
1061 struct echoaudio *chip;
1062 int c, gain, changed;
1065 chip = snd_kcontrol_chip(kcontrol);
1066 spin_lock_irq(&chip->lock);
1067 for (c = 0; c < num_analog_busses_in(chip); c++) {
1068 gain = ucontrol->value.integer.value[c];
1069 /* Ignore out of range values */
1070 if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
1072 if (chip->input_gain[c] != gain) {
1073 set_input_gain(chip, c, gain);
1078 update_input_line_level(chip);
1079 spin_unlock_irq(&chip->lock);
1083 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain, -2500, 50, 0);
1085 static const struct snd_kcontrol_new snd_echo_line_input_gain = {
1086 .name = "Line Capture Volume",
1087 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1088 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1089 .info = snd_echo_input_gain_info,
1090 .get = snd_echo_input_gain_get,
1091 .put = snd_echo_input_gain_put,
1092 .tlv = {.p = db_scale_input_gain},
1095 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1099 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1101 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1102 static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
1103 struct snd_ctl_elem_info *uinfo)
1105 struct echoaudio *chip;
1107 chip = snd_kcontrol_chip(kcontrol);
1108 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1109 uinfo->count = num_analog_busses_out(chip);
1110 uinfo->value.integer.min = 0;
1111 uinfo->value.integer.max = 1;
1115 static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
1116 struct snd_ctl_elem_value *ucontrol)
1118 struct echoaudio *chip;
1121 chip = snd_kcontrol_chip(kcontrol);
1122 for (c = 0; c < num_analog_busses_out(chip); c++)
1123 ucontrol->value.integer.value[c] = chip->nominal_level[c];
1127 static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
1128 struct snd_ctl_elem_value *ucontrol)
1130 struct echoaudio *chip;
1134 chip = snd_kcontrol_chip(kcontrol);
1135 spin_lock_irq(&chip->lock);
1136 for (c = 0; c < num_analog_busses_out(chip); c++) {
1137 if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
1138 set_nominal_level(chip, c,
1139 ucontrol->value.integer.value[c]);
1144 update_output_line_level(chip);
1145 spin_unlock_irq(&chip->lock);
1149 static const struct snd_kcontrol_new snd_echo_output_nominal_level = {
1150 .name = "Line Playback Switch (-10dBV)",
1151 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1152 .info = snd_echo_output_nominal_info,
1153 .get = snd_echo_output_nominal_get,
1154 .put = snd_echo_output_nominal_put,
1157 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1161 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1163 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1164 static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
1165 struct snd_ctl_elem_info *uinfo)
1167 struct echoaudio *chip;
1169 chip = snd_kcontrol_chip(kcontrol);
1170 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1171 uinfo->count = num_analog_busses_in(chip);
1172 uinfo->value.integer.min = 0;
1173 uinfo->value.integer.max = 1;
1177 static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
1178 struct snd_ctl_elem_value *ucontrol)
1180 struct echoaudio *chip;
1183 chip = snd_kcontrol_chip(kcontrol);
1184 for (c = 0; c < num_analog_busses_in(chip); c++)
1185 ucontrol->value.integer.value[c] =
1186 chip->nominal_level[bx_analog_in(chip) + c];
1190 static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
1191 struct snd_ctl_elem_value *ucontrol)
1193 struct echoaudio *chip;
1197 chip = snd_kcontrol_chip(kcontrol);
1198 spin_lock_irq(&chip->lock);
1199 for (c = 0; c < num_analog_busses_in(chip); c++) {
1200 if (chip->nominal_level[bx_analog_in(chip) + c] !=
1201 ucontrol->value.integer.value[c]) {
1202 set_nominal_level(chip, bx_analog_in(chip) + c,
1203 ucontrol->value.integer.value[c]);
1208 update_output_line_level(chip); /* "Output" is not a mistake
1211 spin_unlock_irq(&chip->lock);
1215 static const struct snd_kcontrol_new snd_echo_intput_nominal_level = {
1216 .name = "Line Capture Switch (-10dBV)",
1217 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1218 .info = snd_echo_input_nominal_info,
1219 .get = snd_echo_input_nominal_get,
1220 .put = snd_echo_input_nominal_put,
1223 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1227 #ifdef ECHOCARD_HAS_MONITOR
1229 /******************* Monitor mixer *******************/
1230 static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1231 struct snd_ctl_elem_info *uinfo)
1233 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1235 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1236 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1240 static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1241 struct snd_ctl_elem_value *ucontrol)
1243 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1244 unsigned int out = ucontrol->id.index / num_busses_in(chip);
1245 unsigned int in = ucontrol->id.index % num_busses_in(chip);
1247 if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS)
1250 ucontrol->value.integer.value[0] = chip->monitor_gain[out][in];
1254 static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1255 struct snd_ctl_elem_value *ucontrol)
1257 struct echoaudio *chip;
1259 unsigned int out, in;
1262 chip = snd_kcontrol_chip(kcontrol);
1263 out = ucontrol->id.index / num_busses_in(chip);
1264 in = ucontrol->id.index % num_busses_in(chip);
1265 if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS)
1267 gain = ucontrol->value.integer.value[0];
1268 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1270 if (chip->monitor_gain[out][in] != gain) {
1271 spin_lock_irq(&chip->lock);
1272 set_monitor_gain(chip, out, in, gain);
1273 update_output_line_level(chip);
1274 spin_unlock_irq(&chip->lock);
1280 static struct snd_kcontrol_new snd_echo_monitor_mixer = {
1281 .name = "Monitor Mixer Volume",
1282 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1283 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1284 .info = snd_echo_mixer_info,
1285 .get = snd_echo_mixer_get,
1286 .put = snd_echo_mixer_put,
1287 .tlv = {.p = db_scale_output_gain},
1290 #endif /* ECHOCARD_HAS_MONITOR */
1294 #ifdef ECHOCARD_HAS_VMIXER
1296 /******************* Vmixer *******************/
1297 static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
1298 struct snd_ctl_elem_info *uinfo)
1300 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1302 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1303 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1307 static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
1308 struct snd_ctl_elem_value *ucontrol)
1310 struct echoaudio *chip;
1312 chip = snd_kcontrol_chip(kcontrol);
1313 ucontrol->value.integer.value[0] =
1314 chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
1315 [ucontrol->id.index % num_pipes_out(chip)];
1319 static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
1320 struct snd_ctl_elem_value *ucontrol)
1322 struct echoaudio *chip;
1327 chip = snd_kcontrol_chip(kcontrol);
1328 out = ucontrol->id.index / num_pipes_out(chip);
1329 vch = ucontrol->id.index % num_pipes_out(chip);
1330 gain = ucontrol->value.integer.value[0];
1331 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1333 if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
1334 spin_lock_irq(&chip->lock);
1335 set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
1336 update_vmixer_level(chip);
1337 spin_unlock_irq(&chip->lock);
1343 static struct snd_kcontrol_new snd_echo_vmixer = {
1344 .name = "VMixer Volume",
1345 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1346 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1347 .info = snd_echo_vmixer_info,
1348 .get = snd_echo_vmixer_get,
1349 .put = snd_echo_vmixer_put,
1350 .tlv = {.p = db_scale_output_gain},
1353 #endif /* ECHOCARD_HAS_VMIXER */
1357 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1359 /******************* Digital mode switch *******************/
1360 static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1361 struct snd_ctl_elem_info *uinfo)
1363 static const char * const names[4] = {
1364 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1367 struct echoaudio *chip;
1369 chip = snd_kcontrol_chip(kcontrol);
1370 return snd_ctl_enum_info(uinfo, 1, chip->num_digital_modes, names);
1373 static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
1374 struct snd_ctl_elem_value *ucontrol)
1376 struct echoaudio *chip;
1379 chip = snd_kcontrol_chip(kcontrol);
1380 mode = chip->digital_mode;
1381 for (i = chip->num_digital_modes - 1; i >= 0; i--)
1382 if (mode == chip->digital_mode_list[i]) {
1383 ucontrol->value.enumerated.item[0] = i;
1389 static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1390 struct snd_ctl_elem_value *ucontrol)
1392 struct echoaudio *chip;
1394 unsigned short emode, dmode;
1397 chip = snd_kcontrol_chip(kcontrol);
1399 emode = ucontrol->value.enumerated.item[0];
1400 if (emode >= chip->num_digital_modes)
1402 dmode = chip->digital_mode_list[emode];
1404 if (dmode != chip->digital_mode) {
1405 /* mode_mutex is required to make this operation atomic wrt
1406 pcm_digital_*_open() and set_input_clock() functions. */
1407 mutex_lock(&chip->mode_mutex);
1409 /* Do not allow the user to change the digital mode when a pcm
1410 device is open because it also changes the number of channels
1411 and the allowed sample rates */
1412 if (atomic_read(&chip->opencount)) {
1415 changed = set_digital_mode(chip, dmode);
1416 /* If we had to change the clock source, report it */
1417 if (changed > 0 && chip->clock_src_ctl) {
1418 snd_ctl_notify(chip->card,
1419 SNDRV_CTL_EVENT_MASK_VALUE,
1420 &chip->clock_src_ctl->id);
1421 dev_dbg(chip->card->dev,
1422 "SDM() =%d\n", changed);
1425 changed = 1; /* No errors */
1427 mutex_unlock(&chip->mode_mutex);
1432 static const struct snd_kcontrol_new snd_echo_digital_mode_switch = {
1433 .name = "Digital mode Switch",
1434 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1435 .info = snd_echo_digital_mode_info,
1436 .get = snd_echo_digital_mode_get,
1437 .put = snd_echo_digital_mode_put,
1440 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1444 #ifdef ECHOCARD_HAS_DIGITAL_IO
1446 /******************* S/PDIF mode switch *******************/
1447 static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1448 struct snd_ctl_elem_info *uinfo)
1450 static const char * const names[2] = {"Consumer", "Professional"};
1452 return snd_ctl_enum_info(uinfo, 1, 2, names);
1455 static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
1456 struct snd_ctl_elem_value *ucontrol)
1458 struct echoaudio *chip;
1460 chip = snd_kcontrol_chip(kcontrol);
1461 ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
1465 static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
1466 struct snd_ctl_elem_value *ucontrol)
1468 struct echoaudio *chip;
1471 chip = snd_kcontrol_chip(kcontrol);
1472 mode = !!ucontrol->value.enumerated.item[0];
1473 if (mode != chip->professional_spdif) {
1474 spin_lock_irq(&chip->lock);
1475 set_professional_spdif(chip, mode);
1476 spin_unlock_irq(&chip->lock);
1482 static const struct snd_kcontrol_new snd_echo_spdif_mode_switch = {
1483 .name = "S/PDIF mode Switch",
1484 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1485 .info = snd_echo_spdif_mode_info,
1486 .get = snd_echo_spdif_mode_get,
1487 .put = snd_echo_spdif_mode_put,
1490 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1494 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1496 /******************* Select input clock source *******************/
1497 static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1498 struct snd_ctl_elem_info *uinfo)
1500 static const char * const names[8] = {
1501 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1504 struct echoaudio *chip;
1506 chip = snd_kcontrol_chip(kcontrol);
1507 return snd_ctl_enum_info(uinfo, 1, chip->num_clock_sources, names);
1510 static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
1511 struct snd_ctl_elem_value *ucontrol)
1513 struct echoaudio *chip;
1516 chip = snd_kcontrol_chip(kcontrol);
1517 clock = chip->input_clock;
1519 for (i = 0; i < chip->num_clock_sources; i++)
1520 if (clock == chip->clock_source_list[i])
1521 ucontrol->value.enumerated.item[0] = i;
1526 static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1527 struct snd_ctl_elem_value *ucontrol)
1529 struct echoaudio *chip;
1531 unsigned int eclock, dclock;
1534 chip = snd_kcontrol_chip(kcontrol);
1535 eclock = ucontrol->value.enumerated.item[0];
1536 if (eclock >= chip->input_clock_types)
1538 dclock = chip->clock_source_list[eclock];
1539 if (chip->input_clock != dclock) {
1540 mutex_lock(&chip->mode_mutex);
1541 spin_lock_irq(&chip->lock);
1542 if ((changed = set_input_clock(chip, dclock)) == 0)
1543 changed = 1; /* no errors */
1544 spin_unlock_irq(&chip->lock);
1545 mutex_unlock(&chip->mode_mutex);
1549 dev_dbg(chip->card->dev,
1550 "seticlk val%d err 0x%x\n", dclock, changed);
1555 static const struct snd_kcontrol_new snd_echo_clock_source_switch = {
1556 .name = "Sample Clock Source",
1557 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1558 .info = snd_echo_clock_source_info,
1559 .get = snd_echo_clock_source_get,
1560 .put = snd_echo_clock_source_put,
1563 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1567 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1569 /******************* Phantom power switch *******************/
1570 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1572 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1573 struct snd_ctl_elem_value *ucontrol)
1575 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1577 ucontrol->value.integer.value[0] = chip->phantom_power;
1581 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1582 struct snd_ctl_elem_value *ucontrol)
1584 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1585 int power, changed = 0;
1587 power = !!ucontrol->value.integer.value[0];
1588 if (chip->phantom_power != power) {
1589 spin_lock_irq(&chip->lock);
1590 changed = set_phantom_power(chip, power);
1591 spin_unlock_irq(&chip->lock);
1593 changed = 1; /* no errors */
1598 static const struct snd_kcontrol_new snd_echo_phantom_power_switch = {
1599 .name = "Phantom power Switch",
1600 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1601 .info = snd_echo_phantom_power_info,
1602 .get = snd_echo_phantom_power_get,
1603 .put = snd_echo_phantom_power_put,
1606 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1610 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1612 /******************* Digital input automute switch *******************/
1613 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1615 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1616 struct snd_ctl_elem_value *ucontrol)
1618 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1620 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1624 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1625 struct snd_ctl_elem_value *ucontrol)
1627 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1628 int automute, changed = 0;
1630 automute = !!ucontrol->value.integer.value[0];
1631 if (chip->digital_in_automute != automute) {
1632 spin_lock_irq(&chip->lock);
1633 changed = set_input_auto_mute(chip, automute);
1634 spin_unlock_irq(&chip->lock);
1636 changed = 1; /* no errors */
1641 static const struct snd_kcontrol_new snd_echo_automute_switch = {
1642 .name = "Digital Capture Switch (automute)",
1643 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1644 .info = snd_echo_automute_info,
1645 .get = snd_echo_automute_get,
1646 .put = snd_echo_automute_put,
1649 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1653 /******************* VU-meters switch *******************/
1654 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1656 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1657 struct snd_ctl_elem_value *ucontrol)
1659 struct echoaudio *chip;
1661 chip = snd_kcontrol_chip(kcontrol);
1662 spin_lock_irq(&chip->lock);
1663 set_meters_on(chip, ucontrol->value.integer.value[0]);
1664 spin_unlock_irq(&chip->lock);
1668 static const struct snd_kcontrol_new snd_echo_vumeters_switch = {
1669 .name = "VU-meters Switch",
1670 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1671 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1672 .info = snd_echo_vumeters_switch_info,
1673 .put = snd_echo_vumeters_switch_put,
1678 /***** Read VU-meters (input, output, analog and digital together) *****/
1679 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1680 struct snd_ctl_elem_info *uinfo)
1682 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1684 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1685 uinfo->value.integer.max = 0;
1689 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1690 struct snd_ctl_elem_value *ucontrol)
1692 struct echoaudio *chip;
1694 chip = snd_kcontrol_chip(kcontrol);
1695 get_audio_meters(chip, ucontrol->value.integer.value);
1699 static const struct snd_kcontrol_new snd_echo_vumeters = {
1700 .name = "VU-meters",
1701 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1702 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1703 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
1704 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1705 .info = snd_echo_vumeters_info,
1706 .get = snd_echo_vumeters_get,
1707 .tlv = {.p = db_scale_output_gain},
1712 /*** Channels info - it exports informations about the number of channels ***/
1713 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1714 struct snd_ctl_elem_info *uinfo)
1716 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1718 uinfo->value.integer.min = 0;
1719 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1723 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1724 struct snd_ctl_elem_value *ucontrol)
1726 struct echoaudio *chip;
1727 int detected, clocks, bit, src;
1729 chip = snd_kcontrol_chip(kcontrol);
1730 ucontrol->value.integer.value[0] = num_busses_in(chip);
1731 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1732 ucontrol->value.integer.value[2] = num_busses_out(chip);
1733 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1734 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1736 /* Compute the bitmask of the currently valid input clocks */
1737 detected = detect_input_clocks(chip);
1739 src = chip->num_clock_sources - 1;
1740 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1741 if (detected & (1 << bit))
1742 for (; src >= 0; src--)
1743 if (bit == chip->clock_source_list[src]) {
1747 ucontrol->value.integer.value[5] = clocks;
1752 static const struct snd_kcontrol_new snd_echo_channels_info = {
1753 .name = "Channels info",
1754 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1755 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1756 .info = snd_echo_channels_info_info,
1757 .get = snd_echo_channels_info_get,
1763 /******************************************************************************
1765 ******************************************************************************/
1767 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1769 struct echoaudio *chip = dev_id;
1770 struct snd_pcm_substream *substream;
1773 spin_lock(&chip->lock);
1774 st = service_irq(chip);
1776 spin_unlock(&chip->lock);
1779 /* The hardware doesn't tell us which substream caused the irq,
1780 thus we have to check all running substreams. */
1781 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1782 substream = chip->substream[ss];
1783 if (substream && ((struct audiopipe *)substream->runtime->
1784 private_data)->state == PIPE_STATE_STARTED) {
1785 period = pcm_pointer(substream) /
1786 substream->runtime->period_size;
1787 if (period != chip->last_period[ss]) {
1788 chip->last_period[ss] = period;
1789 spin_unlock(&chip->lock);
1790 snd_pcm_period_elapsed(substream);
1791 spin_lock(&chip->lock);
1795 spin_unlock(&chip->lock);
1797 #ifdef ECHOCARD_HAS_MIDI
1798 if (st > 0 && chip->midi_in) {
1799 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1800 dev_dbg(chip->card->dev, "rawmidi_iread=%d\n", st);
1809 /******************************************************************************
1810 Module construction / destruction
1811 ******************************************************************************/
1813 static int snd_echo_free(struct echoaudio *chip)
1815 if (chip->comm_page)
1816 rest_in_peace(chip);
1819 free_irq(chip->irq, chip);
1821 if (chip->comm_page)
1822 snd_dma_free_pages(&chip->commpage_dma_buf);
1824 iounmap(chip->dsp_registers);
1825 release_and_free_resource(chip->iores);
1826 pci_disable_device(chip->pci);
1828 /* release chip data */
1829 free_firmware_cache(chip);
1836 static int snd_echo_dev_free(struct snd_device *device)
1838 struct echoaudio *chip = device->device_data;
1840 return snd_echo_free(chip);
1845 /* <--snd_echo_probe() */
1846 static int snd_echo_create(struct snd_card *card,
1847 struct pci_dev *pci,
1848 struct echoaudio **rchip)
1850 struct echoaudio *chip;
1853 static const struct snd_device_ops ops = {
1854 .dev_free = snd_echo_dev_free,
1859 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1861 if ((err = pci_enable_device(pci)) < 0)
1863 pci_set_master(pci);
1865 /* Allocate chip if needed */
1867 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1869 pci_disable_device(pci);
1872 dev_dbg(card->dev, "chip=%p\n", chip);
1873 spin_lock_init(&chip->lock);
1877 atomic_set(&chip->opencount, 0);
1878 mutex_init(&chip->mode_mutex);
1879 chip->can_set_rate = 1;
1881 /* If this was called from the resume function, chip is
1882 * already allocated and it contains current card settings.
1887 /* PCI resource allocation */
1888 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1889 sz = pci_resource_len(pci, 0);
1891 sz = PAGE_SIZE; /* We map only the required part */
1893 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1894 ECHOCARD_NAME)) == NULL) {
1895 dev_err(chip->card->dev, "cannot get memory region\n");
1896 snd_echo_free(chip);
1899 chip->dsp_registers = (volatile u32 __iomem *)
1900 ioremap(chip->dsp_registers_phys, sz);
1901 if (!chip->dsp_registers) {
1902 dev_err(chip->card->dev, "ioremap failed\n");
1903 snd_echo_free(chip);
1907 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1908 KBUILD_MODNAME, chip)) {
1909 dev_err(chip->card->dev, "cannot grab irq\n");
1910 snd_echo_free(chip);
1913 chip->irq = pci->irq;
1914 card->sync_irq = chip->irq;
1915 dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n",
1916 chip->pci, chip->irq, chip->pci->subsystem_device);
1918 /* Create the DSP comm page - this is the area of memory used for most
1919 of the communication with the DSP, which accesses it via bus mastering */
1920 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
1921 sizeof(struct comm_page),
1922 &chip->commpage_dma_buf) < 0) {
1923 dev_err(chip->card->dev, "cannot allocate the comm page\n");
1924 snd_echo_free(chip);
1927 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1928 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1930 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1932 err = set_mixer_defaults(chip);
1934 dev_err(card->dev, "init_hw err=%d\n", err);
1935 snd_echo_free(chip);
1939 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1940 snd_echo_free(chip);
1951 static int snd_echo_probe(struct pci_dev *pci,
1952 const struct pci_device_id *pci_id)
1955 struct snd_card *card;
1956 struct echoaudio *chip;
1960 if (dev >= SNDRV_CARDS)
1968 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1973 chip = NULL; /* Tells snd_echo_create to allocate chip */
1974 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
1975 snd_card_free(card);
1979 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
1980 strcpy(card->shortname, chip->card_name);
1983 if (pci_id->device == 0x3410)
1986 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
1987 card->shortname, pci_id->subdevice & 0x000f, dsp,
1988 chip->dsp_registers_phys, chip->irq);
1990 if ((err = snd_echo_new_pcm(chip)) < 0) {
1991 dev_err(chip->card->dev, "new pcm error %d\n", err);
1992 snd_card_free(card);
1996 #ifdef ECHOCARD_HAS_MIDI
1997 if (chip->has_midi) { /* Some Mia's do not have midi */
1998 if ((err = snd_echo_midi_create(card, chip)) < 0) {
1999 dev_err(chip->card->dev, "new midi error %d\n", err);
2000 snd_card_free(card);
2006 #ifdef ECHOCARD_HAS_VMIXER
2007 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2008 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2010 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2011 err = snd_ctl_add(chip->card,
2012 snd_ctl_new1(&snd_echo_line_output_gain, chip));
2016 #else /* ECHOCARD_HAS_VMIXER */
2017 err = snd_ctl_add(chip->card,
2018 snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
2021 #endif /* ECHOCARD_HAS_VMIXER */
2023 #ifdef ECHOCARD_HAS_INPUT_GAIN
2024 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2028 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2029 if (!chip->hasnt_input_nominal_level)
2030 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2034 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2035 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2039 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2042 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2045 #ifdef ECHOCARD_HAS_MONITOR
2046 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2047 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2051 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2052 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2056 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2059 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2060 /* Creates a list of available digital modes */
2061 chip->num_digital_modes = 0;
2062 for (i = 0; i < 6; i++)
2063 if (chip->digital_modes & (1 << i))
2064 chip->digital_mode_list[chip->num_digital_modes++] = i;
2066 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2068 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2070 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2071 /* Creates a list of available clock sources */
2072 chip->num_clock_sources = 0;
2073 for (i = 0; i < 10; i++)
2074 if (chip->input_clock_types & (1 << i))
2075 chip->clock_source_list[chip->num_clock_sources++] = i;
2077 if (chip->num_clock_sources > 1) {
2078 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2079 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2082 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2084 #ifdef ECHOCARD_HAS_DIGITAL_IO
2085 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2089 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2090 if (chip->has_phantom_power)
2091 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2095 err = snd_card_register(card);
2098 dev_info(card->dev, "Card registered: %s\n", card->longname);
2100 pci_set_drvdata(pci, chip);
2105 dev_err(card->dev, "new control error %d\n", err);
2106 snd_card_free(card);
2112 #if defined(CONFIG_PM_SLEEP)
2114 static int snd_echo_suspend(struct device *dev)
2116 struct echoaudio *chip = dev_get_drvdata(dev);
2118 #ifdef ECHOCARD_HAS_MIDI
2119 /* This call can sleep */
2121 snd_echo_midi_output_trigger(chip->midi_out, 0);
2123 spin_lock_irq(&chip->lock);
2124 if (wait_handshake(chip)) {
2125 spin_unlock_irq(&chip->lock);
2128 clear_handshake(chip);
2129 if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) {
2130 spin_unlock_irq(&chip->lock);
2133 spin_unlock_irq(&chip->lock);
2135 chip->dsp_code = NULL;
2136 free_irq(chip->irq, chip);
2138 chip->card->sync_irq = -1;
2144 static int snd_echo_resume(struct device *dev)
2146 struct pci_dev *pci = to_pci_dev(dev);
2147 struct echoaudio *chip = dev_get_drvdata(dev);
2148 struct comm_page *commpage, *commpage_bak;
2149 u32 pipe_alloc_mask;
2152 commpage = chip->comm_page;
2153 commpage_bak = kmemdup(commpage, sizeof(*commpage), GFP_KERNEL);
2154 if (commpage_bak == NULL)
2157 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
2159 kfree(commpage_bak);
2160 dev_err(dev, "resume init_hw err=%d\n", err);
2161 snd_echo_free(chip);
2165 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2166 * restore_dsp_settings() fails.
2168 pipe_alloc_mask = chip->pipe_alloc_mask;
2169 chip->pipe_alloc_mask = 0;
2170 err = restore_dsp_rettings(chip);
2171 chip->pipe_alloc_mask = pipe_alloc_mask;
2173 kfree(commpage_bak);
2177 memcpy(&commpage->audio_format, &commpage_bak->audio_format,
2178 sizeof(commpage->audio_format));
2179 memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr,
2180 sizeof(commpage->sglist_addr));
2181 memcpy(&commpage->midi_output, &commpage_bak->midi_output,
2182 sizeof(commpage->midi_output));
2183 kfree(commpage_bak);
2185 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
2186 KBUILD_MODNAME, chip)) {
2187 dev_err(chip->card->dev, "cannot grab irq\n");
2188 snd_echo_free(chip);
2191 chip->irq = pci->irq;
2192 chip->card->sync_irq = chip->irq;
2193 dev_dbg(dev, "resume irq=%d\n", chip->irq);
2195 #ifdef ECHOCARD_HAS_MIDI
2196 if (chip->midi_input_enabled)
2197 enable_midi_input(chip, true);
2199 snd_echo_midi_output_trigger(chip->midi_out, 1);
2205 static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume);
2206 #define SND_ECHO_PM_OPS &snd_echo_pm
2208 #define SND_ECHO_PM_OPS NULL
2209 #endif /* CONFIG_PM_SLEEP */
2212 static void snd_echo_remove(struct pci_dev *pci)
2214 struct echoaudio *chip;
2216 chip = pci_get_drvdata(pci);
2218 snd_card_free(chip->card);
2223 /******************************************************************************
2224 Everything starts and ends here
2225 ******************************************************************************/
2227 /* pci_driver definition */
2228 static struct pci_driver echo_driver = {
2229 .name = KBUILD_MODNAME,
2230 .id_table = snd_echo_ids,
2231 .probe = snd_echo_probe,
2232 .remove = snd_echo_remove,
2234 .pm = SND_ECHO_PM_OPS,
2238 module_pci_driver(echo_driver);