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);
39 static int get_firmware(const struct firmware **fw_entry,
40 const struct firmware *frm, struct echoaudio *chip)
44 DE_ACT(("firmware requested: %s\n", frm->data));
45 snprintf(name, sizeof(name), "ea/%s", frm->data);
46 if ((err = request_firmware(fw_entry, name, pci_device(chip))) < 0)
47 snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err);
51 static void free_firmware(const struct firmware *fw_entry)
53 release_firmware(fw_entry);
54 DE_ACT(("firmware released\n"));
59 /******************************************************************************
61 ******************************************************************************/
63 static void audiopipe_free(struct snd_pcm_runtime *runtime)
65 struct audiopipe *pipe = runtime->private_data;
67 if (pipe->sgpage.area)
68 snd_dma_free_pages(&pipe->sgpage);
74 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
75 struct snd_pcm_hw_rule *rule)
77 struct snd_interval *c = hw_param_interval(params,
78 SNDRV_PCM_HW_PARAM_CHANNELS);
79 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
84 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
85 /* >=2 channels cannot be S32_BE */
87 fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
88 return snd_mask_refine(f, &fmt);
91 /* > 2 channels cannot be U8 and S32_BE */
93 fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
94 return snd_mask_refine(f, &fmt);
96 /* Mono is ok with any format */
102 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
103 struct snd_pcm_hw_rule *rule)
105 struct snd_interval *c = hw_param_interval(params,
106 SNDRV_PCM_HW_PARAM_CHANNELS);
107 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
108 struct snd_interval ch;
110 snd_interval_any(&ch);
112 /* S32_BE is mono (and stereo) only */
113 if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
115 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
121 return snd_interval_refine(c, &ch);
123 /* U8 can be only mono or stereo */
124 if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
128 return snd_interval_refine(c, &ch);
130 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
136 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
137 struct snd_pcm_hw_rule *rule)
139 struct snd_interval *c = hw_param_interval(params,
140 SNDRV_PCM_HW_PARAM_CHANNELS);
141 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
146 fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
148 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
150 fmask &= SNDRV_PCM_FMTBIT_S16_LE |
151 SNDRV_PCM_FMTBIT_S24_3LE |
152 SNDRV_PCM_FMTBIT_S32_LE;
153 /* 1 channel must be S32_BE or S32_LE */
154 } else if (c->max == 1)
155 fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
156 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
157 /* 2 channels cannot be S32_BE */
158 else if (c->min == 2 && c->max == 2)
159 fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
164 fmt.bits[0] &= (u32)fmask;
165 fmt.bits[1] &= (u32)(fmask >> 32);
166 return snd_mask_refine(f, &fmt);
171 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
172 struct snd_pcm_hw_rule *rule)
174 struct snd_interval *c = hw_param_interval(params,
175 SNDRV_PCM_HW_PARAM_CHANNELS);
176 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
177 struct snd_interval ch;
180 snd_interval_any(&ch);
182 fmask = f->bits[0] + ((u64)f->bits[1] << 32);
184 /* S32_BE is mono (and stereo) only */
185 if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
187 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
192 /* U8 is stereo only */
193 } else if (fmask == SNDRV_PCM_FMTBIT_U8)
195 /* S16_LE and S24_3LE must be at least stereo */
196 else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
197 SNDRV_PCM_FMTBIT_S24_3LE)))
202 return snd_interval_refine(c, &ch);
207 /* Since the sample rate is a global setting, do allow the user to change the
208 sample rate only if there is only one pcm device open. */
209 static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
210 struct snd_pcm_hw_rule *rule)
212 struct snd_interval *rate = hw_param_interval(params,
213 SNDRV_PCM_HW_PARAM_RATE);
214 struct echoaudio *chip = rule->private;
215 struct snd_interval fixed;
217 if (!chip->can_set_rate) {
218 snd_interval_any(&fixed);
219 fixed.min = fixed.max = chip->sample_rate;
220 return snd_interval_refine(rate, &fixed);
226 static int pcm_open(struct snd_pcm_substream *substream,
227 signed char max_channels)
229 struct echoaudio *chip;
230 struct snd_pcm_runtime *runtime;
231 struct audiopipe *pipe;
234 if (max_channels <= 0)
237 chip = snd_pcm_substream_chip(substream);
238 runtime = substream->runtime;
240 pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
243 pipe->index = -1; /* Not configured yet */
245 /* Set up hw capabilities and contraints */
246 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
247 DE_HWP(("max_channels=%d\n", max_channels));
248 pipe->constr.list = channels_list;
249 pipe->constr.mask = 0;
250 for (i = 0; channels_list[i] <= max_channels; i++);
251 pipe->constr.count = i;
252 if (pipe->hw.channels_max > max_channels)
253 pipe->hw.channels_max = max_channels;
254 if (chip->digital_mode == DIGITAL_MODE_ADAT) {
255 pipe->hw.rate_max = 48000;
256 pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
259 runtime->hw = pipe->hw;
260 runtime->private_data = pipe;
261 runtime->private_free = audiopipe_free;
262 snd_pcm_set_sync(substream);
264 /* Only mono and any even number of channels are allowed */
265 if ((err = snd_pcm_hw_constraint_list(runtime, 0,
266 SNDRV_PCM_HW_PARAM_CHANNELS,
270 /* All periods should have the same size */
271 if ((err = snd_pcm_hw_constraint_integer(runtime,
272 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
275 /* The hw accesses memory in chunks 32 frames long and they should be
276 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
277 generated with a resolution of 32 frames. Thus we need the following */
278 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
279 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
282 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
283 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
287 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
288 SNDRV_PCM_HW_PARAM_RATE,
289 hw_rule_sample_rate, chip,
290 SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
293 /* Finally allocate a page for the scatter-gather list */
294 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
295 snd_dma_pci_data(chip->pci),
296 PAGE_SIZE, &pipe->sgpage)) < 0) {
297 DE_HWP(("s-g list allocation failed\n"));
306 static int pcm_analog_in_open(struct snd_pcm_substream *substream)
308 struct echoaudio *chip = snd_pcm_substream_chip(substream);
311 DE_ACT(("pcm_analog_in_open\n"));
312 if ((err = pcm_open(substream, num_analog_busses_in(chip) -
313 substream->number)) < 0)
315 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
316 SNDRV_PCM_HW_PARAM_CHANNELS,
317 hw_rule_capture_channels_by_format, NULL,
318 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
320 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
321 SNDRV_PCM_HW_PARAM_FORMAT,
322 hw_rule_capture_format_by_channels, NULL,
323 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
325 atomic_inc(&chip->opencount);
326 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
327 chip->can_set_rate=0;
328 DE_HWP(("pcm_analog_in_open cs=%d oc=%d r=%d\n",
329 chip->can_set_rate, atomic_read(&chip->opencount),
336 static int pcm_analog_out_open(struct snd_pcm_substream *substream)
338 struct echoaudio *chip = snd_pcm_substream_chip(substream);
339 int max_channels, err;
341 #ifdef ECHOCARD_HAS_VMIXER
342 max_channels = num_pipes_out(chip);
344 max_channels = num_analog_busses_out(chip);
346 DE_ACT(("pcm_analog_out_open\n"));
347 if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
349 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
350 SNDRV_PCM_HW_PARAM_CHANNELS,
351 hw_rule_playback_channels_by_format,
353 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
355 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
356 SNDRV_PCM_HW_PARAM_FORMAT,
357 hw_rule_playback_format_by_channels,
359 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
361 atomic_inc(&chip->opencount);
362 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
363 chip->can_set_rate=0;
364 DE_HWP(("pcm_analog_out_open cs=%d oc=%d r=%d\n",
365 chip->can_set_rate, atomic_read(&chip->opencount),
372 #ifdef ECHOCARD_HAS_DIGITAL_IO
374 static int pcm_digital_in_open(struct snd_pcm_substream *substream)
376 struct echoaudio *chip = snd_pcm_substream_chip(substream);
377 int err, max_channels;
379 DE_ACT(("pcm_digital_in_open\n"));
380 max_channels = num_digital_busses_in(chip) - substream->number;
381 mutex_lock(&chip->mode_mutex);
382 if (chip->digital_mode == DIGITAL_MODE_ADAT)
383 err = pcm_open(substream, max_channels);
384 else /* If the card has ADAT, subtract the 6 channels
385 * that S/PDIF doesn't have
387 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
392 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
393 SNDRV_PCM_HW_PARAM_CHANNELS,
394 hw_rule_capture_channels_by_format, NULL,
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_capture_format_by_channels, NULL,
400 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;
408 mutex_unlock(&chip->mode_mutex);
414 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
416 static int pcm_digital_out_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_out_open\n"));
422 max_channels = num_digital_busses_out(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_playback_channels_by_format,
437 NULL, SNDRV_PCM_HW_PARAM_FORMAT,
440 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
441 SNDRV_PCM_HW_PARAM_FORMAT,
442 hw_rule_playback_format_by_channels,
443 NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
446 atomic_inc(&chip->opencount);
447 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
448 chip->can_set_rate=0;
450 mutex_unlock(&chip->mode_mutex);
454 #endif /* !ECHOCARD_HAS_VMIXER */
456 #endif /* ECHOCARD_HAS_DIGITAL_IO */
460 static int pcm_close(struct snd_pcm_substream *substream)
462 struct echoaudio *chip = snd_pcm_substream_chip(substream);
465 /* Nothing to do here. Audio is already off and pipe will be
466 * freed by its callback
468 DE_ACT(("pcm_close\n"));
470 atomic_dec(&chip->opencount);
471 oc = atomic_read(&chip->opencount);
472 DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc,
473 chip->can_set_rate, chip->rate_set));
475 chip->can_set_rate = 1;
478 DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc,
479 chip->can_set_rate,chip->rate_set));
486 /* Channel allocation and scatter-gather list setup */
487 static int init_engine(struct snd_pcm_substream *substream,
488 struct snd_pcm_hw_params *hw_params,
489 int pipe_index, int interleave)
491 struct echoaudio *chip;
492 int err, per, rest, page, edge, offs;
493 struct snd_sg_buf *sgbuf;
494 struct audiopipe *pipe;
496 chip = snd_pcm_substream_chip(substream);
497 pipe = (struct audiopipe *) substream->runtime->private_data;
499 /* Sets up che hardware. If it's already initialized, reset and
500 * redo with the new parameters
502 spin_lock_irq(&chip->lock);
503 if (pipe->index >= 0) {
504 DE_HWP(("hwp_ie free(%d)\n", pipe->index));
505 err = free_pipes(chip, pipe);
507 chip->substream[pipe->index] = NULL;
510 err = allocate_pipes(chip, pipe, pipe_index, interleave);
512 spin_unlock_irq(&chip->lock);
513 DE_ACT((KERN_NOTICE "allocate_pipes(%d) err=%d\n",
517 spin_unlock_irq(&chip->lock);
518 DE_ACT((KERN_NOTICE "allocate_pipes()=%d\n", pipe_index));
520 DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
521 params_buffer_bytes(hw_params), params_periods(hw_params),
522 params_period_bytes(hw_params)));
523 err = snd_pcm_lib_malloc_pages(substream,
524 params_buffer_bytes(hw_params));
526 snd_printk(KERN_ERR "malloc_pages err=%d\n", err);
527 spin_lock_irq(&chip->lock);
528 free_pipes(chip, pipe);
529 spin_unlock_irq(&chip->lock);
534 sgbuf = snd_pcm_substream_sgbuf(substream);
536 DE_HWP(("pcm_hw_params table size=%d pages=%d\n",
537 sgbuf->size, sgbuf->pages));
538 sglist_init(chip, pipe);
540 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
542 rest = params_period_bytes(hw_params);
543 if (offs + rest > params_buffer_bytes(hw_params))
544 rest = params_buffer_bytes(hw_params) - offs;
546 if (rest <= edge - offs) {
547 sglist_add_mapping(chip, pipe,
548 snd_sgbuf_get_addr(sgbuf, offs),
550 sglist_add_irq(chip, pipe);
554 sglist_add_mapping(chip, pipe,
555 snd_sgbuf_get_addr(sgbuf, offs),
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 /******************* PCM output volume *******************/
960 static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
961 struct snd_ctl_elem_info *uinfo)
963 struct echoaudio *chip;
965 chip = snd_kcontrol_chip(kcontrol);
966 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
967 uinfo->count = num_busses_out(chip);
968 uinfo->value.integer.min = ECHOGAIN_MINOUT;
969 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
973 static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
974 struct snd_ctl_elem_value *ucontrol)
976 struct echoaudio *chip;
979 chip = snd_kcontrol_chip(kcontrol);
980 for (c = 0; c < num_busses_out(chip); c++)
981 ucontrol->value.integer.value[c] = chip->output_gain[c];
985 static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
986 struct snd_ctl_elem_value *ucontrol)
988 struct echoaudio *chip;
989 int c, changed, gain;
992 chip = snd_kcontrol_chip(kcontrol);
993 spin_lock_irq(&chip->lock);
994 for (c = 0; c < num_busses_out(chip); c++) {
995 gain = ucontrol->value.integer.value[c];
996 /* Ignore out of range values */
997 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
999 if (chip->output_gain[c] != gain) {
1000 set_output_gain(chip, c, gain);
1005 update_output_line_level(chip);
1006 spin_unlock_irq(&chip->lock);
1010 #ifdef ECHOCARD_HAS_VMIXER
1011 /* On Vmixer cards this one controls the line-out volume */
1012 static struct snd_kcontrol_new snd_echo_line_output_gain __devinitdata = {
1013 .name = "Line Playback Volume",
1014 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1015 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1016 .info = snd_echo_output_gain_info,
1017 .get = snd_echo_output_gain_get,
1018 .put = snd_echo_output_gain_put,
1019 .tlv = {.p = db_scale_output_gain},
1022 static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1023 .name = "PCM Playback Volume",
1024 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1025 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1026 .info = snd_echo_output_gain_info,
1027 .get = snd_echo_output_gain_get,
1028 .put = snd_echo_output_gain_put,
1029 .tlv = {.p = db_scale_output_gain},
1035 #ifdef ECHOCARD_HAS_INPUT_GAIN
1037 /******************* Analog input volume *******************/
1038 static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
1039 struct snd_ctl_elem_info *uinfo)
1041 struct echoaudio *chip;
1043 chip = snd_kcontrol_chip(kcontrol);
1044 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1045 uinfo->count = num_analog_busses_in(chip);
1046 uinfo->value.integer.min = ECHOGAIN_MININP;
1047 uinfo->value.integer.max = ECHOGAIN_MAXINP;
1051 static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
1052 struct snd_ctl_elem_value *ucontrol)
1054 struct echoaudio *chip;
1057 chip = snd_kcontrol_chip(kcontrol);
1058 for (c = 0; c < num_analog_busses_in(chip); c++)
1059 ucontrol->value.integer.value[c] = chip->input_gain[c];
1063 static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
1064 struct snd_ctl_elem_value *ucontrol)
1066 struct echoaudio *chip;
1067 int c, gain, changed;
1070 chip = snd_kcontrol_chip(kcontrol);
1071 spin_lock_irq(&chip->lock);
1072 for (c = 0; c < num_analog_busses_in(chip); c++) {
1073 gain = ucontrol->value.integer.value[c];
1074 /* Ignore out of range values */
1075 if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
1077 if (chip->input_gain[c] != gain) {
1078 set_input_gain(chip, c, gain);
1083 update_input_line_level(chip);
1084 spin_unlock_irq(&chip->lock);
1088 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain, -2500, 50, 0);
1090 static struct snd_kcontrol_new snd_echo_line_input_gain __devinitdata = {
1091 .name = "Line Capture Volume",
1092 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1093 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1094 .info = snd_echo_input_gain_info,
1095 .get = snd_echo_input_gain_get,
1096 .put = snd_echo_input_gain_put,
1097 .tlv = {.p = db_scale_input_gain},
1100 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1104 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1106 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1107 static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
1108 struct snd_ctl_elem_info *uinfo)
1110 struct echoaudio *chip;
1112 chip = snd_kcontrol_chip(kcontrol);
1113 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1114 uinfo->count = num_analog_busses_out(chip);
1115 uinfo->value.integer.min = 0;
1116 uinfo->value.integer.max = 1;
1120 static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
1121 struct snd_ctl_elem_value *ucontrol)
1123 struct echoaudio *chip;
1126 chip = snd_kcontrol_chip(kcontrol);
1127 for (c = 0; c < num_analog_busses_out(chip); c++)
1128 ucontrol->value.integer.value[c] = chip->nominal_level[c];
1132 static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
1133 struct snd_ctl_elem_value *ucontrol)
1135 struct echoaudio *chip;
1139 chip = snd_kcontrol_chip(kcontrol);
1140 spin_lock_irq(&chip->lock);
1141 for (c = 0; c < num_analog_busses_out(chip); c++) {
1142 if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
1143 set_nominal_level(chip, c,
1144 ucontrol->value.integer.value[c]);
1149 update_output_line_level(chip);
1150 spin_unlock_irq(&chip->lock);
1154 static struct snd_kcontrol_new snd_echo_output_nominal_level __devinitdata = {
1155 .name = "Line Playback Switch (-10dBV)",
1156 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1157 .info = snd_echo_output_nominal_info,
1158 .get = snd_echo_output_nominal_get,
1159 .put = snd_echo_output_nominal_put,
1162 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1166 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1168 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1169 static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
1170 struct snd_ctl_elem_info *uinfo)
1172 struct echoaudio *chip;
1174 chip = snd_kcontrol_chip(kcontrol);
1175 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1176 uinfo->count = num_analog_busses_in(chip);
1177 uinfo->value.integer.min = 0;
1178 uinfo->value.integer.max = 1;
1182 static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
1183 struct snd_ctl_elem_value *ucontrol)
1185 struct echoaudio *chip;
1188 chip = snd_kcontrol_chip(kcontrol);
1189 for (c = 0; c < num_analog_busses_in(chip); c++)
1190 ucontrol->value.integer.value[c] =
1191 chip->nominal_level[bx_analog_in(chip) + c];
1195 static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
1196 struct snd_ctl_elem_value *ucontrol)
1198 struct echoaudio *chip;
1202 chip = snd_kcontrol_chip(kcontrol);
1203 spin_lock_irq(&chip->lock);
1204 for (c = 0; c < num_analog_busses_in(chip); c++) {
1205 if (chip->nominal_level[bx_analog_in(chip) + c] !=
1206 ucontrol->value.integer.value[c]) {
1207 set_nominal_level(chip, bx_analog_in(chip) + c,
1208 ucontrol->value.integer.value[c]);
1213 update_output_line_level(chip); /* "Output" is not a mistake
1216 spin_unlock_irq(&chip->lock);
1220 static struct snd_kcontrol_new snd_echo_intput_nominal_level __devinitdata = {
1221 .name = "Line Capture Switch (-10dBV)",
1222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1223 .info = snd_echo_input_nominal_info,
1224 .get = snd_echo_input_nominal_get,
1225 .put = snd_echo_input_nominal_put,
1228 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1232 #ifdef ECHOCARD_HAS_MONITOR
1234 /******************* Monitor mixer *******************/
1235 static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1236 struct snd_ctl_elem_info *uinfo)
1238 struct echoaudio *chip;
1240 chip = snd_kcontrol_chip(kcontrol);
1241 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1243 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1244 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1245 uinfo->dimen.d[0] = num_busses_out(chip);
1246 uinfo->dimen.d[1] = num_busses_in(chip);
1250 static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1251 struct snd_ctl_elem_value *ucontrol)
1253 struct echoaudio *chip;
1255 chip = snd_kcontrol_chip(kcontrol);
1256 ucontrol->value.integer.value[0] =
1257 chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)]
1258 [ucontrol->id.index % num_busses_in(chip)];
1262 static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1263 struct snd_ctl_elem_value *ucontrol)
1265 struct echoaudio *chip;
1270 chip = snd_kcontrol_chip(kcontrol);
1271 out = ucontrol->id.index / num_busses_in(chip);
1272 in = ucontrol->id.index % num_busses_in(chip);
1273 gain = ucontrol->value.integer.value[0];
1274 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1276 if (chip->monitor_gain[out][in] != gain) {
1277 spin_lock_irq(&chip->lock);
1278 set_monitor_gain(chip, out, in, gain);
1279 update_output_line_level(chip);
1280 spin_unlock_irq(&chip->lock);
1286 static struct snd_kcontrol_new snd_echo_monitor_mixer __devinitdata = {
1287 .name = "Monitor Mixer Volume",
1288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1289 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1290 .info = snd_echo_mixer_info,
1291 .get = snd_echo_mixer_get,
1292 .put = snd_echo_mixer_put,
1293 .tlv = {.p = db_scale_output_gain},
1296 #endif /* ECHOCARD_HAS_MONITOR */
1300 #ifdef ECHOCARD_HAS_VMIXER
1302 /******************* Vmixer *******************/
1303 static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
1304 struct snd_ctl_elem_info *uinfo)
1306 struct echoaudio *chip;
1308 chip = snd_kcontrol_chip(kcontrol);
1309 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1311 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1312 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1313 uinfo->dimen.d[0] = num_busses_out(chip);
1314 uinfo->dimen.d[1] = num_pipes_out(chip);
1318 static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
1319 struct snd_ctl_elem_value *ucontrol)
1321 struct echoaudio *chip;
1323 chip = snd_kcontrol_chip(kcontrol);
1324 ucontrol->value.integer.value[0] =
1325 chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
1326 [ucontrol->id.index % num_pipes_out(chip)];
1330 static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
1331 struct snd_ctl_elem_value *ucontrol)
1333 struct echoaudio *chip;
1338 chip = snd_kcontrol_chip(kcontrol);
1339 out = ucontrol->id.index / num_pipes_out(chip);
1340 vch = ucontrol->id.index % num_pipes_out(chip);
1341 gain = ucontrol->value.integer.value[0];
1342 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1344 if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
1345 spin_lock_irq(&chip->lock);
1346 set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
1347 update_vmixer_level(chip);
1348 spin_unlock_irq(&chip->lock);
1354 static struct snd_kcontrol_new snd_echo_vmixer __devinitdata = {
1355 .name = "VMixer Volume",
1356 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1357 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1358 .info = snd_echo_vmixer_info,
1359 .get = snd_echo_vmixer_get,
1360 .put = snd_echo_vmixer_put,
1361 .tlv = {.p = db_scale_output_gain},
1364 #endif /* ECHOCARD_HAS_VMIXER */
1368 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1370 /******************* Digital mode switch *******************/
1371 static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1372 struct snd_ctl_elem_info *uinfo)
1374 static char *names[4] = {
1375 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1378 struct echoaudio *chip;
1380 chip = snd_kcontrol_chip(kcontrol);
1381 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1382 uinfo->value.enumerated.items = chip->num_digital_modes;
1384 if (uinfo->value.enumerated.item >= chip->num_digital_modes)
1385 uinfo->value.enumerated.item = chip->num_digital_modes - 1;
1386 strcpy(uinfo->value.enumerated.name, names[
1387 chip->digital_mode_list[uinfo->value.enumerated.item]]);
1391 static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
1392 struct snd_ctl_elem_value *ucontrol)
1394 struct echoaudio *chip;
1397 chip = snd_kcontrol_chip(kcontrol);
1398 mode = chip->digital_mode;
1399 for (i = chip->num_digital_modes - 1; i >= 0; i--)
1400 if (mode == chip->digital_mode_list[i]) {
1401 ucontrol->value.enumerated.item[0] = i;
1407 static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1408 struct snd_ctl_elem_value *ucontrol)
1410 struct echoaudio *chip;
1412 unsigned short emode, dmode;
1415 chip = snd_kcontrol_chip(kcontrol);
1417 emode = ucontrol->value.enumerated.item[0];
1418 if (emode >= chip->num_digital_modes)
1420 dmode = chip->digital_mode_list[emode];
1422 if (dmode != chip->digital_mode) {
1423 /* mode_mutex is required to make this operation atomic wrt
1424 pcm_digital_*_open() and set_input_clock() functions. */
1425 mutex_lock(&chip->mode_mutex);
1427 /* Do not allow the user to change the digital mode when a pcm
1428 device is open because it also changes the number of channels
1429 and the allowed sample rates */
1430 if (atomic_read(&chip->opencount)) {
1433 changed = set_digital_mode(chip, dmode);
1434 /* If we had to change the clock source, report it */
1435 if (changed > 0 && chip->clock_src_ctl) {
1436 snd_ctl_notify(chip->card,
1437 SNDRV_CTL_EVENT_MASK_VALUE,
1438 &chip->clock_src_ctl->id);
1439 DE_ACT(("SDM() =%d\n", changed));
1442 changed = 1; /* No errors */
1444 mutex_unlock(&chip->mode_mutex);
1449 static struct snd_kcontrol_new snd_echo_digital_mode_switch __devinitdata = {
1450 .name = "Digital mode Switch",
1451 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1452 .info = snd_echo_digital_mode_info,
1453 .get = snd_echo_digital_mode_get,
1454 .put = snd_echo_digital_mode_put,
1457 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1461 #ifdef ECHOCARD_HAS_DIGITAL_IO
1463 /******************* S/PDIF mode switch *******************/
1464 static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1465 struct snd_ctl_elem_info *uinfo)
1467 static char *names[2] = {"Consumer", "Professional"};
1469 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1470 uinfo->value.enumerated.items = 2;
1472 if (uinfo->value.enumerated.item)
1473 uinfo->value.enumerated.item = 1;
1474 strcpy(uinfo->value.enumerated.name,
1475 names[uinfo->value.enumerated.item]);
1479 static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
1480 struct snd_ctl_elem_value *ucontrol)
1482 struct echoaudio *chip;
1484 chip = snd_kcontrol_chip(kcontrol);
1485 ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
1489 static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
1490 struct snd_ctl_elem_value *ucontrol)
1492 struct echoaudio *chip;
1495 chip = snd_kcontrol_chip(kcontrol);
1496 mode = !!ucontrol->value.enumerated.item[0];
1497 if (mode != chip->professional_spdif) {
1498 spin_lock_irq(&chip->lock);
1499 set_professional_spdif(chip, mode);
1500 spin_unlock_irq(&chip->lock);
1506 static struct snd_kcontrol_new snd_echo_spdif_mode_switch __devinitdata = {
1507 .name = "S/PDIF mode Switch",
1508 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1509 .info = snd_echo_spdif_mode_info,
1510 .get = snd_echo_spdif_mode_get,
1511 .put = snd_echo_spdif_mode_put,
1514 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1518 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1520 /******************* Select input clock source *******************/
1521 static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1522 struct snd_ctl_elem_info *uinfo)
1524 static char *names[8] = {
1525 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1528 struct echoaudio *chip;
1530 chip = snd_kcontrol_chip(kcontrol);
1531 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1532 uinfo->value.enumerated.items = chip->num_clock_sources;
1534 if (uinfo->value.enumerated.item >= chip->num_clock_sources)
1535 uinfo->value.enumerated.item = chip->num_clock_sources - 1;
1536 strcpy(uinfo->value.enumerated.name, names[
1537 chip->clock_source_list[uinfo->value.enumerated.item]]);
1541 static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
1542 struct snd_ctl_elem_value *ucontrol)
1544 struct echoaudio *chip;
1547 chip = snd_kcontrol_chip(kcontrol);
1548 clock = chip->input_clock;
1550 for (i = 0; i < chip->num_clock_sources; i++)
1551 if (clock == chip->clock_source_list[i])
1552 ucontrol->value.enumerated.item[0] = i;
1557 static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1558 struct snd_ctl_elem_value *ucontrol)
1560 struct echoaudio *chip;
1562 unsigned int eclock, dclock;
1565 chip = snd_kcontrol_chip(kcontrol);
1566 eclock = ucontrol->value.enumerated.item[0];
1567 if (eclock >= chip->input_clock_types)
1569 dclock = chip->clock_source_list[eclock];
1570 if (chip->input_clock != dclock) {
1571 mutex_lock(&chip->mode_mutex);
1572 spin_lock_irq(&chip->lock);
1573 if ((changed = set_input_clock(chip, dclock)) == 0)
1574 changed = 1; /* no errors */
1575 spin_unlock_irq(&chip->lock);
1576 mutex_unlock(&chip->mode_mutex);
1580 DE_ACT(("seticlk val%d err 0x%x\n", dclock, changed));
1585 static struct snd_kcontrol_new snd_echo_clock_source_switch __devinitdata = {
1586 .name = "Sample Clock Source",
1587 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1588 .info = snd_echo_clock_source_info,
1589 .get = snd_echo_clock_source_get,
1590 .put = snd_echo_clock_source_put,
1593 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1597 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1599 /******************* Phantom power switch *******************/
1600 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1602 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1603 struct snd_ctl_elem_value *ucontrol)
1605 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1607 ucontrol->value.integer.value[0] = chip->phantom_power;
1611 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1612 struct snd_ctl_elem_value *ucontrol)
1614 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1615 int power, changed = 0;
1617 power = !!ucontrol->value.integer.value[0];
1618 if (chip->phantom_power != power) {
1619 spin_lock_irq(&chip->lock);
1620 changed = set_phantom_power(chip, power);
1621 spin_unlock_irq(&chip->lock);
1623 changed = 1; /* no errors */
1628 static struct snd_kcontrol_new snd_echo_phantom_power_switch __devinitdata = {
1629 .name = "Phantom power Switch",
1630 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1631 .info = snd_echo_phantom_power_info,
1632 .get = snd_echo_phantom_power_get,
1633 .put = snd_echo_phantom_power_put,
1636 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1640 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1642 /******************* Digital input automute switch *******************/
1643 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1645 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1646 struct snd_ctl_elem_value *ucontrol)
1648 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1650 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1654 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1655 struct snd_ctl_elem_value *ucontrol)
1657 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1658 int automute, changed = 0;
1660 automute = !!ucontrol->value.integer.value[0];
1661 if (chip->digital_in_automute != automute) {
1662 spin_lock_irq(&chip->lock);
1663 changed = set_input_auto_mute(chip, automute);
1664 spin_unlock_irq(&chip->lock);
1666 changed = 1; /* no errors */
1671 static struct snd_kcontrol_new snd_echo_automute_switch __devinitdata = {
1672 .name = "Digital Capture Switch (automute)",
1673 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1674 .info = snd_echo_automute_info,
1675 .get = snd_echo_automute_get,
1676 .put = snd_echo_automute_put,
1679 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1683 /******************* VU-meters switch *******************/
1684 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1686 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1687 struct snd_ctl_elem_value *ucontrol)
1689 struct echoaudio *chip;
1691 chip = snd_kcontrol_chip(kcontrol);
1692 spin_lock_irq(&chip->lock);
1693 set_meters_on(chip, ucontrol->value.integer.value[0]);
1694 spin_unlock_irq(&chip->lock);
1698 static struct snd_kcontrol_new snd_echo_vumeters_switch __devinitdata = {
1699 .name = "VU-meters Switch",
1700 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1701 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1702 .info = snd_echo_vumeters_switch_info,
1703 .put = snd_echo_vumeters_switch_put,
1708 /***** Read VU-meters (input, output, analog and digital together) *****/
1709 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1710 struct snd_ctl_elem_info *uinfo)
1712 struct echoaudio *chip;
1714 chip = snd_kcontrol_chip(kcontrol);
1715 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1717 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1718 uinfo->value.integer.max = 0;
1719 #ifdef ECHOCARD_HAS_VMIXER
1720 uinfo->dimen.d[0] = 3; /* Out, In, Virt */
1722 uinfo->dimen.d[0] = 2; /* Out, In */
1724 uinfo->dimen.d[1] = 16; /* 16 channels */
1725 uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */
1729 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol)
1732 struct echoaudio *chip;
1734 chip = snd_kcontrol_chip(kcontrol);
1735 get_audio_meters(chip, ucontrol->value.integer.value);
1739 static struct snd_kcontrol_new snd_echo_vumeters __devinitdata = {
1740 .name = "VU-meters",
1741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1742 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1743 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
1744 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1745 .info = snd_echo_vumeters_info,
1746 .get = snd_echo_vumeters_get,
1747 .tlv = {.p = db_scale_output_gain},
1752 /*** Channels info - it exports informations about the number of channels ***/
1753 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1754 struct snd_ctl_elem_info *uinfo)
1756 struct echoaudio *chip;
1758 chip = snd_kcontrol_chip(kcontrol);
1759 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1761 uinfo->value.integer.min = 0;
1762 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1766 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1767 struct snd_ctl_elem_value *ucontrol)
1769 struct echoaudio *chip;
1770 int detected, clocks, bit, src;
1772 chip = snd_kcontrol_chip(kcontrol);
1773 ucontrol->value.integer.value[0] = num_busses_in(chip);
1774 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1775 ucontrol->value.integer.value[2] = num_busses_out(chip);
1776 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1777 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1779 /* Compute the bitmask of the currently valid input clocks */
1780 detected = detect_input_clocks(chip);
1782 src = chip->num_clock_sources - 1;
1783 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1784 if (detected & (1 << bit))
1785 for (; src >= 0; src--)
1786 if (bit == chip->clock_source_list[src]) {
1790 ucontrol->value.integer.value[5] = clocks;
1795 static struct snd_kcontrol_new snd_echo_channels_info __devinitdata = {
1796 .name = "Channels info",
1797 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1798 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1799 .info = snd_echo_channels_info_info,
1800 .get = snd_echo_channels_info_get,
1806 /******************************************************************************
1808 ******************************************************************************/
1810 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1812 struct echoaudio *chip = dev_id;
1813 struct snd_pcm_substream *substream;
1816 spin_lock(&chip->lock);
1817 st = service_irq(chip);
1819 spin_unlock(&chip->lock);
1822 /* The hardware doesn't tell us which substream caused the irq,
1823 thus we have to check all running substreams. */
1824 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1825 if ((substream = chip->substream[ss])) {
1826 period = pcm_pointer(substream) /
1827 substream->runtime->period_size;
1828 if (period != chip->last_period[ss]) {
1829 chip->last_period[ss] = period;
1830 spin_unlock(&chip->lock);
1831 snd_pcm_period_elapsed(substream);
1832 spin_lock(&chip->lock);
1836 spin_unlock(&chip->lock);
1838 #ifdef ECHOCARD_HAS_MIDI
1839 if (st > 0 && chip->midi_in) {
1840 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1841 DE_MID(("rawmidi_iread=%d\n", st));
1850 /******************************************************************************
1851 Module construction / destruction
1852 ******************************************************************************/
1854 static int snd_echo_free(struct echoaudio *chip)
1856 DE_INIT(("Stop DSP...\n"));
1857 if (chip->comm_page)
1858 rest_in_peace(chip);
1859 DE_INIT(("Stopped.\n"));
1862 free_irq(chip->irq, chip);
1864 if (chip->comm_page)
1865 snd_dma_free_pages(&chip->commpage_dma_buf);
1867 if (chip->dsp_registers)
1868 iounmap(chip->dsp_registers);
1871 release_and_free_resource(chip->iores);
1873 DE_INIT(("MMIO freed.\n"));
1875 pci_disable_device(chip->pci);
1877 /* release chip data */
1879 DE_INIT(("Chip freed.\n"));
1885 static int snd_echo_dev_free(struct snd_device *device)
1887 struct echoaudio *chip = device->device_data;
1889 DE_INIT(("snd_echo_dev_free()...\n"));
1890 return snd_echo_free(chip);
1895 /* <--snd_echo_probe() */
1896 static __devinit int snd_echo_create(struct snd_card *card,
1897 struct pci_dev *pci,
1898 struct echoaudio **rchip)
1900 struct echoaudio *chip;
1903 static struct snd_device_ops ops = {
1904 .dev_free = snd_echo_dev_free,
1909 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1911 if ((err = pci_enable_device(pci)) < 0)
1913 pci_set_master(pci);
1915 /* allocate a chip-specific data */
1916 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1918 pci_disable_device(pci);
1921 DE_INIT(("chip=%p\n", chip));
1923 spin_lock_init(&chip->lock);
1928 /* PCI resource allocation */
1929 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1930 sz = pci_resource_len(pci, 0);
1932 sz = PAGE_SIZE; /* We map only the required part */
1934 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1935 ECHOCARD_NAME)) == NULL) {
1936 snd_echo_free(chip);
1937 snd_printk(KERN_ERR "cannot get memory region\n");
1940 chip->dsp_registers = (volatile u32 __iomem *)
1941 ioremap_nocache(chip->dsp_registers_phys, sz);
1943 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1944 ECHOCARD_NAME, chip)) {
1945 snd_echo_free(chip);
1946 snd_printk(KERN_ERR "cannot grab irq\n");
1949 chip->irq = pci->irq;
1950 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n",
1951 chip->pci, chip->irq, chip->pci->subsystem_device));
1953 /* Create the DSP comm page - this is the area of memory used for most
1954 of the communication with the DSP, which accesses it via bus mastering */
1955 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1956 sizeof(struct comm_page),
1957 &chip->commpage_dma_buf) < 0) {
1958 snd_echo_free(chip);
1959 snd_printk(KERN_ERR "cannot allocate the comm page\n");
1962 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1963 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1965 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1967 DE_INIT(("init_hw err=%d\n", err));
1968 snd_echo_free(chip);
1971 DE_INIT(("Card init OK\n"));
1973 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1974 snd_echo_free(chip);
1977 atomic_set(&chip->opencount, 0);
1978 mutex_init(&chip->mode_mutex);
1979 chip->can_set_rate = 1;
1988 static int __devinit snd_echo_probe(struct pci_dev *pci,
1989 const struct pci_device_id *pci_id)
1992 struct snd_card *card;
1993 struct echoaudio *chip;
1997 if (dev >= SNDRV_CARDS)
2004 DE_INIT(("Echoaudio driver starting...\n"));
2006 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2010 snd_card_set_dev(card, &pci->dev);
2012 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2013 snd_card_free(card);
2017 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
2018 strcpy(card->shortname, chip->card_name);
2021 if (pci_id->device == 0x3410)
2024 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2025 card->shortname, pci_id->subdevice & 0x000f, dsp,
2026 chip->dsp_registers_phys, chip->irq);
2028 if ((err = snd_echo_new_pcm(chip)) < 0) {
2029 snd_printk(KERN_ERR "new pcm error %d\n", err);
2030 snd_card_free(card);
2034 #ifdef ECHOCARD_HAS_MIDI
2035 if (chip->has_midi) { /* Some Mia's do not have midi */
2036 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2037 snd_printk(KERN_ERR "new midi error %d\n", err);
2038 snd_card_free(card);
2044 #ifdef ECHOCARD_HAS_VMIXER
2045 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2046 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_output_gain, chip))) < 0)
2048 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2051 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_pcm_output_gain, chip))) < 0)
2055 #ifdef ECHOCARD_HAS_INPUT_GAIN
2056 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2060 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2061 if (!chip->hasnt_input_nominal_level)
2062 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2066 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2067 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2071 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2074 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2077 #ifdef ECHOCARD_HAS_MONITOR
2078 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2079 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2083 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2084 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2088 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2091 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2092 /* Creates a list of available digital modes */
2093 chip->num_digital_modes = 0;
2094 for (i = 0; i < 6; i++)
2095 if (chip->digital_modes & (1 << i))
2096 chip->digital_mode_list[chip->num_digital_modes++] = i;
2098 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2100 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2102 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2103 /* Creates a list of available clock sources */
2104 chip->num_clock_sources = 0;
2105 for (i = 0; i < 10; i++)
2106 if (chip->input_clock_types & (1 << i))
2107 chip->clock_source_list[chip->num_clock_sources++] = i;
2109 if (chip->num_clock_sources > 1) {
2110 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2111 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2114 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2116 #ifdef ECHOCARD_HAS_DIGITAL_IO
2117 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2121 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2122 if (chip->has_phantom_power)
2123 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2127 if ((err = snd_card_register(card)) < 0) {
2128 snd_card_free(card);
2131 snd_printk(KERN_INFO "Card registered: %s\n", card->longname);
2133 pci_set_drvdata(pci, chip);
2138 snd_printk(KERN_ERR "new control error %d\n", err);
2139 snd_card_free(card);
2145 static void __devexit snd_echo_remove(struct pci_dev *pci)
2147 struct echoaudio *chip;
2149 chip = pci_get_drvdata(pci);
2151 snd_card_free(chip->card);
2152 pci_set_drvdata(pci, NULL);
2157 /******************************************************************************
2158 Everything starts and ends here
2159 ******************************************************************************/
2161 /* pci_driver definition */
2162 static struct pci_driver driver = {
2163 .name = "Echoaudio " ECHOCARD_NAME,
2164 .id_table = snd_echo_ids,
2165 .probe = snd_echo_probe,
2166 .remove = __devexit_p(snd_echo_remove),
2171 /* initialization of the module */
2172 static int __init alsa_card_echo_init(void)
2174 return pci_register_driver(&driver);
2179 /* clean up the module */
2180 static void __exit alsa_card_echo_exit(void)
2182 pci_unregister_driver(&driver);
2186 module_init(alsa_card_echo_init)
2187 module_exit(alsa_card_echo_exit)