2 * Driver for Digigram VX soundcards
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <sound/core.h>
24 #include <sound/control.h>
25 #include <sound/tlv.h>
26 #include <sound/vx_core.h>
31 * write a codec data (24bit)
33 static void vx_write_codec_reg(struct vx_core
*chip
, int codec
, unsigned int data
)
37 snd_assert(chip
->ops
->write_codec
, return);
39 if (chip
->chip_status
& VX_STAT_IS_STALE
)
42 spin_lock_irqsave(&chip
->lock
, flags
);
43 chip
->ops
->write_codec(chip
, codec
, data
);
44 spin_unlock_irqrestore(&chip
->lock
, flags
);
48 * Data type used to access the Codec
52 #ifdef SNDRV_BIG_ENDIAN
63 #else /* LITTLE_ENDIAN */
77 #define SET_CDC_DATA_SEL(di,s) ((di).b.mh = (u8) (s))
78 #define SET_CDC_DATA_REG(di,r) ((di).b.ml = (u8) (r))
79 #define SET_CDC_DATA_VAL(di,d) ((di).b.ll = (u8) (d))
80 #define SET_CDC_DATA_INIT(di) ((di).l = 0L, SET_CDC_DATA_SEL(di,XX_CODEC_SELECTOR))
83 * set up codec register and write the value
84 * @codec: the codec id, 0 or 1
85 * @reg: register index
88 static void vx_set_codec_reg(struct vx_core
*chip
, int codec
, int reg
, int val
)
90 union vx_codec_data data
;
91 /* DAC control register */
92 SET_CDC_DATA_INIT(data
);
93 SET_CDC_DATA_REG(data
, reg
);
94 SET_CDC_DATA_VAL(data
, val
);
95 vx_write_codec_reg(chip
, codec
, data
.l
);
100 * vx_set_analog_output_level - set the output attenuation level
101 * @codec: the output codec, 0 or 1. (1 for VXP440 only)
102 * @left: left output level, 0 = mute
103 * @right: right output level
105 static void vx_set_analog_output_level(struct vx_core
*chip
, int codec
, int left
, int right
)
107 left
= chip
->hw
->output_level_max
- left
;
108 right
= chip
->hw
->output_level_max
- right
;
110 if (chip
->ops
->akm_write
) {
111 chip
->ops
->akm_write(chip
, XX_CODEC_LEVEL_LEFT_REGISTER
, left
);
112 chip
->ops
->akm_write(chip
, XX_CODEC_LEVEL_RIGHT_REGISTER
, right
);
114 /* convert to attenuation level: 0 = 0dB (max), 0xe3 = -113.5 dB (min) */
115 vx_set_codec_reg(chip
, codec
, XX_CODEC_LEVEL_LEFT_REGISTER
, left
);
116 vx_set_codec_reg(chip
, codec
, XX_CODEC_LEVEL_RIGHT_REGISTER
, right
);
122 * vx_toggle_dac_mute - mute/unmute DAC
123 * @mute: 0 = unmute, 1 = mute
126 #define DAC_ATTEN_MIN 0x08
127 #define DAC_ATTEN_MAX 0x38
129 void vx_toggle_dac_mute(struct vx_core
*chip
, int mute
)
132 for (i
= 0; i
< chip
->hw
->num_codecs
; i
++) {
133 if (chip
->ops
->akm_write
)
134 chip
->ops
->akm_write(chip
, XX_CODEC_DAC_CONTROL_REGISTER
, mute
); /* XXX */
136 vx_set_codec_reg(chip
, i
, XX_CODEC_DAC_CONTROL_REGISTER
,
137 mute
? DAC_ATTEN_MAX
: DAC_ATTEN_MIN
);
142 * vx_reset_codec - reset and initialize the codecs
144 void vx_reset_codec(struct vx_core
*chip
, int cold_reset
)
147 int port
= chip
->type
>= VX_TYPE_VXPOCKET
? 0x75 : 0x65;
149 chip
->ops
->reset_codec(chip
);
151 /* AKM codecs should be initialized in reset_codec callback */
152 if (! chip
->ops
->akm_write
) {
153 /* initialize old codecs */
154 for (i
= 0; i
< chip
->hw
->num_codecs
; i
++) {
155 /* DAC control register (change level when zero crossing + mute) */
156 vx_set_codec_reg(chip
, i
, XX_CODEC_DAC_CONTROL_REGISTER
, DAC_ATTEN_MAX
);
157 /* ADC control register */
158 vx_set_codec_reg(chip
, i
, XX_CODEC_ADC_CONTROL_REGISTER
, 0x00);
159 /* Port mode register */
160 vx_set_codec_reg(chip
, i
, XX_CODEC_PORT_MODE_REGISTER
, port
);
161 /* Clock control register */
162 vx_set_codec_reg(chip
, i
, XX_CODEC_CLOCK_CONTROL_REGISTER
, 0x00);
166 /* mute analog output */
167 for (i
= 0; i
< chip
->hw
->num_codecs
; i
++) {
168 chip
->output_level
[i
][0] = 0;
169 chip
->output_level
[i
][1] = 0;
170 vx_set_analog_output_level(chip
, i
, 0, 0);
175 * change the audio input source
176 * @src: the target source (VX_AUDIO_SRC_XXX)
178 static void vx_change_audio_source(struct vx_core
*chip
, int src
)
182 if (chip
->chip_status
& VX_STAT_IS_STALE
)
185 spin_lock_irqsave(&chip
->lock
, flags
);
186 chip
->ops
->change_audio_source(chip
, src
);
187 spin_unlock_irqrestore(&chip
->lock
, flags
);
192 * change the audio source if necessary and possible
193 * returns 1 if the source is actually changed.
195 int vx_sync_audio_source(struct vx_core
*chip
)
197 if (chip
->audio_source_target
== chip
->audio_source
||
200 vx_change_audio_source(chip
, chip
->audio_source_target
);
201 chip
->audio_source
= chip
->audio_source_target
;
207 * audio level, mute, monitoring
209 struct vx_audio_level
{
210 unsigned int has_level
: 1;
211 unsigned int has_monitor_level
: 1;
212 unsigned int has_mute
: 1;
213 unsigned int has_monitor_mute
: 1;
215 unsigned int monitor_mute
;
220 static int vx_adjust_audio_level(struct vx_core
*chip
, int audio
, int capture
,
221 struct vx_audio_level
*info
)
225 if (chip
->chip_status
& VX_STAT_IS_STALE
)
228 vx_init_rmh(&rmh
, CMD_AUDIO_LEVEL_ADJUST
);
230 rmh
.Cmd
[0] |= COMMAND_RECORD_MASK
;
231 /* Add Audio IO mask */
232 rmh
.Cmd
[1] = 1 << audio
;
234 if (info
->has_level
) {
235 rmh
.Cmd
[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL
;
236 rmh
.Cmd
[2] |= info
->level
;
238 if (info
->has_monitor_level
) {
239 rmh
.Cmd
[0] |= VALID_AUDIO_IO_MONITORING_LEVEL
;
240 rmh
.Cmd
[2] |= ((unsigned int)info
->monitor_level
<< 10);
242 if (info
->has_mute
) {
243 rmh
.Cmd
[0] |= VALID_AUDIO_IO_MUTE_LEVEL
;
245 rmh
.Cmd
[2] |= AUDIO_IO_HAS_MUTE_LEVEL
;
247 if (info
->has_monitor_mute
) {
248 /* validate flag for M2 at least to unmute it */
249 rmh
.Cmd
[0] |= VALID_AUDIO_IO_MUTE_MONITORING_1
| VALID_AUDIO_IO_MUTE_MONITORING_2
;
250 if (info
->monitor_mute
)
251 rmh
.Cmd
[2] |= AUDIO_IO_HAS_MUTE_MONITORING_1
;
254 return vx_send_msg(chip
, &rmh
);
259 static int vx_read_audio_level(struct vx_core
*chip
, int audio
, int capture
,
260 struct vx_audio_level
*info
)
265 memset(info
, 0, sizeof(*info
));
266 vx_init_rmh(&rmh
, CMD_GET_AUDIO_LEVELS
);
268 rmh
.Cmd
[0] |= COMMAND_RECORD_MASK
;
269 /* Add Audio IO mask */
270 rmh
.Cmd
[1] = 1 << audio
;
271 err
= vx_send_msg(chip
, &rmh
);
274 info
.level
= rmh
.Stat
[0] & MASK_DSP_WORD_LEVEL
;
275 info
.monitor_level
= (rmh
.Stat
[0] >> 10) & MASK_DSP_WORD_LEVEL
;
276 info
.mute
= (rmh
.Stat
[i
] & AUDIO_IO_HAS_MUTE_LEVEL
) ? 1 : 0;
277 info
.monitor_mute
= (rmh
.Stat
[i
] & AUDIO_IO_HAS_MUTE_MONITORING_1
) ? 1 : 0;
283 * set the monitoring level and mute state of the given audio
284 * no more static, because must be called from vx_pcm to demute monitoring
286 int vx_set_monitor_level(struct vx_core
*chip
, int audio
, int level
, int active
)
288 struct vx_audio_level info
;
290 memset(&info
, 0, sizeof(info
));
291 info
.has_monitor_level
= 1;
292 info
.monitor_level
= level
;
293 info
.has_monitor_mute
= 1;
294 info
.monitor_mute
= !active
;
295 chip
->audio_monitor
[audio
] = level
;
296 chip
->audio_monitor_active
[audio
] = active
;
297 return vx_adjust_audio_level(chip
, audio
, 0, &info
); /* playback only */
302 * set the mute status of the given audio
304 static int vx_set_audio_switch(struct vx_core
*chip
, int audio
, int active
)
306 struct vx_audio_level info
;
308 memset(&info
, 0, sizeof(info
));
311 chip
->audio_active
[audio
] = active
;
312 return vx_adjust_audio_level(chip
, audio
, 0, &info
); /* playback only */
316 * set the mute status of the given audio
318 static int vx_set_audio_gain(struct vx_core
*chip
, int audio
, int capture
, int level
)
320 struct vx_audio_level info
;
322 memset(&info
, 0, sizeof(info
));
325 chip
->audio_gain
[capture
][audio
] = level
;
326 return vx_adjust_audio_level(chip
, audio
, capture
, &info
);
330 * reset all audio levels
332 static void vx_reset_audio_levels(struct vx_core
*chip
)
335 struct vx_audio_level info
;
337 memset(chip
->audio_gain
, 0, sizeof(chip
->audio_gain
));
338 memset(chip
->audio_active
, 0, sizeof(chip
->audio_active
));
339 memset(chip
->audio_monitor
, 0, sizeof(chip
->audio_monitor
));
340 memset(chip
->audio_monitor_active
, 0, sizeof(chip
->audio_monitor_active
));
342 for (c
= 0; c
< 2; c
++) {
343 for (i
= 0; i
< chip
->hw
->num_ins
* 2; i
++) {
344 memset(&info
, 0, sizeof(info
));
346 info
.has_monitor_level
= 1;
348 info
.has_monitor_mute
= 1;
351 info
.level
= CVAL_0DB
; /* default: 0dB */
352 vx_adjust_audio_level(chip
, i
, c
, &info
);
353 chip
->audio_gain
[c
][i
] = CVAL_0DB
;
354 chip
->audio_monitor
[i
] = CVAL_0DB
;
361 * VU, peak meter record
364 #define VU_METER_CHANNELS 2
373 * get the VU and peak meter values
374 * @audio: the audio index
375 * @capture: 0 = playback, 1 = capture operation
376 * @info: the array of vx_vu_meter records (size = 2).
378 static int vx_get_audio_vu_meter(struct vx_core
*chip
, int audio
, int capture
, struct vx_vu_meter
*info
)
383 if (chip
->chip_status
& VX_STAT_IS_STALE
)
386 vx_init_rmh(&rmh
, CMD_AUDIO_VU_PIC_METER
);
387 rmh
.LgStat
+= 2 * VU_METER_CHANNELS
;
389 rmh
.Cmd
[0] |= COMMAND_RECORD_MASK
;
391 /* Add Audio IO mask */
393 for (i
= 0; i
< VU_METER_CHANNELS
; i
++)
394 rmh
.Cmd
[1] |= 1 << (audio
+ i
);
395 err
= vx_send_msg(chip
, &rmh
);
399 for (i
= 0; i
< 2 * VU_METER_CHANNELS
; i
+=2) {
400 info
->saturated
= (rmh
.Stat
[0] & (1 << (audio
+ i
))) ? 1 : 0;
401 info
->vu_level
= rmh
.Stat
[i
+ 1];
402 info
->peak_level
= rmh
.Stat
[i
+ 2];
410 * control API entries
414 * output level control
416 static int vx_output_level_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
418 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
419 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
421 uinfo
->value
.integer
.min
= 0;
422 uinfo
->value
.integer
.max
= chip
->hw
->output_level_max
;
426 static int vx_output_level_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
428 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
429 int codec
= kcontrol
->id
.index
;
430 mutex_lock(&chip
->mixer_mutex
);
431 ucontrol
->value
.integer
.value
[0] = chip
->output_level
[codec
][0];
432 ucontrol
->value
.integer
.value
[1] = chip
->output_level
[codec
][1];
433 mutex_unlock(&chip
->mixer_mutex
);
437 static int vx_output_level_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
439 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
440 int codec
= kcontrol
->id
.index
;
441 unsigned int val
[2], vmax
;
443 vmax
= chip
->hw
->output_level_max
;
444 val
[0] = ucontrol
->value
.integer
.value
[0];
445 val
[1] = ucontrol
->value
.integer
.value
[1];
446 if (val
[0] > vmax
|| val
[1] > vmax
)
448 mutex_lock(&chip
->mixer_mutex
);
449 if (val
[0] != chip
->output_level
[codec
][0] ||
450 val
[1] != chip
->output_level
[codec
][1]) {
451 vx_set_analog_output_level(chip
, codec
, val
[0], val
[1]);
452 chip
->output_level
[codec
][0] = val
[0];
453 chip
->output_level
[codec
][1] = val
[1];
454 mutex_unlock(&chip
->mixer_mutex
);
457 mutex_unlock(&chip
->mixer_mutex
);
461 static struct snd_kcontrol_new vx_control_output_level
= {
462 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
463 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
464 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
465 .name
= "Master Playback Volume",
466 .info
= vx_output_level_info
,
467 .get
= vx_output_level_get
,
468 .put
= vx_output_level_put
,
469 /* tlv will be filled later */
473 * audio source select
475 static int vx_audio_src_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
477 static char *texts_mic
[3] = {
478 "Digital", "Line", "Mic"
480 static char *texts_vx2
[2] = {
483 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
485 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
487 if (chip
->type
>= VX_TYPE_VXPOCKET
) {
488 uinfo
->value
.enumerated
.items
= 3;
489 if (uinfo
->value
.enumerated
.item
> 2)
490 uinfo
->value
.enumerated
.item
= 2;
491 strcpy(uinfo
->value
.enumerated
.name
,
492 texts_mic
[uinfo
->value
.enumerated
.item
]);
494 uinfo
->value
.enumerated
.items
= 2;
495 if (uinfo
->value
.enumerated
.item
> 1)
496 uinfo
->value
.enumerated
.item
= 1;
497 strcpy(uinfo
->value
.enumerated
.name
,
498 texts_vx2
[uinfo
->value
.enumerated
.item
]);
503 static int vx_audio_src_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
505 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
506 ucontrol
->value
.enumerated
.item
[0] = chip
->audio_source_target
;
510 static int vx_audio_src_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
512 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
514 if (chip
->type
>= VX_TYPE_VXPOCKET
) {
515 if (ucontrol
->value
.enumerated
.item
[0] > 2)
518 if (ucontrol
->value
.enumerated
.item
[0] > 1)
521 mutex_lock(&chip
->mixer_mutex
);
522 if (chip
->audio_source_target
!= ucontrol
->value
.enumerated
.item
[0]) {
523 chip
->audio_source_target
= ucontrol
->value
.enumerated
.item
[0];
524 vx_sync_audio_source(chip
);
525 mutex_unlock(&chip
->mixer_mutex
);
528 mutex_unlock(&chip
->mixer_mutex
);
532 static struct snd_kcontrol_new vx_control_audio_src
= {
533 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
534 .name
= "Capture Source",
535 .info
= vx_audio_src_info
,
536 .get
= vx_audio_src_get
,
537 .put
= vx_audio_src_put
,
541 * clock mode selection
543 static int vx_clock_mode_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
545 static char *texts
[3] = {
546 "Auto", "Internal", "External"
549 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
551 uinfo
->value
.enumerated
.items
= 3;
552 if (uinfo
->value
.enumerated
.item
> 2)
553 uinfo
->value
.enumerated
.item
= 2;
554 strcpy(uinfo
->value
.enumerated
.name
,
555 texts
[uinfo
->value
.enumerated
.item
]);
559 static int vx_clock_mode_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
561 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
562 ucontrol
->value
.enumerated
.item
[0] = chip
->clock_mode
;
566 static int vx_clock_mode_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
568 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
570 if (ucontrol
->value
.enumerated
.item
[0] > 2)
572 mutex_lock(&chip
->mixer_mutex
);
573 if (chip
->clock_mode
!= ucontrol
->value
.enumerated
.item
[0]) {
574 chip
->clock_mode
= ucontrol
->value
.enumerated
.item
[0];
575 vx_set_clock(chip
, chip
->freq
);
576 mutex_unlock(&chip
->mixer_mutex
);
579 mutex_unlock(&chip
->mixer_mutex
);
583 static struct snd_kcontrol_new vx_control_clock_mode
= {
584 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
585 .name
= "Clock Mode",
586 .info
= vx_clock_mode_info
,
587 .get
= vx_clock_mode_get
,
588 .put
= vx_clock_mode_put
,
594 static int vx_audio_gain_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
596 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
598 uinfo
->value
.integer
.min
= 0;
599 uinfo
->value
.integer
.max
= CVAL_MAX
;
603 static int vx_audio_gain_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
605 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
606 int audio
= kcontrol
->private_value
& 0xff;
607 int capture
= (kcontrol
->private_value
>> 8) & 1;
609 mutex_lock(&chip
->mixer_mutex
);
610 ucontrol
->value
.integer
.value
[0] = chip
->audio_gain
[capture
][audio
];
611 ucontrol
->value
.integer
.value
[1] = chip
->audio_gain
[capture
][audio
+1];
612 mutex_unlock(&chip
->mixer_mutex
);
616 static int vx_audio_gain_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
618 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
619 int audio
= kcontrol
->private_value
& 0xff;
620 int capture
= (kcontrol
->private_value
>> 8) & 1;
623 val
[0] = ucontrol
->value
.integer
.value
[0];
624 val
[1] = ucontrol
->value
.integer
.value
[1];
625 if (val
[0] > CVAL_MAX
|| val
[1] > CVAL_MAX
)
627 mutex_lock(&chip
->mixer_mutex
);
628 if (val
[0] != chip
->audio_gain
[capture
][audio
] ||
629 val
[1] != chip
->audio_gain
[capture
][audio
+1]) {
630 vx_set_audio_gain(chip
, audio
, capture
, val
[0]);
631 vx_set_audio_gain(chip
, audio
+1, capture
, val
[1]);
632 mutex_unlock(&chip
->mixer_mutex
);
635 mutex_unlock(&chip
->mixer_mutex
);
639 static int vx_audio_monitor_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
641 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
642 int audio
= kcontrol
->private_value
& 0xff;
644 mutex_lock(&chip
->mixer_mutex
);
645 ucontrol
->value
.integer
.value
[0] = chip
->audio_monitor
[audio
];
646 ucontrol
->value
.integer
.value
[1] = chip
->audio_monitor
[audio
+1];
647 mutex_unlock(&chip
->mixer_mutex
);
651 static int vx_audio_monitor_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
653 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
654 int audio
= kcontrol
->private_value
& 0xff;
657 val
[0] = ucontrol
->value
.integer
.value
[0];
658 val
[1] = ucontrol
->value
.integer
.value
[1];
659 if (val
[0] > CVAL_MAX
|| val
[1] > CVAL_MAX
)
662 mutex_lock(&chip
->mixer_mutex
);
663 if (val
[0] != chip
->audio_monitor
[audio
] ||
664 val
[1] != chip
->audio_monitor
[audio
+1]) {
665 vx_set_monitor_level(chip
, audio
, val
[0],
666 chip
->audio_monitor_active
[audio
]);
667 vx_set_monitor_level(chip
, audio
+1, val
[1],
668 chip
->audio_monitor_active
[audio
+1]);
669 mutex_unlock(&chip
->mixer_mutex
);
672 mutex_unlock(&chip
->mixer_mutex
);
676 #define vx_audio_sw_info snd_ctl_boolean_stereo_info
678 static int vx_audio_sw_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
680 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
681 int audio
= kcontrol
->private_value
& 0xff;
683 mutex_lock(&chip
->mixer_mutex
);
684 ucontrol
->value
.integer
.value
[0] = chip
->audio_active
[audio
];
685 ucontrol
->value
.integer
.value
[1] = chip
->audio_active
[audio
+1];
686 mutex_unlock(&chip
->mixer_mutex
);
690 static int vx_audio_sw_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
692 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
693 int audio
= kcontrol
->private_value
& 0xff;
695 mutex_lock(&chip
->mixer_mutex
);
696 if (ucontrol
->value
.integer
.value
[0] != chip
->audio_active
[audio
] ||
697 ucontrol
->value
.integer
.value
[1] != chip
->audio_active
[audio
+1]) {
698 vx_set_audio_switch(chip
, audio
,
699 !!ucontrol
->value
.integer
.value
[0]);
700 vx_set_audio_switch(chip
, audio
+1,
701 !!ucontrol
->value
.integer
.value
[1]);
702 mutex_unlock(&chip
->mixer_mutex
);
705 mutex_unlock(&chip
->mixer_mutex
);
709 static int vx_monitor_sw_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
711 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
712 int audio
= kcontrol
->private_value
& 0xff;
714 mutex_lock(&chip
->mixer_mutex
);
715 ucontrol
->value
.integer
.value
[0] = chip
->audio_monitor_active
[audio
];
716 ucontrol
->value
.integer
.value
[1] = chip
->audio_monitor_active
[audio
+1];
717 mutex_unlock(&chip
->mixer_mutex
);
721 static int vx_monitor_sw_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
723 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
724 int audio
= kcontrol
->private_value
& 0xff;
726 mutex_lock(&chip
->mixer_mutex
);
727 if (ucontrol
->value
.integer
.value
[0] != chip
->audio_monitor_active
[audio
] ||
728 ucontrol
->value
.integer
.value
[1] != chip
->audio_monitor_active
[audio
+1]) {
729 vx_set_monitor_level(chip
, audio
, chip
->audio_monitor
[audio
],
730 !!ucontrol
->value
.integer
.value
[0]);
731 vx_set_monitor_level(chip
, audio
+1, chip
->audio_monitor
[audio
+1],
732 !!ucontrol
->value
.integer
.value
[1]);
733 mutex_unlock(&chip
->mixer_mutex
);
736 mutex_unlock(&chip
->mixer_mutex
);
740 static const DECLARE_TLV_DB_SCALE(db_scale_audio_gain
, -10975, 25, 0);
742 static struct snd_kcontrol_new vx_control_audio_gain
= {
743 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
744 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
745 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
746 /* name will be filled later */
747 .info
= vx_audio_gain_info
,
748 .get
= vx_audio_gain_get
,
749 .put
= vx_audio_gain_put
,
750 .tlv
= { .p
= db_scale_audio_gain
},
752 static struct snd_kcontrol_new vx_control_output_switch
= {
753 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
754 .name
= "PCM Playback Switch",
755 .info
= vx_audio_sw_info
,
756 .get
= vx_audio_sw_get
,
757 .put
= vx_audio_sw_put
759 static struct snd_kcontrol_new vx_control_monitor_gain
= {
760 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
761 .name
= "Monitoring Volume",
762 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
763 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
764 .info
= vx_audio_gain_info
, /* shared */
765 .get
= vx_audio_monitor_get
,
766 .put
= vx_audio_monitor_put
,
767 .tlv
= { .p
= db_scale_audio_gain
},
769 static struct snd_kcontrol_new vx_control_monitor_switch
= {
770 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
771 .name
= "Monitoring Switch",
772 .info
= vx_audio_sw_info
, /* shared */
773 .get
= vx_monitor_sw_get
,
774 .put
= vx_monitor_sw_put
781 static int vx_iec958_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
783 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
788 static int vx_iec958_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
790 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
792 mutex_lock(&chip
->mixer_mutex
);
793 ucontrol
->value
.iec958
.status
[0] = (chip
->uer_bits
>> 0) & 0xff;
794 ucontrol
->value
.iec958
.status
[1] = (chip
->uer_bits
>> 8) & 0xff;
795 ucontrol
->value
.iec958
.status
[2] = (chip
->uer_bits
>> 16) & 0xff;
796 ucontrol
->value
.iec958
.status
[3] = (chip
->uer_bits
>> 24) & 0xff;
797 mutex_unlock(&chip
->mixer_mutex
);
801 static int vx_iec958_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
803 ucontrol
->value
.iec958
.status
[0] = 0xff;
804 ucontrol
->value
.iec958
.status
[1] = 0xff;
805 ucontrol
->value
.iec958
.status
[2] = 0xff;
806 ucontrol
->value
.iec958
.status
[3] = 0xff;
810 static int vx_iec958_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
812 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
815 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
816 (ucontrol
->value
.iec958
.status
[1] << 8) |
817 (ucontrol
->value
.iec958
.status
[2] << 16) |
818 (ucontrol
->value
.iec958
.status
[3] << 24);
819 mutex_lock(&chip
->mixer_mutex
);
820 if (chip
->uer_bits
!= val
) {
821 chip
->uer_bits
= val
;
822 vx_set_iec958_status(chip
, val
);
823 mutex_unlock(&chip
->mixer_mutex
);
826 mutex_unlock(&chip
->mixer_mutex
);
830 static struct snd_kcontrol_new vx_control_iec958_mask
= {
831 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
832 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
833 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
834 .info
= vx_iec958_info
, /* shared */
835 .get
= vx_iec958_mask_get
,
838 static struct snd_kcontrol_new vx_control_iec958
= {
839 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
840 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
841 .info
= vx_iec958_info
,
842 .get
= vx_iec958_get
,
851 #define METER_MAX 0xff
852 #define METER_SHIFT 16
854 static int vx_vu_meter_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
856 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
858 uinfo
->value
.integer
.min
= 0;
859 uinfo
->value
.integer
.max
= METER_MAX
;
863 static int vx_vu_meter_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
865 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
866 struct vx_vu_meter meter
[2];
867 int audio
= kcontrol
->private_value
& 0xff;
868 int capture
= (kcontrol
->private_value
>> 8) & 1;
870 vx_get_audio_vu_meter(chip
, audio
, capture
, meter
);
871 ucontrol
->value
.integer
.value
[0] = meter
[0].vu_level
>> METER_SHIFT
;
872 ucontrol
->value
.integer
.value
[1] = meter
[1].vu_level
>> METER_SHIFT
;
876 static int vx_peak_meter_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
878 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
879 struct vx_vu_meter meter
[2];
880 int audio
= kcontrol
->private_value
& 0xff;
881 int capture
= (kcontrol
->private_value
>> 8) & 1;
883 vx_get_audio_vu_meter(chip
, audio
, capture
, meter
);
884 ucontrol
->value
.integer
.value
[0] = meter
[0].peak_level
>> METER_SHIFT
;
885 ucontrol
->value
.integer
.value
[1] = meter
[1].peak_level
>> METER_SHIFT
;
889 #define vx_saturation_info snd_ctl_boolean_stereo_info
891 static int vx_saturation_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
893 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
894 struct vx_vu_meter meter
[2];
895 int audio
= kcontrol
->private_value
& 0xff;
897 vx_get_audio_vu_meter(chip
, audio
, 1, meter
); /* capture only */
898 ucontrol
->value
.integer
.value
[0] = meter
[0].saturated
;
899 ucontrol
->value
.integer
.value
[1] = meter
[1].saturated
;
903 static struct snd_kcontrol_new vx_control_vu_meter
= {
904 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
905 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
906 /* name will be filled later */
907 .info
= vx_vu_meter_info
,
908 .get
= vx_vu_meter_get
,
911 static struct snd_kcontrol_new vx_control_peak_meter
= {
912 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
913 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
914 /* name will be filled later */
915 .info
= vx_vu_meter_info
, /* shared */
916 .get
= vx_peak_meter_get
,
919 static struct snd_kcontrol_new vx_control_saturation
= {
920 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
921 .name
= "Input Saturation",
922 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
923 .info
= vx_saturation_info
,
924 .get
= vx_saturation_get
,
933 int snd_vx_mixer_new(struct vx_core
*chip
)
937 struct snd_kcontrol_new temp
;
938 struct snd_card
*card
= chip
->card
;
941 strcpy(card
->mixername
, card
->driver
);
943 /* output level controls */
944 for (i
= 0; i
< chip
->hw
->num_outs
; i
++) {
945 temp
= vx_control_output_level
;
947 temp
.tlv
.p
= chip
->hw
->output_level_db_scale
;
948 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
952 /* PCM volumes, switches, monitoring */
953 for (i
= 0; i
< chip
->hw
->num_outs
; i
++) {
955 temp
= vx_control_audio_gain
;
957 temp
.name
= "PCM Playback Volume";
958 temp
.private_value
= val
;
959 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
961 temp
= vx_control_output_switch
;
963 temp
.private_value
= val
;
964 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
966 temp
= vx_control_monitor_gain
;
968 temp
.private_value
= val
;
969 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
971 temp
= vx_control_monitor_switch
;
973 temp
.private_value
= val
;
974 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
977 for (i
= 0; i
< chip
->hw
->num_outs
; i
++) {
978 temp
= vx_control_audio_gain
;
980 temp
.name
= "PCM Capture Volume";
981 temp
.private_value
= (i
* 2) | (1 << 8);
982 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
987 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&vx_control_audio_src
, chip
))) < 0)
990 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&vx_control_clock_mode
, chip
))) < 0)
992 /* IEC958 controls */
993 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&vx_control_iec958_mask
, chip
))) < 0)
995 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&vx_control_iec958
, chip
))) < 0)
997 /* VU, peak, saturation meters */
998 for (c
= 0; c
< 2; c
++) {
999 static char *dir
[2] = { "Output", "Input" };
1000 for (i
= 0; i
< chip
->hw
->num_ins
; i
++) {
1001 int val
= (i
* 2) | (c
<< 8);
1003 temp
= vx_control_saturation
;
1005 temp
.private_value
= val
;
1006 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
1009 sprintf(name
, "%s VU Meter", dir
[c
]);
1010 temp
= vx_control_vu_meter
;
1013 temp
.private_value
= val
;
1014 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
1016 sprintf(name
, "%s Peak Meter", dir
[c
]);
1017 temp
= vx_control_peak_meter
;
1020 temp
.private_value
= val
;
1021 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
1025 vx_reset_audio_levels(chip
);