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 down(&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 up(&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 down(&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 up(&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 snd_assert(pipe_index < px_num(chip), return -EINVAL);
694 snd_assert(is_pipe_allocated(chip, pipe_index), return -EINVAL);
695 set_audio_format(chip, pipe_index, &format);
701 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
703 struct echoaudio *chip = snd_pcm_substream_chip(substream);
704 struct snd_pcm_runtime *runtime = substream->runtime;
705 struct audiopipe *pipe = runtime->private_data;
708 struct list_head *pos;
709 struct snd_pcm_substream *s;
711 snd_pcm_group_for_each(pos, substream) {
712 s = snd_pcm_group_substream_entry(pos);
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 down(&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 up(&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 down(&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 up(&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 static int snd_echo_phantom_power_info(struct snd_kcontrol *kcontrol,
1601 struct snd_ctl_elem_info *uinfo)
1603 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1605 uinfo->value.integer.min = 0;
1606 uinfo->value.integer.max = 1;
1610 static int snd_echo_phantom_power_get(struct snd_kcontrol *kcontrol,
1611 struct snd_ctl_elem_value *ucontrol)
1613 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1615 ucontrol->value.integer.value[0] = chip->phantom_power;
1619 static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1622 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1623 int power, changed = 0;
1625 power = !!ucontrol->value.integer.value[0];
1626 if (chip->phantom_power != power) {
1627 spin_lock_irq(&chip->lock);
1628 changed = set_phantom_power(chip, power);
1629 spin_unlock_irq(&chip->lock);
1631 changed = 1; /* no errors */
1636 static struct snd_kcontrol_new snd_echo_phantom_power_switch __devinitdata = {
1637 .name = "Phantom power Switch",
1638 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1639 .info = snd_echo_phantom_power_info,
1640 .get = snd_echo_phantom_power_get,
1641 .put = snd_echo_phantom_power_put,
1644 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1648 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1650 /******************* Digital input automute switch *******************/
1651 static int snd_echo_automute_info(struct snd_kcontrol *kcontrol,
1652 struct snd_ctl_elem_info *uinfo)
1654 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1656 uinfo->value.integer.min = 0;
1657 uinfo->value.integer.max = 1;
1661 static int snd_echo_automute_get(struct snd_kcontrol *kcontrol,
1662 struct snd_ctl_elem_value *ucontrol)
1664 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1666 ucontrol->value.integer.value[0] = chip->digital_in_automute;
1670 static int snd_echo_automute_put(struct snd_kcontrol *kcontrol,
1671 struct snd_ctl_elem_value *ucontrol)
1673 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1674 int automute, changed = 0;
1676 automute = !!ucontrol->value.integer.value[0];
1677 if (chip->digital_in_automute != automute) {
1678 spin_lock_irq(&chip->lock);
1679 changed = set_input_auto_mute(chip, automute);
1680 spin_unlock_irq(&chip->lock);
1682 changed = 1; /* no errors */
1687 static struct snd_kcontrol_new snd_echo_automute_switch __devinitdata = {
1688 .name = "Digital Capture Switch (automute)",
1689 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1690 .info = snd_echo_automute_info,
1691 .get = snd_echo_automute_get,
1692 .put = snd_echo_automute_put,
1695 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1699 /******************* VU-meters switch *******************/
1700 static int snd_echo_vumeters_switch_info(struct snd_kcontrol *kcontrol,
1701 struct snd_ctl_elem_info *uinfo)
1703 struct echoaudio *chip;
1705 chip = snd_kcontrol_chip(kcontrol);
1706 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1708 uinfo->value.integer.min = 0;
1709 uinfo->value.integer.max = 1;
1713 static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,
1714 struct snd_ctl_elem_value *ucontrol)
1716 struct echoaudio *chip;
1718 chip = snd_kcontrol_chip(kcontrol);
1719 spin_lock_irq(&chip->lock);
1720 set_meters_on(chip, ucontrol->value.integer.value[0]);
1721 spin_unlock_irq(&chip->lock);
1725 static struct snd_kcontrol_new snd_echo_vumeters_switch __devinitdata = {
1726 .name = "VU-meters Switch",
1727 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
1728 .access = SNDRV_CTL_ELEM_ACCESS_WRITE,
1729 .info = snd_echo_vumeters_switch_info,
1730 .put = snd_echo_vumeters_switch_put,
1735 /***** Read VU-meters (input, output, analog and digital together) *****/
1736 static int snd_echo_vumeters_info(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_info *uinfo)
1739 struct echoaudio *chip;
1741 chip = snd_kcontrol_chip(kcontrol);
1742 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1744 uinfo->value.integer.min = ECHOGAIN_MINOUT;
1745 uinfo->value.integer.max = 0;
1746 #ifdef ECHOCARD_HAS_VMIXER
1747 uinfo->dimen.d[0] = 3; /* Out, In, Virt */
1749 uinfo->dimen.d[0] = 2; /* Out, In */
1751 uinfo->dimen.d[1] = 16; /* 16 channels */
1752 uinfo->dimen.d[2] = 2; /* 0=level, 1=peak */
1756 static int snd_echo_vumeters_get(struct snd_kcontrol *kcontrol,
1757 struct snd_ctl_elem_value *ucontrol)
1759 struct echoaudio *chip;
1761 chip = snd_kcontrol_chip(kcontrol);
1762 get_audio_meters(chip, ucontrol->value.integer.value);
1766 static struct snd_kcontrol_new snd_echo_vumeters __devinitdata = {
1767 .name = "VU-meters",
1768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1769 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1770 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
1771 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1772 .info = snd_echo_vumeters_info,
1773 .get = snd_echo_vumeters_get,
1774 .tlv = {.p = db_scale_output_gain},
1779 /*** Channels info - it exports informations about the number of channels ***/
1780 static int snd_echo_channels_info_info(struct snd_kcontrol *kcontrol,
1781 struct snd_ctl_elem_info *uinfo)
1783 struct echoaudio *chip;
1785 chip = snd_kcontrol_chip(kcontrol);
1786 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1788 uinfo->value.integer.min = 0;
1789 uinfo->value.integer.max = 1 << ECHO_CLOCK_NUMBER;
1793 static int snd_echo_channels_info_get(struct snd_kcontrol *kcontrol,
1794 struct snd_ctl_elem_value *ucontrol)
1796 struct echoaudio *chip;
1797 int detected, clocks, bit, src;
1799 chip = snd_kcontrol_chip(kcontrol);
1800 ucontrol->value.integer.value[0] = num_busses_in(chip);
1801 ucontrol->value.integer.value[1] = num_analog_busses_in(chip);
1802 ucontrol->value.integer.value[2] = num_busses_out(chip);
1803 ucontrol->value.integer.value[3] = num_analog_busses_out(chip);
1804 ucontrol->value.integer.value[4] = num_pipes_out(chip);
1806 /* Compute the bitmask of the currently valid input clocks */
1807 detected = detect_input_clocks(chip);
1809 src = chip->num_clock_sources - 1;
1810 for (bit = ECHO_CLOCK_NUMBER - 1; bit >= 0; bit--)
1811 if (detected & (1 << bit))
1812 for (; src >= 0; src--)
1813 if (bit == chip->clock_source_list[src]) {
1817 ucontrol->value.integer.value[5] = clocks;
1822 static struct snd_kcontrol_new snd_echo_channels_info __devinitdata = {
1823 .name = "Channels info",
1824 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
1825 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1826 .info = snd_echo_channels_info_info,
1827 .get = snd_echo_channels_info_get,
1833 /******************************************************************************
1835 ******************************************************************************/
1837 static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1839 struct echoaudio *chip = dev_id;
1840 struct snd_pcm_substream *substream;
1843 spin_lock(&chip->lock);
1844 st = service_irq(chip);
1846 spin_unlock(&chip->lock);
1849 /* The hardware doesn't tell us which substream caused the irq,
1850 thus we have to check all running substreams. */
1851 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1852 if ((substream = chip->substream[ss])) {
1853 period = pcm_pointer(substream) /
1854 substream->runtime->period_size;
1855 if (period != chip->last_period[ss]) {
1856 chip->last_period[ss] = period;
1857 spin_unlock(&chip->lock);
1858 snd_pcm_period_elapsed(substream);
1859 spin_lock(&chip->lock);
1863 spin_unlock(&chip->lock);
1865 #ifdef ECHOCARD_HAS_MIDI
1866 if (st > 0 && chip->midi_in) {
1867 snd_rawmidi_receive(chip->midi_in, chip->midi_buffer, st);
1868 DE_MID(("rawmidi_iread=%d\n", st));
1877 /******************************************************************************
1878 Module construction / destruction
1879 ******************************************************************************/
1881 static int snd_echo_free(struct echoaudio *chip)
1883 DE_INIT(("Stop DSP...\n"));
1884 if (chip->comm_page) {
1885 rest_in_peace(chip);
1886 snd_dma_free_pages(&chip->commpage_dma_buf);
1888 DE_INIT(("Stopped.\n"));
1891 free_irq(chip->irq, chip);
1893 if (chip->dsp_registers)
1894 iounmap(chip->dsp_registers);
1897 release_and_free_resource(chip->iores);
1899 DE_INIT(("MMIO freed.\n"));
1901 pci_disable_device(chip->pci);
1903 /* release chip data */
1905 DE_INIT(("Chip freed.\n"));
1911 static int snd_echo_dev_free(struct snd_device *device)
1913 struct echoaudio *chip = device->device_data;
1915 DE_INIT(("snd_echo_dev_free()...\n"));
1916 return snd_echo_free(chip);
1921 /* <--snd_echo_probe() */
1922 static __devinit int snd_echo_create(struct snd_card *card,
1923 struct pci_dev *pci,
1924 struct echoaudio **rchip)
1926 struct echoaudio *chip;
1929 static struct snd_device_ops ops = {
1930 .dev_free = snd_echo_dev_free,
1935 pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0);
1937 if ((err = pci_enable_device(pci)) < 0)
1939 pci_set_master(pci);
1941 /* allocate a chip-specific data */
1942 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1944 pci_disable_device(pci);
1947 DE_INIT(("chip=%p\n", chip));
1949 spin_lock_init(&chip->lock);
1954 /* PCI resource allocation */
1955 chip->dsp_registers_phys = pci_resource_start(pci, 0);
1956 sz = pci_resource_len(pci, 0);
1958 sz = PAGE_SIZE; /* We map only the required part */
1960 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1961 ECHOCARD_NAME)) == NULL) {
1962 snd_echo_free(chip);
1963 snd_printk(KERN_ERR "cannot get memory region\n");
1966 chip->dsp_registers = (volatile u32 __iomem *)
1967 ioremap_nocache(chip->dsp_registers_phys, sz);
1969 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1970 ECHOCARD_NAME, chip)) {
1971 snd_echo_free(chip);
1972 snd_printk(KERN_ERR "cannot grab irq\n");
1975 chip->irq = pci->irq;
1976 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n",
1977 chip->pci, chip->irq, chip->pci->subsystem_device));
1979 /* Create the DSP comm page - this is the area of memory used for most
1980 of the communication with the DSP, which accesses it via bus mastering */
1981 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1982 sizeof(struct comm_page),
1983 &chip->commpage_dma_buf) < 0) {
1984 snd_echo_free(chip);
1985 snd_printk(KERN_ERR "cannot allocate the comm page\n");
1988 chip->comm_page_phys = chip->commpage_dma_buf.addr;
1989 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1991 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1993 DE_INIT(("init_hw err=%d\n", err));
1994 snd_echo_free(chip);
1997 DE_INIT(("Card init OK\n"));
1999 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2000 snd_echo_free(chip);
2003 atomic_set(&chip->opencount, 0);
2004 init_MUTEX(&chip->mode_mutex);
2005 chip->can_set_rate = 1;
2014 static int __devinit snd_echo_probe(struct pci_dev *pci,
2015 const struct pci_device_id *pci_id)
2018 struct snd_card *card;
2019 struct echoaudio *chip;
2023 if (dev >= SNDRV_CARDS)
2030 DE_INIT(("Echoaudio driver starting...\n"));
2032 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2036 snd_card_set_dev(card, &pci->dev);
2038 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2039 snd_card_free(card);
2043 strcpy(card->driver, "Echo_" ECHOCARD_NAME);
2044 strcpy(card->shortname, chip->card_name);
2047 if (pci_id->device == 0x3410)
2050 sprintf(card->longname, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2051 card->shortname, pci_id->subdevice & 0x000f, dsp,
2052 chip->dsp_registers_phys, chip->irq);
2054 if ((err = snd_echo_new_pcm(chip)) < 0) {
2055 snd_printk(KERN_ERR "new pcm error %d\n", err);
2056 snd_card_free(card);
2060 #ifdef ECHOCARD_HAS_MIDI
2061 if (chip->has_midi) { /* Some Mia's do not have midi */
2062 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2063 snd_printk(KERN_ERR "new midi error %d\n", err);
2064 snd_card_free(card);
2070 #ifdef ECHOCARD_HAS_VMIXER
2071 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2072 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_output_gain, chip))) < 0)
2074 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2077 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_pcm_output_gain, chip))) < 0)
2081 #ifdef ECHOCARD_HAS_INPUT_GAIN
2082 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
2086 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2087 if (!chip->hasnt_input_nominal_level)
2088 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0)
2092 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2093 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0)
2097 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0)
2100 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0)
2103 #ifdef ECHOCARD_HAS_MONITOR
2104 snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip);
2105 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0)
2109 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2110 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0)
2114 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0)
2117 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2118 /* Creates a list of available digital modes */
2119 chip->num_digital_modes = 0;
2120 for (i = 0; i < 6; i++)
2121 if (chip->digital_modes & (1 << i))
2122 chip->digital_mode_list[chip->num_digital_modes++] = i;
2124 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0)
2126 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2128 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2129 /* Creates a list of available clock sources */
2130 chip->num_clock_sources = 0;
2131 for (i = 0; i < 10; i++)
2132 if (chip->input_clock_types & (1 << i))
2133 chip->clock_source_list[chip->num_clock_sources++] = i;
2135 if (chip->num_clock_sources > 1) {
2136 chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip);
2137 if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0)
2140 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2142 #ifdef ECHOCARD_HAS_DIGITAL_IO
2143 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0)
2147 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2148 if (chip->has_phantom_power)
2149 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0)
2153 if ((err = snd_card_register(card)) < 0) {
2154 snd_card_free(card);
2157 snd_printk(KERN_INFO "Card registered: %s\n", card->longname);
2159 pci_set_drvdata(pci, chip);
2164 snd_printk(KERN_ERR "new control error %d\n", err);
2165 snd_card_free(card);
2171 static void __devexit snd_echo_remove(struct pci_dev *pci)
2173 struct echoaudio *chip;
2175 chip = pci_get_drvdata(pci);
2177 snd_card_free(chip->card);
2178 pci_set_drvdata(pci, NULL);
2183 /******************************************************************************
2184 Everything starts and ends here
2185 ******************************************************************************/
2187 /* pci_driver definition */
2188 static struct pci_driver driver = {
2189 .name = "Echoaudio " ECHOCARD_NAME,
2190 .id_table = snd_echo_ids,
2191 .probe = snd_echo_probe,
2192 .remove = __devexit_p(snd_echo_remove),
2197 /* initialization of the module */
2198 static int __init alsa_card_echo_init(void)
2200 return pci_register_driver(&driver);
2205 /* clean up the module */
2206 static void __exit alsa_card_echo_exit(void)
2208 pci_unregister_driver(&driver);
2212 module_init(alsa_card_echo_init)
2213 module_exit(alsa_card_echo_exit)