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 dev_dbg(chip
->card
->dev
,
52 "firmware requested: %s is cached\n",
53 card_fw
[fw_index
].data
);
54 *fw_entry
= chip
->fw_cache
[fw_index
];
59 dev_dbg(chip
->card
->dev
,
60 "firmware requested: %s\n", card_fw
[fw_index
].data
);
61 snprintf(name
, sizeof(name
), "ea/%s", card_fw
[fw_index
].data
);
62 err
= request_firmware(fw_entry
, name
, &chip
->pci
->dev
);
64 dev_err(chip
->card
->dev
,
65 "get_firmware(): Firmware not available (%d)\n", err
);
66 #ifdef CONFIG_PM_SLEEP
68 chip
->fw_cache
[fw_index
] = *fw_entry
;
75 static void free_firmware(const struct firmware
*fw_entry
,
76 struct echoaudio
*chip
)
78 #ifdef CONFIG_PM_SLEEP
79 dev_dbg(chip
->card
->dev
, "firmware not released (kept in cache)\n");
81 release_firmware(fw_entry
);
87 static void free_firmware_cache(struct echoaudio
*chip
)
89 #ifdef CONFIG_PM_SLEEP
92 for (i
= 0; i
< 8 ; i
++)
93 if (chip
->fw_cache
[i
]) {
94 release_firmware(chip
->fw_cache
[i
]);
95 dev_dbg(chip
->card
->dev
, "release_firmware(%d)\n", i
);
103 /******************************************************************************
105 ******************************************************************************/
107 static void audiopipe_free(struct snd_pcm_runtime
*runtime
)
109 struct audiopipe
*pipe
= runtime
->private_data
;
111 if (pipe
->sgpage
.area
)
112 snd_dma_free_pages(&pipe
->sgpage
);
118 static int hw_rule_capture_format_by_channels(struct snd_pcm_hw_params
*params
,
119 struct snd_pcm_hw_rule
*rule
)
121 struct snd_interval
*c
= hw_param_interval(params
,
122 SNDRV_PCM_HW_PARAM_CHANNELS
);
123 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
128 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
129 /* >=2 channels cannot be S32_BE */
131 fmt
.bits
[0] &= ~SNDRV_PCM_FMTBIT_S32_BE
;
132 return snd_mask_refine(f
, &fmt
);
135 /* > 2 channels cannot be U8 and S32_BE */
137 fmt
.bits
[0] &= ~(SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S32_BE
);
138 return snd_mask_refine(f
, &fmt
);
140 /* Mono is ok with any format */
146 static int hw_rule_capture_channels_by_format(struct snd_pcm_hw_params
*params
,
147 struct snd_pcm_hw_rule
*rule
)
149 struct snd_interval
*c
= hw_param_interval(params
,
150 SNDRV_PCM_HW_PARAM_CHANNELS
);
151 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
152 struct snd_interval ch
;
154 snd_interval_any(&ch
);
156 /* S32_BE is mono (and stereo) only */
157 if (f
->bits
[0] == SNDRV_PCM_FMTBIT_S32_BE
) {
159 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
165 return snd_interval_refine(c
, &ch
);
167 /* U8 can be only mono or stereo */
168 if (f
->bits
[0] == SNDRV_PCM_FMTBIT_U8
) {
172 return snd_interval_refine(c
, &ch
);
174 /* S16_LE, S24_3LE and S32_LE support any number of channels. */
180 static int hw_rule_playback_format_by_channels(struct snd_pcm_hw_params
*params
,
181 struct snd_pcm_hw_rule
*rule
)
183 struct snd_interval
*c
= hw_param_interval(params
,
184 SNDRV_PCM_HW_PARAM_CHANNELS
);
185 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
190 fmask
= fmt
.bits
[0] + ((u64
)fmt
.bits
[1] << 32);
192 /* >2 channels must be S16_LE, S24_3LE or S32_LE */
194 fmask
&= SNDRV_PCM_FMTBIT_S16_LE
|
195 SNDRV_PCM_FMTBIT_S24_3LE
|
196 SNDRV_PCM_FMTBIT_S32_LE
;
197 /* 1 channel must be S32_BE or S32_LE */
198 } else if (c
->max
== 1)
199 fmask
&= SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
;
200 #ifndef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
201 /* 2 channels cannot be S32_BE */
202 else if (c
->min
== 2 && c
->max
== 2)
203 fmask
&= ~SNDRV_PCM_FMTBIT_S32_BE
;
208 fmt
.bits
[0] &= (u32
)fmask
;
209 fmt
.bits
[1] &= (u32
)(fmask
>> 32);
210 return snd_mask_refine(f
, &fmt
);
215 static int hw_rule_playback_channels_by_format(struct snd_pcm_hw_params
*params
,
216 struct snd_pcm_hw_rule
*rule
)
218 struct snd_interval
*c
= hw_param_interval(params
,
219 SNDRV_PCM_HW_PARAM_CHANNELS
);
220 struct snd_mask
*f
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
221 struct snd_interval ch
;
224 snd_interval_any(&ch
);
226 fmask
= f
->bits
[0] + ((u64
)f
->bits
[1] << 32);
228 /* S32_BE is mono (and stereo) only */
229 if (fmask
== SNDRV_PCM_FMTBIT_S32_BE
) {
231 #ifdef ECHOCARD_HAS_STEREO_BIG_ENDIAN32
236 /* U8 is stereo only */
237 } else if (fmask
== SNDRV_PCM_FMTBIT_U8
)
239 /* S16_LE and S24_3LE must be at least stereo */
240 else if (!(fmask
& ~(SNDRV_PCM_FMTBIT_S16_LE
|
241 SNDRV_PCM_FMTBIT_S24_3LE
)))
246 return snd_interval_refine(c
, &ch
);
251 /* Since the sample rate is a global setting, do allow the user to change the
252 sample rate only if there is only one pcm device open. */
253 static int hw_rule_sample_rate(struct snd_pcm_hw_params
*params
,
254 struct snd_pcm_hw_rule
*rule
)
256 struct snd_interval
*rate
= hw_param_interval(params
,
257 SNDRV_PCM_HW_PARAM_RATE
);
258 struct echoaudio
*chip
= rule
->private;
259 struct snd_interval fixed
;
261 if (!chip
->can_set_rate
) {
262 snd_interval_any(&fixed
);
263 fixed
.min
= fixed
.max
= chip
->sample_rate
;
264 return snd_interval_refine(rate
, &fixed
);
270 static int pcm_open(struct snd_pcm_substream
*substream
,
271 signed char max_channels
)
273 struct echoaudio
*chip
;
274 struct snd_pcm_runtime
*runtime
;
275 struct audiopipe
*pipe
;
278 if (max_channels
<= 0)
281 chip
= snd_pcm_substream_chip(substream
);
282 runtime
= substream
->runtime
;
284 pipe
= kzalloc(sizeof(struct audiopipe
), GFP_KERNEL
);
287 pipe
->index
= -1; /* Not configured yet */
289 /* Set up hw capabilities and contraints */
290 memcpy(&pipe
->hw
, &pcm_hardware_skel
, sizeof(struct snd_pcm_hardware
));
291 dev_dbg(chip
->card
->dev
, "max_channels=%d\n", max_channels
);
292 pipe
->constr
.list
= channels_list
;
293 pipe
->constr
.mask
= 0;
294 for (i
= 0; channels_list
[i
] <= max_channels
; i
++);
295 pipe
->constr
.count
= i
;
296 if (pipe
->hw
.channels_max
> max_channels
)
297 pipe
->hw
.channels_max
= max_channels
;
298 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
) {
299 pipe
->hw
.rate_max
= 48000;
300 pipe
->hw
.rates
&= SNDRV_PCM_RATE_8000_48000
;
303 runtime
->hw
= pipe
->hw
;
304 runtime
->private_data
= pipe
;
305 runtime
->private_free
= audiopipe_free
;
306 snd_pcm_set_sync(substream
);
308 /* Only mono and any even number of channels are allowed */
309 if ((err
= snd_pcm_hw_constraint_list(runtime
, 0,
310 SNDRV_PCM_HW_PARAM_CHANNELS
,
314 /* All periods should have the same size */
315 if ((err
= snd_pcm_hw_constraint_integer(runtime
,
316 SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
319 /* The hw accesses memory in chunks 32 frames long and they should be
320 32-bytes-aligned. It's not a requirement, but it seems that IRQs are
321 generated with a resolution of 32 frames. Thus we need the following */
322 if ((err
= snd_pcm_hw_constraint_step(runtime
, 0,
323 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
326 if ((err
= snd_pcm_hw_constraint_step(runtime
, 0,
327 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
331 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
332 SNDRV_PCM_HW_PARAM_RATE
,
333 hw_rule_sample_rate
, chip
,
334 SNDRV_PCM_HW_PARAM_RATE
, -1)) < 0)
337 /* Finally allocate a page for the scatter-gather list */
338 if ((err
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
,
339 snd_dma_pci_data(chip
->pci
),
340 PAGE_SIZE
, &pipe
->sgpage
)) < 0) {
341 dev_err(chip
->card
->dev
, "s-g list allocation failed\n");
350 static int pcm_analog_in_open(struct snd_pcm_substream
*substream
)
352 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
355 if ((err
= pcm_open(substream
, num_analog_busses_in(chip
) -
356 substream
->number
)) < 0)
358 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
359 SNDRV_PCM_HW_PARAM_CHANNELS
,
360 hw_rule_capture_channels_by_format
, NULL
,
361 SNDRV_PCM_HW_PARAM_FORMAT
, -1)) < 0)
363 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
364 SNDRV_PCM_HW_PARAM_FORMAT
,
365 hw_rule_capture_format_by_channels
, NULL
,
366 SNDRV_PCM_HW_PARAM_CHANNELS
, -1)) < 0)
368 atomic_inc(&chip
->opencount
);
369 if (atomic_read(&chip
->opencount
) > 1 && chip
->rate_set
)
370 chip
->can_set_rate
=0;
371 dev_dbg(chip
->card
->dev
, "pcm_analog_in_open cs=%d oc=%d r=%d\n",
372 chip
->can_set_rate
, atomic_read(&chip
->opencount
),
379 static int pcm_analog_out_open(struct snd_pcm_substream
*substream
)
381 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
382 int max_channels
, err
;
384 #ifdef ECHOCARD_HAS_VMIXER
385 max_channels
= num_pipes_out(chip
);
387 max_channels
= num_analog_busses_out(chip
);
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 dev_dbg(chip
->card
->dev
, "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 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 max_channels
= num_digital_busses_out(chip
) - substream
->number
;
463 mutex_lock(&chip
->mode_mutex
);
464 if (chip
->digital_mode
== DIGITAL_MODE_ADAT
)
465 err
= pcm_open(substream
, max_channels
);
466 else /* If the card has ADAT, subtract the 6 channels
467 * that S/PDIF doesn't have
469 err
= pcm_open(substream
, max_channels
- ECHOCARD_HAS_ADAT
);
474 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
475 SNDRV_PCM_HW_PARAM_CHANNELS
,
476 hw_rule_playback_channels_by_format
,
477 NULL
, SNDRV_PCM_HW_PARAM_FORMAT
,
480 if ((err
= snd_pcm_hw_rule_add(substream
->runtime
, 0,
481 SNDRV_PCM_HW_PARAM_FORMAT
,
482 hw_rule_playback_format_by_channels
,
483 NULL
, SNDRV_PCM_HW_PARAM_CHANNELS
,
486 atomic_inc(&chip
->opencount
);
487 if (atomic_read(&chip
->opencount
) > 1 && chip
->rate_set
)
488 chip
->can_set_rate
=0;
490 mutex_unlock(&chip
->mode_mutex
);
494 #endif /* !ECHOCARD_HAS_VMIXER */
496 #endif /* ECHOCARD_HAS_DIGITAL_IO */
500 static int pcm_close(struct snd_pcm_substream
*substream
)
502 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
505 /* Nothing to do here. Audio is already off and pipe will be
506 * freed by its callback
509 atomic_dec(&chip
->opencount
);
510 oc
= atomic_read(&chip
->opencount
);
511 dev_dbg(chip
->card
->dev
, "pcm_close oc=%d cs=%d rs=%d\n", oc
,
512 chip
->can_set_rate
, chip
->rate_set
);
514 chip
->can_set_rate
= 1;
517 dev_dbg(chip
->card
->dev
, "pcm_close2 oc=%d cs=%d rs=%d\n", oc
,
518 chip
->can_set_rate
, chip
->rate_set
);
525 /* Channel allocation and scatter-gather list setup */
526 static int init_engine(struct snd_pcm_substream
*substream
,
527 struct snd_pcm_hw_params
*hw_params
,
528 int pipe_index
, int interleave
)
530 struct echoaudio
*chip
;
531 int err
, per
, rest
, page
, edge
, offs
;
532 struct audiopipe
*pipe
;
534 chip
= snd_pcm_substream_chip(substream
);
535 pipe
= (struct audiopipe
*) substream
->runtime
->private_data
;
537 /* Sets up che hardware. If it's already initialized, reset and
538 * redo with the new parameters
540 spin_lock_irq(&chip
->lock
);
541 if (pipe
->index
>= 0) {
542 dev_dbg(chip
->card
->dev
, "hwp_ie free(%d)\n", pipe
->index
);
543 err
= free_pipes(chip
, pipe
);
545 chip
->substream
[pipe
->index
] = NULL
;
548 err
= allocate_pipes(chip
, pipe
, pipe_index
, interleave
);
550 spin_unlock_irq(&chip
->lock
);
551 dev_err(chip
->card
->dev
, "allocate_pipes(%d) err=%d\n",
555 spin_unlock_irq(&chip
->lock
);
556 dev_dbg(chip
->card
->dev
, "allocate_pipes()=%d\n", pipe_index
);
558 dev_dbg(chip
->card
->dev
,
559 "pcm_hw_params (bufsize=%dB periods=%d persize=%dB)\n",
560 params_buffer_bytes(hw_params
), params_periods(hw_params
),
561 params_period_bytes(hw_params
));
562 err
= snd_pcm_lib_malloc_pages(substream
,
563 params_buffer_bytes(hw_params
));
565 dev_err(chip
->card
->dev
, "malloc_pages err=%d\n", err
);
566 spin_lock_irq(&chip
->lock
);
567 free_pipes(chip
, pipe
);
568 spin_unlock_irq(&chip
->lock
);
573 sglist_init(chip
, pipe
);
575 for (offs
= page
= per
= 0; offs
< params_buffer_bytes(hw_params
);
577 rest
= params_period_bytes(hw_params
);
578 if (offs
+ rest
> params_buffer_bytes(hw_params
))
579 rest
= params_buffer_bytes(hw_params
) - offs
;
582 addr
= snd_pcm_sgbuf_get_addr(substream
, offs
);
583 if (rest
<= edge
- offs
) {
584 sglist_add_mapping(chip
, pipe
, addr
, rest
);
585 sglist_add_irq(chip
, pipe
);
589 sglist_add_mapping(chip
, pipe
, addr
,
601 /* Close the ring buffer */
602 sglist_wrap(chip
, pipe
);
604 /* This stuff is used by the irq handler, so it must be
605 * initialized before chip->substream
607 chip
->last_period
[pipe_index
] = 0;
608 pipe
->last_counter
= 0;
611 chip
->substream
[pipe_index
] = substream
;
613 spin_lock_irq(&chip
->lock
);
614 set_sample_rate(chip
, hw_params
->rate_num
/ hw_params
->rate_den
);
615 spin_unlock_irq(&chip
->lock
);
621 static int pcm_analog_in_hw_params(struct snd_pcm_substream
*substream
,
622 struct snd_pcm_hw_params
*hw_params
)
624 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
626 return init_engine(substream
, hw_params
, px_analog_in(chip
) +
627 substream
->number
, params_channels(hw_params
));
632 static int pcm_analog_out_hw_params(struct snd_pcm_substream
*substream
,
633 struct snd_pcm_hw_params
*hw_params
)
635 return init_engine(substream
, hw_params
, substream
->number
,
636 params_channels(hw_params
));
641 #ifdef ECHOCARD_HAS_DIGITAL_IO
643 static int pcm_digital_in_hw_params(struct snd_pcm_substream
*substream
,
644 struct snd_pcm_hw_params
*hw_params
)
646 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
648 return init_engine(substream
, hw_params
, px_digital_in(chip
) +
649 substream
->number
, params_channels(hw_params
));
654 #ifndef ECHOCARD_HAS_VMIXER /* See the note in snd_echo_new_pcm() */
655 static int pcm_digital_out_hw_params(struct snd_pcm_substream
*substream
,
656 struct snd_pcm_hw_params
*hw_params
)
658 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
660 return init_engine(substream
, hw_params
, px_digital_out(chip
) +
661 substream
->number
, params_channels(hw_params
));
663 #endif /* !ECHOCARD_HAS_VMIXER */
665 #endif /* ECHOCARD_HAS_DIGITAL_IO */
669 static int pcm_hw_free(struct snd_pcm_substream
*substream
)
671 struct echoaudio
*chip
;
672 struct audiopipe
*pipe
;
674 chip
= snd_pcm_substream_chip(substream
);
675 pipe
= (struct audiopipe
*) substream
->runtime
->private_data
;
677 spin_lock_irq(&chip
->lock
);
678 if (pipe
->index
>= 0) {
679 dev_dbg(chip
->card
->dev
, "pcm_hw_free(%d)\n", pipe
->index
);
680 free_pipes(chip
, pipe
);
681 chip
->substream
[pipe
->index
] = NULL
;
684 spin_unlock_irq(&chip
->lock
);
686 snd_pcm_lib_free_pages(substream
);
692 static int pcm_prepare(struct snd_pcm_substream
*substream
)
694 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
695 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
696 struct audioformat format
;
697 int pipe_index
= ((struct audiopipe
*)runtime
->private_data
)->index
;
699 dev_dbg(chip
->card
->dev
, "Prepare rate=%d format=%d channels=%d\n",
700 runtime
->rate
, runtime
->format
, runtime
->channels
);
701 format
.interleave
= runtime
->channels
;
702 format
.data_are_bigendian
= 0;
703 format
.mono_to_stereo
= 0;
704 switch (runtime
->format
) {
705 case SNDRV_PCM_FORMAT_U8
:
706 format
.bits_per_sample
= 8;
708 case SNDRV_PCM_FORMAT_S16_LE
:
709 format
.bits_per_sample
= 16;
711 case SNDRV_PCM_FORMAT_S24_3LE
:
712 format
.bits_per_sample
= 24;
714 case SNDRV_PCM_FORMAT_S32_BE
:
715 format
.data_are_bigendian
= 1;
717 case SNDRV_PCM_FORMAT_S32_LE
:
718 format
.bits_per_sample
= 32;
721 dev_err(chip
->card
->dev
,
722 "Prepare error: unsupported format %d\n",
727 if (snd_BUG_ON(pipe_index
>= px_num(chip
)))
729 if (snd_BUG_ON(!is_pipe_allocated(chip
, pipe_index
)))
731 set_audio_format(chip
, pipe_index
, &format
);
737 static int pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
739 struct echoaudio
*chip
= snd_pcm_substream_chip(substream
);
740 struct audiopipe
*pipe
;
743 struct snd_pcm_substream
*s
;
745 snd_pcm_group_for_each_entry(s
, substream
) {
746 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
747 if (s
== chip
->substream
[i
]) {
748 channelmask
|= 1 << i
;
749 snd_pcm_trigger_done(s
, substream
);
754 spin_lock(&chip
->lock
);
756 case SNDRV_PCM_TRIGGER_RESUME
:
757 case SNDRV_PCM_TRIGGER_START
:
758 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
759 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
760 if (channelmask
& (1 << i
)) {
761 pipe
= chip
->substream
[i
]->runtime
->private_data
;
762 switch (pipe
->state
) {
763 case PIPE_STATE_STOPPED
:
764 chip
->last_period
[i
] = 0;
765 pipe
->last_counter
= 0;
767 *pipe
->dma_counter
= 0;
769 case PIPE_STATE_PAUSED
:
770 pipe
->state
= PIPE_STATE_STARTED
;
772 case PIPE_STATE_STARTED
:
777 err
= start_transport(chip
, channelmask
,
778 chip
->pipe_cyclic_mask
);
780 case SNDRV_PCM_TRIGGER_SUSPEND
:
781 case SNDRV_PCM_TRIGGER_STOP
:
782 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
783 if (channelmask
& (1 << i
)) {
784 pipe
= chip
->substream
[i
]->runtime
->private_data
;
785 pipe
->state
= PIPE_STATE_STOPPED
;
788 err
= stop_transport(chip
, channelmask
);
790 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
791 for (i
= 0; i
< DSP_MAXPIPES
; i
++) {
792 if (channelmask
& (1 << i
)) {
793 pipe
= chip
->substream
[i
]->runtime
->private_data
;
794 pipe
->state
= PIPE_STATE_PAUSED
;
797 err
= pause_transport(chip
, channelmask
);
802 spin_unlock(&chip
->lock
);
808 static snd_pcm_uframes_t
pcm_pointer(struct snd_pcm_substream
*substream
)
810 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
811 struct audiopipe
*pipe
= runtime
->private_data
;
812 size_t cnt
, bufsize
, pos
;
814 cnt
= le32_to_cpu(*pipe
->dma_counter
);
815 pipe
->position
+= cnt
- pipe
->last_counter
;
816 pipe
->last_counter
= cnt
;
817 bufsize
= substream
->runtime
->buffer_size
;
818 pos
= bytes_to_frames(substream
->runtime
, pipe
->position
);
820 while (pos
>= bufsize
) {
821 pipe
->position
-= frames_to_bytes(substream
->runtime
, bufsize
);
829 /* pcm *_ops structures */
830 static const struct snd_pcm_ops analog_playback_ops
= {
831 .open
= pcm_analog_out_open
,
833 .ioctl
= snd_pcm_lib_ioctl
,
834 .hw_params
= pcm_analog_out_hw_params
,
835 .hw_free
= pcm_hw_free
,
836 .prepare
= pcm_prepare
,
837 .trigger
= pcm_trigger
,
838 .pointer
= pcm_pointer
,
839 .page
= snd_pcm_sgbuf_ops_page
,
841 static const struct snd_pcm_ops analog_capture_ops
= {
842 .open
= pcm_analog_in_open
,
844 .ioctl
= snd_pcm_lib_ioctl
,
845 .hw_params
= pcm_analog_in_hw_params
,
846 .hw_free
= pcm_hw_free
,
847 .prepare
= pcm_prepare
,
848 .trigger
= pcm_trigger
,
849 .pointer
= pcm_pointer
,
850 .page
= snd_pcm_sgbuf_ops_page
,
852 #ifdef ECHOCARD_HAS_DIGITAL_IO
853 #ifndef ECHOCARD_HAS_VMIXER
854 static const struct snd_pcm_ops digital_playback_ops
= {
855 .open
= pcm_digital_out_open
,
857 .ioctl
= snd_pcm_lib_ioctl
,
858 .hw_params
= pcm_digital_out_hw_params
,
859 .hw_free
= pcm_hw_free
,
860 .prepare
= pcm_prepare
,
861 .trigger
= pcm_trigger
,
862 .pointer
= pcm_pointer
,
863 .page
= snd_pcm_sgbuf_ops_page
,
865 #endif /* !ECHOCARD_HAS_VMIXER */
866 static const struct snd_pcm_ops digital_capture_ops
= {
867 .open
= pcm_digital_in_open
,
869 .ioctl
= snd_pcm_lib_ioctl
,
870 .hw_params
= pcm_digital_in_hw_params
,
871 .hw_free
= pcm_hw_free
,
872 .prepare
= pcm_prepare
,
873 .trigger
= pcm_trigger
,
874 .pointer
= pcm_pointer
,
875 .page
= snd_pcm_sgbuf_ops_page
,
877 #endif /* ECHOCARD_HAS_DIGITAL_IO */
881 /* Preallocate memory only for the first substream because it's the most
884 static int snd_echo_preallocate_pages(struct snd_pcm
*pcm
, struct device
*dev
)
886 struct snd_pcm_substream
*ss
;
889 for (stream
= 0; stream
< 2; stream
++)
890 for (ss
= pcm
->streams
[stream
].substream
; ss
; ss
= ss
->next
) {
891 err
= snd_pcm_lib_preallocate_pages(ss
, SNDRV_DMA_TYPE_DEV_SG
,
893 ss
->number
? 0 : 128<<10,
903 /*<--snd_echo_probe() */
904 static int snd_echo_new_pcm(struct echoaudio
*chip
)
909 #ifdef ECHOCARD_HAS_VMIXER
910 /* This card has a Vmixer, that is there is no direct mapping from PCM
911 streams to physical outputs. The user can mix the streams as he wishes
912 via control interface and it's possible to send any stream to any
913 output, thus it makes no sense to keep analog and digital outputs
916 /* PCM#0 Virtual outputs and analog inputs */
917 if ((err
= snd_pcm_new(chip
->card
, "PCM", 0, num_pipes_out(chip
),
918 num_analog_busses_in(chip
), &pcm
)) < 0)
920 pcm
->private_data
= chip
;
921 chip
->analog_pcm
= pcm
;
922 strcpy(pcm
->name
, chip
->card
->shortname
);
923 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &analog_playback_ops
);
924 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &analog_capture_ops
);
925 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
928 #ifdef ECHOCARD_HAS_DIGITAL_IO
929 /* PCM#1 Digital inputs, no outputs */
930 if ((err
= snd_pcm_new(chip
->card
, "Digital PCM", 1, 0,
931 num_digital_busses_in(chip
), &pcm
)) < 0)
933 pcm
->private_data
= chip
;
934 chip
->digital_pcm
= pcm
;
935 strcpy(pcm
->name
, chip
->card
->shortname
);
936 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &digital_capture_ops
);
937 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
939 #endif /* ECHOCARD_HAS_DIGITAL_IO */
941 #else /* ECHOCARD_HAS_VMIXER */
943 /* The card can manage substreams formed by analog and digital channels
944 at the same time, but I prefer to keep analog and digital channels
945 separated, because that mixed thing is confusing and useless. So we
946 register two PCM devices: */
948 /* PCM#0 Analog i/o */
949 if ((err
= snd_pcm_new(chip
->card
, "Analog PCM", 0,
950 num_analog_busses_out(chip
),
951 num_analog_busses_in(chip
), &pcm
)) < 0)
953 pcm
->private_data
= chip
;
954 chip
->analog_pcm
= pcm
;
955 strcpy(pcm
->name
, chip
->card
->shortname
);
956 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &analog_playback_ops
);
957 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &analog_capture_ops
);
958 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
961 #ifdef ECHOCARD_HAS_DIGITAL_IO
962 /* PCM#1 Digital i/o */
963 if ((err
= snd_pcm_new(chip
->card
, "Digital PCM", 1,
964 num_digital_busses_out(chip
),
965 num_digital_busses_in(chip
), &pcm
)) < 0)
967 pcm
->private_data
= chip
;
968 chip
->digital_pcm
= pcm
;
969 strcpy(pcm
->name
, chip
->card
->shortname
);
970 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &digital_playback_ops
);
971 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &digital_capture_ops
);
972 if ((err
= snd_echo_preallocate_pages(pcm
, snd_dma_pci_data(chip
->pci
))) < 0)
974 #endif /* ECHOCARD_HAS_DIGITAL_IO */
976 #endif /* ECHOCARD_HAS_VMIXER */
984 /******************************************************************************
986 ******************************************************************************/
988 #if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
990 /******************* PCM output volume *******************/
991 static int snd_echo_output_gain_info(struct snd_kcontrol
*kcontrol
,
992 struct snd_ctl_elem_info
*uinfo
)
994 struct echoaudio
*chip
;
996 chip
= snd_kcontrol_chip(kcontrol
);
997 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
998 uinfo
->count
= num_busses_out(chip
);
999 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1000 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1004 static int snd_echo_output_gain_get(struct snd_kcontrol
*kcontrol
,
1005 struct snd_ctl_elem_value
*ucontrol
)
1007 struct echoaudio
*chip
;
1010 chip
= snd_kcontrol_chip(kcontrol
);
1011 for (c
= 0; c
< num_busses_out(chip
); c
++)
1012 ucontrol
->value
.integer
.value
[c
] = chip
->output_gain
[c
];
1016 static int snd_echo_output_gain_put(struct snd_kcontrol
*kcontrol
,
1017 struct snd_ctl_elem_value
*ucontrol
)
1019 struct echoaudio
*chip
;
1020 int c
, changed
, gain
;
1023 chip
= snd_kcontrol_chip(kcontrol
);
1024 spin_lock_irq(&chip
->lock
);
1025 for (c
= 0; c
< num_busses_out(chip
); c
++) {
1026 gain
= ucontrol
->value
.integer
.value
[c
];
1027 /* Ignore out of range values */
1028 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1030 if (chip
->output_gain
[c
] != gain
) {
1031 set_output_gain(chip
, c
, gain
);
1036 update_output_line_level(chip
);
1037 spin_unlock_irq(&chip
->lock
);
1041 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1042 /* On the Mia this one controls the line-out volume */
1043 static const struct snd_kcontrol_new snd_echo_line_output_gain
= {
1044 .name
= "Line Playback Volume",
1045 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1046 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1047 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1048 .info
= snd_echo_output_gain_info
,
1049 .get
= snd_echo_output_gain_get
,
1050 .put
= snd_echo_output_gain_put
,
1051 .tlv
= {.p
= db_scale_output_gain
},
1054 static const struct snd_kcontrol_new snd_echo_pcm_output_gain
= {
1055 .name
= "PCM Playback Volume",
1056 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1057 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| 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
},
1065 #endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1069 #ifdef ECHOCARD_HAS_INPUT_GAIN
1071 /******************* Analog input volume *******************/
1072 static int snd_echo_input_gain_info(struct snd_kcontrol
*kcontrol
,
1073 struct snd_ctl_elem_info
*uinfo
)
1075 struct echoaudio
*chip
;
1077 chip
= snd_kcontrol_chip(kcontrol
);
1078 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1079 uinfo
->count
= num_analog_busses_in(chip
);
1080 uinfo
->value
.integer
.min
= ECHOGAIN_MININP
;
1081 uinfo
->value
.integer
.max
= ECHOGAIN_MAXINP
;
1085 static int snd_echo_input_gain_get(struct snd_kcontrol
*kcontrol
,
1086 struct snd_ctl_elem_value
*ucontrol
)
1088 struct echoaudio
*chip
;
1091 chip
= snd_kcontrol_chip(kcontrol
);
1092 for (c
= 0; c
< num_analog_busses_in(chip
); c
++)
1093 ucontrol
->value
.integer
.value
[c
] = chip
->input_gain
[c
];
1097 static int snd_echo_input_gain_put(struct snd_kcontrol
*kcontrol
,
1098 struct snd_ctl_elem_value
*ucontrol
)
1100 struct echoaudio
*chip
;
1101 int c
, gain
, changed
;
1104 chip
= snd_kcontrol_chip(kcontrol
);
1105 spin_lock_irq(&chip
->lock
);
1106 for (c
= 0; c
< num_analog_busses_in(chip
); c
++) {
1107 gain
= ucontrol
->value
.integer
.value
[c
];
1108 /* Ignore out of range values */
1109 if (gain
< ECHOGAIN_MININP
|| gain
> ECHOGAIN_MAXINP
)
1111 if (chip
->input_gain
[c
] != gain
) {
1112 set_input_gain(chip
, c
, gain
);
1117 update_input_line_level(chip
);
1118 spin_unlock_irq(&chip
->lock
);
1122 static const DECLARE_TLV_DB_SCALE(db_scale_input_gain
, -2500, 50, 0);
1124 static const struct snd_kcontrol_new snd_echo_line_input_gain
= {
1125 .name
= "Line Capture Volume",
1126 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1127 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1128 .info
= snd_echo_input_gain_info
,
1129 .get
= snd_echo_input_gain_get
,
1130 .put
= snd_echo_input_gain_put
,
1131 .tlv
= {.p
= db_scale_input_gain
},
1134 #endif /* ECHOCARD_HAS_INPUT_GAIN */
1138 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
1140 /************ Analog output nominal level (+4dBu / -10dBV) ***************/
1141 static int snd_echo_output_nominal_info (struct snd_kcontrol
*kcontrol
,
1142 struct snd_ctl_elem_info
*uinfo
)
1144 struct echoaudio
*chip
;
1146 chip
= snd_kcontrol_chip(kcontrol
);
1147 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1148 uinfo
->count
= num_analog_busses_out(chip
);
1149 uinfo
->value
.integer
.min
= 0;
1150 uinfo
->value
.integer
.max
= 1;
1154 static int snd_echo_output_nominal_get(struct snd_kcontrol
*kcontrol
,
1155 struct snd_ctl_elem_value
*ucontrol
)
1157 struct echoaudio
*chip
;
1160 chip
= snd_kcontrol_chip(kcontrol
);
1161 for (c
= 0; c
< num_analog_busses_out(chip
); c
++)
1162 ucontrol
->value
.integer
.value
[c
] = chip
->nominal_level
[c
];
1166 static int snd_echo_output_nominal_put(struct snd_kcontrol
*kcontrol
,
1167 struct snd_ctl_elem_value
*ucontrol
)
1169 struct echoaudio
*chip
;
1173 chip
= snd_kcontrol_chip(kcontrol
);
1174 spin_lock_irq(&chip
->lock
);
1175 for (c
= 0; c
< num_analog_busses_out(chip
); c
++) {
1176 if (chip
->nominal_level
[c
] != ucontrol
->value
.integer
.value
[c
]) {
1177 set_nominal_level(chip
, c
,
1178 ucontrol
->value
.integer
.value
[c
]);
1183 update_output_line_level(chip
);
1184 spin_unlock_irq(&chip
->lock
);
1188 static const struct snd_kcontrol_new snd_echo_output_nominal_level
= {
1189 .name
= "Line Playback Switch (-10dBV)",
1190 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1191 .info
= snd_echo_output_nominal_info
,
1192 .get
= snd_echo_output_nominal_get
,
1193 .put
= snd_echo_output_nominal_put
,
1196 #endif /* ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL */
1200 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
1202 /*************** Analog input nominal level (+4dBu / -10dBV) ***************/
1203 static int snd_echo_input_nominal_info(struct snd_kcontrol
*kcontrol
,
1204 struct snd_ctl_elem_info
*uinfo
)
1206 struct echoaudio
*chip
;
1208 chip
= snd_kcontrol_chip(kcontrol
);
1209 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1210 uinfo
->count
= num_analog_busses_in(chip
);
1211 uinfo
->value
.integer
.min
= 0;
1212 uinfo
->value
.integer
.max
= 1;
1216 static int snd_echo_input_nominal_get(struct snd_kcontrol
*kcontrol
,
1217 struct snd_ctl_elem_value
*ucontrol
)
1219 struct echoaudio
*chip
;
1222 chip
= snd_kcontrol_chip(kcontrol
);
1223 for (c
= 0; c
< num_analog_busses_in(chip
); c
++)
1224 ucontrol
->value
.integer
.value
[c
] =
1225 chip
->nominal_level
[bx_analog_in(chip
) + c
];
1229 static int snd_echo_input_nominal_put(struct snd_kcontrol
*kcontrol
,
1230 struct snd_ctl_elem_value
*ucontrol
)
1232 struct echoaudio
*chip
;
1236 chip
= snd_kcontrol_chip(kcontrol
);
1237 spin_lock_irq(&chip
->lock
);
1238 for (c
= 0; c
< num_analog_busses_in(chip
); c
++) {
1239 if (chip
->nominal_level
[bx_analog_in(chip
) + c
] !=
1240 ucontrol
->value
.integer
.value
[c
]) {
1241 set_nominal_level(chip
, bx_analog_in(chip
) + c
,
1242 ucontrol
->value
.integer
.value
[c
]);
1247 update_output_line_level(chip
); /* "Output" is not a mistake
1250 spin_unlock_irq(&chip
->lock
);
1254 static const struct snd_kcontrol_new snd_echo_intput_nominal_level
= {
1255 .name
= "Line Capture Switch (-10dBV)",
1256 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1257 .info
= snd_echo_input_nominal_info
,
1258 .get
= snd_echo_input_nominal_get
,
1259 .put
= snd_echo_input_nominal_put
,
1262 #endif /* ECHOCARD_HAS_INPUT_NOMINAL_LEVEL */
1266 #ifdef ECHOCARD_HAS_MONITOR
1268 /******************* Monitor mixer *******************/
1269 static int snd_echo_mixer_info(struct snd_kcontrol
*kcontrol
,
1270 struct snd_ctl_elem_info
*uinfo
)
1272 struct echoaudio
*chip
;
1274 chip
= snd_kcontrol_chip(kcontrol
);
1275 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1277 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1278 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1279 uinfo
->dimen
.d
[0] = num_busses_out(chip
);
1280 uinfo
->dimen
.d
[1] = num_busses_in(chip
);
1284 static int snd_echo_mixer_get(struct snd_kcontrol
*kcontrol
,
1285 struct snd_ctl_elem_value
*ucontrol
)
1287 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1288 unsigned int out
= ucontrol
->id
.index
/ num_busses_in(chip
);
1289 unsigned int in
= ucontrol
->id
.index
% num_busses_in(chip
);
1291 if (out
>= ECHO_MAXAUDIOOUTPUTS
|| in
>= ECHO_MAXAUDIOINPUTS
)
1294 ucontrol
->value
.integer
.value
[0] = chip
->monitor_gain
[out
][in
];
1298 static int snd_echo_mixer_put(struct snd_kcontrol
*kcontrol
,
1299 struct snd_ctl_elem_value
*ucontrol
)
1301 struct echoaudio
*chip
;
1303 unsigned int out
, in
;
1306 chip
= snd_kcontrol_chip(kcontrol
);
1307 out
= ucontrol
->id
.index
/ num_busses_in(chip
);
1308 in
= ucontrol
->id
.index
% num_busses_in(chip
);
1309 if (out
>= ECHO_MAXAUDIOOUTPUTS
|| in
>= ECHO_MAXAUDIOINPUTS
)
1311 gain
= ucontrol
->value
.integer
.value
[0];
1312 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1314 if (chip
->monitor_gain
[out
][in
] != gain
) {
1315 spin_lock_irq(&chip
->lock
);
1316 set_monitor_gain(chip
, out
, in
, gain
);
1317 update_output_line_level(chip
);
1318 spin_unlock_irq(&chip
->lock
);
1324 static struct snd_kcontrol_new snd_echo_monitor_mixer
= {
1325 .name
= "Monitor Mixer Volume",
1326 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1327 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1328 .info
= snd_echo_mixer_info
,
1329 .get
= snd_echo_mixer_get
,
1330 .put
= snd_echo_mixer_put
,
1331 .tlv
= {.p
= db_scale_output_gain
},
1334 #endif /* ECHOCARD_HAS_MONITOR */
1338 #ifdef ECHOCARD_HAS_VMIXER
1340 /******************* Vmixer *******************/
1341 static int snd_echo_vmixer_info(struct snd_kcontrol
*kcontrol
,
1342 struct snd_ctl_elem_info
*uinfo
)
1344 struct echoaudio
*chip
;
1346 chip
= snd_kcontrol_chip(kcontrol
);
1347 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1349 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1350 uinfo
->value
.integer
.max
= ECHOGAIN_MAXOUT
;
1351 uinfo
->dimen
.d
[0] = num_busses_out(chip
);
1352 uinfo
->dimen
.d
[1] = num_pipes_out(chip
);
1356 static int snd_echo_vmixer_get(struct snd_kcontrol
*kcontrol
,
1357 struct snd_ctl_elem_value
*ucontrol
)
1359 struct echoaudio
*chip
;
1361 chip
= snd_kcontrol_chip(kcontrol
);
1362 ucontrol
->value
.integer
.value
[0] =
1363 chip
->vmixer_gain
[ucontrol
->id
.index
/ num_pipes_out(chip
)]
1364 [ucontrol
->id
.index
% num_pipes_out(chip
)];
1368 static int snd_echo_vmixer_put(struct snd_kcontrol
*kcontrol
,
1369 struct snd_ctl_elem_value
*ucontrol
)
1371 struct echoaudio
*chip
;
1376 chip
= snd_kcontrol_chip(kcontrol
);
1377 out
= ucontrol
->id
.index
/ num_pipes_out(chip
);
1378 vch
= ucontrol
->id
.index
% num_pipes_out(chip
);
1379 gain
= ucontrol
->value
.integer
.value
[0];
1380 if (gain
< ECHOGAIN_MINOUT
|| gain
> ECHOGAIN_MAXOUT
)
1382 if (chip
->vmixer_gain
[out
][vch
] != ucontrol
->value
.integer
.value
[0]) {
1383 spin_lock_irq(&chip
->lock
);
1384 set_vmixer_gain(chip
, out
, vch
, ucontrol
->value
.integer
.value
[0]);
1385 update_vmixer_level(chip
);
1386 spin_unlock_irq(&chip
->lock
);
1392 static struct snd_kcontrol_new snd_echo_vmixer
= {
1393 .name
= "VMixer Volume",
1394 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1395 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1396 .info
= snd_echo_vmixer_info
,
1397 .get
= snd_echo_vmixer_get
,
1398 .put
= snd_echo_vmixer_put
,
1399 .tlv
= {.p
= db_scale_output_gain
},
1402 #endif /* ECHOCARD_HAS_VMIXER */
1406 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
1408 /******************* Digital mode switch *******************/
1409 static int snd_echo_digital_mode_info(struct snd_kcontrol
*kcontrol
,
1410 struct snd_ctl_elem_info
*uinfo
)
1412 static const char * const names
[4] = {
1413 "S/PDIF Coaxial", "S/PDIF Optical", "ADAT Optical",
1416 struct echoaudio
*chip
;
1418 chip
= snd_kcontrol_chip(kcontrol
);
1419 return snd_ctl_enum_info(uinfo
, 1, chip
->num_digital_modes
, names
);
1422 static int snd_echo_digital_mode_get(struct snd_kcontrol
*kcontrol
,
1423 struct snd_ctl_elem_value
*ucontrol
)
1425 struct echoaudio
*chip
;
1428 chip
= snd_kcontrol_chip(kcontrol
);
1429 mode
= chip
->digital_mode
;
1430 for (i
= chip
->num_digital_modes
- 1; i
>= 0; i
--)
1431 if (mode
== chip
->digital_mode_list
[i
]) {
1432 ucontrol
->value
.enumerated
.item
[0] = i
;
1438 static int snd_echo_digital_mode_put(struct snd_kcontrol
*kcontrol
,
1439 struct snd_ctl_elem_value
*ucontrol
)
1441 struct echoaudio
*chip
;
1443 unsigned short emode
, dmode
;
1446 chip
= snd_kcontrol_chip(kcontrol
);
1448 emode
= ucontrol
->value
.enumerated
.item
[0];
1449 if (emode
>= chip
->num_digital_modes
)
1451 dmode
= chip
->digital_mode_list
[emode
];
1453 if (dmode
!= chip
->digital_mode
) {
1454 /* mode_mutex is required to make this operation atomic wrt
1455 pcm_digital_*_open() and set_input_clock() functions. */
1456 mutex_lock(&chip
->mode_mutex
);
1458 /* Do not allow the user to change the digital mode when a pcm
1459 device is open because it also changes the number of channels
1460 and the allowed sample rates */
1461 if (atomic_read(&chip
->opencount
)) {
1464 changed
= set_digital_mode(chip
, dmode
);
1465 /* If we had to change the clock source, report it */
1466 if (changed
> 0 && chip
->clock_src_ctl
) {
1467 snd_ctl_notify(chip
->card
,
1468 SNDRV_CTL_EVENT_MASK_VALUE
,
1469 &chip
->clock_src_ctl
->id
);
1470 dev_dbg(chip
->card
->dev
,
1471 "SDM() =%d\n", changed
);
1474 changed
= 1; /* No errors */
1476 mutex_unlock(&chip
->mode_mutex
);
1481 static const struct snd_kcontrol_new snd_echo_digital_mode_switch
= {
1482 .name
= "Digital mode Switch",
1483 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1484 .info
= snd_echo_digital_mode_info
,
1485 .get
= snd_echo_digital_mode_get
,
1486 .put
= snd_echo_digital_mode_put
,
1489 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
1493 #ifdef ECHOCARD_HAS_DIGITAL_IO
1495 /******************* S/PDIF mode switch *******************/
1496 static int snd_echo_spdif_mode_info(struct snd_kcontrol
*kcontrol
,
1497 struct snd_ctl_elem_info
*uinfo
)
1499 static const char * const names
[2] = {"Consumer", "Professional"};
1501 return snd_ctl_enum_info(uinfo
, 1, 2, names
);
1504 static int snd_echo_spdif_mode_get(struct snd_kcontrol
*kcontrol
,
1505 struct snd_ctl_elem_value
*ucontrol
)
1507 struct echoaudio
*chip
;
1509 chip
= snd_kcontrol_chip(kcontrol
);
1510 ucontrol
->value
.enumerated
.item
[0] = !!chip
->professional_spdif
;
1514 static int snd_echo_spdif_mode_put(struct snd_kcontrol
*kcontrol
,
1515 struct snd_ctl_elem_value
*ucontrol
)
1517 struct echoaudio
*chip
;
1520 chip
= snd_kcontrol_chip(kcontrol
);
1521 mode
= !!ucontrol
->value
.enumerated
.item
[0];
1522 if (mode
!= chip
->professional_spdif
) {
1523 spin_lock_irq(&chip
->lock
);
1524 set_professional_spdif(chip
, mode
);
1525 spin_unlock_irq(&chip
->lock
);
1531 static const struct snd_kcontrol_new snd_echo_spdif_mode_switch
= {
1532 .name
= "S/PDIF mode Switch",
1533 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1534 .info
= snd_echo_spdif_mode_info
,
1535 .get
= snd_echo_spdif_mode_get
,
1536 .put
= snd_echo_spdif_mode_put
,
1539 #endif /* ECHOCARD_HAS_DIGITAL_IO */
1543 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
1545 /******************* Select input clock source *******************/
1546 static int snd_echo_clock_source_info(struct snd_kcontrol
*kcontrol
,
1547 struct snd_ctl_elem_info
*uinfo
)
1549 static const char * const names
[8] = {
1550 "Internal", "Word", "Super", "S/PDIF", "ADAT", "ESync",
1553 struct echoaudio
*chip
;
1555 chip
= snd_kcontrol_chip(kcontrol
);
1556 return snd_ctl_enum_info(uinfo
, 1, chip
->num_clock_sources
, names
);
1559 static int snd_echo_clock_source_get(struct snd_kcontrol
*kcontrol
,
1560 struct snd_ctl_elem_value
*ucontrol
)
1562 struct echoaudio
*chip
;
1565 chip
= snd_kcontrol_chip(kcontrol
);
1566 clock
= chip
->input_clock
;
1568 for (i
= 0; i
< chip
->num_clock_sources
; i
++)
1569 if (clock
== chip
->clock_source_list
[i
])
1570 ucontrol
->value
.enumerated
.item
[0] = i
;
1575 static int snd_echo_clock_source_put(struct snd_kcontrol
*kcontrol
,
1576 struct snd_ctl_elem_value
*ucontrol
)
1578 struct echoaudio
*chip
;
1580 unsigned int eclock
, dclock
;
1583 chip
= snd_kcontrol_chip(kcontrol
);
1584 eclock
= ucontrol
->value
.enumerated
.item
[0];
1585 if (eclock
>= chip
->input_clock_types
)
1587 dclock
= chip
->clock_source_list
[eclock
];
1588 if (chip
->input_clock
!= dclock
) {
1589 mutex_lock(&chip
->mode_mutex
);
1590 spin_lock_irq(&chip
->lock
);
1591 if ((changed
= set_input_clock(chip
, dclock
)) == 0)
1592 changed
= 1; /* no errors */
1593 spin_unlock_irq(&chip
->lock
);
1594 mutex_unlock(&chip
->mode_mutex
);
1598 dev_dbg(chip
->card
->dev
,
1599 "seticlk val%d err 0x%x\n", dclock
, changed
);
1604 static const struct snd_kcontrol_new snd_echo_clock_source_switch
= {
1605 .name
= "Sample Clock Source",
1606 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
1607 .info
= snd_echo_clock_source_info
,
1608 .get
= snd_echo_clock_source_get
,
1609 .put
= snd_echo_clock_source_put
,
1612 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
1616 #ifdef ECHOCARD_HAS_PHANTOM_POWER
1618 /******************* Phantom power switch *******************/
1619 #define snd_echo_phantom_power_info snd_ctl_boolean_mono_info
1621 static int snd_echo_phantom_power_get(struct snd_kcontrol
*kcontrol
,
1622 struct snd_ctl_elem_value
*ucontrol
)
1624 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1626 ucontrol
->value
.integer
.value
[0] = chip
->phantom_power
;
1630 static int snd_echo_phantom_power_put(struct snd_kcontrol
*kcontrol
,
1631 struct snd_ctl_elem_value
*ucontrol
)
1633 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1634 int power
, changed
= 0;
1636 power
= !!ucontrol
->value
.integer
.value
[0];
1637 if (chip
->phantom_power
!= power
) {
1638 spin_lock_irq(&chip
->lock
);
1639 changed
= set_phantom_power(chip
, power
);
1640 spin_unlock_irq(&chip
->lock
);
1642 changed
= 1; /* no errors */
1647 static const struct snd_kcontrol_new snd_echo_phantom_power_switch
= {
1648 .name
= "Phantom power Switch",
1649 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1650 .info
= snd_echo_phantom_power_info
,
1651 .get
= snd_echo_phantom_power_get
,
1652 .put
= snd_echo_phantom_power_put
,
1655 #endif /* ECHOCARD_HAS_PHANTOM_POWER */
1659 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
1661 /******************* Digital input automute switch *******************/
1662 #define snd_echo_automute_info snd_ctl_boolean_mono_info
1664 static int snd_echo_automute_get(struct snd_kcontrol
*kcontrol
,
1665 struct snd_ctl_elem_value
*ucontrol
)
1667 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1669 ucontrol
->value
.integer
.value
[0] = chip
->digital_in_automute
;
1673 static int snd_echo_automute_put(struct snd_kcontrol
*kcontrol
,
1674 struct snd_ctl_elem_value
*ucontrol
)
1676 struct echoaudio
*chip
= snd_kcontrol_chip(kcontrol
);
1677 int automute
, changed
= 0;
1679 automute
= !!ucontrol
->value
.integer
.value
[0];
1680 if (chip
->digital_in_automute
!= automute
) {
1681 spin_lock_irq(&chip
->lock
);
1682 changed
= set_input_auto_mute(chip
, automute
);
1683 spin_unlock_irq(&chip
->lock
);
1685 changed
= 1; /* no errors */
1690 static const struct snd_kcontrol_new snd_echo_automute_switch
= {
1691 .name
= "Digital Capture Switch (automute)",
1692 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1693 .info
= snd_echo_automute_info
,
1694 .get
= snd_echo_automute_get
,
1695 .put
= snd_echo_automute_put
,
1698 #endif /* ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE */
1702 /******************* VU-meters switch *******************/
1703 #define snd_echo_vumeters_switch_info snd_ctl_boolean_mono_info
1705 static int snd_echo_vumeters_switch_put(struct snd_kcontrol
*kcontrol
,
1706 struct snd_ctl_elem_value
*ucontrol
)
1708 struct echoaudio
*chip
;
1710 chip
= snd_kcontrol_chip(kcontrol
);
1711 spin_lock_irq(&chip
->lock
);
1712 set_meters_on(chip
, ucontrol
->value
.integer
.value
[0]);
1713 spin_unlock_irq(&chip
->lock
);
1717 static const struct snd_kcontrol_new snd_echo_vumeters_switch
= {
1718 .name
= "VU-meters Switch",
1719 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
1720 .access
= SNDRV_CTL_ELEM_ACCESS_WRITE
,
1721 .info
= snd_echo_vumeters_switch_info
,
1722 .put
= snd_echo_vumeters_switch_put
,
1727 /***** Read VU-meters (input, output, analog and digital together) *****/
1728 static int snd_echo_vumeters_info(struct snd_kcontrol
*kcontrol
,
1729 struct snd_ctl_elem_info
*uinfo
)
1731 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1733 uinfo
->value
.integer
.min
= ECHOGAIN_MINOUT
;
1734 uinfo
->value
.integer
.max
= 0;
1735 #ifdef ECHOCARD_HAS_VMIXER
1736 uinfo
->dimen
.d
[0] = 3; /* Out, In, Virt */
1738 uinfo
->dimen
.d
[0] = 2; /* Out, In */
1740 uinfo
->dimen
.d
[1] = 16; /* 16 channels */
1741 uinfo
->dimen
.d
[2] = 2; /* 0=level, 1=peak */
1745 static int snd_echo_vumeters_get(struct snd_kcontrol
*kcontrol
,
1746 struct snd_ctl_elem_value
*ucontrol
)
1748 struct echoaudio
*chip
;
1750 chip
= snd_kcontrol_chip(kcontrol
);
1751 get_audio_meters(chip
, ucontrol
->value
.integer
.value
);
1755 static const struct snd_kcontrol_new snd_echo_vumeters
= {
1756 .name
= "VU-meters",
1757 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1758 .access
= SNDRV_CTL_ELEM_ACCESS_READ
|
1759 SNDRV_CTL_ELEM_ACCESS_VOLATILE
|
1760 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
1761 .info
= snd_echo_vumeters_info
,
1762 .get
= snd_echo_vumeters_get
,
1763 .tlv
= {.p
= db_scale_output_gain
},
1768 /*** Channels info - it exports informations about the number of channels ***/
1769 static int snd_echo_channels_info_info(struct snd_kcontrol
*kcontrol
,
1770 struct snd_ctl_elem_info
*uinfo
)
1772 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1774 uinfo
->value
.integer
.min
= 0;
1775 uinfo
->value
.integer
.max
= 1 << ECHO_CLOCK_NUMBER
;
1779 static int snd_echo_channels_info_get(struct snd_kcontrol
*kcontrol
,
1780 struct snd_ctl_elem_value
*ucontrol
)
1782 struct echoaudio
*chip
;
1783 int detected
, clocks
, bit
, src
;
1785 chip
= snd_kcontrol_chip(kcontrol
);
1786 ucontrol
->value
.integer
.value
[0] = num_busses_in(chip
);
1787 ucontrol
->value
.integer
.value
[1] = num_analog_busses_in(chip
);
1788 ucontrol
->value
.integer
.value
[2] = num_busses_out(chip
);
1789 ucontrol
->value
.integer
.value
[3] = num_analog_busses_out(chip
);
1790 ucontrol
->value
.integer
.value
[4] = num_pipes_out(chip
);
1792 /* Compute the bitmask of the currently valid input clocks */
1793 detected
= detect_input_clocks(chip
);
1795 src
= chip
->num_clock_sources
- 1;
1796 for (bit
= ECHO_CLOCK_NUMBER
- 1; bit
>= 0; bit
--)
1797 if (detected
& (1 << bit
))
1798 for (; src
>= 0; src
--)
1799 if (bit
== chip
->clock_source_list
[src
]) {
1803 ucontrol
->value
.integer
.value
[5] = clocks
;
1808 static const struct snd_kcontrol_new snd_echo_channels_info
= {
1809 .name
= "Channels info",
1810 .iface
= SNDRV_CTL_ELEM_IFACE_HWDEP
,
1811 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
1812 .info
= snd_echo_channels_info_info
,
1813 .get
= snd_echo_channels_info_get
,
1819 /******************************************************************************
1821 ******************************************************************************/
1823 static irqreturn_t
snd_echo_interrupt(int irq
, void *dev_id
)
1825 struct echoaudio
*chip
= dev_id
;
1826 struct snd_pcm_substream
*substream
;
1829 spin_lock(&chip
->lock
);
1830 st
= service_irq(chip
);
1832 spin_unlock(&chip
->lock
);
1835 /* The hardware doesn't tell us which substream caused the irq,
1836 thus we have to check all running substreams. */
1837 for (ss
= 0; ss
< DSP_MAXPIPES
; ss
++) {
1838 substream
= chip
->substream
[ss
];
1839 if (substream
&& ((struct audiopipe
*)substream
->runtime
->
1840 private_data
)->state
== PIPE_STATE_STARTED
) {
1841 period
= pcm_pointer(substream
) /
1842 substream
->runtime
->period_size
;
1843 if (period
!= chip
->last_period
[ss
]) {
1844 chip
->last_period
[ss
] = period
;
1845 spin_unlock(&chip
->lock
);
1846 snd_pcm_period_elapsed(substream
);
1847 spin_lock(&chip
->lock
);
1851 spin_unlock(&chip
->lock
);
1853 #ifdef ECHOCARD_HAS_MIDI
1854 if (st
> 0 && chip
->midi_in
) {
1855 snd_rawmidi_receive(chip
->midi_in
, chip
->midi_buffer
, st
);
1856 dev_dbg(chip
->card
->dev
, "rawmidi_iread=%d\n", st
);
1865 /******************************************************************************
1866 Module construction / destruction
1867 ******************************************************************************/
1869 static int snd_echo_free(struct echoaudio
*chip
)
1871 if (chip
->comm_page
)
1872 rest_in_peace(chip
);
1875 free_irq(chip
->irq
, chip
);
1877 if (chip
->comm_page
)
1878 snd_dma_free_pages(&chip
->commpage_dma_buf
);
1880 iounmap(chip
->dsp_registers
);
1881 release_and_free_resource(chip
->iores
);
1882 pci_disable_device(chip
->pci
);
1884 /* release chip data */
1885 free_firmware_cache(chip
);
1892 static int snd_echo_dev_free(struct snd_device
*device
)
1894 struct echoaudio
*chip
= device
->device_data
;
1896 return snd_echo_free(chip
);
1901 /* <--snd_echo_probe() */
1902 static int snd_echo_create(struct snd_card
*card
,
1903 struct pci_dev
*pci
,
1904 struct echoaudio
**rchip
)
1906 struct echoaudio
*chip
;
1909 static struct snd_device_ops ops
= {
1910 .dev_free
= snd_echo_dev_free
,
1915 pci_write_config_byte(pci
, PCI_LATENCY_TIMER
, 0xC0);
1917 if ((err
= pci_enable_device(pci
)) < 0)
1919 pci_set_master(pci
);
1921 /* Allocate chip if needed */
1923 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
1925 pci_disable_device(pci
);
1928 dev_dbg(card
->dev
, "chip=%p\n", chip
);
1929 spin_lock_init(&chip
->lock
);
1933 atomic_set(&chip
->opencount
, 0);
1934 mutex_init(&chip
->mode_mutex
);
1935 chip
->can_set_rate
= 1;
1937 /* If this was called from the resume function, chip is
1938 * already allocated and it contains current card settings.
1943 /* PCI resource allocation */
1944 chip
->dsp_registers_phys
= pci_resource_start(pci
, 0);
1945 sz
= pci_resource_len(pci
, 0);
1947 sz
= PAGE_SIZE
; /* We map only the required part */
1949 if ((chip
->iores
= request_mem_region(chip
->dsp_registers_phys
, sz
,
1950 ECHOCARD_NAME
)) == NULL
) {
1951 dev_err(chip
->card
->dev
, "cannot get memory region\n");
1952 snd_echo_free(chip
);
1955 chip
->dsp_registers
= (volatile u32 __iomem
*)
1956 ioremap_nocache(chip
->dsp_registers_phys
, sz
);
1957 if (!chip
->dsp_registers
) {
1958 dev_err(chip
->card
->dev
, "ioremap failed\n");
1959 snd_echo_free(chip
);
1963 if (request_irq(pci
->irq
, snd_echo_interrupt
, IRQF_SHARED
,
1964 KBUILD_MODNAME
, chip
)) {
1965 dev_err(chip
->card
->dev
, "cannot grab irq\n");
1966 snd_echo_free(chip
);
1969 chip
->irq
= pci
->irq
;
1970 dev_dbg(card
->dev
, "pci=%p irq=%d subdev=%04x Init hardware...\n",
1971 chip
->pci
, chip
->irq
, chip
->pci
->subsystem_device
);
1973 /* Create the DSP comm page - this is the area of memory used for most
1974 of the communication with the DSP, which accesses it via bus mastering */
1975 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(chip
->pci
),
1976 sizeof(struct comm_page
),
1977 &chip
->commpage_dma_buf
) < 0) {
1978 dev_err(chip
->card
->dev
, "cannot allocate the comm page\n");
1979 snd_echo_free(chip
);
1982 chip
->comm_page_phys
= chip
->commpage_dma_buf
.addr
;
1983 chip
->comm_page
= (struct comm_page
*)chip
->commpage_dma_buf
.area
;
1985 err
= init_hw(chip
, chip
->pci
->device
, chip
->pci
->subsystem_device
);
1987 err
= set_mixer_defaults(chip
);
1989 dev_err(card
->dev
, "init_hw err=%d\n", err
);
1990 snd_echo_free(chip
);
1994 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
1995 snd_echo_free(chip
);
2006 static int snd_echo_probe(struct pci_dev
*pci
,
2007 const struct pci_device_id
*pci_id
)
2010 struct snd_card
*card
;
2011 struct echoaudio
*chip
;
2015 if (dev
>= SNDRV_CARDS
)
2023 err
= snd_card_new(&pci
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
2028 chip
= NULL
; /* Tells snd_echo_create to allocate chip */
2029 if ((err
= snd_echo_create(card
, pci
, &chip
)) < 0) {
2030 snd_card_free(card
);
2034 strcpy(card
->driver
, "Echo_" ECHOCARD_NAME
);
2035 strcpy(card
->shortname
, chip
->card_name
);
2038 if (pci_id
->device
== 0x3410)
2041 sprintf(card
->longname
, "%s rev.%d (DSP%s) at 0x%lx irq %i",
2042 card
->shortname
, pci_id
->subdevice
& 0x000f, dsp
,
2043 chip
->dsp_registers_phys
, chip
->irq
);
2045 if ((err
= snd_echo_new_pcm(chip
)) < 0) {
2046 dev_err(chip
->card
->dev
, "new pcm error %d\n", err
);
2047 snd_card_free(card
);
2051 #ifdef ECHOCARD_HAS_MIDI
2052 if (chip
->has_midi
) { /* Some Mia's do not have midi */
2053 if ((err
= snd_echo_midi_create(card
, chip
)) < 0) {
2054 dev_err(chip
->card
->dev
, "new midi error %d\n", err
);
2055 snd_card_free(card
);
2061 #ifdef ECHOCARD_HAS_VMIXER
2062 snd_echo_vmixer
.count
= num_pipes_out(chip
) * num_busses_out(chip
);
2063 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vmixer
, chip
))) < 0)
2065 #ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2066 err
= snd_ctl_add(chip
->card
,
2067 snd_ctl_new1(&snd_echo_line_output_gain
, chip
));
2071 #else /* ECHOCARD_HAS_VMIXER */
2072 err
= snd_ctl_add(chip
->card
,
2073 snd_ctl_new1(&snd_echo_pcm_output_gain
, chip
));
2076 #endif /* ECHOCARD_HAS_VMIXER */
2078 #ifdef ECHOCARD_HAS_INPUT_GAIN
2079 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_line_input_gain
, chip
))) < 0)
2083 #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL
2084 if (!chip
->hasnt_input_nominal_level
)
2085 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_intput_nominal_level
, chip
))) < 0)
2089 #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL
2090 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_output_nominal_level
, chip
))) < 0)
2094 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vumeters_switch
, chip
))) < 0)
2097 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_vumeters
, chip
))) < 0)
2100 #ifdef ECHOCARD_HAS_MONITOR
2101 snd_echo_monitor_mixer
.count
= num_busses_in(chip
) * num_busses_out(chip
);
2102 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_monitor_mixer
, chip
))) < 0)
2106 #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE
2107 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_automute_switch
, chip
))) < 0)
2111 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_channels_info
, chip
))) < 0)
2114 #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
2115 /* Creates a list of available digital modes */
2116 chip
->num_digital_modes
= 0;
2117 for (i
= 0; i
< 6; i
++)
2118 if (chip
->digital_modes
& (1 << i
))
2119 chip
->digital_mode_list
[chip
->num_digital_modes
++] = i
;
2121 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_digital_mode_switch
, chip
))) < 0)
2123 #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */
2125 #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
2126 /* Creates a list of available clock sources */
2127 chip
->num_clock_sources
= 0;
2128 for (i
= 0; i
< 10; i
++)
2129 if (chip
->input_clock_types
& (1 << i
))
2130 chip
->clock_source_list
[chip
->num_clock_sources
++] = i
;
2132 if (chip
->num_clock_sources
> 1) {
2133 chip
->clock_src_ctl
= snd_ctl_new1(&snd_echo_clock_source_switch
, chip
);
2134 if ((err
= snd_ctl_add(chip
->card
, chip
->clock_src_ctl
)) < 0)
2137 #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */
2139 #ifdef ECHOCARD_HAS_DIGITAL_IO
2140 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_spdif_mode_switch
, chip
))) < 0)
2144 #ifdef ECHOCARD_HAS_PHANTOM_POWER
2145 if (chip
->has_phantom_power
)
2146 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_echo_phantom_power_switch
, chip
))) < 0)
2150 err
= snd_card_register(card
);
2153 dev_info(card
->dev
, "Card registered: %s\n", card
->longname
);
2155 pci_set_drvdata(pci
, chip
);
2160 dev_err(card
->dev
, "new control error %d\n", err
);
2161 snd_card_free(card
);
2167 #if defined(CONFIG_PM_SLEEP)
2169 static int snd_echo_suspend(struct device
*dev
)
2171 struct echoaudio
*chip
= dev_get_drvdata(dev
);
2173 snd_pcm_suspend_all(chip
->analog_pcm
);
2174 snd_pcm_suspend_all(chip
->digital_pcm
);
2176 #ifdef ECHOCARD_HAS_MIDI
2177 /* This call can sleep */
2179 snd_echo_midi_output_trigger(chip
->midi_out
, 0);
2181 spin_lock_irq(&chip
->lock
);
2182 if (wait_handshake(chip
)) {
2183 spin_unlock_irq(&chip
->lock
);
2186 clear_handshake(chip
);
2187 if (send_vector(chip
, DSP_VC_GO_COMATOSE
) < 0) {
2188 spin_unlock_irq(&chip
->lock
);
2191 spin_unlock_irq(&chip
->lock
);
2193 chip
->dsp_code
= NULL
;
2194 free_irq(chip
->irq
, chip
);
2201 static int snd_echo_resume(struct device
*dev
)
2203 struct pci_dev
*pci
= to_pci_dev(dev
);
2204 struct echoaudio
*chip
= dev_get_drvdata(dev
);
2205 struct comm_page
*commpage
, *commpage_bak
;
2206 u32 pipe_alloc_mask
;
2209 commpage_bak
= kmalloc(sizeof(*commpage
), GFP_KERNEL
);
2210 if (commpage_bak
== NULL
)
2212 commpage
= chip
->comm_page
;
2213 memcpy(commpage_bak
, commpage
, sizeof(*commpage
));
2215 err
= init_hw(chip
, chip
->pci
->device
, chip
->pci
->subsystem_device
);
2217 kfree(commpage_bak
);
2218 dev_err(dev
, "resume init_hw err=%d\n", err
);
2219 snd_echo_free(chip
);
2223 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2224 * restore_dsp_settings() fails.
2226 pipe_alloc_mask
= chip
->pipe_alloc_mask
;
2227 chip
->pipe_alloc_mask
= 0;
2228 err
= restore_dsp_rettings(chip
);
2229 chip
->pipe_alloc_mask
= pipe_alloc_mask
;
2231 kfree(commpage_bak
);
2235 memcpy(&commpage
->audio_format
, &commpage_bak
->audio_format
,
2236 sizeof(commpage
->audio_format
));
2237 memcpy(&commpage
->sglist_addr
, &commpage_bak
->sglist_addr
,
2238 sizeof(commpage
->sglist_addr
));
2239 memcpy(&commpage
->midi_output
, &commpage_bak
->midi_output
,
2240 sizeof(commpage
->midi_output
));
2241 kfree(commpage_bak
);
2243 if (request_irq(pci
->irq
, snd_echo_interrupt
, IRQF_SHARED
,
2244 KBUILD_MODNAME
, chip
)) {
2245 dev_err(chip
->card
->dev
, "cannot grab irq\n");
2246 snd_echo_free(chip
);
2249 chip
->irq
= pci
->irq
;
2250 dev_dbg(dev
, "resume irq=%d\n", chip
->irq
);
2252 #ifdef ECHOCARD_HAS_MIDI
2253 if (chip
->midi_input_enabled
)
2254 enable_midi_input(chip
, true);
2256 snd_echo_midi_output_trigger(chip
->midi_out
, 1);
2262 static SIMPLE_DEV_PM_OPS(snd_echo_pm
, snd_echo_suspend
, snd_echo_resume
);
2263 #define SND_ECHO_PM_OPS &snd_echo_pm
2265 #define SND_ECHO_PM_OPS NULL
2266 #endif /* CONFIG_PM_SLEEP */
2269 static void snd_echo_remove(struct pci_dev
*pci
)
2271 struct echoaudio
*chip
;
2273 chip
= pci_get_drvdata(pci
);
2275 snd_card_free(chip
->card
);
2280 /******************************************************************************
2281 Everything starts and ends here
2282 ******************************************************************************/
2284 /* pci_driver definition */
2285 static struct pci_driver echo_driver
= {
2286 .name
= KBUILD_MODNAME
,
2287 .id_table
= snd_echo_ids
,
2288 .probe
= snd_echo_probe
,
2289 .remove
= snd_echo_remove
,
2291 .pm
= SND_ECHO_PM_OPS
,
2295 module_pci_driver(echo_driver
);