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
)
49 #ifdef CONFIG_PM_SLEEP
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 dev_err(chip
->card
->dev
,
62 "get_firmware(): Firmware not available (%d)\n", err
);
63 #ifdef CONFIG_PM_SLEEP
65 chip
->fw_cache
[fw_index
] = *fw_entry
;
72 static void free_firmware(const struct firmware
*fw_entry
)
74 #ifdef CONFIG_PM_SLEEP
75 DE_ACT(("firmware not released (kept in cache)\n"));
77 release_firmware(fw_entry
);
78 DE_ACT(("firmware released\n"));
84 static void free_firmware_cache(struct echoaudio
*chip
)
86 #ifdef CONFIG_PM_SLEEP
89 for (i
= 0; i
< 8 ; i
++)
90 if (chip
->fw_cache
[i
]) {
91 release_firmware(chip
->fw_cache
[i
]);
92 DE_ACT(("release_firmware(%d)\n", i
));
95 DE_ACT(("firmware_cache released\n"));
101 /******************************************************************************
103 ******************************************************************************/
105 static void audiopipe_free(struct snd_pcm_runtime
*runtime
)
107 struct audiopipe
*pipe
= runtime
->private_data
;
109 if (pipe
->sgpage
.area
)
110 snd_dma_free_pages(&pipe
->sgpage
);
116 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params
*params
,
117 struct snd_pcm_hw_rule
*rule
)
119 struct snd_interval
*c
= hw_param_interval(params
,
120 SNDRV_PCM_HW_PARAM_CHANNELS
);
121 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
126 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
127 /* >=2 channels cannot be S32_BE */
129 fmt
.bits
[0] &= ~SNDRV_PCM_FMTBIT_S32_BE
;
130 return snd_mask_refine(f
, &fmt
);
133 /* > 2 channels cannot be U8 and S32_BE */
135 fmt
.bits
[0] &= ~(SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S32_BE
);
136 return snd_mask_refine(f
, &fmt
);
138 /* Mono is ok with any format */
144 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params
*params
,
145 struct snd_pcm_hw_rule
*rule
)
147 struct snd_interval
*c
= hw_param_interval(params
,
148 SNDRV_PCM_HW_PARAM_CHANNELS
);
149 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
150 struct snd_interval ch
;
152 snd_interval_any(&ch
);
154 /* S32_BE is mono (and stereo) only */
155 if (f
->bits
[0] == SNDRV_PCM_FMTBIT_S32_BE
) {
157 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
163 return snd_interval_refine(c
, &ch
);
165 /* U8 can be only mono or stereo */
166 if (f
->bits
[0] == SNDRV_PCM_FMTBIT_U8
) {
170 return snd_interval_refine(c
, &ch
);
172 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
178 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params
*params
,
179 struct snd_pcm_hw_rule
*rule
)
181 struct snd_interval
*c
= hw_param_interval(params
,
182 SNDRV_PCM_HW_PARAM_CHANNELS
);
183 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
188 fmask
= fmt
.bits
[0] + ((u64
)fmt
.bits
[1] << 32);
190 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
192 fmask
&= SNDRV_PCM_FMTBIT_S16_LE
|
193 SNDRV_PCM_FMTBIT_S24_3LE
|
194 SNDRV_PCM_FMTBIT_S32_LE
;
195 /* 1 channel must be S32_BE or S32_LE */
196 } else if (c
->max
== 1)
197 fmask
&= SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
;
198 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
199 /* 2 channels cannot be S32_BE */
200 else if (c
->min
== 2 && c
->max
== 2)
201 fmask
&= ~SNDRV_PCM_FMTBIT_S32_BE
;
206 fmt
.bits
[0] &= (u32
)fmask
;
207 fmt
.bits
[1] &= (u32
)(fmask
>> 32);
208 return snd_mask_refine(f
, &fmt
);
213 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params
*params
,
214 struct snd_pcm_hw_rule
*rule
)
216 struct snd_interval
*c
= hw_param_interval(params
,
217 SNDRV_PCM_HW_PARAM_CHANNELS
);
218 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
219 struct snd_interval ch
;
222 snd_interval_any(&ch
);
224 fmask
= f
->bits
[0] + ((u64
)f
->bits
[1] << 32);
226 /* S32_BE is mono (and stereo) only */
227 if (fmask
== SNDRV_PCM_FMTBIT_S32_BE
) {
229 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
234 /* U8 is stereo only */
235 } else if (fmask
== SNDRV_PCM_FMTBIT_U8
)
237 /* S16_LE and S24_3LE must be at least stereo */
238 else if (!(fmask
& ~(SNDRV_PCM_FMTBIT_S16_LE
|
239 SNDRV_PCM_FMTBIT_S24_3LE
)))
244 return snd_interval_refine(c
, &ch
);
249 /* Since the sample rate is a global setting, do allow the user to change the
250 sample rate only if there is only one pcm device open. */
251 static int hw_rule_sample_rate(struct snd_pcm_hw_params
*params
,
252 struct snd_pcm_hw_rule
*rule
)
254 struct snd_interval
*rate
= hw_param_interval(params
,
255 SNDRV_PCM_HW_PARAM_RATE
);
256 struct echoaudio
*chip
= rule
->private;
257 struct snd_interval fixed
;
259 if (!chip
->can_set_rate
) {
260 snd_interval_any(&fixed
);
261 fixed
.min
= fixed
.max
= chip
->sample_rate
;
262 return snd_interval_refine(rate
, &fixed
);
268 static int pcm_open(struct snd_pcm_substream
*substream
,
269 signed char max_channels
)
271 struct echoaudio
*chip
;
272 struct snd_pcm_runtime
*runtime
;
273 struct audiopipe
*pipe
;
276 if (max_channels
<= 0)
279 chip
= snd_pcm_substream_chip(substream
);
280 runtime
= substream
->runtime
;
282 pipe
= kzalloc(sizeof(struct audiopipe
), GFP_KERNEL
);
285 pipe
->index
= -1; /* Not configured yet */
287 /* Set up hw capabilities and contraints */
288 memcpy(&pipe
->hw
, &pcm_hardware_skel
, sizeof(struct snd_pcm_hardware
));
289 DE_HWP(("max_channels=%d\n", max_channels
));
290 pipe
->constr
.list
= channels_list
;
291 pipe
->constr
.mask
= 0;
292 for (i
= 0; channels_list
[i
] <= max_channels
; i
++);
293 pipe
->constr
.count
= i
;
294 if (pipe
->hw
.channels_max
> max_channels
)
295 pipe
->hw
.channels_max
= max_channels
;
296 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
) {
297 pipe
->hw
.rate_max
= 48000;
298 pipe
->hw
.rates
&= SNDRV_PCM_RATE_8000_48000
;
301 runtime
->hw
= pipe
->hw
;
302 runtime
->private_data
= pipe
;
303 runtime
->private_free
= audiopipe_free
;
304 snd_pcm_set_sync(substream
);
306 /* Only mono and any even number of channels are allowed */
307 if ((err
= snd_pcm_hw_constraint_list(runtime
, 0,
308 SNDRV_PCM_HW_PARAM_CHANNELS
,
312 /* All periods should have the same size */
313 if ((err
= snd_pcm_hw_constraint_integer(runtime
,
314 SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
317 /* The hw accesses memory in chunks 32 frames long and they should be
318 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
319 generated with a resolution of 32 frames. Thus we need the following */
320 if ((err
= snd_pcm_hw_constraint_step(runtime
, 0,
321 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
324 if ((err
= snd_pcm_hw_constraint_step(runtime
, 0,
325 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
329 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
330 SNDRV_PCM_HW_PARAM_RATE
,
331 hw_rule_sample_rate
, chip
,
332 SNDRV_PCM_HW_PARAM_RATE
, -1)) < 0)
335 /* Finally allocate a page for the scatter-gather list */
336 if ((err
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
,
337 snd_dma_pci_data(chip
->pci
),
338 PAGE_SIZE
, &pipe
->sgpage
)) < 0) {
339 DE_HWP(("s-g list allocation failed\n"));
348 static int pcm_analog_in_open(struct snd_pcm_substream
*substream
)
350 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
353 DE_ACT(("pcm_analog_in_open\n"));
354 if ((err
= pcm_open(substream
, num_analog_busses_in(chip
) -
355 substream
->number
)) < 0)
357 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
358 SNDRV_PCM_HW_PARAM_CHANNELS
,
359 hw_rule_capture_channels_by_format
, NULL
,
360 SNDRV_PCM_HW_PARAM_FORMAT
, -1)) < 0)
362 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
363 SNDRV_PCM_HW_PARAM_FORMAT
,
364 hw_rule_capture_format_by_channels
, NULL
,
365 SNDRV_PCM_HW_PARAM_CHANNELS
, -1)) < 0)
367 atomic_inc(&chip
->opencount
);
368 if (atomic_read(&chip
->opencount
) > 1 && chip
->rate_set
)
369 chip
->can_set_rate
=0;
370 DE_HWP(("pcm_analog_in_open cs=%d oc=%d r=%d\n",
371 chip
->can_set_rate
, atomic_read(&chip
->opencount
),
378 static int pcm_analog_out_open(struct snd_pcm_substream
*substream
)
380 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
381 int max_channels
, err
;
383 #ifdef ECHOCARD_HAS_VMIXER
384 max_channels
= num_pipes_out(chip
);
386 max_channels
= num_analog_busses_out(chip
);
388 DE_ACT(("pcm_analog_out_open\n"));
389 if ((err
= pcm_open(substream
, max_channels
- substream
->number
)) < 0)
391 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
392 SNDRV_PCM_HW_PARAM_CHANNELS
,
393 hw_rule_playback_channels_by_format
,
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_playback_format_by_channels
,
401 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;
406 DE_HWP(("pcm_analog_out_open cs=%d oc=%d r=%d\n",
407 chip
->can_set_rate
, atomic_read(&chip
->opencount
),
414 #ifdef ECHOCARD_HAS_DIGITAL_IO
416 static int pcm_digital_in_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_in_open\n"));
422 max_channels
= num_digital_busses_in(chip
) - substream
->number
;
423 mutex_lock(&chip
->mode_mutex
);
424 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
)
425 err
= pcm_open(substream
, max_channels
);
426 else /* If the card has ADAT, subtract the 6 channels
427 * that S/PDIF doesn't have
429 err
= pcm_open(substream
, max_channels
- ECHOCARD_HAS_ADAT
);
434 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
435 SNDRV_PCM_HW_PARAM_CHANNELS
,
436 hw_rule_capture_channels_by_format
, NULL
,
437 SNDRV_PCM_HW_PARAM_FORMAT
, -1)) < 0)
439 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
440 SNDRV_PCM_HW_PARAM_FORMAT
,
441 hw_rule_capture_format_by_channels
, NULL
,
442 SNDRV_PCM_HW_PARAM_CHANNELS
, -1)) < 0)
445 atomic_inc(&chip
->opencount
);
446 if (atomic_read(&chip
->opencount
) > 1 && chip
->rate_set
)
447 chip
->can_set_rate
=0;
450 mutex_unlock(&chip
->mode_mutex
);
456 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
458 static int pcm_digital_out_open(struct snd_pcm_substream
*substream
)
460 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
461 int err
, max_channels
;
463 DE_ACT(("pcm_digital_out_open\n"));
464 max_channels
= num_digital_busses_out(chip
) - substream
->number
;
465 mutex_lock(&chip
->mode_mutex
);
466 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
)
467 err
= pcm_open(substream
, max_channels
);
468 else /* If the card has ADAT, subtract the 6 channels
469 * that S/PDIF doesn't have
471 err
= pcm_open(substream
, max_channels
- ECHOCARD_HAS_ADAT
);
476 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
477 SNDRV_PCM_HW_PARAM_CHANNELS
,
478 hw_rule_playback_channels_by_format
,
479 NULL
, SNDRV_PCM_HW_PARAM_FORMAT
,
482 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
483 SNDRV_PCM_HW_PARAM_FORMAT
,
484 hw_rule_playback_format_by_channels
,
485 NULL
, SNDRV_PCM_HW_PARAM_CHANNELS
,
488 atomic_inc(&chip
->opencount
);
489 if (atomic_read(&chip
->opencount
) > 1 && chip
->rate_set
)
490 chip
->can_set_rate
=0;
492 mutex_unlock(&chip
->mode_mutex
);
496 #endif /* !ECHOCARD_HAS_VMIXER */
498 #endif /* ECHOCARD_HAS_DIGITAL_IO */
502 static int pcm_close(struct snd_pcm_substream
*substream
)
504 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
507 /* Nothing to do here. Audio is already off and pipe will be
508 * freed by its callback
510 DE_ACT(("pcm_close\n"));
512 atomic_dec(&chip
->opencount
);
513 oc
= atomic_read(&chip
->opencount
);
514 DE_ACT(("pcm_close oc=%d cs=%d rs=%d\n", oc
,
515 chip
->can_set_rate
, chip
->rate_set
));
517 chip
->can_set_rate
= 1;
520 DE_ACT(("pcm_close2 oc=%d cs=%d rs=%d\n", oc
,
521 chip
->can_set_rate
,chip
->rate_set
));
528 /* Channel allocation and scatter-gather list setup */
529 static int init_engine(struct snd_pcm_substream
*substream
,
530 struct snd_pcm_hw_params
*hw_params
,
531 int pipe_index
, int interleave
)
533 struct echoaudio
*chip
;
534 int err
, per
, rest
, page
, edge
, offs
;
535 struct audiopipe
*pipe
;
537 chip
= snd_pcm_substream_chip(substream
);
538 pipe
= (struct audiopipe
*) substream
->runtime
->private_data
;
540 /* Sets up che hardware. If it's already initialized, reset and
541 * redo with the new parameters
543 spin_lock_irq(&chip
->lock
);
544 if (pipe
->index
>= 0) {
545 DE_HWP(("hwp_ie free(%d)\n", pipe
->index
));
546 err
= free_pipes(chip
, pipe
);
548 chip
->substream
[pipe
->index
] = NULL
;
551 err
= allocate_pipes(chip
, pipe
, pipe_index
, interleave
);
553 spin_unlock_irq(&chip
->lock
);
554 DE_ACT((KERN_NOTICE
"allocate_pipes(%d) err=%d\n",
558 spin_unlock_irq(&chip
->lock
);
559 DE_ACT((KERN_NOTICE
"allocate_pipes()=%d\n", pipe_index
));
561 DE_HWP(("pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
562 params_buffer_bytes(hw_params
), params_periods(hw_params
),
563 params_period_bytes(hw_params
)));
564 err
= snd_pcm_lib_malloc_pages(substream
,
565 params_buffer_bytes(hw_params
));
567 dev_err(chip
->card
->dev
, "malloc_pages err=%d\n", err
);
568 spin_lock_irq(&chip
->lock
);
569 free_pipes(chip
, pipe
);
570 spin_unlock_irq(&chip
->lock
);
575 sglist_init(chip
, pipe
);
577 for (offs
= page
= per
= 0; offs
< params_buffer_bytes(hw_params
);
579 rest
= params_period_bytes(hw_params
);
580 if (offs
+ rest
> params_buffer_bytes(hw_params
))
581 rest
= params_buffer_bytes(hw_params
) - offs
;
584 addr
= snd_pcm_sgbuf_get_addr(substream
, offs
);
585 if (rest
<= edge
- offs
) {
586 sglist_add_mapping(chip
, pipe
, addr
, rest
);
587 sglist_add_irq(chip
, pipe
);
591 sglist_add_mapping(chip
, pipe
, addr
,
603 /* Close the ring buffer */
604 sglist_wrap(chip
, pipe
);
606 /* This stuff is used by the irq handler, so it must be
607 * initialized before chip->substream
609 chip
->last_period
[pipe_index
] = 0;
610 pipe
->last_counter
= 0;
613 chip
->substream
[pipe_index
] = substream
;
615 spin_lock_irq(&chip
->lock
);
616 set_sample_rate(chip
, hw_params
->rate_num
/ hw_params
->rate_den
);
617 spin_unlock_irq(&chip
->lock
);
618 DE_HWP(("pcm_hw_params ok\n"));
624 static int pcm_analog_in_hw_params(struct snd_pcm_substream
*substream
,
625 struct snd_pcm_hw_params
*hw_params
)
627 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
629 return init_engine(substream
, hw_params
, px_analog_in(chip
) +
630 substream
->number
, params_channels(hw_params
));
635 static int pcm_analog_out_hw_params(struct snd_pcm_substream
*substream
,
636 struct snd_pcm_hw_params
*hw_params
)
638 return init_engine(substream
, hw_params
, substream
->number
,
639 params_channels(hw_params
));
644 #ifdef ECHOCARD_HAS_DIGITAL_IO
646 static int pcm_digital_in_hw_params(struct snd_pcm_substream
*substream
,
647 struct snd_pcm_hw_params
*hw_params
)
649 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
651 return init_engine(substream
, hw_params
, px_digital_in(chip
) +
652 substream
->number
, params_channels(hw_params
));
657 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
658 static int pcm_digital_out_hw_params(struct snd_pcm_substream
*substream
,
659 struct snd_pcm_hw_params
*hw_params
)
661 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
663 return init_engine(substream
, hw_params
, px_digital_out(chip
) +
664 substream
->number
, params_channels(hw_params
));
666 #endif /* !ECHOCARD_HAS_VMIXER */
668 #endif /* ECHOCARD_HAS_DIGITAL_IO */
672 static int pcm_hw_free(struct snd_pcm_substream
*substream
)
674 struct echoaudio
*chip
;
675 struct audiopipe
*pipe
;
677 chip
= snd_pcm_substream_chip(substream
);
678 pipe
= (struct audiopipe
*) substream
->runtime
->private_data
;
680 spin_lock_irq(&chip
->lock
);
681 if (pipe
->index
>= 0) {
682 DE_HWP(("pcm_hw_free(%d)\n", pipe
->index
));
683 free_pipes(chip
, pipe
);
684 chip
->substream
[pipe
->index
] = NULL
;
687 spin_unlock_irq(&chip
->lock
);
689 DE_HWP(("pcm_hw_freed\n"));
690 snd_pcm_lib_free_pages(substream
);
696 static int pcm_prepare(struct snd_pcm_substream
*substream
)
698 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
699 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
700 struct audioformat format
;
701 int pipe_index
= ((struct audiopipe
*)runtime
->private_data
)->index
;
703 DE_HWP(("Prepare rate=%d format=%d channels=%d\n",
704 runtime
->rate
, runtime
->format
, runtime
->channels
));
705 format
.interleave
= runtime
->channels
;
706 format
.data_are_bigendian
= 0;
707 format
.mono_to_stereo
= 0;
708 switch (runtime
->format
) {
709 case SNDRV_PCM_FORMAT_U8
:
710 format
.bits_per_sample
= 8;
712 case SNDRV_PCM_FORMAT_S16_LE
:
713 format
.bits_per_sample
= 16;
715 case SNDRV_PCM_FORMAT_S24_3LE
:
716 format
.bits_per_sample
= 24;
718 case SNDRV_PCM_FORMAT_S32_BE
:
719 format
.data_are_bigendian
= 1;
720 case SNDRV_PCM_FORMAT_S32_LE
:
721 format
.bits_per_sample
= 32;
724 DE_HWP(("Prepare error: unsupported format %d\n",
729 if (snd_BUG_ON(pipe_index
>= px_num(chip
)))
731 if (snd_BUG_ON(!is_pipe_allocated(chip
, pipe_index
)))
733 set_audio_format(chip
, pipe_index
, &format
);
739 static int pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
741 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
742 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
743 struct audiopipe
*pipe
= runtime
->private_data
;
746 struct snd_pcm_substream
*s
;
748 snd_pcm_group_for_each_entry(s
, substream
) {
749 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
750 if (s
== chip
->substream
[i
]) {
751 channelmask
|= 1 << i
;
752 snd_pcm_trigger_done(s
, substream
);
757 spin_lock(&chip
->lock
);
759 case SNDRV_PCM_TRIGGER_RESUME
:
760 DE_ACT(("pcm_trigger resume\n"));
761 case SNDRV_PCM_TRIGGER_START
:
762 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
763 DE_ACT(("pcm_trigger start\n"));
764 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
765 if (channelmask
& (1 << i
)) {
766 pipe
= chip
->substream
[i
]->runtime
->private_data
;
767 switch (pipe
->state
) {
768 case PIPE_STATE_STOPPED
:
769 chip
->last_period
[i
] = 0;
770 pipe
->last_counter
= 0;
772 *pipe
->dma_counter
= 0;
773 case PIPE_STATE_PAUSED
:
774 pipe
->state
= PIPE_STATE_STARTED
;
776 case PIPE_STATE_STARTED
:
781 err
= start_transport(chip
, channelmask
,
782 chip
->pipe_cyclic_mask
);
784 case SNDRV_PCM_TRIGGER_SUSPEND
:
785 DE_ACT(("pcm_trigger suspend\n"));
786 case SNDRV_PCM_TRIGGER_STOP
:
787 DE_ACT(("pcm_trigger stop\n"));
788 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
789 if (channelmask
& (1 << i
)) {
790 pipe
= chip
->substream
[i
]->runtime
->private_data
;
791 pipe
->state
= PIPE_STATE_STOPPED
;
794 err
= stop_transport(chip
, channelmask
);
796 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
797 DE_ACT(("pcm_trigger pause\n"));
798 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
799 if (channelmask
& (1 << i
)) {
800 pipe
= chip
->substream
[i
]->runtime
->private_data
;
801 pipe
->state
= PIPE_STATE_PAUSED
;
804 err
= pause_transport(chip
, channelmask
);
809 spin_unlock(&chip
->lock
);
815 static snd_pcm_uframes_t
pcm_pointer(struct snd_pcm_substream
*substream
)
817 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
818 struct audiopipe
*pipe
= runtime
->private_data
;
819 size_t cnt
, bufsize
, pos
;
821 cnt
= le32_to_cpu(*pipe
->dma_counter
);
822 pipe
->position
+= cnt
- pipe
->last_counter
;
823 pipe
->last_counter
= cnt
;
824 bufsize
= substream
->runtime
->buffer_size
;
825 pos
= bytes_to_frames(substream
->runtime
, pipe
->position
);
827 while (pos
>= bufsize
) {
828 pipe
->position
-= frames_to_bytes(substream
->runtime
, bufsize
);
836 /* pcm *_ops structures */
837 static struct snd_pcm_ops analog_playback_ops
= {
838 .open
= pcm_analog_out_open
,
840 .ioctl
= snd_pcm_lib_ioctl
,
841 .hw_params
= pcm_analog_out_hw_params
,
842 .hw_free
= pcm_hw_free
,
843 .prepare
= pcm_prepare
,
844 .trigger
= pcm_trigger
,
845 .pointer
= pcm_pointer
,
846 .page
= snd_pcm_sgbuf_ops_page
,
848 static struct snd_pcm_ops analog_capture_ops
= {
849 .open
= pcm_analog_in_open
,
851 .ioctl
= snd_pcm_lib_ioctl
,
852 .hw_params
= pcm_analog_in_hw_params
,
853 .hw_free
= pcm_hw_free
,
854 .prepare
= pcm_prepare
,
855 .trigger
= pcm_trigger
,
856 .pointer
= pcm_pointer
,
857 .page
= snd_pcm_sgbuf_ops_page
,
859 #ifdef ECHOCARD_HAS_DIGITAL_IO
860 #ifndef ECHOCARD_HAS_VMIXER
861 static struct snd_pcm_ops digital_playback_ops
= {
862 .open
= pcm_digital_out_open
,
864 .ioctl
= snd_pcm_lib_ioctl
,
865 .hw_params
= pcm_digital_out_hw_params
,
866 .hw_free
= pcm_hw_free
,
867 .prepare
= pcm_prepare
,
868 .trigger
= pcm_trigger
,
869 .pointer
= pcm_pointer
,
870 .page
= snd_pcm_sgbuf_ops_page
,
872 #endif /* !ECHOCARD_HAS_VMIXER */
873 static struct snd_pcm_ops digital_capture_ops
= {
874 .open
= pcm_digital_in_open
,
876 .ioctl
= snd_pcm_lib_ioctl
,
877 .hw_params
= pcm_digital_in_hw_params
,
878 .hw_free
= pcm_hw_free
,
879 .prepare
= pcm_prepare
,
880 .trigger
= pcm_trigger
,
881 .pointer
= pcm_pointer
,
882 .page
= snd_pcm_sgbuf_ops_page
,
884 #endif /* ECHOCARD_HAS_DIGITAL_IO */
888 /* Preallocate memory only for the first substream because it's the most
891 static int snd_echo_preallocate_pages(struct snd_pcm
*pcm
, struct device
*dev
)
893 struct snd_pcm_substream
*ss
;
896 for (stream
= 0; stream
< 2; stream
++)
897 for (ss
= pcm
->streams
[stream
].substream
; ss
; ss
= ss
->next
) {
898 err
= snd_pcm_lib_preallocate_pages(ss
, SNDRV_DMA_TYPE_DEV_SG
,
900 ss
->number
? 0 : 128<<10,
910 /*<--snd_echo_probe() */
911 static int snd_echo_new_pcm(struct echoaudio
*chip
)
916 #ifdef ECHOCARD_HAS_VMIXER
917 /* This card has a Vmixer, that is there is no direct mapping from PCM
918 streams to physical outputs. The user can mix the streams as he wishes
919 via control interface and it's possible to send any stream to any
920 output, thus it makes no sense to keep analog and digital outputs
923 /* PCM#0 Virtual outputs and analog inputs */
924 if ((err
= snd_pcm_new(chip
->card
, "PCM", 0, num_pipes_out(chip
),
925 num_analog_busses_in(chip
), &pcm
)) < 0)
927 pcm
->private_data
= chip
;
928 chip
->analog_pcm
= pcm
;
929 strcpy(pcm
->name
, chip
->card
->shortname
);
930 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &analog_playback_ops
);
931 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &analog_capture_ops
);
932 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
934 DE_INIT(("Analog PCM ok\n"));
936 #ifdef ECHOCARD_HAS_DIGITAL_IO
937 /* PCM#1 Digital inputs, no outputs */
938 if ((err
= snd_pcm_new(chip
->card
, "Digital PCM", 1, 0,
939 num_digital_busses_in(chip
), &pcm
)) < 0)
941 pcm
->private_data
= chip
;
942 chip
->digital_pcm
= pcm
;
943 strcpy(pcm
->name
, chip
->card
->shortname
);
944 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &digital_capture_ops
);
945 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
947 DE_INIT(("Digital PCM ok\n"));
948 #endif /* ECHOCARD_HAS_DIGITAL_IO */
950 #else /* ECHOCARD_HAS_VMIXER */
952 /* The card can manage substreams formed by analog and digital channels
953 at the same time, but I prefer to keep analog and digital channels
954 separated, because that mixed thing is confusing and useless. So we
955 register two PCM devices: */
957 /* PCM#0 Analog i/o */
958 if ((err
= snd_pcm_new(chip
->card
, "Analog PCM", 0,
959 num_analog_busses_out(chip
),
960 num_analog_busses_in(chip
), &pcm
)) < 0)
962 pcm
->private_data
= chip
;
963 chip
->analog_pcm
= pcm
;
964 strcpy(pcm
->name
, chip
->card
->shortname
);
965 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &analog_playback_ops
);
966 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &analog_capture_ops
);
967 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
969 DE_INIT(("Analog PCM ok\n"));
971 #ifdef ECHOCARD_HAS_DIGITAL_IO
972 /* PCM#1 Digital i/o */
973 if ((err
= snd_pcm_new(chip
->card
, "Digital PCM", 1,
974 num_digital_busses_out(chip
),
975 num_digital_busses_in(chip
), &pcm
)) < 0)
977 pcm
->private_data
= chip
;
978 chip
->digital_pcm
= pcm
;
979 strcpy(pcm
->name
, chip
->card
->shortname
);
980 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &digital_playback_ops
);
981 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &digital_capture_ops
);
982 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
984 DE_INIT(("Digital PCM ok\n"));
985 #endif /* ECHOCARD_HAS_DIGITAL_IO */
987 #endif /* ECHOCARD_HAS_VMIXER */
995 /******************************************************************************
997 ******************************************************************************/
999 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
1001 /******************* PCM output volume *******************/
1002 static int snd_echo_output_gain_info(struct snd_kcontrol
*kcontrol
,
1003 struct snd_ctl_elem_info
*uinfo
)
1005 struct echoaudio
*chip
;
1007 chip
= snd_kcontrol_chip(kcontrol
);
1008 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1009 uinfo
->count
= num_busses_out(chip
);
1010 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1011 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1015 static int snd_echo_output_gain_get(struct snd_kcontrol
*kcontrol
,
1016 struct snd_ctl_elem_value
*ucontrol
)
1018 struct echoaudio
*chip
;
1021 chip
= snd_kcontrol_chip(kcontrol
);
1022 for (c
= 0; c
< num_busses_out(chip
); c
++)
1023 ucontrol
->value
.integer
.value
[c
] = chip
->output_gain
[c
];
1027 static int snd_echo_output_gain_put(struct snd_kcontrol
*kcontrol
,
1028 struct snd_ctl_elem_value
*ucontrol
)
1030 struct echoaudio
*chip
;
1031 int c
, changed
, gain
;
1034 chip
= snd_kcontrol_chip(kcontrol
);
1035 spin_lock_irq(&chip
->lock
);
1036 for (c
= 0; c
< num_busses_out(chip
); c
++) {
1037 gain
= ucontrol
->value
.integer
.value
[c
];
1038 /* Ignore out of range values */
1039 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1041 if (chip
->output_gain
[c
] != gain
) {
1042 set_output_gain(chip
, c
, gain
);
1047 update_output_line_level(chip
);
1048 spin_unlock_irq(&chip
->lock
);
1052 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1053 /* On the Mia this one controls the line-out volume */
1054 static struct snd_kcontrol_new snd_echo_line_output_gain
= {
1055 .name
= "Line Playback Volume",
1056 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1057 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1058 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1059 .info
= snd_echo_output_gain_info
,
1060 .get
= snd_echo_output_gain_get
,
1061 .put
= snd_echo_output_gain_put
,
1062 .tlv
= {.p
= db_scale_output_gain
},
1065 static struct snd_kcontrol_new snd_echo_pcm_output_gain
= {
1066 .name
= "PCM Playback Volume",
1067 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1068 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1069 .info
= snd_echo_output_gain_info
,
1070 .get
= snd_echo_output_gain_get
,
1071 .put
= snd_echo_output_gain_put
,
1072 .tlv
= {.p
= db_scale_output_gain
},
1076 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1080 #ifdef ECHOCARD_HAS_INPUT_GAIN
1082 /******************* Analog input volume *******************/
1083 static int snd_echo_input_gain_info(struct snd_kcontrol
*kcontrol
,
1084 struct snd_ctl_elem_info
*uinfo
)
1086 struct echoaudio
*chip
;
1088 chip
= snd_kcontrol_chip(kcontrol
);
1089 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1090 uinfo
->count
= num_analog_busses_in(chip
);
1091 uinfo
->value
.integer
.min
= ECHOGAIN_MININP
;
1092 uinfo
->value
.integer
.max
= ECHOGAIN_MAXINP
;
1096 static int snd_echo_input_gain_get(struct snd_kcontrol
*kcontrol
,
1097 struct snd_ctl_elem_value
*ucontrol
)
1099 struct echoaudio
*chip
;
1102 chip
= snd_kcontrol_chip(kcontrol
);
1103 for (c
= 0; c
< num_analog_busses_in(chip
); c
++)
1104 ucontrol
->value
.integer
.value
[c
] = chip
->input_gain
[c
];
1108 static int snd_echo_input_gain_put(struct snd_kcontrol
*kcontrol
,
1109 struct snd_ctl_elem_value
*ucontrol
)
1111 struct echoaudio
*chip
;
1112 int c
, gain
, changed
;
1115 chip
= snd_kcontrol_chip(kcontrol
);
1116 spin_lock_irq(&chip
->lock
);
1117 for (c
= 0; c
< num_analog_busses_in(chip
); c
++) {
1118 gain
= ucontrol
->value
.integer
.value
[c
];
1119 /* Ignore out of range values */
1120 if (gain
< ECHOGAIN_MININP
|| gain
> ECHOGAIN_MAXINP
)
1122 if (chip
->input_gain
[c
] != gain
) {
1123 set_input_gain(chip
, c
, gain
);
1128 update_input_line_level(chip
);
1129 spin_unlock_irq(&chip
->lock
);
1133 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain
, -2500, 50, 0);
1135 static struct snd_kcontrol_new snd_echo_line_input_gain
= {
1136 .name
= "Line Capture Volume",
1137 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1138 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1139 .info
= snd_echo_input_gain_info
,
1140 .get
= snd_echo_input_gain_get
,
1141 .put
= snd_echo_input_gain_put
,
1142 .tlv
= {.p
= db_scale_input_gain
},
1145 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1149 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1151 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1152 static int snd_echo_output_nominal_info (struct snd_kcontrol
*kcontrol
,
1153 struct snd_ctl_elem_info
*uinfo
)
1155 struct echoaudio
*chip
;
1157 chip
= snd_kcontrol_chip(kcontrol
);
1158 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1159 uinfo
->count
= num_analog_busses_out(chip
);
1160 uinfo
->value
.integer
.min
= 0;
1161 uinfo
->value
.integer
.max
= 1;
1165 static int snd_echo_output_nominal_get(struct snd_kcontrol
*kcontrol
,
1166 struct snd_ctl_elem_value
*ucontrol
)
1168 struct echoaudio
*chip
;
1171 chip
= snd_kcontrol_chip(kcontrol
);
1172 for (c
= 0; c
< num_analog_busses_out(chip
); c
++)
1173 ucontrol
->value
.integer
.value
[c
] = chip
->nominal_level
[c
];
1177 static int snd_echo_output_nominal_put(struct snd_kcontrol
*kcontrol
,
1178 struct snd_ctl_elem_value
*ucontrol
)
1180 struct echoaudio
*chip
;
1184 chip
= snd_kcontrol_chip(kcontrol
);
1185 spin_lock_irq(&chip
->lock
);
1186 for (c
= 0; c
< num_analog_busses_out(chip
); c
++) {
1187 if (chip
->nominal_level
[c
] != ucontrol
->value
.integer
.value
[c
]) {
1188 set_nominal_level(chip
, c
,
1189 ucontrol
->value
.integer
.value
[c
]);
1194 update_output_line_level(chip
);
1195 spin_unlock_irq(&chip
->lock
);
1199 static struct snd_kcontrol_new snd_echo_output_nominal_level
= {
1200 .name
= "Line Playback Switch (-10dBV)",
1201 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1202 .info
= snd_echo_output_nominal_info
,
1203 .get
= snd_echo_output_nominal_get
,
1204 .put
= snd_echo_output_nominal_put
,
1207 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1211 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1213 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1214 static int snd_echo_input_nominal_info(struct snd_kcontrol
*kcontrol
,
1215 struct snd_ctl_elem_info
*uinfo
)
1217 struct echoaudio
*chip
;
1219 chip
= snd_kcontrol_chip(kcontrol
);
1220 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1221 uinfo
->count
= num_analog_busses_in(chip
);
1222 uinfo
->value
.integer
.min
= 0;
1223 uinfo
->value
.integer
.max
= 1;
1227 static int snd_echo_input_nominal_get(struct snd_kcontrol
*kcontrol
,
1228 struct snd_ctl_elem_value
*ucontrol
)
1230 struct echoaudio
*chip
;
1233 chip
= snd_kcontrol_chip(kcontrol
);
1234 for (c
= 0; c
< num_analog_busses_in(chip
); c
++)
1235 ucontrol
->value
.integer
.value
[c
] =
1236 chip
->nominal_level
[bx_analog_in(chip
) + c
];
1240 static int snd_echo_input_nominal_put(struct snd_kcontrol
*kcontrol
,
1241 struct snd_ctl_elem_value
*ucontrol
)
1243 struct echoaudio
*chip
;
1247 chip
= snd_kcontrol_chip(kcontrol
);
1248 spin_lock_irq(&chip
->lock
);
1249 for (c
= 0; c
< num_analog_busses_in(chip
); c
++) {
1250 if (chip
->nominal_level
[bx_analog_in(chip
) + c
] !=
1251 ucontrol
->value
.integer
.value
[c
]) {
1252 set_nominal_level(chip
, bx_analog_in(chip
) + c
,
1253 ucontrol
->value
.integer
.value
[c
]);
1258 update_output_line_level(chip
); /* "Output" is not a mistake
1261 spin_unlock_irq(&chip
->lock
);
1265 static struct snd_kcontrol_new snd_echo_intput_nominal_level
= {
1266 .name
= "Line Capture Switch (-10dBV)",
1267 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1268 .info
= snd_echo_input_nominal_info
,
1269 .get
= snd_echo_input_nominal_get
,
1270 .put
= snd_echo_input_nominal_put
,
1273 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1277 #ifdef ECHOCARD_HAS_MONITOR
1279 /******************* Monitor mixer *******************/
1280 static int snd_echo_mixer_info(struct snd_kcontrol
*kcontrol
,
1281 struct snd_ctl_elem_info
*uinfo
)
1283 struct echoaudio
*chip
;
1285 chip
= snd_kcontrol_chip(kcontrol
);
1286 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1288 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1289 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1290 uinfo
->dimen
.d
[0] = num_busses_out(chip
);
1291 uinfo
->dimen
.d
[1] = num_busses_in(chip
);
1295 static int snd_echo_mixer_get(struct snd_kcontrol
*kcontrol
,
1296 struct snd_ctl_elem_value
*ucontrol
)
1298 struct echoaudio
*chip
;
1300 chip
= snd_kcontrol_chip(kcontrol
);
1301 ucontrol
->value
.integer
.value
[0] =
1302 chip
->monitor_gain
[ucontrol
->id
.index
/ num_busses_in(chip
)]
1303 [ucontrol
->id
.index
% num_busses_in(chip
)];
1307 static int snd_echo_mixer_put(struct snd_kcontrol
*kcontrol
,
1308 struct snd_ctl_elem_value
*ucontrol
)
1310 struct echoaudio
*chip
;
1315 chip
= snd_kcontrol_chip(kcontrol
);
1316 out
= ucontrol
->id
.index
/ num_busses_in(chip
);
1317 in
= ucontrol
->id
.index
% num_busses_in(chip
);
1318 gain
= ucontrol
->value
.integer
.value
[0];
1319 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1321 if (chip
->monitor_gain
[out
][in
] != gain
) {
1322 spin_lock_irq(&chip
->lock
);
1323 set_monitor_gain(chip
, out
, in
, gain
);
1324 update_output_line_level(chip
);
1325 spin_unlock_irq(&chip
->lock
);
1331 static struct snd_kcontrol_new snd_echo_monitor_mixer
= {
1332 .name
= "Monitor Mixer Volume",
1333 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1334 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1335 .info
= snd_echo_mixer_info
,
1336 .get
= snd_echo_mixer_get
,
1337 .put
= snd_echo_mixer_put
,
1338 .tlv
= {.p
= db_scale_output_gain
},
1341 #endif /* ECHOCARD_HAS_MONITOR */
1345 #ifdef ECHOCARD_HAS_VMIXER
1347 /******************* Vmixer *******************/
1348 static int snd_echo_vmixer_info(struct snd_kcontrol
*kcontrol
,
1349 struct snd_ctl_elem_info
*uinfo
)
1351 struct echoaudio
*chip
;
1353 chip
= snd_kcontrol_chip(kcontrol
);
1354 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1356 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1357 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1358 uinfo
->dimen
.d
[0] = num_busses_out(chip
);
1359 uinfo
->dimen
.d
[1] = num_pipes_out(chip
);
1363 static int snd_echo_vmixer_get(struct snd_kcontrol
*kcontrol
,
1364 struct snd_ctl_elem_value
*ucontrol
)
1366 struct echoaudio
*chip
;
1368 chip
= snd_kcontrol_chip(kcontrol
);
1369 ucontrol
->value
.integer
.value
[0] =
1370 chip
->vmixer_gain
[ucontrol
->id
.index
/ num_pipes_out(chip
)]
1371 [ucontrol
->id
.index
% num_pipes_out(chip
)];
1375 static int snd_echo_vmixer_put(struct snd_kcontrol
*kcontrol
,
1376 struct snd_ctl_elem_value
*ucontrol
)
1378 struct echoaudio
*chip
;
1383 chip
= snd_kcontrol_chip(kcontrol
);
1384 out
= ucontrol
->id
.index
/ num_pipes_out(chip
);
1385 vch
= ucontrol
->id
.index
% num_pipes_out(chip
);
1386 gain
= ucontrol
->value
.integer
.value
[0];
1387 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1389 if (chip
->vmixer_gain
[out
][vch
] != ucontrol
->value
.integer
.value
[0]) {
1390 spin_lock_irq(&chip
->lock
);
1391 set_vmixer_gain(chip
, out
, vch
, ucontrol
->value
.integer
.value
[0]);
1392 update_vmixer_level(chip
);
1393 spin_unlock_irq(&chip
->lock
);
1399 static struct snd_kcontrol_new snd_echo_vmixer
= {
1400 .name
= "VMixer Volume",
1401 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1402 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1403 .info
= snd_echo_vmixer_info
,
1404 .get
= snd_echo_vmixer_get
,
1405 .put
= snd_echo_vmixer_put
,
1406 .tlv
= {.p
= db_scale_output_gain
},
1409 #endif /* ECHOCARD_HAS_VMIXER */
1413 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1415 /******************* Digital mode switch *******************/
1416 static int snd_echo_digital_mode_info(struct snd_kcontrol
*kcontrol
,
1417 struct snd_ctl_elem_info
*uinfo
)
1419 static char *names
[4] = {
1420 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1423 struct echoaudio
*chip
;
1425 chip
= snd_kcontrol_chip(kcontrol
);
1426 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1427 uinfo
->value
.enumerated
.items
= chip
->num_digital_modes
;
1429 if (uinfo
->value
.enumerated
.item
>= chip
->num_digital_modes
)
1430 uinfo
->value
.enumerated
.item
= chip
->num_digital_modes
- 1;
1431 strcpy(uinfo
->value
.enumerated
.name
, names
[
1432 chip
->digital_mode_list
[uinfo
->value
.enumerated
.item
]]);
1436 static int snd_echo_digital_mode_get(struct snd_kcontrol
*kcontrol
,
1437 struct snd_ctl_elem_value
*ucontrol
)
1439 struct echoaudio
*chip
;
1442 chip
= snd_kcontrol_chip(kcontrol
);
1443 mode
= chip
->digital_mode
;
1444 for (i
= chip
->num_digital_modes
- 1; i
>= 0; i
--)
1445 if (mode
== chip
->digital_mode_list
[i
]) {
1446 ucontrol
->value
.enumerated
.item
[0] = i
;
1452 static int snd_echo_digital_mode_put(struct snd_kcontrol
*kcontrol
,
1453 struct snd_ctl_elem_value
*ucontrol
)
1455 struct echoaudio
*chip
;
1457 unsigned short emode
, dmode
;
1460 chip
= snd_kcontrol_chip(kcontrol
);
1462 emode
= ucontrol
->value
.enumerated
.item
[0];
1463 if (emode
>= chip
->num_digital_modes
)
1465 dmode
= chip
->digital_mode_list
[emode
];
1467 if (dmode
!= chip
->digital_mode
) {
1468 /* mode_mutex is required to make this operation atomic wrt
1469 pcm_digital_*_open() and set_input_clock() functions. */
1470 mutex_lock(&chip
->mode_mutex
);
1472 /* Do not allow the user to change the digital mode when a pcm
1473 device is open because it also changes the number of channels
1474 and the allowed sample rates */
1475 if (atomic_read(&chip
->opencount
)) {
1478 changed
= set_digital_mode(chip
, dmode
);
1479 /* If we had to change the clock source, report it */
1480 if (changed
> 0 && chip
->clock_src_ctl
) {
1481 snd_ctl_notify(chip
->card
,
1482 SNDRV_CTL_EVENT_MASK_VALUE
,
1483 &chip
->clock_src_ctl
->id
);
1484 DE_ACT(("SDM() =%d\n", changed
));
1487 changed
= 1; /* No errors */
1489 mutex_unlock(&chip
->mode_mutex
);
1494 static struct snd_kcontrol_new snd_echo_digital_mode_switch
= {
1495 .name
= "Digital mode Switch",
1496 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1497 .info
= snd_echo_digital_mode_info
,
1498 .get
= snd_echo_digital_mode_get
,
1499 .put
= snd_echo_digital_mode_put
,
1502 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1506 #ifdef ECHOCARD_HAS_DIGITAL_IO
1508 /******************* S/PDIF mode switch *******************/
1509 static int snd_echo_spdif_mode_info(struct snd_kcontrol
*kcontrol
,
1510 struct snd_ctl_elem_info
*uinfo
)
1512 static char *names
[2] = {"Consumer", "Professional"};
1514 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1515 uinfo
->value
.enumerated
.items
= 2;
1517 if (uinfo
->value
.enumerated
.item
)
1518 uinfo
->value
.enumerated
.item
= 1;
1519 strcpy(uinfo
->value
.enumerated
.name
,
1520 names
[uinfo
->value
.enumerated
.item
]);
1524 static int snd_echo_spdif_mode_get(struct snd_kcontrol
*kcontrol
,
1525 struct snd_ctl_elem_value
*ucontrol
)
1527 struct echoaudio
*chip
;
1529 chip
= snd_kcontrol_chip(kcontrol
);
1530 ucontrol
->value
.enumerated
.item
[0] = !!chip
->professional_spdif
;
1534 static int snd_echo_spdif_mode_put(struct snd_kcontrol
*kcontrol
,
1535 struct snd_ctl_elem_value
*ucontrol
)
1537 struct echoaudio
*chip
;
1540 chip
= snd_kcontrol_chip(kcontrol
);
1541 mode
= !!ucontrol
->value
.enumerated
.item
[0];
1542 if (mode
!= chip
->professional_spdif
) {
1543 spin_lock_irq(&chip
->lock
);
1544 set_professional_spdif(chip
, mode
);
1545 spin_unlock_irq(&chip
->lock
);
1551 static struct snd_kcontrol_new snd_echo_spdif_mode_switch
= {
1552 .name
= "S/PDIF mode Switch",
1553 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1554 .info
= snd_echo_spdif_mode_info
,
1555 .get
= snd_echo_spdif_mode_get
,
1556 .put
= snd_echo_spdif_mode_put
,
1559 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1563 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1565 /******************* Select input clock source *******************/
1566 static int snd_echo_clock_source_info(struct snd_kcontrol
*kcontrol
,
1567 struct snd_ctl_elem_info
*uinfo
)
1569 static char *names
[8] = {
1570 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1573 struct echoaudio
*chip
;
1575 chip
= snd_kcontrol_chip(kcontrol
);
1576 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1577 uinfo
->value
.enumerated
.items
= chip
->num_clock_sources
;
1579 if (uinfo
->value
.enumerated
.item
>= chip
->num_clock_sources
)
1580 uinfo
->value
.enumerated
.item
= chip
->num_clock_sources
- 1;
1581 strcpy(uinfo
->value
.enumerated
.name
, names
[
1582 chip
->clock_source_list
[uinfo
->value
.enumerated
.item
]]);
1586 static int snd_echo_clock_source_get(struct snd_kcontrol
*kcontrol
,
1587 struct snd_ctl_elem_value
*ucontrol
)
1589 struct echoaudio
*chip
;
1592 chip
= snd_kcontrol_chip(kcontrol
);
1593 clock
= chip
->input_clock
;
1595 for (i
= 0; i
< chip
->num_clock_sources
; i
++)
1596 if (clock
== chip
->clock_source_list
[i
])
1597 ucontrol
->value
.enumerated
.item
[0] = i
;
1602 static int snd_echo_clock_source_put(struct snd_kcontrol
*kcontrol
,
1603 struct snd_ctl_elem_value
*ucontrol
)
1605 struct echoaudio
*chip
;
1607 unsigned int eclock
, dclock
;
1610 chip
= snd_kcontrol_chip(kcontrol
);
1611 eclock
= ucontrol
->value
.enumerated
.item
[0];
1612 if (eclock
>= chip
->input_clock_types
)
1614 dclock
= chip
->clock_source_list
[eclock
];
1615 if (chip
->input_clock
!= dclock
) {
1616 mutex_lock(&chip
->mode_mutex
);
1617 spin_lock_irq(&chip
->lock
);
1618 if ((changed
= set_input_clock(chip
, dclock
)) == 0)
1619 changed
= 1; /* no errors */
1620 spin_unlock_irq(&chip
->lock
);
1621 mutex_unlock(&chip
->mode_mutex
);
1625 DE_ACT(("seticlk val%d err 0x%x\n", dclock
, changed
));
1630 static struct snd_kcontrol_new snd_echo_clock_source_switch
= {
1631 .name
= "Sample Clock Source",
1632 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1633 .info
= snd_echo_clock_source_info
,
1634 .get
= snd_echo_clock_source_get
,
1635 .put
= snd_echo_clock_source_put
,
1638 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1642 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1644 /******************* Phantom power switch *******************/
1645 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1647 static int snd_echo_phantom_power_get(struct snd_kcontrol
*kcontrol
,
1648 struct snd_ctl_elem_value
*ucontrol
)
1650 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1652 ucontrol
->value
.integer
.value
[0] = chip
->phantom_power
;
1656 static int snd_echo_phantom_power_put(struct snd_kcontrol
*kcontrol
,
1657 struct snd_ctl_elem_value
*ucontrol
)
1659 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1660 int power
, changed
= 0;
1662 power
= !!ucontrol
->value
.integer
.value
[0];
1663 if (chip
->phantom_power
!= power
) {
1664 spin_lock_irq(&chip
->lock
);
1665 changed
= set_phantom_power(chip
, power
);
1666 spin_unlock_irq(&chip
->lock
);
1668 changed
= 1; /* no errors */
1673 static struct snd_kcontrol_new snd_echo_phantom_power_switch
= {
1674 .name
= "Phantom power Switch",
1675 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1676 .info
= snd_echo_phantom_power_info
,
1677 .get
= snd_echo_phantom_power_get
,
1678 .put
= snd_echo_phantom_power_put
,
1681 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1685 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1687 /******************* Digital input automute switch *******************/
1688 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1690 static int snd_echo_automute_get(struct snd_kcontrol
*kcontrol
,
1691 struct snd_ctl_elem_value
*ucontrol
)
1693 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1695 ucontrol
->value
.integer
.value
[0] = chip
->digital_in_automute
;
1699 static int snd_echo_automute_put(struct snd_kcontrol
*kcontrol
,
1700 struct snd_ctl_elem_value
*ucontrol
)
1702 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1703 int automute
, changed
= 0;
1705 automute
= !!ucontrol
->value
.integer
.value
[0];
1706 if (chip
->digital_in_automute
!= automute
) {
1707 spin_lock_irq(&chip
->lock
);
1708 changed
= set_input_auto_mute(chip
, automute
);
1709 spin_unlock_irq(&chip
->lock
);
1711 changed
= 1; /* no errors */
1716 static struct snd_kcontrol_new snd_echo_automute_switch
= {
1717 .name
= "Digital Capture Switch (automute)",
1718 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1719 .info
= snd_echo_automute_info
,
1720 .get
= snd_echo_automute_get
,
1721 .put
= snd_echo_automute_put
,
1724 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1728 /******************* VU-meters switch *******************/
1729 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1731 static int snd_echo_vumeters_switch_put(struct snd_kcontrol
*kcontrol
,
1732 struct snd_ctl_elem_value
*ucontrol
)
1734 struct echoaudio
*chip
;
1736 chip
= snd_kcontrol_chip(kcontrol
);
1737 spin_lock_irq(&chip
->lock
);
1738 set_meters_on(chip
, ucontrol
->value
.integer
.value
[0]);
1739 spin_unlock_irq(&chip
->lock
);
1743 static struct snd_kcontrol_new snd_echo_vumeters_switch
= {
1744 .name
= "VU-meters Switch",
1745 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1746 .access
= SNDRV_CTL_ELEM_ACCESS_WRITE
,
1747 .info
= snd_echo_vumeters_switch_info
,
1748 .put
= snd_echo_vumeters_switch_put
,
1753 /***** Read VU-meters (input, output, analog and digital together) *****/
1754 static int snd_echo_vumeters_info(struct snd_kcontrol
*kcontrol
,
1755 struct snd_ctl_elem_info
*uinfo
)
1757 struct echoaudio
*chip
;
1759 chip
= snd_kcontrol_chip(kcontrol
);
1760 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1762 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1763 uinfo
->value
.integer
.max
= 0;
1764 #ifdef ECHOCARD_HAS_VMIXER
1765 uinfo
->dimen
.d
[0] = 3; /* Out, In, Virt */
1767 uinfo
->dimen
.d
[0] = 2; /* Out, In */
1769 uinfo
->dimen
.d
[1] = 16; /* 16 channels */
1770 uinfo
->dimen
.d
[2] = 2; /* 0=level, 1=peak */
1774 static int snd_echo_vumeters_get(struct snd_kcontrol
*kcontrol
,
1775 struct snd_ctl_elem_value
*ucontrol
)
1777 struct echoaudio
*chip
;
1779 chip
= snd_kcontrol_chip(kcontrol
);
1780 get_audio_meters(chip
, ucontrol
->value
.integer
.value
);
1784 static struct snd_kcontrol_new snd_echo_vumeters
= {
1785 .name
= "VU-meters",
1786 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1787 .access
= SNDRV_CTL_ELEM_ACCESS_READ
|
1788 SNDRV_CTL_ELEM_ACCESS_VOLATILE
|
1789 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1790 .info
= snd_echo_vumeters_info
,
1791 .get
= snd_echo_vumeters_get
,
1792 .tlv
= {.p
= db_scale_output_gain
},
1797 /*** Channels info - it exports informations about the number of channels ***/
1798 static int snd_echo_channels_info_info(struct snd_kcontrol
*kcontrol
,
1799 struct snd_ctl_elem_info
*uinfo
)
1801 struct echoaudio
*chip
;
1803 chip
= snd_kcontrol_chip(kcontrol
);
1804 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1806 uinfo
->value
.integer
.min
= 0;
1807 uinfo
->value
.integer
.max
= 1 << ECHO_CLOCK_NUMBER
;
1811 static int snd_echo_channels_info_get(struct snd_kcontrol
*kcontrol
,
1812 struct snd_ctl_elem_value
*ucontrol
)
1814 struct echoaudio
*chip
;
1815 int detected
, clocks
, bit
, src
;
1817 chip
= snd_kcontrol_chip(kcontrol
);
1818 ucontrol
->value
.integer
.value
[0] = num_busses_in(chip
);
1819 ucontrol
->value
.integer
.value
[1] = num_analog_busses_in(chip
);
1820 ucontrol
->value
.integer
.value
[2] = num_busses_out(chip
);
1821 ucontrol
->value
.integer
.value
[3] = num_analog_busses_out(chip
);
1822 ucontrol
->value
.integer
.value
[4] = num_pipes_out(chip
);
1824 /* Compute the bitmask of the currently valid input clocks */
1825 detected
= detect_input_clocks(chip
);
1827 src
= chip
->num_clock_sources
- 1;
1828 for (bit
= ECHO_CLOCK_NUMBER
- 1; bit
>= 0; bit
--)
1829 if (detected
& (1 << bit
))
1830 for (; src
>= 0; src
--)
1831 if (bit
== chip
->clock_source_list
[src
]) {
1835 ucontrol
->value
.integer
.value
[5] = clocks
;
1840 static struct snd_kcontrol_new snd_echo_channels_info
= {
1841 .name
= "Channels info",
1842 .iface
= SNDRV_CTL_ELEM_IFACE_HWDEP
,
1843 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
1844 .info
= snd_echo_channels_info_info
,
1845 .get
= snd_echo_channels_info_get
,
1851 /******************************************************************************
1853 ******************************************************************************/
1855 static irqreturn_t
snd_echo_interrupt(int irq
, void *dev_id
)
1857 struct echoaudio
*chip
= dev_id
;
1858 struct snd_pcm_substream
*substream
;
1861 spin_lock(&chip
->lock
);
1862 st
= service_irq(chip
);
1864 spin_unlock(&chip
->lock
);
1867 /* The hardware doesn't tell us which substream caused the irq,
1868 thus we have to check all running substreams. */
1869 for (ss
= 0; ss
< DSP_MAXPIPES
; ss
++) {
1870 substream
= chip
->substream
[ss
];
1871 if (substream
&& ((struct audiopipe
*)substream
->runtime
->
1872 private_data
)->state
== PIPE_STATE_STARTED
) {
1873 period
= pcm_pointer(substream
) /
1874 substream
->runtime
->period_size
;
1875 if (period
!= chip
->last_period
[ss
]) {
1876 chip
->last_period
[ss
] = period
;
1877 spin_unlock(&chip
->lock
);
1878 snd_pcm_period_elapsed(substream
);
1879 spin_lock(&chip
->lock
);
1883 spin_unlock(&chip
->lock
);
1885 #ifdef ECHOCARD_HAS_MIDI
1886 if (st
> 0 && chip
->midi_in
) {
1887 snd_rawmidi_receive(chip
->midi_in
, chip
->midi_buffer
, st
);
1888 DE_MID(("rawmidi_iread=%d\n", st
));
1897 /******************************************************************************
1898 Module construction / destruction
1899 ******************************************************************************/
1901 static int snd_echo_free(struct echoaudio
*chip
)
1903 DE_INIT(("Stop DSP...\n"));
1904 if (chip
->comm_page
)
1905 rest_in_peace(chip
);
1906 DE_INIT(("Stopped.\n"));
1909 free_irq(chip
->irq
, chip
);
1911 if (chip
->comm_page
)
1912 snd_dma_free_pages(&chip
->commpage_dma_buf
);
1914 if (chip
->dsp_registers
)
1915 iounmap(chip
->dsp_registers
);
1918 release_and_free_resource(chip
->iores
);
1920 DE_INIT(("MMIO freed.\n"));
1922 pci_disable_device(chip
->pci
);
1924 /* release chip data */
1925 free_firmware_cache(chip
);
1927 DE_INIT(("Chip freed.\n"));
1933 static int snd_echo_dev_free(struct snd_device
*device
)
1935 struct echoaudio
*chip
= device
->device_data
;
1937 DE_INIT(("snd_echo_dev_free()...\n"));
1938 return snd_echo_free(chip
);
1943 /* <--snd_echo_probe() */
1944 static int snd_echo_create(struct snd_card
*card
,
1945 struct pci_dev
*pci
,
1946 struct echoaudio
**rchip
)
1948 struct echoaudio
*chip
;
1951 static struct snd_device_ops ops
= {
1952 .dev_free
= snd_echo_dev_free
,
1957 pci_write_config_byte(pci
, PCI_LATENCY_TIMER
, 0xC0);
1959 if ((err
= pci_enable_device(pci
)) < 0)
1961 pci_set_master(pci
);
1963 /* Allocate chip if needed */
1965 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
1967 pci_disable_device(pci
);
1970 DE_INIT(("chip=%p\n", chip
));
1971 spin_lock_init(&chip
->lock
);
1975 atomic_set(&chip
->opencount
, 0);
1976 mutex_init(&chip
->mode_mutex
);
1977 chip
->can_set_rate
= 1;
1979 /* If this was called from the resume function, chip is
1980 * already allocated and it contains current card settings.
1985 /* PCI resource allocation */
1986 chip
->dsp_registers_phys
= pci_resource_start(pci
, 0);
1987 sz
= pci_resource_len(pci
, 0);
1989 sz
= PAGE_SIZE
; /* We map only the required part */
1991 if ((chip
->iores
= request_mem_region(chip
->dsp_registers_phys
, sz
,
1992 ECHOCARD_NAME
)) == NULL
) {
1993 dev_err(chip
->card
->dev
, "cannot get memory region\n");
1994 snd_echo_free(chip
);
1997 chip
->dsp_registers
= (volatile u32 __iomem
*)
1998 ioremap_nocache(chip
->dsp_registers_phys
, sz
);
2000 if (request_irq(pci
->irq
, snd_echo_interrupt
, IRQF_SHARED
,
2001 KBUILD_MODNAME
, chip
)) {
2002 dev_err(chip
->card
->dev
, "cannot grab irq\n");
2003 snd_echo_free(chip
);
2006 chip
->irq
= pci
->irq
;
2007 DE_INIT(("pci=%p irq=%d subdev=%04x Init hardware...\n",
2008 chip
->pci
, chip
->irq
, chip
->pci
->subsystem_device
));
2010 /* Create the DSP comm page - this is the area of memory used for most
2011 of the communication with the DSP, which accesses it via bus mastering */
2012 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(chip
->pci
),
2013 sizeof(struct comm_page
),
2014 &chip
->commpage_dma_buf
) < 0) {
2015 dev_err(chip
->card
->dev
, "cannot allocate the comm page\n");
2016 snd_echo_free(chip
);
2019 chip
->comm_page_phys
= chip
->commpage_dma_buf
.addr
;
2020 chip
->comm_page
= (struct comm_page
*)chip
->commpage_dma_buf
.area
;
2022 err
= init_hw(chip
, chip
->pci
->device
, chip
->pci
->subsystem_device
);
2024 err
= set_mixer_defaults(chip
);
2026 DE_INIT(("init_hw err=%d\n", err
));
2027 snd_echo_free(chip
);
2030 DE_INIT(("Card init OK\n"));
2032 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
2033 snd_echo_free(chip
);
2044 static int snd_echo_probe(struct pci_dev
*pci
,
2045 const struct pci_device_id
*pci_id
)
2048 struct snd_card
*card
;
2049 struct echoaudio
*chip
;
2053 if (dev
>= SNDRV_CARDS
)
2060 DE_INIT(("Echoaudio driver starting...\n"));
2062 err
= snd_card_new(&pci
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
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 dev_err(chip
->card
->dev
, "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 dev_err(chip
->card
->dev
, "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 dev_info(card
->dev
, "Card registered: %s\n", card
->longname
);
2194 pci_set_drvdata(pci
, chip
);
2199 dev_err(card
->dev
, "new control error %d\n", err
);
2200 snd_card_free(card
);
2206 #if defined(CONFIG_PM_SLEEP)
2208 static int snd_echo_suspend(struct device
*dev
)
2210 struct pci_dev
*pci
= to_pci_dev(dev
);
2211 struct echoaudio
*chip
= dev_get_drvdata(dev
);
2213 DE_INIT(("suspend start\n"));
2214 snd_pcm_suspend_all(chip
->analog_pcm
);
2215 snd_pcm_suspend_all(chip
->digital_pcm
);
2217 #ifdef ECHOCARD_HAS_MIDI
2218 /* This call can sleep */
2220 snd_echo_midi_output_trigger(chip
->midi_out
, 0);
2222 spin_lock_irq(&chip
->lock
);
2223 if (wait_handshake(chip
)) {
2224 spin_unlock_irq(&chip
->lock
);
2227 clear_handshake(chip
);
2228 if (send_vector(chip
, DSP_VC_GO_COMATOSE
) < 0) {
2229 spin_unlock_irq(&chip
->lock
);
2232 spin_unlock_irq(&chip
->lock
);
2234 chip
->dsp_code
= NULL
;
2235 free_irq(chip
->irq
, chip
);
2237 pci_save_state(pci
);
2238 pci_disable_device(pci
);
2240 DE_INIT(("suspend done\n"));
2246 static int snd_echo_resume(struct device
*dev
)
2248 struct pci_dev
*pci
= to_pci_dev(dev
);
2249 struct echoaudio
*chip
= dev_get_drvdata(dev
);
2250 struct comm_page
*commpage
, *commpage_bak
;
2251 u32 pipe_alloc_mask
;
2254 DE_INIT(("resume start\n"));
2255 pci_restore_state(pci
);
2256 commpage_bak
= kmalloc(sizeof(struct echoaudio
), GFP_KERNEL
);
2257 if (commpage_bak
== NULL
)
2259 commpage
= chip
->comm_page
;
2260 memcpy(commpage_bak
, commpage
, sizeof(struct comm_page
));
2262 err
= init_hw(chip
, chip
->pci
->device
, chip
->pci
->subsystem_device
);
2264 kfree(commpage_bak
);
2265 DE_INIT(("resume init_hw err=%d\n", err
));
2266 snd_echo_free(chip
);
2269 DE_INIT(("resume init OK\n"));
2271 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2272 * restore_dsp_settings() fails.
2274 pipe_alloc_mask
= chip
->pipe_alloc_mask
;
2275 chip
->pipe_alloc_mask
= 0;
2276 err
= restore_dsp_rettings(chip
);
2277 chip
->pipe_alloc_mask
= pipe_alloc_mask
;
2279 kfree(commpage_bak
);
2282 DE_INIT(("resume restore OK\n"));
2284 memcpy(&commpage
->audio_format
, &commpage_bak
->audio_format
,
2285 sizeof(commpage
->audio_format
));
2286 memcpy(&commpage
->sglist_addr
, &commpage_bak
->sglist_addr
,
2287 sizeof(commpage
->sglist_addr
));
2288 memcpy(&commpage
->midi_output
, &commpage_bak
->midi_output
,
2289 sizeof(commpage
->midi_output
));
2290 kfree(commpage_bak
);
2292 if (request_irq(pci
->irq
, snd_echo_interrupt
, IRQF_SHARED
,
2293 KBUILD_MODNAME
, chip
)) {
2294 dev_err(chip
->card
->dev
, "cannot grab irq\n");
2295 snd_echo_free(chip
);
2298 chip
->irq
= pci
->irq
;
2299 DE_INIT(("resume irq=%d\n", chip
->irq
));
2301 #ifdef ECHOCARD_HAS_MIDI
2302 if (chip
->midi_input_enabled
)
2303 enable_midi_input(chip
, TRUE
);
2305 snd_echo_midi_output_trigger(chip
->midi_out
, 1);
2308 DE_INIT(("resume done\n"));
2312 static SIMPLE_DEV_PM_OPS(snd_echo_pm
, snd_echo_suspend
, snd_echo_resume
);
2313 #define SND_ECHO_PM_OPS &snd_echo_pm
2315 #define SND_ECHO_PM_OPS NULL
2316 #endif /* CONFIG_PM_SLEEP */
2319 static void snd_echo_remove(struct pci_dev
*pci
)
2321 struct echoaudio
*chip
;
2323 chip
= pci_get_drvdata(pci
);
2325 snd_card_free(chip
->card
);
2330 /******************************************************************************
2331 Everything starts and ends here
2332 ******************************************************************************/
2334 /* pci_driver definition */
2335 static struct pci_driver echo_driver
= {
2336 .name
= KBUILD_MODNAME
,
2337 .id_table
= snd_echo_ids
,
2338 .probe
= snd_echo_probe
,
2339 .remove
= snd_echo_remove
,
2341 .pm
= SND_ECHO_PM_OPS
,
2345 module_pci_driver(echo_driver
);