blob: 5a347321f8c037a384a310f696674daa06c7b118 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for Digigram VX soundcards
3 *
4 * Common mixer part
5 *
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
7 *
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.
12 *
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.
17 *
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
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <sound/core.h>
24#include <sound/control.h>
Takashi Iwai1186ed82006-08-23 19:53:28 +020025#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <sound/vx_core.h>
27#include "vx_cmd.h"
28
29
30/*
31 * write a codec data (24bit)
32 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010033static void vx_write_codec_reg(struct vx_core *chip, int codec, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
35 unsigned long flags;
36
37 snd_assert(chip->ops->write_codec, return);
38
39 if (chip->chip_status & VX_STAT_IS_STALE)
40 return;
41
42 spin_lock_irqsave(&chip->lock, flags);
43 chip->ops->write_codec(chip, codec, data);
44 spin_unlock_irqrestore(&chip->lock, flags);
45}
46
47/*
48 * Data type used to access the Codec
49 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010050union vx_codec_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 u32 l;
52#ifdef SNDRV_BIG_ENDIAN
53 struct w {
54 u16 h;
55 u16 l;
56 } w;
57 struct b {
58 u8 hh;
59 u8 mh;
60 u8 ml;
61 u8 ll;
62 } b;
63#else /* LITTLE_ENDIAN */
64 struct w {
65 u16 l;
66 u16 h;
67 } w;
68 struct b {
69 u8 ll;
70 u8 ml;
71 u8 mh;
72 u8 hh;
73 } b;
74#endif
Takashi Iwaiaf263672005-11-17 14:46:59 +010075};
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
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))
81
82/*
83 * set up codec register and write the value
84 * @codec: the codec id, 0 or 1
85 * @reg: register index
86 * @val: data value
87 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010088static void vx_set_codec_reg(struct vx_core *chip, int codec, int reg, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Takashi Iwaiaf263672005-11-17 14:46:59 +010090 union vx_codec_data data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 /* 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);
96}
97
98
99/*
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
104 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100105static void vx_set_analog_output_level(struct vx_core *chip, int codec, int left, int right)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 left = chip->hw->output_level_max - left;
108 right = chip->hw->output_level_max - right;
109
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);
113 } else {
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);
117 }
118}
119
120
121/*
122 * vx_toggle_dac_mute - mute/unmute DAC
123 * @mute: 0 = unmute, 1 = mute
124 */
125
126#define DAC_ATTEN_MIN 0x08
127#define DAC_ATTEN_MAX 0x38
128
Takashi Iwaiaf263672005-11-17 14:46:59 +0100129void vx_toggle_dac_mute(struct vx_core *chip, int mute)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
131 unsigned int i;
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 */
135 else
136 vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER,
137 mute ? DAC_ATTEN_MAX : DAC_ATTEN_MIN);
138 }
139}
140
141/*
142 * vx_reset_codec - reset and initialize the codecs
143 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100144void vx_reset_codec(struct vx_core *chip, int cold_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 unsigned int i;
147 int port = chip->type >= VX_TYPE_VXPOCKET ? 0x75 : 0x65;
148
149 chip->ops->reset_codec(chip);
150
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);
163 }
164 }
165
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);
171 }
172}
173
174/*
175 * change the audio input source
176 * @src: the target source (VX_AUDIO_SRC_XXX)
177 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100178static void vx_change_audio_source(struct vx_core *chip, int src)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
180 unsigned long flags;
181
182 if (chip->chip_status & VX_STAT_IS_STALE)
183 return;
184
185 spin_lock_irqsave(&chip->lock, flags);
186 chip->ops->change_audio_source(chip, src);
187 spin_unlock_irqrestore(&chip->lock, flags);
188}
189
190
191/*
192 * change the audio source if necessary and possible
193 * returns 1 if the source is actually changed.
194 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100195int vx_sync_audio_source(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
197 if (chip->audio_source_target == chip->audio_source ||
198 chip->pcm_running)
199 return 0;
200 vx_change_audio_source(chip, chip->audio_source_target);
201 chip->audio_source = chip->audio_source_target;
202 return 1;
203}
204
205
206/*
207 * audio level, mute, monitoring
208 */
209struct 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;
214 unsigned int mute;
215 unsigned int monitor_mute;
216 short level;
217 short monitor_level;
218};
219
Takashi Iwaiaf263672005-11-17 14:46:59 +0100220static int vx_adjust_audio_level(struct vx_core *chip, int audio, int capture,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 struct vx_audio_level *info)
222{
223 struct vx_rmh rmh;
224
225 if (chip->chip_status & VX_STAT_IS_STALE)
226 return -EBUSY;
227
228 vx_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
229 if (capture)
230 rmh.Cmd[0] |= COMMAND_RECORD_MASK;
231 /* Add Audio IO mask */
232 rmh.Cmd[1] = 1 << audio;
233 rmh.Cmd[2] = 0;
234 if (info->has_level) {
235 rmh.Cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
236 rmh.Cmd[2] |= info->level;
237 }
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);
241 }
242 if (info->has_mute) {
243 rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_LEVEL;
244 if (info->mute)
245 rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_LEVEL;
246 }
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;
252 }
253
254 return vx_send_msg(chip, &rmh);
255}
256
257
258#if 0 // not used
Takashi Iwaiaf263672005-11-17 14:46:59 +0100259static int vx_read_audio_level(struct vx_core *chip, int audio, int capture,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 struct vx_audio_level *info)
261{
262 int err;
263 struct vx_rmh rmh;
264
265 memset(info, 0, sizeof(*info));
266 vx_init_rmh(&rmh, CMD_GET_AUDIO_LEVELS);
267 if (capture)
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);
272 if (err < 0)
273 return err;
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;
278 return 0;
279}
280#endif // not used
281
282/*
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
285 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100286int vx_set_monitor_level(struct vx_core *chip, int audio, int level, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct vx_audio_level info;
289
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 */
298}
299
300
301/*
302 * set the mute status of the given audio
303 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100304static int vx_set_audio_switch(struct vx_core *chip, int audio, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
306 struct vx_audio_level info;
307
308 memset(&info, 0, sizeof(info));
309 info.has_mute = 1;
310 info.mute = !active;
311 chip->audio_active[audio] = active;
312 return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */
313}
314
315/*
316 * set the mute status of the given audio
317 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100318static int vx_set_audio_gain(struct vx_core *chip, int audio, int capture, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
320 struct vx_audio_level info;
321
322 memset(&info, 0, sizeof(info));
323 info.has_level = 1;
324 info.level = level;
325 chip->audio_gain[capture][audio] = level;
326 return vx_adjust_audio_level(chip, audio, capture, &info);
327}
328
329/*
330 * reset all audio levels
331 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100332static void vx_reset_audio_levels(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
334 unsigned int i, c;
335 struct vx_audio_level info;
336
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));
341
342 for (c = 0; c < 2; c++) {
343 for (i = 0; i < chip->hw->num_ins * 2; i++) {
344 memset(&info, 0, sizeof(info));
345 if (c == 0) {
346 info.has_monitor_level = 1;
347 info.has_mute = 1;
348 info.has_monitor_mute = 1;
349 }
350 info.has_level = 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;
355 }
356 }
357}
358
359
360/*
361 * VU, peak meter record
362 */
363
364#define VU_METER_CHANNELS 2
365
366struct vx_vu_meter {
367 int saturated;
368 int vu_level;
369 int peak_level;
370};
371
372/*
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).
377 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100378static int vx_get_audio_vu_meter(struct vx_core *chip, int audio, int capture, struct vx_vu_meter *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
380 struct vx_rmh rmh;
381 int i, err;
382
383 if (chip->chip_status & VX_STAT_IS_STALE)
384 return -EBUSY;
385
386 vx_init_rmh(&rmh, CMD_AUDIO_VU_PIC_METER);
387 rmh.LgStat += 2 * VU_METER_CHANNELS;
388 if (capture)
389 rmh.Cmd[0] |= COMMAND_RECORD_MASK;
390
391 /* Add Audio IO mask */
392 rmh.Cmd[1] = 0;
393 for (i = 0; i < VU_METER_CHANNELS; i++)
394 rmh.Cmd[1] |= 1 << (audio + i);
395 err = vx_send_msg(chip, &rmh);
396 if (err < 0)
397 return err;
398 /* Read response */
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];
403 info++;
404 }
405 return 0;
406}
407
408
409/*
410 * control API entries
411 */
412
413/*
414 * output level control
415 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100416static int vx_output_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100418 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
420 uinfo->count = 2;
421 uinfo->value.integer.min = 0;
422 uinfo->value.integer.max = chip->hw->output_level_max;
423 return 0;
424}
425
Takashi Iwaiaf263672005-11-17 14:46:59 +0100426static int vx_output_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100428 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 int codec = kcontrol->id.index;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100430 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 ucontrol->value.integer.value[0] = chip->output_level[codec][0];
432 ucontrol->value.integer.value[1] = chip->output_level[codec][1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100433 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return 0;
435}
436
Takashi Iwaiaf263672005-11-17 14:46:59 +0100437static int vx_output_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100439 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 int codec = kcontrol->id.index;
Takashi Iwaid05ab182007-11-15 16:13:32 +0100441 unsigned int val[2], vmax;
442
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)
447 return -EINVAL;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100448 mutex_lock(&chip->mixer_mutex);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100449 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];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100454 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return 1;
456 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100457 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return 0;
459}
460
Takashi Iwaiaf263672005-11-17 14:46:59 +0100461static struct snd_kcontrol_new vx_control_output_level = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200463 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
464 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .name = "Master Playback Volume",
466 .info = vx_output_level_info,
467 .get = vx_output_level_get,
468 .put = vx_output_level_put,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200469 /* tlv will be filled later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470};
471
472/*
473 * audio source select
474 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100475static int vx_audio_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
477 static char *texts_mic[3] = {
478 "Digital", "Line", "Mic"
479 };
480 static char *texts_vx2[2] = {
481 "Digital", "Analog"
482 };
Takashi Iwaiaf263672005-11-17 14:46:59 +0100483 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
486 uinfo->count = 1;
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]);
493 } else {
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]);
499 }
500 return 0;
501}
502
Takashi Iwaiaf263672005-11-17 14:46:59 +0100503static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100505 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 ucontrol->value.enumerated.item[0] = chip->audio_source_target;
507 return 0;
508}
509
Takashi Iwaiaf263672005-11-17 14:46:59 +0100510static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100512 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100513
514 if (chip->type >= VX_TYPE_VXPOCKET) {
515 if (ucontrol->value.enumerated.item[0] > 2)
516 return -EINVAL;
517 } else {
518 if (ucontrol->value.enumerated.item[0] > 1)
519 return -EINVAL;
520 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100521 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 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);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100525 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return 1;
527 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100528 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 return 0;
530}
531
Takashi Iwaiaf263672005-11-17 14:46:59 +0100532static struct snd_kcontrol_new vx_control_audio_src = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 .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,
538};
539
540/*
541 * clock mode selection
542 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100543static int vx_clock_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
545 static char *texts[3] = {
546 "Auto", "Internal", "External"
547 };
548
549 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
550 uinfo->count = 1;
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]);
556 return 0;
557}
558
Takashi Iwaiaf263672005-11-17 14:46:59 +0100559static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100561 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 ucontrol->value.enumerated.item[0] = chip->clock_mode;
563 return 0;
564}
565
Takashi Iwaiaf263672005-11-17 14:46:59 +0100566static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100568 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100569
570 if (ucontrol->value.enumerated.item[0] > 2)
571 return -EINVAL;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100572 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 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);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100576 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 return 1;
578 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100579 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return 0;
581}
582
Takashi Iwaiaf263672005-11-17 14:46:59 +0100583static struct snd_kcontrol_new vx_control_clock_mode = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 .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,
589};
590
591/*
592 * Audio Gain
593 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100594static int vx_audio_gain_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
596 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
597 uinfo->count = 2;
598 uinfo->value.integer.min = 0;
599 uinfo->value.integer.max = CVAL_MAX;
600 return 0;
601}
602
Takashi Iwaiaf263672005-11-17 14:46:59 +0100603static int vx_audio_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100605 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 int audio = kcontrol->private_value & 0xff;
607 int capture = (kcontrol->private_value >> 8) & 1;
608
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100609 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio];
611 ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100612 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return 0;
614}
615
Takashi Iwaiaf263672005-11-17 14:46:59 +0100616static int vx_audio_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100618 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 int audio = kcontrol->private_value & 0xff;
620 int capture = (kcontrol->private_value >> 8) & 1;
Takashi Iwaid05ab182007-11-15 16:13:32 +0100621 unsigned int val[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Takashi Iwaid05ab182007-11-15 16:13:32 +0100623 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)
626 return -EINVAL;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100627 mutex_lock(&chip->mixer_mutex);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100628 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]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100632 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 return 1;
634 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100635 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 return 0;
637}
638
Takashi Iwaiaf263672005-11-17 14:46:59 +0100639static int vx_audio_monitor_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100641 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 int audio = kcontrol->private_value & 0xff;
643
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100644 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 ucontrol->value.integer.value[0] = chip->audio_monitor[audio];
646 ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100647 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return 0;
649}
650
Takashi Iwaiaf263672005-11-17 14:46:59 +0100651static int vx_audio_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100653 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 int audio = kcontrol->private_value & 0xff;
Takashi Iwaid05ab182007-11-15 16:13:32 +0100655 unsigned int val[2];
656
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)
660 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100662 mutex_lock(&chip->mixer_mutex);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100663 if (val[0] != chip->audio_monitor[audio] ||
664 val[1] != chip->audio_monitor[audio+1]) {
665 vx_set_monitor_level(chip, audio, val[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 chip->audio_monitor_active[audio]);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100667 vx_set_monitor_level(chip, audio+1, val[1],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 chip->audio_monitor_active[audio+1]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100669 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 return 1;
671 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100672 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 return 0;
674}
675
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200676#define vx_audio_sw_info snd_ctl_boolean_stereo_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Takashi Iwaiaf263672005-11-17 14:46:59 +0100678static int vx_audio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100680 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 int audio = kcontrol->private_value & 0xff;
682
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100683 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 ucontrol->value.integer.value[0] = chip->audio_active[audio];
685 ucontrol->value.integer.value[1] = chip->audio_active[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100686 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 return 0;
688}
689
Takashi Iwaiaf263672005-11-17 14:46:59 +0100690static int vx_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100692 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 int audio = kcontrol->private_value & 0xff;
694
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100695 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (ucontrol->value.integer.value[0] != chip->audio_active[audio] ||
697 ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) {
Takashi Iwaid05ab182007-11-15 16:13:32 +0100698 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]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100702 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 return 1;
704 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100705 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 return 0;
707}
708
Takashi Iwaiaf263672005-11-17 14:46:59 +0100709static int vx_monitor_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100711 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 int audio = kcontrol->private_value & 0xff;
713
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100714 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio];
716 ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100717 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 return 0;
719}
720
Takashi Iwaiaf263672005-11-17 14:46:59 +0100721static int vx_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100723 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 int audio = kcontrol->private_value & 0xff;
725
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100726 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 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],
Takashi Iwaid05ab182007-11-15 16:13:32 +0100730 !!ucontrol->value.integer.value[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1],
Takashi Iwaid05ab182007-11-15 16:13:32 +0100732 !!ucontrol->value.integer.value[1]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100733 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return 1;
735 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100736 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 return 0;
738}
739
Takashi Iwai0cb29ea2007-01-29 15:33:49 +0100740static const DECLARE_TLV_DB_SCALE(db_scale_audio_gain, -10975, 25, 0);
Takashi Iwai1186ed82006-08-23 19:53:28 +0200741
Takashi Iwaiaf263672005-11-17 14:46:59 +0100742static struct snd_kcontrol_new vx_control_audio_gain = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200744 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
745 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 /* name will be filled later */
747 .info = vx_audio_gain_info,
748 .get = vx_audio_gain_get,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200749 .put = vx_audio_gain_put,
750 .tlv = { .p = db_scale_audio_gain },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100752static struct snd_kcontrol_new vx_control_output_switch = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 .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
758};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100759static struct snd_kcontrol_new vx_control_monitor_gain = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
761 .name = "Monitoring Volume",
Takashi Iwai1186ed82006-08-23 19:53:28 +0200762 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
763 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .info = vx_audio_gain_info, /* shared */
765 .get = vx_audio_monitor_get,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200766 .put = vx_audio_monitor_put,
767 .tlv = { .p = db_scale_audio_gain },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100769static struct snd_kcontrol_new vx_control_monitor_switch = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 .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
775};
776
777
778/*
779 * IEC958 status bits
780 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100781static int vx_iec958_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
783 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
784 uinfo->count = 1;
785 return 0;
786}
787
Takashi Iwaiaf263672005-11-17 14:46:59 +0100788static int vx_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100790 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100792 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 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;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100797 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 return 0;
799}
800
Takashi Iwaiaf263672005-11-17 14:46:59 +0100801static int vx_iec958_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
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;
807 return 0;
808}
809
Takashi Iwaiaf263672005-11-17 14:46:59 +0100810static int vx_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100812 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 unsigned int val;
814
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);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100819 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (chip->uer_bits != val) {
821 chip->uer_bits = val;
822 vx_set_iec958_status(chip, val);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100823 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 return 1;
825 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100826 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return 0;
828}
829
Takashi Iwaiaf263672005-11-17 14:46:59 +0100830static struct snd_kcontrol_new vx_control_iec958_mask = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch5549d542005-08-03 13:50:30 +0200832 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
834 .info = vx_iec958_info, /* shared */
835 .get = vx_iec958_mask_get,
836};
837
Takashi Iwaiaf263672005-11-17 14:46:59 +0100838static struct snd_kcontrol_new vx_control_iec958 = {
Clemens Ladisch5549d542005-08-03 13:50:30 +0200839 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
841 .info = vx_iec958_info,
842 .get = vx_iec958_get,
843 .put = vx_iec958_put
844};
845
846
847/*
848 * VU meter
849 */
850
851#define METER_MAX 0xff
852#define METER_SHIFT 16
853
Takashi Iwaiaf263672005-11-17 14:46:59 +0100854static int vx_vu_meter_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
857 uinfo->count = 2;
858 uinfo->value.integer.min = 0;
859 uinfo->value.integer.max = METER_MAX;
860 return 0;
861}
862
Takashi Iwaiaf263672005-11-17 14:46:59 +0100863static int vx_vu_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100865 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 struct vx_vu_meter meter[2];
867 int audio = kcontrol->private_value & 0xff;
868 int capture = (kcontrol->private_value >> 8) & 1;
869
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;
873 return 0;
874}
875
Takashi Iwaiaf263672005-11-17 14:46:59 +0100876static int vx_peak_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100878 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 struct vx_vu_meter meter[2];
880 int audio = kcontrol->private_value & 0xff;
881 int capture = (kcontrol->private_value >> 8) & 1;
882
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;
886 return 0;
887}
888
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200889#define vx_saturation_info snd_ctl_boolean_stereo_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Takashi Iwaiaf263672005-11-17 14:46:59 +0100891static int vx_saturation_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100893 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 struct vx_vu_meter meter[2];
895 int audio = kcontrol->private_value & 0xff;
896
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;
900 return 0;
901}
902
Takashi Iwaiaf263672005-11-17 14:46:59 +0100903static struct snd_kcontrol_new vx_control_vu_meter = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 .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,
909};
910
Takashi Iwaiaf263672005-11-17 14:46:59 +0100911static struct snd_kcontrol_new vx_control_peak_meter = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 .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,
917};
918
Takashi Iwaiaf263672005-11-17 14:46:59 +0100919static struct snd_kcontrol_new vx_control_saturation = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 .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,
925};
926
927
928
929/*
930 *
931 */
932
Takashi Iwaiaf263672005-11-17 14:46:59 +0100933int snd_vx_mixer_new(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 unsigned int i, c;
936 int err;
Takashi Iwaiaf263672005-11-17 14:46:59 +0100937 struct snd_kcontrol_new temp;
938 struct snd_card *card = chip->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 char name[32];
940
941 strcpy(card->mixername, card->driver);
942
943 /* output level controls */
944 for (i = 0; i < chip->hw->num_outs; i++) {
945 temp = vx_control_output_level;
946 temp.index = i;
Takashi Iwai1186ed82006-08-23 19:53:28 +0200947 temp.tlv.p = chip->hw->output_level_db_scale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
949 return err;
950 }
951
952 /* PCM volumes, switches, monitoring */
953 for (i = 0; i < chip->hw->num_outs; i++) {
954 int val = i * 2;
955 temp = vx_control_audio_gain;
956 temp.index = i;
957 temp.name = "PCM Playback Volume";
958 temp.private_value = val;
959 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
960 return err;
961 temp = vx_control_output_switch;
962 temp.index = i;
963 temp.private_value = val;
964 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
965 return err;
966 temp = vx_control_monitor_gain;
967 temp.index = i;
968 temp.private_value = val;
969 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
970 return err;
971 temp = vx_control_monitor_switch;
972 temp.index = i;
973 temp.private_value = val;
974 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
975 return err;
976 }
977 for (i = 0; i < chip->hw->num_outs; i++) {
978 temp = vx_control_audio_gain;
979 temp.index = i;
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)
983 return err;
984 }
985
986 /* Audio source */
987 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_audio_src, chip))) < 0)
988 return err;
989 /* clock mode */
990 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_clock_mode, chip))) < 0)
991 return err;
992 /* IEC958 controls */
993 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958_mask, chip))) < 0)
994 return err;
995 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958, chip))) < 0)
996 return err;
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);
1002 if (c == 1) {
1003 temp = vx_control_saturation;
1004 temp.index = i;
1005 temp.private_value = val;
1006 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
1007 return err;
1008 }
1009 sprintf(name, "%s VU Meter", dir[c]);
1010 temp = vx_control_vu_meter;
1011 temp.index = i;
1012 temp.name = name;
1013 temp.private_value = val;
1014 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
1015 return err;
1016 sprintf(name, "%s Peak Meter", dir[c]);
1017 temp = vx_control_peak_meter;
1018 temp.index = i;
1019 temp.name = name;
1020 temp.private_value = val;
1021 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
1022 return err;
1023 }
1024 }
1025 vx_reset_audio_levels(chip);
1026 return 0;
1027}