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)
74 #ifdef CONFIG_PM_SLEEP
75 DE_ACT(("firmware not released (kept in cache)\n"));
77 release_firmware(fw_entry);
78 DE_ACT(("firmware released\n"));
84 static void free_firmware_cache(struct echoaudio *chip)
86 #ifdef CONFIG_PM_SLEEP
89 for (i = 0; i < 8 ; i++)
90 if (chip->fw_cache[i]) {
91 release_firmware(chip->fw_cache[i]);
92 DE_ACT(("release_firmware(%d)\n", i));
95 DE_ACT(("firmware_cache released\n"));
101 /******************************************************************************
103 ******************************************************************************/
105 static void audiopipe_free(struct snd_pcm_runtime *runtime)
107 struct audiopipe *pipe = runtime->private_data;
109 if (pipe->sgpage.area)
110 snd_dma_free_pages(&pipe->sgpage);
116 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
117 struct snd_pcm_hw_rule *rule)
119 struct snd_interval *c = hw_param_interval(params,
120 SNDRV_PCM_HW_PARAM_CHANNELS);
121 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
126 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
127 /* >=2 channels cannot be S32_BE */
129 fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
130 return snd_mask_refine(f, &fmt);
133 /* > 2 channels cannot be U8 and S32_BE */
135 fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
136 return snd_mask_refine(f, &fmt);
138 /* Mono is ok with any format */
144 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
145 struct snd_pcm_hw_rule *rule)
147 struct snd_interval *c = hw_param_interval(params,
148 SNDRV_PCM_HW_PARAM_CHANNELS);
149 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
150 struct snd_interval ch;
152 snd_interval_any(&ch);
154 /* S32_BE is mono (and stereo) only */
155 if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
157 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
163 return snd_interval_refine(c, &ch);
165 /* U8 can be only mono or stereo */
166 if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
170 return snd_interval_refine(c, &ch);
172 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
178 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
179 struct snd_pcm_hw_rule *rule)
181 struct snd_interval *c = hw_param_interval(params,
182 SNDRV_PCM_HW_PARAM_CHANNELS);
183 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
188 fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
190 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
192 fmask &= SNDRV_PCM_FMTBIT_S16_LE |
193 SNDRV_PCM_FMTBIT_S24_3LE |
194 SNDRV_PCM_FMTBIT_S32_LE;
195 /* 1 channel must be S32_BE or S32_LE */
196 } else if (c->max == 1)
197 fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
198 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
199 /* 2 channels cannot be S32_BE */
200 else if (c->min == 2 && c->max == 2)
201 fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
206 fmt.bits[0] &= (u32)fmask;
207 fmt.bits[1] &= (u32)(fmask >> 32);
208 return snd_mask_refine(f, &fmt);
213 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
214 struct snd_pcm_hw_rule *rule)
216 struct snd_interval *c = hw_param_interval(params,
217 SNDRV_PCM_HW_PARAM_CHANNELS);
218 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
219 struct snd_interval ch;
222 snd_interval_any(&ch);
224 fmask = f->bits[0] + ((u64)f->bits[1] << 32);
226 /* S32_BE is mono (and stereo) only */
227 if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
229 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
234 /* U8 is stereo only */
235 } else if (fmask == SNDRV_PCM_FMTBIT_U8)
237 /* S16_LE and S24_3LE must be at least stereo */
238 else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
239 SNDRV_PCM_FMTBIT_S24_3LE)))
244 return snd_interval_refine(c, &ch);
249 /* Since the sample rate is a global setting, do allow the user to change the
250 sample rate only if there is only one pcm device open. */
251 static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
252 struct snd_pcm_hw_rule *rule)
254 struct snd_interval *rate = hw_param_interval(params,
255 SNDRV_PCM_HW_PARAM_RATE);
256 struct echoaudio *chip = rule->private;
257 struct snd_interval fixed;
259 if (!chip->can_set_rate) {
260 snd_interval_any(&fixed);
261 fixed.min = fixed.max = chip->sample_rate;
262 return snd_interval_refine(rate, &fixed);
268 static int pcm_open(struct snd_pcm_substream *substream,
269 signed char max_channels)
271 struct echoaudio *chip;
272 struct snd_pcm_runtime *runtime;
273 struct audiopipe *pipe;
276 if (max_channels <= 0)
279 chip = snd_pcm_substream_chip(substream);
280 runtime = substream->runtime;
282 pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
285 pipe->index = -1; /* Not configured yet */
287 /* Set up hw capabilities and contraints */
288 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
289 DE_HWP(("max_channels=%d\n", max_channels));
290 pipe->constr.list = channels_list;
291 pipe->constr.mask = 0;
292 for (i = 0; channels_list[i] <= max_channels; i++);
293 pipe->constr.count = i;
294 if (pipe->hw.channels_max > max_channels)
295 pipe->hw.channels_max = max_channels;
296 if (chip->digital_mode == DIGITAL_MODE_ADAT) {
297 pipe->hw.rate_max = 48000;
298 pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
301 runtime->hw = pipe->hw;
302 runtime->private_data = pipe;
303 runtime->private_free = audiopipe_free;
304 snd_pcm_set_sync(substream);
306 /* Only mono and any even number of channels are allowed */
307 if ((err = snd_pcm_hw_constraint_list(runtime, 0,
308 SNDRV_PCM_HW_PARAM_CHANNELS,
312 /* All periods should have the same size */
313 if ((err = snd_pcm_hw_constraint_integer(runtime,
314 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
317 /* The hw accesses memory in chunks 32 frames long and they should be
318 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
319 generated with a resolution of 32 frames. Thus we need the following */
320 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
321 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
324 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
325 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
329 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
330 SNDRV_PCM_HW_PARAM_RATE,
331 hw_rule_sample_rate, chip,
332 SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
335 /* Finally allocate a page for the scatter-gather list */
336 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
337 snd_dma_pci_data(chip->pci),
338 PAGE_SIZE, &pipe->sgpage)) < 0) {
339 DE_HWP(("s-g list allocation failed\n"));
348 static int pcm_analog_in_open(struct snd_pcm_substream *substream)
350 struct echoaudio *chip = snd_pcm_substream_chip(substream);
353 DE_ACT(("pcm_analog_in_open\n"));
354 if ((err = pcm_open(substream, num_analog_busses_in(chip) -
355 substream->number)) < 0)
357 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
358 SNDRV_PCM_HW_PARAM_CHANNELS,
359 hw_rule_capture_channels_by_format, NULL,
360 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
362 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
363 SNDRV_PCM_HW_PARAM_FORMAT,
364 hw_rule_capture_format_by_channels, NULL,
365 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
367 atomic_inc(&chip->opencount);
368 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
369 chip->can_set_rate=0;
370 DE_HWP(("pcm_analog_in_open cs=%d oc=%d r=%d\n",
371 chip->can_set_rate, atomic_read(&chip->opencount),
378 static int pcm_analog_out_open(struct snd_pcm_substream *substream)
380 struct echoaudio *chip = snd_pcm_substream_chip(substream);
381 int max_channels, err;
383 #ifdef ECHOCARD_HAS_VMIXER
384 max_channels = num_pipes_out(chip);
386 max_channels = num_analog_busses_out(chip);
388 DE_ACT(("pcm_analog_out_open\n"));
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 DE_HWP(("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 DE_ACT(("pcm_digital_in_open\n"));
422 max_channels = num_digital_busses_in(chip) - substream->number;
423 mutex_lock(&chip->mode_mutex);
424 if (chip->digital_mode == DIGITAL_MODE_ADAT)
425 err = pcm_open(substream, max_channels);
426 else /* If the card has ADAT, subtract the 6 channels
427 * that S/PDIF doesn't have
429 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
434 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
435 SNDRV_PCM_HW_PARAM_CHANNELS,
436 hw_rule_capture_channels_by_format, NULL,
437 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
439 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
440 SNDRV_PCM_HW_PARAM_FORMAT,
441 hw_rule_capture_format_by_channels, NULL,
442 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
445 atomic_inc(&chip->opencount);
446 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
447 chip->can_set_rate=0;
450 mutex_unlock(&chip->mode_mutex);
456 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
458 static int pcm_digital_out_open(struct snd_pcm_substream *substream)
460 struct echoaudio *chip = snd_pcm_substream_chip(substream);
461 int err, max_channels;
463 DE_ACT(("pcm_digital_out_open\n"));
464 max_channels = num_digital_busses_out(chip) - substream->number;
465 mutex_lock(&chip->mode_mutex);
466 if (chip->digital_mode == DIGITAL_MODE_ADAT)
467 err = pcm_open(substream, max_channels);
468 else /* If the card has ADAT, subtract the 6 channels
469 * that S/PDIF doesn't have
471 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
476 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
477 SNDRV_PCM_HW_PARAM_CHANNELS,
478 hw_rule_playback_channels_by_format,
479 NULL, SNDRV_PCM_HW_PARAM_FORMAT,
482 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
483 SNDRV_PCM_HW_PARAM_FORMAT,
484 hw_rule_playback_format_by_channels,
485 NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
488 atomic_inc(&chip->opencount);
489 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
490 chip->can_set_rate=0;
492 mutex_unlock(&chip->mode_mutex);
496 #endif /* !ECHOCARD_HAS_VMIXER */
498 #endif /* ECHOCARD_HAS_DIGITAL_IO */
502 static int pcm_close(struct snd_pcm_substream *substream)
504 struct echoaudio *chip = snd_pcm_substream_chip(substream);
507 /* Nothing to do here. Audio is already off and pipe will be
508 * freed by its callback
510 DE_ACT(("pcm_close\n"));
512 atomic_dec(&chip->opencount);
513 oc = atomic_read(&chip->opencount);
514 DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc,
515 chip->can_set_rate, chip->rate_set));
517 chip->can_set_rate = 1;
520 DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc,
521 chip->can_set_rate,chip->rate_set));
528 /* Channel allocation and scatter-gather list setup */
529 static int init_engine(struct snd_pcm_substream *substream,
530 struct snd_pcm_hw_params *hw_params,
531 int pipe_index, int interleave)
533 struct echoaudio *chip;
534 int err, per, rest, page, edge, offs;
535 struct audiopipe *pipe;
537 chip = snd_pcm_substream_chip(substream);
538 pipe = (struct audiopipe *) substream->runtime->private_data;
540 /* Sets up che hardware. If it's already initialized, reset and
541 * redo with the new parameters
543 spin_lock_irq(&chip->lock);
544 if (pipe->index >= 0) {
545 DE_HWP(("hwp_ie free(%d)\n", pipe->index));
546 err = free_pipes(chip, pipe);
548 chip->substream[pipe->index] = NULL;
551 err = allocate_pipes(chip, pipe, pipe_index, interleave);
553 spin_unlock_irq(&chip->lock);
554 DE_ACT((KERN_NOTICE "allocate_pipes(%d) err=%d\n",
558 spin_unlock_irq(&chip->lock);
559 DE_ACT((KERN_NOTICE "allocate_pipes()=%d\n", pipe_index));
561 DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
562 params_buffer_bytes(hw_params), params_periods(hw_params),
563 params_period_bytes(hw_params)));
564 err = snd_pcm_lib_malloc_pages(substream,
565 params_buffer_bytes(hw_params));
567 dev_err(chip->card->dev, "malloc_pages err=%d\n", err);
568 spin_lock_irq(&chip->lock);
569 free_pipes(chip, pipe);
570 spin_unlock_irq(&chip->lock);
575 sglist_init(chip, pipe);
577 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
579 rest = params_period_bytes(hw_params);
580 if (offs + rest > params_buffer_bytes(hw_params))
581 rest = params_buffer_bytes(hw_params) - offs;
584 addr = snd_pcm_sgbuf_get_addr(substream, offs);
585 if (rest <= edge - offs) {
586 sglist_add_mapping(chip, pipe, addr, rest);
587 sglist_add_irq(chip, pipe);
591 sglist_add_mapping(chip, pipe, addr,
603 /* Close the ring buffer */
604 sglist_wrap(chip, pipe);
606 /* This stuff is used by the irq handler, so it must be
607 * initialized before chip->substream
609 chip->last_period[pipe_index] = 0;
610 pipe->last_counter = 0;
613 chip->substream[pipe_index] = substream;
615 spin_lock_irq(&chip->lock);
616 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
617 spin_unlock_irq(&chip->lock);
618 DE_HWP(("pcm_hw_params ok\n"));
624 static int pcm_analog_in_hw_params(struct snd_pcm_substream *substream,
625 struct snd_pcm_hw_params *hw_params)
627 struct echoaudio *chip = snd_pcm_substream_chip(substream);
629 return init_engine(substream, hw_params, px_analog_in(chip) +
630 substream->number, params_channels(hw_params));
635 static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream,
636 struct snd_pcm_hw_params *hw_params)
638 return init_engine(substream, hw_params, substream->number,
639 params_channels(hw_params));
644 #ifdef ECHOCARD_HAS_DIGITAL_IO
646 static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream,
647 struct snd_pcm_hw_params *hw_params)
649 struct echoaudio *chip = snd_pcm_substream_chip(substream);
651 return init_engine(substream, hw_params, px_digital_in(chip) +
652 substream->number, params_channels(hw_params));
657 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
658 static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream,
659 struct snd_pcm_hw_params *hw_params)
661 struct echoaudio *chip = snd_pcm_substream_chip(substream);
663 return init_engine(substream, hw_params, px_digital_out(chip) +
664 substream->number, params_channels(hw_params));
666 #endif /* !ECHOCARD_HAS_VMIXER */
668 #endif /* ECHOCARD_HAS_DIGITAL_IO */
672 static int pcm_hw_free(struct snd_pcm_substream *substream)
674 struct echoaudio *chip;
675 struct audiopipe *pipe;
677 chip = snd_pcm_substream_chip(substream);
678 pipe = (struct audiopipe *) substream->runtime->private_data;
680 spin_lock_irq(&chip->lock);
681 if (pipe->index >= 0) {
682 DE_HWP(("pcm_hw_free(%d)\n", pipe->index));
683 free_pipes(chip, pipe);
684 chip->substream[pipe->index] = NULL;
687 spin_unlock_irq(&chip->lock);
689 DE_HWP(("pcm_hw_freed\n"));
690 snd_pcm_lib_free_pages(substream);
696 static int pcm_prepare(struct snd_pcm_substream *substream)
698 struct echoaudio *chip = snd_pcm_substream_chip(substream);
699 struct snd_pcm_runtime *runtime = substream->runtime;
700 struct audioformat format;
701 int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
703 DE_HWP(("Prepare rate=%d format=%d channels=%d\n",
704 runtime->rate, runtime->format, runtime->channels));
705 format.interleave = runtime->channels;
706 format.data_are_bigendian = 0;
707 format.mono_to_stereo = 0;
708 switch (runtime->format) {
709 case SNDRV_PCM_FORMAT_U8:
710 format.bits_per_sample = 8;
712 case SNDRV_PCM_FORMAT_S16_LE:
713 format.bits_per_sample = 16;
715 case SNDRV_PCM_FORMAT_S24_3LE:
716 format.bits_per_sample = 24;
718 case SNDRV_PCM_FORMAT_S32_BE:
719 format.data_are_bigendian = 1;
720 case SNDRV_PCM_FORMAT_S32_LE:
721 format.bits_per_sample = 32;
724 DE_HWP(("Prepare error: unsupported format %d\n",
729 if (snd_BUG_ON(pipe_index >= px_num(chip)))
731 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
733 set_audio_format(chip, pipe_index, &format);
739 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
741 struct echoaudio *chip = snd_pcm_substream_chip(substream);
742 struct snd_pcm_runtime *runtime = substream->runtime;
743 struct audiopipe *pipe = runtime->private_data;
746 struct snd_pcm_substream *s;
748 snd_pcm_group_for_each_entry(s, substream) {
749 for (i = 0; i < DSP_MAXPIPES; i++) {
750 if (s == chip->substream[i]) {
751 channelmask |= 1 << i;
752 snd_pcm_trigger_done(s, substream);
757 spin_lock(&chip->lock);
759 case SNDRV_PCM_TRIGGER_RESUME:
760 DE_ACT(("pcm_trigger resume\n"));
761 case SNDRV_PCM_TRIGGER_START:
762 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
763 DE_ACT(("pcm_trigger start\n"));
764 for (i = 0; i < DSP_MAXPIPES; i++) {
765 if (channelmask & (1 << i)) {
766 pipe = chip->substream[i]->runtime->private_data;
767 switch (pipe->state) {
768 case PIPE_STATE_STOPPED:
769 chip->last_period[i] = 0;
770 pipe->last_counter = 0;
772 *pipe->dma_counter = 0;
773 case PIPE_STATE_PAUSED:
774 pipe->state = PIPE_STATE_STARTED;
776 case PIPE_STATE_STARTED:
781 err = start_transport(chip, channelmask,
782 chip->pipe_cyclic_mask);
784 case SNDRV_PCM_TRIGGER_SUSPEND:
785 DE_ACT(("pcm_trigger suspend\n"));
786 case SNDRV_PCM_TRIGGER_STOP:
787 DE_ACT(("pcm_trigger stop\n"));
788 for (i = 0; i < DSP_MAXPIPES; i++) {
789 if (channelmask & (1 << i)) {
790 pipe = chip->substream[i]->runtime->private_data;
791 pipe->state = PIPE_STATE_STOPPED;
794 err = stop_transport(chip, channelmask);
796 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
797 DE_ACT(("pcm_trigger pause\n"));
798 for (i = 0; i < DSP_MAXPIPES; i++) {
799 if (channelmask & (1 << i)) {
800 pipe = chip->substream[i]->runtime->private_data;
801 pipe->state = PIPE_STATE_PAUSED;
804 err = pause_transport(chip, channelmask);
809 spin_unlock(&chip->lock);
815 static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
817 struct snd_pcm_runtime *runtime = substream->runtime;
818 struct audiopipe *pipe = runtime->private_data;
819 size_t cnt, bufsize, pos;
821 cnt = le32_to_cpu(*pipe->dma_counter);
822 pipe->position += cnt - pipe->last_counter;
823 pipe->last_counter = cnt;
824 bufsize = substream->runtime->buffer_size;
825 pos = bytes_to_frames(substream->runtime, pipe->position);
827 while (pos >= bufsize) {
828 pipe->position -= frames_to_bytes(substream->runtime, bufsize);
836 /* pcm *_ops structures */
837 static struct snd_pcm_ops analog_playback_ops = {
838 .open = pcm_analog_out_open,
840 .ioctl = snd_pcm_lib_ioctl,
841 .hw_params = pcm_analog_out_hw_params,
842 .hw_free = pcm_hw_free,
843 .prepare = pcm_prepare,
844 .trigger = pcm_trigger,
845 .pointer = pcm_pointer,
846 .page = snd_pcm_sgbuf_ops_page,
848 static struct snd_pcm_ops analog_capture_ops = {
849 .open = pcm_analog_in_open,
851 .ioctl = snd_pcm_lib_ioctl,
852 .hw_params = pcm_analog_in_hw_params,
853 .hw_free = pcm_hw_free,
854 .prepare = pcm_prepare,
855 .trigger = pcm_trigger,
856 .pointer = pcm_pointer,
857 .page = snd_pcm_sgbuf_ops_page,
859 #ifdef ECHOCARD_HAS_DIGITAL_IO
860 #ifndef ECHOCARD_HAS_VMIXER
861 static struct snd_pcm_ops digital_playback_ops = {
862 .open = pcm_digital_out_open,
864 .ioctl = snd_pcm_lib_ioctl,
865 .hw_params = pcm_digital_out_hw_params,
866 .hw_free = pcm_hw_free,
867 .prepare = pcm_prepare,
868 .trigger = pcm_trigger,
869 .pointer = pcm_pointer,
870 .page = snd_pcm_sgbuf_ops_page,
872 #endif /* !ECHOCARD_HAS_VMIXER */
873 static struct snd_pcm_ops digital_capture_ops = {
874 .open = pcm_digital_in_open,
876 .ioctl = snd_pcm_lib_ioctl,
877 .hw_params = pcm_digital_in_hw_params,
878 .hw_free = pcm_hw_free,
879 .prepare = pcm_prepare,
880 .trigger = pcm_trigger,
881 .pointer = pcm_pointer,
882 .page = snd_pcm_sgbuf_ops_page,
884 #endif /* ECHOCARD_HAS_DIGITAL_IO */
888 /* Preallocate memory only for the first substream because it's the most
891 static int snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev)
893 struct snd_pcm_substream *ss;
896 for (stream = 0; stream < 2; stream++)
897 for (ss = pcm->streams[stream].substream; ss; ss = ss->next) {
898 err = snd_pcm_lib_preallocate_pages(ss, SNDRV_DMA_TYPE_DEV_SG,
900 ss->number ? 0 : 128<<10,
910 /*<--snd_echo_probe() */
911 static int snd_echo_new_pcm(struct echoaudio *chip)
916 #ifdef ECHOCARD_HAS_VMIXER
917 /* This card has a Vmixer, that is there is no direct mapping from PCM
918 streams to physical outputs. The user can mix the streams as he wishes
919 via control interface and it's possible to send any stream to any
920 output, thus it makes no sense to keep analog and digital outputs
923 /* PCM#0 Virtual outputs and analog inputs */
924 if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip),
925 num_analog_busses_in(chip), &pcm)) < 0)
927 pcm->private_data = chip;
928 chip->analog_pcm = pcm;
929 strcpy(pcm->name, chip->card->shortname);
930 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
931 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
932 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
934 DE_INIT(("Analog PCM ok\n"));
936 #ifdef ECHOCARD_HAS_DIGITAL_IO
937 /* PCM#1 Digital inputs, no outputs */
938 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0,
939 num_digital_busses_in(chip), &pcm)) < 0)
941 pcm->private_data = chip;
942 chip->digital_pcm = pcm;
943 strcpy(pcm->name, chip->card->shortname);
944 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
945 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
947 DE_INIT(("Digital PCM ok\n"));
948 #endif /* ECHOCARD_HAS_DIGITAL_IO */
950 #else /* ECHOCARD_HAS_VMIXER */
952 /* The card can manage substreams formed by analog and digital channels
953 at the same time, but I prefer to keep analog and digital channels
954 separated, because that mixed thing is confusing and useless. So we
955 register two PCM devices: */
957 /* PCM#0 Analog i/o */
958 if ((err = snd_pcm_new(chip->card, "Analog PCM", 0,
959 num_analog_busses_out(chip),
960 num_analog_busses_in(chip), &pcm)) < 0)
962 pcm->private_data = chip;
963 chip->analog_pcm = pcm;
964 strcpy(pcm->name, chip->card->shortname);
965 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
966 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
967 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
969 DE_INIT(("Analog PCM ok\n"));
971 #ifdef ECHOCARD_HAS_DIGITAL_IO
972 /* PCM#1 Digital i/o */
973 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1,
974 num_digital_busses_out(chip),
975 num_digital_busses_in(chip), &pcm)) < 0)
977 pcm->private_data = chip;
978 chip->digital_pcm = pcm;
979 strcpy(pcm->name, chip->card->shortname);
980 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops);
981 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
982 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
984 DE_INIT(("Digital PCM ok\n"));
985 #endif /* ECHOCARD_HAS_DIGITAL_IO */
987 #endif /* ECHOCARD_HAS_VMIXER */
995 /******************************************************************************
997 ******************************************************************************/
999 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
1001 /******************* PCM output volume *******************/
1002 static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
1003 struct snd_ctl_elem_info *uinfo)
1005 struct echoaudio *chip;
1007 chip = snd_kcontrol_chip(kcontrol);
1008 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1009 uinfo->count = num_busses_out(chip);
1010 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1011 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1015 static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
1016 struct snd_ctl_elem_value *ucontrol)
1018 struct echoaudio *chip;
1021 chip = snd_kcontrol_chip(kcontrol);
1022 for (c = 0; c < num_busses_out(chip); c++)
1023 ucontrol->value.integer.value[c] = chip->output_gain[c];
1027 static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
1028 struct snd_ctl_elem_value *ucontrol)
1030 struct echoaudio *chip;
1031 int c, changed, gain;
1034 chip = snd_kcontrol_chip(kcontrol);
1035 spin_lock_irq(&chip->lock);
1036 for (c = 0; c < num_busses_out(chip); c++) {
1037 gain = ucontrol->value.integer.value[c];
1038 /* Ignore out of range values */
1039 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1041 if (chip->output_gain[c] != gain) {
1042 set_output_gain(chip, c, gain);
1047 update_output_line_level(chip);
1048 spin_unlock_irq(&chip->lock);
1052 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1053 /* On the Mia this one controls the line-out volume */
1054 static struct snd_kcontrol_new snd_echo_line_output_gain = {
1055 .name = "Line Playback Volume",
1056 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1057 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1058 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1059 .info = snd_echo_output_gain_info,
1060 .get = snd_echo_output_gain_get,
1061 .put = snd_echo_output_gain_put,
1062 .tlv = {.p = db_scale_output_gain},
1065 static struct snd_kcontrol_new snd_echo_pcm_output_gain = {
1066 .name = "PCM Playback Volume",
1067 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1068 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1069 .info = snd_echo_output_gain_info,
1070 .get = snd_echo_output_gain_get,
1071 .put = snd_echo_output_gain_put,
1072 .tlv = {.p = db_scale_output_gain},
1076 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1080 #ifdef ECHOCARD_HAS_INPUT_GAIN
1082 /******************* Analog input volume *******************/
1083 static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
1084 struct snd_ctl_elem_info *uinfo)
1086 struct echoaudio *chip;
1088 chip = snd_kcontrol_chip(kcontrol);
1089 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1090 uinfo->count = num_analog_busses_in(chip);
1091 uinfo->value.integer.min = ECHOGAIN_MININP;
1092 uinfo->value.integer.max = ECHOGAIN_MAXINP;
1096 static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
1097 struct snd_ctl_elem_value *ucontrol)
1099 struct echoaudio *chip;
1102 chip = snd_kcontrol_chip(kcontrol);
1103 for (c = 0; c < num_analog_busses_in(chip); c++)
1104 ucontrol->value.integer.value[c] = chip->input_gain[c];
1108 static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
1109 struct snd_ctl_elem_value *ucontrol)
1111 struct echoaudio *chip;
1112 int c, gain, changed;
1115 chip = snd_kcontrol_chip(kcontrol);
1116 spin_lock_irq(&chip->lock);
1117 for (c = 0; c < num_analog_busses_in(chip); c++) {
1118 gain = ucontrol->value.integer.value[c];
1119 /* Ignore out of range values */
1120 if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
1122 if (chip->input_gain[c] != gain) {
1123 set_input_gain(chip, c, gain);
1128 update_input_line_level(chip);
1129 spin_unlock_irq(&chip->lock);
1133 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain, -2500, 50, 0);
1135 static struct snd_kcontrol_new snd_echo_line_input_gain = {
1136 .name = "Line Capture Volume",
1137 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1138 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1139 .info = snd_echo_input_gain_info,
1140 .get = snd_echo_input_gain_get,
1141 .put = snd_echo_input_gain_put,
1142 .tlv = {.p = db_scale_input_gain},
1145 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1149 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1151 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1152 static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
1153 struct snd_ctl_elem_info *uinfo)
1155 struct echoaudio *chip;
1157 chip = snd_kcontrol_chip(kcontrol);
1158 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1159 uinfo->count = num_analog_busses_out(chip);
1160 uinfo->value.integer.min = 0;
1161 uinfo->value.integer.max = 1;
1165 static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
1166 struct snd_ctl_elem_value *ucontrol)
1168 struct echoaudio *chip;
1171 chip = snd_kcontrol_chip(kcontrol);
1172 for (c = 0; c < num_analog_busses_out(chip); c++)
1173 ucontrol->value.integer.value[c] = chip->nominal_level[c];
1177 static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
1178 struct snd_ctl_elem_value *ucontrol)
1180 struct echoaudio *chip;
1184 chip = snd_kcontrol_chip(kcontrol);
1185 spin_lock_irq(&chip->lock);
1186 for (c = 0; c < num_analog_busses_out(chip); c++) {
1187 if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
1188 set_nominal_level(chip, c,
1189 ucontrol->value.integer.value[c]);
1194 update_output_line_level(chip);
1195 spin_unlock_irq(&chip->lock);
1199 static struct snd_kcontrol_new snd_echo_output_nominal_level = {
1200 .name = "Line Playback Switch (-10dBV)",
1201 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1202 .info = snd_echo_output_nominal_info,
1203 .get = snd_echo_output_nominal_get,
1204 .put = snd_echo_output_nominal_put,
1207 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1211 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1213 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1214 static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
1215 struct snd_ctl_elem_info *uinfo)
1217 struct echoaudio *chip;
1219 chip = snd_kcontrol_chip(kcontrol);
1220 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1221 uinfo->count = num_analog_busses_in(chip);
1222 uinfo->value.integer.min = 0;
1223 uinfo->value.integer.max = 1;
1227 static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
1228 struct snd_ctl_elem_value *ucontrol)
1230 struct echoaudio *chip;
1233 chip = snd_kcontrol_chip(kcontrol);
1234 for (c = 0; c < num_analog_busses_in(chip); c++)
1235 ucontrol->value.integer.value[c] =
1236 chip->nominal_level[bx_analog_in(chip) + c];
1240 static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
1241 struct snd_ctl_elem_value *ucontrol)
1243 struct echoaudio *chip;
1247 chip = snd_kcontrol_chip(kcontrol);
1248 spin_lock_irq(&chip->lock);
1249 for (c = 0; c < num_analog_busses_in(chip); c++) {
1250 if (chip->nominal_level[bx_analog_in(chip) + c] !=
1251 ucontrol->value.integer.value[c]) {
1252 set_nominal_level(chip, bx_analog_in(chip) + c,
1253 ucontrol->value.integer.value[c]);
1258 update_output_line_level(chip); /* "Output" is not a mistake
1261 spin_unlock_irq(&chip->lock);
1265 static struct snd_kcontrol_new snd_echo_intput_nominal_level = {
1266 .name = "Line Capture Switch (-10dBV)",
1267 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1268 .info = snd_echo_input_nominal_info,
1269 .get = snd_echo_input_nominal_get,
1270 .put = snd_echo_input_nominal_put,
1273 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1277 #ifdef ECHOCARD_HAS_MONITOR
1279 /******************* Monitor mixer *******************/
1280 static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1281 struct snd_ctl_elem_info *uinfo)
1283 struct echoaudio *chip;
1285 chip = snd_kcontrol_chip(kcontrol);
1286 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1288 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1289 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1290 uinfo->dimen.d[0] = num_busses_out(chip);
1291 uinfo->dimen.d[1] = num_busses_in(chip);
1295 static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1296 struct snd_ctl_elem_value *ucontrol)
1298 struct echoaudio *chip;
1300 chip = snd_kcontrol_chip(kcontrol);
1301 ucontrol->value.integer.value[0] =
1302 chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)]
1303 [ucontrol->id.index % num_busses_in(chip)];
1307 static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1308 struct snd_ctl_elem_value *ucontrol)
1310 struct echoaudio *chip;
1315 chip = snd_kcontrol_chip(kcontrol);
1316 out = ucontrol->id.index / num_busses_in(chip);
1317 in = ucontrol->id.index % num_busses_in(chip);
1318 gain = ucontrol->value.integer.value[0];
1319 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1321 if (chip->monitor_gain[out][in] != gain) {
1322 spin_lock_irq(&chip->lock);
1323 set_monitor_gain(chip, out, in, gain);
1324 update_output_line_level(chip);
1325 spin_unlock_irq(&chip->lock);
1331 static struct snd_kcontrol_new snd_echo_monitor_mixer = {
1332 .name = "Monitor Mixer Volume",
1333 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1334 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1335 .info = snd_echo_mixer_info,
1336 .get = snd_echo_mixer_get,
1337 .put = snd_echo_mixer_put,
1338 .tlv = {.p = db_scale_output_gain},
1341 #endif /* ECHOCARD_HAS_MONITOR */
1345 #ifdef ECHOCARD_HAS_VMIXER
1347 /******************* Vmixer *******************/
1348 static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
1349 struct snd_ctl_elem_info *uinfo)
1351 struct echoaudio *chip;
1353 chip = snd_kcontrol_chip(kcontrol);
1354 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1356 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1357 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1358 uinfo->dimen.d[0] = num_busses_out(chip);
1359 uinfo->dimen.d[1] = num_pipes_out(chip);
1363 static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
1364 struct snd_ctl_elem_value *ucontrol)
1366 struct echoaudio *chip;
1368 chip = snd_kcontrol_chip(kcontrol);
1369 ucontrol->value.integer.value[0] =
1370 chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
1371 [ucontrol->id.index % num_pipes_out(chip)];
1375 static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
1376 struct snd_ctl_elem_value *ucontrol)
1378 struct echoaudio *chip;
1383 chip = snd_kcontrol_chip(kcontrol);
1384 out = ucontrol->id.index / num_pipes_out(chip);
1385 vch = ucontrol->id.index % num_pipes_out(chip);
1386 gain = ucontrol->value.integer.value[0];
1387 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1389 if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
1390 spin_lock_irq(&chip->lock);
1391 set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
1392 update_vmixer_level(chip);
1393 spin_unlock_irq(&chip->lock);
1399 static struct snd_kcontrol_new snd_echo_vmixer = {
1400 .name = "VMixer Volume",
1401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1402 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1403 .info = snd_echo_vmixer_info,
1404 .get = snd_echo_vmixer_get,
1405 .put = snd_echo_vmixer_put,
1406 .tlv = {.p = db_scale_output_gain},
1409 #endif /* ECHOCARD_HAS_VMIXER */
1413 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1415 /******************* Digital mode switch *******************/
1416 static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1417 struct snd_ctl_elem_info *uinfo)
1419 static const char * const names[4] = {
1420 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1423 struct echoaudio *chip;
1425 chip = snd_kcontrol_chip(kcontrol);
1426 return snd_ctl_enum_info(uinfo, 1, chip->num_digital_modes, names);
1429 static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
1430 struct snd_ctl_elem_value *ucontrol)
1432 struct echoaudio *chip;
1435 chip = snd_kcontrol_chip(kcontrol);
1436 mode = chip->digital_mode;
1437 for (i = chip->num_digital_modes - 1; i >= 0; i--)
1438 if (mode == chip->digital_mode_list[i]) {
1439 ucontrol->value.enumerated.item[0] = i;
1445 static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1446 struct snd_ctl_elem_value *ucontrol)
1448 struct echoaudio *chip;
1450 unsigned short emode, dmode;
1453 chip = snd_kcontrol_chip(kcontrol);
1455 emode = ucontrol->value.enumerated.item[0];
1456 if (emode >= chip->num_digital_modes)
1458 dmode = chip->digital_mode_list[emode];
1460 if (dmode != chip->digital_mode) {
1461 /* mode_mutex is required to make this operation atomic wrt
1462 pcm_digital_*_open() and set_input_clock() functions. */
1463 mutex_lock(&chip->mode_mutex);
1465 /* Do not allow the user to change the digital mode when a pcm
1466 device is open because it also changes the number of channels
1467 and the allowed sample rates */
1468 if (atomic_read(&chip->opencount)) {
1471 changed = set_digital_mode(chip, dmode);
1472 /* If we had to change the clock source, report it */
1473 if (changed > 0 && chip->clock_src_ctl) {
1474 snd_ctl_notify(chip->card,
1475 SNDRV_CTL_EVENT_MASK_VALUE,
1476 &chip->clock_src_ctl->id);
1477 DE_ACT(("SDM() =%d\n", changed));
1480 changed = 1; /* No errors */
1482 mutex_unlock(&chip->mode_mutex);
1487 static struct snd_kcontrol_new snd_echo_digital_mode_switch = {
1488 .name = "Digital mode Switch",
1489 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1490 .info = snd_echo_digital_mode_info,
1491 .get = snd_echo_digital_mode_get,
1492 .put = snd_echo_digital_mode_put,
1495 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1499 #ifdef ECHOCARD_HAS_DIGITAL_IO
1501 /******************* S/PDIF mode switch *******************/
1502 static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1503 struct snd_ctl_elem_info *uinfo)
1505 static const char * const names[2] = {"Consumer", "Professional"};
1507 return snd_ctl_enum_info(uinfo, 1, 2, names);
1510 static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
1511 struct snd_ctl_elem_value *ucontrol)
1513 struct echoaudio *chip;
1515 chip = snd_kcontrol_chip(kcontrol);
1516 ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
1520 static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
1521 struct snd_ctl_elem_value *ucontrol)
1523 struct echoaudio *chip;
1526 chip = snd_kcontrol_chip(kcontrol);
1527 mode = !!ucontrol->value.enumerated.item[0];
1528 if (mode != chip->professional_spdif) {
1529 spin_lock_irq(&chip->lock);
1530 set_professional_spdif(chip, mode);
1531 spin_unlock_irq(&chip->lock);
1537 static struct snd_kcontrol_new snd_echo_spdif_mode_switch = {
1538 .name = "S/PDIF mode Switch",
1539 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1540 .info = snd_echo_spdif_mode_info,
1541 .get = snd_echo_spdif_mode_get,
1542 .put = snd_echo_spdif_mode_put,
1545 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1549 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1551 /******************* Select input clock source *******************/
1552 static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1553 struct snd_ctl_elem_info *uinfo)
1555 static const char * const names[8] = {
1556 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1559 struct echoaudio *chip;
1561 chip = snd_kcontrol_chip(kcontrol);
1562 return snd_ctl_enum_info(uinfo, 1, chip->num_clock_sources, names);
1565 static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
1566 struct snd_ctl_elem_value *ucontrol)
1568 struct echoaudio *chip;
1571 chip = snd_kcontrol_chip(kcontrol);
1572 clock = chip->input_clock;
1574 for (i = 0; i < chip->num_clock_sources; i++)
1575 if (clock == chip->clock_source_list[i])
1576 ucontrol->value.enumerated.item[0] = i;
1581 static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1582 struct snd_ctl_elem_value *ucontrol)
1584 struct echoaudio *chip;
1586 unsigned int eclock, dclock;
1589 chip = snd_kcontrol_chip(kcontrol);
1590 eclock = ucontrol->value.enumerated.item[0];
1591 if (eclock >= chip->input_clock_types)
1593 dclock = chip->clock_source_list[eclock];
1594 if (chip->input_clock != dclock) {
1595 mutex_lock(&chip->mode_mutex);
1596 spin_lock_irq(&chip->lock);
1597 if ((changed = set_input_clock(chip, dclock)) == 0)
1598 changed = 1; /* no errors */
1599 spin_unlock_irq(&chip->lock);
1600 mutex_unlock(&chip->mode_mutex);
1604 DE_ACT(("seticlk val%d err 0x%x\n", dclock, changed));
1609 static struct snd_kcontrol_new snd_echo_clock_source_switch = {
1610 .name = "Sample Clock Source",
1611 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1612 .info = snd_echo_clock_source_info,
1613 .get = snd_echo_clock_source_get,
1614 .put = snd_echo_clock_source_put,
1617 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1621 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1623 /******************* Phantom power switch *******************/
1624 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1626 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1627 struct snd_ctl_elem_value *ucontrol)
1629 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1631 ucontrol->value.integer.value[0] = chip->phantom_power;
1635 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1636 struct snd_ctl_elem_value *ucontrol)
1638 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1639 int power, changed = 0;
1641 power = !!ucontrol->value.integer.value[0];
1642 if (chip->phantom_power != power) {
1643 spin_lock_irq(&chip->lock);
1644 changed = set_phantom_power(chip, power);
1645 spin_unlock_irq(&chip->lock);
1647 changed = 1; /* no errors */
1652 static struct snd_kcontrol_new snd_echo_phantom_power_switch = {
1653 .name = "Phantom power Switch",
1654 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1655 .info = snd_echo_phantom_power_info,
1656 .get = snd_echo_phantom_power_get,
1657 .put = snd_echo_phantom_power_put,
1660 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1664 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1666 /******************* Digital input automute switch *******************/
1667 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1669 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1670 struct snd_ctl_elem_value *ucontrol)
1672 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1674 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1678 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1679 struct snd_ctl_elem_value *ucontrol)
1681 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1682 int automute, changed = 0;
1684 automute = !!ucontrol->value.integer.value[0];
1685 if (chip->digital_in_automute != automute) {
1686 spin_lock_irq(&chip->lock);
1687 changed = set_input_auto_mute(chip, automute);
1688 spin_unlock_irq(&chip->lock);
1690 changed = 1; /* no errors */
1695 static struct snd_kcontrol_new snd_echo_automute_switch = {
1696 .name = "Digital Capture Switch (automute)",
1697 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1698 .info = snd_echo_automute_info,
1699 .get = snd_echo_automute_get,
1700 .put = snd_echo_automute_put,
1703 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1707 /******************* VU-meters switch *******************/
1708 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1710 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1711 struct snd_ctl_elem_value *ucontrol)
1713 struct echoaudio *chip;
1715 chip = snd_kcontrol_chip(kcontrol);
1716 spin_lock_irq(&chip->lock);
1717 set_meters_on(chip, ucontrol->value.integer.value[0]);
1718 spin_unlock_irq(&chip->lock);
1722 static struct snd_kcontrol_new snd_echo_vumeters_switch = {
1723 .name = "VU-meters Switch",
1724 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1725 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1726 .info = snd_echo_vumeters_switch_info,
1727 .put = snd_echo_vumeters_switch_put,
1732 /***** Read VU-meters (input, output, analog and digital together) *****/
1733 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1734 struct snd_ctl_elem_info *uinfo)
1736 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1738 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1739 uinfo->value.integer.max = 0;
1740 #ifdef ECHOCARD_HAS_VMIXER
1741 uinfo->dimen.d[0] = 3; /* Out, In, Virt */
1743 uinfo->dimen.d[0] = 2; /* Out, In */
1745 uinfo->dimen.d[1] = 16; /* 16 channels */
1746 uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */
1750 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol)
1753 struct echoaudio *chip;
1755 chip = snd_kcontrol_chip(kcontrol);
1756 get_audio_meters(chip, ucontrol->value.integer.value);
1760 static struct snd_kcontrol_new snd_echo_vumeters = {
1761 .name = "VU-meters",
1762 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1763 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1764 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
1765 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1766 .info = snd_echo_vumeters_info,
1767 .get = snd_echo_vumeters_get,
1768 .tlv = {.p = db_scale_output_gain},
1773 /*** Channels info - it exports informations about the number of channels ***/
1774 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1775 struct snd_ctl_elem_info *uinfo)
1777 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1779 uinfo->value.integer.min = 0;
1780 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1784 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1785 struct snd_ctl_elem_value *ucontrol)
1787 struct echoaudio *chip;
1788 int detected, clocks, bit, src;
1790 chip = snd_kcontrol_chip(kcontrol);
1791 ucontrol->value.integer.value[0] = num_busses_in(chip);
1792 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1793 ucontrol->value.integer.value[2] = num_busses_out(chip);
1794 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1795 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1797 /* Compute the bitmask of the currently valid input clocks */
1798 detected = detect_input_clocks(chip);
1800 src = chip->num_clock_sources - 1;
1801 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1802 if (detected & (1 << bit))
1803 for (; src >= 0; src--)
1804 if (bit == chip->clock_source_list[src]) {
1808 ucontrol->value.integer.value[5] = clocks;
1813 static struct snd_kcontrol_new snd_echo_channels_info = {
1814 .name = "Channels info",
1815 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1816 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1817 .info = snd_echo_channels_info_info,
1818 .get = snd_echo_channels_info_get,
1824 /******************************************************************************
1826 ******************************************************************************/
1828 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1830 struct echoaudio *chip = dev_id;
1831 struct snd_pcm_substream *substream;
1834 spin_lock(&chip->lock);
1835 st = service_irq(chip);
1837 spin_unlock(&chip->lock);
1840 /* The hardware doesn't tell us which substream caused the irq,
1841 thus we have to check all running substreams. */
1842 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1843 substream = chip->substream[ss];
1844 if (substream && ((struct audiopipe *)substream->runtime->
1845 private_data)->state == PIPE_STATE_STARTED) {
1846 period = pcm_pointer(substream) /
1847 substream->runtime->period_size;
1848 if (period != chip->last_period[ss]) {
1849 chip->last_period[ss] = period;
1850 spin_unlock(&chip->lock);
1851 snd_pcm_period_elapsed(substream);
1852 spin_lock(&chip->lock);
1856 spin_unlock(&chip->lock);
1858 #ifdef ECHOCARD_HAS_MIDI
1859 if (st > 0 && chip->midi_in) {
1860 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1861 DE_MID(("rawmidi_iread=%d\n", st));
1870 /******************************************************************************
1871 Module construction / destruction
1872 ******************************************************************************/
1874 static int snd_echo_free(struct echoaudio *chip)
1876 DE_INIT(("Stop DSP...\n"));
1877 if (chip->comm_page)
1878 rest_in_peace(chip);
1879 DE_INIT(("Stopped.\n"));
1882 free_irq(chip->irq, chip);
1884 if (chip->comm_page)
1885 snd_dma_free_pages(&chip->commpage_dma_buf);
1887 if (chip->dsp_registers)
1888 iounmap(chip->dsp_registers);
1891 release_and_free_resource(chip->iores);
1893 DE_INIT(("MMIO freed.\n"));
1895 pci_disable_device(chip->pci);
1897 /* release chip data */
1898 free_firmware_cache(chip);
1900 DE_INIT(("Chip freed.\n"));
1906 static int snd_echo_dev_free(struct snd_device *device)
1908 struct echoaudio *chip = device->device_data;
1910 DE_INIT(("snd_echo_dev_free()...\n"));
1911 return snd_echo_free(chip);
1916 /* <--snd_echo_probe() */
1917 static int snd_echo_create(struct snd_card *card,
1918 struct pci_dev *pci,
1919 struct echoaudio **rchip)
1921 struct echoaudio *chip;
1924 static struct snd_device_ops ops = {
1925 .dev_free = snd_echo_dev_free,
1930 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1932 if ((err = pci_enable_device(pci)) < 0)
1934 pci_set_master(pci);
1936 /* Allocate chip if needed */
1938 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1940 pci_disable_device(pci);
1943 DE_INIT(("chip=%p\n", chip));
1944 spin_lock_init(&chip->lock);
1948 atomic_set(&chip->opencount, 0);
1949 mutex_init(&chip->mode_mutex);
1950 chip->can_set_rate = 1;
1952 /* If this was called from the resume function, chip is
1953 * already allocated and it contains current card settings.
1958 /* PCI resource allocation */
1959 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1960 sz = pci_resource_len(pci, 0);
1962 sz = PAGE_SIZE; /* We map only the required part */
1964 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1965 ECHOCARD_NAME)) == NULL) {
1966 dev_err(chip->card->dev, "cannot get memory region\n");
1967 snd_echo_free(chip);
1970 chip->dsp_registers = (volatile u32 __iomem *)
1971 ioremap_nocache(chip->dsp_registers_phys, sz);
1973 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1974 KBUILD_MODNAME, chip)) {
1975 dev_err(chip->card->dev, "cannot grab irq\n");
1976 snd_echo_free(chip);
1979 chip->irq = pci->irq;
1980 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n",
1981 chip->pci, chip->irq, chip->pci->subsystem_device));
1983 /* Create the DSP comm page - this is the area of memory used for most
1984 of the communication with the DSP, which accesses it via bus mastering */
1985 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1986 sizeof(struct comm_page),
1987 &chip->commpage_dma_buf) < 0) {
1988 dev_err(chip->card->dev, "cannot allocate the comm page\n");
1989 snd_echo_free(chip);
1992 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1993 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1995 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1997 err = set_mixer_defaults(chip);
1999 DE_INIT(("init_hw err=%d\n", err));
2000 snd_echo_free(chip);
2003 DE_INIT(("Card init OK\n"));
2005 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2006 snd_echo_free(chip);
2017 static int snd_echo_probe(struct pci_dev *pci,
2018 const struct pci_device_id *pci_id)
2021 struct snd_card *card;
2022 struct echoaudio *chip;
2026 if (dev >= SNDRV_CARDS)
2033 DE_INIT(("Echoaudio driver starting...\n"));
2035 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2040 chip = NULL; /* Tells snd_echo_create to allocate chip */
2041 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2042 snd_card_free(card);
2046 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
2047 strcpy(card->shortname, chip->card_name);
2050 if (pci_id->device == 0x3410)
2053 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2054 card->shortname, pci_id->subdevice & 0x000f, dsp,
2055 chip->dsp_registers_phys, chip->irq);
2057 if ((err = snd_echo_new_pcm(chip)) < 0) {
2058 dev_err(chip->card->dev, "new pcm error %d\n", err);
2059 snd_card_free(card);
2063 #ifdef ECHOCARD_HAS_MIDI
2064 if (chip->has_midi) { /* Some Mia's do not have midi */
2065 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2066 dev_err(chip->card->dev, "new midi error %d\n", err);
2067 snd_card_free(card);
2073 #ifdef ECHOCARD_HAS_VMIXER
2074 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2075 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2077 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2078 err = snd_ctl_add(chip->card,
2079 snd_ctl_new1(&snd_echo_line_output_gain, chip));
2083 #else /* ECHOCARD_HAS_VMIXER */
2084 err = snd_ctl_add(chip->card,
2085 snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
2088 #endif /* ECHOCARD_HAS_VMIXER */
2090 #ifdef ECHOCARD_HAS_INPUT_GAIN
2091 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2095 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2096 if (!chip->hasnt_input_nominal_level)
2097 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2101 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2102 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2106 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2109 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2112 #ifdef ECHOCARD_HAS_MONITOR
2113 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2114 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2118 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2119 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2123 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2126 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2127 /* Creates a list of available digital modes */
2128 chip->num_digital_modes = 0;
2129 for (i = 0; i < 6; i++)
2130 if (chip->digital_modes & (1 << i))
2131 chip->digital_mode_list[chip->num_digital_modes++] = i;
2133 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2135 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2137 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2138 /* Creates a list of available clock sources */
2139 chip->num_clock_sources = 0;
2140 for (i = 0; i < 10; i++)
2141 if (chip->input_clock_types & (1 << i))
2142 chip->clock_source_list[chip->num_clock_sources++] = i;
2144 if (chip->num_clock_sources > 1) {
2145 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2146 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2149 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2151 #ifdef ECHOCARD_HAS_DIGITAL_IO
2152 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2156 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2157 if (chip->has_phantom_power)
2158 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2162 err = snd_card_register(card);
2165 dev_info(card->dev, "Card registered: %s\n", card->longname);
2167 pci_set_drvdata(pci, chip);
2172 dev_err(card->dev, "new control error %d\n", err);
2173 snd_card_free(card);
2179 #if defined(CONFIG_PM_SLEEP)
2181 static int snd_echo_suspend(struct device *dev)
2183 struct pci_dev *pci = to_pci_dev(dev);
2184 struct echoaudio *chip = dev_get_drvdata(dev);
2186 DE_INIT(("suspend start\n"));
2187 snd_pcm_suspend_all(chip->analog_pcm);
2188 snd_pcm_suspend_all(chip->digital_pcm);
2190 #ifdef ECHOCARD_HAS_MIDI
2191 /* This call can sleep */
2193 snd_echo_midi_output_trigger(chip->midi_out, 0);
2195 spin_lock_irq(&chip->lock);
2196 if (wait_handshake(chip)) {
2197 spin_unlock_irq(&chip->lock);
2200 clear_handshake(chip);
2201 if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) {
2202 spin_unlock_irq(&chip->lock);
2205 spin_unlock_irq(&chip->lock);
2207 chip->dsp_code = NULL;
2208 free_irq(chip->irq, chip);
2210 pci_save_state(pci);
2211 pci_disable_device(pci);
2213 DE_INIT(("suspend done\n"));
2219 static int snd_echo_resume(struct device *dev)
2221 struct pci_dev *pci = to_pci_dev(dev);
2222 struct echoaudio *chip = dev_get_drvdata(dev);
2223 struct comm_page *commpage, *commpage_bak;
2224 u32 pipe_alloc_mask;
2227 DE_INIT(("resume start\n"));
2228 pci_restore_state(pci);
2229 commpage_bak = kmalloc(sizeof(struct echoaudio), GFP_KERNEL);
2230 if (commpage_bak == NULL)
2232 commpage = chip->comm_page;
2233 memcpy(commpage_bak, commpage, sizeof(struct comm_page));
2235 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
2237 kfree(commpage_bak);
2238 DE_INIT(("resume init_hw err=%d\n", err));
2239 snd_echo_free(chip);
2242 DE_INIT(("resume init OK\n"));
2244 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2245 * restore_dsp_settings() fails.
2247 pipe_alloc_mask = chip->pipe_alloc_mask;
2248 chip->pipe_alloc_mask = 0;
2249 err = restore_dsp_rettings(chip);
2250 chip->pipe_alloc_mask = pipe_alloc_mask;
2252 kfree(commpage_bak);
2255 DE_INIT(("resume restore OK\n"));
2257 memcpy(&commpage->audio_format, &commpage_bak->audio_format,
2258 sizeof(commpage->audio_format));
2259 memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr,
2260 sizeof(commpage->sglist_addr));
2261 memcpy(&commpage->midi_output, &commpage_bak->midi_output,
2262 sizeof(commpage->midi_output));
2263 kfree(commpage_bak);
2265 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
2266 KBUILD_MODNAME, chip)) {
2267 dev_err(chip->card->dev, "cannot grab irq\n");
2268 snd_echo_free(chip);
2271 chip->irq = pci->irq;
2272 DE_INIT(("resume irq=%d\n", chip->irq));
2274 #ifdef ECHOCARD_HAS_MIDI
2275 if (chip->midi_input_enabled)
2276 enable_midi_input(chip, TRUE);
2278 snd_echo_midi_output_trigger(chip->midi_out, 1);
2281 DE_INIT(("resume done\n"));
2285 static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume);
2286 #define SND_ECHO_PM_OPS &snd_echo_pm
2288 #define SND_ECHO_PM_OPS NULL
2289 #endif /* CONFIG_PM_SLEEP */
2292 static void snd_echo_remove(struct pci_dev *pci)
2294 struct echoaudio *chip;
2296 chip = pci_get_drvdata(pci);
2298 snd_card_free(chip->card);
2303 /******************************************************************************
2304 Everything starts and ends here
2305 ******************************************************************************/
2307 /* pci_driver definition */
2308 static struct pci_driver echo_driver = {
2309 .name = KBUILD_MODNAME,
2310 .id_table = snd_echo_ids,
2311 .probe = snd_echo_probe,
2312 .remove = snd_echo_remove,
2314 .pm = SND_ECHO_PM_OPS,
2318 module_pci_driver(echo_driver);