2 * ALSA driver for Echoaudio soundcards.
3 * Copyright (C) 2003-2004 Giuliano Pochini <pochini@shiny.it>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <linux/module.h>
21 MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>");
22 MODULE_LICENSE("GPL v2");
23 MODULE_DESCRIPTION("Echoaudio " ECHOCARD_NAME
" soundcards driver");
24 MODULE_SUPPORTED_DEVICE("{{Echoaudio," ECHOCARD_NAME
"}}");
25 MODULE_DEVICE_TABLE(pci
, snd_echo_ids
);
27 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
28 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
29 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
31 module_param_array(index
, int, NULL
, 0444);
32 MODULE_PARM_DESC(index
, "Index value for " ECHOCARD_NAME
" soundcard.");
33 module_param_array(id
, charp
, NULL
, 0444);
34 MODULE_PARM_DESC(id
, "ID string for " ECHOCARD_NAME
" soundcard.");
35 module_param_array(enable
, bool, NULL
, 0444);
36 MODULE_PARM_DESC(enable
, "Enable " ECHOCARD_NAME
" soundcard.");
38 static unsigned int channels_list
[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
39 static const DECLARE_TLV_DB_SCALE(db_scale_output_gain
, -12800, 100, 1);
43 static int get_firmware(const struct firmware
**fw_entry
,
44 struct echoaudio
*chip
, const short fw_index
)
50 if (chip
->fw_cache
[fw_index
]) {
51 DE_ACT(("firmware requested: %s is cached\n", card_fw
[fw_index
].data
));
52 *fw_entry
= chip
->fw_cache
[fw_index
];
57 DE_ACT(("firmware requested: %s\n", card_fw
[fw_index
].data
));
58 snprintf(name
, sizeof(name
), "ea/%s", card_fw
[fw_index
].data
);
59 err
= request_firmware(fw_entry
, name
, pci_device(chip
));
61 snd_printk(KERN_ERR
"get_firmware(): Firmware not available (%d)\n", err
);
64 chip
->fw_cache
[fw_index
] = *fw_entry
;
71 static void free_firmware(const struct firmware
*fw_entry
)
74 DE_ACT(("firmware not released (kept in cache)\n"));
76 release_firmware(fw_entry
);
77 DE_ACT(("firmware released\n"));
83 static void free_firmware_cache(struct echoaudio
*chip
)
88 for (i
= 0; i
< 8 ; i
++)
89 if (chip
->fw_cache
[i
]) {
90 release_firmware(chip
->fw_cache
[i
]);
91 DE_ACT(("release_firmware(%d)\n", i
));
94 DE_ACT(("firmware_cache released\n"));
100 /******************************************************************************
102 ******************************************************************************/
104 static void audiopipe_free(struct snd_pcm_runtime
*runtime
)
106 struct audiopipe
*pipe
= runtime
->private_data
;
108 if (pipe
->sgpage
.area
)
109 snd_dma_free_pages(&pipe
->sgpage
);
115 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params
*params
,
116 struct snd_pcm_hw_rule
*rule
)
118 struct snd_interval
*c
= hw_param_interval(params
,
119 SNDRV_PCM_HW_PARAM_CHANNELS
);
120 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
125 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
126 /* >=2 channels cannot be S32_BE */
128 fmt
.bits
[0] &= ~SNDRV_PCM_FMTBIT_S32_BE
;
129 return snd_mask_refine(f
, &fmt
);
132 /* > 2 channels cannot be U8 and S32_BE */
134 fmt
.bits
[0] &= ~(SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S32_BE
);
135 return snd_mask_refine(f
, &fmt
);
137 /* Mono is ok with any format */
143 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params
*params
,
144 struct snd_pcm_hw_rule
*rule
)
146 struct snd_interval
*c
= hw_param_interval(params
,
147 SNDRV_PCM_HW_PARAM_CHANNELS
);
148 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
149 struct snd_interval ch
;
151 snd_interval_any(&ch
);
153 /* S32_BE is mono (and stereo) only */
154 if (f
->bits
[0] == SNDRV_PCM_FMTBIT_S32_BE
) {
156 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
162 return snd_interval_refine(c
, &ch
);
164 /* U8 can be only mono or stereo */
165 if (f
->bits
[0] == SNDRV_PCM_FMTBIT_U8
) {
169 return snd_interval_refine(c
, &ch
);
171 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
177 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params
*params
,
178 struct snd_pcm_hw_rule
*rule
)
180 struct snd_interval
*c
= hw_param_interval(params
,
181 SNDRV_PCM_HW_PARAM_CHANNELS
);
182 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
187 fmask
= fmt
.bits
[0] + ((u64
)fmt
.bits
[1] << 32);
189 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
191 fmask
&= SNDRV_PCM_FMTBIT_S16_LE
|
192 SNDRV_PCM_FMTBIT_S24_3LE
|
193 SNDRV_PCM_FMTBIT_S32_LE
;
194 /* 1 channel must be S32_BE or S32_LE */
195 } else if (c
->max
== 1)
196 fmask
&= SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
;
197 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
198 /* 2 channels cannot be S32_BE */
199 else if (c
->min
== 2 && c
->max
== 2)
200 fmask
&= ~SNDRV_PCM_FMTBIT_S32_BE
;
205 fmt
.bits
[0] &= (u32
)fmask
;
206 fmt
.bits
[1] &= (u32
)(fmask
>> 32);
207 return snd_mask_refine(f
, &fmt
);
212 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params
*params
,
213 struct snd_pcm_hw_rule
*rule
)
215 struct snd_interval
*c
= hw_param_interval(params
,
216 SNDRV_PCM_HW_PARAM_CHANNELS
);
217 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
218 struct snd_interval ch
;
221 snd_interval_any(&ch
);
223 fmask
= f
->bits
[0] + ((u64
)f
->bits
[1] << 32);
225 /* S32_BE is mono (and stereo) only */
226 if (fmask
== SNDRV_PCM_FMTBIT_S32_BE
) {
228 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
233 /* U8 is stereo only */
234 } else if (fmask
== SNDRV_PCM_FMTBIT_U8
)
236 /* S16_LE and S24_3LE must be at least stereo */
237 else if (!(fmask
& ~(SNDRV_PCM_FMTBIT_S16_LE
|
238 SNDRV_PCM_FMTBIT_S24_3LE
)))
243 return snd_interval_refine(c
, &ch
);
248 /* Since the sample rate is a global setting, do allow the user to change the
249 sample rate only if there is only one pcm device open. */
250 static int hw_rule_sample_rate(struct snd_pcm_hw_params
*params
,
251 struct snd_pcm_hw_rule
*rule
)
253 struct snd_interval
*rate
= hw_param_interval(params
,
254 SNDRV_PCM_HW_PARAM_RATE
);
255 struct echoaudio
*chip
= rule
->private;
256 struct snd_interval fixed
;
258 if (!chip
->can_set_rate
) {
259 snd_interval_any(&fixed
);
260 fixed
.min
= fixed
.max
= chip
->sample_rate
;
261 return snd_interval_refine(rate
, &fixed
);
267 static int pcm_open(struct snd_pcm_substream
*substream
,
268 signed char max_channels
)
270 struct echoaudio
*chip
;
271 struct snd_pcm_runtime
*runtime
;
272 struct audiopipe
*pipe
;
275 if (max_channels
<= 0)
278 chip
= snd_pcm_substream_chip(substream
);
279 runtime
= substream
->runtime
;
281 pipe
= kzalloc(sizeof(struct audiopipe
), GFP_KERNEL
);
284 pipe
->index
= -1; /* Not configured yet */
286 /* Set up hw capabilities and contraints */
287 memcpy(&pipe
->hw
, &pcm_hardware_skel
, sizeof(struct snd_pcm_hardware
));
288 DE_HWP(("max_channels=%d\n", max_channels
));
289 pipe
->constr
.list
= channels_list
;
290 pipe
->constr
.mask
= 0;
291 for (i
= 0; channels_list
[i
] <= max_channels
; i
++);
292 pipe
->constr
.count
= i
;
293 if (pipe
->hw
.channels_max
> max_channels
)
294 pipe
->hw
.channels_max
= max_channels
;
295 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
) {
296 pipe
->hw
.rate_max
= 48000;
297 pipe
->hw
.rates
&= SNDRV_PCM_RATE_8000_48000
;
300 runtime
->hw
= pipe
->hw
;
301 runtime
->private_data
= pipe
;
302 runtime
->private_free
= audiopipe_free
;
303 snd_pcm_set_sync(substream
);
305 /* Only mono and any even number of channels are allowed */
306 if ((err
= snd_pcm_hw_constraint_list(runtime
, 0,
307 SNDRV_PCM_HW_PARAM_CHANNELS
,
311 /* All periods should have the same size */
312 if ((err
= snd_pcm_hw_constraint_integer(runtime
,
313 SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
316 /* The hw accesses memory in chunks 32 frames long and they should be
317 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
318 generated with a resolution of 32 frames. Thus we need the following */
319 if ((err
= snd_pcm_hw_constraint_step(runtime
, 0,
320 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
323 if ((err
= snd_pcm_hw_constraint_step(runtime
, 0,
324 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
328 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
329 SNDRV_PCM_HW_PARAM_RATE
,
330 hw_rule_sample_rate
, chip
,
331 SNDRV_PCM_HW_PARAM_RATE
, -1)) < 0)
334 /* Finally allocate a page for the scatter-gather list */
335 if ((err
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
,
336 snd_dma_pci_data(chip
->pci
),
337 PAGE_SIZE
, &pipe
->sgpage
)) < 0) {
338 DE_HWP(("s-g list allocation failed\n"));
347 static int pcm_analog_in_open(struct snd_pcm_substream
*substream
)
349 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
352 DE_ACT(("pcm_analog_in_open\n"));
353 if ((err
= pcm_open(substream
, num_analog_busses_in(chip
) -
354 substream
->number
)) < 0)
356 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
357 SNDRV_PCM_HW_PARAM_CHANNELS
,
358 hw_rule_capture_channels_by_format
, NULL
,
359 SNDRV_PCM_HW_PARAM_FORMAT
, -1)) < 0)
361 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
362 SNDRV_PCM_HW_PARAM_FORMAT
,
363 hw_rule_capture_format_by_channels
, NULL
,
364 SNDRV_PCM_HW_PARAM_CHANNELS
, -1)) < 0)
366 atomic_inc(&chip
->opencount
);
367 if (atomic_read(&chip
->opencount
) > 1 && chip
->rate_set
)
368 chip
->can_set_rate
=0;
369 DE_HWP(("pcm_analog_in_open cs=%d oc=%d r=%d\n",
370 chip
->can_set_rate
, atomic_read(&chip
->opencount
),
377 static int pcm_analog_out_open(struct snd_pcm_substream
*substream
)
379 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
380 int max_channels
, err
;
382 #ifdef ECHOCARD_HAS_VMIXER
383 max_channels
= num_pipes_out(chip
);
385 max_channels
= num_analog_busses_out(chip
);
387 DE_ACT(("pcm_analog_out_open\n"));
388 if ((err
= pcm_open(substream
, max_channels
- substream
->number
)) < 0)
390 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
391 SNDRV_PCM_HW_PARAM_CHANNELS
,
392 hw_rule_playback_channels_by_format
,
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_playback_format_by_channels
,
400 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;
405 DE_HWP(("pcm_analog_out_open cs=%d oc=%d r=%d\n",
406 chip
->can_set_rate
, atomic_read(&chip
->opencount
),
413 #ifdef ECHOCARD_HAS_DIGITAL_IO
415 static int pcm_digital_in_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_in_open\n"));
421 max_channels
= num_digital_busses_in(chip
) - substream
->number
;
422 mutex_lock(&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_capture_channels_by_format
, NULL
,
436 SNDRV_PCM_HW_PARAM_FORMAT
, -1)) < 0)
438 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
439 SNDRV_PCM_HW_PARAM_FORMAT
,
440 hw_rule_capture_format_by_channels
, NULL
,
441 SNDRV_PCM_HW_PARAM_CHANNELS
, -1)) < 0)
444 atomic_inc(&chip
->opencount
);
445 if (atomic_read(&chip
->opencount
) > 1 && chip
->rate_set
)
446 chip
->can_set_rate
=0;
449 mutex_unlock(&chip
->mode_mutex
);
455 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
457 static int pcm_digital_out_open(struct snd_pcm_substream
*substream
)
459 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
460 int err
, max_channels
;
462 DE_ACT(("pcm_digital_out_open\n"));
463 max_channels
= num_digital_busses_out(chip
) - substream
->number
;
464 mutex_lock(&chip
->mode_mutex
);
465 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
)
466 err
= pcm_open(substream
, max_channels
);
467 else /* If the card has ADAT, subtract the 6 channels
468 * that S/PDIF doesn't have
470 err
= pcm_open(substream
, max_channels
- ECHOCARD_HAS_ADAT
);
475 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
476 SNDRV_PCM_HW_PARAM_CHANNELS
,
477 hw_rule_playback_channels_by_format
,
478 NULL
, SNDRV_PCM_HW_PARAM_FORMAT
,
481 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
482 SNDRV_PCM_HW_PARAM_FORMAT
,
483 hw_rule_playback_format_by_channels
,
484 NULL
, SNDRV_PCM_HW_PARAM_CHANNELS
,
487 atomic_inc(&chip
->opencount
);
488 if (atomic_read(&chip
->opencount
) > 1 && chip
->rate_set
)
489 chip
->can_set_rate
=0;
491 mutex_unlock(&chip
->mode_mutex
);
495 #endif /* !ECHOCARD_HAS_VMIXER */
497 #endif /* ECHOCARD_HAS_DIGITAL_IO */
501 static int pcm_close(struct snd_pcm_substream
*substream
)
503 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
506 /* Nothing to do here. Audio is already off and pipe will be
507 * freed by its callback
509 DE_ACT(("pcm_close\n"));
511 atomic_dec(&chip
->opencount
);
512 oc
= atomic_read(&chip
->opencount
);
513 DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc
,
514 chip
->can_set_rate
, chip
->rate_set
));
516 chip
->can_set_rate
= 1;
519 DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc
,
520 chip
->can_set_rate
,chip
->rate_set
));
527 /* Channel allocation and scatter-gather list setup */
528 static int init_engine(struct snd_pcm_substream
*substream
,
529 struct snd_pcm_hw_params
*hw_params
,
530 int pipe_index
, int interleave
)
532 struct echoaudio
*chip
;
533 int err
, per
, rest
, page
, edge
, offs
;
534 struct audiopipe
*pipe
;
536 chip
= snd_pcm_substream_chip(substream
);
537 pipe
= (struct audiopipe
*) substream
->runtime
->private_data
;
539 /* Sets up che hardware. If it's already initialized, reset and
540 * redo with the new parameters
542 spin_lock_irq(&chip
->lock
);
543 if (pipe
->index
>= 0) {
544 DE_HWP(("hwp_ie free(%d)\n", pipe
->index
));
545 err
= free_pipes(chip
, pipe
);
547 chip
->substream
[pipe
->index
] = NULL
;
550 err
= allocate_pipes(chip
, pipe
, pipe_index
, interleave
);
552 spin_unlock_irq(&chip
->lock
);
553 DE_ACT((KERN_NOTICE
"allocate_pipes(%d) err=%d\n",
557 spin_unlock_irq(&chip
->lock
);
558 DE_ACT((KERN_NOTICE
"allocate_pipes()=%d\n", pipe_index
));
560 DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
561 params_buffer_bytes(hw_params
), params_periods(hw_params
),
562 params_period_bytes(hw_params
)));
563 err
= snd_pcm_lib_malloc_pages(substream
,
564 params_buffer_bytes(hw_params
));
566 snd_printk(KERN_ERR
"malloc_pages err=%d\n", err
);
567 spin_lock_irq(&chip
->lock
);
568 free_pipes(chip
, pipe
);
569 spin_unlock_irq(&chip
->lock
);
574 sglist_init(chip
, pipe
);
576 for (offs
= page
= per
= 0; offs
< params_buffer_bytes(hw_params
);
578 rest
= params_period_bytes(hw_params
);
579 if (offs
+ rest
> params_buffer_bytes(hw_params
))
580 rest
= params_buffer_bytes(hw_params
) - offs
;
583 addr
= snd_pcm_sgbuf_get_addr(substream
, offs
);
584 if (rest
<= edge
- offs
) {
585 sglist_add_mapping(chip
, pipe
, addr
, rest
);
586 sglist_add_irq(chip
, pipe
);
590 sglist_add_mapping(chip
, pipe
, addr
,
602 /* Close the ring buffer */
603 sglist_wrap(chip
, pipe
);
605 /* This stuff is used by the irq handler, so it must be
606 * initialized before chip->substream
608 chip
->last_period
[pipe_index
] = 0;
609 pipe
->last_counter
= 0;
612 chip
->substream
[pipe_index
] = substream
;
614 spin_lock_irq(&chip
->lock
);
615 set_sample_rate(chip
, hw_params
->rate_num
/ hw_params
->rate_den
);
616 spin_unlock_irq(&chip
->lock
);
617 DE_HWP(("pcm_hw_params ok\n"));
623 static int pcm_analog_in_hw_params(struct snd_pcm_substream
*substream
,
624 struct snd_pcm_hw_params
*hw_params
)
626 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
628 return init_engine(substream
, hw_params
, px_analog_in(chip
) +
629 substream
->number
, params_channels(hw_params
));
634 static int pcm_analog_out_hw_params(struct snd_pcm_substream
*substream
,
635 struct snd_pcm_hw_params
*hw_params
)
637 return init_engine(substream
, hw_params
, substream
->number
,
638 params_channels(hw_params
));
643 #ifdef ECHOCARD_HAS_DIGITAL_IO
645 static int pcm_digital_in_hw_params(struct snd_pcm_substream
*substream
,
646 struct snd_pcm_hw_params
*hw_params
)
648 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
650 return init_engine(substream
, hw_params
, px_digital_in(chip
) +
651 substream
->number
, params_channels(hw_params
));
656 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
657 static int pcm_digital_out_hw_params(struct snd_pcm_substream
*substream
,
658 struct snd_pcm_hw_params
*hw_params
)
660 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
662 return init_engine(substream
, hw_params
, px_digital_out(chip
) +
663 substream
->number
, params_channels(hw_params
));
665 #endif /* !ECHOCARD_HAS_VMIXER */
667 #endif /* ECHOCARD_HAS_DIGITAL_IO */
671 static int pcm_hw_free(struct snd_pcm_substream
*substream
)
673 struct echoaudio
*chip
;
674 struct audiopipe
*pipe
;
676 chip
= snd_pcm_substream_chip(substream
);
677 pipe
= (struct audiopipe
*) substream
->runtime
->private_data
;
679 spin_lock_irq(&chip
->lock
);
680 if (pipe
->index
>= 0) {
681 DE_HWP(("pcm_hw_free(%d)\n", pipe
->index
));
682 free_pipes(chip
, pipe
);
683 chip
->substream
[pipe
->index
] = NULL
;
686 spin_unlock_irq(&chip
->lock
);
688 DE_HWP(("pcm_hw_freed\n"));
689 snd_pcm_lib_free_pages(substream
);
695 static int pcm_prepare(struct snd_pcm_substream
*substream
)
697 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
698 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
699 struct audioformat format
;
700 int pipe_index
= ((struct audiopipe
*)runtime
->private_data
)->index
;
702 DE_HWP(("Prepare rate=%d format=%d channels=%d\n",
703 runtime
->rate
, runtime
->format
, runtime
->channels
));
704 format
.interleave
= runtime
->channels
;
705 format
.data_are_bigendian
= 0;
706 format
.mono_to_stereo
= 0;
707 switch (runtime
->format
) {
708 case SNDRV_PCM_FORMAT_U8
:
709 format
.bits_per_sample
= 8;
711 case SNDRV_PCM_FORMAT_S16_LE
:
712 format
.bits_per_sample
= 16;
714 case SNDRV_PCM_FORMAT_S24_3LE
:
715 format
.bits_per_sample
= 24;
717 case SNDRV_PCM_FORMAT_S32_BE
:
718 format
.data_are_bigendian
= 1;
719 case SNDRV_PCM_FORMAT_S32_LE
:
720 format
.bits_per_sample
= 32;
723 DE_HWP(("Prepare error: unsupported format %d\n",
728 if (snd_BUG_ON(pipe_index
>= px_num(chip
)))
730 if (snd_BUG_ON(!is_pipe_allocated(chip
, pipe_index
)))
732 set_audio_format(chip
, pipe_index
, &format
);
738 static int pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
740 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
741 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
742 struct audiopipe
*pipe
= runtime
->private_data
;
745 struct snd_pcm_substream
*s
;
747 snd_pcm_group_for_each_entry(s
, substream
) {
748 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
749 if (s
== chip
->substream
[i
]) {
750 channelmask
|= 1 << i
;
751 snd_pcm_trigger_done(s
, substream
);
756 spin_lock(&chip
->lock
);
758 case SNDRV_PCM_TRIGGER_RESUME
:
759 DE_ACT(("pcm_trigger resume\n"));
760 case SNDRV_PCM_TRIGGER_START
:
761 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
762 DE_ACT(("pcm_trigger start\n"));
763 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
764 if (channelmask
& (1 << i
)) {
765 pipe
= chip
->substream
[i
]->runtime
->private_data
;
766 switch (pipe
->state
) {
767 case PIPE_STATE_STOPPED
:
768 chip
->last_period
[i
] = 0;
769 pipe
->last_counter
= 0;
771 *pipe
->dma_counter
= 0;
772 case PIPE_STATE_PAUSED
:
773 pipe
->state
= PIPE_STATE_STARTED
;
775 case PIPE_STATE_STARTED
:
780 err
= start_transport(chip
, channelmask
,
781 chip
->pipe_cyclic_mask
);
783 case SNDRV_PCM_TRIGGER_SUSPEND
:
784 DE_ACT(("pcm_trigger suspend\n"));
785 case SNDRV_PCM_TRIGGER_STOP
:
786 DE_ACT(("pcm_trigger stop\n"));
787 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
788 if (channelmask
& (1 << i
)) {
789 pipe
= chip
->substream
[i
]->runtime
->private_data
;
790 pipe
->state
= PIPE_STATE_STOPPED
;
793 err
= stop_transport(chip
, channelmask
);
795 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
796 DE_ACT(("pcm_trigger pause\n"));
797 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
798 if (channelmask
& (1 << i
)) {
799 pipe
= chip
->substream
[i
]->runtime
->private_data
;
800 pipe
->state
= PIPE_STATE_PAUSED
;
803 err
= pause_transport(chip
, channelmask
);
808 spin_unlock(&chip
->lock
);
814 static snd_pcm_uframes_t
pcm_pointer(struct snd_pcm_substream
*substream
)
816 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
817 struct audiopipe
*pipe
= runtime
->private_data
;
818 size_t cnt
, bufsize
, pos
;
820 cnt
= le32_to_cpu(*pipe
->dma_counter
);
821 pipe
->position
+= cnt
- pipe
->last_counter
;
822 pipe
->last_counter
= cnt
;
823 bufsize
= substream
->runtime
->buffer_size
;
824 pos
= bytes_to_frames(substream
->runtime
, pipe
->position
);
826 while (pos
>= bufsize
) {
827 pipe
->position
-= frames_to_bytes(substream
->runtime
, bufsize
);
835 /* pcm *_ops structures */
836 static struct snd_pcm_ops analog_playback_ops
= {
837 .open
= pcm_analog_out_open
,
839 .ioctl
= snd_pcm_lib_ioctl
,
840 .hw_params
= pcm_analog_out_hw_params
,
841 .hw_free
= pcm_hw_free
,
842 .prepare
= pcm_prepare
,
843 .trigger
= pcm_trigger
,
844 .pointer
= pcm_pointer
,
845 .page
= snd_pcm_sgbuf_ops_page
,
847 static struct snd_pcm_ops analog_capture_ops
= {
848 .open
= pcm_analog_in_open
,
850 .ioctl
= snd_pcm_lib_ioctl
,
851 .hw_params
= pcm_analog_in_hw_params
,
852 .hw_free
= pcm_hw_free
,
853 .prepare
= pcm_prepare
,
854 .trigger
= pcm_trigger
,
855 .pointer
= pcm_pointer
,
856 .page
= snd_pcm_sgbuf_ops_page
,
858 #ifdef ECHOCARD_HAS_DIGITAL_IO
859 #ifndef ECHOCARD_HAS_VMIXER
860 static struct snd_pcm_ops digital_playback_ops
= {
861 .open
= pcm_digital_out_open
,
863 .ioctl
= snd_pcm_lib_ioctl
,
864 .hw_params
= pcm_digital_out_hw_params
,
865 .hw_free
= pcm_hw_free
,
866 .prepare
= pcm_prepare
,
867 .trigger
= pcm_trigger
,
868 .pointer
= pcm_pointer
,
869 .page
= snd_pcm_sgbuf_ops_page
,
871 #endif /* !ECHOCARD_HAS_VMIXER */
872 static struct snd_pcm_ops digital_capture_ops
= {
873 .open
= pcm_digital_in_open
,
875 .ioctl
= snd_pcm_lib_ioctl
,
876 .hw_params
= pcm_digital_in_hw_params
,
877 .hw_free
= pcm_hw_free
,
878 .prepare
= pcm_prepare
,
879 .trigger
= pcm_trigger
,
880 .pointer
= pcm_pointer
,
881 .page
= snd_pcm_sgbuf_ops_page
,
883 #endif /* ECHOCARD_HAS_DIGITAL_IO */
887 /* Preallocate memory only for the first substream because it's the most
890 static int snd_echo_preallocate_pages(struct snd_pcm
*pcm
, struct device
*dev
)
892 struct snd_pcm_substream
*ss
;
895 for (stream
= 0; stream
< 2; stream
++)
896 for (ss
= pcm
->streams
[stream
].substream
; ss
; ss
= ss
->next
) {
897 err
= snd_pcm_lib_preallocate_pages(ss
, SNDRV_DMA_TYPE_DEV_SG
,
899 ss
->number
? 0 : 128<<10,
909 /*<--snd_echo_probe() */
910 static int __devinit
snd_echo_new_pcm(struct echoaudio
*chip
)
915 #ifdef ECHOCARD_HAS_VMIXER
916 /* This card has a Vmixer, that is there is no direct mapping from PCM
917 streams to physical outputs. The user can mix the streams as he wishes
918 via control interface and it's possible to send any stream to any
919 output, thus it makes no sense to keep analog and digital outputs
922 /* PCM#0 Virtual outputs and analog inputs */
923 if ((err
= snd_pcm_new(chip
->card
, "PCM", 0, num_pipes_out(chip
),
924 num_analog_busses_in(chip
), &pcm
)) < 0)
926 pcm
->private_data
= chip
;
927 chip
->analog_pcm
= pcm
;
928 strcpy(pcm
->name
, chip
->card
->shortname
);
929 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &analog_playback_ops
);
930 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &analog_capture_ops
);
931 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
933 DE_INIT(("Analog PCM ok\n"));
935 #ifdef ECHOCARD_HAS_DIGITAL_IO
936 /* PCM#1 Digital inputs, no outputs */
937 if ((err
= snd_pcm_new(chip
->card
, "Digital PCM", 1, 0,
938 num_digital_busses_in(chip
), &pcm
)) < 0)
940 pcm
->private_data
= chip
;
941 chip
->digital_pcm
= pcm
;
942 strcpy(pcm
->name
, chip
->card
->shortname
);
943 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &digital_capture_ops
);
944 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
946 DE_INIT(("Digital PCM ok\n"));
947 #endif /* ECHOCARD_HAS_DIGITAL_IO */
949 #else /* ECHOCARD_HAS_VMIXER */
951 /* The card can manage substreams formed by analog and digital channels
952 at the same time, but I prefer to keep analog and digital channels
953 separated, because that mixed thing is confusing and useless. So we
954 register two PCM devices: */
956 /* PCM#0 Analog i/o */
957 if ((err
= snd_pcm_new(chip
->card
, "Analog PCM", 0,
958 num_analog_busses_out(chip
),
959 num_analog_busses_in(chip
), &pcm
)) < 0)
961 pcm
->private_data
= chip
;
962 chip
->analog_pcm
= pcm
;
963 strcpy(pcm
->name
, chip
->card
->shortname
);
964 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &analog_playback_ops
);
965 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &analog_capture_ops
);
966 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
968 DE_INIT(("Analog PCM ok\n"));
970 #ifdef ECHOCARD_HAS_DIGITAL_IO
971 /* PCM#1 Digital i/o */
972 if ((err
= snd_pcm_new(chip
->card
, "Digital PCM", 1,
973 num_digital_busses_out(chip
),
974 num_digital_busses_in(chip
), &pcm
)) < 0)
976 pcm
->private_data
= chip
;
977 chip
->digital_pcm
= pcm
;
978 strcpy(pcm
->name
, chip
->card
->shortname
);
979 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &digital_playback_ops
);
980 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &digital_capture_ops
);
981 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
983 DE_INIT(("Digital PCM ok\n"));
984 #endif /* ECHOCARD_HAS_DIGITAL_IO */
986 #endif /* ECHOCARD_HAS_VMIXER */
994 /******************************************************************************
996 ******************************************************************************/
998 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
1000 /******************* PCM output volume *******************/
1001 static int snd_echo_output_gain_info(struct snd_kcontrol
*kcontrol
,
1002 struct snd_ctl_elem_info
*uinfo
)
1004 struct echoaudio
*chip
;
1006 chip
= snd_kcontrol_chip(kcontrol
);
1007 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1008 uinfo
->count
= num_busses_out(chip
);
1009 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1010 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1014 static int snd_echo_output_gain_get(struct snd_kcontrol
*kcontrol
,
1015 struct snd_ctl_elem_value
*ucontrol
)
1017 struct echoaudio
*chip
;
1020 chip
= snd_kcontrol_chip(kcontrol
);
1021 for (c
= 0; c
< num_busses_out(chip
); c
++)
1022 ucontrol
->value
.integer
.value
[c
] = chip
->output_gain
[c
];
1026 static int snd_echo_output_gain_put(struct snd_kcontrol
*kcontrol
,
1027 struct snd_ctl_elem_value
*ucontrol
)
1029 struct echoaudio
*chip
;
1030 int c
, changed
, gain
;
1033 chip
= snd_kcontrol_chip(kcontrol
);
1034 spin_lock_irq(&chip
->lock
);
1035 for (c
= 0; c
< num_busses_out(chip
); c
++) {
1036 gain
= ucontrol
->value
.integer
.value
[c
];
1037 /* Ignore out of range values */
1038 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1040 if (chip
->output_gain
[c
] != gain
) {
1041 set_output_gain(chip
, c
, gain
);
1046 update_output_line_level(chip
);
1047 spin_unlock_irq(&chip
->lock
);
1051 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1052 /* On the Mia this one controls the line-out volume */
1053 static struct snd_kcontrol_new snd_echo_line_output_gain __devinitdata
= {
1054 .name
= "Line Playback Volume",
1055 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1056 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1057 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1058 .info
= snd_echo_output_gain_info
,
1059 .get
= snd_echo_output_gain_get
,
1060 .put
= snd_echo_output_gain_put
,
1061 .tlv
= {.p
= db_scale_output_gain
},
1064 static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata
= {
1065 .name
= "PCM Playback Volume",
1066 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1067 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1068 .info
= snd_echo_output_gain_info
,
1069 .get
= snd_echo_output_gain_get
,
1070 .put
= snd_echo_output_gain_put
,
1071 .tlv
= {.p
= db_scale_output_gain
},
1075 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1079 #ifdef ECHOCARD_HAS_INPUT_GAIN
1081 /******************* Analog input volume *******************/
1082 static int snd_echo_input_gain_info(struct snd_kcontrol
*kcontrol
,
1083 struct snd_ctl_elem_info
*uinfo
)
1085 struct echoaudio
*chip
;
1087 chip
= snd_kcontrol_chip(kcontrol
);
1088 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1089 uinfo
->count
= num_analog_busses_in(chip
);
1090 uinfo
->value
.integer
.min
= ECHOGAIN_MININP
;
1091 uinfo
->value
.integer
.max
= ECHOGAIN_MAXINP
;
1095 static int snd_echo_input_gain_get(struct snd_kcontrol
*kcontrol
,
1096 struct snd_ctl_elem_value
*ucontrol
)
1098 struct echoaudio
*chip
;
1101 chip
= snd_kcontrol_chip(kcontrol
);
1102 for (c
= 0; c
< num_analog_busses_in(chip
); c
++)
1103 ucontrol
->value
.integer
.value
[c
] = chip
->input_gain
[c
];
1107 static int snd_echo_input_gain_put(struct snd_kcontrol
*kcontrol
,
1108 struct snd_ctl_elem_value
*ucontrol
)
1110 struct echoaudio
*chip
;
1111 int c
, gain
, changed
;
1114 chip
= snd_kcontrol_chip(kcontrol
);
1115 spin_lock_irq(&chip
->lock
);
1116 for (c
= 0; c
< num_analog_busses_in(chip
); c
++) {
1117 gain
= ucontrol
->value
.integer
.value
[c
];
1118 /* Ignore out of range values */
1119 if (gain
< ECHOGAIN_MININP
|| gain
> ECHOGAIN_MAXINP
)
1121 if (chip
->input_gain
[c
] != gain
) {
1122 set_input_gain(chip
, c
, gain
);
1127 update_input_line_level(chip
);
1128 spin_unlock_irq(&chip
->lock
);
1132 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain
, -2500, 50, 0);
1134 static struct snd_kcontrol_new snd_echo_line_input_gain __devinitdata
= {
1135 .name
= "Line Capture Volume",
1136 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1137 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1138 .info
= snd_echo_input_gain_info
,
1139 .get
= snd_echo_input_gain_get
,
1140 .put
= snd_echo_input_gain_put
,
1141 .tlv
= {.p
= db_scale_input_gain
},
1144 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1148 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1150 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1151 static int snd_echo_output_nominal_info (struct snd_kcontrol
*kcontrol
,
1152 struct snd_ctl_elem_info
*uinfo
)
1154 struct echoaudio
*chip
;
1156 chip
= snd_kcontrol_chip(kcontrol
);
1157 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1158 uinfo
->count
= num_analog_busses_out(chip
);
1159 uinfo
->value
.integer
.min
= 0;
1160 uinfo
->value
.integer
.max
= 1;
1164 static int snd_echo_output_nominal_get(struct snd_kcontrol
*kcontrol
,
1165 struct snd_ctl_elem_value
*ucontrol
)
1167 struct echoaudio
*chip
;
1170 chip
= snd_kcontrol_chip(kcontrol
);
1171 for (c
= 0; c
< num_analog_busses_out(chip
); c
++)
1172 ucontrol
->value
.integer
.value
[c
] = chip
->nominal_level
[c
];
1176 static int snd_echo_output_nominal_put(struct snd_kcontrol
*kcontrol
,
1177 struct snd_ctl_elem_value
*ucontrol
)
1179 struct echoaudio
*chip
;
1183 chip
= snd_kcontrol_chip(kcontrol
);
1184 spin_lock_irq(&chip
->lock
);
1185 for (c
= 0; c
< num_analog_busses_out(chip
); c
++) {
1186 if (chip
->nominal_level
[c
] != ucontrol
->value
.integer
.value
[c
]) {
1187 set_nominal_level(chip
, c
,
1188 ucontrol
->value
.integer
.value
[c
]);
1193 update_output_line_level(chip
);
1194 spin_unlock_irq(&chip
->lock
);
1198 static struct snd_kcontrol_new snd_echo_output_nominal_level __devinitdata
= {
1199 .name
= "Line Playback Switch (-10dBV)",
1200 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1201 .info
= snd_echo_output_nominal_info
,
1202 .get
= snd_echo_output_nominal_get
,
1203 .put
= snd_echo_output_nominal_put
,
1206 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1210 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1212 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1213 static int snd_echo_input_nominal_info(struct snd_kcontrol
*kcontrol
,
1214 struct snd_ctl_elem_info
*uinfo
)
1216 struct echoaudio
*chip
;
1218 chip
= snd_kcontrol_chip(kcontrol
);
1219 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1220 uinfo
->count
= num_analog_busses_in(chip
);
1221 uinfo
->value
.integer
.min
= 0;
1222 uinfo
->value
.integer
.max
= 1;
1226 static int snd_echo_input_nominal_get(struct snd_kcontrol
*kcontrol
,
1227 struct snd_ctl_elem_value
*ucontrol
)
1229 struct echoaudio
*chip
;
1232 chip
= snd_kcontrol_chip(kcontrol
);
1233 for (c
= 0; c
< num_analog_busses_in(chip
); c
++)
1234 ucontrol
->value
.integer
.value
[c
] =
1235 chip
->nominal_level
[bx_analog_in(chip
) + c
];
1239 static int snd_echo_input_nominal_put(struct snd_kcontrol
*kcontrol
,
1240 struct snd_ctl_elem_value
*ucontrol
)
1242 struct echoaudio
*chip
;
1246 chip
= snd_kcontrol_chip(kcontrol
);
1247 spin_lock_irq(&chip
->lock
);
1248 for (c
= 0; c
< num_analog_busses_in(chip
); c
++) {
1249 if (chip
->nominal_level
[bx_analog_in(chip
) + c
] !=
1250 ucontrol
->value
.integer
.value
[c
]) {
1251 set_nominal_level(chip
, bx_analog_in(chip
) + c
,
1252 ucontrol
->value
.integer
.value
[c
]);
1257 update_output_line_level(chip
); /* "Output" is not a mistake
1260 spin_unlock_irq(&chip
->lock
);
1264 static struct snd_kcontrol_new snd_echo_intput_nominal_level __devinitdata
= {
1265 .name
= "Line Capture Switch (-10dBV)",
1266 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1267 .info
= snd_echo_input_nominal_info
,
1268 .get
= snd_echo_input_nominal_get
,
1269 .put
= snd_echo_input_nominal_put
,
1272 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1276 #ifdef ECHOCARD_HAS_MONITOR
1278 /******************* Monitor mixer *******************/
1279 static int snd_echo_mixer_info(struct snd_kcontrol
*kcontrol
,
1280 struct snd_ctl_elem_info
*uinfo
)
1282 struct echoaudio
*chip
;
1284 chip
= snd_kcontrol_chip(kcontrol
);
1285 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1287 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1288 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1289 uinfo
->dimen
.d
[0] = num_busses_out(chip
);
1290 uinfo
->dimen
.d
[1] = num_busses_in(chip
);
1294 static int snd_echo_mixer_get(struct snd_kcontrol
*kcontrol
,
1295 struct snd_ctl_elem_value
*ucontrol
)
1297 struct echoaudio
*chip
;
1299 chip
= snd_kcontrol_chip(kcontrol
);
1300 ucontrol
->value
.integer
.value
[0] =
1301 chip
->monitor_gain
[ucontrol
->id
.index
/ num_busses_in(chip
)]
1302 [ucontrol
->id
.index
% num_busses_in(chip
)];
1306 static int snd_echo_mixer_put(struct snd_kcontrol
*kcontrol
,
1307 struct snd_ctl_elem_value
*ucontrol
)
1309 struct echoaudio
*chip
;
1314 chip
= snd_kcontrol_chip(kcontrol
);
1315 out
= ucontrol
->id
.index
/ num_busses_in(chip
);
1316 in
= ucontrol
->id
.index
% num_busses_in(chip
);
1317 gain
= ucontrol
->value
.integer
.value
[0];
1318 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1320 if (chip
->monitor_gain
[out
][in
] != gain
) {
1321 spin_lock_irq(&chip
->lock
);
1322 set_monitor_gain(chip
, out
, in
, gain
);
1323 update_output_line_level(chip
);
1324 spin_unlock_irq(&chip
->lock
);
1330 static struct snd_kcontrol_new snd_echo_monitor_mixer __devinitdata
= {
1331 .name
= "Monitor Mixer Volume",
1332 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1333 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1334 .info
= snd_echo_mixer_info
,
1335 .get
= snd_echo_mixer_get
,
1336 .put
= snd_echo_mixer_put
,
1337 .tlv
= {.p
= db_scale_output_gain
},
1340 #endif /* ECHOCARD_HAS_MONITOR */
1344 #ifdef ECHOCARD_HAS_VMIXER
1346 /******************* Vmixer *******************/
1347 static int snd_echo_vmixer_info(struct snd_kcontrol
*kcontrol
,
1348 struct snd_ctl_elem_info
*uinfo
)
1350 struct echoaudio
*chip
;
1352 chip
= snd_kcontrol_chip(kcontrol
);
1353 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1355 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1356 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1357 uinfo
->dimen
.d
[0] = num_busses_out(chip
);
1358 uinfo
->dimen
.d
[1] = num_pipes_out(chip
);
1362 static int snd_echo_vmixer_get(struct snd_kcontrol
*kcontrol
,
1363 struct snd_ctl_elem_value
*ucontrol
)
1365 struct echoaudio
*chip
;
1367 chip
= snd_kcontrol_chip(kcontrol
);
1368 ucontrol
->value
.integer
.value
[0] =
1369 chip
->vmixer_gain
[ucontrol
->id
.index
/ num_pipes_out(chip
)]
1370 [ucontrol
->id
.index
% num_pipes_out(chip
)];
1374 static int snd_echo_vmixer_put(struct snd_kcontrol
*kcontrol
,
1375 struct snd_ctl_elem_value
*ucontrol
)
1377 struct echoaudio
*chip
;
1382 chip
= snd_kcontrol_chip(kcontrol
);
1383 out
= ucontrol
->id
.index
/ num_pipes_out(chip
);
1384 vch
= ucontrol
->id
.index
% num_pipes_out(chip
);
1385 gain
= ucontrol
->value
.integer
.value
[0];
1386 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1388 if (chip
->vmixer_gain
[out
][vch
] != ucontrol
->value
.integer
.value
[0]) {
1389 spin_lock_irq(&chip
->lock
);
1390 set_vmixer_gain(chip
, out
, vch
, ucontrol
->value
.integer
.value
[0]);
1391 update_vmixer_level(chip
);
1392 spin_unlock_irq(&chip
->lock
);
1398 static struct snd_kcontrol_new snd_echo_vmixer __devinitdata
= {
1399 .name
= "VMixer Volume",
1400 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1401 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1402 .info
= snd_echo_vmixer_info
,
1403 .get
= snd_echo_vmixer_get
,
1404 .put
= snd_echo_vmixer_put
,
1405 .tlv
= {.p
= db_scale_output_gain
},
1408 #endif /* ECHOCARD_HAS_VMIXER */
1412 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1414 /******************* Digital mode switch *******************/
1415 static int snd_echo_digital_mode_info(struct snd_kcontrol
*kcontrol
,
1416 struct snd_ctl_elem_info
*uinfo
)
1418 static char *names
[4] = {
1419 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1422 struct echoaudio
*chip
;
1424 chip
= snd_kcontrol_chip(kcontrol
);
1425 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1426 uinfo
->value
.enumerated
.items
= chip
->num_digital_modes
;
1428 if (uinfo
->value
.enumerated
.item
>= chip
->num_digital_modes
)
1429 uinfo
->value
.enumerated
.item
= chip
->num_digital_modes
- 1;
1430 strcpy(uinfo
->value
.enumerated
.name
, names
[
1431 chip
->digital_mode_list
[uinfo
->value
.enumerated
.item
]]);
1435 static int snd_echo_digital_mode_get(struct snd_kcontrol
*kcontrol
,
1436 struct snd_ctl_elem_value
*ucontrol
)
1438 struct echoaudio
*chip
;
1441 chip
= snd_kcontrol_chip(kcontrol
);
1442 mode
= chip
->digital_mode
;
1443 for (i
= chip
->num_digital_modes
- 1; i
>= 0; i
--)
1444 if (mode
== chip
->digital_mode_list
[i
]) {
1445 ucontrol
->value
.enumerated
.item
[0] = i
;
1451 static int snd_echo_digital_mode_put(struct snd_kcontrol
*kcontrol
,
1452 struct snd_ctl_elem_value
*ucontrol
)
1454 struct echoaudio
*chip
;
1456 unsigned short emode
, dmode
;
1459 chip
= snd_kcontrol_chip(kcontrol
);
1461 emode
= ucontrol
->value
.enumerated
.item
[0];
1462 if (emode
>= chip
->num_digital_modes
)
1464 dmode
= chip
->digital_mode_list
[emode
];
1466 if (dmode
!= chip
->digital_mode
) {
1467 /* mode_mutex is required to make this operation atomic wrt
1468 pcm_digital_*_open() and set_input_clock() functions. */
1469 mutex_lock(&chip
->mode_mutex
);
1471 /* Do not allow the user to change the digital mode when a pcm
1472 device is open because it also changes the number of channels
1473 and the allowed sample rates */
1474 if (atomic_read(&chip
->opencount
)) {
1477 changed
= set_digital_mode(chip
, dmode
);
1478 /* If we had to change the clock source, report it */
1479 if (changed
> 0 && chip
->clock_src_ctl
) {
1480 snd_ctl_notify(chip
->card
,
1481 SNDRV_CTL_EVENT_MASK_VALUE
,
1482 &chip
->clock_src_ctl
->id
);
1483 DE_ACT(("SDM() =%d\n", changed
));
1486 changed
= 1; /* No errors */
1488 mutex_unlock(&chip
->mode_mutex
);
1493 static struct snd_kcontrol_new snd_echo_digital_mode_switch __devinitdata
= {
1494 .name
= "Digital mode Switch",
1495 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1496 .info
= snd_echo_digital_mode_info
,
1497 .get
= snd_echo_digital_mode_get
,
1498 .put
= snd_echo_digital_mode_put
,
1501 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1505 #ifdef ECHOCARD_HAS_DIGITAL_IO
1507 /******************* S/PDIF mode switch *******************/
1508 static int snd_echo_spdif_mode_info(struct snd_kcontrol
*kcontrol
,
1509 struct snd_ctl_elem_info
*uinfo
)
1511 static char *names
[2] = {"Consumer", "Professional"};
1513 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1514 uinfo
->value
.enumerated
.items
= 2;
1516 if (uinfo
->value
.enumerated
.item
)
1517 uinfo
->value
.enumerated
.item
= 1;
1518 strcpy(uinfo
->value
.enumerated
.name
,
1519 names
[uinfo
->value
.enumerated
.item
]);
1523 static int snd_echo_spdif_mode_get(struct snd_kcontrol
*kcontrol
,
1524 struct snd_ctl_elem_value
*ucontrol
)
1526 struct echoaudio
*chip
;
1528 chip
= snd_kcontrol_chip(kcontrol
);
1529 ucontrol
->value
.enumerated
.item
[0] = !!chip
->professional_spdif
;
1533 static int snd_echo_spdif_mode_put(struct snd_kcontrol
*kcontrol
,
1534 struct snd_ctl_elem_value
*ucontrol
)
1536 struct echoaudio
*chip
;
1539 chip
= snd_kcontrol_chip(kcontrol
);
1540 mode
= !!ucontrol
->value
.enumerated
.item
[0];
1541 if (mode
!= chip
->professional_spdif
) {
1542 spin_lock_irq(&chip
->lock
);
1543 set_professional_spdif(chip
, mode
);
1544 spin_unlock_irq(&chip
->lock
);
1550 static struct snd_kcontrol_new snd_echo_spdif_mode_switch __devinitdata
= {
1551 .name
= "S/PDIF mode Switch",
1552 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1553 .info
= snd_echo_spdif_mode_info
,
1554 .get
= snd_echo_spdif_mode_get
,
1555 .put
= snd_echo_spdif_mode_put
,
1558 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1562 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1564 /******************* Select input clock source *******************/
1565 static int snd_echo_clock_source_info(struct snd_kcontrol
*kcontrol
,
1566 struct snd_ctl_elem_info
*uinfo
)
1568 static char *names
[8] = {
1569 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1572 struct echoaudio
*chip
;
1574 chip
= snd_kcontrol_chip(kcontrol
);
1575 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1576 uinfo
->value
.enumerated
.items
= chip
->num_clock_sources
;
1578 if (uinfo
->value
.enumerated
.item
>= chip
->num_clock_sources
)
1579 uinfo
->value
.enumerated
.item
= chip
->num_clock_sources
- 1;
1580 strcpy(uinfo
->value
.enumerated
.name
, names
[
1581 chip
->clock_source_list
[uinfo
->value
.enumerated
.item
]]);
1585 static int snd_echo_clock_source_get(struct snd_kcontrol
*kcontrol
,
1586 struct snd_ctl_elem_value
*ucontrol
)
1588 struct echoaudio
*chip
;
1591 chip
= snd_kcontrol_chip(kcontrol
);
1592 clock
= chip
->input_clock
;
1594 for (i
= 0; i
< chip
->num_clock_sources
; i
++)
1595 if (clock
== chip
->clock_source_list
[i
])
1596 ucontrol
->value
.enumerated
.item
[0] = i
;
1601 static int snd_echo_clock_source_put(struct snd_kcontrol
*kcontrol
,
1602 struct snd_ctl_elem_value
*ucontrol
)
1604 struct echoaudio
*chip
;
1606 unsigned int eclock
, dclock
;
1609 chip
= snd_kcontrol_chip(kcontrol
);
1610 eclock
= ucontrol
->value
.enumerated
.item
[0];
1611 if (eclock
>= chip
->input_clock_types
)
1613 dclock
= chip
->clock_source_list
[eclock
];
1614 if (chip
->input_clock
!= dclock
) {
1615 mutex_lock(&chip
->mode_mutex
);
1616 spin_lock_irq(&chip
->lock
);
1617 if ((changed
= set_input_clock(chip
, dclock
)) == 0)
1618 changed
= 1; /* no errors */
1619 spin_unlock_irq(&chip
->lock
);
1620 mutex_unlock(&chip
->mode_mutex
);
1624 DE_ACT(("seticlk val%d err 0x%x\n", dclock
, changed
));
1629 static struct snd_kcontrol_new snd_echo_clock_source_switch __devinitdata
= {
1630 .name
= "Sample Clock Source",
1631 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1632 .info
= snd_echo_clock_source_info
,
1633 .get
= snd_echo_clock_source_get
,
1634 .put
= snd_echo_clock_source_put
,
1637 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1641 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1643 /******************* Phantom power switch *******************/
1644 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1646 static int snd_echo_phantom_power_get(struct snd_kcontrol
*kcontrol
,
1647 struct snd_ctl_elem_value
*ucontrol
)
1649 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1651 ucontrol
->value
.integer
.value
[0] = chip
->phantom_power
;
1655 static int snd_echo_phantom_power_put(struct snd_kcontrol
*kcontrol
,
1656 struct snd_ctl_elem_value
*ucontrol
)
1658 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1659 int power
, changed
= 0;
1661 power
= !!ucontrol
->value
.integer
.value
[0];
1662 if (chip
->phantom_power
!= power
) {
1663 spin_lock_irq(&chip
->lock
);
1664 changed
= set_phantom_power(chip
, power
);
1665 spin_unlock_irq(&chip
->lock
);
1667 changed
= 1; /* no errors */
1672 static struct snd_kcontrol_new snd_echo_phantom_power_switch __devinitdata
= {
1673 .name
= "Phantom power Switch",
1674 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1675 .info
= snd_echo_phantom_power_info
,
1676 .get
= snd_echo_phantom_power_get
,
1677 .put
= snd_echo_phantom_power_put
,
1680 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1684 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1686 /******************* Digital input automute switch *******************/
1687 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1689 static int snd_echo_automute_get(struct snd_kcontrol
*kcontrol
,
1690 struct snd_ctl_elem_value
*ucontrol
)
1692 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1694 ucontrol
->value
.integer
.value
[0] = chip
->digital_in_automute
;
1698 static int snd_echo_automute_put(struct snd_kcontrol
*kcontrol
,
1699 struct snd_ctl_elem_value
*ucontrol
)
1701 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1702 int automute
, changed
= 0;
1704 automute
= !!ucontrol
->value
.integer
.value
[0];
1705 if (chip
->digital_in_automute
!= automute
) {
1706 spin_lock_irq(&chip
->lock
);
1707 changed
= set_input_auto_mute(chip
, automute
);
1708 spin_unlock_irq(&chip
->lock
);
1710 changed
= 1; /* no errors */
1715 static struct snd_kcontrol_new snd_echo_automute_switch __devinitdata
= {
1716 .name
= "Digital Capture Switch (automute)",
1717 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1718 .info
= snd_echo_automute_info
,
1719 .get
= snd_echo_automute_get
,
1720 .put
= snd_echo_automute_put
,
1723 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1727 /******************* VU-meters switch *******************/
1728 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1730 static int snd_echo_vumeters_switch_put(struct snd_kcontrol
*kcontrol
,
1731 struct snd_ctl_elem_value
*ucontrol
)
1733 struct echoaudio
*chip
;
1735 chip
= snd_kcontrol_chip(kcontrol
);
1736 spin_lock_irq(&chip
->lock
);
1737 set_meters_on(chip
, ucontrol
->value
.integer
.value
[0]);
1738 spin_unlock_irq(&chip
->lock
);
1742 static struct snd_kcontrol_new snd_echo_vumeters_switch __devinitdata
= {
1743 .name
= "VU-meters Switch",
1744 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1745 .access
= SNDRV_CTL_ELEM_ACCESS_WRITE
,
1746 .info
= snd_echo_vumeters_switch_info
,
1747 .put
= snd_echo_vumeters_switch_put
,
1752 /***** Read VU-meters (input, output, analog and digital together) *****/
1753 static int snd_echo_vumeters_info(struct snd_kcontrol
*kcontrol
,
1754 struct snd_ctl_elem_info
*uinfo
)
1756 struct echoaudio
*chip
;
1758 chip
= snd_kcontrol_chip(kcontrol
);
1759 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1761 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1762 uinfo
->value
.integer
.max
= 0;
1763 #ifdef ECHOCARD_HAS_VMIXER
1764 uinfo
->dimen
.d
[0] = 3; /* Out, In, Virt */
1766 uinfo
->dimen
.d
[0] = 2; /* Out, In */
1768 uinfo
->dimen
.d
[1] = 16; /* 16 channels */
1769 uinfo
->dimen
.d
[2] = 2; /* 0=level, 1=peak */
1773 static int snd_echo_vumeters_get(struct snd_kcontrol
*kcontrol
,
1774 struct snd_ctl_elem_value
*ucontrol
)
1776 struct echoaudio
*chip
;
1778 chip
= snd_kcontrol_chip(kcontrol
);
1779 get_audio_meters(chip
, ucontrol
->value
.integer
.value
);
1783 static struct snd_kcontrol_new snd_echo_vumeters __devinitdata
= {
1784 .name
= "VU-meters",
1785 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1786 .access
= SNDRV_CTL_ELEM_ACCESS_READ
|
1787 SNDRV_CTL_ELEM_ACCESS_VOLATILE
|
1788 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1789 .info
= snd_echo_vumeters_info
,
1790 .get
= snd_echo_vumeters_get
,
1791 .tlv
= {.p
= db_scale_output_gain
},
1796 /*** Channels info - it exports informations about the number of channels ***/
1797 static int snd_echo_channels_info_info(struct snd_kcontrol
*kcontrol
,
1798 struct snd_ctl_elem_info
*uinfo
)
1800 struct echoaudio
*chip
;
1802 chip
= snd_kcontrol_chip(kcontrol
);
1803 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1805 uinfo
->value
.integer
.min
= 0;
1806 uinfo
->value
.integer
.max
= 1 << ECHO_CLOCK_NUMBER
;
1810 static int snd_echo_channels_info_get(struct snd_kcontrol
*kcontrol
,
1811 struct snd_ctl_elem_value
*ucontrol
)
1813 struct echoaudio
*chip
;
1814 int detected
, clocks
, bit
, src
;
1816 chip
= snd_kcontrol_chip(kcontrol
);
1817 ucontrol
->value
.integer
.value
[0] = num_busses_in(chip
);
1818 ucontrol
->value
.integer
.value
[1] = num_analog_busses_in(chip
);
1819 ucontrol
->value
.integer
.value
[2] = num_busses_out(chip
);
1820 ucontrol
->value
.integer
.value
[3] = num_analog_busses_out(chip
);
1821 ucontrol
->value
.integer
.value
[4] = num_pipes_out(chip
);
1823 /* Compute the bitmask of the currently valid input clocks */
1824 detected
= detect_input_clocks(chip
);
1826 src
= chip
->num_clock_sources
- 1;
1827 for (bit
= ECHO_CLOCK_NUMBER
- 1; bit
>= 0; bit
--)
1828 if (detected
& (1 << bit
))
1829 for (; src
>= 0; src
--)
1830 if (bit
== chip
->clock_source_list
[src
]) {
1834 ucontrol
->value
.integer
.value
[5] = clocks
;
1839 static struct snd_kcontrol_new snd_echo_channels_info __devinitdata
= {
1840 .name
= "Channels info",
1841 .iface
= SNDRV_CTL_ELEM_IFACE_HWDEP
,
1842 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
1843 .info
= snd_echo_channels_info_info
,
1844 .get
= snd_echo_channels_info_get
,
1850 /******************************************************************************
1852 ******************************************************************************/
1854 static irqreturn_t
snd_echo_interrupt(int irq
, void *dev_id
)
1856 struct echoaudio
*chip
= dev_id
;
1857 struct snd_pcm_substream
*substream
;
1860 spin_lock(&chip
->lock
);
1861 st
= service_irq(chip
);
1863 spin_unlock(&chip
->lock
);
1866 /* The hardware doesn't tell us which substream caused the irq,
1867 thus we have to check all running substreams. */
1868 for (ss
= 0; ss
< DSP_MAXPIPES
; ss
++) {
1869 substream
= chip
->substream
[ss
];
1870 if (substream
&& ((struct audiopipe
*)substream
->runtime
->
1871 private_data
)->state
== PIPE_STATE_STARTED
) {
1872 period
= pcm_pointer(substream
) /
1873 substream
->runtime
->period_size
;
1874 if (period
!= chip
->last_period
[ss
]) {
1875 chip
->last_period
[ss
] = period
;
1876 spin_unlock(&chip
->lock
);
1877 snd_pcm_period_elapsed(substream
);
1878 spin_lock(&chip
->lock
);
1882 spin_unlock(&chip
->lock
);
1884 #ifdef ECHOCARD_HAS_MIDI
1885 if (st
> 0 && chip
->midi_in
) {
1886 snd_rawmidi_receive(chip
->midi_in
, chip
->midi_buffer
, st
);
1887 DE_MID(("rawmidi_iread=%d\n", st
));
1896 /******************************************************************************
1897 Module construction / destruction
1898 ******************************************************************************/
1900 static int snd_echo_free(struct echoaudio
*chip
)
1902 DE_INIT(("Stop DSP...\n"));
1903 if (chip
->comm_page
)
1904 rest_in_peace(chip
);
1905 DE_INIT(("Stopped.\n"));
1908 free_irq(chip
->irq
, chip
);
1910 if (chip
->comm_page
)
1911 snd_dma_free_pages(&chip
->commpage_dma_buf
);
1913 if (chip
->dsp_registers
)
1914 iounmap(chip
->dsp_registers
);
1917 release_and_free_resource(chip
->iores
);
1919 DE_INIT(("MMIO freed.\n"));
1921 pci_disable_device(chip
->pci
);
1923 /* release chip data */
1924 free_firmware_cache(chip
);
1926 DE_INIT(("Chip freed.\n"));
1932 static int snd_echo_dev_free(struct snd_device
*device
)
1934 struct echoaudio
*chip
= device
->device_data
;
1936 DE_INIT(("snd_echo_dev_free()...\n"));
1937 return snd_echo_free(chip
);
1942 /* <--snd_echo_probe() */
1943 static __devinit
int snd_echo_create(struct snd_card
*card
,
1944 struct pci_dev
*pci
,
1945 struct echoaudio
**rchip
)
1947 struct echoaudio
*chip
;
1950 static struct snd_device_ops ops
= {
1951 .dev_free
= snd_echo_dev_free
,
1956 pci_write_config_byte(pci
, PCI_LATENCY_TIMER
, 0xC0);
1958 if ((err
= pci_enable_device(pci
)) < 0)
1960 pci_set_master(pci
);
1962 /* Allocate chip if needed */
1964 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
1966 pci_disable_device(pci
);
1969 DE_INIT(("chip=%p\n", chip
));
1970 spin_lock_init(&chip
->lock
);
1974 atomic_set(&chip
->opencount
, 0);
1975 mutex_init(&chip
->mode_mutex
);
1976 chip
->can_set_rate
= 1;
1978 /* If this was called from the resume function, chip is
1979 * already allocated and it contains current card settings.
1984 /* PCI resource allocation */
1985 chip
->dsp_registers_phys
= pci_resource_start(pci
, 0);
1986 sz
= pci_resource_len(pci
, 0);
1988 sz
= PAGE_SIZE
; /* We map only the required part */
1990 if ((chip
->iores
= request_mem_region(chip
->dsp_registers_phys
, sz
,
1991 ECHOCARD_NAME
)) == NULL
) {
1992 snd_echo_free(chip
);
1993 snd_printk(KERN_ERR
"cannot get memory region\n");
1996 chip
->dsp_registers
= (volatile u32 __iomem
*)
1997 ioremap_nocache(chip
->dsp_registers_phys
, sz
);
1999 if (request_irq(pci
->irq
, snd_echo_interrupt
, IRQF_SHARED
,
2000 KBUILD_MODNAME
, chip
)) {
2001 snd_echo_free(chip
);
2002 snd_printk(KERN_ERR
"cannot grab irq\n");
2005 chip
->irq
= pci
->irq
;
2006 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n",
2007 chip
->pci
, chip
->irq
, chip
->pci
->subsystem_device
));
2009 /* Create the DSP comm page - this is the area of memory used for most
2010 of the communication with the DSP, which accesses it via bus mastering */
2011 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(chip
->pci
),
2012 sizeof(struct comm_page
),
2013 &chip
->commpage_dma_buf
) < 0) {
2014 snd_echo_free(chip
);
2015 snd_printk(KERN_ERR
"cannot allocate the comm page\n");
2018 chip
->comm_page_phys
= chip
->commpage_dma_buf
.addr
;
2019 chip
->comm_page
= (struct comm_page
*)chip
->commpage_dma_buf
.area
;
2021 err
= init_hw(chip
, chip
->pci
->device
, chip
->pci
->subsystem_device
);
2023 err
= set_mixer_defaults(chip
);
2025 DE_INIT(("init_hw err=%d\n", err
));
2026 snd_echo_free(chip
);
2029 DE_INIT(("Card init OK\n"));
2031 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
2032 snd_echo_free(chip
);
2043 static int __devinit
snd_echo_probe(struct pci_dev
*pci
,
2044 const struct pci_device_id
*pci_id
)
2047 struct snd_card
*card
;
2048 struct echoaudio
*chip
;
2052 if (dev
>= SNDRV_CARDS
)
2059 DE_INIT(("Echoaudio driver starting...\n"));
2061 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
, 0, &card
);
2065 snd_card_set_dev(card
, &pci
->dev
);
2067 chip
= NULL
; /* Tells snd_echo_create to allocate chip */
2068 if ((err
= snd_echo_create(card
, pci
, &chip
)) < 0) {
2069 snd_card_free(card
);
2073 strcpy(card
->driver
, "Echo_" ECHOCARD_NAME
);
2074 strcpy(card
->shortname
, chip
->card_name
);
2077 if (pci_id
->device
== 0x3410)
2080 sprintf(card
->longname
, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2081 card
->shortname
, pci_id
->subdevice
& 0x000f, dsp
,
2082 chip
->dsp_registers_phys
, chip
->irq
);
2084 if ((err
= snd_echo_new_pcm(chip
)) < 0) {
2085 snd_printk(KERN_ERR
"new pcm error %d\n", err
);
2086 snd_card_free(card
);
2090 #ifdef ECHOCARD_HAS_MIDI
2091 if (chip
->has_midi
) { /* Some Mia's do not have midi */
2092 if ((err
= snd_echo_midi_create(card
, chip
)) < 0) {
2093 snd_printk(KERN_ERR
"new midi error %d\n", err
);
2094 snd_card_free(card
);
2100 #ifdef ECHOCARD_HAS_VMIXER
2101 snd_echo_vmixer
.count
= num_pipes_out(chip
) * num_busses_out(chip
);
2102 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vmixer
, chip
))) < 0)
2104 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2105 err
= snd_ctl_add(chip
->card
,
2106 snd_ctl_new1(&snd_echo_line_output_gain
, chip
));
2110 #else /* ECHOCARD_HAS_VMIXER */
2111 err
= snd_ctl_add(chip
->card
,
2112 snd_ctl_new1(&snd_echo_pcm_output_gain
, chip
));
2115 #endif /* ECHOCARD_HAS_VMIXER */
2117 #ifdef ECHOCARD_HAS_INPUT_GAIN
2118 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_line_input_gain
, chip
))) < 0)
2122 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2123 if (!chip
->hasnt_input_nominal_level
)
2124 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_intput_nominal_level
, chip
))) < 0)
2128 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2129 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_output_nominal_level
, chip
))) < 0)
2133 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vumeters_switch
, chip
))) < 0)
2136 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vumeters
, chip
))) < 0)
2139 #ifdef ECHOCARD_HAS_MONITOR
2140 snd_echo_monitor_mixer
.count
= num_busses_in(chip
) * num_busses_out(chip
);
2141 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_monitor_mixer
, chip
))) < 0)
2145 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2146 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_automute_switch
, chip
))) < 0)
2150 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_channels_info
, chip
))) < 0)
2153 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2154 /* Creates a list of available digital modes */
2155 chip
->num_digital_modes
= 0;
2156 for (i
= 0; i
< 6; i
++)
2157 if (chip
->digital_modes
& (1 << i
))
2158 chip
->digital_mode_list
[chip
->num_digital_modes
++] = i
;
2160 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_digital_mode_switch
, chip
))) < 0)
2162 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2164 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2165 /* Creates a list of available clock sources */
2166 chip
->num_clock_sources
= 0;
2167 for (i
= 0; i
< 10; i
++)
2168 if (chip
->input_clock_types
& (1 << i
))
2169 chip
->clock_source_list
[chip
->num_clock_sources
++] = i
;
2171 if (chip
->num_clock_sources
> 1) {
2172 chip
->clock_src_ctl
= snd_ctl_new1(&snd_echo_clock_source_switch
, chip
);
2173 if ((err
= snd_ctl_add(chip
->card
, chip
->clock_src_ctl
)) < 0)
2176 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2178 #ifdef ECHOCARD_HAS_DIGITAL_IO
2179 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_spdif_mode_switch
, chip
))) < 0)
2183 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2184 if (chip
->has_phantom_power
)
2185 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_phantom_power_switch
, chip
))) < 0)
2189 err
= snd_card_register(card
);
2192 snd_printk(KERN_INFO
"Card registered: %s\n", card
->longname
);
2194 pci_set_drvdata(pci
, chip
);
2199 snd_printk(KERN_ERR
"new control error %d\n", err
);
2200 snd_card_free(card
);
2206 #if defined(CONFIG_PM)
2208 static int snd_echo_suspend(struct pci_dev
*pci
, pm_message_t state
)
2210 struct echoaudio
*chip
= pci_get_drvdata(pci
);
2212 DE_INIT(("suspend start\n"));
2213 snd_pcm_suspend_all(chip
->analog_pcm
);
2214 snd_pcm_suspend_all(chip
->digital_pcm
);
2216 #ifdef ECHOCARD_HAS_MIDI
2217 /* This call can sleep */
2219 snd_echo_midi_output_trigger(chip
->midi_out
, 0);
2221 spin_lock_irq(&chip
->lock
);
2222 if (wait_handshake(chip
)) {
2223 spin_unlock_irq(&chip
->lock
);
2226 clear_handshake(chip
);
2227 if (send_vector(chip
, DSP_VC_GO_COMATOSE
) < 0) {
2228 spin_unlock_irq(&chip
->lock
);
2231 spin_unlock_irq(&chip
->lock
);
2233 chip
->dsp_code
= NULL
;
2234 free_irq(chip
->irq
, chip
);
2236 pci_save_state(pci
);
2237 pci_disable_device(pci
);
2239 DE_INIT(("suspend done\n"));
2245 static int snd_echo_resume(struct pci_dev
*pci
)
2247 struct echoaudio
*chip
= pci_get_drvdata(pci
);
2248 struct comm_page
*commpage
, *commpage_bak
;
2249 u32 pipe_alloc_mask
;
2252 DE_INIT(("resume start\n"));
2253 pci_restore_state(pci
);
2254 commpage_bak
= kmalloc(sizeof(struct echoaudio
), GFP_KERNEL
);
2255 if (commpage_bak
== NULL
)
2257 commpage
= chip
->comm_page
;
2258 memcpy(commpage_bak
, commpage
, sizeof(struct comm_page
));
2260 err
= init_hw(chip
, chip
->pci
->device
, chip
->pci
->subsystem_device
);
2262 kfree(commpage_bak
);
2263 DE_INIT(("resume init_hw err=%d\n", err
));
2264 snd_echo_free(chip
);
2267 DE_INIT(("resume init OK\n"));
2269 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2270 * restore_dsp_settings() fails.
2272 pipe_alloc_mask
= chip
->pipe_alloc_mask
;
2273 chip
->pipe_alloc_mask
= 0;
2274 err
= restore_dsp_rettings(chip
);
2275 chip
->pipe_alloc_mask
= pipe_alloc_mask
;
2277 kfree(commpage_bak
);
2280 DE_INIT(("resume restore OK\n"));
2282 memcpy(&commpage
->audio_format
, &commpage_bak
->audio_format
,
2283 sizeof(commpage
->audio_format
));
2284 memcpy(&commpage
->sglist_addr
, &commpage_bak
->sglist_addr
,
2285 sizeof(commpage
->sglist_addr
));
2286 memcpy(&commpage
->midi_output
, &commpage_bak
->midi_output
,
2287 sizeof(commpage
->midi_output
));
2288 kfree(commpage_bak
);
2290 if (request_irq(pci
->irq
, snd_echo_interrupt
, IRQF_SHARED
,
2291 KBUILD_MODNAME
, chip
)) {
2292 snd_echo_free(chip
);
2293 snd_printk(KERN_ERR
"cannot grab irq\n");
2296 chip
->irq
= pci
->irq
;
2297 DE_INIT(("resume irq=%d\n", chip
->irq
));
2299 #ifdef ECHOCARD_HAS_MIDI
2300 if (chip
->midi_input_enabled
)
2301 enable_midi_input(chip
, TRUE
);
2303 snd_echo_midi_output_trigger(chip
->midi_out
, 1);
2306 DE_INIT(("resume done\n"));
2310 #endif /* CONFIG_PM */
2314 static void __devexit
snd_echo_remove(struct pci_dev
*pci
)
2316 struct echoaudio
*chip
;
2318 chip
= pci_get_drvdata(pci
);
2320 snd_card_free(chip
->card
);
2321 pci_set_drvdata(pci
, NULL
);
2326 /******************************************************************************
2327 Everything starts and ends here
2328 ******************************************************************************/
2330 /* pci_driver definition */
2331 static struct pci_driver driver
= {
2332 .name
= KBUILD_MODNAME
,
2333 .id_table
= snd_echo_ids
,
2334 .probe
= snd_echo_probe
,
2335 .remove
= __devexit_p(snd_echo_remove
),
2337 .suspend
= snd_echo_suspend
,
2338 .resume
= snd_echo_resume
,
2339 #endif /* CONFIG_PM */
2344 /* initialization of the module */
2345 static int __init
alsa_card_echo_init(void)
2347 return pci_register_driver(&driver
);
2352 /* clean up the module */
2353 static void __exit
alsa_card_echo_exit(void)
2355 pci_unregister_driver(&driver
);
2359 module_init(alsa_card_echo_init
)
2360 module_exit(alsa_card_echo_exit
)