Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <sound/core.h> |
| 24 | #include <sound/control.h> |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 25 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <sound/vx_core.h> |
| 27 | #include "vx_cmd.h" |
| 28 | |
| 29 | |
| 30 | /* |
| 31 | * write a codec data (24bit) |
| 32 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 33 | static void vx_write_codec_reg(struct vx_core *chip, int codec, unsigned int data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 50 | union vx_codec_data { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 75 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 88 | static void vx_set_codec_reg(struct vx_core *chip, int codec, int reg, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 90 | union vx_codec_data data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* DAC control register */ |
| 92 | SET_CDC_DATA_INIT(data); |
| 93 | SET_CDC_DATA_REG(data, reg); |
| 94 | SET_CDC_DATA_VAL(data, val); |
| 95 | vx_write_codec_reg(chip, codec, data.l); |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 105 | static void vx_set_analog_output_level(struct vx_core *chip, int codec, int left, int right) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 129 | void vx_toggle_dac_mute(struct vx_core *chip, int mute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 144 | void vx_reset_codec(struct vx_core *chip, int cold_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 178 | static void vx_change_audio_source(struct vx_core *chip, int src) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 195 | int vx_sync_audio_source(struct vx_core *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 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 | */ |
| 209 | struct vx_audio_level { |
| 210 | unsigned int has_level: 1; |
| 211 | unsigned int has_monitor_level: 1; |
| 212 | unsigned int has_mute: 1; |
| 213 | unsigned int has_monitor_mute: 1; |
| 214 | unsigned int mute; |
| 215 | unsigned int monitor_mute; |
| 216 | short level; |
| 217 | short monitor_level; |
| 218 | }; |
| 219 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 220 | static int vx_adjust_audio_level(struct vx_core *chip, int audio, int capture, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 259 | static int vx_read_audio_level(struct vx_core *chip, int audio, int capture, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 286 | int vx_set_monitor_level(struct vx_core *chip, int audio, int level, int active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 304 | static int vx_set_audio_switch(struct vx_core *chip, int audio, int active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 318 | static int vx_set_audio_gain(struct vx_core *chip, int audio, int capture, int level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 332 | static void vx_reset_audio_levels(struct vx_core *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
| 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 | |
| 366 | struct 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 378 | static int vx_get_audio_vu_meter(struct vx_core *chip, int audio, int capture, struct vx_vu_meter *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 416 | static int vx_output_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 418 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 426 | static int vx_output_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 428 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | int codec = kcontrol->id.index; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 430 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | ucontrol->value.integer.value[0] = chip->output_level[codec][0]; |
| 432 | ucontrol->value.integer.value[1] = chip->output_level[codec][1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 433 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 437 | static int vx_output_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 439 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | int codec = kcontrol->id.index; |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 441 | 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 Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 448 | mutex_lock(&chip->mixer_mutex); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 449 | if (val[0] != chip->output_level[codec][0] || |
| 450 | val[1] != chip->output_level[codec][1]) { |
| 451 | vx_set_analog_output_level(chip, codec, val[0], val[1]); |
| 452 | chip->output_level[codec][0] = val[0]; |
| 453 | chip->output_level[codec][1] = val[1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 454 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | return 1; |
| 456 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 457 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 461 | static struct snd_kcontrol_new vx_control_output_level = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 463 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 464 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | .name = "Master Playback Volume", |
| 466 | .info = vx_output_level_info, |
| 467 | .get = vx_output_level_get, |
| 468 | .put = vx_output_level_put, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 469 | /* tlv will be filled later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | }; |
| 471 | |
| 472 | /* |
| 473 | * audio source select |
| 474 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 475 | static int vx_audio_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
| 477 | static char *texts_mic[3] = { |
| 478 | "Digital", "Line", "Mic" |
| 479 | }; |
| 480 | static char *texts_vx2[2] = { |
| 481 | "Digital", "Analog" |
| 482 | }; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 483 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 503 | static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 505 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | ucontrol->value.enumerated.item[0] = chip->audio_source_target; |
| 507 | return 0; |
| 508 | } |
| 509 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 510 | static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 512 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 513 | |
| 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 Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 521 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) { |
| 523 | chip->audio_source_target = ucontrol->value.enumerated.item[0]; |
| 524 | vx_sync_audio_source(chip); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 525 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | return 1; |
| 527 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 528 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 532 | static struct snd_kcontrol_new vx_control_audio_src = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 534 | .name = "Capture Source", |
| 535 | .info = vx_audio_src_info, |
| 536 | .get = vx_audio_src_get, |
| 537 | .put = vx_audio_src_put, |
| 538 | }; |
| 539 | |
| 540 | /* |
| 541 | * clock mode selection |
| 542 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 543 | static int vx_clock_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 559 | static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 561 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | ucontrol->value.enumerated.item[0] = chip->clock_mode; |
| 563 | return 0; |
| 564 | } |
| 565 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 566 | static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 568 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 569 | |
| 570 | if (ucontrol->value.enumerated.item[0] > 2) |
| 571 | return -EINVAL; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 572 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | if (chip->clock_mode != ucontrol->value.enumerated.item[0]) { |
| 574 | chip->clock_mode = ucontrol->value.enumerated.item[0]; |
| 575 | vx_set_clock(chip, chip->freq); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 576 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return 1; |
| 578 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 579 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | return 0; |
| 581 | } |
| 582 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 583 | static struct snd_kcontrol_new vx_control_clock_mode = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 585 | .name = "Clock Mode", |
| 586 | .info = vx_clock_mode_info, |
| 587 | .get = vx_clock_mode_get, |
| 588 | .put = vx_clock_mode_put, |
| 589 | }; |
| 590 | |
| 591 | /* |
| 592 | * Audio Gain |
| 593 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 594 | static int vx_audio_gain_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 603 | static int vx_audio_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 605 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | int audio = kcontrol->private_value & 0xff; |
| 607 | int capture = (kcontrol->private_value >> 8) & 1; |
| 608 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 609 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio]; |
| 611 | ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 612 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 616 | static int vx_audio_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 618 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | int audio = kcontrol->private_value & 0xff; |
| 620 | int capture = (kcontrol->private_value >> 8) & 1; |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 621 | unsigned int val[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 623 | val[0] = ucontrol->value.integer.value[0]; |
| 624 | val[1] = ucontrol->value.integer.value[1]; |
| 625 | if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) |
| 626 | return -EINVAL; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 627 | mutex_lock(&chip->mixer_mutex); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 628 | if (val[0] != chip->audio_gain[capture][audio] || |
| 629 | val[1] != chip->audio_gain[capture][audio+1]) { |
| 630 | vx_set_audio_gain(chip, audio, capture, val[0]); |
| 631 | vx_set_audio_gain(chip, audio+1, capture, val[1]); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 632 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | return 1; |
| 634 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 635 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 639 | static int vx_audio_monitor_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 641 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | int audio = kcontrol->private_value & 0xff; |
| 643 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 644 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | ucontrol->value.integer.value[0] = chip->audio_monitor[audio]; |
| 646 | ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 647 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | return 0; |
| 649 | } |
| 650 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 651 | static int vx_audio_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 653 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | int audio = kcontrol->private_value & 0xff; |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 655 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 662 | mutex_lock(&chip->mixer_mutex); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 663 | if (val[0] != chip->audio_monitor[audio] || |
| 664 | val[1] != chip->audio_monitor[audio+1]) { |
| 665 | vx_set_monitor_level(chip, audio, val[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | chip->audio_monitor_active[audio]); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 667 | vx_set_monitor_level(chip, audio+1, val[1], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | chip->audio_monitor_active[audio+1]); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 669 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | return 1; |
| 671 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 672 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | return 0; |
| 674 | } |
| 675 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 676 | #define vx_audio_sw_info snd_ctl_boolean_stereo_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 678 | static int vx_audio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 680 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | int audio = kcontrol->private_value & 0xff; |
| 682 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 683 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | ucontrol->value.integer.value[0] = chip->audio_active[audio]; |
| 685 | ucontrol->value.integer.value[1] = chip->audio_active[audio+1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 686 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return 0; |
| 688 | } |
| 689 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 690 | static int vx_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 692 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | int audio = kcontrol->private_value & 0xff; |
| 694 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 695 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | if (ucontrol->value.integer.value[0] != chip->audio_active[audio] || |
| 697 | ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) { |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 698 | vx_set_audio_switch(chip, audio, |
| 699 | !!ucontrol->value.integer.value[0]); |
| 700 | vx_set_audio_switch(chip, audio+1, |
| 701 | !!ucontrol->value.integer.value[1]); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 702 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | return 1; |
| 704 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 705 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | return 0; |
| 707 | } |
| 708 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 709 | static int vx_monitor_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 711 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | int audio = kcontrol->private_value & 0xff; |
| 713 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 714 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio]; |
| 716 | ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 717 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | return 0; |
| 719 | } |
| 720 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 721 | static int vx_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 723 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | int audio = kcontrol->private_value & 0xff; |
| 725 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 726 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] || |
| 728 | ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) { |
| 729 | vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 730 | !!ucontrol->value.integer.value[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 732 | !!ucontrol->value.integer.value[1]); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 733 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | return 1; |
| 735 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 736 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return 0; |
| 738 | } |
| 739 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 740 | static const DECLARE_TLV_DB_SCALE(db_scale_audio_gain, -10975, 25, 0); |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 741 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 742 | static struct snd_kcontrol_new vx_control_audio_gain = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 744 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 745 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | /* name will be filled later */ |
| 747 | .info = vx_audio_gain_info, |
| 748 | .get = vx_audio_gain_get, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 749 | .put = vx_audio_gain_put, |
| 750 | .tlv = { .p = db_scale_audio_gain }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | }; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 752 | static struct snd_kcontrol_new vx_control_output_switch = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 754 | .name = "PCM Playback Switch", |
| 755 | .info = vx_audio_sw_info, |
| 756 | .get = vx_audio_sw_get, |
| 757 | .put = vx_audio_sw_put |
| 758 | }; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 759 | static struct snd_kcontrol_new vx_control_monitor_gain = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 761 | .name = "Monitoring Volume", |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 762 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 763 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | .info = vx_audio_gain_info, /* shared */ |
| 765 | .get = vx_audio_monitor_get, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 766 | .put = vx_audio_monitor_put, |
| 767 | .tlv = { .p = db_scale_audio_gain }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | }; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 769 | static struct snd_kcontrol_new vx_control_monitor_switch = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 771 | .name = "Monitoring Switch", |
| 772 | .info = vx_audio_sw_info, /* shared */ |
| 773 | .get = vx_monitor_sw_get, |
| 774 | .put = vx_monitor_sw_put |
| 775 | }; |
| 776 | |
| 777 | |
| 778 | /* |
| 779 | * IEC958 status bits |
| 780 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 781 | static int vx_iec958_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { |
| 783 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 784 | uinfo->count = 1; |
| 785 | return 0; |
| 786 | } |
| 787 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 788 | static int vx_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 790 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 792 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | ucontrol->value.iec958.status[0] = (chip->uer_bits >> 0) & 0xff; |
| 794 | ucontrol->value.iec958.status[1] = (chip->uer_bits >> 8) & 0xff; |
| 795 | ucontrol->value.iec958.status[2] = (chip->uer_bits >> 16) & 0xff; |
| 796 | ucontrol->value.iec958.status[3] = (chip->uer_bits >> 24) & 0xff; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 797 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | return 0; |
| 799 | } |
| 800 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 801 | static int vx_iec958_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 810 | static int vx_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 812 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | 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 Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 819 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | if (chip->uer_bits != val) { |
| 821 | chip->uer_bits = val; |
| 822 | vx_set_iec958_status(chip, val); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 823 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | return 1; |
| 825 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 826 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | return 0; |
| 828 | } |
| 829 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 830 | static struct snd_kcontrol_new vx_control_iec958_mask = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
Clemens Ladisch | 5549d54 | 2005-08-03 13:50:30 +0200 | [diff] [blame] | 832 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), |
| 834 | .info = vx_iec958_info, /* shared */ |
| 835 | .get = vx_iec958_mask_get, |
| 836 | }; |
| 837 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 838 | static struct snd_kcontrol_new vx_control_iec958 = { |
Clemens Ladisch | 5549d54 | 2005-08-03 13:50:30 +0200 | [diff] [blame] | 839 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | .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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 854 | static int vx_vu_meter_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | { |
| 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 863 | static int vx_vu_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 865 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 876 | static int vx_peak_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 878 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | 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 Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 889 | #define vx_saturation_info snd_ctl_boolean_stereo_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 891 | static int vx_saturation_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 893 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | 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 Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 903 | static struct snd_kcontrol_new vx_control_vu_meter = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 905 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 906 | /* name will be filled later */ |
| 907 | .info = vx_vu_meter_info, |
| 908 | .get = vx_vu_meter_get, |
| 909 | }; |
| 910 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 911 | static struct snd_kcontrol_new vx_control_peak_meter = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 913 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 914 | /* name will be filled later */ |
| 915 | .info = vx_vu_meter_info, /* shared */ |
| 916 | .get = vx_peak_meter_get, |
| 917 | }; |
| 918 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 919 | static struct snd_kcontrol_new vx_control_saturation = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 921 | .name = "Input Saturation", |
| 922 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 923 | .info = vx_saturation_info, |
| 924 | .get = vx_saturation_get, |
| 925 | }; |
| 926 | |
| 927 | |
| 928 | |
| 929 | /* |
| 930 | * |
| 931 | */ |
| 932 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 933 | int snd_vx_mixer_new(struct vx_core *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | { |
| 935 | unsigned int i, c; |
| 936 | int err; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 937 | struct snd_kcontrol_new temp; |
| 938 | struct snd_card *card = chip->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | 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 Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 947 | temp.tlv.p = chip->hw->output_level_db_scale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | 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 | } |