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 MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>");
20 MODULE_LICENSE("GPL v2");
21 MODULE_DESCRIPTION("Echoaudio " ECHOCARD_NAME " soundcards driver");
22 MODULE_SUPPORTED_DEVICE("{{Echoaudio," ECHOCARD_NAME "}}");
23 MODULE_DEVICE_TABLE(pci, snd_echo_ids);
25 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
26 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
27 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
29 module_param_array(index, int, NULL, 0444);
30 MODULE_PARM_DESC(index, "Index value for " ECHOCARD_NAME " soundcard.");
31 module_param_array(id, charp, NULL, 0444);
32 MODULE_PARM_DESC(id, "ID string for " ECHOCARD_NAME " soundcard.");
33 module_param_array(enable, bool, NULL, 0444);
34 MODULE_PARM_DESC(enable, "Enable " ECHOCARD_NAME " soundcard.");
36 static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
37 static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1);
41 static int get_firmware(const struct firmware **fw_entry,
42 struct echoaudio *chip, const short fw_index)
46 const struct firmware *frm = &card_fw[fw_index];
48 DE_ACT(("firmware requested: %s\n", frm->data));
49 snprintf(name, sizeof(name), "ea/%s", frm->data);
50 if ((err = request_firmware(fw_entry, name, pci_device(chip))) < 0)
51 snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err);
57 static void free_firmware(const struct firmware *fw_entry)
59 release_firmware(fw_entry);
60 DE_ACT(("firmware released\n"));
65 /******************************************************************************
67 ******************************************************************************/
69 static void audiopipe_free(struct snd_pcm_runtime *runtime)
71 struct audiopipe *pipe = runtime->private_data;
73 if (pipe->sgpage.area)
74 snd_dma_free_pages(&pipe->sgpage);
80 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
81 struct snd_pcm_hw_rule *rule)
83 struct snd_interval *c = hw_param_interval(params,
84 SNDRV_PCM_HW_PARAM_CHANNELS);
85 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
90 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
91 /* >=2 channels cannot be S32_BE */
93 fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
94 return snd_mask_refine(f, &fmt);
97 /* > 2 channels cannot be U8 and S32_BE */
99 fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
100 return snd_mask_refine(f, &fmt);
102 /* Mono is ok with any format */
108 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
109 struct snd_pcm_hw_rule *rule)
111 struct snd_interval *c = hw_param_interval(params,
112 SNDRV_PCM_HW_PARAM_CHANNELS);
113 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
114 struct snd_interval ch;
116 snd_interval_any(&ch);
118 /* S32_BE is mono (and stereo) only */
119 if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
121 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
127 return snd_interval_refine(c, &ch);
129 /* U8 can be only mono or stereo */
130 if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
134 return snd_interval_refine(c, &ch);
136 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
142 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
143 struct snd_pcm_hw_rule *rule)
145 struct snd_interval *c = hw_param_interval(params,
146 SNDRV_PCM_HW_PARAM_CHANNELS);
147 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
152 fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
154 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
156 fmask &= SNDRV_PCM_FMTBIT_S16_LE |
157 SNDRV_PCM_FMTBIT_S24_3LE |
158 SNDRV_PCM_FMTBIT_S32_LE;
159 /* 1 channel must be S32_BE or S32_LE */
160 } else if (c->max == 1)
161 fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
162 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
163 /* 2 channels cannot be S32_BE */
164 else if (c->min == 2 && c->max == 2)
165 fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
170 fmt.bits[0] &= (u32)fmask;
171 fmt.bits[1] &= (u32)(fmask >> 32);
172 return snd_mask_refine(f, &fmt);
177 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
178 struct snd_pcm_hw_rule *rule)
180 struct snd_interval *c = hw_param_interval(params,
181 SNDRV_PCM_HW_PARAM_CHANNELS);
182 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
183 struct snd_interval ch;
186 snd_interval_any(&ch);
188 fmask = f->bits[0] + ((u64)f->bits[1] << 32);
190 /* S32_BE is mono (and stereo) only */
191 if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
193 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
198 /* U8 is stereo only */
199 } else if (fmask == SNDRV_PCM_FMTBIT_U8)
201 /* S16_LE and S24_3LE must be at least stereo */
202 else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
203 SNDRV_PCM_FMTBIT_S24_3LE)))
208 return snd_interval_refine(c, &ch);
213 /* Since the sample rate is a global setting, do allow the user to change the
214 sample rate only if there is only one pcm device open. */
215 static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
216 struct snd_pcm_hw_rule *rule)
218 struct snd_interval *rate = hw_param_interval(params,
219 SNDRV_PCM_HW_PARAM_RATE);
220 struct echoaudio *chip = rule->private;
221 struct snd_interval fixed;
223 if (!chip->can_set_rate) {
224 snd_interval_any(&fixed);
225 fixed.min = fixed.max = chip->sample_rate;
226 return snd_interval_refine(rate, &fixed);
232 static int pcm_open(struct snd_pcm_substream *substream,
233 signed char max_channels)
235 struct echoaudio *chip;
236 struct snd_pcm_runtime *runtime;
237 struct audiopipe *pipe;
240 if (max_channels <= 0)
243 chip = snd_pcm_substream_chip(substream);
244 runtime = substream->runtime;
246 pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
249 pipe->index = -1; /* Not configured yet */
251 /* Set up hw capabilities and contraints */
252 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
253 DE_HWP(("max_channels=%d\n", max_channels));
254 pipe->constr.list = channels_list;
255 pipe->constr.mask = 0;
256 for (i = 0; channels_list[i] <= max_channels; i++);
257 pipe->constr.count = i;
258 if (pipe->hw.channels_max > max_channels)
259 pipe->hw.channels_max = max_channels;
260 if (chip->digital_mode == DIGITAL_MODE_ADAT) {
261 pipe->hw.rate_max = 48000;
262 pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
265 runtime->hw = pipe->hw;
266 runtime->private_data = pipe;
267 runtime->private_free = audiopipe_free;
268 snd_pcm_set_sync(substream);
270 /* Only mono and any even number of channels are allowed */
271 if ((err = snd_pcm_hw_constraint_list(runtime, 0,
272 SNDRV_PCM_HW_PARAM_CHANNELS,
276 /* All periods should have the same size */
277 if ((err = snd_pcm_hw_constraint_integer(runtime,
278 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
281 /* The hw accesses memory in chunks 32 frames long and they should be
282 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
283 generated with a resolution of 32 frames. Thus we need the following */
284 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
285 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
288 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
289 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
293 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
294 SNDRV_PCM_HW_PARAM_RATE,
295 hw_rule_sample_rate, chip,
296 SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
299 /* Finally allocate a page for the scatter-gather list */
300 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
301 snd_dma_pci_data(chip->pci),
302 PAGE_SIZE, &pipe->sgpage)) < 0) {
303 DE_HWP(("s-g list allocation failed\n"));
312 static int pcm_analog_in_open(struct snd_pcm_substream *substream)
314 struct echoaudio *chip = snd_pcm_substream_chip(substream);
317 DE_ACT(("pcm_analog_in_open\n"));
318 if ((err = pcm_open(substream, num_analog_busses_in(chip) -
319 substream->number)) < 0)
321 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
322 SNDRV_PCM_HW_PARAM_CHANNELS,
323 hw_rule_capture_channels_by_format, NULL,
324 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
326 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
327 SNDRV_PCM_HW_PARAM_FORMAT,
328 hw_rule_capture_format_by_channels, NULL,
329 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
331 atomic_inc(&chip->opencount);
332 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
333 chip->can_set_rate=0;
334 DE_HWP(("pcm_analog_in_open cs=%d oc=%d r=%d\n",
335 chip->can_set_rate, atomic_read(&chip->opencount),
342 static int pcm_analog_out_open(struct snd_pcm_substream *substream)
344 struct echoaudio *chip = snd_pcm_substream_chip(substream);
345 int max_channels, err;
347 #ifdef ECHOCARD_HAS_VMIXER
348 max_channels = num_pipes_out(chip);
350 max_channels = num_analog_busses_out(chip);
352 DE_ACT(("pcm_analog_out_open\n"));
353 if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
355 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
356 SNDRV_PCM_HW_PARAM_CHANNELS,
357 hw_rule_playback_channels_by_format,
359 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
361 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
362 SNDRV_PCM_HW_PARAM_FORMAT,
363 hw_rule_playback_format_by_channels,
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_out_open cs=%d oc=%d r=%d\n",
371 chip->can_set_rate, atomic_read(&chip->opencount),
378 #ifdef ECHOCARD_HAS_DIGITAL_IO
380 static int pcm_digital_in_open(struct snd_pcm_substream *substream)
382 struct echoaudio *chip = snd_pcm_substream_chip(substream);
383 int err, max_channels;
385 DE_ACT(("pcm_digital_in_open\n"));
386 max_channels = num_digital_busses_in(chip) - substream->number;
387 mutex_lock(&chip->mode_mutex);
388 if (chip->digital_mode == DIGITAL_MODE_ADAT)
389 err = pcm_open(substream, max_channels);
390 else /* If the card has ADAT, subtract the 6 channels
391 * that S/PDIF doesn't have
393 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
398 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
399 SNDRV_PCM_HW_PARAM_CHANNELS,
400 hw_rule_capture_channels_by_format, NULL,
401 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
403 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
404 SNDRV_PCM_HW_PARAM_FORMAT,
405 hw_rule_capture_format_by_channels, NULL,
406 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
409 atomic_inc(&chip->opencount);
410 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
411 chip->can_set_rate=0;
414 mutex_unlock(&chip->mode_mutex);
420 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
422 static int pcm_digital_out_open(struct snd_pcm_substream *substream)
424 struct echoaudio *chip = snd_pcm_substream_chip(substream);
425 int err, max_channels;
427 DE_ACT(("pcm_digital_out_open\n"));
428 max_channels = num_digital_busses_out(chip) - substream->number;
429 mutex_lock(&chip->mode_mutex);
430 if (chip->digital_mode == DIGITAL_MODE_ADAT)
431 err = pcm_open(substream, max_channels);
432 else /* If the card has ADAT, subtract the 6 channels
433 * that S/PDIF doesn't have
435 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
440 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
441 SNDRV_PCM_HW_PARAM_CHANNELS,
442 hw_rule_playback_channels_by_format,
443 NULL, SNDRV_PCM_HW_PARAM_FORMAT,
446 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
447 SNDRV_PCM_HW_PARAM_FORMAT,
448 hw_rule_playback_format_by_channels,
449 NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
452 atomic_inc(&chip->opencount);
453 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
454 chip->can_set_rate=0;
456 mutex_unlock(&chip->mode_mutex);
460 #endif /* !ECHOCARD_HAS_VMIXER */
462 #endif /* ECHOCARD_HAS_DIGITAL_IO */
466 static int pcm_close(struct snd_pcm_substream *substream)
468 struct echoaudio *chip = snd_pcm_substream_chip(substream);
471 /* Nothing to do here. Audio is already off and pipe will be
472 * freed by its callback
474 DE_ACT(("pcm_close\n"));
476 atomic_dec(&chip->opencount);
477 oc = atomic_read(&chip->opencount);
478 DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc,
479 chip->can_set_rate, chip->rate_set));
481 chip->can_set_rate = 1;
484 DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc,
485 chip->can_set_rate,chip->rate_set));
492 /* Channel allocation and scatter-gather list setup */
493 static int init_engine(struct snd_pcm_substream *substream,
494 struct snd_pcm_hw_params *hw_params,
495 int pipe_index, int interleave)
497 struct echoaudio *chip;
498 int err, per, rest, page, edge, offs;
499 struct audiopipe *pipe;
501 chip = snd_pcm_substream_chip(substream);
502 pipe = (struct audiopipe *) substream->runtime->private_data;
504 /* Sets up che hardware. If it's already initialized, reset and
505 * redo with the new parameters
507 spin_lock_irq(&chip->lock);
508 if (pipe->index >= 0) {
509 DE_HWP(("hwp_ie free(%d)\n", pipe->index));
510 err = free_pipes(chip, pipe);
512 chip->substream[pipe->index] = NULL;
515 err = allocate_pipes(chip, pipe, pipe_index, interleave);
517 spin_unlock_irq(&chip->lock);
518 DE_ACT((KERN_NOTICE "allocate_pipes(%d) err=%d\n",
522 spin_unlock_irq(&chip->lock);
523 DE_ACT((KERN_NOTICE "allocate_pipes()=%d\n", pipe_index));
525 DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
526 params_buffer_bytes(hw_params), params_periods(hw_params),
527 params_period_bytes(hw_params)));
528 err = snd_pcm_lib_malloc_pages(substream,
529 params_buffer_bytes(hw_params));
531 snd_printk(KERN_ERR "malloc_pages err=%d\n", err);
532 spin_lock_irq(&chip->lock);
533 free_pipes(chip, pipe);
534 spin_unlock_irq(&chip->lock);
539 sglist_init(chip, pipe);
541 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
543 rest = params_period_bytes(hw_params);
544 if (offs + rest > params_buffer_bytes(hw_params))
545 rest = params_buffer_bytes(hw_params) - offs;
548 addr = snd_pcm_sgbuf_get_addr(substream, offs);
549 if (rest <= edge - offs) {
550 sglist_add_mapping(chip, pipe, addr, rest);
551 sglist_add_irq(chip, pipe);
555 sglist_add_mapping(chip, pipe, addr,
567 /* Close the ring buffer */
568 sglist_wrap(chip, pipe);
570 /* This stuff is used by the irq handler, so it must be
571 * initialized before chip->substream
573 chip->last_period[pipe_index] = 0;
574 pipe->last_counter = 0;
577 chip->substream[pipe_index] = substream;
579 spin_lock_irq(&chip->lock);
580 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
581 spin_unlock_irq(&chip->lock);
582 DE_HWP(("pcm_hw_params ok\n"));
588 static int pcm_analog_in_hw_params(struct snd_pcm_substream *substream,
589 struct snd_pcm_hw_params *hw_params)
591 struct echoaudio *chip = snd_pcm_substream_chip(substream);
593 return init_engine(substream, hw_params, px_analog_in(chip) +
594 substream->number, params_channels(hw_params));
599 static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream,
600 struct snd_pcm_hw_params *hw_params)
602 return init_engine(substream, hw_params, substream->number,
603 params_channels(hw_params));
608 #ifdef ECHOCARD_HAS_DIGITAL_IO
610 static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream,
611 struct snd_pcm_hw_params *hw_params)
613 struct echoaudio *chip = snd_pcm_substream_chip(substream);
615 return init_engine(substream, hw_params, px_digital_in(chip) +
616 substream->number, params_channels(hw_params));
621 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
622 static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream,
623 struct snd_pcm_hw_params *hw_params)
625 struct echoaudio *chip = snd_pcm_substream_chip(substream);
627 return init_engine(substream, hw_params, px_digital_out(chip) +
628 substream->number, params_channels(hw_params));
630 #endif /* !ECHOCARD_HAS_VMIXER */
632 #endif /* ECHOCARD_HAS_DIGITAL_IO */
636 static int pcm_hw_free(struct snd_pcm_substream *substream)
638 struct echoaudio *chip;
639 struct audiopipe *pipe;
641 chip = snd_pcm_substream_chip(substream);
642 pipe = (struct audiopipe *) substream->runtime->private_data;
644 spin_lock_irq(&chip->lock);
645 if (pipe->index >= 0) {
646 DE_HWP(("pcm_hw_free(%d)\n", pipe->index));
647 free_pipes(chip, pipe);
648 chip->substream[pipe->index] = NULL;
651 spin_unlock_irq(&chip->lock);
653 DE_HWP(("pcm_hw_freed\n"));
654 snd_pcm_lib_free_pages(substream);
660 static int pcm_prepare(struct snd_pcm_substream *substream)
662 struct echoaudio *chip = snd_pcm_substream_chip(substream);
663 struct snd_pcm_runtime *runtime = substream->runtime;
664 struct audioformat format;
665 int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
667 DE_HWP(("Prepare rate=%d format=%d channels=%d\n",
668 runtime->rate, runtime->format, runtime->channels));
669 format.interleave = runtime->channels;
670 format.data_are_bigendian = 0;
671 format.mono_to_stereo = 0;
672 switch (runtime->format) {
673 case SNDRV_PCM_FORMAT_U8:
674 format.bits_per_sample = 8;
676 case SNDRV_PCM_FORMAT_S16_LE:
677 format.bits_per_sample = 16;
679 case SNDRV_PCM_FORMAT_S24_3LE:
680 format.bits_per_sample = 24;
682 case SNDRV_PCM_FORMAT_S32_BE:
683 format.data_are_bigendian = 1;
684 case SNDRV_PCM_FORMAT_S32_LE:
685 format.bits_per_sample = 32;
688 DE_HWP(("Prepare error: unsupported format %d\n",
693 if (snd_BUG_ON(pipe_index >= px_num(chip)))
695 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
697 set_audio_format(chip, pipe_index, &format);
703 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
705 struct echoaudio *chip = snd_pcm_substream_chip(substream);
706 struct snd_pcm_runtime *runtime = substream->runtime;
707 struct audiopipe *pipe = runtime->private_data;
710 struct snd_pcm_substream *s;
712 snd_pcm_group_for_each_entry(s, substream) {
713 for (i = 0; i < DSP_MAXPIPES; i++) {
714 if (s == chip->substream[i]) {
715 channelmask |= 1 << i;
716 snd_pcm_trigger_done(s, substream);
721 spin_lock(&chip->lock);
723 case SNDRV_PCM_TRIGGER_START:
724 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
725 DE_ACT(("pcm_trigger start\n"));
726 for (i = 0; i < DSP_MAXPIPES; i++) {
727 if (channelmask & (1 << i)) {
728 pipe = chip->substream[i]->runtime->private_data;
729 switch (pipe->state) {
730 case PIPE_STATE_STOPPED:
731 chip->last_period[i] = 0;
732 pipe->last_counter = 0;
734 *pipe->dma_counter = 0;
735 case PIPE_STATE_PAUSED:
736 pipe->state = PIPE_STATE_STARTED;
738 case PIPE_STATE_STARTED:
743 err = start_transport(chip, channelmask,
744 chip->pipe_cyclic_mask);
746 case SNDRV_PCM_TRIGGER_STOP:
747 DE_ACT(("pcm_trigger stop\n"));
748 for (i = 0; i < DSP_MAXPIPES; i++) {
749 if (channelmask & (1 << i)) {
750 pipe = chip->substream[i]->runtime->private_data;
751 pipe->state = PIPE_STATE_STOPPED;
754 err = stop_transport(chip, channelmask);
756 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
757 DE_ACT(("pcm_trigger pause\n"));
758 for (i = 0; i < DSP_MAXPIPES; i++) {
759 if (channelmask & (1 << i)) {
760 pipe = chip->substream[i]->runtime->private_data;
761 pipe->state = PIPE_STATE_PAUSED;
764 err = pause_transport(chip, channelmask);
769 spin_unlock(&chip->lock);
775 static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
777 struct snd_pcm_runtime *runtime = substream->runtime;
778 struct audiopipe *pipe = runtime->private_data;
779 size_t cnt, bufsize, pos;
781 cnt = le32_to_cpu(*pipe->dma_counter);
782 pipe->position += cnt - pipe->last_counter;
783 pipe->last_counter = cnt;
784 bufsize = substream->runtime->buffer_size;
785 pos = bytes_to_frames(substream->runtime, pipe->position);
787 while (pos >= bufsize) {
788 pipe->position -= frames_to_bytes(substream->runtime, bufsize);
796 /* pcm *_ops structures */
797 static struct snd_pcm_ops analog_playback_ops = {
798 .open = pcm_analog_out_open,
800 .ioctl = snd_pcm_lib_ioctl,
801 .hw_params = pcm_analog_out_hw_params,
802 .hw_free = pcm_hw_free,
803 .prepare = pcm_prepare,
804 .trigger = pcm_trigger,
805 .pointer = pcm_pointer,
806 .page = snd_pcm_sgbuf_ops_page,
808 static struct snd_pcm_ops analog_capture_ops = {
809 .open = pcm_analog_in_open,
811 .ioctl = snd_pcm_lib_ioctl,
812 .hw_params = pcm_analog_in_hw_params,
813 .hw_free = pcm_hw_free,
814 .prepare = pcm_prepare,
815 .trigger = pcm_trigger,
816 .pointer = pcm_pointer,
817 .page = snd_pcm_sgbuf_ops_page,
819 #ifdef ECHOCARD_HAS_DIGITAL_IO
820 #ifndef ECHOCARD_HAS_VMIXER
821 static struct snd_pcm_ops digital_playback_ops = {
822 .open = pcm_digital_out_open,
824 .ioctl = snd_pcm_lib_ioctl,
825 .hw_params = pcm_digital_out_hw_params,
826 .hw_free = pcm_hw_free,
827 .prepare = pcm_prepare,
828 .trigger = pcm_trigger,
829 .pointer = pcm_pointer,
830 .page = snd_pcm_sgbuf_ops_page,
832 #endif /* !ECHOCARD_HAS_VMIXER */
833 static struct snd_pcm_ops digital_capture_ops = {
834 .open = pcm_digital_in_open,
836 .ioctl = snd_pcm_lib_ioctl,
837 .hw_params = pcm_digital_in_hw_params,
838 .hw_free = pcm_hw_free,
839 .prepare = pcm_prepare,
840 .trigger = pcm_trigger,
841 .pointer = pcm_pointer,
842 .page = snd_pcm_sgbuf_ops_page,
844 #endif /* ECHOCARD_HAS_DIGITAL_IO */
848 /* Preallocate memory only for the first substream because it's the most
851 static int snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev)
853 struct snd_pcm_substream *ss;
856 for (stream = 0; stream < 2; stream++)
857 for (ss = pcm->streams[stream].substream; ss; ss = ss->next) {
858 err = snd_pcm_lib_preallocate_pages(ss, SNDRV_DMA_TYPE_DEV_SG,
860 ss->number ? 0 : 128<<10,
870 /*<--snd_echo_probe() */
871 static int __devinit snd_echo_new_pcm(struct echoaudio *chip)
876 #ifdef ECHOCARD_HAS_VMIXER
877 /* This card has a Vmixer, that is there is no direct mapping from PCM
878 streams to physical outputs. The user can mix the streams as he wishes
879 via control interface and it's possible to send any stream to any
880 output, thus it makes no sense to keep analog and digital outputs
883 /* PCM#0 Virtual outputs and analog inputs */
884 if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip),
885 num_analog_busses_in(chip), &pcm)) < 0)
887 pcm->private_data = chip;
888 chip->analog_pcm = pcm;
889 strcpy(pcm->name, chip->card->shortname);
890 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
891 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
892 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
894 DE_INIT(("Analog PCM ok\n"));
896 #ifdef ECHOCARD_HAS_DIGITAL_IO
897 /* PCM#1 Digital inputs, no outputs */
898 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0,
899 num_digital_busses_in(chip), &pcm)) < 0)
901 pcm->private_data = chip;
902 chip->digital_pcm = pcm;
903 strcpy(pcm->name, chip->card->shortname);
904 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
905 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
907 DE_INIT(("Digital PCM ok\n"));
908 #endif /* ECHOCARD_HAS_DIGITAL_IO */
910 #else /* ECHOCARD_HAS_VMIXER */
912 /* The card can manage substreams formed by analog and digital channels
913 at the same time, but I prefer to keep analog and digital channels
914 separated, because that mixed thing is confusing and useless. So we
915 register two PCM devices: */
917 /* PCM#0 Analog i/o */
918 if ((err = snd_pcm_new(chip->card, "Analog PCM", 0,
919 num_analog_busses_out(chip),
920 num_analog_busses_in(chip), &pcm)) < 0)
922 pcm->private_data = chip;
923 chip->analog_pcm = pcm;
924 strcpy(pcm->name, chip->card->shortname);
925 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
926 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
927 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
929 DE_INIT(("Analog PCM ok\n"));
931 #ifdef ECHOCARD_HAS_DIGITAL_IO
932 /* PCM#1 Digital i/o */
933 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1,
934 num_digital_busses_out(chip),
935 num_digital_busses_in(chip), &pcm)) < 0)
937 pcm->private_data = chip;
938 chip->digital_pcm = pcm;
939 strcpy(pcm->name, chip->card->shortname);
940 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops);
941 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
942 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
944 DE_INIT(("Digital PCM ok\n"));
945 #endif /* ECHOCARD_HAS_DIGITAL_IO */
947 #endif /* ECHOCARD_HAS_VMIXER */
955 /******************************************************************************
957 ******************************************************************************/
959 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
961 /******************* PCM output volume *******************/
962 static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
963 struct snd_ctl_elem_info *uinfo)
965 struct echoaudio *chip;
967 chip = snd_kcontrol_chip(kcontrol);
968 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
969 uinfo->count = num_busses_out(chip);
970 uinfo->value.integer.min = ECHOGAIN_MINOUT;
971 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
975 static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
976 struct snd_ctl_elem_value *ucontrol)
978 struct echoaudio *chip;
981 chip = snd_kcontrol_chip(kcontrol);
982 for (c = 0; c < num_busses_out(chip); c++)
983 ucontrol->value.integer.value[c] = chip->output_gain[c];
987 static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
988 struct snd_ctl_elem_value *ucontrol)
990 struct echoaudio *chip;
991 int c, changed, gain;
994 chip = snd_kcontrol_chip(kcontrol);
995 spin_lock_irq(&chip->lock);
996 for (c = 0; c < num_busses_out(chip); c++) {
997 gain = ucontrol->value.integer.value[c];
998 /* Ignore out of range values */
999 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1001 if (chip->output_gain[c] != gain) {
1002 set_output_gain(chip, c, gain);
1007 update_output_line_level(chip);
1008 spin_unlock_irq(&chip->lock);
1012 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1013 /* On the Mia this one controls the line-out volume */
1014 static struct snd_kcontrol_new snd_echo_line_output_gain __devinitdata = {
1015 .name = "Line Playback Volume",
1016 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1017 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1018 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1019 .info = snd_echo_output_gain_info,
1020 .get = snd_echo_output_gain_get,
1021 .put = snd_echo_output_gain_put,
1022 .tlv = {.p = db_scale_output_gain},
1025 static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1026 .name = "PCM Playback Volume",
1027 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1028 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1029 .info = snd_echo_output_gain_info,
1030 .get = snd_echo_output_gain_get,
1031 .put = snd_echo_output_gain_put,
1032 .tlv = {.p = db_scale_output_gain},
1036 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1040 #ifdef ECHOCARD_HAS_INPUT_GAIN
1042 /******************* Analog input volume *******************/
1043 static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
1044 struct snd_ctl_elem_info *uinfo)
1046 struct echoaudio *chip;
1048 chip = snd_kcontrol_chip(kcontrol);
1049 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1050 uinfo->count = num_analog_busses_in(chip);
1051 uinfo->value.integer.min = ECHOGAIN_MININP;
1052 uinfo->value.integer.max = ECHOGAIN_MAXINP;
1056 static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
1057 struct snd_ctl_elem_value *ucontrol)
1059 struct echoaudio *chip;
1062 chip = snd_kcontrol_chip(kcontrol);
1063 for (c = 0; c < num_analog_busses_in(chip); c++)
1064 ucontrol->value.integer.value[c] = chip->input_gain[c];
1068 static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
1069 struct snd_ctl_elem_value *ucontrol)
1071 struct echoaudio *chip;
1072 int c, gain, changed;
1075 chip = snd_kcontrol_chip(kcontrol);
1076 spin_lock_irq(&chip->lock);
1077 for (c = 0; c < num_analog_busses_in(chip); c++) {
1078 gain = ucontrol->value.integer.value[c];
1079 /* Ignore out of range values */
1080 if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
1082 if (chip->input_gain[c] != gain) {
1083 set_input_gain(chip, c, gain);
1088 update_input_line_level(chip);
1089 spin_unlock_irq(&chip->lock);
1093 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain, -2500, 50, 0);
1095 static struct snd_kcontrol_new snd_echo_line_input_gain __devinitdata = {
1096 .name = "Line Capture Volume",
1097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1098 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1099 .info = snd_echo_input_gain_info,
1100 .get = snd_echo_input_gain_get,
1101 .put = snd_echo_input_gain_put,
1102 .tlv = {.p = db_scale_input_gain},
1105 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1109 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1111 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1112 static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
1113 struct snd_ctl_elem_info *uinfo)
1115 struct echoaudio *chip;
1117 chip = snd_kcontrol_chip(kcontrol);
1118 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1119 uinfo->count = num_analog_busses_out(chip);
1120 uinfo->value.integer.min = 0;
1121 uinfo->value.integer.max = 1;
1125 static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
1126 struct snd_ctl_elem_value *ucontrol)
1128 struct echoaudio *chip;
1131 chip = snd_kcontrol_chip(kcontrol);
1132 for (c = 0; c < num_analog_busses_out(chip); c++)
1133 ucontrol->value.integer.value[c] = chip->nominal_level[c];
1137 static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
1138 struct snd_ctl_elem_value *ucontrol)
1140 struct echoaudio *chip;
1144 chip = snd_kcontrol_chip(kcontrol);
1145 spin_lock_irq(&chip->lock);
1146 for (c = 0; c < num_analog_busses_out(chip); c++) {
1147 if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
1148 set_nominal_level(chip, c,
1149 ucontrol->value.integer.value[c]);
1154 update_output_line_level(chip);
1155 spin_unlock_irq(&chip->lock);
1159 static struct snd_kcontrol_new snd_echo_output_nominal_level __devinitdata = {
1160 .name = "Line Playback Switch (-10dBV)",
1161 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1162 .info = snd_echo_output_nominal_info,
1163 .get = snd_echo_output_nominal_get,
1164 .put = snd_echo_output_nominal_put,
1167 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1171 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1173 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1174 static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
1175 struct snd_ctl_elem_info *uinfo)
1177 struct echoaudio *chip;
1179 chip = snd_kcontrol_chip(kcontrol);
1180 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1181 uinfo->count = num_analog_busses_in(chip);
1182 uinfo->value.integer.min = 0;
1183 uinfo->value.integer.max = 1;
1187 static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
1188 struct snd_ctl_elem_value *ucontrol)
1190 struct echoaudio *chip;
1193 chip = snd_kcontrol_chip(kcontrol);
1194 for (c = 0; c < num_analog_busses_in(chip); c++)
1195 ucontrol->value.integer.value[c] =
1196 chip->nominal_level[bx_analog_in(chip) + c];
1200 static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
1201 struct snd_ctl_elem_value *ucontrol)
1203 struct echoaudio *chip;
1207 chip = snd_kcontrol_chip(kcontrol);
1208 spin_lock_irq(&chip->lock);
1209 for (c = 0; c < num_analog_busses_in(chip); c++) {
1210 if (chip->nominal_level[bx_analog_in(chip) + c] !=
1211 ucontrol->value.integer.value[c]) {
1212 set_nominal_level(chip, bx_analog_in(chip) + c,
1213 ucontrol->value.integer.value[c]);
1218 update_output_line_level(chip); /* "Output" is not a mistake
1221 spin_unlock_irq(&chip->lock);
1225 static struct snd_kcontrol_new snd_echo_intput_nominal_level __devinitdata = {
1226 .name = "Line Capture Switch (-10dBV)",
1227 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1228 .info = snd_echo_input_nominal_info,
1229 .get = snd_echo_input_nominal_get,
1230 .put = snd_echo_input_nominal_put,
1233 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1237 #ifdef ECHOCARD_HAS_MONITOR
1239 /******************* Monitor mixer *******************/
1240 static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1241 struct snd_ctl_elem_info *uinfo)
1243 struct echoaudio *chip;
1245 chip = snd_kcontrol_chip(kcontrol);
1246 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1248 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1249 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1250 uinfo->dimen.d[0] = num_busses_out(chip);
1251 uinfo->dimen.d[1] = num_busses_in(chip);
1255 static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1256 struct snd_ctl_elem_value *ucontrol)
1258 struct echoaudio *chip;
1260 chip = snd_kcontrol_chip(kcontrol);
1261 ucontrol->value.integer.value[0] =
1262 chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)]
1263 [ucontrol->id.index % num_busses_in(chip)];
1267 static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1268 struct snd_ctl_elem_value *ucontrol)
1270 struct echoaudio *chip;
1275 chip = snd_kcontrol_chip(kcontrol);
1276 out = ucontrol->id.index / num_busses_in(chip);
1277 in = ucontrol->id.index % num_busses_in(chip);
1278 gain = ucontrol->value.integer.value[0];
1279 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1281 if (chip->monitor_gain[out][in] != gain) {
1282 spin_lock_irq(&chip->lock);
1283 set_monitor_gain(chip, out, in, gain);
1284 update_output_line_level(chip);
1285 spin_unlock_irq(&chip->lock);
1291 static struct snd_kcontrol_new snd_echo_monitor_mixer __devinitdata = {
1292 .name = "Monitor Mixer Volume",
1293 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1294 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1295 .info = snd_echo_mixer_info,
1296 .get = snd_echo_mixer_get,
1297 .put = snd_echo_mixer_put,
1298 .tlv = {.p = db_scale_output_gain},
1301 #endif /* ECHOCARD_HAS_MONITOR */
1305 #ifdef ECHOCARD_HAS_VMIXER
1307 /******************* Vmixer *******************/
1308 static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
1309 struct snd_ctl_elem_info *uinfo)
1311 struct echoaudio *chip;
1313 chip = snd_kcontrol_chip(kcontrol);
1314 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1316 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1317 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1318 uinfo->dimen.d[0] = num_busses_out(chip);
1319 uinfo->dimen.d[1] = num_pipes_out(chip);
1323 static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
1324 struct snd_ctl_elem_value *ucontrol)
1326 struct echoaudio *chip;
1328 chip = snd_kcontrol_chip(kcontrol);
1329 ucontrol->value.integer.value[0] =
1330 chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
1331 [ucontrol->id.index % num_pipes_out(chip)];
1335 static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
1336 struct snd_ctl_elem_value *ucontrol)
1338 struct echoaudio *chip;
1343 chip = snd_kcontrol_chip(kcontrol);
1344 out = ucontrol->id.index / num_pipes_out(chip);
1345 vch = ucontrol->id.index % num_pipes_out(chip);
1346 gain = ucontrol->value.integer.value[0];
1347 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1349 if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
1350 spin_lock_irq(&chip->lock);
1351 set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
1352 update_vmixer_level(chip);
1353 spin_unlock_irq(&chip->lock);
1359 static struct snd_kcontrol_new snd_echo_vmixer __devinitdata = {
1360 .name = "VMixer Volume",
1361 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1362 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1363 .info = snd_echo_vmixer_info,
1364 .get = snd_echo_vmixer_get,
1365 .put = snd_echo_vmixer_put,
1366 .tlv = {.p = db_scale_output_gain},
1369 #endif /* ECHOCARD_HAS_VMIXER */
1373 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1375 /******************* Digital mode switch *******************/
1376 static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1377 struct snd_ctl_elem_info *uinfo)
1379 static char *names[4] = {
1380 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1383 struct echoaudio *chip;
1385 chip = snd_kcontrol_chip(kcontrol);
1386 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1387 uinfo->value.enumerated.items = chip->num_digital_modes;
1389 if (uinfo->value.enumerated.item >= chip->num_digital_modes)
1390 uinfo->value.enumerated.item = chip->num_digital_modes - 1;
1391 strcpy(uinfo->value.enumerated.name, names[
1392 chip->digital_mode_list[uinfo->value.enumerated.item]]);
1396 static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
1397 struct snd_ctl_elem_value *ucontrol)
1399 struct echoaudio *chip;
1402 chip = snd_kcontrol_chip(kcontrol);
1403 mode = chip->digital_mode;
1404 for (i = chip->num_digital_modes - 1; i >= 0; i--)
1405 if (mode == chip->digital_mode_list[i]) {
1406 ucontrol->value.enumerated.item[0] = i;
1412 static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1413 struct snd_ctl_elem_value *ucontrol)
1415 struct echoaudio *chip;
1417 unsigned short emode, dmode;
1420 chip = snd_kcontrol_chip(kcontrol);
1422 emode = ucontrol->value.enumerated.item[0];
1423 if (emode >= chip->num_digital_modes)
1425 dmode = chip->digital_mode_list[emode];
1427 if (dmode != chip->digital_mode) {
1428 /* mode_mutex is required to make this operation atomic wrt
1429 pcm_digital_*_open() and set_input_clock() functions. */
1430 mutex_lock(&chip->mode_mutex);
1432 /* Do not allow the user to change the digital mode when a pcm
1433 device is open because it also changes the number of channels
1434 and the allowed sample rates */
1435 if (atomic_read(&chip->opencount)) {
1438 changed = set_digital_mode(chip, dmode);
1439 /* If we had to change the clock source, report it */
1440 if (changed > 0 && chip->clock_src_ctl) {
1441 snd_ctl_notify(chip->card,
1442 SNDRV_CTL_EVENT_MASK_VALUE,
1443 &chip->clock_src_ctl->id);
1444 DE_ACT(("SDM() =%d\n", changed));
1447 changed = 1; /* No errors */
1449 mutex_unlock(&chip->mode_mutex);
1454 static struct snd_kcontrol_new snd_echo_digital_mode_switch __devinitdata = {
1455 .name = "Digital mode Switch",
1456 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1457 .info = snd_echo_digital_mode_info,
1458 .get = snd_echo_digital_mode_get,
1459 .put = snd_echo_digital_mode_put,
1462 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1466 #ifdef ECHOCARD_HAS_DIGITAL_IO
1468 /******************* S/PDIF mode switch *******************/
1469 static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1470 struct snd_ctl_elem_info *uinfo)
1472 static char *names[2] = {"Consumer", "Professional"};
1474 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1475 uinfo->value.enumerated.items = 2;
1477 if (uinfo->value.enumerated.item)
1478 uinfo->value.enumerated.item = 1;
1479 strcpy(uinfo->value.enumerated.name,
1480 names[uinfo->value.enumerated.item]);
1484 static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
1485 struct snd_ctl_elem_value *ucontrol)
1487 struct echoaudio *chip;
1489 chip = snd_kcontrol_chip(kcontrol);
1490 ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
1494 static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
1495 struct snd_ctl_elem_value *ucontrol)
1497 struct echoaudio *chip;
1500 chip = snd_kcontrol_chip(kcontrol);
1501 mode = !!ucontrol->value.enumerated.item[0];
1502 if (mode != chip->professional_spdif) {
1503 spin_lock_irq(&chip->lock);
1504 set_professional_spdif(chip, mode);
1505 spin_unlock_irq(&chip->lock);
1511 static struct snd_kcontrol_new snd_echo_spdif_mode_switch __devinitdata = {
1512 .name = "S/PDIF mode Switch",
1513 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1514 .info = snd_echo_spdif_mode_info,
1515 .get = snd_echo_spdif_mode_get,
1516 .put = snd_echo_spdif_mode_put,
1519 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1523 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1525 /******************* Select input clock source *******************/
1526 static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1527 struct snd_ctl_elem_info *uinfo)
1529 static char *names[8] = {
1530 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1533 struct echoaudio *chip;
1535 chip = snd_kcontrol_chip(kcontrol);
1536 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1537 uinfo->value.enumerated.items = chip->num_clock_sources;
1539 if (uinfo->value.enumerated.item >= chip->num_clock_sources)
1540 uinfo->value.enumerated.item = chip->num_clock_sources - 1;
1541 strcpy(uinfo->value.enumerated.name, names[
1542 chip->clock_source_list[uinfo->value.enumerated.item]]);
1546 static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
1547 struct snd_ctl_elem_value *ucontrol)
1549 struct echoaudio *chip;
1552 chip = snd_kcontrol_chip(kcontrol);
1553 clock = chip->input_clock;
1555 for (i = 0; i < chip->num_clock_sources; i++)
1556 if (clock == chip->clock_source_list[i])
1557 ucontrol->value.enumerated.item[0] = i;
1562 static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1563 struct snd_ctl_elem_value *ucontrol)
1565 struct echoaudio *chip;
1567 unsigned int eclock, dclock;
1570 chip = snd_kcontrol_chip(kcontrol);
1571 eclock = ucontrol->value.enumerated.item[0];
1572 if (eclock >= chip->input_clock_types)
1574 dclock = chip->clock_source_list[eclock];
1575 if (chip->input_clock != dclock) {
1576 mutex_lock(&chip->mode_mutex);
1577 spin_lock_irq(&chip->lock);
1578 if ((changed = set_input_clock(chip, dclock)) == 0)
1579 changed = 1; /* no errors */
1580 spin_unlock_irq(&chip->lock);
1581 mutex_unlock(&chip->mode_mutex);
1585 DE_ACT(("seticlk val%d err 0x%x\n", dclock, changed));
1590 static struct snd_kcontrol_new snd_echo_clock_source_switch __devinitdata = {
1591 .name = "Sample Clock Source",
1592 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1593 .info = snd_echo_clock_source_info,
1594 .get = snd_echo_clock_source_get,
1595 .put = snd_echo_clock_source_put,
1598 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1602 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1604 /******************* Phantom power switch *******************/
1605 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1607 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1608 struct snd_ctl_elem_value *ucontrol)
1610 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1612 ucontrol->value.integer.value[0] = chip->phantom_power;
1616 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1619 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1620 int power, changed = 0;
1622 power = !!ucontrol->value.integer.value[0];
1623 if (chip->phantom_power != power) {
1624 spin_lock_irq(&chip->lock);
1625 changed = set_phantom_power(chip, power);
1626 spin_unlock_irq(&chip->lock);
1628 changed = 1; /* no errors */
1633 static struct snd_kcontrol_new snd_echo_phantom_power_switch __devinitdata = {
1634 .name = "Phantom power Switch",
1635 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1636 .info = snd_echo_phantom_power_info,
1637 .get = snd_echo_phantom_power_get,
1638 .put = snd_echo_phantom_power_put,
1641 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1645 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1647 /******************* Digital input automute switch *******************/
1648 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1650 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1651 struct snd_ctl_elem_value *ucontrol)
1653 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1655 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1659 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1660 struct snd_ctl_elem_value *ucontrol)
1662 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1663 int automute, changed = 0;
1665 automute = !!ucontrol->value.integer.value[0];
1666 if (chip->digital_in_automute != automute) {
1667 spin_lock_irq(&chip->lock);
1668 changed = set_input_auto_mute(chip, automute);
1669 spin_unlock_irq(&chip->lock);
1671 changed = 1; /* no errors */
1676 static struct snd_kcontrol_new snd_echo_automute_switch __devinitdata = {
1677 .name = "Digital Capture Switch (automute)",
1678 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1679 .info = snd_echo_automute_info,
1680 .get = snd_echo_automute_get,
1681 .put = snd_echo_automute_put,
1684 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1688 /******************* VU-meters switch *******************/
1689 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1691 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1692 struct snd_ctl_elem_value *ucontrol)
1694 struct echoaudio *chip;
1696 chip = snd_kcontrol_chip(kcontrol);
1697 spin_lock_irq(&chip->lock);
1698 set_meters_on(chip, ucontrol->value.integer.value[0]);
1699 spin_unlock_irq(&chip->lock);
1703 static struct snd_kcontrol_new snd_echo_vumeters_switch __devinitdata = {
1704 .name = "VU-meters Switch",
1705 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1706 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1707 .info = snd_echo_vumeters_switch_info,
1708 .put = snd_echo_vumeters_switch_put,
1713 /***** Read VU-meters (input, output, analog and digital together) *****/
1714 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1715 struct snd_ctl_elem_info *uinfo)
1717 struct echoaudio *chip;
1719 chip = snd_kcontrol_chip(kcontrol);
1720 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1722 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1723 uinfo->value.integer.max = 0;
1724 #ifdef ECHOCARD_HAS_VMIXER
1725 uinfo->dimen.d[0] = 3; /* Out, In, Virt */
1727 uinfo->dimen.d[0] = 2; /* Out, In */
1729 uinfo->dimen.d[1] = 16; /* 16 channels */
1730 uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */
1734 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1735 struct snd_ctl_elem_value *ucontrol)
1737 struct echoaudio *chip;
1739 chip = snd_kcontrol_chip(kcontrol);
1740 get_audio_meters(chip, ucontrol->value.integer.value);
1744 static struct snd_kcontrol_new snd_echo_vumeters __devinitdata = {
1745 .name = "VU-meters",
1746 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1747 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1748 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
1749 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1750 .info = snd_echo_vumeters_info,
1751 .get = snd_echo_vumeters_get,
1752 .tlv = {.p = db_scale_output_gain},
1757 /*** Channels info - it exports informations about the number of channels ***/
1758 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1759 struct snd_ctl_elem_info *uinfo)
1761 struct echoaudio *chip;
1763 chip = snd_kcontrol_chip(kcontrol);
1764 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1766 uinfo->value.integer.min = 0;
1767 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1771 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1772 struct snd_ctl_elem_value *ucontrol)
1774 struct echoaudio *chip;
1775 int detected, clocks, bit, src;
1777 chip = snd_kcontrol_chip(kcontrol);
1778 ucontrol->value.integer.value[0] = num_busses_in(chip);
1779 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1780 ucontrol->value.integer.value[2] = num_busses_out(chip);
1781 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1782 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1784 /* Compute the bitmask of the currently valid input clocks */
1785 detected = detect_input_clocks(chip);
1787 src = chip->num_clock_sources - 1;
1788 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1789 if (detected & (1 << bit))
1790 for (; src >= 0; src--)
1791 if (bit == chip->clock_source_list[src]) {
1795 ucontrol->value.integer.value[5] = clocks;
1800 static struct snd_kcontrol_new snd_echo_channels_info __devinitdata = {
1801 .name = "Channels info",
1802 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1803 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1804 .info = snd_echo_channels_info_info,
1805 .get = snd_echo_channels_info_get,
1811 /******************************************************************************
1813 ******************************************************************************/
1815 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1817 struct echoaudio *chip = dev_id;
1818 struct snd_pcm_substream *substream;
1821 spin_lock(&chip->lock);
1822 st = service_irq(chip);
1824 spin_unlock(&chip->lock);
1827 /* The hardware doesn't tell us which substream caused the irq,
1828 thus we have to check all running substreams. */
1829 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1830 if ((substream = chip->substream[ss])) {
1831 period = pcm_pointer(substream) /
1832 substream->runtime->period_size;
1833 if (period != chip->last_period[ss]) {
1834 chip->last_period[ss] = period;
1835 spin_unlock(&chip->lock);
1836 snd_pcm_period_elapsed(substream);
1837 spin_lock(&chip->lock);
1841 spin_unlock(&chip->lock);
1843 #ifdef ECHOCARD_HAS_MIDI
1844 if (st > 0 && chip->midi_in) {
1845 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1846 DE_MID(("rawmidi_iread=%d\n", st));
1855 /******************************************************************************
1856 Module construction / destruction
1857 ******************************************************************************/
1859 static int snd_echo_free(struct echoaudio *chip)
1861 DE_INIT(("Stop DSP...\n"));
1862 if (chip->comm_page)
1863 rest_in_peace(chip);
1864 DE_INIT(("Stopped.\n"));
1867 free_irq(chip->irq, chip);
1869 if (chip->comm_page)
1870 snd_dma_free_pages(&chip->commpage_dma_buf);
1872 if (chip->dsp_registers)
1873 iounmap(chip->dsp_registers);
1876 release_and_free_resource(chip->iores);
1878 DE_INIT(("MMIO freed.\n"));
1880 pci_disable_device(chip->pci);
1882 /* release chip data */
1884 DE_INIT(("Chip freed.\n"));
1890 static int snd_echo_dev_free(struct snd_device *device)
1892 struct echoaudio *chip = device->device_data;
1894 DE_INIT(("snd_echo_dev_free()...\n"));
1895 return snd_echo_free(chip);
1900 /* <--snd_echo_probe() */
1901 static __devinit int snd_echo_create(struct snd_card *card,
1902 struct pci_dev *pci,
1903 struct echoaudio **rchip)
1905 struct echoaudio *chip;
1908 static struct snd_device_ops ops = {
1909 .dev_free = snd_echo_dev_free,
1914 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1916 if ((err = pci_enable_device(pci)) < 0)
1918 pci_set_master(pci);
1920 /* allocate a chip-specific data */
1921 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1923 pci_disable_device(pci);
1926 DE_INIT(("chip=%p\n", chip));
1928 spin_lock_init(&chip->lock);
1933 /* PCI resource allocation */
1934 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1935 sz = pci_resource_len(pci, 0);
1937 sz = PAGE_SIZE; /* We map only the required part */
1939 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1940 ECHOCARD_NAME)) == NULL) {
1941 snd_echo_free(chip);
1942 snd_printk(KERN_ERR "cannot get memory region\n");
1945 chip->dsp_registers = (volatile u32 __iomem *)
1946 ioremap_nocache(chip->dsp_registers_phys, sz);
1948 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1949 ECHOCARD_NAME, chip)) {
1950 snd_echo_free(chip);
1951 snd_printk(KERN_ERR "cannot grab irq\n");
1954 chip->irq = pci->irq;
1955 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n",
1956 chip->pci, chip->irq, chip->pci->subsystem_device));
1958 /* Create the DSP comm page - this is the area of memory used for most
1959 of the communication with the DSP, which accesses it via bus mastering */
1960 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1961 sizeof(struct comm_page),
1962 &chip->commpage_dma_buf) < 0) {
1963 snd_echo_free(chip);
1964 snd_printk(KERN_ERR "cannot allocate the comm page\n");
1967 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1968 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1970 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1972 DE_INIT(("init_hw err=%d\n", err));
1973 snd_echo_free(chip);
1976 DE_INIT(("Card init OK\n"));
1978 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1979 snd_echo_free(chip);
1982 atomic_set(&chip->opencount, 0);
1983 mutex_init(&chip->mode_mutex);
1984 chip->can_set_rate = 1;
1993 static int __devinit snd_echo_probe(struct pci_dev *pci,
1994 const struct pci_device_id *pci_id)
1997 struct snd_card *card;
1998 struct echoaudio *chip;
2002 if (dev >= SNDRV_CARDS)
2009 DE_INIT(("Echoaudio driver starting...\n"));
2011 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2015 snd_card_set_dev(card, &pci->dev);
2017 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2018 snd_card_free(card);
2022 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
2023 strcpy(card->shortname, chip->card_name);
2026 if (pci_id->device == 0x3410)
2029 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2030 card->shortname, pci_id->subdevice & 0x000f, dsp,
2031 chip->dsp_registers_phys, chip->irq);
2033 if ((err = snd_echo_new_pcm(chip)) < 0) {
2034 snd_printk(KERN_ERR "new pcm error %d\n", err);
2035 snd_card_free(card);
2039 #ifdef ECHOCARD_HAS_MIDI
2040 if (chip->has_midi) { /* Some Mia's do not have midi */
2041 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2042 snd_printk(KERN_ERR "new midi error %d\n", err);
2043 snd_card_free(card);
2049 #ifdef ECHOCARD_HAS_VMIXER
2050 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2051 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2053 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2054 err = snd_ctl_add(chip->card,
2055 snd_ctl_new1(&snd_echo_line_output_gain, chip));
2059 #else /* ECHOCARD_HAS_VMIXER */
2060 err = snd_ctl_add(chip->card,
2061 snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
2064 #endif /* ECHOCARD_HAS_VMIXER */
2066 #ifdef ECHOCARD_HAS_INPUT_GAIN
2067 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2071 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2072 if (!chip->hasnt_input_nominal_level)
2073 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2077 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2078 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2082 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2085 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2088 #ifdef ECHOCARD_HAS_MONITOR
2089 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2090 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2094 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2095 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2099 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2102 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2103 /* Creates a list of available digital modes */
2104 chip->num_digital_modes = 0;
2105 for (i = 0; i < 6; i++)
2106 if (chip->digital_modes & (1 << i))
2107 chip->digital_mode_list[chip->num_digital_modes++] = i;
2109 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2111 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2113 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2114 /* Creates a list of available clock sources */
2115 chip->num_clock_sources = 0;
2116 for (i = 0; i < 10; i++)
2117 if (chip->input_clock_types & (1 << i))
2118 chip->clock_source_list[chip->num_clock_sources++] = i;
2120 if (chip->num_clock_sources > 1) {
2121 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2122 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2125 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2127 #ifdef ECHOCARD_HAS_DIGITAL_IO
2128 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2132 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2133 if (chip->has_phantom_power)
2134 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2138 if ((err = snd_card_register(card)) < 0) {
2139 snd_card_free(card);
2142 snd_printk(KERN_INFO "Card registered: %s\n", card->longname);
2144 pci_set_drvdata(pci, chip);
2149 snd_printk(KERN_ERR "new control error %d\n", err);
2150 snd_card_free(card);
2156 static void __devexit snd_echo_remove(struct pci_dev *pci)
2158 struct echoaudio *chip;
2160 chip = pci_get_drvdata(pci);
2162 snd_card_free(chip->card);
2163 pci_set_drvdata(pci, NULL);
2168 /******************************************************************************
2169 Everything starts and ends here
2170 ******************************************************************************/
2172 /* pci_driver definition */
2173 static struct pci_driver driver = {
2174 .name = "Echoaudio " ECHOCARD_NAME,
2175 .id_table = snd_echo_ids,
2176 .probe = snd_echo_probe,
2177 .remove = __devexit_p(snd_echo_remove),
2182 /* initialization of the module */
2183 static int __init alsa_card_echo_init(void)
2185 return pci_register_driver(&driver);
2190 /* clean up the module */
2191 static void __exit alsa_card_echo_exit(void)
2193 pci_unregister_driver(&driver);
2197 module_init(alsa_card_echo_init)
2198 module_exit(alsa_card_echo_exit)