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 DE_ACT(("firmware requested: %s is cached\n", card_fw[fw_index].data));
52 *fw_entry = chip->fw_cache[fw_index];
57 DE_ACT(("firmware requested: %s\n", card_fw[fw_index].data));
58 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data);
59 err = request_firmware(fw_entry, name, pci_device(chip));
61 dev_err(chip->card->dev,
62 "get_firmware(): Firmware not available (%d)\n", err);
63 #ifdef CONFIG_PM_SLEEP
65 chip->fw_cache[fw_index] = *fw_entry;
72 static void free_firmware(const struct firmware *fw_entry,
73 struct echoaudio *chip)
75 #ifdef CONFIG_PM_SLEEP
76 DE_ACT(("firmware not released (kept in cache)\n"));
78 release_firmware(fw_entry);
79 DE_ACT(("firmware released\n"));
85 static void free_firmware_cache(struct echoaudio *chip)
87 #ifdef CONFIG_PM_SLEEP
90 for (i = 0; i < 8 ; i++)
91 if (chip->fw_cache[i]) {
92 release_firmware(chip->fw_cache[i]);
93 DE_ACT(("release_firmware(%d)\n", i));
96 DE_ACT(("firmware_cache released\n"));
102 /******************************************************************************
104 ******************************************************************************/
106 static void audiopipe_free(struct snd_pcm_runtime *runtime)
108 struct audiopipe *pipe = runtime->private_data;
110 if (pipe->sgpage.area)
111 snd_dma_free_pages(&pipe->sgpage);
117 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
118 struct snd_pcm_hw_rule *rule)
120 struct snd_interval *c = hw_param_interval(params,
121 SNDRV_PCM_HW_PARAM_CHANNELS);
122 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
127 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
128 /* >=2 channels cannot be S32_BE */
130 fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
131 return snd_mask_refine(f, &fmt);
134 /* > 2 channels cannot be U8 and S32_BE */
136 fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
137 return snd_mask_refine(f, &fmt);
139 /* Mono is ok with any format */
145 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
146 struct snd_pcm_hw_rule *rule)
148 struct snd_interval *c = hw_param_interval(params,
149 SNDRV_PCM_HW_PARAM_CHANNELS);
150 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
151 struct snd_interval ch;
153 snd_interval_any(&ch);
155 /* S32_BE is mono (and stereo) only */
156 if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
158 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
164 return snd_interval_refine(c, &ch);
166 /* U8 can be only mono or stereo */
167 if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
171 return snd_interval_refine(c, &ch);
173 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
179 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
180 struct snd_pcm_hw_rule *rule)
182 struct snd_interval *c = hw_param_interval(params,
183 SNDRV_PCM_HW_PARAM_CHANNELS);
184 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
189 fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
191 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
193 fmask &= SNDRV_PCM_FMTBIT_S16_LE |
194 SNDRV_PCM_FMTBIT_S24_3LE |
195 SNDRV_PCM_FMTBIT_S32_LE;
196 /* 1 channel must be S32_BE or S32_LE */
197 } else if (c->max == 1)
198 fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
199 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
200 /* 2 channels cannot be S32_BE */
201 else if (c->min == 2 && c->max == 2)
202 fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
207 fmt.bits[0] &= (u32)fmask;
208 fmt.bits[1] &= (u32)(fmask >> 32);
209 return snd_mask_refine(f, &fmt);
214 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
215 struct snd_pcm_hw_rule *rule)
217 struct snd_interval *c = hw_param_interval(params,
218 SNDRV_PCM_HW_PARAM_CHANNELS);
219 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
220 struct snd_interval ch;
223 snd_interval_any(&ch);
225 fmask = f->bits[0] + ((u64)f->bits[1] << 32);
227 /* S32_BE is mono (and stereo) only */
228 if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
230 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
235 /* U8 is stereo only */
236 } else if (fmask == SNDRV_PCM_FMTBIT_U8)
238 /* S16_LE and S24_3LE must be at least stereo */
239 else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
240 SNDRV_PCM_FMTBIT_S24_3LE)))
245 return snd_interval_refine(c, &ch);
250 /* Since the sample rate is a global setting, do allow the user to change the
251 sample rate only if there is only one pcm device open. */
252 static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
253 struct snd_pcm_hw_rule *rule)
255 struct snd_interval *rate = hw_param_interval(params,
256 SNDRV_PCM_HW_PARAM_RATE);
257 struct echoaudio *chip = rule->private;
258 struct snd_interval fixed;
260 if (!chip->can_set_rate) {
261 snd_interval_any(&fixed);
262 fixed.min = fixed.max = chip->sample_rate;
263 return snd_interval_refine(rate, &fixed);
269 static int pcm_open(struct snd_pcm_substream *substream,
270 signed char max_channels)
272 struct echoaudio *chip;
273 struct snd_pcm_runtime *runtime;
274 struct audiopipe *pipe;
277 if (max_channels <= 0)
280 chip = snd_pcm_substream_chip(substream);
281 runtime = substream->runtime;
283 pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
286 pipe->index = -1; /* Not configured yet */
288 /* Set up hw capabilities and contraints */
289 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
290 DE_HWP(("max_channels=%d\n", max_channels));
291 pipe->constr.list = channels_list;
292 pipe->constr.mask = 0;
293 for (i = 0; channels_list[i] <= max_channels; i++);
294 pipe->constr.count = i;
295 if (pipe->hw.channels_max > max_channels)
296 pipe->hw.channels_max = max_channels;
297 if (chip->digital_mode == DIGITAL_MODE_ADAT) {
298 pipe->hw.rate_max = 48000;
299 pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
302 runtime->hw = pipe->hw;
303 runtime->private_data = pipe;
304 runtime->private_free = audiopipe_free;
305 snd_pcm_set_sync(substream);
307 /* Only mono and any even number of channels are allowed */
308 if ((err = snd_pcm_hw_constraint_list(runtime, 0,
309 SNDRV_PCM_HW_PARAM_CHANNELS,
313 /* All periods should have the same size */
314 if ((err = snd_pcm_hw_constraint_integer(runtime,
315 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
318 /* The hw accesses memory in chunks 32 frames long and they should be
319 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
320 generated with a resolution of 32 frames. Thus we need the following */
321 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
322 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
325 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
326 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
330 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
331 SNDRV_PCM_HW_PARAM_RATE,
332 hw_rule_sample_rate, chip,
333 SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
336 /* Finally allocate a page for the scatter-gather list */
337 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
338 snd_dma_pci_data(chip->pci),
339 PAGE_SIZE, &pipe->sgpage)) < 0) {
340 DE_HWP(("s-g list allocation failed\n"));
349 static int pcm_analog_in_open(struct snd_pcm_substream *substream)
351 struct echoaudio *chip = snd_pcm_substream_chip(substream);
354 DE_ACT(("pcm_analog_in_open\n"));
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 DE_HWP(("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 DE_ACT(("pcm_analog_out_open\n"));
390 if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
392 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
393 SNDRV_PCM_HW_PARAM_CHANNELS,
394 hw_rule_playback_channels_by_format,
396 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
398 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
399 SNDRV_PCM_HW_PARAM_FORMAT,
400 hw_rule_playback_format_by_channels,
402 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
404 atomic_inc(&chip->opencount);
405 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
406 chip->can_set_rate=0;
407 DE_HWP(("pcm_analog_out_open cs=%d oc=%d r=%d\n",
408 chip->can_set_rate, atomic_read(&chip->opencount),
415 #ifdef ECHOCARD_HAS_DIGITAL_IO
417 static int pcm_digital_in_open(struct snd_pcm_substream *substream)
419 struct echoaudio *chip = snd_pcm_substream_chip(substream);
420 int err, max_channels;
422 DE_ACT(("pcm_digital_in_open\n"));
423 max_channels = num_digital_busses_in(chip) - substream->number;
424 mutex_lock(&chip->mode_mutex);
425 if (chip->digital_mode == DIGITAL_MODE_ADAT)
426 err = pcm_open(substream, max_channels);
427 else /* If the card has ADAT, subtract the 6 channels
428 * that S/PDIF doesn't have
430 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
435 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
436 SNDRV_PCM_HW_PARAM_CHANNELS,
437 hw_rule_capture_channels_by_format, NULL,
438 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
440 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
441 SNDRV_PCM_HW_PARAM_FORMAT,
442 hw_rule_capture_format_by_channels, NULL,
443 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
446 atomic_inc(&chip->opencount);
447 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
448 chip->can_set_rate=0;
451 mutex_unlock(&chip->mode_mutex);
457 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
459 static int pcm_digital_out_open(struct snd_pcm_substream *substream)
461 struct echoaudio *chip = snd_pcm_substream_chip(substream);
462 int err, max_channels;
464 DE_ACT(("pcm_digital_out_open\n"));
465 max_channels = num_digital_busses_out(chip) - substream->number;
466 mutex_lock(&chip->mode_mutex);
467 if (chip->digital_mode == DIGITAL_MODE_ADAT)
468 err = pcm_open(substream, max_channels);
469 else /* If the card has ADAT, subtract the 6 channels
470 * that S/PDIF doesn't have
472 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
477 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
478 SNDRV_PCM_HW_PARAM_CHANNELS,
479 hw_rule_playback_channels_by_format,
480 NULL, SNDRV_PCM_HW_PARAM_FORMAT,
483 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
484 SNDRV_PCM_HW_PARAM_FORMAT,
485 hw_rule_playback_format_by_channels,
486 NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
489 atomic_inc(&chip->opencount);
490 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
491 chip->can_set_rate=0;
493 mutex_unlock(&chip->mode_mutex);
497 #endif /* !ECHOCARD_HAS_VMIXER */
499 #endif /* ECHOCARD_HAS_DIGITAL_IO */
503 static int pcm_close(struct snd_pcm_substream *substream)
505 struct echoaudio *chip = snd_pcm_substream_chip(substream);
508 /* Nothing to do here. Audio is already off and pipe will be
509 * freed by its callback
511 DE_ACT(("pcm_close\n"));
513 atomic_dec(&chip->opencount);
514 oc = atomic_read(&chip->opencount);
515 DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc,
516 chip->can_set_rate, chip->rate_set));
518 chip->can_set_rate = 1;
521 DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc,
522 chip->can_set_rate,chip->rate_set));
529 /* Channel allocation and scatter-gather list setup */
530 static int init_engine(struct snd_pcm_substream *substream,
531 struct snd_pcm_hw_params *hw_params,
532 int pipe_index, int interleave)
534 struct echoaudio *chip;
535 int err, per, rest, page, edge, offs;
536 struct audiopipe *pipe;
538 chip = snd_pcm_substream_chip(substream);
539 pipe = (struct audiopipe *) substream->runtime->private_data;
541 /* Sets up che hardware. If it's already initialized, reset and
542 * redo with the new parameters
544 spin_lock_irq(&chip->lock);
545 if (pipe->index >= 0) {
546 DE_HWP(("hwp_ie free(%d)\n", pipe->index));
547 err = free_pipes(chip, pipe);
549 chip->substream[pipe->index] = NULL;
552 err = allocate_pipes(chip, pipe, pipe_index, interleave);
554 spin_unlock_irq(&chip->lock);
555 DE_ACT((KERN_NOTICE "allocate_pipes(%d) err=%d\n",
559 spin_unlock_irq(&chip->lock);
560 DE_ACT((KERN_NOTICE "allocate_pipes()=%d\n", pipe_index));
562 DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
563 params_buffer_bytes(hw_params), params_periods(hw_params),
564 params_period_bytes(hw_params)));
565 err = snd_pcm_lib_malloc_pages(substream,
566 params_buffer_bytes(hw_params));
568 dev_err(chip->card->dev, "malloc_pages err=%d\n", err);
569 spin_lock_irq(&chip->lock);
570 free_pipes(chip, pipe);
571 spin_unlock_irq(&chip->lock);
576 sglist_init(chip, pipe);
578 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
580 rest = params_period_bytes(hw_params);
581 if (offs + rest > params_buffer_bytes(hw_params))
582 rest = params_buffer_bytes(hw_params) - offs;
585 addr = snd_pcm_sgbuf_get_addr(substream, offs);
586 if (rest <= edge - offs) {
587 sglist_add_mapping(chip, pipe, addr, rest);
588 sglist_add_irq(chip, pipe);
592 sglist_add_mapping(chip, pipe, addr,
604 /* Close the ring buffer */
605 sglist_wrap(chip, pipe);
607 /* This stuff is used by the irq handler, so it must be
608 * initialized before chip->substream
610 chip->last_period[pipe_index] = 0;
611 pipe->last_counter = 0;
614 chip->substream[pipe_index] = substream;
616 spin_lock_irq(&chip->lock);
617 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
618 spin_unlock_irq(&chip->lock);
619 DE_HWP(("pcm_hw_params ok\n"));
625 static int pcm_analog_in_hw_params(struct snd_pcm_substream *substream,
626 struct snd_pcm_hw_params *hw_params)
628 struct echoaudio *chip = snd_pcm_substream_chip(substream);
630 return init_engine(substream, hw_params, px_analog_in(chip) +
631 substream->number, params_channels(hw_params));
636 static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream,
637 struct snd_pcm_hw_params *hw_params)
639 return init_engine(substream, hw_params, substream->number,
640 params_channels(hw_params));
645 #ifdef ECHOCARD_HAS_DIGITAL_IO
647 static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream,
648 struct snd_pcm_hw_params *hw_params)
650 struct echoaudio *chip = snd_pcm_substream_chip(substream);
652 return init_engine(substream, hw_params, px_digital_in(chip) +
653 substream->number, params_channels(hw_params));
658 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
659 static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream,
660 struct snd_pcm_hw_params *hw_params)
662 struct echoaudio *chip = snd_pcm_substream_chip(substream);
664 return init_engine(substream, hw_params, px_digital_out(chip) +
665 substream->number, params_channels(hw_params));
667 #endif /* !ECHOCARD_HAS_VMIXER */
669 #endif /* ECHOCARD_HAS_DIGITAL_IO */
673 static int pcm_hw_free(struct snd_pcm_substream *substream)
675 struct echoaudio *chip;
676 struct audiopipe *pipe;
678 chip = snd_pcm_substream_chip(substream);
679 pipe = (struct audiopipe *) substream->runtime->private_data;
681 spin_lock_irq(&chip->lock);
682 if (pipe->index >= 0) {
683 DE_HWP(("pcm_hw_free(%d)\n", pipe->index));
684 free_pipes(chip, pipe);
685 chip->substream[pipe->index] = NULL;
688 spin_unlock_irq(&chip->lock);
690 DE_HWP(("pcm_hw_freed\n"));
691 snd_pcm_lib_free_pages(substream);
697 static int pcm_prepare(struct snd_pcm_substream *substream)
699 struct echoaudio *chip = snd_pcm_substream_chip(substream);
700 struct snd_pcm_runtime *runtime = substream->runtime;
701 struct audioformat format;
702 int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
704 DE_HWP(("Prepare rate=%d format=%d channels=%d\n",
705 runtime->rate, runtime->format, runtime->channels));
706 format.interleave = runtime->channels;
707 format.data_are_bigendian = 0;
708 format.mono_to_stereo = 0;
709 switch (runtime->format) {
710 case SNDRV_PCM_FORMAT_U8:
711 format.bits_per_sample = 8;
713 case SNDRV_PCM_FORMAT_S16_LE:
714 format.bits_per_sample = 16;
716 case SNDRV_PCM_FORMAT_S24_3LE:
717 format.bits_per_sample = 24;
719 case SNDRV_PCM_FORMAT_S32_BE:
720 format.data_are_bigendian = 1;
721 case SNDRV_PCM_FORMAT_S32_LE:
722 format.bits_per_sample = 32;
725 DE_HWP(("Prepare error: unsupported format %d\n",
730 if (snd_BUG_ON(pipe_index >= px_num(chip)))
732 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
734 set_audio_format(chip, pipe_index, &format);
740 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
742 struct echoaudio *chip = snd_pcm_substream_chip(substream);
743 struct snd_pcm_runtime *runtime = substream->runtime;
744 struct audiopipe *pipe = runtime->private_data;
747 struct snd_pcm_substream *s;
749 snd_pcm_group_for_each_entry(s, substream) {
750 for (i = 0; i < DSP_MAXPIPES; i++) {
751 if (s == chip->substream[i]) {
752 channelmask |= 1 << i;
753 snd_pcm_trigger_done(s, substream);
758 spin_lock(&chip->lock);
760 case SNDRV_PCM_TRIGGER_RESUME:
761 DE_ACT(("pcm_trigger resume\n"));
762 case SNDRV_PCM_TRIGGER_START:
763 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
764 DE_ACT(("pcm_trigger start\n"));
765 for (i = 0; i < DSP_MAXPIPES; i++) {
766 if (channelmask & (1 << i)) {
767 pipe = chip->substream[i]->runtime->private_data;
768 switch (pipe->state) {
769 case PIPE_STATE_STOPPED:
770 chip->last_period[i] = 0;
771 pipe->last_counter = 0;
773 *pipe->dma_counter = 0;
774 case PIPE_STATE_PAUSED:
775 pipe->state = PIPE_STATE_STARTED;
777 case PIPE_STATE_STARTED:
782 err = start_transport(chip, channelmask,
783 chip->pipe_cyclic_mask);
785 case SNDRV_PCM_TRIGGER_SUSPEND:
786 DE_ACT(("pcm_trigger suspend\n"));
787 case SNDRV_PCM_TRIGGER_STOP:
788 DE_ACT(("pcm_trigger stop\n"));
789 for (i = 0; i < DSP_MAXPIPES; i++) {
790 if (channelmask & (1 << i)) {
791 pipe = chip->substream[i]->runtime->private_data;
792 pipe->state = PIPE_STATE_STOPPED;
795 err = stop_transport(chip, channelmask);
797 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
798 DE_ACT(("pcm_trigger pause\n"));
799 for (i = 0; i < DSP_MAXPIPES; i++) {
800 if (channelmask & (1 << i)) {
801 pipe = chip->substream[i]->runtime->private_data;
802 pipe->state = PIPE_STATE_PAUSED;
805 err = pause_transport(chip, channelmask);
810 spin_unlock(&chip->lock);
816 static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
818 struct snd_pcm_runtime *runtime = substream->runtime;
819 struct audiopipe *pipe = runtime->private_data;
820 size_t cnt, bufsize, pos;
822 cnt = le32_to_cpu(*pipe->dma_counter);
823 pipe->position += cnt - pipe->last_counter;
824 pipe->last_counter = cnt;
825 bufsize = substream->runtime->buffer_size;
826 pos = bytes_to_frames(substream->runtime, pipe->position);
828 while (pos >= bufsize) {
829 pipe->position -= frames_to_bytes(substream->runtime, bufsize);
837 /* pcm *_ops structures */
838 static struct snd_pcm_ops analog_playback_ops = {
839 .open = pcm_analog_out_open,
841 .ioctl = snd_pcm_lib_ioctl,
842 .hw_params = pcm_analog_out_hw_params,
843 .hw_free = pcm_hw_free,
844 .prepare = pcm_prepare,
845 .trigger = pcm_trigger,
846 .pointer = pcm_pointer,
847 .page = snd_pcm_sgbuf_ops_page,
849 static struct snd_pcm_ops analog_capture_ops = {
850 .open = pcm_analog_in_open,
852 .ioctl = snd_pcm_lib_ioctl,
853 .hw_params = pcm_analog_in_hw_params,
854 .hw_free = pcm_hw_free,
855 .prepare = pcm_prepare,
856 .trigger = pcm_trigger,
857 .pointer = pcm_pointer,
858 .page = snd_pcm_sgbuf_ops_page,
860 #ifdef ECHOCARD_HAS_DIGITAL_IO
861 #ifndef ECHOCARD_HAS_VMIXER
862 static struct snd_pcm_ops digital_playback_ops = {
863 .open = pcm_digital_out_open,
865 .ioctl = snd_pcm_lib_ioctl,
866 .hw_params = pcm_digital_out_hw_params,
867 .hw_free = pcm_hw_free,
868 .prepare = pcm_prepare,
869 .trigger = pcm_trigger,
870 .pointer = pcm_pointer,
871 .page = snd_pcm_sgbuf_ops_page,
873 #endif /* !ECHOCARD_HAS_VMIXER */
874 static struct snd_pcm_ops digital_capture_ops = {
875 .open = pcm_digital_in_open,
877 .ioctl = snd_pcm_lib_ioctl,
878 .hw_params = pcm_digital_in_hw_params,
879 .hw_free = pcm_hw_free,
880 .prepare = pcm_prepare,
881 .trigger = pcm_trigger,
882 .pointer = pcm_pointer,
883 .page = snd_pcm_sgbuf_ops_page,
885 #endif /* ECHOCARD_HAS_DIGITAL_IO */
889 /* Preallocate memory only for the first substream because it's the most
892 static int snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev)
894 struct snd_pcm_substream *ss;
897 for (stream = 0; stream < 2; stream++)
898 for (ss = pcm->streams[stream].substream; ss; ss = ss->next) {
899 err = snd_pcm_lib_preallocate_pages(ss, SNDRV_DMA_TYPE_DEV_SG,
901 ss->number ? 0 : 128<<10,
911 /*<--snd_echo_probe() */
912 static int snd_echo_new_pcm(struct echoaudio *chip)
917 #ifdef ECHOCARD_HAS_VMIXER
918 /* This card has a Vmixer, that is there is no direct mapping from PCM
919 streams to physical outputs. The user can mix the streams as he wishes
920 via control interface and it's possible to send any stream to any
921 output, thus it makes no sense to keep analog and digital outputs
924 /* PCM#0 Virtual outputs and analog inputs */
925 if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip),
926 num_analog_busses_in(chip), &pcm)) < 0)
928 pcm->private_data = chip;
929 chip->analog_pcm = pcm;
930 strcpy(pcm->name, chip->card->shortname);
931 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
932 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
933 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
935 DE_INIT(("Analog PCM ok\n"));
937 #ifdef ECHOCARD_HAS_DIGITAL_IO
938 /* PCM#1 Digital inputs, no outputs */
939 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0,
940 num_digital_busses_in(chip), &pcm)) < 0)
942 pcm->private_data = chip;
943 chip->digital_pcm = pcm;
944 strcpy(pcm->name, chip->card->shortname);
945 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
946 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
948 DE_INIT(("Digital PCM ok\n"));
949 #endif /* ECHOCARD_HAS_DIGITAL_IO */
951 #else /* ECHOCARD_HAS_VMIXER */
953 /* The card can manage substreams formed by analog and digital channels
954 at the same time, but I prefer to keep analog and digital channels
955 separated, because that mixed thing is confusing and useless. So we
956 register two PCM devices: */
958 /* PCM#0 Analog i/o */
959 if ((err = snd_pcm_new(chip->card, "Analog PCM", 0,
960 num_analog_busses_out(chip),
961 num_analog_busses_in(chip), &pcm)) < 0)
963 pcm->private_data = chip;
964 chip->analog_pcm = pcm;
965 strcpy(pcm->name, chip->card->shortname);
966 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
967 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
968 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
970 DE_INIT(("Analog PCM ok\n"));
972 #ifdef ECHOCARD_HAS_DIGITAL_IO
973 /* PCM#1 Digital i/o */
974 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1,
975 num_digital_busses_out(chip),
976 num_digital_busses_in(chip), &pcm)) < 0)
978 pcm->private_data = chip;
979 chip->digital_pcm = pcm;
980 strcpy(pcm->name, chip->card->shortname);
981 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops);
982 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
983 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
985 DE_INIT(("Digital PCM ok\n"));
986 #endif /* ECHOCARD_HAS_DIGITAL_IO */
988 #endif /* ECHOCARD_HAS_VMIXER */
996 /******************************************************************************
998 ******************************************************************************/
1000 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
1002 /******************* PCM output volume *******************/
1003 static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
1004 struct snd_ctl_elem_info *uinfo)
1006 struct echoaudio *chip;
1008 chip = snd_kcontrol_chip(kcontrol);
1009 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1010 uinfo->count = num_busses_out(chip);
1011 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1012 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1016 static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
1017 struct snd_ctl_elem_value *ucontrol)
1019 struct echoaudio *chip;
1022 chip = snd_kcontrol_chip(kcontrol);
1023 for (c = 0; c < num_busses_out(chip); c++)
1024 ucontrol->value.integer.value[c] = chip->output_gain[c];
1028 static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
1029 struct snd_ctl_elem_value *ucontrol)
1031 struct echoaudio *chip;
1032 int c, changed, gain;
1035 chip = snd_kcontrol_chip(kcontrol);
1036 spin_lock_irq(&chip->lock);
1037 for (c = 0; c < num_busses_out(chip); c++) {
1038 gain = ucontrol->value.integer.value[c];
1039 /* Ignore out of range values */
1040 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1042 if (chip->output_gain[c] != gain) {
1043 set_output_gain(chip, c, gain);
1048 update_output_line_level(chip);
1049 spin_unlock_irq(&chip->lock);
1053 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1054 /* On the Mia this one controls the line-out volume */
1055 static struct snd_kcontrol_new snd_echo_line_output_gain = {
1056 .name = "Line Playback Volume",
1057 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1058 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1059 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1060 .info = snd_echo_output_gain_info,
1061 .get = snd_echo_output_gain_get,
1062 .put = snd_echo_output_gain_put,
1063 .tlv = {.p = db_scale_output_gain},
1066 static struct snd_kcontrol_new snd_echo_pcm_output_gain = {
1067 .name = "PCM Playback Volume",
1068 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1069 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1070 .info = snd_echo_output_gain_info,
1071 .get = snd_echo_output_gain_get,
1072 .put = snd_echo_output_gain_put,
1073 .tlv = {.p = db_scale_output_gain},
1077 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1081 #ifdef ECHOCARD_HAS_INPUT_GAIN
1083 /******************* Analog input volume *******************/
1084 static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
1085 struct snd_ctl_elem_info *uinfo)
1087 struct echoaudio *chip;
1089 chip = snd_kcontrol_chip(kcontrol);
1090 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1091 uinfo->count = num_analog_busses_in(chip);
1092 uinfo->value.integer.min = ECHOGAIN_MININP;
1093 uinfo->value.integer.max = ECHOGAIN_MAXINP;
1097 static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
1098 struct snd_ctl_elem_value *ucontrol)
1100 struct echoaudio *chip;
1103 chip = snd_kcontrol_chip(kcontrol);
1104 for (c = 0; c < num_analog_busses_in(chip); c++)
1105 ucontrol->value.integer.value[c] = chip->input_gain[c];
1109 static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
1110 struct snd_ctl_elem_value *ucontrol)
1112 struct echoaudio *chip;
1113 int c, gain, changed;
1116 chip = snd_kcontrol_chip(kcontrol);
1117 spin_lock_irq(&chip->lock);
1118 for (c = 0; c < num_analog_busses_in(chip); c++) {
1119 gain = ucontrol->value.integer.value[c];
1120 /* Ignore out of range values */
1121 if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
1123 if (chip->input_gain[c] != gain) {
1124 set_input_gain(chip, c, gain);
1129 update_input_line_level(chip);
1130 spin_unlock_irq(&chip->lock);
1134 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain, -2500, 50, 0);
1136 static struct snd_kcontrol_new snd_echo_line_input_gain = {
1137 .name = "Line Capture Volume",
1138 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1139 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1140 .info = snd_echo_input_gain_info,
1141 .get = snd_echo_input_gain_get,
1142 .put = snd_echo_input_gain_put,
1143 .tlv = {.p = db_scale_input_gain},
1146 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1150 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1152 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1153 static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
1154 struct snd_ctl_elem_info *uinfo)
1156 struct echoaudio *chip;
1158 chip = snd_kcontrol_chip(kcontrol);
1159 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1160 uinfo->count = num_analog_busses_out(chip);
1161 uinfo->value.integer.min = 0;
1162 uinfo->value.integer.max = 1;
1166 static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
1167 struct snd_ctl_elem_value *ucontrol)
1169 struct echoaudio *chip;
1172 chip = snd_kcontrol_chip(kcontrol);
1173 for (c = 0; c < num_analog_busses_out(chip); c++)
1174 ucontrol->value.integer.value[c] = chip->nominal_level[c];
1178 static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
1179 struct snd_ctl_elem_value *ucontrol)
1181 struct echoaudio *chip;
1185 chip = snd_kcontrol_chip(kcontrol);
1186 spin_lock_irq(&chip->lock);
1187 for (c = 0; c < num_analog_busses_out(chip); c++) {
1188 if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
1189 set_nominal_level(chip, c,
1190 ucontrol->value.integer.value[c]);
1195 update_output_line_level(chip);
1196 spin_unlock_irq(&chip->lock);
1200 static struct snd_kcontrol_new snd_echo_output_nominal_level = {
1201 .name = "Line Playback Switch (-10dBV)",
1202 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1203 .info = snd_echo_output_nominal_info,
1204 .get = snd_echo_output_nominal_get,
1205 .put = snd_echo_output_nominal_put,
1208 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1212 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1214 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1215 static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
1216 struct snd_ctl_elem_info *uinfo)
1218 struct echoaudio *chip;
1220 chip = snd_kcontrol_chip(kcontrol);
1221 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1222 uinfo->count = num_analog_busses_in(chip);
1223 uinfo->value.integer.min = 0;
1224 uinfo->value.integer.max = 1;
1228 static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
1229 struct snd_ctl_elem_value *ucontrol)
1231 struct echoaudio *chip;
1234 chip = snd_kcontrol_chip(kcontrol);
1235 for (c = 0; c < num_analog_busses_in(chip); c++)
1236 ucontrol->value.integer.value[c] =
1237 chip->nominal_level[bx_analog_in(chip) + c];
1241 static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
1242 struct snd_ctl_elem_value *ucontrol)
1244 struct echoaudio *chip;
1248 chip = snd_kcontrol_chip(kcontrol);
1249 spin_lock_irq(&chip->lock);
1250 for (c = 0; c < num_analog_busses_in(chip); c++) {
1251 if (chip->nominal_level[bx_analog_in(chip) + c] !=
1252 ucontrol->value.integer.value[c]) {
1253 set_nominal_level(chip, bx_analog_in(chip) + c,
1254 ucontrol->value.integer.value[c]);
1259 update_output_line_level(chip); /* "Output" is not a mistake
1262 spin_unlock_irq(&chip->lock);
1266 static struct snd_kcontrol_new snd_echo_intput_nominal_level = {
1267 .name = "Line Capture Switch (-10dBV)",
1268 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1269 .info = snd_echo_input_nominal_info,
1270 .get = snd_echo_input_nominal_get,
1271 .put = snd_echo_input_nominal_put,
1274 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1278 #ifdef ECHOCARD_HAS_MONITOR
1280 /******************* Monitor mixer *******************/
1281 static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1282 struct snd_ctl_elem_info *uinfo)
1284 struct echoaudio *chip;
1286 chip = snd_kcontrol_chip(kcontrol);
1287 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1289 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1290 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1291 uinfo->dimen.d[0] = num_busses_out(chip);
1292 uinfo->dimen.d[1] = num_busses_in(chip);
1296 static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1297 struct snd_ctl_elem_value *ucontrol)
1299 struct echoaudio *chip;
1301 chip = snd_kcontrol_chip(kcontrol);
1302 ucontrol->value.integer.value[0] =
1303 chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)]
1304 [ucontrol->id.index % num_busses_in(chip)];
1308 static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1309 struct snd_ctl_elem_value *ucontrol)
1311 struct echoaudio *chip;
1316 chip = snd_kcontrol_chip(kcontrol);
1317 out = ucontrol->id.index / num_busses_in(chip);
1318 in = ucontrol->id.index % num_busses_in(chip);
1319 gain = ucontrol->value.integer.value[0];
1320 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1322 if (chip->monitor_gain[out][in] != gain) {
1323 spin_lock_irq(&chip->lock);
1324 set_monitor_gain(chip, out, in, gain);
1325 update_output_line_level(chip);
1326 spin_unlock_irq(&chip->lock);
1332 static struct snd_kcontrol_new snd_echo_monitor_mixer = {
1333 .name = "Monitor Mixer Volume",
1334 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1335 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1336 .info = snd_echo_mixer_info,
1337 .get = snd_echo_mixer_get,
1338 .put = snd_echo_mixer_put,
1339 .tlv = {.p = db_scale_output_gain},
1342 #endif /* ECHOCARD_HAS_MONITOR */
1346 #ifdef ECHOCARD_HAS_VMIXER
1348 /******************* Vmixer *******************/
1349 static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
1350 struct snd_ctl_elem_info *uinfo)
1352 struct echoaudio *chip;
1354 chip = snd_kcontrol_chip(kcontrol);
1355 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1357 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1358 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1359 uinfo->dimen.d[0] = num_busses_out(chip);
1360 uinfo->dimen.d[1] = num_pipes_out(chip);
1364 static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
1365 struct snd_ctl_elem_value *ucontrol)
1367 struct echoaudio *chip;
1369 chip = snd_kcontrol_chip(kcontrol);
1370 ucontrol->value.integer.value[0] =
1371 chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
1372 [ucontrol->id.index % num_pipes_out(chip)];
1376 static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
1377 struct snd_ctl_elem_value *ucontrol)
1379 struct echoaudio *chip;
1384 chip = snd_kcontrol_chip(kcontrol);
1385 out = ucontrol->id.index / num_pipes_out(chip);
1386 vch = ucontrol->id.index % num_pipes_out(chip);
1387 gain = ucontrol->value.integer.value[0];
1388 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1390 if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
1391 spin_lock_irq(&chip->lock);
1392 set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
1393 update_vmixer_level(chip);
1394 spin_unlock_irq(&chip->lock);
1400 static struct snd_kcontrol_new snd_echo_vmixer = {
1401 .name = "VMixer Volume",
1402 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1403 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1404 .info = snd_echo_vmixer_info,
1405 .get = snd_echo_vmixer_get,
1406 .put = snd_echo_vmixer_put,
1407 .tlv = {.p = db_scale_output_gain},
1410 #endif /* ECHOCARD_HAS_VMIXER */
1414 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1416 /******************* Digital mode switch *******************/
1417 static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1418 struct snd_ctl_elem_info *uinfo)
1420 static const char * const names[4] = {
1421 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1424 struct echoaudio *chip;
1426 chip = snd_kcontrol_chip(kcontrol);
1427 return snd_ctl_enum_info(uinfo, 1, chip->num_digital_modes, names);
1430 static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
1431 struct snd_ctl_elem_value *ucontrol)
1433 struct echoaudio *chip;
1436 chip = snd_kcontrol_chip(kcontrol);
1437 mode = chip->digital_mode;
1438 for (i = chip->num_digital_modes - 1; i >= 0; i--)
1439 if (mode == chip->digital_mode_list[i]) {
1440 ucontrol->value.enumerated.item[0] = i;
1446 static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1447 struct snd_ctl_elem_value *ucontrol)
1449 struct echoaudio *chip;
1451 unsigned short emode, dmode;
1454 chip = snd_kcontrol_chip(kcontrol);
1456 emode = ucontrol->value.enumerated.item[0];
1457 if (emode >= chip->num_digital_modes)
1459 dmode = chip->digital_mode_list[emode];
1461 if (dmode != chip->digital_mode) {
1462 /* mode_mutex is required to make this operation atomic wrt
1463 pcm_digital_*_open() and set_input_clock() functions. */
1464 mutex_lock(&chip->mode_mutex);
1466 /* Do not allow the user to change the digital mode when a pcm
1467 device is open because it also changes the number of channels
1468 and the allowed sample rates */
1469 if (atomic_read(&chip->opencount)) {
1472 changed = set_digital_mode(chip, dmode);
1473 /* If we had to change the clock source, report it */
1474 if (changed > 0 && chip->clock_src_ctl) {
1475 snd_ctl_notify(chip->card,
1476 SNDRV_CTL_EVENT_MASK_VALUE,
1477 &chip->clock_src_ctl->id);
1478 DE_ACT(("SDM() =%d\n", changed));
1481 changed = 1; /* No errors */
1483 mutex_unlock(&chip->mode_mutex);
1488 static struct snd_kcontrol_new snd_echo_digital_mode_switch = {
1489 .name = "Digital mode Switch",
1490 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1491 .info = snd_echo_digital_mode_info,
1492 .get = snd_echo_digital_mode_get,
1493 .put = snd_echo_digital_mode_put,
1496 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1500 #ifdef ECHOCARD_HAS_DIGITAL_IO
1502 /******************* S/PDIF mode switch *******************/
1503 static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1504 struct snd_ctl_elem_info *uinfo)
1506 static const char * const names[2] = {"Consumer", "Professional"};
1508 return snd_ctl_enum_info(uinfo, 1, 2, names);
1511 static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
1512 struct snd_ctl_elem_value *ucontrol)
1514 struct echoaudio *chip;
1516 chip = snd_kcontrol_chip(kcontrol);
1517 ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
1521 static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
1522 struct snd_ctl_elem_value *ucontrol)
1524 struct echoaudio *chip;
1527 chip = snd_kcontrol_chip(kcontrol);
1528 mode = !!ucontrol->value.enumerated.item[0];
1529 if (mode != chip->professional_spdif) {
1530 spin_lock_irq(&chip->lock);
1531 set_professional_spdif(chip, mode);
1532 spin_unlock_irq(&chip->lock);
1538 static struct snd_kcontrol_new snd_echo_spdif_mode_switch = {
1539 .name = "S/PDIF mode Switch",
1540 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1541 .info = snd_echo_spdif_mode_info,
1542 .get = snd_echo_spdif_mode_get,
1543 .put = snd_echo_spdif_mode_put,
1546 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1550 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1552 /******************* Select input clock source *******************/
1553 static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1554 struct snd_ctl_elem_info *uinfo)
1556 static const char * const names[8] = {
1557 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1560 struct echoaudio *chip;
1562 chip = snd_kcontrol_chip(kcontrol);
1563 return snd_ctl_enum_info(uinfo, 1, chip->num_clock_sources, names);
1566 static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
1567 struct snd_ctl_elem_value *ucontrol)
1569 struct echoaudio *chip;
1572 chip = snd_kcontrol_chip(kcontrol);
1573 clock = chip->input_clock;
1575 for (i = 0; i < chip->num_clock_sources; i++)
1576 if (clock == chip->clock_source_list[i])
1577 ucontrol->value.enumerated.item[0] = i;
1582 static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1583 struct snd_ctl_elem_value *ucontrol)
1585 struct echoaudio *chip;
1587 unsigned int eclock, dclock;
1590 chip = snd_kcontrol_chip(kcontrol);
1591 eclock = ucontrol->value.enumerated.item[0];
1592 if (eclock >= chip->input_clock_types)
1594 dclock = chip->clock_source_list[eclock];
1595 if (chip->input_clock != dclock) {
1596 mutex_lock(&chip->mode_mutex);
1597 spin_lock_irq(&chip->lock);
1598 if ((changed = set_input_clock(chip, dclock)) == 0)
1599 changed = 1; /* no errors */
1600 spin_unlock_irq(&chip->lock);
1601 mutex_unlock(&chip->mode_mutex);
1605 DE_ACT(("seticlk val%d err 0x%x\n", dclock, changed));
1610 static struct snd_kcontrol_new snd_echo_clock_source_switch = {
1611 .name = "Sample Clock Source",
1612 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1613 .info = snd_echo_clock_source_info,
1614 .get = snd_echo_clock_source_get,
1615 .put = snd_echo_clock_source_put,
1618 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1622 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1624 /******************* Phantom power switch *******************/
1625 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1627 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1628 struct snd_ctl_elem_value *ucontrol)
1630 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1632 ucontrol->value.integer.value[0] = chip->phantom_power;
1636 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *ucontrol)
1639 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1640 int power, changed = 0;
1642 power = !!ucontrol->value.integer.value[0];
1643 if (chip->phantom_power != power) {
1644 spin_lock_irq(&chip->lock);
1645 changed = set_phantom_power(chip, power);
1646 spin_unlock_irq(&chip->lock);
1648 changed = 1; /* no errors */
1653 static struct snd_kcontrol_new snd_echo_phantom_power_switch = {
1654 .name = "Phantom power Switch",
1655 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1656 .info = snd_echo_phantom_power_info,
1657 .get = snd_echo_phantom_power_get,
1658 .put = snd_echo_phantom_power_put,
1661 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1665 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1667 /******************* Digital input automute switch *******************/
1668 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1670 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1671 struct snd_ctl_elem_value *ucontrol)
1673 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1675 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1679 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1680 struct snd_ctl_elem_value *ucontrol)
1682 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1683 int automute, changed = 0;
1685 automute = !!ucontrol->value.integer.value[0];
1686 if (chip->digital_in_automute != automute) {
1687 spin_lock_irq(&chip->lock);
1688 changed = set_input_auto_mute(chip, automute);
1689 spin_unlock_irq(&chip->lock);
1691 changed = 1; /* no errors */
1696 static struct snd_kcontrol_new snd_echo_automute_switch = {
1697 .name = "Digital Capture Switch (automute)",
1698 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1699 .info = snd_echo_automute_info,
1700 .get = snd_echo_automute_get,
1701 .put = snd_echo_automute_put,
1704 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1708 /******************* VU-meters switch *******************/
1709 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1711 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1712 struct snd_ctl_elem_value *ucontrol)
1714 struct echoaudio *chip;
1716 chip = snd_kcontrol_chip(kcontrol);
1717 spin_lock_irq(&chip->lock);
1718 set_meters_on(chip, ucontrol->value.integer.value[0]);
1719 spin_unlock_irq(&chip->lock);
1723 static struct snd_kcontrol_new snd_echo_vumeters_switch = {
1724 .name = "VU-meters Switch",
1725 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1726 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1727 .info = snd_echo_vumeters_switch_info,
1728 .put = snd_echo_vumeters_switch_put,
1733 /***** Read VU-meters (input, output, analog and digital together) *****/
1734 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1735 struct snd_ctl_elem_info *uinfo)
1737 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1739 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1740 uinfo->value.integer.max = 0;
1741 #ifdef ECHOCARD_HAS_VMIXER
1742 uinfo->dimen.d[0] = 3; /* Out, In, Virt */
1744 uinfo->dimen.d[0] = 2; /* Out, In */
1746 uinfo->dimen.d[1] = 16; /* 16 channels */
1747 uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */
1751 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1752 struct snd_ctl_elem_value *ucontrol)
1754 struct echoaudio *chip;
1756 chip = snd_kcontrol_chip(kcontrol);
1757 get_audio_meters(chip, ucontrol->value.integer.value);
1761 static struct snd_kcontrol_new snd_echo_vumeters = {
1762 .name = "VU-meters",
1763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1764 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1765 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
1766 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1767 .info = snd_echo_vumeters_info,
1768 .get = snd_echo_vumeters_get,
1769 .tlv = {.p = db_scale_output_gain},
1774 /*** Channels info - it exports informations about the number of channels ***/
1775 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1776 struct snd_ctl_elem_info *uinfo)
1778 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1780 uinfo->value.integer.min = 0;
1781 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1785 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1786 struct snd_ctl_elem_value *ucontrol)
1788 struct echoaudio *chip;
1789 int detected, clocks, bit, src;
1791 chip = snd_kcontrol_chip(kcontrol);
1792 ucontrol->value.integer.value[0] = num_busses_in(chip);
1793 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1794 ucontrol->value.integer.value[2] = num_busses_out(chip);
1795 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1796 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1798 /* Compute the bitmask of the currently valid input clocks */
1799 detected = detect_input_clocks(chip);
1801 src = chip->num_clock_sources - 1;
1802 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1803 if (detected & (1 << bit))
1804 for (; src >= 0; src--)
1805 if (bit == chip->clock_source_list[src]) {
1809 ucontrol->value.integer.value[5] = clocks;
1814 static struct snd_kcontrol_new snd_echo_channels_info = {
1815 .name = "Channels info",
1816 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1817 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1818 .info = snd_echo_channels_info_info,
1819 .get = snd_echo_channels_info_get,
1825 /******************************************************************************
1827 ******************************************************************************/
1829 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1831 struct echoaudio *chip = dev_id;
1832 struct snd_pcm_substream *substream;
1835 spin_lock(&chip->lock);
1836 st = service_irq(chip);
1838 spin_unlock(&chip->lock);
1841 /* The hardware doesn't tell us which substream caused the irq,
1842 thus we have to check all running substreams. */
1843 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1844 substream = chip->substream[ss];
1845 if (substream && ((struct audiopipe *)substream->runtime->
1846 private_data)->state == PIPE_STATE_STARTED) {
1847 period = pcm_pointer(substream) /
1848 substream->runtime->period_size;
1849 if (period != chip->last_period[ss]) {
1850 chip->last_period[ss] = period;
1851 spin_unlock(&chip->lock);
1852 snd_pcm_period_elapsed(substream);
1853 spin_lock(&chip->lock);
1857 spin_unlock(&chip->lock);
1859 #ifdef ECHOCARD_HAS_MIDI
1860 if (st > 0 && chip->midi_in) {
1861 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1862 DE_MID(("rawmidi_iread=%d\n", st));
1871 /******************************************************************************
1872 Module construction / destruction
1873 ******************************************************************************/
1875 static int snd_echo_free(struct echoaudio *chip)
1877 DE_INIT(("Stop DSP...\n"));
1878 if (chip->comm_page)
1879 rest_in_peace(chip);
1880 DE_INIT(("Stopped.\n"));
1883 free_irq(chip->irq, chip);
1885 if (chip->comm_page)
1886 snd_dma_free_pages(&chip->commpage_dma_buf);
1888 if (chip->dsp_registers)
1889 iounmap(chip->dsp_registers);
1892 release_and_free_resource(chip->iores);
1894 DE_INIT(("MMIO freed.\n"));
1896 pci_disable_device(chip->pci);
1898 /* release chip data */
1899 free_firmware_cache(chip);
1901 DE_INIT(("Chip freed.\n"));
1907 static int snd_echo_dev_free(struct snd_device *device)
1909 struct echoaudio *chip = device->device_data;
1911 DE_INIT(("snd_echo_dev_free()...\n"));
1912 return snd_echo_free(chip);
1917 /* <--snd_echo_probe() */
1918 static int snd_echo_create(struct snd_card *card,
1919 struct pci_dev *pci,
1920 struct echoaudio **rchip)
1922 struct echoaudio *chip;
1925 static struct snd_device_ops ops = {
1926 .dev_free = snd_echo_dev_free,
1931 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1933 if ((err = pci_enable_device(pci)) < 0)
1935 pci_set_master(pci);
1937 /* Allocate chip if needed */
1939 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1941 pci_disable_device(pci);
1944 DE_INIT(("chip=%p\n", chip));
1945 spin_lock_init(&chip->lock);
1949 atomic_set(&chip->opencount, 0);
1950 mutex_init(&chip->mode_mutex);
1951 chip->can_set_rate = 1;
1953 /* If this was called from the resume function, chip is
1954 * already allocated and it contains current card settings.
1959 /* PCI resource allocation */
1960 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1961 sz = pci_resource_len(pci, 0);
1963 sz = PAGE_SIZE; /* We map only the required part */
1965 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1966 ECHOCARD_NAME)) == NULL) {
1967 dev_err(chip->card->dev, "cannot get memory region\n");
1968 snd_echo_free(chip);
1971 chip->dsp_registers = (volatile u32 __iomem *)
1972 ioremap_nocache(chip->dsp_registers_phys, sz);
1974 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1975 KBUILD_MODNAME, chip)) {
1976 dev_err(chip->card->dev, "cannot grab irq\n");
1977 snd_echo_free(chip);
1980 chip->irq = pci->irq;
1981 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n",
1982 chip->pci, chip->irq, chip->pci->subsystem_device));
1984 /* Create the DSP comm page - this is the area of memory used for most
1985 of the communication with the DSP, which accesses it via bus mastering */
1986 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1987 sizeof(struct comm_page),
1988 &chip->commpage_dma_buf) < 0) {
1989 dev_err(chip->card->dev, "cannot allocate the comm page\n");
1990 snd_echo_free(chip);
1993 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1994 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1996 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1998 err = set_mixer_defaults(chip);
2000 DE_INIT(("init_hw err=%d\n", err));
2001 snd_echo_free(chip);
2004 DE_INIT(("Card init OK\n"));
2006 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2007 snd_echo_free(chip);
2018 static int snd_echo_probe(struct pci_dev *pci,
2019 const struct pci_device_id *pci_id)
2022 struct snd_card *card;
2023 struct echoaudio *chip;
2027 if (dev >= SNDRV_CARDS)
2034 DE_INIT(("Echoaudio driver starting...\n"));
2036 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2041 chip = NULL; /* Tells snd_echo_create to allocate chip */
2042 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2043 snd_card_free(card);
2047 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
2048 strcpy(card->shortname, chip->card_name);
2051 if (pci_id->device == 0x3410)
2054 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2055 card->shortname, pci_id->subdevice & 0x000f, dsp,
2056 chip->dsp_registers_phys, chip->irq);
2058 if ((err = snd_echo_new_pcm(chip)) < 0) {
2059 dev_err(chip->card->dev, "new pcm error %d\n", err);
2060 snd_card_free(card);
2064 #ifdef ECHOCARD_HAS_MIDI
2065 if (chip->has_midi) { /* Some Mia's do not have midi */
2066 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2067 dev_err(chip->card->dev, "new midi error %d\n", err);
2068 snd_card_free(card);
2074 #ifdef ECHOCARD_HAS_VMIXER
2075 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2076 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2078 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2079 err = snd_ctl_add(chip->card,
2080 snd_ctl_new1(&snd_echo_line_output_gain, chip));
2084 #else /* ECHOCARD_HAS_VMIXER */
2085 err = snd_ctl_add(chip->card,
2086 snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
2089 #endif /* ECHOCARD_HAS_VMIXER */
2091 #ifdef ECHOCARD_HAS_INPUT_GAIN
2092 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2096 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2097 if (!chip->hasnt_input_nominal_level)
2098 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2102 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2103 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2107 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2110 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2113 #ifdef ECHOCARD_HAS_MONITOR
2114 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2115 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2119 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2120 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2124 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2127 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2128 /* Creates a list of available digital modes */
2129 chip->num_digital_modes = 0;
2130 for (i = 0; i < 6; i++)
2131 if (chip->digital_modes & (1 << i))
2132 chip->digital_mode_list[chip->num_digital_modes++] = i;
2134 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2136 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2138 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2139 /* Creates a list of available clock sources */
2140 chip->num_clock_sources = 0;
2141 for (i = 0; i < 10; i++)
2142 if (chip->input_clock_types & (1 << i))
2143 chip->clock_source_list[chip->num_clock_sources++] = i;
2145 if (chip->num_clock_sources > 1) {
2146 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2147 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2150 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2152 #ifdef ECHOCARD_HAS_DIGITAL_IO
2153 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2157 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2158 if (chip->has_phantom_power)
2159 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2163 err = snd_card_register(card);
2166 dev_info(card->dev, "Card registered: %s\n", card->longname);
2168 pci_set_drvdata(pci, chip);
2173 dev_err(card->dev, "new control error %d\n", err);
2174 snd_card_free(card);
2180 #if defined(CONFIG_PM_SLEEP)
2182 static int snd_echo_suspend(struct device *dev)
2184 struct pci_dev *pci = to_pci_dev(dev);
2185 struct echoaudio *chip = dev_get_drvdata(dev);
2187 DE_INIT(("suspend start\n"));
2188 snd_pcm_suspend_all(chip->analog_pcm);
2189 snd_pcm_suspend_all(chip->digital_pcm);
2191 #ifdef ECHOCARD_HAS_MIDI
2192 /* This call can sleep */
2194 snd_echo_midi_output_trigger(chip->midi_out, 0);
2196 spin_lock_irq(&chip->lock);
2197 if (wait_handshake(chip)) {
2198 spin_unlock_irq(&chip->lock);
2201 clear_handshake(chip);
2202 if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) {
2203 spin_unlock_irq(&chip->lock);
2206 spin_unlock_irq(&chip->lock);
2208 chip->dsp_code = NULL;
2209 free_irq(chip->irq, chip);
2211 pci_save_state(pci);
2212 pci_disable_device(pci);
2214 DE_INIT(("suspend done\n"));
2220 static int snd_echo_resume(struct device *dev)
2222 struct pci_dev *pci = to_pci_dev(dev);
2223 struct echoaudio *chip = dev_get_drvdata(dev);
2224 struct comm_page *commpage, *commpage_bak;
2225 u32 pipe_alloc_mask;
2228 DE_INIT(("resume start\n"));
2229 pci_restore_state(pci);
2230 commpage_bak = kmalloc(sizeof(struct echoaudio), GFP_KERNEL);
2231 if (commpage_bak == NULL)
2233 commpage = chip->comm_page;
2234 memcpy(commpage_bak, commpage, sizeof(struct comm_page));
2236 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
2238 kfree(commpage_bak);
2239 DE_INIT(("resume init_hw err=%d\n", err));
2240 snd_echo_free(chip);
2243 DE_INIT(("resume init OK\n"));
2245 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2246 * restore_dsp_settings() fails.
2248 pipe_alloc_mask = chip->pipe_alloc_mask;
2249 chip->pipe_alloc_mask = 0;
2250 err = restore_dsp_rettings(chip);
2251 chip->pipe_alloc_mask = pipe_alloc_mask;
2253 kfree(commpage_bak);
2256 DE_INIT(("resume restore OK\n"));
2258 memcpy(&commpage->audio_format, &commpage_bak->audio_format,
2259 sizeof(commpage->audio_format));
2260 memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr,
2261 sizeof(commpage->sglist_addr));
2262 memcpy(&commpage->midi_output, &commpage_bak->midi_output,
2263 sizeof(commpage->midi_output));
2264 kfree(commpage_bak);
2266 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
2267 KBUILD_MODNAME, chip)) {
2268 dev_err(chip->card->dev, "cannot grab irq\n");
2269 snd_echo_free(chip);
2272 chip->irq = pci->irq;
2273 DE_INIT(("resume irq=%d\n", chip->irq));
2275 #ifdef ECHOCARD_HAS_MIDI
2276 if (chip->midi_input_enabled)
2277 enable_midi_input(chip, TRUE);
2279 snd_echo_midi_output_trigger(chip->midi_out, 1);
2282 DE_INIT(("resume done\n"));
2286 static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume);
2287 #define SND_ECHO_PM_OPS &snd_echo_pm
2289 #define SND_ECHO_PM_OPS NULL
2290 #endif /* CONFIG_PM_SLEEP */
2293 static void snd_echo_remove(struct pci_dev *pci)
2295 struct echoaudio *chip;
2297 chip = pci_get_drvdata(pci);
2299 snd_card_free(chip->card);
2304 /******************************************************************************
2305 Everything starts and ends here
2306 ******************************************************************************/
2308 /* pci_driver definition */
2309 static struct pci_driver echo_driver = {
2310 .name = KBUILD_MODNAME,
2311 .id_table = snd_echo_ids,
2312 .probe = snd_echo_probe,
2313 .remove = snd_echo_remove,
2315 .pm = SND_ECHO_PM_OPS,
2319 module_pci_driver(echo_driver);