2 * ALSA driver for Echoaudio soundcards.
3 * Copyright (C) 2003-2004 Giuliano Pochini <pochini@shiny.it>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <linux/module.h>
21 MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>");
22 MODULE_LICENSE("GPL v2");
23 MODULE_DESCRIPTION("Echoaudio " ECHOCARD_NAME " soundcards driver");
24 MODULE_SUPPORTED_DEVICE("{{Echoaudio," ECHOCARD_NAME "}}");
25 MODULE_DEVICE_TABLE(pci, snd_echo_ids);
27 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
28 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
29 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
31 module_param_array(index, int, NULL, 0444);
32 MODULE_PARM_DESC(index, "Index value for " ECHOCARD_NAME " soundcard.");
33 module_param_array(id, charp, NULL, 0444);
34 MODULE_PARM_DESC(id, "ID string for " ECHOCARD_NAME " soundcard.");
35 module_param_array(enable, bool, NULL, 0444);
36 MODULE_PARM_DESC(enable, "Enable " ECHOCARD_NAME " soundcard.");
38 static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
39 static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1);
43 static int get_firmware(const struct firmware **fw_entry,
44 struct echoaudio *chip, const short fw_index)
49 #ifdef CONFIG_PM_SLEEP
50 if (chip->fw_cache[fw_index]) {
51 dev_dbg(chip->card->dev,
52 "firmware requested: %s is cached\n",
53 card_fw[fw_index].data);
54 *fw_entry = chip->fw_cache[fw_index];
59 dev_dbg(chip->card->dev,
60 "firmware requested: %s\n", card_fw[fw_index].data);
61 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data);
62 err = request_firmware(fw_entry, name, pci_device(chip));
64 dev_err(chip->card->dev,
65 "get_firmware(): Firmware not available (%d)\n", err);
66 #ifdef CONFIG_PM_SLEEP
68 chip->fw_cache[fw_index] = *fw_entry;
75 static void free_firmware(const struct firmware *fw_entry,
76 struct echoaudio *chip)
78 #ifdef CONFIG_PM_SLEEP
79 dev_dbg(chip->card->dev, "firmware not released (kept in cache)\n");
81 release_firmware(fw_entry);
87 static void free_firmware_cache(struct echoaudio *chip)
89 #ifdef CONFIG_PM_SLEEP
92 for (i = 0; i < 8 ; i++)
93 if (chip->fw_cache[i]) {
94 release_firmware(chip->fw_cache[i]);
95 dev_dbg(chip->card->dev, "release_firmware(%d)\n", i);
103 /******************************************************************************
105 ******************************************************************************/
107 static void audiopipe_free(struct snd_pcm_runtime *runtime)
109 struct audiopipe *pipe = runtime->private_data;
111 if (pipe->sgpage.area)
112 snd_dma_free_pages(&pipe->sgpage);
118 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
119 struct snd_pcm_hw_rule *rule)
121 struct snd_interval *c = hw_param_interval(params,
122 SNDRV_PCM_HW_PARAM_CHANNELS);
123 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
128 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
129 /* >=2 channels cannot be S32_BE */
131 fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
132 return snd_mask_refine(f, &fmt);
135 /* > 2 channels cannot be U8 and S32_BE */
137 fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
138 return snd_mask_refine(f, &fmt);
140 /* Mono is ok with any format */
146 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
147 struct snd_pcm_hw_rule *rule)
149 struct snd_interval *c = hw_param_interval(params,
150 SNDRV_PCM_HW_PARAM_CHANNELS);
151 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
152 struct snd_interval ch;
154 snd_interval_any(&ch);
156 /* S32_BE is mono (and stereo) only */
157 if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
159 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
165 return snd_interval_refine(c, &ch);
167 /* U8 can be only mono or stereo */
168 if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
172 return snd_interval_refine(c, &ch);
174 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
180 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
181 struct snd_pcm_hw_rule *rule)
183 struct snd_interval *c = hw_param_interval(params,
184 SNDRV_PCM_HW_PARAM_CHANNELS);
185 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
190 fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
192 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
194 fmask &= SNDRV_PCM_FMTBIT_S16_LE |
195 SNDRV_PCM_FMTBIT_S24_3LE |
196 SNDRV_PCM_FMTBIT_S32_LE;
197 /* 1 channel must be S32_BE or S32_LE */
198 } else if (c->max == 1)
199 fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
200 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
201 /* 2 channels cannot be S32_BE */
202 else if (c->min == 2 && c->max == 2)
203 fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
208 fmt.bits[0] &= (u32)fmask;
209 fmt.bits[1] &= (u32)(fmask >> 32);
210 return snd_mask_refine(f, &fmt);
215 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
216 struct snd_pcm_hw_rule *rule)
218 struct snd_interval *c = hw_param_interval(params,
219 SNDRV_PCM_HW_PARAM_CHANNELS);
220 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
221 struct snd_interval ch;
224 snd_interval_any(&ch);
226 fmask = f->bits[0] + ((u64)f->bits[1] << 32);
228 /* S32_BE is mono (and stereo) only */
229 if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
231 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
236 /* U8 is stereo only */
237 } else if (fmask == SNDRV_PCM_FMTBIT_U8)
239 /* S16_LE and S24_3LE must be at least stereo */
240 else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
241 SNDRV_PCM_FMTBIT_S24_3LE)))
246 return snd_interval_refine(c, &ch);
251 /* Since the sample rate is a global setting, do allow the user to change the
252 sample rate only if there is only one pcm device open. */
253 static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
254 struct snd_pcm_hw_rule *rule)
256 struct snd_interval *rate = hw_param_interval(params,
257 SNDRV_PCM_HW_PARAM_RATE);
258 struct echoaudio *chip = rule->private;
259 struct snd_interval fixed;
261 if (!chip->can_set_rate) {
262 snd_interval_any(&fixed);
263 fixed.min = fixed.max = chip->sample_rate;
264 return snd_interval_refine(rate, &fixed);
270 static int pcm_open(struct snd_pcm_substream *substream,
271 signed char max_channels)
273 struct echoaudio *chip;
274 struct snd_pcm_runtime *runtime;
275 struct audiopipe *pipe;
278 if (max_channels <= 0)
281 chip = snd_pcm_substream_chip(substream);
282 runtime = substream->runtime;
284 pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
287 pipe->index = -1; /* Not configured yet */
289 /* Set up hw capabilities and contraints */
290 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
291 dev_dbg(chip->card->dev, "max_channels=%d\n", max_channels);
292 pipe->constr.list = channels_list;
293 pipe->constr.mask = 0;
294 for (i = 0; channels_list[i] <= max_channels; i++);
295 pipe->constr.count = i;
296 if (pipe->hw.channels_max > max_channels)
297 pipe->hw.channels_max = max_channels;
298 if (chip->digital_mode == DIGITAL_MODE_ADAT) {
299 pipe->hw.rate_max = 48000;
300 pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
303 runtime->hw = pipe->hw;
304 runtime->private_data = pipe;
305 runtime->private_free = audiopipe_free;
306 snd_pcm_set_sync(substream);
308 /* Only mono and any even number of channels are allowed */
309 if ((err = snd_pcm_hw_constraint_list(runtime, 0,
310 SNDRV_PCM_HW_PARAM_CHANNELS,
314 /* All periods should have the same size */
315 if ((err = snd_pcm_hw_constraint_integer(runtime,
316 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
319 /* The hw accesses memory in chunks 32 frames long and they should be
320 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
321 generated with a resolution of 32 frames. Thus we need the following */
322 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
323 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
326 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
327 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
331 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
332 SNDRV_PCM_HW_PARAM_RATE,
333 hw_rule_sample_rate, chip,
334 SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
337 /* Finally allocate a page for the scatter-gather list */
338 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
339 snd_dma_pci_data(chip->pci),
340 PAGE_SIZE, &pipe->sgpage)) < 0) {
341 dev_err(chip->card->dev, "s-g list allocation failed\n");
350 static int pcm_analog_in_open(struct snd_pcm_substream *substream)
352 struct echoaudio *chip = snd_pcm_substream_chip(substream);
355 if ((err = pcm_open(substream, num_analog_busses_in(chip) -
356 substream->number)) < 0)
358 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
359 SNDRV_PCM_HW_PARAM_CHANNELS,
360 hw_rule_capture_channels_by_format, NULL,
361 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
363 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
364 SNDRV_PCM_HW_PARAM_FORMAT,
365 hw_rule_capture_format_by_channels, NULL,
366 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
368 atomic_inc(&chip->opencount);
369 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
370 chip->can_set_rate=0;
371 dev_dbg(chip->card->dev, "pcm_analog_in_open cs=%d oc=%d r=%d\n",
372 chip->can_set_rate, atomic_read(&chip->opencount),
379 static int pcm_analog_out_open(struct snd_pcm_substream *substream)
381 struct echoaudio *chip = snd_pcm_substream_chip(substream);
382 int max_channels, err;
384 #ifdef ECHOCARD_HAS_VMIXER
385 max_channels = num_pipes_out(chip);
387 max_channels = num_analog_busses_out(chip);
389 if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
391 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
392 SNDRV_PCM_HW_PARAM_CHANNELS,
393 hw_rule_playback_channels_by_format,
395 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
397 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
398 SNDRV_PCM_HW_PARAM_FORMAT,
399 hw_rule_playback_format_by_channels,
401 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
403 atomic_inc(&chip->opencount);
404 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
405 chip->can_set_rate=0;
406 dev_dbg(chip->card->dev, "pcm_analog_out_open cs=%d oc=%d r=%d\n",
407 chip->can_set_rate, atomic_read(&chip->opencount),
414 #ifdef ECHOCARD_HAS_DIGITAL_IO
416 static int pcm_digital_in_open(struct snd_pcm_substream *substream)
418 struct echoaudio *chip = snd_pcm_substream_chip(substream);
419 int err, max_channels;
421 max_channels = num_digital_busses_in(chip) - substream->number;
422 mutex_lock(&chip->mode_mutex);
423 if (chip->digital_mode == DIGITAL_MODE_ADAT)
424 err = pcm_open(substream, max_channels);
425 else /* If the card has ADAT, subtract the 6 channels
426 * that S/PDIF doesn't have
428 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
433 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
434 SNDRV_PCM_HW_PARAM_CHANNELS,
435 hw_rule_capture_channels_by_format, NULL,
436 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
438 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
439 SNDRV_PCM_HW_PARAM_FORMAT,
440 hw_rule_capture_format_by_channels, NULL,
441 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
444 atomic_inc(&chip->opencount);
445 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
446 chip->can_set_rate=0;
449 mutex_unlock(&chip->mode_mutex);
455 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
457 static int pcm_digital_out_open(struct snd_pcm_substream *substream)
459 struct echoaudio *chip = snd_pcm_substream_chip(substream);
460 int err, max_channels;
462 max_channels = num_digital_busses_out(chip) - substream->number;
463 mutex_lock(&chip->mode_mutex);
464 if (chip->digital_mode == DIGITAL_MODE_ADAT)
465 err = pcm_open(substream, max_channels);
466 else /* If the card has ADAT, subtract the 6 channels
467 * that S/PDIF doesn't have
469 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
474 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
475 SNDRV_PCM_HW_PARAM_CHANNELS,
476 hw_rule_playback_channels_by_format,
477 NULL, SNDRV_PCM_HW_PARAM_FORMAT,
480 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
481 SNDRV_PCM_HW_PARAM_FORMAT,
482 hw_rule_playback_format_by_channels,
483 NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
486 atomic_inc(&chip->opencount);
487 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
488 chip->can_set_rate=0;
490 mutex_unlock(&chip->mode_mutex);
494 #endif /* !ECHOCARD_HAS_VMIXER */
496 #endif /* ECHOCARD_HAS_DIGITAL_IO */
500 static int pcm_close(struct snd_pcm_substream *substream)
502 struct echoaudio *chip = snd_pcm_substream_chip(substream);
505 /* Nothing to do here. Audio is already off and pipe will be
506 * freed by its callback
509 atomic_dec(&chip->opencount);
510 oc = atomic_read(&chip->opencount);
511 dev_dbg(chip->card->dev, "pcm_close oc=%d cs=%d rs=%d\n", oc,
512 chip->can_set_rate, chip->rate_set);
514 chip->can_set_rate = 1;
517 dev_dbg(chip->card->dev, "pcm_close2 oc=%d cs=%d rs=%d\n", oc,
518 chip->can_set_rate, chip->rate_set);
525 /* Channel allocation and scatter-gather list setup */
526 static int init_engine(struct snd_pcm_substream *substream,
527 struct snd_pcm_hw_params *hw_params,
528 int pipe_index, int interleave)
530 struct echoaudio *chip;
531 int err, per, rest, page, edge, offs;
532 struct audiopipe *pipe;
534 chip = snd_pcm_substream_chip(substream);
535 pipe = (struct audiopipe *) substream->runtime->private_data;
537 /* Sets up che hardware. If it's already initialized, reset and
538 * redo with the new parameters
540 spin_lock_irq(&chip->lock);
541 if (pipe->index >= 0) {
542 dev_dbg(chip->card->dev, "hwp_ie free(%d)\n", pipe->index);
543 err = free_pipes(chip, pipe);
545 chip->substream[pipe->index] = NULL;
548 err = allocate_pipes(chip, pipe, pipe_index, interleave);
550 spin_unlock_irq(&chip->lock);
551 dev_err(chip->card->dev, "allocate_pipes(%d) err=%d\n",
555 spin_unlock_irq(&chip->lock);
556 dev_dbg(chip->card->dev, "allocate_pipes()=%d\n", pipe_index);
558 dev_dbg(chip->card->dev,
559 "pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
560 params_buffer_bytes(hw_params), params_periods(hw_params),
561 params_period_bytes(hw_params));
562 err = snd_pcm_lib_malloc_pages(substream,
563 params_buffer_bytes(hw_params));
565 dev_err(chip->card->dev, "malloc_pages err=%d\n", err);
566 spin_lock_irq(&chip->lock);
567 free_pipes(chip, pipe);
568 spin_unlock_irq(&chip->lock);
573 sglist_init(chip, pipe);
575 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
577 rest = params_period_bytes(hw_params);
578 if (offs + rest > params_buffer_bytes(hw_params))
579 rest = params_buffer_bytes(hw_params) - offs;
582 addr = snd_pcm_sgbuf_get_addr(substream, offs);
583 if (rest <= edge - offs) {
584 sglist_add_mapping(chip, pipe, addr, rest);
585 sglist_add_irq(chip, pipe);
589 sglist_add_mapping(chip, pipe, addr,
601 /* Close the ring buffer */
602 sglist_wrap(chip, pipe);
604 /* This stuff is used by the irq handler, so it must be
605 * initialized before chip->substream
607 chip->last_period[pipe_index] = 0;
608 pipe->last_counter = 0;
611 chip->substream[pipe_index] = substream;
613 spin_lock_irq(&chip->lock);
614 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
615 spin_unlock_irq(&chip->lock);
621 static int pcm_analog_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_analog_in(chip) +
627 substream->number, params_channels(hw_params));
632 static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream,
633 struct snd_pcm_hw_params *hw_params)
635 return init_engine(substream, hw_params, substream->number,
636 params_channels(hw_params));
641 #ifdef ECHOCARD_HAS_DIGITAL_IO
643 static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream,
644 struct snd_pcm_hw_params *hw_params)
646 struct echoaudio *chip = snd_pcm_substream_chip(substream);
648 return init_engine(substream, hw_params, px_digital_in(chip) +
649 substream->number, params_channels(hw_params));
654 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
655 static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream,
656 struct snd_pcm_hw_params *hw_params)
658 struct echoaudio *chip = snd_pcm_substream_chip(substream);
660 return init_engine(substream, hw_params, px_digital_out(chip) +
661 substream->number, params_channels(hw_params));
663 #endif /* !ECHOCARD_HAS_VMIXER */
665 #endif /* ECHOCARD_HAS_DIGITAL_IO */
669 static int pcm_hw_free(struct snd_pcm_substream *substream)
671 struct echoaudio *chip;
672 struct audiopipe *pipe;
674 chip = snd_pcm_substream_chip(substream);
675 pipe = (struct audiopipe *) substream->runtime->private_data;
677 spin_lock_irq(&chip->lock);
678 if (pipe->index >= 0) {
679 dev_dbg(chip->card->dev, "pcm_hw_free(%d)\n", pipe->index);
680 free_pipes(chip, pipe);
681 chip->substream[pipe->index] = NULL;
684 spin_unlock_irq(&chip->lock);
686 snd_pcm_lib_free_pages(substream);
692 static int pcm_prepare(struct snd_pcm_substream *substream)
694 struct echoaudio *chip = snd_pcm_substream_chip(substream);
695 struct snd_pcm_runtime *runtime = substream->runtime;
696 struct audioformat format;
697 int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
699 dev_dbg(chip->card->dev, "Prepare rate=%d format=%d channels=%d\n",
700 runtime->rate, runtime->format, runtime->channels);
701 format.interleave = runtime->channels;
702 format.data_are_bigendian = 0;
703 format.mono_to_stereo = 0;
704 switch (runtime->format) {
705 case SNDRV_PCM_FORMAT_U8:
706 format.bits_per_sample = 8;
708 case SNDRV_PCM_FORMAT_S16_LE:
709 format.bits_per_sample = 16;
711 case SNDRV_PCM_FORMAT_S24_3LE:
712 format.bits_per_sample = 24;
714 case SNDRV_PCM_FORMAT_S32_BE:
715 format.data_are_bigendian = 1;
716 case SNDRV_PCM_FORMAT_S32_LE:
717 format.bits_per_sample = 32;
720 dev_err(chip->card->dev,
721 "Prepare error: unsupported format %d\n",
726 if (snd_BUG_ON(pipe_index >= px_num(chip)))
728 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
730 set_audio_format(chip, pipe_index, &format);
736 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
738 struct echoaudio *chip = snd_pcm_substream_chip(substream);
739 struct snd_pcm_runtime *runtime = substream->runtime;
740 struct audiopipe *pipe = runtime->private_data;
743 struct snd_pcm_substream *s;
745 snd_pcm_group_for_each_entry(s, substream) {
746 for (i = 0; i < DSP_MAXPIPES; i++) {
747 if (s == chip->substream[i]) {
748 channelmask |= 1 << i;
749 snd_pcm_trigger_done(s, substream);
754 spin_lock(&chip->lock);
756 case SNDRV_PCM_TRIGGER_RESUME:
757 case SNDRV_PCM_TRIGGER_START:
758 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
759 for (i = 0; i < DSP_MAXPIPES; i++) {
760 if (channelmask & (1 << i)) {
761 pipe = chip->substream[i]->runtime->private_data;
762 switch (pipe->state) {
763 case PIPE_STATE_STOPPED:
764 chip->last_period[i] = 0;
765 pipe->last_counter = 0;
767 *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;
811 size_t cnt, bufsize, pos;
813 cnt = le32_to_cpu(*pipe->dma_counter);
814 pipe->position += cnt - pipe->last_counter;
815 pipe->last_counter = cnt;
816 bufsize = substream->runtime->buffer_size;
817 pos = bytes_to_frames(substream->runtime, pipe->position);
819 while (pos >= bufsize) {
820 pipe->position -= frames_to_bytes(substream->runtime, bufsize);
828 /* pcm *_ops structures */
829 static struct snd_pcm_ops analog_playback_ops = {
830 .open = pcm_analog_out_open,
832 .ioctl = snd_pcm_lib_ioctl,
833 .hw_params = pcm_analog_out_hw_params,
834 .hw_free = pcm_hw_free,
835 .prepare = pcm_prepare,
836 .trigger = pcm_trigger,
837 .pointer = pcm_pointer,
838 .page = snd_pcm_sgbuf_ops_page,
840 static struct snd_pcm_ops analog_capture_ops = {
841 .open = pcm_analog_in_open,
843 .ioctl = snd_pcm_lib_ioctl,
844 .hw_params = pcm_analog_in_hw_params,
845 .hw_free = pcm_hw_free,
846 .prepare = pcm_prepare,
847 .trigger = pcm_trigger,
848 .pointer = pcm_pointer,
849 .page = snd_pcm_sgbuf_ops_page,
851 #ifdef ECHOCARD_HAS_DIGITAL_IO
852 #ifndef ECHOCARD_HAS_VMIXER
853 static struct snd_pcm_ops digital_playback_ops = {
854 .open = pcm_digital_out_open,
856 .ioctl = snd_pcm_lib_ioctl,
857 .hw_params = pcm_digital_out_hw_params,
858 .hw_free = pcm_hw_free,
859 .prepare = pcm_prepare,
860 .trigger = pcm_trigger,
861 .pointer = pcm_pointer,
862 .page = snd_pcm_sgbuf_ops_page,
864 #endif /* !ECHOCARD_HAS_VMIXER */
865 static struct snd_pcm_ops digital_capture_ops = {
866 .open = pcm_digital_in_open,
868 .ioctl = snd_pcm_lib_ioctl,
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,
874 .page = snd_pcm_sgbuf_ops_page,
876 #endif /* ECHOCARD_HAS_DIGITAL_IO */
880 /* Preallocate memory only for the first substream because it's the most
883 static int snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev)
885 struct snd_pcm_substream *ss;
888 for (stream = 0; stream < 2; stream++)
889 for (ss = pcm->streams[stream].substream; ss; ss = ss->next) {
890 err = snd_pcm_lib_preallocate_pages(ss, SNDRV_DMA_TYPE_DEV_SG,
892 ss->number ? 0 : 128<<10,
902 /*<--snd_echo_probe() */
903 static int snd_echo_new_pcm(struct echoaudio *chip)
908 #ifdef ECHOCARD_HAS_VMIXER
909 /* This card has a Vmixer, that is there is no direct mapping from PCM
910 streams to physical outputs. The user can mix the streams as he wishes
911 via control interface and it's possible to send any stream to any
912 output, thus it makes no sense to keep analog and digital outputs
915 /* PCM#0 Virtual outputs and analog inputs */
916 if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip),
917 num_analog_busses_in(chip), &pcm)) < 0)
919 pcm->private_data = chip;
920 chip->analog_pcm = pcm;
921 strcpy(pcm->name, chip->card->shortname);
922 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
923 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
924 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
927 #ifdef ECHOCARD_HAS_DIGITAL_IO
928 /* PCM#1 Digital inputs, no outputs */
929 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0,
930 num_digital_busses_in(chip), &pcm)) < 0)
932 pcm->private_data = chip;
933 chip->digital_pcm = pcm;
934 strcpy(pcm->name, chip->card->shortname);
935 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
936 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
938 #endif /* ECHOCARD_HAS_DIGITAL_IO */
940 #else /* ECHOCARD_HAS_VMIXER */
942 /* The card can manage substreams formed by analog and digital channels
943 at the same time, but I prefer to keep analog and digital channels
944 separated, because that mixed thing is confusing and useless. So we
945 register two PCM devices: */
947 /* PCM#0 Analog i/o */
948 if ((err = snd_pcm_new(chip->card, "Analog PCM", 0,
949 num_analog_busses_out(chip),
950 num_analog_busses_in(chip), &pcm)) < 0)
952 pcm->private_data = chip;
953 chip->analog_pcm = pcm;
954 strcpy(pcm->name, chip->card->shortname);
955 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
956 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
957 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
960 #ifdef ECHOCARD_HAS_DIGITAL_IO
961 /* PCM#1 Digital i/o */
962 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1,
963 num_digital_busses_out(chip),
964 num_digital_busses_in(chip), &pcm)) < 0)
966 pcm->private_data = chip;
967 chip->digital_pcm = pcm;
968 strcpy(pcm->name, chip->card->shortname);
969 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops);
970 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
971 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
973 #endif /* ECHOCARD_HAS_DIGITAL_IO */
975 #endif /* ECHOCARD_HAS_VMIXER */
983 /******************************************************************************
985 ******************************************************************************/
987 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
989 /******************* PCM output volume *******************/
990 static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
991 struct snd_ctl_elem_info *uinfo)
993 struct echoaudio *chip;
995 chip = snd_kcontrol_chip(kcontrol);
996 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
997 uinfo->count = num_busses_out(chip);
998 uinfo->value.integer.min = ECHOGAIN_MINOUT;
999 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1003 static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
1004 struct snd_ctl_elem_value *ucontrol)
1006 struct echoaudio *chip;
1009 chip = snd_kcontrol_chip(kcontrol);
1010 for (c = 0; c < num_busses_out(chip); c++)
1011 ucontrol->value.integer.value[c] = chip->output_gain[c];
1015 static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
1016 struct snd_ctl_elem_value *ucontrol)
1018 struct echoaudio *chip;
1019 int c, changed, gain;
1022 chip = snd_kcontrol_chip(kcontrol);
1023 spin_lock_irq(&chip->lock);
1024 for (c = 0; c < num_busses_out(chip); c++) {
1025 gain = ucontrol->value.integer.value[c];
1026 /* Ignore out of range values */
1027 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1029 if (chip->output_gain[c] != gain) {
1030 set_output_gain(chip, c, gain);
1035 update_output_line_level(chip);
1036 spin_unlock_irq(&chip->lock);
1040 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1041 /* On the Mia this one controls the line-out volume */
1042 static struct snd_kcontrol_new snd_echo_line_output_gain = {
1043 .name = "Line Playback Volume",
1044 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1045 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1046 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1047 .info = snd_echo_output_gain_info,
1048 .get = snd_echo_output_gain_get,
1049 .put = snd_echo_output_gain_put,
1050 .tlv = {.p = db_scale_output_gain},
1053 static struct snd_kcontrol_new snd_echo_pcm_output_gain = {
1054 .name = "PCM Playback Volume",
1055 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1056 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1057 .info = snd_echo_output_gain_info,
1058 .get = snd_echo_output_gain_get,
1059 .put = snd_echo_output_gain_put,
1060 .tlv = {.p = db_scale_output_gain},
1064 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1068 #ifdef ECHOCARD_HAS_INPUT_GAIN
1070 /******************* Analog input volume *******************/
1071 static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
1072 struct snd_ctl_elem_info *uinfo)
1074 struct echoaudio *chip;
1076 chip = snd_kcontrol_chip(kcontrol);
1077 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1078 uinfo->count = num_analog_busses_in(chip);
1079 uinfo->value.integer.min = ECHOGAIN_MININP;
1080 uinfo->value.integer.max = ECHOGAIN_MAXINP;
1084 static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
1085 struct snd_ctl_elem_value *ucontrol)
1087 struct echoaudio *chip;
1090 chip = snd_kcontrol_chip(kcontrol);
1091 for (c = 0; c < num_analog_busses_in(chip); c++)
1092 ucontrol->value.integer.value[c] = chip->input_gain[c];
1096 static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
1097 struct snd_ctl_elem_value *ucontrol)
1099 struct echoaudio *chip;
1100 int c, gain, changed;
1103 chip = snd_kcontrol_chip(kcontrol);
1104 spin_lock_irq(&chip->lock);
1105 for (c = 0; c < num_analog_busses_in(chip); c++) {
1106 gain = ucontrol->value.integer.value[c];
1107 /* Ignore out of range values */
1108 if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
1110 if (chip->input_gain[c] != gain) {
1111 set_input_gain(chip, c, gain);
1116 update_input_line_level(chip);
1117 spin_unlock_irq(&chip->lock);
1121 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain, -2500, 50, 0);
1123 static struct snd_kcontrol_new snd_echo_line_input_gain = {
1124 .name = "Line Capture Volume",
1125 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1126 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1127 .info = snd_echo_input_gain_info,
1128 .get = snd_echo_input_gain_get,
1129 .put = snd_echo_input_gain_put,
1130 .tlv = {.p = db_scale_input_gain},
1133 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1137 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1139 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1140 static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
1141 struct snd_ctl_elem_info *uinfo)
1143 struct echoaudio *chip;
1145 chip = snd_kcontrol_chip(kcontrol);
1146 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1147 uinfo->count = num_analog_busses_out(chip);
1148 uinfo->value.integer.min = 0;
1149 uinfo->value.integer.max = 1;
1153 static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
1154 struct snd_ctl_elem_value *ucontrol)
1156 struct echoaudio *chip;
1159 chip = snd_kcontrol_chip(kcontrol);
1160 for (c = 0; c < num_analog_busses_out(chip); c++)
1161 ucontrol->value.integer.value[c] = chip->nominal_level[c];
1165 static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
1166 struct snd_ctl_elem_value *ucontrol)
1168 struct echoaudio *chip;
1172 chip = snd_kcontrol_chip(kcontrol);
1173 spin_lock_irq(&chip->lock);
1174 for (c = 0; c < num_analog_busses_out(chip); c++) {
1175 if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
1176 set_nominal_level(chip, c,
1177 ucontrol->value.integer.value[c]);
1182 update_output_line_level(chip);
1183 spin_unlock_irq(&chip->lock);
1187 static struct snd_kcontrol_new snd_echo_output_nominal_level = {
1188 .name = "Line Playback Switch (-10dBV)",
1189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1190 .info = snd_echo_output_nominal_info,
1191 .get = snd_echo_output_nominal_get,
1192 .put = snd_echo_output_nominal_put,
1195 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1199 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1201 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1202 static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
1203 struct snd_ctl_elem_info *uinfo)
1205 struct echoaudio *chip;
1207 chip = snd_kcontrol_chip(kcontrol);
1208 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1209 uinfo->count = num_analog_busses_in(chip);
1210 uinfo->value.integer.min = 0;
1211 uinfo->value.integer.max = 1;
1215 static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
1216 struct snd_ctl_elem_value *ucontrol)
1218 struct echoaudio *chip;
1221 chip = snd_kcontrol_chip(kcontrol);
1222 for (c = 0; c < num_analog_busses_in(chip); c++)
1223 ucontrol->value.integer.value[c] =
1224 chip->nominal_level[bx_analog_in(chip) + c];
1228 static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
1229 struct snd_ctl_elem_value *ucontrol)
1231 struct echoaudio *chip;
1235 chip = snd_kcontrol_chip(kcontrol);
1236 spin_lock_irq(&chip->lock);
1237 for (c = 0; c < num_analog_busses_in(chip); c++) {
1238 if (chip->nominal_level[bx_analog_in(chip) + c] !=
1239 ucontrol->value.integer.value[c]) {
1240 set_nominal_level(chip, bx_analog_in(chip) + c,
1241 ucontrol->value.integer.value[c]);
1246 update_output_line_level(chip); /* "Output" is not a mistake
1249 spin_unlock_irq(&chip->lock);
1253 static struct snd_kcontrol_new snd_echo_intput_nominal_level = {
1254 .name = "Line Capture Switch (-10dBV)",
1255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1256 .info = snd_echo_input_nominal_info,
1257 .get = snd_echo_input_nominal_get,
1258 .put = snd_echo_input_nominal_put,
1261 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1265 #ifdef ECHOCARD_HAS_MONITOR
1267 /******************* Monitor mixer *******************/
1268 static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1269 struct snd_ctl_elem_info *uinfo)
1271 struct echoaudio *chip;
1273 chip = snd_kcontrol_chip(kcontrol);
1274 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1276 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1277 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1278 uinfo->dimen.d[0] = num_busses_out(chip);
1279 uinfo->dimen.d[1] = num_busses_in(chip);
1283 static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1284 struct snd_ctl_elem_value *ucontrol)
1286 struct echoaudio *chip;
1288 chip = snd_kcontrol_chip(kcontrol);
1289 ucontrol->value.integer.value[0] =
1290 chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)]
1291 [ucontrol->id.index % num_busses_in(chip)];
1295 static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1296 struct snd_ctl_elem_value *ucontrol)
1298 struct echoaudio *chip;
1303 chip = snd_kcontrol_chip(kcontrol);
1304 out = ucontrol->id.index / num_busses_in(chip);
1305 in = ucontrol->id.index % num_busses_in(chip);
1306 gain = ucontrol->value.integer.value[0];
1307 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1309 if (chip->monitor_gain[out][in] != gain) {
1310 spin_lock_irq(&chip->lock);
1311 set_monitor_gain(chip, out, in, gain);
1312 update_output_line_level(chip);
1313 spin_unlock_irq(&chip->lock);
1319 static struct snd_kcontrol_new snd_echo_monitor_mixer = {
1320 .name = "Monitor Mixer Volume",
1321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1322 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1323 .info = snd_echo_mixer_info,
1324 .get = snd_echo_mixer_get,
1325 .put = snd_echo_mixer_put,
1326 .tlv = {.p = db_scale_output_gain},
1329 #endif /* ECHOCARD_HAS_MONITOR */
1333 #ifdef ECHOCARD_HAS_VMIXER
1335 /******************* Vmixer *******************/
1336 static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
1337 struct snd_ctl_elem_info *uinfo)
1339 struct echoaudio *chip;
1341 chip = snd_kcontrol_chip(kcontrol);
1342 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1344 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1345 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1346 uinfo->dimen.d[0] = num_busses_out(chip);
1347 uinfo->dimen.d[1] = num_pipes_out(chip);
1351 static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
1352 struct snd_ctl_elem_value *ucontrol)
1354 struct echoaudio *chip;
1356 chip = snd_kcontrol_chip(kcontrol);
1357 ucontrol->value.integer.value[0] =
1358 chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
1359 [ucontrol->id.index % num_pipes_out(chip)];
1363 static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
1364 struct snd_ctl_elem_value *ucontrol)
1366 struct echoaudio *chip;
1371 chip = snd_kcontrol_chip(kcontrol);
1372 out = ucontrol->id.index / num_pipes_out(chip);
1373 vch = ucontrol->id.index % num_pipes_out(chip);
1374 gain = ucontrol->value.integer.value[0];
1375 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1377 if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
1378 spin_lock_irq(&chip->lock);
1379 set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
1380 update_vmixer_level(chip);
1381 spin_unlock_irq(&chip->lock);
1387 static struct snd_kcontrol_new snd_echo_vmixer = {
1388 .name = "VMixer Volume",
1389 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1390 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1391 .info = snd_echo_vmixer_info,
1392 .get = snd_echo_vmixer_get,
1393 .put = snd_echo_vmixer_put,
1394 .tlv = {.p = db_scale_output_gain},
1397 #endif /* ECHOCARD_HAS_VMIXER */
1401 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1403 /******************* Digital mode switch *******************/
1404 static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1405 struct snd_ctl_elem_info *uinfo)
1407 static const char * const names[4] = {
1408 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1411 struct echoaudio *chip;
1413 chip = snd_kcontrol_chip(kcontrol);
1414 return snd_ctl_enum_info(uinfo, 1, chip->num_digital_modes, names);
1417 static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
1418 struct snd_ctl_elem_value *ucontrol)
1420 struct echoaudio *chip;
1423 chip = snd_kcontrol_chip(kcontrol);
1424 mode = chip->digital_mode;
1425 for (i = chip->num_digital_modes - 1; i >= 0; i--)
1426 if (mode == chip->digital_mode_list[i]) {
1427 ucontrol->value.enumerated.item[0] = i;
1433 static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1434 struct snd_ctl_elem_value *ucontrol)
1436 struct echoaudio *chip;
1438 unsigned short emode, dmode;
1441 chip = snd_kcontrol_chip(kcontrol);
1443 emode = ucontrol->value.enumerated.item[0];
1444 if (emode >= chip->num_digital_modes)
1446 dmode = chip->digital_mode_list[emode];
1448 if (dmode != chip->digital_mode) {
1449 /* mode_mutex is required to make this operation atomic wrt
1450 pcm_digital_*_open() and set_input_clock() functions. */
1451 mutex_lock(&chip->mode_mutex);
1453 /* Do not allow the user to change the digital mode when a pcm
1454 device is open because it also changes the number of channels
1455 and the allowed sample rates */
1456 if (atomic_read(&chip->opencount)) {
1459 changed = set_digital_mode(chip, dmode);
1460 /* If we had to change the clock source, report it */
1461 if (changed > 0 && chip->clock_src_ctl) {
1462 snd_ctl_notify(chip->card,
1463 SNDRV_CTL_EVENT_MASK_VALUE,
1464 &chip->clock_src_ctl->id);
1465 dev_dbg(chip->card->dev,
1466 "SDM() =%d\n", changed);
1469 changed = 1; /* No errors */
1471 mutex_unlock(&chip->mode_mutex);
1476 static struct snd_kcontrol_new snd_echo_digital_mode_switch = {
1477 .name = "Digital mode Switch",
1478 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1479 .info = snd_echo_digital_mode_info,
1480 .get = snd_echo_digital_mode_get,
1481 .put = snd_echo_digital_mode_put,
1484 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1488 #ifdef ECHOCARD_HAS_DIGITAL_IO
1490 /******************* S/PDIF mode switch *******************/
1491 static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1492 struct snd_ctl_elem_info *uinfo)
1494 static const char * const names[2] = {"Consumer", "Professional"};
1496 return snd_ctl_enum_info(uinfo, 1, 2, names);
1499 static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
1500 struct snd_ctl_elem_value *ucontrol)
1502 struct echoaudio *chip;
1504 chip = snd_kcontrol_chip(kcontrol);
1505 ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
1509 static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
1510 struct snd_ctl_elem_value *ucontrol)
1512 struct echoaudio *chip;
1515 chip = snd_kcontrol_chip(kcontrol);
1516 mode = !!ucontrol->value.enumerated.item[0];
1517 if (mode != chip->professional_spdif) {
1518 spin_lock_irq(&chip->lock);
1519 set_professional_spdif(chip, mode);
1520 spin_unlock_irq(&chip->lock);
1526 static struct snd_kcontrol_new snd_echo_spdif_mode_switch = {
1527 .name = "S/PDIF mode Switch",
1528 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1529 .info = snd_echo_spdif_mode_info,
1530 .get = snd_echo_spdif_mode_get,
1531 .put = snd_echo_spdif_mode_put,
1534 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1538 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1540 /******************* Select input clock source *******************/
1541 static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1542 struct snd_ctl_elem_info *uinfo)
1544 static const char * const names[8] = {
1545 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1548 struct echoaudio *chip;
1550 chip = snd_kcontrol_chip(kcontrol);
1551 return snd_ctl_enum_info(uinfo, 1, chip->num_clock_sources, names);
1554 static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
1555 struct snd_ctl_elem_value *ucontrol)
1557 struct echoaudio *chip;
1560 chip = snd_kcontrol_chip(kcontrol);
1561 clock = chip->input_clock;
1563 for (i = 0; i < chip->num_clock_sources; i++)
1564 if (clock == chip->clock_source_list[i])
1565 ucontrol->value.enumerated.item[0] = i;
1570 static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1571 struct snd_ctl_elem_value *ucontrol)
1573 struct echoaudio *chip;
1575 unsigned int eclock, dclock;
1578 chip = snd_kcontrol_chip(kcontrol);
1579 eclock = ucontrol->value.enumerated.item[0];
1580 if (eclock >= chip->input_clock_types)
1582 dclock = chip->clock_source_list[eclock];
1583 if (chip->input_clock != dclock) {
1584 mutex_lock(&chip->mode_mutex);
1585 spin_lock_irq(&chip->lock);
1586 if ((changed = set_input_clock(chip, dclock)) == 0)
1587 changed = 1; /* no errors */
1588 spin_unlock_irq(&chip->lock);
1589 mutex_unlock(&chip->mode_mutex);
1593 dev_dbg(chip->card->dev,
1594 "seticlk val%d err 0x%x\n", dclock, changed);
1599 static struct snd_kcontrol_new snd_echo_clock_source_switch = {
1600 .name = "Sample Clock Source",
1601 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1602 .info = snd_echo_clock_source_info,
1603 .get = snd_echo_clock_source_get,
1604 .put = snd_echo_clock_source_put,
1607 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1611 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1613 /******************* Phantom power switch *******************/
1614 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1616 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1619 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1621 ucontrol->value.integer.value[0] = chip->phantom_power;
1625 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1626 struct snd_ctl_elem_value *ucontrol)
1628 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1629 int power, changed = 0;
1631 power = !!ucontrol->value.integer.value[0];
1632 if (chip->phantom_power != power) {
1633 spin_lock_irq(&chip->lock);
1634 changed = set_phantom_power(chip, power);
1635 spin_unlock_irq(&chip->lock);
1637 changed = 1; /* no errors */
1642 static struct snd_kcontrol_new snd_echo_phantom_power_switch = {
1643 .name = "Phantom power Switch",
1644 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1645 .info = snd_echo_phantom_power_info,
1646 .get = snd_echo_phantom_power_get,
1647 .put = snd_echo_phantom_power_put,
1650 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1654 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1656 /******************* Digital input automute switch *******************/
1657 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1659 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1660 struct snd_ctl_elem_value *ucontrol)
1662 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1664 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1668 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1669 struct snd_ctl_elem_value *ucontrol)
1671 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1672 int automute, changed = 0;
1674 automute = !!ucontrol->value.integer.value[0];
1675 if (chip->digital_in_automute != automute) {
1676 spin_lock_irq(&chip->lock);
1677 changed = set_input_auto_mute(chip, automute);
1678 spin_unlock_irq(&chip->lock);
1680 changed = 1; /* no errors */
1685 static struct snd_kcontrol_new snd_echo_automute_switch = {
1686 .name = "Digital Capture Switch (automute)",
1687 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1688 .info = snd_echo_automute_info,
1689 .get = snd_echo_automute_get,
1690 .put = snd_echo_automute_put,
1693 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1697 /******************* VU-meters switch *******************/
1698 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1700 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1701 struct snd_ctl_elem_value *ucontrol)
1703 struct echoaudio *chip;
1705 chip = snd_kcontrol_chip(kcontrol);
1706 spin_lock_irq(&chip->lock);
1707 set_meters_on(chip, ucontrol->value.integer.value[0]);
1708 spin_unlock_irq(&chip->lock);
1712 static struct snd_kcontrol_new snd_echo_vumeters_switch = {
1713 .name = "VU-meters Switch",
1714 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1715 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1716 .info = snd_echo_vumeters_switch_info,
1717 .put = snd_echo_vumeters_switch_put,
1722 /***** Read VU-meters (input, output, analog and digital together) *****/
1723 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1724 struct snd_ctl_elem_info *uinfo)
1726 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1728 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1729 uinfo->value.integer.max = 0;
1730 #ifdef ECHOCARD_HAS_VMIXER
1731 uinfo->dimen.d[0] = 3; /* Out, In, Virt */
1733 uinfo->dimen.d[0] = 2; /* Out, In */
1735 uinfo->dimen.d[1] = 16; /* 16 channels */
1736 uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */
1740 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1741 struct snd_ctl_elem_value *ucontrol)
1743 struct echoaudio *chip;
1745 chip = snd_kcontrol_chip(kcontrol);
1746 get_audio_meters(chip, ucontrol->value.integer.value);
1750 static struct snd_kcontrol_new snd_echo_vumeters = {
1751 .name = "VU-meters",
1752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1753 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1754 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
1755 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1756 .info = snd_echo_vumeters_info,
1757 .get = snd_echo_vumeters_get,
1758 .tlv = {.p = db_scale_output_gain},
1763 /*** Channels info - it exports informations about the number of channels ***/
1764 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1765 struct snd_ctl_elem_info *uinfo)
1767 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1769 uinfo->value.integer.min = 0;
1770 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1774 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1775 struct snd_ctl_elem_value *ucontrol)
1777 struct echoaudio *chip;
1778 int detected, clocks, bit, src;
1780 chip = snd_kcontrol_chip(kcontrol);
1781 ucontrol->value.integer.value[0] = num_busses_in(chip);
1782 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1783 ucontrol->value.integer.value[2] = num_busses_out(chip);
1784 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1785 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1787 /* Compute the bitmask of the currently valid input clocks */
1788 detected = detect_input_clocks(chip);
1790 src = chip->num_clock_sources - 1;
1791 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1792 if (detected & (1 << bit))
1793 for (; src >= 0; src--)
1794 if (bit == chip->clock_source_list[src]) {
1798 ucontrol->value.integer.value[5] = clocks;
1803 static struct snd_kcontrol_new snd_echo_channels_info = {
1804 .name = "Channels info",
1805 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1806 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1807 .info = snd_echo_channels_info_info,
1808 .get = snd_echo_channels_info_get,
1814 /******************************************************************************
1816 ******************************************************************************/
1818 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1820 struct echoaudio *chip = dev_id;
1821 struct snd_pcm_substream *substream;
1824 spin_lock(&chip->lock);
1825 st = service_irq(chip);
1827 spin_unlock(&chip->lock);
1830 /* The hardware doesn't tell us which substream caused the irq,
1831 thus we have to check all running substreams. */
1832 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1833 substream = chip->substream[ss];
1834 if (substream && ((struct audiopipe *)substream->runtime->
1835 private_data)->state == PIPE_STATE_STARTED) {
1836 period = pcm_pointer(substream) /
1837 substream->runtime->period_size;
1838 if (period != chip->last_period[ss]) {
1839 chip->last_period[ss] = period;
1840 spin_unlock(&chip->lock);
1841 snd_pcm_period_elapsed(substream);
1842 spin_lock(&chip->lock);
1846 spin_unlock(&chip->lock);
1848 #ifdef ECHOCARD_HAS_MIDI
1849 if (st > 0 && chip->midi_in) {
1850 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1851 dev_dbg(chip->card->dev, "rawmidi_iread=%d\n", st);
1860 /******************************************************************************
1861 Module construction / destruction
1862 ******************************************************************************/
1864 static int snd_echo_free(struct echoaudio *chip)
1866 if (chip->comm_page)
1867 rest_in_peace(chip);
1870 free_irq(chip->irq, chip);
1872 if (chip->comm_page)
1873 snd_dma_free_pages(&chip->commpage_dma_buf);
1875 if (chip->dsp_registers)
1876 iounmap(chip->dsp_registers);
1878 release_and_free_resource(chip->iores);
1881 pci_disable_device(chip->pci);
1883 /* release chip data */
1884 free_firmware_cache(chip);
1891 static int snd_echo_dev_free(struct snd_device *device)
1893 struct echoaudio *chip = device->device_data;
1895 return snd_echo_free(chip);
1900 /* <--snd_echo_probe() */
1901 static int snd_echo_create(struct snd_card *card,
1902 struct pci_dev *pci,
1903 struct echoaudio **rchip)
1905 struct echoaudio *chip;
1908 static struct snd_device_ops ops = {
1909 .dev_free = snd_echo_dev_free,
1914 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1916 if ((err = pci_enable_device(pci)) < 0)
1918 pci_set_master(pci);
1920 /* Allocate chip if needed */
1922 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1924 pci_disable_device(pci);
1927 dev_dbg(card->dev, "chip=%p\n", chip);
1928 spin_lock_init(&chip->lock);
1932 atomic_set(&chip->opencount, 0);
1933 mutex_init(&chip->mode_mutex);
1934 chip->can_set_rate = 1;
1936 /* If this was called from the resume function, chip is
1937 * already allocated and it contains current card settings.
1942 /* PCI resource allocation */
1943 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1944 sz = pci_resource_len(pci, 0);
1946 sz = PAGE_SIZE; /* We map only the required part */
1948 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1949 ECHOCARD_NAME)) == NULL) {
1950 dev_err(chip->card->dev, "cannot get memory region\n");
1951 snd_echo_free(chip);
1954 chip->dsp_registers = (volatile u32 __iomem *)
1955 ioremap_nocache(chip->dsp_registers_phys, sz);
1957 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1958 KBUILD_MODNAME, chip)) {
1959 dev_err(chip->card->dev, "cannot grab irq\n");
1960 snd_echo_free(chip);
1963 chip->irq = pci->irq;
1964 dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n",
1965 chip->pci, chip->irq, chip->pci->subsystem_device);
1967 /* Create the DSP comm page - this is the area of memory used for most
1968 of the communication with the DSP, which accesses it via bus mastering */
1969 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1970 sizeof(struct comm_page),
1971 &chip->commpage_dma_buf) < 0) {
1972 dev_err(chip->card->dev, "cannot allocate the comm page\n");
1973 snd_echo_free(chip);
1976 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1977 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1979 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1981 err = set_mixer_defaults(chip);
1983 dev_err(card->dev, "init_hw err=%d\n", err);
1984 snd_echo_free(chip);
1988 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1989 snd_echo_free(chip);
2000 static int snd_echo_probe(struct pci_dev *pci,
2001 const struct pci_device_id *pci_id)
2004 struct snd_card *card;
2005 struct echoaudio *chip;
2009 if (dev >= SNDRV_CARDS)
2017 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2022 chip = NULL; /* Tells snd_echo_create to allocate chip */
2023 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2024 snd_card_free(card);
2028 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
2029 strcpy(card->shortname, chip->card_name);
2032 if (pci_id->device == 0x3410)
2035 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2036 card->shortname, pci_id->subdevice & 0x000f, dsp,
2037 chip->dsp_registers_phys, chip->irq);
2039 if ((err = snd_echo_new_pcm(chip)) < 0) {
2040 dev_err(chip->card->dev, "new pcm error %d\n", err);
2041 snd_card_free(card);
2045 #ifdef ECHOCARD_HAS_MIDI
2046 if (chip->has_midi) { /* Some Mia's do not have midi */
2047 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2048 dev_err(chip->card->dev, "new midi error %d\n", err);
2049 snd_card_free(card);
2055 #ifdef ECHOCARD_HAS_VMIXER
2056 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2057 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2059 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2060 err = snd_ctl_add(chip->card,
2061 snd_ctl_new1(&snd_echo_line_output_gain, chip));
2065 #else /* ECHOCARD_HAS_VMIXER */
2066 err = snd_ctl_add(chip->card,
2067 snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
2070 #endif /* ECHOCARD_HAS_VMIXER */
2072 #ifdef ECHOCARD_HAS_INPUT_GAIN
2073 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2077 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2078 if (!chip->hasnt_input_nominal_level)
2079 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2083 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2084 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2088 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2091 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2094 #ifdef ECHOCARD_HAS_MONITOR
2095 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2096 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2100 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2101 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2105 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2108 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2109 /* Creates a list of available digital modes */
2110 chip->num_digital_modes = 0;
2111 for (i = 0; i < 6; i++)
2112 if (chip->digital_modes & (1 << i))
2113 chip->digital_mode_list[chip->num_digital_modes++] = i;
2115 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2117 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2119 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2120 /* Creates a list of available clock sources */
2121 chip->num_clock_sources = 0;
2122 for (i = 0; i < 10; i++)
2123 if (chip->input_clock_types & (1 << i))
2124 chip->clock_source_list[chip->num_clock_sources++] = i;
2126 if (chip->num_clock_sources > 1) {
2127 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2128 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2131 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2133 #ifdef ECHOCARD_HAS_DIGITAL_IO
2134 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2138 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2139 if (chip->has_phantom_power)
2140 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2144 err = snd_card_register(card);
2147 dev_info(card->dev, "Card registered: %s\n", card->longname);
2149 pci_set_drvdata(pci, chip);
2154 dev_err(card->dev, "new control error %d\n", err);
2155 snd_card_free(card);
2161 #if defined(CONFIG_PM_SLEEP)
2163 static int snd_echo_suspend(struct device *dev)
2165 struct pci_dev *pci = to_pci_dev(dev);
2166 struct echoaudio *chip = dev_get_drvdata(dev);
2168 snd_pcm_suspend_all(chip->analog_pcm);
2169 snd_pcm_suspend_all(chip->digital_pcm);
2171 #ifdef ECHOCARD_HAS_MIDI
2172 /* This call can sleep */
2174 snd_echo_midi_output_trigger(chip->midi_out, 0);
2176 spin_lock_irq(&chip->lock);
2177 if (wait_handshake(chip)) {
2178 spin_unlock_irq(&chip->lock);
2181 clear_handshake(chip);
2182 if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) {
2183 spin_unlock_irq(&chip->lock);
2186 spin_unlock_irq(&chip->lock);
2188 chip->dsp_code = NULL;
2189 free_irq(chip->irq, chip);
2191 pci_save_state(pci);
2192 pci_disable_device(pci);
2199 static int snd_echo_resume(struct device *dev)
2201 struct pci_dev *pci = to_pci_dev(dev);
2202 struct echoaudio *chip = dev_get_drvdata(dev);
2203 struct comm_page *commpage, *commpage_bak;
2204 u32 pipe_alloc_mask;
2207 pci_restore_state(pci);
2208 commpage_bak = kmalloc(sizeof(struct echoaudio), GFP_KERNEL);
2209 if (commpage_bak == NULL)
2211 commpage = chip->comm_page;
2212 memcpy(commpage_bak, commpage, sizeof(struct comm_page));
2214 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
2216 kfree(commpage_bak);
2217 dev_err(dev, "resume init_hw err=%d\n", err);
2218 snd_echo_free(chip);
2222 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2223 * restore_dsp_settings() fails.
2225 pipe_alloc_mask = chip->pipe_alloc_mask;
2226 chip->pipe_alloc_mask = 0;
2227 err = restore_dsp_rettings(chip);
2228 chip->pipe_alloc_mask = pipe_alloc_mask;
2230 kfree(commpage_bak);
2234 memcpy(&commpage->audio_format, &commpage_bak->audio_format,
2235 sizeof(commpage->audio_format));
2236 memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr,
2237 sizeof(commpage->sglist_addr));
2238 memcpy(&commpage->midi_output, &commpage_bak->midi_output,
2239 sizeof(commpage->midi_output));
2240 kfree(commpage_bak);
2242 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
2243 KBUILD_MODNAME, chip)) {
2244 dev_err(chip->card->dev, "cannot grab irq\n");
2245 snd_echo_free(chip);
2248 chip->irq = pci->irq;
2249 dev_dbg(dev, "resume irq=%d\n", chip->irq);
2251 #ifdef ECHOCARD_HAS_MIDI
2252 if (chip->midi_input_enabled)
2253 enable_midi_input(chip, TRUE);
2255 snd_echo_midi_output_trigger(chip->midi_out, 1);
2261 static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume);
2262 #define SND_ECHO_PM_OPS &snd_echo_pm
2264 #define SND_ECHO_PM_OPS NULL
2265 #endif /* CONFIG_PM_SLEEP */
2268 static void snd_echo_remove(struct pci_dev *pci)
2270 struct echoaudio *chip;
2272 chip = pci_get_drvdata(pci);
2274 snd_card_free(chip->card);
2279 /******************************************************************************
2280 Everything starts and ends here
2281 ******************************************************************************/
2283 /* pci_driver definition */
2284 static struct pci_driver echo_driver = {
2285 .name = KBUILD_MODNAME,
2286 .id_table = snd_echo_ids,
2287 .probe = snd_echo_probe,
2288 .remove = snd_echo_remove,
2290 .pm = SND_ECHO_PM_OPS,
2294 module_pci_driver(echo_driver);