blob: 1613ed844ac6228e40574301511f72054a530a87 [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
23#include <sound/driver.h>
24#include <sound/core.h>
25#include <sound/control.h>
Takashi Iwai1186ed82006-08-23 19:53:28 +020026#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <sound/vx_core.h>
28#include "vx_cmd.h"
29
30
31/*
32 * write a codec data (24bit)
33 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010034static void vx_write_codec_reg(struct vx_core *chip, int codec, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
36 unsigned long flags;
37
38 snd_assert(chip->ops->write_codec, return);
39
40 if (chip->chip_status & VX_STAT_IS_STALE)
41 return;
42
43 spin_lock_irqsave(&chip->lock, flags);
44 chip->ops->write_codec(chip, codec, data);
45 spin_unlock_irqrestore(&chip->lock, flags);
46}
47
48/*
49 * Data type used to access the Codec
50 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010051union vx_codec_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 u32 l;
53#ifdef SNDRV_BIG_ENDIAN
54 struct w {
55 u16 h;
56 u16 l;
57 } w;
58 struct b {
59 u8 hh;
60 u8 mh;
61 u8 ml;
62 u8 ll;
63 } b;
64#else /* LITTLE_ENDIAN */
65 struct w {
66 u16 l;
67 u16 h;
68 } w;
69 struct b {
70 u8 ll;
71 u8 ml;
72 u8 mh;
73 u8 hh;
74 } b;
75#endif
Takashi Iwaiaf263672005-11-17 14:46:59 +010076};
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
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))
82
83/*
84 * set up codec register and write the value
85 * @codec: the codec id, 0 or 1
86 * @reg: register index
87 * @val: data value
88 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010089static void vx_set_codec_reg(struct vx_core *chip, int codec, int reg, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Takashi Iwaiaf263672005-11-17 14:46:59 +010091 union vx_codec_data data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 /* 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);
97}
98
99
100/*
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
105 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100106static void vx_set_analog_output_level(struct vx_core *chip, int codec, int left, int right)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 left = chip->hw->output_level_max - left;
109 right = chip->hw->output_level_max - right;
110
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);
114 } else {
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);
118 }
119}
120
121
122/*
123 * vx_toggle_dac_mute - mute/unmute DAC
124 * @mute: 0 = unmute, 1 = mute
125 */
126
127#define DAC_ATTEN_MIN 0x08
128#define DAC_ATTEN_MAX 0x38
129
Takashi Iwaiaf263672005-11-17 14:46:59 +0100130void vx_toggle_dac_mute(struct vx_core *chip, int mute)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
132 unsigned int i;
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 */
136 else
137 vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER,
138 mute ? DAC_ATTEN_MAX : DAC_ATTEN_MIN);
139 }
140}
141
142/*
143 * vx_reset_codec - reset and initialize the codecs
144 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100145void vx_reset_codec(struct vx_core *chip, int cold_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 unsigned int i;
148 int port = chip->type >= VX_TYPE_VXPOCKET ? 0x75 : 0x65;
149
150 chip->ops->reset_codec(chip);
151
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);
164 }
165 }
166
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);
172 }
173}
174
175/*
176 * change the audio input source
177 * @src: the target source (VX_AUDIO_SRC_XXX)
178 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100179static void vx_change_audio_source(struct vx_core *chip, int src)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 unsigned long flags;
182
183 if (chip->chip_status & VX_STAT_IS_STALE)
184 return;
185
186 spin_lock_irqsave(&chip->lock, flags);
187 chip->ops->change_audio_source(chip, src);
188 spin_unlock_irqrestore(&chip->lock, flags);
189}
190
191
192/*
193 * change the audio source if necessary and possible
194 * returns 1 if the source is actually changed.
195 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100196int vx_sync_audio_source(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198 if (chip->audio_source_target == chip->audio_source ||
199 chip->pcm_running)
200 return 0;
201 vx_change_audio_source(chip, chip->audio_source_target);
202 chip->audio_source = chip->audio_source_target;
203 return 1;
204}
205
206
207/*
208 * audio level, mute, monitoring
209 */
210struct 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;
215 unsigned int mute;
216 unsigned int monitor_mute;
217 short level;
218 short monitor_level;
219};
220
Takashi Iwaiaf263672005-11-17 14:46:59 +0100221static int vx_adjust_audio_level(struct vx_core *chip, int audio, int capture,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 struct vx_audio_level *info)
223{
224 struct vx_rmh rmh;
225
226 if (chip->chip_status & VX_STAT_IS_STALE)
227 return -EBUSY;
228
229 vx_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
230 if (capture)
231 rmh.Cmd[0] |= COMMAND_RECORD_MASK;
232 /* Add Audio IO mask */
233 rmh.Cmd[1] = 1 << audio;
234 rmh.Cmd[2] = 0;
235 if (info->has_level) {
236 rmh.Cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
237 rmh.Cmd[2] |= info->level;
238 }
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);
242 }
243 if (info->has_mute) {
244 rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_LEVEL;
245 if (info->mute)
246 rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_LEVEL;
247 }
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;
253 }
254
255 return vx_send_msg(chip, &rmh);
256}
257
258
259#if 0 // not used
Takashi Iwaiaf263672005-11-17 14:46:59 +0100260static int vx_read_audio_level(struct vx_core *chip, int audio, int capture,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 struct vx_audio_level *info)
262{
263 int err;
264 struct vx_rmh rmh;
265
266 memset(info, 0, sizeof(*info));
267 vx_init_rmh(&rmh, CMD_GET_AUDIO_LEVELS);
268 if (capture)
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);
273 if (err < 0)
274 return err;
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;
279 return 0;
280}
281#endif // not used
282
283/*
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
286 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100287int vx_set_monitor_level(struct vx_core *chip, int audio, int level, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 struct vx_audio_level info;
290
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 */
299}
300
301
302/*
303 * set the mute status of the given audio
304 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100305static int vx_set_audio_switch(struct vx_core *chip, int audio, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
307 struct vx_audio_level info;
308
309 memset(&info, 0, sizeof(info));
310 info.has_mute = 1;
311 info.mute = !active;
312 chip->audio_active[audio] = active;
313 return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */
314}
315
316/*
317 * set the mute status of the given audio
318 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100319static int vx_set_audio_gain(struct vx_core *chip, int audio, int capture, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 struct vx_audio_level info;
322
323 memset(&info, 0, sizeof(info));
324 info.has_level = 1;
325 info.level = level;
326 chip->audio_gain[capture][audio] = level;
327 return vx_adjust_audio_level(chip, audio, capture, &info);
328}
329
330/*
331 * reset all audio levels
332 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100333static void vx_reset_audio_levels(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 unsigned int i, c;
336 struct vx_audio_level info;
337
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));
342
343 for (c = 0; c < 2; c++) {
344 for (i = 0; i < chip->hw->num_ins * 2; i++) {
345 memset(&info, 0, sizeof(info));
346 if (c == 0) {
347 info.has_monitor_level = 1;
348 info.has_mute = 1;
349 info.has_monitor_mute = 1;
350 }
351 info.has_level = 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;
356 }
357 }
358}
359
360
361/*
362 * VU, peak meter record
363 */
364
365#define VU_METER_CHANNELS 2
366
367struct vx_vu_meter {
368 int saturated;
369 int vu_level;
370 int peak_level;
371};
372
373/*
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).
378 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100379static 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 -0700380{
381 struct vx_rmh rmh;
382 int i, err;
383
384 if (chip->chip_status & VX_STAT_IS_STALE)
385 return -EBUSY;
386
387 vx_init_rmh(&rmh, CMD_AUDIO_VU_PIC_METER);
388 rmh.LgStat += 2 * VU_METER_CHANNELS;
389 if (capture)
390 rmh.Cmd[0] |= COMMAND_RECORD_MASK;
391
392 /* Add Audio IO mask */
393 rmh.Cmd[1] = 0;
394 for (i = 0; i < VU_METER_CHANNELS; i++)
395 rmh.Cmd[1] |= 1 << (audio + i);
396 err = vx_send_msg(chip, &rmh);
397 if (err < 0)
398 return err;
399 /* Read response */
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];
404 info++;
405 }
406 return 0;
407}
408
409
410/*
411 * control API entries
412 */
413
414/*
415 * output level control
416 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100417static int vx_output_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100419 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
421 uinfo->count = 2;
422 uinfo->value.integer.min = 0;
423 uinfo->value.integer.max = chip->hw->output_level_max;
424 return 0;
425}
426
Takashi Iwaiaf263672005-11-17 14:46:59 +0100427static int vx_output_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100429 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 int codec = kcontrol->id.index;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100431 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 ucontrol->value.integer.value[0] = chip->output_level[codec][0];
433 ucontrol->value.integer.value[1] = chip->output_level[codec][1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100434 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 return 0;
436}
437
Takashi Iwaiaf263672005-11-17 14:46:59 +0100438static int vx_output_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100440 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 int codec = kcontrol->id.index;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100442 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 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];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100450 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 return 1;
452 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100453 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 return 0;
455}
456
Takashi Iwaiaf263672005-11-17 14:46:59 +0100457static struct snd_kcontrol_new vx_control_output_level = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200459 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
460 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 .name = "Master Playback Volume",
462 .info = vx_output_level_info,
463 .get = vx_output_level_get,
464 .put = vx_output_level_put,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200465 /* tlv will be filled later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466};
467
468/*
469 * audio source select
470 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100471static int vx_audio_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
473 static char *texts_mic[3] = {
474 "Digital", "Line", "Mic"
475 };
476 static char *texts_vx2[2] = {
477 "Digital", "Analog"
478 };
Takashi Iwaiaf263672005-11-17 14:46:59 +0100479 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
482 uinfo->count = 1;
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]);
489 } else {
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]);
495 }
496 return 0;
497}
498
Takashi Iwaiaf263672005-11-17 14:46:59 +0100499static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100501 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 ucontrol->value.enumerated.item[0] = chip->audio_source_target;
503 return 0;
504}
505
Takashi Iwaiaf263672005-11-17 14:46:59 +0100506static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100508 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100509 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 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);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100513 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return 1;
515 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100516 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return 0;
518}
519
Takashi Iwaiaf263672005-11-17 14:46:59 +0100520static struct snd_kcontrol_new vx_control_audio_src = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 .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,
526};
527
528/*
529 * clock mode selection
530 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100531static int vx_clock_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
533 static char *texts[3] = {
534 "Auto", "Internal", "External"
535 };
536
537 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
538 uinfo->count = 1;
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]);
544 return 0;
545}
546
Takashi Iwaiaf263672005-11-17 14:46:59 +0100547static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100549 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 ucontrol->value.enumerated.item[0] = chip->clock_mode;
551 return 0;
552}
553
Takashi Iwaiaf263672005-11-17 14:46:59 +0100554static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100556 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100557 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 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);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100561 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 return 1;
563 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100564 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return 0;
566}
567
Takashi Iwaiaf263672005-11-17 14:46:59 +0100568static struct snd_kcontrol_new vx_control_clock_mode = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 .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,
574};
575
576/*
577 * Audio Gain
578 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100579static int vx_audio_gain_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
581 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
582 uinfo->count = 2;
583 uinfo->value.integer.min = 0;
584 uinfo->value.integer.max = CVAL_MAX;
585 return 0;
586}
587
Takashi Iwaiaf263672005-11-17 14:46:59 +0100588static int vx_audio_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100590 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 int audio = kcontrol->private_value & 0xff;
592 int capture = (kcontrol->private_value >> 8) & 1;
593
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100594 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio];
596 ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100597 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 return 0;
599}
600
Takashi Iwaiaf263672005-11-17 14:46:59 +0100601static int vx_audio_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100603 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 int audio = kcontrol->private_value & 0xff;
605 int capture = (kcontrol->private_value >> 8) & 1;
606
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100607 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 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]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100612 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return 1;
614 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100615 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 return 0;
617}
618
Takashi Iwaiaf263672005-11-17 14:46:59 +0100619static int vx_audio_monitor_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100621 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 int audio = kcontrol->private_value & 0xff;
623
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100624 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 ucontrol->value.integer.value[0] = chip->audio_monitor[audio];
626 ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100627 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return 0;
629}
630
Takashi Iwaiaf263672005-11-17 14:46:59 +0100631static int vx_audio_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100633 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 int audio = kcontrol->private_value & 0xff;
635
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100636 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 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]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100643 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return 1;
645 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100646 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 return 0;
648}
649
Takashi Iwaiaf263672005-11-17 14:46:59 +0100650static int vx_audio_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
652 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
653 uinfo->count = 2;
654 uinfo->value.integer.min = 0;
655 uinfo->value.integer.max = 1;
656 return 0;
657}
658
Takashi Iwaiaf263672005-11-17 14:46:59 +0100659static int vx_audio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100661 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 int audio = kcontrol->private_value & 0xff;
663
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100664 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 ucontrol->value.integer.value[0] = chip->audio_active[audio];
666 ucontrol->value.integer.value[1] = chip->audio_active[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100667 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return 0;
669}
670
Takashi Iwaiaf263672005-11-17 14:46:59 +0100671static int vx_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100673 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 int audio = kcontrol->private_value & 0xff;
675
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100676 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 if (ucontrol->value.integer.value[0] != chip->audio_active[audio] ||
678 ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) {
679 vx_set_audio_switch(chip, audio, ucontrol->value.integer.value[0]);
680 vx_set_audio_switch(chip, audio+1, ucontrol->value.integer.value[1]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100681 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 return 1;
683 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100684 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 return 0;
686}
687
Takashi Iwaiaf263672005-11-17 14:46:59 +0100688static int vx_monitor_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100690 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 int audio = kcontrol->private_value & 0xff;
692
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100693 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio];
695 ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100696 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 return 0;
698}
699
Takashi Iwaiaf263672005-11-17 14:46:59 +0100700static int vx_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100702 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 int audio = kcontrol->private_value & 0xff;
704
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100705 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] ||
707 ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) {
708 vx_set_monitor_level(chip, audio, chip->audio_monitor[audio],
709 ucontrol->value.integer.value[0]);
710 vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1],
711 ucontrol->value.integer.value[1]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100712 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 return 1;
714 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100715 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 return 0;
717}
718
Takashi Iwai1186ed82006-08-23 19:53:28 +0200719static DECLARE_TLV_DB_SCALE(db_scale_audio_gain, -10975, 25, 0);
720
Takashi Iwaiaf263672005-11-17 14:46:59 +0100721static struct snd_kcontrol_new vx_control_audio_gain = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200723 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
724 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 /* name will be filled later */
726 .info = vx_audio_gain_info,
727 .get = vx_audio_gain_get,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200728 .put = vx_audio_gain_put,
729 .tlv = { .p = db_scale_audio_gain },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100731static struct snd_kcontrol_new vx_control_output_switch = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
733 .name = "PCM Playback Switch",
734 .info = vx_audio_sw_info,
735 .get = vx_audio_sw_get,
736 .put = vx_audio_sw_put
737};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100738static struct snd_kcontrol_new vx_control_monitor_gain = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
740 .name = "Monitoring Volume",
Takashi Iwai1186ed82006-08-23 19:53:28 +0200741 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
742 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 .info = vx_audio_gain_info, /* shared */
744 .get = vx_audio_monitor_get,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200745 .put = vx_audio_monitor_put,
746 .tlv = { .p = db_scale_audio_gain },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100748static struct snd_kcontrol_new vx_control_monitor_switch = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
750 .name = "Monitoring Switch",
751 .info = vx_audio_sw_info, /* shared */
752 .get = vx_monitor_sw_get,
753 .put = vx_monitor_sw_put
754};
755
756
757/*
758 * IEC958 status bits
759 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100760static int vx_iec958_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761{
762 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
763 uinfo->count = 1;
764 return 0;
765}
766
Takashi Iwaiaf263672005-11-17 14:46:59 +0100767static int vx_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100769 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100771 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 ucontrol->value.iec958.status[0] = (chip->uer_bits >> 0) & 0xff;
773 ucontrol->value.iec958.status[1] = (chip->uer_bits >> 8) & 0xff;
774 ucontrol->value.iec958.status[2] = (chip->uer_bits >> 16) & 0xff;
775 ucontrol->value.iec958.status[3] = (chip->uer_bits >> 24) & 0xff;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100776 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 return 0;
778}
779
Takashi Iwaiaf263672005-11-17 14:46:59 +0100780static int vx_iec958_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
782 ucontrol->value.iec958.status[0] = 0xff;
783 ucontrol->value.iec958.status[1] = 0xff;
784 ucontrol->value.iec958.status[2] = 0xff;
785 ucontrol->value.iec958.status[3] = 0xff;
786 return 0;
787}
788
Takashi Iwaiaf263672005-11-17 14:46:59 +0100789static int vx_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100791 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 unsigned int val;
793
794 val = (ucontrol->value.iec958.status[0] << 0) |
795 (ucontrol->value.iec958.status[1] << 8) |
796 (ucontrol->value.iec958.status[2] << 16) |
797 (ucontrol->value.iec958.status[3] << 24);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100798 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (chip->uer_bits != val) {
800 chip->uer_bits = val;
801 vx_set_iec958_status(chip, val);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100802 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return 1;
804 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100805 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 return 0;
807}
808
Takashi Iwaiaf263672005-11-17 14:46:59 +0100809static struct snd_kcontrol_new vx_control_iec958_mask = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch5549d542005-08-03 13:50:30 +0200811 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
813 .info = vx_iec958_info, /* shared */
814 .get = vx_iec958_mask_get,
815};
816
Takashi Iwaiaf263672005-11-17 14:46:59 +0100817static struct snd_kcontrol_new vx_control_iec958 = {
Clemens Ladisch5549d542005-08-03 13:50:30 +0200818 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
820 .info = vx_iec958_info,
821 .get = vx_iec958_get,
822 .put = vx_iec958_put
823};
824
825
826/*
827 * VU meter
828 */
829
830#define METER_MAX 0xff
831#define METER_SHIFT 16
832
Takashi Iwaiaf263672005-11-17 14:46:59 +0100833static int vx_vu_meter_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
835 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
836 uinfo->count = 2;
837 uinfo->value.integer.min = 0;
838 uinfo->value.integer.max = METER_MAX;
839 return 0;
840}
841
Takashi Iwaiaf263672005-11-17 14:46:59 +0100842static int vx_vu_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100844 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 struct vx_vu_meter meter[2];
846 int audio = kcontrol->private_value & 0xff;
847 int capture = (kcontrol->private_value >> 8) & 1;
848
849 vx_get_audio_vu_meter(chip, audio, capture, meter);
850 ucontrol->value.integer.value[0] = meter[0].vu_level >> METER_SHIFT;
851 ucontrol->value.integer.value[1] = meter[1].vu_level >> METER_SHIFT;
852 return 0;
853}
854
Takashi Iwaiaf263672005-11-17 14:46:59 +0100855static int vx_peak_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100857 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 struct vx_vu_meter meter[2];
859 int audio = kcontrol->private_value & 0xff;
860 int capture = (kcontrol->private_value >> 8) & 1;
861
862 vx_get_audio_vu_meter(chip, audio, capture, meter);
863 ucontrol->value.integer.value[0] = meter[0].peak_level >> METER_SHIFT;
864 ucontrol->value.integer.value[1] = meter[1].peak_level >> METER_SHIFT;
865 return 0;
866}
867
Takashi Iwaiaf263672005-11-17 14:46:59 +0100868static int vx_saturation_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
870 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
871 uinfo->count = 2;
872 uinfo->value.integer.min = 0;
873 uinfo->value.integer.max = 1;
874 return 0;
875}
876
Takashi Iwaiaf263672005-11-17 14:46:59 +0100877static int vx_saturation_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100879 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 struct vx_vu_meter meter[2];
881 int audio = kcontrol->private_value & 0xff;
882
883 vx_get_audio_vu_meter(chip, audio, 1, meter); /* capture only */
884 ucontrol->value.integer.value[0] = meter[0].saturated;
885 ucontrol->value.integer.value[1] = meter[1].saturated;
886 return 0;
887}
888
Takashi Iwaiaf263672005-11-17 14:46:59 +0100889static struct snd_kcontrol_new vx_control_vu_meter = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
891 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
892 /* name will be filled later */
893 .info = vx_vu_meter_info,
894 .get = vx_vu_meter_get,
895};
896
Takashi Iwaiaf263672005-11-17 14:46:59 +0100897static struct snd_kcontrol_new vx_control_peak_meter = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
899 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
900 /* name will be filled later */
901 .info = vx_vu_meter_info, /* shared */
902 .get = vx_peak_meter_get,
903};
904
Takashi Iwaiaf263672005-11-17 14:46:59 +0100905static struct snd_kcontrol_new vx_control_saturation = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
907 .name = "Input Saturation",
908 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
909 .info = vx_saturation_info,
910 .get = vx_saturation_get,
911};
912
913
914
915/*
916 *
917 */
918
Takashi Iwaiaf263672005-11-17 14:46:59 +0100919int snd_vx_mixer_new(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
921 unsigned int i, c;
922 int err;
Takashi Iwaiaf263672005-11-17 14:46:59 +0100923 struct snd_kcontrol_new temp;
924 struct snd_card *card = chip->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 char name[32];
926
927 strcpy(card->mixername, card->driver);
928
929 /* output level controls */
930 for (i = 0; i < chip->hw->num_outs; i++) {
931 temp = vx_control_output_level;
932 temp.index = i;
Takashi Iwai1186ed82006-08-23 19:53:28 +0200933 temp.tlv.p = chip->hw->output_level_db_scale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
935 return err;
936 }
937
938 /* PCM volumes, switches, monitoring */
939 for (i = 0; i < chip->hw->num_outs; i++) {
940 int val = i * 2;
941 temp = vx_control_audio_gain;
942 temp.index = i;
943 temp.name = "PCM Playback Volume";
944 temp.private_value = val;
945 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
946 return err;
947 temp = vx_control_output_switch;
948 temp.index = i;
949 temp.private_value = val;
950 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
951 return err;
952 temp = vx_control_monitor_gain;
953 temp.index = i;
954 temp.private_value = val;
955 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
956 return err;
957 temp = vx_control_monitor_switch;
958 temp.index = i;
959 temp.private_value = val;
960 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
961 return err;
962 }
963 for (i = 0; i < chip->hw->num_outs; i++) {
964 temp = vx_control_audio_gain;
965 temp.index = i;
966 temp.name = "PCM Capture Volume";
967 temp.private_value = (i * 2) | (1 << 8);
968 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
969 return err;
970 }
971
972 /* Audio source */
973 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_audio_src, chip))) < 0)
974 return err;
975 /* clock mode */
976 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_clock_mode, chip))) < 0)
977 return err;
978 /* IEC958 controls */
979 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958_mask, chip))) < 0)
980 return err;
981 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958, chip))) < 0)
982 return err;
983 /* VU, peak, saturation meters */
984 for (c = 0; c < 2; c++) {
985 static char *dir[2] = { "Output", "Input" };
986 for (i = 0; i < chip->hw->num_ins; i++) {
987 int val = (i * 2) | (c << 8);
988 if (c == 1) {
989 temp = vx_control_saturation;
990 temp.index = i;
991 temp.private_value = val;
992 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
993 return err;
994 }
995 sprintf(name, "%s VU Meter", dir[c]);
996 temp = vx_control_vu_meter;
997 temp.index = i;
998 temp.name = name;
999 temp.private_value = val;
1000 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
1001 return err;
1002 sprintf(name, "%s Peak Meter", dir[c]);
1003 temp = vx_control_peak_meter;
1004 temp.index = i;
1005 temp.name = name;
1006 temp.private_value = val;
1007 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
1008 return err;
1009 }
1010 }
1011 vx_reset_audio_levels(chip);
1012 return 0;
1013}