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/driver.h>
24 #include <sound/core.h>
25 #include <sound/control.h>
26 #include <sound/tlv.h>
27 #include <sound/vx_core.h>
32 * write a codec data (24bit)
34 static void vx_write_codec_reg(struct vx_core
*chip
, int codec
, unsigned int data
)
38 snd_assert(chip
->ops
->write_codec
, return);
40 if (chip
->chip_status
& VX_STAT_IS_STALE
)
43 spin_lock_irqsave(&chip
->lock
, flags
);
44 chip
->ops
->write_codec(chip
, codec
, data
);
45 spin_unlock_irqrestore(&chip
->lock
, flags
);
49 * Data type used to access the Codec
53 #ifdef SNDRV_BIG_ENDIAN
64 #else /* LITTLE_ENDIAN */
78 #define SET_CDC_DATA_SEL(di,s) ((di).b.mh = (u8) (s))
79 #define SET_CDC_DATA_REG(di,r) ((di).b.ml = (u8) (r))
80 #define SET_CDC_DATA_VAL(di,d) ((di).b.ll = (u8) (d))
81 #define SET_CDC_DATA_INIT(di) ((di).l = 0L, SET_CDC_DATA_SEL(di,XX_CODEC_SELECTOR))
84 * set up codec register and write the value
85 * @codec: the codec id, 0 or 1
86 * @reg: register index
89 static void vx_set_codec_reg(struct vx_core
*chip
, int codec
, int reg
, int val
)
91 union vx_codec_data data
;
92 /* DAC control register */
93 SET_CDC_DATA_INIT(data
);
94 SET_CDC_DATA_REG(data
, reg
);
95 SET_CDC_DATA_VAL(data
, val
);
96 vx_write_codec_reg(chip
, codec
, data
.l
);
101 * vx_set_analog_output_level - set the output attenuation level
102 * @codec: the output codec, 0 or 1. (1 for VXP440 only)
103 * @left: left output level, 0 = mute
104 * @right: right output level
106 static void vx_set_analog_output_level(struct vx_core
*chip
, int codec
, int left
, int right
)
108 left
= chip
->hw
->output_level_max
- left
;
109 right
= chip
->hw
->output_level_max
- right
;
111 if (chip
->ops
->akm_write
) {
112 chip
->ops
->akm_write(chip
, XX_CODEC_LEVEL_LEFT_REGISTER
, left
);
113 chip
->ops
->akm_write(chip
, XX_CODEC_LEVEL_RIGHT_REGISTER
, right
);
115 /* convert to attenuation level: 0 = 0dB (max), 0xe3 = -113.5 dB (min) */
116 vx_set_codec_reg(chip
, codec
, XX_CODEC_LEVEL_LEFT_REGISTER
, left
);
117 vx_set_codec_reg(chip
, codec
, XX_CODEC_LEVEL_RIGHT_REGISTER
, right
);
123 * vx_toggle_dac_mute - mute/unmute DAC
124 * @mute: 0 = unmute, 1 = mute
127 #define DAC_ATTEN_MIN 0x08
128 #define DAC_ATTEN_MAX 0x38
130 void vx_toggle_dac_mute(struct vx_core
*chip
, int mute
)
133 for (i
= 0; i
< chip
->hw
->num_codecs
; i
++) {
134 if (chip
->ops
->akm_write
)
135 chip
->ops
->akm_write(chip
, XX_CODEC_DAC_CONTROL_REGISTER
, mute
); /* XXX */
137 vx_set_codec_reg(chip
, i
, XX_CODEC_DAC_CONTROL_REGISTER
,
138 mute
? DAC_ATTEN_MAX
: DAC_ATTEN_MIN
);
143 * vx_reset_codec - reset and initialize the codecs
145 void vx_reset_codec(struct vx_core
*chip
, int cold_reset
)
148 int port
= chip
->type
>= VX_TYPE_VXPOCKET
? 0x75 : 0x65;
150 chip
->ops
->reset_codec(chip
);
152 /* AKM codecs should be initialized in reset_codec callback */
153 if (! chip
->ops
->akm_write
) {
154 /* initialize old codecs */
155 for (i
= 0; i
< chip
->hw
->num_codecs
; i
++) {
156 /* DAC control register (change level when zero crossing + mute) */
157 vx_set_codec_reg(chip
, i
, XX_CODEC_DAC_CONTROL_REGISTER
, DAC_ATTEN_MAX
);
158 /* ADC control register */
159 vx_set_codec_reg(chip
, i
, XX_CODEC_ADC_CONTROL_REGISTER
, 0x00);
160 /* Port mode register */
161 vx_set_codec_reg(chip
, i
, XX_CODEC_PORT_MODE_REGISTER
, port
);
162 /* Clock control register */
163 vx_set_codec_reg(chip
, i
, XX_CODEC_CLOCK_CONTROL_REGISTER
, 0x00);
167 /* mute analog output */
168 for (i
= 0; i
< chip
->hw
->num_codecs
; i
++) {
169 chip
->output_level
[i
][0] = 0;
170 chip
->output_level
[i
][1] = 0;
171 vx_set_analog_output_level(chip
, i
, 0, 0);
176 * change the audio input source
177 * @src: the target source (VX_AUDIO_SRC_XXX)
179 static void vx_change_audio_source(struct vx_core
*chip
, int src
)
183 if (chip
->chip_status
& VX_STAT_IS_STALE
)
186 spin_lock_irqsave(&chip
->lock
, flags
);
187 chip
->ops
->change_audio_source(chip
, src
);
188 spin_unlock_irqrestore(&chip
->lock
, flags
);
193 * change the audio source if necessary and possible
194 * returns 1 if the source is actually changed.
196 int vx_sync_audio_source(struct vx_core
*chip
)
198 if (chip
->audio_source_target
== chip
->audio_source
||
201 vx_change_audio_source(chip
, chip
->audio_source_target
);
202 chip
->audio_source
= chip
->audio_source_target
;
208 * audio level, mute, monitoring
210 struct vx_audio_level
{
211 unsigned int has_level
: 1;
212 unsigned int has_monitor_level
: 1;
213 unsigned int has_mute
: 1;
214 unsigned int has_monitor_mute
: 1;
216 unsigned int monitor_mute
;
221 static int vx_adjust_audio_level(struct vx_core
*chip
, int audio
, int capture
,
222 struct vx_audio_level
*info
)
226 if (chip
->chip_status
& VX_STAT_IS_STALE
)
229 vx_init_rmh(&rmh
, CMD_AUDIO_LEVEL_ADJUST
);
231 rmh
.Cmd
[0] |= COMMAND_RECORD_MASK
;
232 /* Add Audio IO mask */
233 rmh
.Cmd
[1] = 1 << audio
;
235 if (info
->has_level
) {
236 rmh
.Cmd
[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL
;
237 rmh
.Cmd
[2] |= info
->level
;
239 if (info
->has_monitor_level
) {
240 rmh
.Cmd
[0] |= VALID_AUDIO_IO_MONITORING_LEVEL
;
241 rmh
.Cmd
[2] |= ((unsigned int)info
->monitor_level
<< 10);
243 if (info
->has_mute
) {
244 rmh
.Cmd
[0] |= VALID_AUDIO_IO_MUTE_LEVEL
;
246 rmh
.Cmd
[2] |= AUDIO_IO_HAS_MUTE_LEVEL
;
248 if (info
->has_monitor_mute
) {
249 /* validate flag for M2 at least to unmute it */
250 rmh
.Cmd
[0] |= VALID_AUDIO_IO_MUTE_MONITORING_1
| VALID_AUDIO_IO_MUTE_MONITORING_2
;
251 if (info
->monitor_mute
)
252 rmh
.Cmd
[2] |= AUDIO_IO_HAS_MUTE_MONITORING_1
;
255 return vx_send_msg(chip
, &rmh
);
260 static int vx_read_audio_level(struct vx_core
*chip
, int audio
, int capture
,
261 struct vx_audio_level
*info
)
266 memset(info
, 0, sizeof(*info
));
267 vx_init_rmh(&rmh
, CMD_GET_AUDIO_LEVELS
);
269 rmh
.Cmd
[0] |= COMMAND_RECORD_MASK
;
270 /* Add Audio IO mask */
271 rmh
.Cmd
[1] = 1 << audio
;
272 err
= vx_send_msg(chip
, &rmh
);
275 info
.level
= rmh
.Stat
[0] & MASK_DSP_WORD_LEVEL
;
276 info
.monitor_level
= (rmh
.Stat
[0] >> 10) & MASK_DSP_WORD_LEVEL
;
277 info
.mute
= (rmh
.Stat
[i
] & AUDIO_IO_HAS_MUTE_LEVEL
) ? 1 : 0;
278 info
.monitor_mute
= (rmh
.Stat
[i
] & AUDIO_IO_HAS_MUTE_MONITORING_1
) ? 1 : 0;
284 * set the monitoring level and mute state of the given audio
285 * no more static, because must be called from vx_pcm to demute monitoring
287 int vx_set_monitor_level(struct vx_core
*chip
, int audio
, int level
, int active
)
289 struct vx_audio_level info
;
291 memset(&info
, 0, sizeof(info
));
292 info
.has_monitor_level
= 1;
293 info
.monitor_level
= level
;
294 info
.has_monitor_mute
= 1;
295 info
.monitor_mute
= !active
;
296 chip
->audio_monitor
[audio
] = level
;
297 chip
->audio_monitor_active
[audio
] = active
;
298 return vx_adjust_audio_level(chip
, audio
, 0, &info
); /* playback only */
303 * set the mute status of the given audio
305 static int vx_set_audio_switch(struct vx_core
*chip
, int audio
, int active
)
307 struct vx_audio_level info
;
309 memset(&info
, 0, sizeof(info
));
312 chip
->audio_active
[audio
] = active
;
313 return vx_adjust_audio_level(chip
, audio
, 0, &info
); /* playback only */
317 * set the mute status of the given audio
319 static int vx_set_audio_gain(struct vx_core
*chip
, int audio
, int capture
, int level
)
321 struct vx_audio_level info
;
323 memset(&info
, 0, sizeof(info
));
326 chip
->audio_gain
[capture
][audio
] = level
;
327 return vx_adjust_audio_level(chip
, audio
, capture
, &info
);
331 * reset all audio levels
333 static void vx_reset_audio_levels(struct vx_core
*chip
)
336 struct vx_audio_level info
;
338 memset(chip
->audio_gain
, 0, sizeof(chip
->audio_gain
));
339 memset(chip
->audio_active
, 0, sizeof(chip
->audio_active
));
340 memset(chip
->audio_monitor
, 0, sizeof(chip
->audio_monitor
));
341 memset(chip
->audio_monitor_active
, 0, sizeof(chip
->audio_monitor_active
));
343 for (c
= 0; c
< 2; c
++) {
344 for (i
= 0; i
< chip
->hw
->num_ins
* 2; i
++) {
345 memset(&info
, 0, sizeof(info
));
347 info
.has_monitor_level
= 1;
349 info
.has_monitor_mute
= 1;
352 info
.level
= CVAL_0DB
; /* default: 0dB */
353 vx_adjust_audio_level(chip
, i
, c
, &info
);
354 chip
->audio_gain
[c
][i
] = CVAL_0DB
;
355 chip
->audio_monitor
[i
] = CVAL_0DB
;
362 * VU, peak meter record
365 #define VU_METER_CHANNELS 2
374 * get the VU and peak meter values
375 * @audio: the audio index
376 * @capture: 0 = playback, 1 = capture operation
377 * @info: the array of vx_vu_meter records (size = 2).
379 static int vx_get_audio_vu_meter(struct vx_core
*chip
, int audio
, int capture
, struct vx_vu_meter
*info
)
384 if (chip
->chip_status
& VX_STAT_IS_STALE
)
387 vx_init_rmh(&rmh
, CMD_AUDIO_VU_PIC_METER
);
388 rmh
.LgStat
+= 2 * VU_METER_CHANNELS
;
390 rmh
.Cmd
[0] |= COMMAND_RECORD_MASK
;
392 /* Add Audio IO mask */
394 for (i
= 0; i
< VU_METER_CHANNELS
; i
++)
395 rmh
.Cmd
[1] |= 1 << (audio
+ i
);
396 err
= vx_send_msg(chip
, &rmh
);
400 for (i
= 0; i
< 2 * VU_METER_CHANNELS
; i
+=2) {
401 info
->saturated
= (rmh
.Stat
[0] & (1 << (audio
+ i
))) ? 1 : 0;
402 info
->vu_level
= rmh
.Stat
[i
+ 1];
403 info
->peak_level
= rmh
.Stat
[i
+ 2];
411 * control API entries
415 * output level control
417 static int vx_output_level_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
419 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
420 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
422 uinfo
->value
.integer
.min
= 0;
423 uinfo
->value
.integer
.max
= chip
->hw
->output_level_max
;
427 static int vx_output_level_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
429 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
430 int codec
= kcontrol
->id
.index
;
431 mutex_lock(&chip
->mixer_mutex
);
432 ucontrol
->value
.integer
.value
[0] = chip
->output_level
[codec
][0];
433 ucontrol
->value
.integer
.value
[1] = chip
->output_level
[codec
][1];
434 mutex_unlock(&chip
->mixer_mutex
);
438 static int vx_output_level_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
440 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
441 int codec
= kcontrol
->id
.index
;
442 mutex_lock(&chip
->mixer_mutex
);
443 if (ucontrol
->value
.integer
.value
[0] != chip
->output_level
[codec
][0] ||
444 ucontrol
->value
.integer
.value
[1] != chip
->output_level
[codec
][1]) {
445 vx_set_analog_output_level(chip
, codec
,
446 ucontrol
->value
.integer
.value
[0],
447 ucontrol
->value
.integer
.value
[1]);
448 chip
->output_level
[codec
][0] = ucontrol
->value
.integer
.value
[0];
449 chip
->output_level
[codec
][1] = ucontrol
->value
.integer
.value
[1];
450 mutex_unlock(&chip
->mixer_mutex
);
453 mutex_unlock(&chip
->mixer_mutex
);
457 static struct snd_kcontrol_new vx_control_output_level
= {
458 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
459 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
460 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
461 .name
= "Master Playback Volume",
462 .info
= vx_output_level_info
,
463 .get
= vx_output_level_get
,
464 .put
= vx_output_level_put
,
465 /* tlv will be filled later */
469 * audio source select
471 static int vx_audio_src_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
473 static char *texts_mic
[3] = {
474 "Digital", "Line", "Mic"
476 static char *texts_vx2
[2] = {
479 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
481 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
483 if (chip
->type
>= VX_TYPE_VXPOCKET
) {
484 uinfo
->value
.enumerated
.items
= 3;
485 if (uinfo
->value
.enumerated
.item
> 2)
486 uinfo
->value
.enumerated
.item
= 2;
487 strcpy(uinfo
->value
.enumerated
.name
,
488 texts_mic
[uinfo
->value
.enumerated
.item
]);
490 uinfo
->value
.enumerated
.items
= 2;
491 if (uinfo
->value
.enumerated
.item
> 1)
492 uinfo
->value
.enumerated
.item
= 1;
493 strcpy(uinfo
->value
.enumerated
.name
,
494 texts_vx2
[uinfo
->value
.enumerated
.item
]);
499 static int vx_audio_src_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
501 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
502 ucontrol
->value
.enumerated
.item
[0] = chip
->audio_source_target
;
506 static int vx_audio_src_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
508 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
509 mutex_lock(&chip
->mixer_mutex
);
510 if (chip
->audio_source_target
!= ucontrol
->value
.enumerated
.item
[0]) {
511 chip
->audio_source_target
= ucontrol
->value
.enumerated
.item
[0];
512 vx_sync_audio_source(chip
);
513 mutex_unlock(&chip
->mixer_mutex
);
516 mutex_unlock(&chip
->mixer_mutex
);
520 static struct snd_kcontrol_new vx_control_audio_src
= {
521 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
522 .name
= "Capture Source",
523 .info
= vx_audio_src_info
,
524 .get
= vx_audio_src_get
,
525 .put
= vx_audio_src_put
,
529 * clock mode selection
531 static int vx_clock_mode_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
533 static char *texts
[3] = {
534 "Auto", "Internal", "External"
537 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
539 uinfo
->value
.enumerated
.items
= 3;
540 if (uinfo
->value
.enumerated
.item
> 2)
541 uinfo
->value
.enumerated
.item
= 2;
542 strcpy(uinfo
->value
.enumerated
.name
,
543 texts
[uinfo
->value
.enumerated
.item
]);
547 static int vx_clock_mode_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
549 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
550 ucontrol
->value
.enumerated
.item
[0] = chip
->clock_mode
;
554 static int vx_clock_mode_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
556 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
557 mutex_lock(&chip
->mixer_mutex
);
558 if (chip
->clock_mode
!= ucontrol
->value
.enumerated
.item
[0]) {
559 chip
->clock_mode
= ucontrol
->value
.enumerated
.item
[0];
560 vx_set_clock(chip
, chip
->freq
);
561 mutex_unlock(&chip
->mixer_mutex
);
564 mutex_unlock(&chip
->mixer_mutex
);
568 static struct snd_kcontrol_new vx_control_clock_mode
= {
569 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
570 .name
= "Clock Mode",
571 .info
= vx_clock_mode_info
,
572 .get
= vx_clock_mode_get
,
573 .put
= vx_clock_mode_put
,
579 static int vx_audio_gain_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
581 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
583 uinfo
->value
.integer
.min
= 0;
584 uinfo
->value
.integer
.max
= CVAL_MAX
;
588 static int vx_audio_gain_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
590 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
591 int audio
= kcontrol
->private_value
& 0xff;
592 int capture
= (kcontrol
->private_value
>> 8) & 1;
594 mutex_lock(&chip
->mixer_mutex
);
595 ucontrol
->value
.integer
.value
[0] = chip
->audio_gain
[capture
][audio
];
596 ucontrol
->value
.integer
.value
[1] = chip
->audio_gain
[capture
][audio
+1];
597 mutex_unlock(&chip
->mixer_mutex
);
601 static int vx_audio_gain_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
603 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
604 int audio
= kcontrol
->private_value
& 0xff;
605 int capture
= (kcontrol
->private_value
>> 8) & 1;
607 mutex_lock(&chip
->mixer_mutex
);
608 if (ucontrol
->value
.integer
.value
[0] != chip
->audio_gain
[capture
][audio
] ||
609 ucontrol
->value
.integer
.value
[1] != chip
->audio_gain
[capture
][audio
+1]) {
610 vx_set_audio_gain(chip
, audio
, capture
, ucontrol
->value
.integer
.value
[0]);
611 vx_set_audio_gain(chip
, audio
+1, capture
, ucontrol
->value
.integer
.value
[1]);
612 mutex_unlock(&chip
->mixer_mutex
);
615 mutex_unlock(&chip
->mixer_mutex
);
619 static int vx_audio_monitor_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
621 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
622 int audio
= kcontrol
->private_value
& 0xff;
624 mutex_lock(&chip
->mixer_mutex
);
625 ucontrol
->value
.integer
.value
[0] = chip
->audio_monitor
[audio
];
626 ucontrol
->value
.integer
.value
[1] = chip
->audio_monitor
[audio
+1];
627 mutex_unlock(&chip
->mixer_mutex
);
631 static int vx_audio_monitor_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
633 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
634 int audio
= kcontrol
->private_value
& 0xff;
636 mutex_lock(&chip
->mixer_mutex
);
637 if (ucontrol
->value
.integer
.value
[0] != chip
->audio_monitor
[audio
] ||
638 ucontrol
->value
.integer
.value
[1] != chip
->audio_monitor
[audio
+1]) {
639 vx_set_monitor_level(chip
, audio
, ucontrol
->value
.integer
.value
[0],
640 chip
->audio_monitor_active
[audio
]);
641 vx_set_monitor_level(chip
, audio
+1, ucontrol
->value
.integer
.value
[1],
642 chip
->audio_monitor_active
[audio
+1]);
643 mutex_unlock(&chip
->mixer_mutex
);
646 mutex_unlock(&chip
->mixer_mutex
);
650 #define vx_audio_sw_info snd_ctl_boolean_stereo_info
652 static int vx_audio_sw_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
654 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
655 int audio
= kcontrol
->private_value
& 0xff;
657 mutex_lock(&chip
->mixer_mutex
);
658 ucontrol
->value
.integer
.value
[0] = chip
->audio_active
[audio
];
659 ucontrol
->value
.integer
.value
[1] = chip
->audio_active
[audio
+1];
660 mutex_unlock(&chip
->mixer_mutex
);
664 static int vx_audio_sw_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
666 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
667 int audio
= kcontrol
->private_value
& 0xff;
669 mutex_lock(&chip
->mixer_mutex
);
670 if (ucontrol
->value
.integer
.value
[0] != chip
->audio_active
[audio
] ||
671 ucontrol
->value
.integer
.value
[1] != chip
->audio_active
[audio
+1]) {
672 vx_set_audio_switch(chip
, audio
, ucontrol
->value
.integer
.value
[0]);
673 vx_set_audio_switch(chip
, audio
+1, ucontrol
->value
.integer
.value
[1]);
674 mutex_unlock(&chip
->mixer_mutex
);
677 mutex_unlock(&chip
->mixer_mutex
);
681 static int vx_monitor_sw_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
683 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
684 int audio
= kcontrol
->private_value
& 0xff;
686 mutex_lock(&chip
->mixer_mutex
);
687 ucontrol
->value
.integer
.value
[0] = chip
->audio_monitor_active
[audio
];
688 ucontrol
->value
.integer
.value
[1] = chip
->audio_monitor_active
[audio
+1];
689 mutex_unlock(&chip
->mixer_mutex
);
693 static int vx_monitor_sw_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
695 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
696 int audio
= kcontrol
->private_value
& 0xff;
698 mutex_lock(&chip
->mixer_mutex
);
699 if (ucontrol
->value
.integer
.value
[0] != chip
->audio_monitor_active
[audio
] ||
700 ucontrol
->value
.integer
.value
[1] != chip
->audio_monitor_active
[audio
+1]) {
701 vx_set_monitor_level(chip
, audio
, chip
->audio_monitor
[audio
],
702 ucontrol
->value
.integer
.value
[0]);
703 vx_set_monitor_level(chip
, audio
+1, chip
->audio_monitor
[audio
+1],
704 ucontrol
->value
.integer
.value
[1]);
705 mutex_unlock(&chip
->mixer_mutex
);
708 mutex_unlock(&chip
->mixer_mutex
);
712 static const DECLARE_TLV_DB_SCALE(db_scale_audio_gain
, -10975, 25, 0);
714 static struct snd_kcontrol_new vx_control_audio_gain
= {
715 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
716 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
717 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
718 /* name will be filled later */
719 .info
= vx_audio_gain_info
,
720 .get
= vx_audio_gain_get
,
721 .put
= vx_audio_gain_put
,
722 .tlv
= { .p
= db_scale_audio_gain
},
724 static struct snd_kcontrol_new vx_control_output_switch
= {
725 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
726 .name
= "PCM Playback Switch",
727 .info
= vx_audio_sw_info
,
728 .get
= vx_audio_sw_get
,
729 .put
= vx_audio_sw_put
731 static struct snd_kcontrol_new vx_control_monitor_gain
= {
732 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
733 .name
= "Monitoring Volume",
734 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
735 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
736 .info
= vx_audio_gain_info
, /* shared */
737 .get
= vx_audio_monitor_get
,
738 .put
= vx_audio_monitor_put
,
739 .tlv
= { .p
= db_scale_audio_gain
},
741 static struct snd_kcontrol_new vx_control_monitor_switch
= {
742 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
743 .name
= "Monitoring Switch",
744 .info
= vx_audio_sw_info
, /* shared */
745 .get
= vx_monitor_sw_get
,
746 .put
= vx_monitor_sw_put
753 static int vx_iec958_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
755 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
760 static int vx_iec958_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
762 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
764 mutex_lock(&chip
->mixer_mutex
);
765 ucontrol
->value
.iec958
.status
[0] = (chip
->uer_bits
>> 0) & 0xff;
766 ucontrol
->value
.iec958
.status
[1] = (chip
->uer_bits
>> 8) & 0xff;
767 ucontrol
->value
.iec958
.status
[2] = (chip
->uer_bits
>> 16) & 0xff;
768 ucontrol
->value
.iec958
.status
[3] = (chip
->uer_bits
>> 24) & 0xff;
769 mutex_unlock(&chip
->mixer_mutex
);
773 static int vx_iec958_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
775 ucontrol
->value
.iec958
.status
[0] = 0xff;
776 ucontrol
->value
.iec958
.status
[1] = 0xff;
777 ucontrol
->value
.iec958
.status
[2] = 0xff;
778 ucontrol
->value
.iec958
.status
[3] = 0xff;
782 static int vx_iec958_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
784 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
787 val
= (ucontrol
->value
.iec958
.status
[0] << 0) |
788 (ucontrol
->value
.iec958
.status
[1] << 8) |
789 (ucontrol
->value
.iec958
.status
[2] << 16) |
790 (ucontrol
->value
.iec958
.status
[3] << 24);
791 mutex_lock(&chip
->mixer_mutex
);
792 if (chip
->uer_bits
!= val
) {
793 chip
->uer_bits
= val
;
794 vx_set_iec958_status(chip
, val
);
795 mutex_unlock(&chip
->mixer_mutex
);
798 mutex_unlock(&chip
->mixer_mutex
);
802 static struct snd_kcontrol_new vx_control_iec958_mask
= {
803 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
804 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
805 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
806 .info
= vx_iec958_info
, /* shared */
807 .get
= vx_iec958_mask_get
,
810 static struct snd_kcontrol_new vx_control_iec958
= {
811 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
812 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
813 .info
= vx_iec958_info
,
814 .get
= vx_iec958_get
,
823 #define METER_MAX 0xff
824 #define METER_SHIFT 16
826 static int vx_vu_meter_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
828 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
830 uinfo
->value
.integer
.min
= 0;
831 uinfo
->value
.integer
.max
= METER_MAX
;
835 static int vx_vu_meter_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
837 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
838 struct vx_vu_meter meter
[2];
839 int audio
= kcontrol
->private_value
& 0xff;
840 int capture
= (kcontrol
->private_value
>> 8) & 1;
842 vx_get_audio_vu_meter(chip
, audio
, capture
, meter
);
843 ucontrol
->value
.integer
.value
[0] = meter
[0].vu_level
>> METER_SHIFT
;
844 ucontrol
->value
.integer
.value
[1] = meter
[1].vu_level
>> METER_SHIFT
;
848 static int vx_peak_meter_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
850 struct vx_core
*chip
= snd_kcontrol_chip(kcontrol
);
851 struct vx_vu_meter meter
[2];
852 int audio
= kcontrol
->private_value
& 0xff;
853 int capture
= (kcontrol
->private_value
>> 8) & 1;
855 vx_get_audio_vu_meter(chip
, audio
, capture
, meter
);
856 ucontrol
->value
.integer
.value
[0] = meter
[0].peak_level
>> METER_SHIFT
;
857 ucontrol
->value
.integer
.value
[1] = meter
[1].peak_level
>> METER_SHIFT
;
861 #define vx_saturation_info snd_ctl_boolean_stereo_info
863 static int vx_saturation_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;
869 vx_get_audio_vu_meter(chip
, audio
, 1, meter
); /* capture only */
870 ucontrol
->value
.integer
.value
[0] = meter
[0].saturated
;
871 ucontrol
->value
.integer
.value
[1] = meter
[1].saturated
;
875 static struct snd_kcontrol_new vx_control_vu_meter
= {
876 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
877 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
878 /* name will be filled later */
879 .info
= vx_vu_meter_info
,
880 .get
= vx_vu_meter_get
,
883 static struct snd_kcontrol_new vx_control_peak_meter
= {
884 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
885 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
886 /* name will be filled later */
887 .info
= vx_vu_meter_info
, /* shared */
888 .get
= vx_peak_meter_get
,
891 static struct snd_kcontrol_new vx_control_saturation
= {
892 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
893 .name
= "Input Saturation",
894 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
895 .info
= vx_saturation_info
,
896 .get
= vx_saturation_get
,
905 int snd_vx_mixer_new(struct vx_core
*chip
)
909 struct snd_kcontrol_new temp
;
910 struct snd_card
*card
= chip
->card
;
913 strcpy(card
->mixername
, card
->driver
);
915 /* output level controls */
916 for (i
= 0; i
< chip
->hw
->num_outs
; i
++) {
917 temp
= vx_control_output_level
;
919 temp
.tlv
.p
= chip
->hw
->output_level_db_scale
;
920 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
924 /* PCM volumes, switches, monitoring */
925 for (i
= 0; i
< chip
->hw
->num_outs
; i
++) {
927 temp
= vx_control_audio_gain
;
929 temp
.name
= "PCM Playback Volume";
930 temp
.private_value
= val
;
931 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
933 temp
= vx_control_output_switch
;
935 temp
.private_value
= val
;
936 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
938 temp
= vx_control_monitor_gain
;
940 temp
.private_value
= val
;
941 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
943 temp
= vx_control_monitor_switch
;
945 temp
.private_value
= val
;
946 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
949 for (i
= 0; i
< chip
->hw
->num_outs
; i
++) {
950 temp
= vx_control_audio_gain
;
952 temp
.name
= "PCM Capture Volume";
953 temp
.private_value
= (i
* 2) | (1 << 8);
954 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
959 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&vx_control_audio_src
, chip
))) < 0)
962 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&vx_control_clock_mode
, chip
))) < 0)
964 /* IEC958 controls */
965 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&vx_control_iec958_mask
, chip
))) < 0)
967 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&vx_control_iec958
, chip
))) < 0)
969 /* VU, peak, saturation meters */
970 for (c
= 0; c
< 2; c
++) {
971 static char *dir
[2] = { "Output", "Input" };
972 for (i
= 0; i
< chip
->hw
->num_ins
; i
++) {
973 int val
= (i
* 2) | (c
<< 8);
975 temp
= vx_control_saturation
;
977 temp
.private_value
= val
;
978 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
981 sprintf(name
, "%s VU Meter", dir
[c
]);
982 temp
= vx_control_vu_meter
;
985 temp
.private_value
= val
;
986 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
988 sprintf(name
, "%s Peak Meter", dir
[c
]);
989 temp
= vx_control_peak_meter
;
992 temp
.private_value
= val
;
993 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&temp
, chip
))) < 0)
997 vx_reset_audio_levels(chip
);