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};
38 static int get_firmware(const struct firmware **fw_entry,
39 const struct firmware *frm, struct echoaudio *chip)
43 DE_ACT(("firmware requested: %s\n", frm->data));
44 snprintf(name, sizeof(name), "ea/%s", frm->data);
45 if ((err = request_firmware(fw_entry, name, pci_device(chip))) < 0)
46 snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err);
50 static void free_firmware(const struct firmware *fw_entry)
52 release_firmware(fw_entry);
53 DE_ACT(("firmware released\n"));
58 /******************************************************************************
60 ******************************************************************************/
62 static void audiopipe_free(struct snd_pcm_runtime *runtime)
64 struct audiopipe *pipe = runtime->private_data;
66 if (pipe->sgpage.area)
67 snd_dma_free_pages(&pipe->sgpage);
73 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params,
74 struct snd_pcm_hw_rule *rule)
76 struct snd_interval *c = hw_param_interval(params,
77 SNDRV_PCM_HW_PARAM_CHANNELS);
78 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
83 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
84 /* >=2 channels cannot be S32_BE */
86 fmt.bits[0] &= ~SNDRV_PCM_FMTBIT_S32_BE;
87 return snd_mask_refine(f, &fmt);
90 /* > 2 channels cannot be U8 and S32_BE */
92 fmt.bits[0] &= ~(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_BE);
93 return snd_mask_refine(f, &fmt);
95 /* Mono is ok with any format */
101 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params,
102 struct snd_pcm_hw_rule *rule)
104 struct snd_interval *c = hw_param_interval(params,
105 SNDRV_PCM_HW_PARAM_CHANNELS);
106 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
107 struct snd_interval ch;
109 snd_interval_any(&ch);
111 /* S32_BE is mono (and stereo) only */
112 if (f->bits[0] == SNDRV_PCM_FMTBIT_S32_BE) {
114 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
120 return snd_interval_refine(c, &ch);
122 /* U8 can be only mono or stereo */
123 if (f->bits[0] == SNDRV_PCM_FMTBIT_U8) {
127 return snd_interval_refine(c, &ch);
129 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
135 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params,
136 struct snd_pcm_hw_rule *rule)
138 struct snd_interval *c = hw_param_interval(params,
139 SNDRV_PCM_HW_PARAM_CHANNELS);
140 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
145 fmask = fmt.bits[0] + ((u64)fmt.bits[1] << 32);
147 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
149 fmask &= SNDRV_PCM_FMTBIT_S16_LE |
150 SNDRV_PCM_FMTBIT_S24_3LE |
151 SNDRV_PCM_FMTBIT_S32_LE;
152 /* 1 channel must be S32_BE or S32_LE */
153 } else if (c->max == 1)
154 fmask &= SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
155 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
156 /* 2 channels cannot be S32_BE */
157 else if (c->min == 2 && c->max == 2)
158 fmask &= ~SNDRV_PCM_FMTBIT_S32_BE;
163 fmt.bits[0] &= (u32)fmask;
164 fmt.bits[1] &= (u32)(fmask >> 32);
165 return snd_mask_refine(f, &fmt);
170 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params,
171 struct snd_pcm_hw_rule *rule)
173 struct snd_interval *c = hw_param_interval(params,
174 SNDRV_PCM_HW_PARAM_CHANNELS);
175 struct snd_mask *f = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
176 struct snd_interval ch;
179 snd_interval_any(&ch);
181 fmask = f->bits[0] + ((u64)f->bits[1] << 32);
183 /* S32_BE is mono (and stereo) only */
184 if (fmask == SNDRV_PCM_FMTBIT_S32_BE) {
186 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
191 /* U8 is stereo only */
192 } else if (fmask == SNDRV_PCM_FMTBIT_U8)
194 /* S16_LE and S24_3LE must be at least stereo */
195 else if (!(fmask & ~(SNDRV_PCM_FMTBIT_S16_LE |
196 SNDRV_PCM_FMTBIT_S24_3LE)))
201 return snd_interval_refine(c, &ch);
206 /* Since the sample rate is a global setting, do allow the user to change the
207 sample rate only if there is only one pcm device open. */
208 static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
209 struct snd_pcm_hw_rule *rule)
211 struct snd_interval *rate = hw_param_interval(params,
212 SNDRV_PCM_HW_PARAM_RATE);
213 struct echoaudio *chip = rule->private;
214 struct snd_interval fixed;
216 if (!chip->can_set_rate) {
217 snd_interval_any(&fixed);
218 fixed.min = fixed.max = chip->sample_rate;
219 return snd_interval_refine(rate, &fixed);
225 static int pcm_open(struct snd_pcm_substream *substream,
226 signed char max_channels)
228 struct echoaudio *chip;
229 struct snd_pcm_runtime *runtime;
230 struct audiopipe *pipe;
233 if (max_channels <= 0)
236 chip = snd_pcm_substream_chip(substream);
237 runtime = substream->runtime;
239 pipe = kzalloc(sizeof(struct audiopipe), GFP_KERNEL);
242 pipe->index = -1; /* Not configured yet */
244 /* Set up hw capabilities and contraints */
245 memcpy(&pipe->hw, &pcm_hardware_skel, sizeof(struct snd_pcm_hardware));
246 DE_HWP(("max_channels=%d\n", max_channels));
247 pipe->constr.list = channels_list;
248 pipe->constr.mask = 0;
249 for (i = 0; channels_list[i] <= max_channels; i++);
250 pipe->constr.count = i;
251 if (pipe->hw.channels_max > max_channels)
252 pipe->hw.channels_max = max_channels;
253 if (chip->digital_mode == DIGITAL_MODE_ADAT) {
254 pipe->hw.rate_max = 48000;
255 pipe->hw.rates &= SNDRV_PCM_RATE_8000_48000;
258 runtime->hw = pipe->hw;
259 runtime->private_data = pipe;
260 runtime->private_free = audiopipe_free;
261 snd_pcm_set_sync(substream);
263 /* Only mono and any even number of channels are allowed */
264 if ((err = snd_pcm_hw_constraint_list(runtime, 0,
265 SNDRV_PCM_HW_PARAM_CHANNELS,
269 /* All periods should have the same size */
270 if ((err = snd_pcm_hw_constraint_integer(runtime,
271 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
274 /* The hw accesses memory in chunks 32 frames long and they should be
275 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
276 generated with a resolution of 32 frames. Thus we need the following */
277 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
278 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
281 if ((err = snd_pcm_hw_constraint_step(runtime, 0,
282 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
286 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
287 SNDRV_PCM_HW_PARAM_RATE,
288 hw_rule_sample_rate, chip,
289 SNDRV_PCM_HW_PARAM_RATE, -1)) < 0)
292 /* Finally allocate a page for the scatter-gather list */
293 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
294 snd_dma_pci_data(chip->pci),
295 PAGE_SIZE, &pipe->sgpage)) < 0) {
296 DE_HWP(("s-g list allocation failed\n"));
305 static int pcm_analog_in_open(struct snd_pcm_substream *substream)
307 struct echoaudio *chip = snd_pcm_substream_chip(substream);
310 DE_ACT(("pcm_analog_in_open\n"));
311 if ((err = pcm_open(substream, num_analog_busses_in(chip) -
312 substream->number)) < 0)
314 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
315 SNDRV_PCM_HW_PARAM_CHANNELS,
316 hw_rule_capture_channels_by_format, NULL,
317 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
319 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
320 SNDRV_PCM_HW_PARAM_FORMAT,
321 hw_rule_capture_format_by_channels, NULL,
322 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
324 atomic_inc(&chip->opencount);
325 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
326 chip->can_set_rate=0;
327 DE_HWP(("pcm_analog_in_open cs=%d oc=%d r=%d\n",
328 chip->can_set_rate, atomic_read(&chip->opencount),
335 static int pcm_analog_out_open(struct snd_pcm_substream *substream)
337 struct echoaudio *chip = snd_pcm_substream_chip(substream);
338 int max_channels, err;
340 #ifdef ECHOCARD_HAS_VMIXER
341 max_channels = num_pipes_out(chip);
343 max_channels = num_analog_busses_out(chip);
345 DE_ACT(("pcm_analog_out_open\n"));
346 if ((err = pcm_open(substream, max_channels - substream->number)) < 0)
348 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
349 SNDRV_PCM_HW_PARAM_CHANNELS,
350 hw_rule_playback_channels_by_format,
352 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
354 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
355 SNDRV_PCM_HW_PARAM_FORMAT,
356 hw_rule_playback_format_by_channels,
358 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
360 atomic_inc(&chip->opencount);
361 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
362 chip->can_set_rate=0;
363 DE_HWP(("pcm_analog_out_open cs=%d oc=%d r=%d\n",
364 chip->can_set_rate, atomic_read(&chip->opencount),
371 #ifdef ECHOCARD_HAS_DIGITAL_IO
373 static int pcm_digital_in_open(struct snd_pcm_substream *substream)
375 struct echoaudio *chip = snd_pcm_substream_chip(substream);
376 int err, max_channels;
378 DE_ACT(("pcm_digital_in_open\n"));
379 max_channels = num_digital_busses_in(chip) - substream->number;
380 down(&chip->mode_mutex);
381 if (chip->digital_mode == DIGITAL_MODE_ADAT)
382 err = pcm_open(substream, max_channels);
383 else /* If the card has ADAT, subtract the 6 channels
384 * that S/PDIF doesn't have
386 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
391 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
392 SNDRV_PCM_HW_PARAM_CHANNELS,
393 hw_rule_capture_channels_by_format, NULL,
394 SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0)
396 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
397 SNDRV_PCM_HW_PARAM_FORMAT,
398 hw_rule_capture_format_by_channels, NULL,
399 SNDRV_PCM_HW_PARAM_CHANNELS, -1)) < 0)
402 atomic_inc(&chip->opencount);
403 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
404 chip->can_set_rate=0;
407 up(&chip->mode_mutex);
413 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
415 static int pcm_digital_out_open(struct snd_pcm_substream *substream)
417 struct echoaudio *chip = snd_pcm_substream_chip(substream);
418 int err, max_channels;
420 DE_ACT(("pcm_digital_out_open\n"));
421 max_channels = num_digital_busses_out(chip) - substream->number;
422 down(&chip->mode_mutex);
423 if (chip->digital_mode == DIGITAL_MODE_ADAT)
424 err = pcm_open(substream, max_channels);
425 else /* If the card has ADAT, subtract the 6 channels
426 * that S/PDIF doesn't have
428 err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
433 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
434 SNDRV_PCM_HW_PARAM_CHANNELS,
435 hw_rule_playback_channels_by_format,
436 NULL, SNDRV_PCM_HW_PARAM_FORMAT,
439 if ((err = snd_pcm_hw_rule_add(substream->runtime, 0,
440 SNDRV_PCM_HW_PARAM_FORMAT,
441 hw_rule_playback_format_by_channels,
442 NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
445 atomic_inc(&chip->opencount);
446 if (atomic_read(&chip->opencount) > 1 && chip->rate_set)
447 chip->can_set_rate=0;
449 up(&chip->mode_mutex);
453 #endif /* !ECHOCARD_HAS_VMIXER */
455 #endif /* ECHOCARD_HAS_DIGITAL_IO */
459 static int pcm_close(struct snd_pcm_substream *substream)
461 struct echoaudio *chip = snd_pcm_substream_chip(substream);
464 /* Nothing to do here. Audio is already off and pipe will be
465 * freed by its callback
467 DE_ACT(("pcm_close\n"));
469 atomic_dec(&chip->opencount);
470 oc = atomic_read(&chip->opencount);
471 DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc,
472 chip->can_set_rate, chip->rate_set));
474 chip->can_set_rate = 1;
477 DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc,
478 chip->can_set_rate,chip->rate_set));
485 /* Channel allocation and scatter-gather list setup */
486 static int init_engine(struct snd_pcm_substream *substream,
487 struct snd_pcm_hw_params *hw_params,
488 int pipe_index, int interleave)
490 struct echoaudio *chip;
491 int err, per, rest, page, edge, offs;
492 struct snd_sg_buf *sgbuf;
493 struct audiopipe *pipe;
495 chip = snd_pcm_substream_chip(substream);
496 pipe = (struct audiopipe *) substream->runtime->private_data;
498 /* Sets up che hardware. If it's already initialized, reset and
499 * redo with the new parameters
501 spin_lock_irq(&chip->lock);
502 if (pipe->index >= 0) {
503 DE_HWP(("hwp_ie free(%d)\n", pipe->index));
504 err = free_pipes(chip, pipe);
506 chip->substream[pipe->index] = NULL;
509 err = allocate_pipes(chip, pipe, pipe_index, interleave);
511 spin_unlock_irq(&chip->lock);
512 DE_ACT((KERN_NOTICE "allocate_pipes(%d) err=%d\n",
516 spin_unlock_irq(&chip->lock);
517 DE_ACT((KERN_NOTICE "allocate_pipes()=%d\n", pipe_index));
519 DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
520 params_buffer_bytes(hw_params), params_periods(hw_params),
521 params_period_bytes(hw_params)));
522 err = snd_pcm_lib_malloc_pages(substream,
523 params_buffer_bytes(hw_params));
525 snd_printk(KERN_ERR "malloc_pages err=%d\n", err);
526 spin_lock_irq(&chip->lock);
527 free_pipes(chip, pipe);
528 spin_unlock_irq(&chip->lock);
533 sgbuf = snd_pcm_substream_sgbuf(substream);
535 DE_HWP(("pcm_hw_params table size=%d pages=%d\n",
536 sgbuf->size, sgbuf->pages));
537 sglist_init(chip, pipe);
539 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
541 rest = params_period_bytes(hw_params);
542 if (offs + rest > params_buffer_bytes(hw_params))
543 rest = params_buffer_bytes(hw_params) - offs;
545 if (rest <= edge - offs) {
546 sglist_add_mapping(chip, pipe,
547 snd_sgbuf_get_addr(sgbuf, offs),
549 sglist_add_irq(chip, pipe);
553 sglist_add_mapping(chip, pipe,
554 snd_sgbuf_get_addr(sgbuf, offs),
566 /* Close the ring buffer */
567 sglist_wrap(chip, pipe);
569 /* This stuff is used by the irq handler, so it must be
570 * initialized before chip->substream
572 chip->last_period[pipe_index] = 0;
573 pipe->last_counter = 0;
576 chip->substream[pipe_index] = substream;
578 spin_lock_irq(&chip->lock);
579 set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den);
580 spin_unlock_irq(&chip->lock);
581 DE_HWP(("pcm_hw_params ok\n"));
587 static int pcm_analog_in_hw_params(struct snd_pcm_substream *substream,
588 struct snd_pcm_hw_params *hw_params)
590 struct echoaudio *chip = snd_pcm_substream_chip(substream);
592 return init_engine(substream, hw_params, px_analog_in(chip) +
593 substream->number, params_channels(hw_params));
598 static int pcm_analog_out_hw_params(struct snd_pcm_substream *substream,
599 struct snd_pcm_hw_params *hw_params)
601 return init_engine(substream, hw_params, substream->number,
602 params_channels(hw_params));
607 #ifdef ECHOCARD_HAS_DIGITAL_IO
609 static int pcm_digital_in_hw_params(struct snd_pcm_substream *substream,
610 struct snd_pcm_hw_params *hw_params)
612 struct echoaudio *chip = snd_pcm_substream_chip(substream);
614 return init_engine(substream, hw_params, px_digital_in(chip) +
615 substream->number, params_channels(hw_params));
620 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
621 static int pcm_digital_out_hw_params(struct snd_pcm_substream *substream,
622 struct snd_pcm_hw_params *hw_params)
624 struct echoaudio *chip = snd_pcm_substream_chip(substream);
626 return init_engine(substream, hw_params, px_digital_out(chip) +
627 substream->number, params_channels(hw_params));
629 #endif /* !ECHOCARD_HAS_VMIXER */
631 #endif /* ECHOCARD_HAS_DIGITAL_IO */
635 static int pcm_hw_free(struct snd_pcm_substream *substream)
637 struct echoaudio *chip;
638 struct audiopipe *pipe;
640 chip = snd_pcm_substream_chip(substream);
641 pipe = (struct audiopipe *) substream->runtime->private_data;
643 spin_lock_irq(&chip->lock);
644 if (pipe->index >= 0) {
645 DE_HWP(("pcm_hw_free(%d)\n", pipe->index));
646 free_pipes(chip, pipe);
647 chip->substream[pipe->index] = NULL;
650 spin_unlock_irq(&chip->lock);
652 DE_HWP(("pcm_hw_freed\n"));
653 snd_pcm_lib_free_pages(substream);
659 static int pcm_prepare(struct snd_pcm_substream *substream)
661 struct echoaudio *chip = snd_pcm_substream_chip(substream);
662 struct snd_pcm_runtime *runtime = substream->runtime;
663 struct audioformat format;
664 int pipe_index = ((struct audiopipe *)runtime->private_data)->index;
666 DE_HWP(("Prepare rate=%d format=%d channels=%d\n",
667 runtime->rate, runtime->format, runtime->channels));
668 format.interleave = runtime->channels;
669 format.data_are_bigendian = 0;
670 format.mono_to_stereo = 0;
671 switch (runtime->format) {
672 case SNDRV_PCM_FORMAT_U8:
673 format.bits_per_sample = 8;
675 case SNDRV_PCM_FORMAT_S16_LE:
676 format.bits_per_sample = 16;
678 case SNDRV_PCM_FORMAT_S24_3LE:
679 format.bits_per_sample = 24;
681 case SNDRV_PCM_FORMAT_S32_BE:
682 format.data_are_bigendian = 1;
683 case SNDRV_PCM_FORMAT_S32_LE:
684 format.bits_per_sample = 32;
687 DE_HWP(("Prepare error: unsupported format %d\n",
692 snd_assert(pipe_index < px_num(chip), return -EINVAL);
693 snd_assert(is_pipe_allocated(chip, pipe_index), return -EINVAL);
694 set_audio_format(chip, pipe_index, &format);
700 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
702 struct echoaudio *chip = snd_pcm_substream_chip(substream);
703 struct snd_pcm_runtime *runtime = substream->runtime;
704 struct audiopipe *pipe = runtime->private_data;
707 struct list_head *pos;
708 struct snd_pcm_substream *s;
710 snd_pcm_group_for_each(pos, substream) {
711 s = snd_pcm_group_substream_entry(pos);
712 for (i = 0; i < DSP_MAXPIPES; i++) {
713 if (s == chip->substream[i]) {
714 channelmask |= 1 << i;
715 snd_pcm_trigger_done(s, substream);
720 spin_lock(&chip->lock);
722 case SNDRV_PCM_TRIGGER_START:
723 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
724 DE_ACT(("pcm_trigger start\n"));
725 for (i = 0; i < DSP_MAXPIPES; i++) {
726 if (channelmask & (1 << i)) {
727 pipe = chip->substream[i]->runtime->private_data;
728 switch (pipe->state) {
729 case PIPE_STATE_STOPPED:
730 chip->last_period[i] = 0;
731 pipe->last_counter = 0;
733 *pipe->dma_counter = 0;
734 case PIPE_STATE_PAUSED:
735 pipe->state = PIPE_STATE_STARTED;
737 case PIPE_STATE_STARTED:
742 err = start_transport(chip, channelmask,
743 chip->pipe_cyclic_mask);
745 case SNDRV_PCM_TRIGGER_STOP:
746 DE_ACT(("pcm_trigger stop\n"));
747 for (i = 0; i < DSP_MAXPIPES; i++) {
748 if (channelmask & (1 << i)) {
749 pipe = chip->substream[i]->runtime->private_data;
750 pipe->state = PIPE_STATE_STOPPED;
753 err = stop_transport(chip, channelmask);
755 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
756 DE_ACT(("pcm_trigger pause\n"));
757 for (i = 0; i < DSP_MAXPIPES; i++) {
758 if (channelmask & (1 << i)) {
759 pipe = chip->substream[i]->runtime->private_data;
760 pipe->state = PIPE_STATE_PAUSED;
763 err = pause_transport(chip, channelmask);
768 spin_unlock(&chip->lock);
774 static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
776 struct snd_pcm_runtime *runtime = substream->runtime;
777 struct audiopipe *pipe = runtime->private_data;
778 size_t cnt, bufsize, pos;
780 cnt = le32_to_cpu(*pipe->dma_counter);
781 pipe->position += cnt - pipe->last_counter;
782 pipe->last_counter = cnt;
783 bufsize = substream->runtime->buffer_size;
784 pos = bytes_to_frames(substream->runtime, pipe->position);
786 while (pos >= bufsize) {
787 pipe->position -= frames_to_bytes(substream->runtime, bufsize);
795 /* pcm *_ops structures */
796 static struct snd_pcm_ops analog_playback_ops = {
797 .open = pcm_analog_out_open,
799 .ioctl = snd_pcm_lib_ioctl,
800 .hw_params = pcm_analog_out_hw_params,
801 .hw_free = pcm_hw_free,
802 .prepare = pcm_prepare,
803 .trigger = pcm_trigger,
804 .pointer = pcm_pointer,
805 .page = snd_pcm_sgbuf_ops_page,
807 static struct snd_pcm_ops analog_capture_ops = {
808 .open = pcm_analog_in_open,
810 .ioctl = snd_pcm_lib_ioctl,
811 .hw_params = pcm_analog_in_hw_params,
812 .hw_free = pcm_hw_free,
813 .prepare = pcm_prepare,
814 .trigger = pcm_trigger,
815 .pointer = pcm_pointer,
816 .page = snd_pcm_sgbuf_ops_page,
818 #ifdef ECHOCARD_HAS_DIGITAL_IO
819 #ifndef ECHOCARD_HAS_VMIXER
820 static struct snd_pcm_ops digital_playback_ops = {
821 .open = pcm_digital_out_open,
823 .ioctl = snd_pcm_lib_ioctl,
824 .hw_params = pcm_digital_out_hw_params,
825 .hw_free = pcm_hw_free,
826 .prepare = pcm_prepare,
827 .trigger = pcm_trigger,
828 .pointer = pcm_pointer,
829 .page = snd_pcm_sgbuf_ops_page,
831 #endif /* !ECHOCARD_HAS_VMIXER */
832 static struct snd_pcm_ops digital_capture_ops = {
833 .open = pcm_digital_in_open,
835 .ioctl = snd_pcm_lib_ioctl,
836 .hw_params = pcm_digital_in_hw_params,
837 .hw_free = pcm_hw_free,
838 .prepare = pcm_prepare,
839 .trigger = pcm_trigger,
840 .pointer = pcm_pointer,
841 .page = snd_pcm_sgbuf_ops_page,
843 #endif /* ECHOCARD_HAS_DIGITAL_IO */
847 /* Preallocate memory only for the first substream because it's the most
850 static int snd_echo_preallocate_pages(struct snd_pcm *pcm, struct device *dev)
852 struct snd_pcm_substream *ss;
855 for (stream = 0; stream < 2; stream++)
856 for (ss = pcm->streams[stream].substream; ss; ss = ss->next) {
857 err = snd_pcm_lib_preallocate_pages(ss, SNDRV_DMA_TYPE_DEV_SG,
859 ss->number ? 0 : 128<<10,
869 /*<--snd_echo_probe() */
870 static int __devinit snd_echo_new_pcm(struct echoaudio *chip)
875 #ifdef ECHOCARD_HAS_VMIXER
876 /* This card has a Vmixer, that is there is no direct mapping from PCM
877 streams to physical outputs. The user can mix the streams as he wishes
878 via control interface and it's possible to send any stream to any
879 output, thus it makes no sense to keep analog and digital outputs
882 /* PCM#0 Virtual outputs and analog inputs */
883 if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip),
884 num_analog_busses_in(chip), &pcm)) < 0)
886 pcm->private_data = chip;
887 chip->analog_pcm = pcm;
888 strcpy(pcm->name, chip->card->shortname);
889 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
890 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
891 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
893 DE_INIT(("Analog PCM ok\n"));
895 #ifdef ECHOCARD_HAS_DIGITAL_IO
896 /* PCM#1 Digital inputs, no outputs */
897 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0,
898 num_digital_busses_in(chip), &pcm)) < 0)
900 pcm->private_data = chip;
901 chip->digital_pcm = pcm;
902 strcpy(pcm->name, chip->card->shortname);
903 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
904 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
906 DE_INIT(("Digital PCM ok\n"));
907 #endif /* ECHOCARD_HAS_DIGITAL_IO */
909 #else /* ECHOCARD_HAS_VMIXER */
911 /* The card can manage substreams formed by analog and digital channels
912 at the same time, but I prefer to keep analog and digital channels
913 separated, because that mixed thing is confusing and useless. So we
914 register two PCM devices: */
916 /* PCM#0 Analog i/o */
917 if ((err = snd_pcm_new(chip->card, "Analog PCM", 0,
918 num_analog_busses_out(chip),
919 num_analog_busses_in(chip), &pcm)) < 0)
921 pcm->private_data = chip;
922 chip->analog_pcm = pcm;
923 strcpy(pcm->name, chip->card->shortname);
924 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops);
925 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops);
926 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
928 DE_INIT(("Analog PCM ok\n"));
930 #ifdef ECHOCARD_HAS_DIGITAL_IO
931 /* PCM#1 Digital i/o */
932 if ((err = snd_pcm_new(chip->card, "Digital PCM", 1,
933 num_digital_busses_out(chip),
934 num_digital_busses_in(chip), &pcm)) < 0)
936 pcm->private_data = chip;
937 chip->digital_pcm = pcm;
938 strcpy(pcm->name, chip->card->shortname);
939 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops);
940 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops);
941 if ((err = snd_echo_preallocate_pages(pcm, snd_dma_pci_data(chip->pci))) < 0)
943 DE_INIT(("Digital PCM ok\n"));
944 #endif /* ECHOCARD_HAS_DIGITAL_IO */
946 #endif /* ECHOCARD_HAS_VMIXER */
954 /******************************************************************************
956 ******************************************************************************/
958 /******************* PCM output volume *******************/
959 static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
960 struct snd_ctl_elem_info *uinfo)
962 struct echoaudio *chip;
964 chip = snd_kcontrol_chip(kcontrol);
965 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
966 uinfo->count = num_busses_out(chip);
967 uinfo->value.integer.min = ECHOGAIN_MINOUT;
968 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
972 static int snd_echo_output_gain_get(struct snd_kcontrol *kcontrol,
973 struct snd_ctl_elem_value *ucontrol)
975 struct echoaudio *chip;
978 chip = snd_kcontrol_chip(kcontrol);
979 for (c = 0; c < num_busses_out(chip); c++)
980 ucontrol->value.integer.value[c] = chip->output_gain[c];
984 static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
985 struct snd_ctl_elem_value *ucontrol)
987 struct echoaudio *chip;
988 int c, changed, gain;
991 chip = snd_kcontrol_chip(kcontrol);
992 spin_lock_irq(&chip->lock);
993 for (c = 0; c < num_busses_out(chip); c++) {
994 gain = ucontrol->value.integer.value[c];
995 /* Ignore out of range values */
996 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
998 if (chip->output_gain[c] != gain) {
999 set_output_gain(chip, c, gain);
1004 update_output_line_level(chip);
1005 spin_unlock_irq(&chip->lock);
1009 #ifdef ECHOCARD_HAS_VMIXER
1010 /* On Vmixer cards this one controls the line-out volume */
1011 static struct snd_kcontrol_new snd_echo_line_output_gain __devinitdata = {
1012 .name = "Line Playback Volume",
1013 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1014 .info = snd_echo_output_gain_info,
1015 .get = snd_echo_output_gain_get,
1016 .put = snd_echo_output_gain_put,
1019 static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1020 .name = "PCM Playback Volume",
1021 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1022 .info = snd_echo_output_gain_info,
1023 .get = snd_echo_output_gain_get,
1024 .put = snd_echo_output_gain_put,
1030 #ifdef ECHOCARD_HAS_INPUT_GAIN
1032 /******************* Analog input volume *******************/
1033 static int snd_echo_input_gain_info(struct snd_kcontrol *kcontrol,
1034 struct snd_ctl_elem_info *uinfo)
1036 struct echoaudio *chip;
1038 chip = snd_kcontrol_chip(kcontrol);
1039 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1040 uinfo->count = num_analog_busses_in(chip);
1041 uinfo->value.integer.min = ECHOGAIN_MININP;
1042 uinfo->value.integer.max = ECHOGAIN_MAXINP;
1046 static int snd_echo_input_gain_get(struct snd_kcontrol *kcontrol,
1047 struct snd_ctl_elem_value *ucontrol)
1049 struct echoaudio *chip;
1052 chip = snd_kcontrol_chip(kcontrol);
1053 for (c = 0; c < num_analog_busses_in(chip); c++)
1054 ucontrol->value.integer.value[c] = chip->input_gain[c];
1058 static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol,
1059 struct snd_ctl_elem_value *ucontrol)
1061 struct echoaudio *chip;
1062 int c, gain, changed;
1065 chip = snd_kcontrol_chip(kcontrol);
1066 spin_lock_irq(&chip->lock);
1067 for (c = 0; c < num_analog_busses_in(chip); c++) {
1068 gain = ucontrol->value.integer.value[c];
1069 /* Ignore out of range values */
1070 if (gain < ECHOGAIN_MININP || gain > ECHOGAIN_MAXINP)
1072 if (chip->input_gain[c] != gain) {
1073 set_input_gain(chip, c, gain);
1078 update_input_line_level(chip);
1079 spin_unlock_irq(&chip->lock);
1083 static struct snd_kcontrol_new snd_echo_line_input_gain __devinitdata = {
1084 .name = "Line Capture Volume",
1085 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1086 .info = snd_echo_input_gain_info,
1087 .get = snd_echo_input_gain_get,
1088 .put = snd_echo_input_gain_put,
1091 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1095 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1097 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1098 static int snd_echo_output_nominal_info (struct snd_kcontrol *kcontrol,
1099 struct snd_ctl_elem_info *uinfo)
1101 struct echoaudio *chip;
1103 chip = snd_kcontrol_chip(kcontrol);
1104 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1105 uinfo->count = num_analog_busses_out(chip);
1106 uinfo->value.integer.min = 0;
1107 uinfo->value.integer.max = 1;
1111 static int snd_echo_output_nominal_get(struct snd_kcontrol *kcontrol,
1112 struct snd_ctl_elem_value *ucontrol)
1114 struct echoaudio *chip;
1117 chip = snd_kcontrol_chip(kcontrol);
1118 for (c = 0; c < num_analog_busses_out(chip); c++)
1119 ucontrol->value.integer.value[c] = chip->nominal_level[c];
1123 static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol,
1124 struct snd_ctl_elem_value *ucontrol)
1126 struct echoaudio *chip;
1130 chip = snd_kcontrol_chip(kcontrol);
1131 spin_lock_irq(&chip->lock);
1132 for (c = 0; c < num_analog_busses_out(chip); c++) {
1133 if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) {
1134 set_nominal_level(chip, c,
1135 ucontrol->value.integer.value[c]);
1140 update_output_line_level(chip);
1141 spin_unlock_irq(&chip->lock);
1145 static struct snd_kcontrol_new snd_echo_output_nominal_level __devinitdata = {
1146 .name = "Line Playback Switch (-10dBV)",
1147 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1148 .info = snd_echo_output_nominal_info,
1149 .get = snd_echo_output_nominal_get,
1150 .put = snd_echo_output_nominal_put,
1153 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1157 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1159 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1160 static int snd_echo_input_nominal_info(struct snd_kcontrol *kcontrol,
1161 struct snd_ctl_elem_info *uinfo)
1163 struct echoaudio *chip;
1165 chip = snd_kcontrol_chip(kcontrol);
1166 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1167 uinfo->count = num_analog_busses_in(chip);
1168 uinfo->value.integer.min = 0;
1169 uinfo->value.integer.max = 1;
1173 static int snd_echo_input_nominal_get(struct snd_kcontrol *kcontrol,
1174 struct snd_ctl_elem_value *ucontrol)
1176 struct echoaudio *chip;
1179 chip = snd_kcontrol_chip(kcontrol);
1180 for (c = 0; c < num_analog_busses_in(chip); c++)
1181 ucontrol->value.integer.value[c] =
1182 chip->nominal_level[bx_analog_in(chip) + c];
1186 static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,
1187 struct snd_ctl_elem_value *ucontrol)
1189 struct echoaudio *chip;
1193 chip = snd_kcontrol_chip(kcontrol);
1194 spin_lock_irq(&chip->lock);
1195 for (c = 0; c < num_analog_busses_in(chip); c++) {
1196 if (chip->nominal_level[bx_analog_in(chip) + c] !=
1197 ucontrol->value.integer.value[c]) {
1198 set_nominal_level(chip, bx_analog_in(chip) + c,
1199 ucontrol->value.integer.value[c]);
1204 update_output_line_level(chip); /* "Output" is not a mistake
1207 spin_unlock_irq(&chip->lock);
1211 static struct snd_kcontrol_new snd_echo_intput_nominal_level __devinitdata = {
1212 .name = "Line Capture Switch (-10dBV)",
1213 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1214 .info = snd_echo_input_nominal_info,
1215 .get = snd_echo_input_nominal_get,
1216 .put = snd_echo_input_nominal_put,
1219 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1223 #ifdef ECHOCARD_HAS_MONITOR
1225 /******************* Monitor mixer *******************/
1226 static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1227 struct snd_ctl_elem_info *uinfo)
1229 struct echoaudio *chip;
1231 chip = snd_kcontrol_chip(kcontrol);
1232 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1234 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1235 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1236 uinfo->dimen.d[0] = num_busses_out(chip);
1237 uinfo->dimen.d[1] = num_busses_in(chip);
1241 static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1242 struct snd_ctl_elem_value *ucontrol)
1244 struct echoaudio *chip;
1246 chip = snd_kcontrol_chip(kcontrol);
1247 ucontrol->value.integer.value[0] =
1248 chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)]
1249 [ucontrol->id.index % num_busses_in(chip)];
1253 static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1254 struct snd_ctl_elem_value *ucontrol)
1256 struct echoaudio *chip;
1261 chip = snd_kcontrol_chip(kcontrol);
1262 out = ucontrol->id.index / num_busses_in(chip);
1263 in = ucontrol->id.index % num_busses_in(chip);
1264 gain = ucontrol->value.integer.value[0];
1265 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1267 if (chip->monitor_gain[out][in] != gain) {
1268 spin_lock_irq(&chip->lock);
1269 set_monitor_gain(chip, out, in, gain);
1270 update_output_line_level(chip);
1271 spin_unlock_irq(&chip->lock);
1277 static struct snd_kcontrol_new snd_echo_monitor_mixer __devinitdata = {
1278 .name = "Monitor Mixer Volume",
1279 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1280 .info = snd_echo_mixer_info,
1281 .get = snd_echo_mixer_get,
1282 .put = snd_echo_mixer_put,
1285 #endif /* ECHOCARD_HAS_MONITOR */
1289 #ifdef ECHOCARD_HAS_VMIXER
1291 /******************* Vmixer *******************/
1292 static int snd_echo_vmixer_info(struct snd_kcontrol *kcontrol,
1293 struct snd_ctl_elem_info *uinfo)
1295 struct echoaudio *chip;
1297 chip = snd_kcontrol_chip(kcontrol);
1298 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1300 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1301 uinfo->value.integer.max = ECHOGAIN_MAXOUT;
1302 uinfo->dimen.d[0] = num_busses_out(chip);
1303 uinfo->dimen.d[1] = num_pipes_out(chip);
1307 static int snd_echo_vmixer_get(struct snd_kcontrol *kcontrol,
1308 struct snd_ctl_elem_value *ucontrol)
1310 struct echoaudio *chip;
1312 chip = snd_kcontrol_chip(kcontrol);
1313 ucontrol->value.integer.value[0] =
1314 chip->vmixer_gain[ucontrol->id.index / num_pipes_out(chip)]
1315 [ucontrol->id.index % num_pipes_out(chip)];
1319 static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,
1320 struct snd_ctl_elem_value *ucontrol)
1322 struct echoaudio *chip;
1327 chip = snd_kcontrol_chip(kcontrol);
1328 out = ucontrol->id.index / num_pipes_out(chip);
1329 vch = ucontrol->id.index % num_pipes_out(chip);
1330 gain = ucontrol->value.integer.value[0];
1331 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1333 if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) {
1334 spin_lock_irq(&chip->lock);
1335 set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]);
1336 update_vmixer_level(chip);
1337 spin_unlock_irq(&chip->lock);
1343 static struct snd_kcontrol_new snd_echo_vmixer __devinitdata = {
1344 .name = "VMixer Volume",
1345 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1346 .info = snd_echo_vmixer_info,
1347 .get = snd_echo_vmixer_get,
1348 .put = snd_echo_vmixer_put,
1351 #endif /* ECHOCARD_HAS_VMIXER */
1355 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1357 /******************* Digital mode switch *******************/
1358 static int snd_echo_digital_mode_info(struct snd_kcontrol *kcontrol,
1359 struct snd_ctl_elem_info *uinfo)
1361 static char *names[4] = {
1362 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1365 struct echoaudio *chip;
1367 chip = snd_kcontrol_chip(kcontrol);
1368 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1369 uinfo->value.enumerated.items = chip->num_digital_modes;
1371 if (uinfo->value.enumerated.item >= chip->num_digital_modes)
1372 uinfo->value.enumerated.item = chip->num_digital_modes - 1;
1373 strcpy(uinfo->value.enumerated.name, names[
1374 chip->digital_mode_list[uinfo->value.enumerated.item]]);
1378 static int snd_echo_digital_mode_get(struct snd_kcontrol *kcontrol,
1379 struct snd_ctl_elem_value *ucontrol)
1381 struct echoaudio *chip;
1384 chip = snd_kcontrol_chip(kcontrol);
1385 mode = chip->digital_mode;
1386 for (i = chip->num_digital_modes - 1; i >= 0; i--)
1387 if (mode == chip->digital_mode_list[i]) {
1388 ucontrol->value.enumerated.item[0] = i;
1394 static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
1395 struct snd_ctl_elem_value *ucontrol)
1397 struct echoaudio *chip;
1399 unsigned short emode, dmode;
1402 chip = snd_kcontrol_chip(kcontrol);
1404 emode = ucontrol->value.enumerated.item[0];
1405 if (emode >= chip->num_digital_modes)
1407 dmode = chip->digital_mode_list[emode];
1409 if (dmode != chip->digital_mode) {
1410 /* mode_mutex is required to make this operation atomic wrt
1411 pcm_digital_*_open() and set_input_clock() functions. */
1412 down(&chip->mode_mutex);
1414 /* Do not allow the user to change the digital mode when a pcm
1415 device is open because it also changes the number of channels
1416 and the allowed sample rates */
1417 if (atomic_read(&chip->opencount)) {
1420 changed = set_digital_mode(chip, dmode);
1421 /* If we had to change the clock source, report it */
1422 if (changed > 0 && chip->clock_src_ctl) {
1423 snd_ctl_notify(chip->card,
1424 SNDRV_CTL_EVENT_MASK_VALUE,
1425 &chip->clock_src_ctl->id);
1426 DE_ACT(("SDM() =%d\n", changed));
1429 changed = 1; /* No errors */
1431 up(&chip->mode_mutex);
1436 static struct snd_kcontrol_new snd_echo_digital_mode_switch __devinitdata = {
1437 .name = "Digital mode Switch",
1438 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1439 .info = snd_echo_digital_mode_info,
1440 .get = snd_echo_digital_mode_get,
1441 .put = snd_echo_digital_mode_put,
1444 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1448 #ifdef ECHOCARD_HAS_DIGITAL_IO
1450 /******************* S/PDIF mode switch *******************/
1451 static int snd_echo_spdif_mode_info(struct snd_kcontrol *kcontrol,
1452 struct snd_ctl_elem_info *uinfo)
1454 static char *names[2] = {"Consumer", "Professional"};
1456 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1457 uinfo->value.enumerated.items = 2;
1459 if (uinfo->value.enumerated.item)
1460 uinfo->value.enumerated.item = 1;
1461 strcpy(uinfo->value.enumerated.name,
1462 names[uinfo->value.enumerated.item]);
1466 static int snd_echo_spdif_mode_get(struct snd_kcontrol *kcontrol,
1467 struct snd_ctl_elem_value *ucontrol)
1469 struct echoaudio *chip;
1471 chip = snd_kcontrol_chip(kcontrol);
1472 ucontrol->value.enumerated.item[0] = !!chip->professional_spdif;
1476 static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol,
1477 struct snd_ctl_elem_value *ucontrol)
1479 struct echoaudio *chip;
1482 chip = snd_kcontrol_chip(kcontrol);
1483 mode = !!ucontrol->value.enumerated.item[0];
1484 if (mode != chip->professional_spdif) {
1485 spin_lock_irq(&chip->lock);
1486 set_professional_spdif(chip, mode);
1487 spin_unlock_irq(&chip->lock);
1493 static struct snd_kcontrol_new snd_echo_spdif_mode_switch __devinitdata = {
1494 .name = "S/PDIF mode Switch",
1495 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1496 .info = snd_echo_spdif_mode_info,
1497 .get = snd_echo_spdif_mode_get,
1498 .put = snd_echo_spdif_mode_put,
1501 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1505 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1507 /******************* Select input clock source *******************/
1508 static int snd_echo_clock_source_info(struct snd_kcontrol *kcontrol,
1509 struct snd_ctl_elem_info *uinfo)
1511 static char *names[8] = {
1512 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1515 struct echoaudio *chip;
1517 chip = snd_kcontrol_chip(kcontrol);
1518 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1519 uinfo->value.enumerated.items = chip->num_clock_sources;
1521 if (uinfo->value.enumerated.item >= chip->num_clock_sources)
1522 uinfo->value.enumerated.item = chip->num_clock_sources - 1;
1523 strcpy(uinfo->value.enumerated.name, names[
1524 chip->clock_source_list[uinfo->value.enumerated.item]]);
1528 static int snd_echo_clock_source_get(struct snd_kcontrol *kcontrol,
1529 struct snd_ctl_elem_value *ucontrol)
1531 struct echoaudio *chip;
1534 chip = snd_kcontrol_chip(kcontrol);
1535 clock = chip->input_clock;
1537 for (i = 0; i < chip->num_clock_sources; i++)
1538 if (clock == chip->clock_source_list[i])
1539 ucontrol->value.enumerated.item[0] = i;
1544 static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
1545 struct snd_ctl_elem_value *ucontrol)
1547 struct echoaudio *chip;
1549 unsigned int eclock, dclock;
1552 chip = snd_kcontrol_chip(kcontrol);
1553 eclock = ucontrol->value.enumerated.item[0];
1554 if (eclock >= chip->input_clock_types)
1556 dclock = chip->clock_source_list[eclock];
1557 if (chip->input_clock != dclock) {
1558 down(&chip->mode_mutex);
1559 spin_lock_irq(&chip->lock);
1560 if ((changed = set_input_clock(chip, dclock)) == 0)
1561 changed = 1; /* no errors */
1562 spin_unlock_irq(&chip->lock);
1563 up(&chip->mode_mutex);
1567 DE_ACT(("seticlk val%d err 0x%x\n", dclock, changed));
1572 static struct snd_kcontrol_new snd_echo_clock_source_switch __devinitdata = {
1573 .name = "Sample Clock Source",
1574 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1575 .info = snd_echo_clock_source_info,
1576 .get = snd_echo_clock_source_get,
1577 .put = snd_echo_clock_source_put,
1580 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1584 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1586 /******************* Phantom power switch *******************/
1587 static int snd_echo_phantom_power_info(struct snd_kcontrol *kcontrol,
1588 struct snd_ctl_elem_info *uinfo)
1590 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1592 uinfo->value.integer.min = 0;
1593 uinfo->value.integer.max = 1;
1597 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1598 struct snd_ctl_elem_value *ucontrol)
1600 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1602 ucontrol->value.integer.value[0] = chip->phantom_power;
1606 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1607 struct snd_ctl_elem_value *ucontrol)
1609 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1610 int power, changed = 0;
1612 power = !!ucontrol->value.integer.value[0];
1613 if (chip->phantom_power != power) {
1614 spin_lock_irq(&chip->lock);
1615 changed = set_phantom_power(chip, power);
1616 spin_unlock_irq(&chip->lock);
1618 changed = 1; /* no errors */
1623 static struct snd_kcontrol_new snd_echo_phantom_power_switch __devinitdata = {
1624 .name = "Phantom power Switch",
1625 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1626 .info = snd_echo_phantom_power_info,
1627 .get = snd_echo_phantom_power_get,
1628 .put = snd_echo_phantom_power_put,
1631 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1635 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1637 /******************* Digital input automute switch *******************/
1638 static int snd_echo_automute_info(struct snd_kcontrol *kcontrol,
1639 struct snd_ctl_elem_info *uinfo)
1641 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1643 uinfo->value.integer.min = 0;
1644 uinfo->value.integer.max = 1;
1648 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1649 struct snd_ctl_elem_value *ucontrol)
1651 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1653 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1657 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1658 struct snd_ctl_elem_value *ucontrol)
1660 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1661 int automute, changed = 0;
1663 automute = !!ucontrol->value.integer.value[0];
1664 if (chip->digital_in_automute != automute) {
1665 spin_lock_irq(&chip->lock);
1666 changed = set_input_auto_mute(chip, automute);
1667 spin_unlock_irq(&chip->lock);
1669 changed = 1; /* no errors */
1674 static struct snd_kcontrol_new snd_echo_automute_switch __devinitdata = {
1675 .name = "Digital Capture Switch (automute)",
1676 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1677 .info = snd_echo_automute_info,
1678 .get = snd_echo_automute_get,
1679 .put = snd_echo_automute_put,
1682 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1686 /******************* VU-meters switch *******************/
1687 static int snd_echo_vumeters_switch_info(struct snd_kcontrol *kcontrol,
1688 struct snd_ctl_elem_info *uinfo)
1690 struct echoaudio *chip;
1692 chip = snd_kcontrol_chip(kcontrol);
1693 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1695 uinfo->value.integer.min = 0;
1696 uinfo->value.integer.max = 1;
1700 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1701 struct snd_ctl_elem_value *ucontrol)
1703 struct echoaudio *chip;
1705 chip = snd_kcontrol_chip(kcontrol);
1706 spin_lock_irq(&chip->lock);
1707 set_meters_on(chip, ucontrol->value.integer.value[0]);
1708 spin_unlock_irq(&chip->lock);
1712 static struct snd_kcontrol_new snd_echo_vumeters_switch __devinitdata = {
1713 .name = "VU-meters Switch",
1714 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1715 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1716 .info = snd_echo_vumeters_switch_info,
1717 .put = snd_echo_vumeters_switch_put,
1722 /***** Read VU-meters (input, output, analog and digital together) *****/
1723 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1724 struct snd_ctl_elem_info *uinfo)
1726 struct echoaudio *chip;
1728 chip = snd_kcontrol_chip(kcontrol);
1729 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1731 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1732 uinfo->value.integer.max = 0;
1733 #ifdef ECHOCARD_HAS_VMIXER
1734 uinfo->dimen.d[0] = 3; /* Out, In, Virt */
1736 uinfo->dimen.d[0] = 2; /* Out, In */
1738 uinfo->dimen.d[1] = 16; /* 16 channels */
1739 uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */
1743 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1744 struct snd_ctl_elem_value *ucontrol)
1746 struct echoaudio *chip;
1748 chip = snd_kcontrol_chip(kcontrol);
1749 get_audio_meters(chip, ucontrol->value.integer.value);
1753 static struct snd_kcontrol_new snd_echo_vumeters __devinitdata = {
1754 .name = "VU-meters",
1755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1756 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1757 .info = snd_echo_vumeters_info,
1758 .get = snd_echo_vumeters_get,
1763 /*** Channels info - it exports informations about the number of channels ***/
1764 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1765 struct snd_ctl_elem_info *uinfo)
1767 struct echoaudio *chip;
1769 chip = snd_kcontrol_chip(kcontrol);
1770 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1772 uinfo->value.integer.min = 0;
1773 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1777 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1778 struct snd_ctl_elem_value *ucontrol)
1780 struct echoaudio *chip;
1781 int detected, clocks, bit, src;
1783 chip = snd_kcontrol_chip(kcontrol);
1784 ucontrol->value.integer.value[0] = num_busses_in(chip);
1785 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1786 ucontrol->value.integer.value[2] = num_busses_out(chip);
1787 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1788 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1790 /* Compute the bitmask of the currently valid input clocks */
1791 detected = detect_input_clocks(chip);
1793 src = chip->num_clock_sources - 1;
1794 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1795 if (detected & (1 << bit))
1796 for (; src >= 0; src--)
1797 if (bit == chip->clock_source_list[src]) {
1801 ucontrol->value.integer.value[5] = clocks;
1806 static struct snd_kcontrol_new snd_echo_channels_info __devinitdata = {
1807 .name = "Channels info",
1808 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1809 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1810 .info = snd_echo_channels_info_info,
1811 .get = snd_echo_channels_info_get,
1817 /******************************************************************************
1819 ******************************************************************************/
1821 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1823 struct echoaudio *chip = dev_id;
1824 struct snd_pcm_substream *substream;
1827 spin_lock(&chip->lock);
1828 st = service_irq(chip);
1830 spin_unlock(&chip->lock);
1833 /* The hardware doesn't tell us which substream caused the irq,
1834 thus we have to check all running substreams. */
1835 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1836 if ((substream = chip->substream[ss])) {
1837 period = pcm_pointer(substream) /
1838 substream->runtime->period_size;
1839 if (period != chip->last_period[ss]) {
1840 chip->last_period[ss] = period;
1841 spin_unlock(&chip->lock);
1842 snd_pcm_period_elapsed(substream);
1843 spin_lock(&chip->lock);
1847 spin_unlock(&chip->lock);
1849 #ifdef ECHOCARD_HAS_MIDI
1850 if (st > 0 && chip->midi_in) {
1851 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1852 DE_MID(("rawmidi_iread=%d\n", st));
1861 /******************************************************************************
1862 Module construction / destruction
1863 ******************************************************************************/
1865 static int snd_echo_free(struct echoaudio *chip)
1867 DE_INIT(("Stop DSP...\n"));
1868 if (chip->comm_page) {
1869 rest_in_peace(chip);
1870 snd_dma_free_pages(&chip->commpage_dma_buf);
1872 DE_INIT(("Stopped.\n"));
1875 free_irq(chip->irq, chip);
1877 if (chip->dsp_registers)
1878 iounmap(chip->dsp_registers);
1881 release_and_free_resource(chip->iores);
1883 DE_INIT(("MMIO freed.\n"));
1885 pci_disable_device(chip->pci);
1887 /* release chip data */
1889 DE_INIT(("Chip freed.\n"));
1895 static int snd_echo_dev_free(struct snd_device *device)
1897 struct echoaudio *chip = device->device_data;
1899 DE_INIT(("snd_echo_dev_free()...\n"));
1900 return snd_echo_free(chip);
1905 /* <--snd_echo_probe() */
1906 static __devinit int snd_echo_create(struct snd_card *card,
1907 struct pci_dev *pci,
1908 struct echoaudio **rchip)
1910 struct echoaudio *chip;
1913 static struct snd_device_ops ops = {
1914 .dev_free = snd_echo_dev_free,
1919 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1921 if ((err = pci_enable_device(pci)) < 0)
1923 pci_set_master(pci);
1925 /* allocate a chip-specific data */
1926 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1928 pci_disable_device(pci);
1931 DE_INIT(("chip=%p\n", chip));
1933 spin_lock_init(&chip->lock);
1938 /* PCI resource allocation */
1939 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1940 sz = pci_resource_len(pci, 0);
1942 sz = PAGE_SIZE; /* We map only the required part */
1944 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1945 ECHOCARD_NAME)) == NULL) {
1946 snd_echo_free(chip);
1947 snd_printk(KERN_ERR "cannot get memory region\n");
1950 chip->dsp_registers = (volatile u32 __iomem *)
1951 ioremap_nocache(chip->dsp_registers_phys, sz);
1953 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1954 ECHOCARD_NAME, chip)) {
1955 snd_echo_free(chip);
1956 snd_printk(KERN_ERR "cannot grab irq\n");
1959 chip->irq = pci->irq;
1960 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n",
1961 chip->pci, chip->irq, chip->pci->subsystem_device));
1963 /* Create the DSP comm page - this is the area of memory used for most
1964 of the communication with the DSP, which accesses it via bus mastering */
1965 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1966 sizeof(struct comm_page),
1967 &chip->commpage_dma_buf) < 0) {
1968 snd_echo_free(chip);
1969 snd_printk(KERN_ERR "cannot allocate the comm page\n");
1972 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1973 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1975 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1977 DE_INIT(("init_hw err=%d\n", err));
1978 snd_echo_free(chip);
1981 DE_INIT(("Card init OK\n"));
1983 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1984 snd_echo_free(chip);
1987 atomic_set(&chip->opencount, 0);
1988 init_MUTEX(&chip->mode_mutex);
1989 chip->can_set_rate = 1;
1998 static int __devinit snd_echo_probe(struct pci_dev *pci,
1999 const struct pci_device_id *pci_id)
2002 struct snd_card *card;
2003 struct echoaudio *chip;
2007 if (dev >= SNDRV_CARDS)
2014 DE_INIT(("Echoaudio driver starting...\n"));
2016 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2020 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2021 snd_card_free(card);
2025 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
2026 strcpy(card->shortname, chip->card_name);
2029 if (pci_id->device == 0x3410)
2032 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2033 card->shortname, pci_id->subdevice & 0x000f, dsp,
2034 chip->dsp_registers_phys, chip->irq);
2036 if ((err = snd_echo_new_pcm(chip)) < 0) {
2037 snd_printk(KERN_ERR "new pcm error %d\n", err);
2038 snd_card_free(card);
2042 #ifdef ECHOCARD_HAS_MIDI
2043 if (chip->has_midi) { /* Some Mia's do not have midi */
2044 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2045 snd_printk(KERN_ERR "new midi error %d\n", err);
2046 snd_card_free(card);
2052 #ifdef ECHOCARD_HAS_VMIXER
2053 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2054 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_output_gain, chip))) < 0)
2056 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2059 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_pcm_output_gain, chip))) < 0)
2063 #ifdef ECHOCARD_HAS_INPUT_GAIN
2064 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2068 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2069 if (!chip->hasnt_input_nominal_level)
2070 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2074 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2075 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2079 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2082 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2085 #ifdef ECHOCARD_HAS_MONITOR
2086 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2087 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2091 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2092 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2096 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2099 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2100 /* Creates a list of available digital modes */
2101 chip->num_digital_modes = 0;
2102 for (i = 0; i < 6; i++)
2103 if (chip->digital_modes & (1 << i))
2104 chip->digital_mode_list[chip->num_digital_modes++] = i;
2106 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2108 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2110 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2111 /* Creates a list of available clock sources */
2112 chip->num_clock_sources = 0;
2113 for (i = 0; i < 10; i++)
2114 if (chip->input_clock_types & (1 << i))
2115 chip->clock_source_list[chip->num_clock_sources++] = i;
2117 if (chip->num_clock_sources > 1) {
2118 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2119 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2122 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2124 #ifdef ECHOCARD_HAS_DIGITAL_IO
2125 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2129 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2130 if (chip->has_phantom_power)
2131 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2135 if ((err = snd_card_register(card)) < 0) {
2136 snd_card_free(card);
2139 snd_printk(KERN_INFO "Card registered: %s\n", card->longname);
2141 pci_set_drvdata(pci, chip);
2146 snd_printk(KERN_ERR "new control error %d\n", err);
2147 snd_card_free(card);
2153 static void __devexit snd_echo_remove(struct pci_dev *pci)
2155 struct echoaudio *chip;
2157 chip = pci_get_drvdata(pci);
2159 snd_card_free(chip->card);
2160 pci_set_drvdata(pci, NULL);
2165 /******************************************************************************
2166 Everything starts and ends here
2167 ******************************************************************************/
2169 /* pci_driver definition */
2170 static struct pci_driver driver = {
2171 .name = "Echoaudio " ECHOCARD_NAME,
2172 .id_table = snd_echo_ids,
2173 .probe = snd_echo_probe,
2174 .remove = __devexit_p(snd_echo_remove),
2179 /* initialization of the module */
2180 static int __init alsa_card_echo_init(void)
2182 return pci_register_driver(&driver);
2187 /* clean up the module */
2188 static void __exit alsa_card_echo_exit(void)
2190 pci_unregister_driver(&driver);
2194 module_init(alsa_card_echo_init)
2195 module_exit(alsa_card_echo_exit)