blob: 3b6823fc0606537d6659b2bb5541eb88165d1349 [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{
Takashi Iwai5e246b82008-08-08 17:12:47 +020035 if (snd_BUG_ON(!chip->ops->write_codec))
36 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 if (chip->chip_status & VX_STAT_IS_STALE)
39 return;
40
Takashi Iwaidb0a5212014-09-09 17:17:20 +020041 mutex_lock(&chip->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 chip->ops->write_codec(chip, codec, data);
Takashi Iwaidb0a5212014-09-09 17:17:20 +020043 mutex_unlock(&chip->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
46/*
47 * Data type used to access the Codec
48 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010049union vx_codec_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 u32 l;
51#ifdef SNDRV_BIG_ENDIAN
52 struct w {
53 u16 h;
54 u16 l;
55 } w;
56 struct b {
57 u8 hh;
58 u8 mh;
59 u8 ml;
60 u8 ll;
61 } b;
62#else /* LITTLE_ENDIAN */
63 struct w {
64 u16 l;
65 u16 h;
66 } w;
67 struct b {
68 u8 ll;
69 u8 ml;
70 u8 mh;
71 u8 hh;
72 } b;
73#endif
Takashi Iwaiaf263672005-11-17 14:46:59 +010074};
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76#define SET_CDC_DATA_SEL(di,s) ((di).b.mh = (u8) (s))
77#define SET_CDC_DATA_REG(di,r) ((di).b.ml = (u8) (r))
78#define SET_CDC_DATA_VAL(di,d) ((di).b.ll = (u8) (d))
79#define SET_CDC_DATA_INIT(di) ((di).l = 0L, SET_CDC_DATA_SEL(di,XX_CODEC_SELECTOR))
80
81/*
82 * set up codec register and write the value
83 * @codec: the codec id, 0 or 1
84 * @reg: register index
85 * @val: data value
86 */
Takashi Iwaiaf263672005-11-17 14:46:59 +010087static void vx_set_codec_reg(struct vx_core *chip, int codec, int reg, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Takashi Iwaiaf263672005-11-17 14:46:59 +010089 union vx_codec_data data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 /* DAC control register */
91 SET_CDC_DATA_INIT(data);
92 SET_CDC_DATA_REG(data, reg);
93 SET_CDC_DATA_VAL(data, val);
94 vx_write_codec_reg(chip, codec, data.l);
95}
96
97
98/*
99 * vx_set_analog_output_level - set the output attenuation level
100 * @codec: the output codec, 0 or 1. (1 for VXP440 only)
101 * @left: left output level, 0 = mute
102 * @right: right output level
103 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100104static void vx_set_analog_output_level(struct vx_core *chip, int codec, int left, int right)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
106 left = chip->hw->output_level_max - left;
107 right = chip->hw->output_level_max - right;
108
109 if (chip->ops->akm_write) {
110 chip->ops->akm_write(chip, XX_CODEC_LEVEL_LEFT_REGISTER, left);
111 chip->ops->akm_write(chip, XX_CODEC_LEVEL_RIGHT_REGISTER, right);
112 } else {
113 /* convert to attenuation level: 0 = 0dB (max), 0xe3 = -113.5 dB (min) */
114 vx_set_codec_reg(chip, codec, XX_CODEC_LEVEL_LEFT_REGISTER, left);
115 vx_set_codec_reg(chip, codec, XX_CODEC_LEVEL_RIGHT_REGISTER, right);
116 }
117}
118
119
120/*
121 * vx_toggle_dac_mute - mute/unmute DAC
122 * @mute: 0 = unmute, 1 = mute
123 */
124
125#define DAC_ATTEN_MIN 0x08
126#define DAC_ATTEN_MAX 0x38
127
Takashi Iwaiaf263672005-11-17 14:46:59 +0100128void vx_toggle_dac_mute(struct vx_core *chip, int mute)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 unsigned int i;
131 for (i = 0; i < chip->hw->num_codecs; i++) {
132 if (chip->ops->akm_write)
133 chip->ops->akm_write(chip, XX_CODEC_DAC_CONTROL_REGISTER, mute); /* XXX */
134 else
135 vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER,
136 mute ? DAC_ATTEN_MAX : DAC_ATTEN_MIN);
137 }
138}
139
140/*
141 * vx_reset_codec - reset and initialize the codecs
142 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100143void vx_reset_codec(struct vx_core *chip, int cold_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 unsigned int i;
146 int port = chip->type >= VX_TYPE_VXPOCKET ? 0x75 : 0x65;
147
148 chip->ops->reset_codec(chip);
149
150 /* AKM codecs should be initialized in reset_codec callback */
151 if (! chip->ops->akm_write) {
152 /* initialize old codecs */
153 for (i = 0; i < chip->hw->num_codecs; i++) {
154 /* DAC control register (change level when zero crossing + mute) */
155 vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER, DAC_ATTEN_MAX);
156 /* ADC control register */
157 vx_set_codec_reg(chip, i, XX_CODEC_ADC_CONTROL_REGISTER, 0x00);
158 /* Port mode register */
159 vx_set_codec_reg(chip, i, XX_CODEC_PORT_MODE_REGISTER, port);
160 /* Clock control register */
161 vx_set_codec_reg(chip, i, XX_CODEC_CLOCK_CONTROL_REGISTER, 0x00);
162 }
163 }
164
165 /* mute analog output */
166 for (i = 0; i < chip->hw->num_codecs; i++) {
167 chip->output_level[i][0] = 0;
168 chip->output_level[i][1] = 0;
169 vx_set_analog_output_level(chip, i, 0, 0);
170 }
171}
172
173/*
174 * change the audio input source
175 * @src: the target source (VX_AUDIO_SRC_XXX)
176 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100177static void vx_change_audio_source(struct vx_core *chip, int src)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 if (chip->chip_status & VX_STAT_IS_STALE)
180 return;
181
Takashi Iwaidb0a5212014-09-09 17:17:20 +0200182 mutex_lock(&chip->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 chip->ops->change_audio_source(chip, src);
Takashi Iwaidb0a5212014-09-09 17:17:20 +0200184 mutex_unlock(&chip->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}
186
187
188/*
189 * change the audio source if necessary and possible
190 * returns 1 if the source is actually changed.
191 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100192int vx_sync_audio_source(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
194 if (chip->audio_source_target == chip->audio_source ||
195 chip->pcm_running)
196 return 0;
197 vx_change_audio_source(chip, chip->audio_source_target);
198 chip->audio_source = chip->audio_source_target;
199 return 1;
200}
201
202
203/*
204 * audio level, mute, monitoring
205 */
206struct vx_audio_level {
207 unsigned int has_level: 1;
208 unsigned int has_monitor_level: 1;
209 unsigned int has_mute: 1;
210 unsigned int has_monitor_mute: 1;
211 unsigned int mute;
212 unsigned int monitor_mute;
213 short level;
214 short monitor_level;
215};
216
Takashi Iwaiaf263672005-11-17 14:46:59 +0100217static int vx_adjust_audio_level(struct vx_core *chip, int audio, int capture,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 struct vx_audio_level *info)
219{
220 struct vx_rmh rmh;
221
222 if (chip->chip_status & VX_STAT_IS_STALE)
223 return -EBUSY;
224
225 vx_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
226 if (capture)
227 rmh.Cmd[0] |= COMMAND_RECORD_MASK;
228 /* Add Audio IO mask */
229 rmh.Cmd[1] = 1 << audio;
230 rmh.Cmd[2] = 0;
231 if (info->has_level) {
232 rmh.Cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
233 rmh.Cmd[2] |= info->level;
234 }
235 if (info->has_monitor_level) {
236 rmh.Cmd[0] |= VALID_AUDIO_IO_MONITORING_LEVEL;
237 rmh.Cmd[2] |= ((unsigned int)info->monitor_level << 10);
238 }
239 if (info->has_mute) {
240 rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_LEVEL;
241 if (info->mute)
242 rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_LEVEL;
243 }
244 if (info->has_monitor_mute) {
245 /* validate flag for M2 at least to unmute it */
246 rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_MONITORING_1 | VALID_AUDIO_IO_MUTE_MONITORING_2;
247 if (info->monitor_mute)
248 rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_MONITORING_1;
249 }
250
251 return vx_send_msg(chip, &rmh);
252}
253
254
255#if 0 // not used
Takashi Iwaiaf263672005-11-17 14:46:59 +0100256static int vx_read_audio_level(struct vx_core *chip, int audio, int capture,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 struct vx_audio_level *info)
258{
259 int err;
260 struct vx_rmh rmh;
261
262 memset(info, 0, sizeof(*info));
263 vx_init_rmh(&rmh, CMD_GET_AUDIO_LEVELS);
264 if (capture)
265 rmh.Cmd[0] |= COMMAND_RECORD_MASK;
266 /* Add Audio IO mask */
267 rmh.Cmd[1] = 1 << audio;
268 err = vx_send_msg(chip, &rmh);
269 if (err < 0)
270 return err;
271 info.level = rmh.Stat[0] & MASK_DSP_WORD_LEVEL;
272 info.monitor_level = (rmh.Stat[0] >> 10) & MASK_DSP_WORD_LEVEL;
273 info.mute = (rmh.Stat[i] & AUDIO_IO_HAS_MUTE_LEVEL) ? 1 : 0;
274 info.monitor_mute = (rmh.Stat[i] & AUDIO_IO_HAS_MUTE_MONITORING_1) ? 1 : 0;
275 return 0;
276}
277#endif // not used
278
279/*
280 * set the monitoring level and mute state of the given audio
281 * no more static, because must be called from vx_pcm to demute monitoring
282 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100283int vx_set_monitor_level(struct vx_core *chip, int audio, int level, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
285 struct vx_audio_level info;
286
287 memset(&info, 0, sizeof(info));
288 info.has_monitor_level = 1;
289 info.monitor_level = level;
290 info.has_monitor_mute = 1;
291 info.monitor_mute = !active;
292 chip->audio_monitor[audio] = level;
293 chip->audio_monitor_active[audio] = active;
294 return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */
295}
296
297
298/*
299 * set the mute status of the given audio
300 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100301static int vx_set_audio_switch(struct vx_core *chip, int audio, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 struct vx_audio_level info;
304
305 memset(&info, 0, sizeof(info));
306 info.has_mute = 1;
307 info.mute = !active;
308 chip->audio_active[audio] = active;
309 return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */
310}
311
312/*
313 * set the mute status of the given audio
314 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100315static int vx_set_audio_gain(struct vx_core *chip, int audio, int capture, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
317 struct vx_audio_level info;
318
319 memset(&info, 0, sizeof(info));
320 info.has_level = 1;
321 info.level = level;
322 chip->audio_gain[capture][audio] = level;
323 return vx_adjust_audio_level(chip, audio, capture, &info);
324}
325
326/*
327 * reset all audio levels
328 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100329static void vx_reset_audio_levels(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
331 unsigned int i, c;
332 struct vx_audio_level info;
333
334 memset(chip->audio_gain, 0, sizeof(chip->audio_gain));
335 memset(chip->audio_active, 0, sizeof(chip->audio_active));
336 memset(chip->audio_monitor, 0, sizeof(chip->audio_monitor));
337 memset(chip->audio_monitor_active, 0, sizeof(chip->audio_monitor_active));
338
339 for (c = 0; c < 2; c++) {
340 for (i = 0; i < chip->hw->num_ins * 2; i++) {
341 memset(&info, 0, sizeof(info));
342 if (c == 0) {
343 info.has_monitor_level = 1;
344 info.has_mute = 1;
345 info.has_monitor_mute = 1;
346 }
347 info.has_level = 1;
348 info.level = CVAL_0DB; /* default: 0dB */
349 vx_adjust_audio_level(chip, i, c, &info);
350 chip->audio_gain[c][i] = CVAL_0DB;
351 chip->audio_monitor[i] = CVAL_0DB;
352 }
353 }
354}
355
356
357/*
358 * VU, peak meter record
359 */
360
361#define VU_METER_CHANNELS 2
362
363struct vx_vu_meter {
364 int saturated;
365 int vu_level;
366 int peak_level;
367};
368
369/*
370 * get the VU and peak meter values
371 * @audio: the audio index
372 * @capture: 0 = playback, 1 = capture operation
373 * @info: the array of vx_vu_meter records (size = 2).
374 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100375static 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 -0700376{
377 struct vx_rmh rmh;
378 int i, err;
379
380 if (chip->chip_status & VX_STAT_IS_STALE)
381 return -EBUSY;
382
383 vx_init_rmh(&rmh, CMD_AUDIO_VU_PIC_METER);
384 rmh.LgStat += 2 * VU_METER_CHANNELS;
385 if (capture)
386 rmh.Cmd[0] |= COMMAND_RECORD_MASK;
387
388 /* Add Audio IO mask */
389 rmh.Cmd[1] = 0;
390 for (i = 0; i < VU_METER_CHANNELS; i++)
391 rmh.Cmd[1] |= 1 << (audio + i);
392 err = vx_send_msg(chip, &rmh);
393 if (err < 0)
394 return err;
395 /* Read response */
396 for (i = 0; i < 2 * VU_METER_CHANNELS; i +=2) {
397 info->saturated = (rmh.Stat[0] & (1 << (audio + i))) ? 1 : 0;
398 info->vu_level = rmh.Stat[i + 1];
399 info->peak_level = rmh.Stat[i + 2];
400 info++;
401 }
402 return 0;
403}
404
405
406/*
407 * control API entries
408 */
409
410/*
411 * output level control
412 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100413static int vx_output_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100415 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
417 uinfo->count = 2;
418 uinfo->value.integer.min = 0;
419 uinfo->value.integer.max = chip->hw->output_level_max;
420 return 0;
421}
422
Takashi Iwaiaf263672005-11-17 14:46:59 +0100423static int vx_output_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100425 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 int codec = kcontrol->id.index;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100427 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 ucontrol->value.integer.value[0] = chip->output_level[codec][0];
429 ucontrol->value.integer.value[1] = chip->output_level[codec][1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100430 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 return 0;
432}
433
Takashi Iwaiaf263672005-11-17 14:46:59 +0100434static int vx_output_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100436 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 int codec = kcontrol->id.index;
Takashi Iwaid05ab182007-11-15 16:13:32 +0100438 unsigned int val[2], vmax;
439
440 vmax = chip->hw->output_level_max;
441 val[0] = ucontrol->value.integer.value[0];
442 val[1] = ucontrol->value.integer.value[1];
443 if (val[0] > vmax || val[1] > vmax)
444 return -EINVAL;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100445 mutex_lock(&chip->mixer_mutex);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100446 if (val[0] != chip->output_level[codec][0] ||
447 val[1] != chip->output_level[codec][1]) {
448 vx_set_analog_output_level(chip, codec, val[0], val[1]);
449 chip->output_level[codec][0] = val[0];
450 chip->output_level[codec][1] = val[1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100451 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return 1;
453 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100454 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return 0;
456}
457
Takashi Iwaiaf263672005-11-17 14:46:59 +0100458static struct snd_kcontrol_new vx_control_output_level = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200460 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
461 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 .name = "Master Playback Volume",
463 .info = vx_output_level_info,
464 .get = vx_output_level_get,
465 .put = vx_output_level_put,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200466 /* tlv will be filled later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467};
468
469/*
470 * audio source select
471 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100472static int vx_audio_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
474 static char *texts_mic[3] = {
475 "Digital", "Line", "Mic"
476 };
477 static char *texts_vx2[2] = {
478 "Digital", "Analog"
479 };
Takashi Iwaiaf263672005-11-17 14:46:59 +0100480 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
483 uinfo->count = 1;
484 if (chip->type >= VX_TYPE_VXPOCKET) {
485 uinfo->value.enumerated.items = 3;
486 if (uinfo->value.enumerated.item > 2)
487 uinfo->value.enumerated.item = 2;
488 strcpy(uinfo->value.enumerated.name,
489 texts_mic[uinfo->value.enumerated.item]);
490 } else {
491 uinfo->value.enumerated.items = 2;
492 if (uinfo->value.enumerated.item > 1)
493 uinfo->value.enumerated.item = 1;
494 strcpy(uinfo->value.enumerated.name,
495 texts_vx2[uinfo->value.enumerated.item]);
496 }
497 return 0;
498}
499
Takashi Iwaiaf263672005-11-17 14:46:59 +0100500static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100502 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 ucontrol->value.enumerated.item[0] = chip->audio_source_target;
504 return 0;
505}
506
Takashi Iwaiaf263672005-11-17 14:46:59 +0100507static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100509 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100510
511 if (chip->type >= VX_TYPE_VXPOCKET) {
512 if (ucontrol->value.enumerated.item[0] > 2)
513 return -EINVAL;
514 } else {
515 if (ucontrol->value.enumerated.item[0] > 1)
516 return -EINVAL;
517 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100518 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) {
520 chip->audio_source_target = ucontrol->value.enumerated.item[0];
521 vx_sync_audio_source(chip);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100522 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 return 1;
524 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100525 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return 0;
527}
528
Takashi Iwaiaf263672005-11-17 14:46:59 +0100529static struct snd_kcontrol_new vx_control_audio_src = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
531 .name = "Capture Source",
532 .info = vx_audio_src_info,
533 .get = vx_audio_src_get,
534 .put = vx_audio_src_put,
535};
536
537/*
538 * clock mode selection
539 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100540static int vx_clock_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
542 static char *texts[3] = {
543 "Auto", "Internal", "External"
544 };
545
546 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
547 uinfo->count = 1;
548 uinfo->value.enumerated.items = 3;
549 if (uinfo->value.enumerated.item > 2)
550 uinfo->value.enumerated.item = 2;
551 strcpy(uinfo->value.enumerated.name,
552 texts[uinfo->value.enumerated.item]);
553 return 0;
554}
555
Takashi Iwaiaf263672005-11-17 14:46:59 +0100556static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100558 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 ucontrol->value.enumerated.item[0] = chip->clock_mode;
560 return 0;
561}
562
Takashi Iwaiaf263672005-11-17 14:46:59 +0100563static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100565 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100566
567 if (ucontrol->value.enumerated.item[0] > 2)
568 return -EINVAL;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100569 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 if (chip->clock_mode != ucontrol->value.enumerated.item[0]) {
571 chip->clock_mode = ucontrol->value.enumerated.item[0];
572 vx_set_clock(chip, chip->freq);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100573 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return 1;
575 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100576 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 return 0;
578}
579
Takashi Iwaiaf263672005-11-17 14:46:59 +0100580static struct snd_kcontrol_new vx_control_clock_mode = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
582 .name = "Clock Mode",
583 .info = vx_clock_mode_info,
584 .get = vx_clock_mode_get,
585 .put = vx_clock_mode_put,
586};
587
588/*
589 * Audio Gain
590 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100591static int vx_audio_gain_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
593 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
594 uinfo->count = 2;
595 uinfo->value.integer.min = 0;
596 uinfo->value.integer.max = CVAL_MAX;
597 return 0;
598}
599
Takashi Iwaiaf263672005-11-17 14:46:59 +0100600static int vx_audio_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100602 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 int audio = kcontrol->private_value & 0xff;
604 int capture = (kcontrol->private_value >> 8) & 1;
605
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100606 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio];
608 ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100609 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 return 0;
611}
612
Takashi Iwaiaf263672005-11-17 14:46:59 +0100613static int vx_audio_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100615 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 int audio = kcontrol->private_value & 0xff;
617 int capture = (kcontrol->private_value >> 8) & 1;
Takashi Iwaid05ab182007-11-15 16:13:32 +0100618 unsigned int val[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Takashi Iwaid05ab182007-11-15 16:13:32 +0100620 val[0] = ucontrol->value.integer.value[0];
621 val[1] = ucontrol->value.integer.value[1];
622 if (val[0] > CVAL_MAX || val[1] > CVAL_MAX)
623 return -EINVAL;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100624 mutex_lock(&chip->mixer_mutex);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100625 if (val[0] != chip->audio_gain[capture][audio] ||
626 val[1] != chip->audio_gain[capture][audio+1]) {
627 vx_set_audio_gain(chip, audio, capture, val[0]);
628 vx_set_audio_gain(chip, audio+1, capture, val[1]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100629 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return 1;
631 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100632 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 return 0;
634}
635
Takashi Iwaiaf263672005-11-17 14:46:59 +0100636static int vx_audio_monitor_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100638 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 int audio = kcontrol->private_value & 0xff;
640
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100641 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 ucontrol->value.integer.value[0] = chip->audio_monitor[audio];
643 ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100644 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return 0;
646}
647
Takashi Iwaiaf263672005-11-17 14:46:59 +0100648static int vx_audio_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100650 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 int audio = kcontrol->private_value & 0xff;
Takashi Iwaid05ab182007-11-15 16:13:32 +0100652 unsigned int val[2];
653
654 val[0] = ucontrol->value.integer.value[0];
655 val[1] = ucontrol->value.integer.value[1];
656 if (val[0] > CVAL_MAX || val[1] > CVAL_MAX)
657 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100659 mutex_lock(&chip->mixer_mutex);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100660 if (val[0] != chip->audio_monitor[audio] ||
661 val[1] != chip->audio_monitor[audio+1]) {
662 vx_set_monitor_level(chip, audio, val[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 chip->audio_monitor_active[audio]);
Takashi Iwaid05ab182007-11-15 16:13:32 +0100664 vx_set_monitor_level(chip, audio+1, val[1],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 chip->audio_monitor_active[audio+1]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100666 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 return 1;
668 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100669 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 return 0;
671}
672
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200673#define vx_audio_sw_info snd_ctl_boolean_stereo_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Takashi Iwaiaf263672005-11-17 14:46:59 +0100675static int vx_audio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100677 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 int audio = kcontrol->private_value & 0xff;
679
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100680 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 ucontrol->value.integer.value[0] = chip->audio_active[audio];
682 ucontrol->value.integer.value[1] = chip->audio_active[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100683 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 return 0;
685}
686
Takashi Iwaiaf263672005-11-17 14:46:59 +0100687static int vx_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100689 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 int audio = kcontrol->private_value & 0xff;
691
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100692 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 if (ucontrol->value.integer.value[0] != chip->audio_active[audio] ||
694 ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) {
Takashi Iwaid05ab182007-11-15 16:13:32 +0100695 vx_set_audio_switch(chip, audio,
696 !!ucontrol->value.integer.value[0]);
697 vx_set_audio_switch(chip, audio+1,
698 !!ucontrol->value.integer.value[1]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100699 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 return 1;
701 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100702 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 return 0;
704}
705
Takashi Iwaiaf263672005-11-17 14:46:59 +0100706static int vx_monitor_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100708 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 int audio = kcontrol->private_value & 0xff;
710
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100711 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio];
713 ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1];
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100714 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 return 0;
716}
717
Takashi Iwaiaf263672005-11-17 14:46:59 +0100718static int vx_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100720 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 int audio = kcontrol->private_value & 0xff;
722
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100723 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] ||
725 ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) {
726 vx_set_monitor_level(chip, audio, chip->audio_monitor[audio],
Takashi Iwaid05ab182007-11-15 16:13:32 +0100727 !!ucontrol->value.integer.value[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1],
Takashi Iwaid05ab182007-11-15 16:13:32 +0100729 !!ucontrol->value.integer.value[1]);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100730 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 return 1;
732 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100733 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return 0;
735}
736
Takashi Iwai0cb29ea2007-01-29 15:33:49 +0100737static const DECLARE_TLV_DB_SCALE(db_scale_audio_gain, -10975, 25, 0);
Takashi Iwai1186ed82006-08-23 19:53:28 +0200738
Takashi Iwaiaf263672005-11-17 14:46:59 +0100739static struct snd_kcontrol_new vx_control_audio_gain = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
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 /* name will be filled later */
744 .info = vx_audio_gain_info,
745 .get = vx_audio_gain_get,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200746 .put = vx_audio_gain_put,
747 .tlv = { .p = db_scale_audio_gain },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100749static struct snd_kcontrol_new vx_control_output_switch = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
751 .name = "PCM Playback Switch",
752 .info = vx_audio_sw_info,
753 .get = vx_audio_sw_get,
754 .put = vx_audio_sw_put
755};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100756static struct snd_kcontrol_new vx_control_monitor_gain = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
758 .name = "Monitoring Volume",
Takashi Iwai1186ed82006-08-23 19:53:28 +0200759 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
760 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 .info = vx_audio_gain_info, /* shared */
762 .get = vx_audio_monitor_get,
Takashi Iwai1186ed82006-08-23 19:53:28 +0200763 .put = vx_audio_monitor_put,
764 .tlv = { .p = db_scale_audio_gain },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765};
Takashi Iwaiaf263672005-11-17 14:46:59 +0100766static struct snd_kcontrol_new vx_control_monitor_switch = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
768 .name = "Monitoring Switch",
769 .info = vx_audio_sw_info, /* shared */
770 .get = vx_monitor_sw_get,
771 .put = vx_monitor_sw_put
772};
773
774
775/*
776 * IEC958 status bits
777 */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100778static int vx_iec958_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
781 uinfo->count = 1;
782 return 0;
783}
784
Takashi Iwaiaf263672005-11-17 14:46:59 +0100785static int vx_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100787 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100789 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 ucontrol->value.iec958.status[0] = (chip->uer_bits >> 0) & 0xff;
791 ucontrol->value.iec958.status[1] = (chip->uer_bits >> 8) & 0xff;
792 ucontrol->value.iec958.status[2] = (chip->uer_bits >> 16) & 0xff;
793 ucontrol->value.iec958.status[3] = (chip->uer_bits >> 24) & 0xff;
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100794 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 return 0;
796}
797
Takashi Iwaiaf263672005-11-17 14:46:59 +0100798static int vx_iec958_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
800 ucontrol->value.iec958.status[0] = 0xff;
801 ucontrol->value.iec958.status[1] = 0xff;
802 ucontrol->value.iec958.status[2] = 0xff;
803 ucontrol->value.iec958.status[3] = 0xff;
804 return 0;
805}
806
Takashi Iwaiaf263672005-11-17 14:46:59 +0100807static int vx_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100809 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 unsigned int val;
811
812 val = (ucontrol->value.iec958.status[0] << 0) |
813 (ucontrol->value.iec958.status[1] << 8) |
814 (ucontrol->value.iec958.status[2] << 16) |
815 (ucontrol->value.iec958.status[3] << 24);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100816 mutex_lock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 if (chip->uer_bits != val) {
818 chip->uer_bits = val;
819 vx_set_iec958_status(chip, val);
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100820 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 return 1;
822 }
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100823 mutex_unlock(&chip->mixer_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 return 0;
825}
826
Takashi Iwaiaf263672005-11-17 14:46:59 +0100827static struct snd_kcontrol_new vx_control_iec958_mask = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 .access = SNDRV_CTL_ELEM_ACCESS_READ,
Clemens Ladisch5549d542005-08-03 13:50:30 +0200829 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
831 .info = vx_iec958_info, /* shared */
832 .get = vx_iec958_mask_get,
833};
834
Takashi Iwaiaf263672005-11-17 14:46:59 +0100835static struct snd_kcontrol_new vx_control_iec958 = {
Clemens Ladisch5549d542005-08-03 13:50:30 +0200836 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
838 .info = vx_iec958_info,
839 .get = vx_iec958_get,
840 .put = vx_iec958_put
841};
842
843
844/*
845 * VU meter
846 */
847
848#define METER_MAX 0xff
849#define METER_SHIFT 16
850
Takashi Iwaiaf263672005-11-17 14:46:59 +0100851static int vx_vu_meter_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
853 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
854 uinfo->count = 2;
855 uinfo->value.integer.min = 0;
856 uinfo->value.integer.max = METER_MAX;
857 return 0;
858}
859
Takashi Iwaiaf263672005-11-17 14:46:59 +0100860static int vx_vu_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100862 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 struct vx_vu_meter meter[2];
864 int audio = kcontrol->private_value & 0xff;
865 int capture = (kcontrol->private_value >> 8) & 1;
866
867 vx_get_audio_vu_meter(chip, audio, capture, meter);
868 ucontrol->value.integer.value[0] = meter[0].vu_level >> METER_SHIFT;
869 ucontrol->value.integer.value[1] = meter[1].vu_level >> METER_SHIFT;
870 return 0;
871}
872
Takashi Iwaiaf263672005-11-17 14:46:59 +0100873static int vx_peak_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100875 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 struct vx_vu_meter meter[2];
877 int audio = kcontrol->private_value & 0xff;
878 int capture = (kcontrol->private_value >> 8) & 1;
879
880 vx_get_audio_vu_meter(chip, audio, capture, meter);
881 ucontrol->value.integer.value[0] = meter[0].peak_level >> METER_SHIFT;
882 ucontrol->value.integer.value[1] = meter[1].peak_level >> METER_SHIFT;
883 return 0;
884}
885
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200886#define vx_saturation_info snd_ctl_boolean_stereo_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Takashi Iwaiaf263672005-11-17 14:46:59 +0100888static int vx_saturation_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100890 struct vx_core *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 struct vx_vu_meter meter[2];
892 int audio = kcontrol->private_value & 0xff;
893
894 vx_get_audio_vu_meter(chip, audio, 1, meter); /* capture only */
895 ucontrol->value.integer.value[0] = meter[0].saturated;
896 ucontrol->value.integer.value[1] = meter[1].saturated;
897 return 0;
898}
899
Takashi Iwaiaf263672005-11-17 14:46:59 +0100900static struct snd_kcontrol_new vx_control_vu_meter = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
902 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
903 /* name will be filled later */
904 .info = vx_vu_meter_info,
905 .get = vx_vu_meter_get,
906};
907
Takashi Iwaiaf263672005-11-17 14:46:59 +0100908static struct snd_kcontrol_new vx_control_peak_meter = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
910 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
911 /* name will be filled later */
912 .info = vx_vu_meter_info, /* shared */
913 .get = vx_peak_meter_get,
914};
915
Takashi Iwaiaf263672005-11-17 14:46:59 +0100916static struct snd_kcontrol_new vx_control_saturation = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
918 .name = "Input Saturation",
919 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
920 .info = vx_saturation_info,
921 .get = vx_saturation_get,
922};
923
924
925
926/*
927 *
928 */
929
Takashi Iwaiaf263672005-11-17 14:46:59 +0100930int snd_vx_mixer_new(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931{
932 unsigned int i, c;
933 int err;
Takashi Iwaiaf263672005-11-17 14:46:59 +0100934 struct snd_kcontrol_new temp;
935 struct snd_card *card = chip->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 char name[32];
937
938 strcpy(card->mixername, card->driver);
939
940 /* output level controls */
941 for (i = 0; i < chip->hw->num_outs; i++) {
942 temp = vx_control_output_level;
943 temp.index = i;
Takashi Iwai1186ed82006-08-23 19:53:28 +0200944 temp.tlv.p = chip->hw->output_level_db_scale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
946 return err;
947 }
948
949 /* PCM volumes, switches, monitoring */
950 for (i = 0; i < chip->hw->num_outs; i++) {
951 int val = i * 2;
952 temp = vx_control_audio_gain;
953 temp.index = i;
954 temp.name = "PCM Playback Volume";
955 temp.private_value = val;
956 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
957 return err;
958 temp = vx_control_output_switch;
959 temp.index = i;
960 temp.private_value = val;
961 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
962 return err;
963 temp = vx_control_monitor_gain;
964 temp.index = i;
965 temp.private_value = val;
966 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
967 return err;
968 temp = vx_control_monitor_switch;
969 temp.index = i;
970 temp.private_value = val;
971 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
972 return err;
973 }
974 for (i = 0; i < chip->hw->num_outs; i++) {
975 temp = vx_control_audio_gain;
976 temp.index = i;
977 temp.name = "PCM Capture Volume";
978 temp.private_value = (i * 2) | (1 << 8);
979 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
980 return err;
981 }
982
983 /* Audio source */
984 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_audio_src, chip))) < 0)
985 return err;
986 /* clock mode */
987 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_clock_mode, chip))) < 0)
988 return err;
989 /* IEC958 controls */
990 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958_mask, chip))) < 0)
991 return err;
992 if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958, chip))) < 0)
993 return err;
994 /* VU, peak, saturation meters */
995 for (c = 0; c < 2; c++) {
996 static char *dir[2] = { "Output", "Input" };
997 for (i = 0; i < chip->hw->num_ins; i++) {
998 int val = (i * 2) | (c << 8);
999 if (c == 1) {
1000 temp = vx_control_saturation;
1001 temp.index = i;
1002 temp.private_value = val;
1003 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
1004 return err;
1005 }
1006 sprintf(name, "%s VU Meter", dir[c]);
1007 temp = vx_control_vu_meter;
1008 temp.index = i;
1009 temp.name = name;
1010 temp.private_value = val;
1011 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
1012 return err;
1013 sprintf(name, "%s Peak Meter", dir[c]);
1014 temp = vx_control_peak_meter;
1015 temp.index = i;
1016 temp.name = name;
1017 temp.private_value = val;
1018 if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0)
1019 return err;
1020 }
1021 }
1022 vx_reset_audio_levels(chip);
1023 return 0;
1024}