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 | |
Takashi Iwai | 5e246b8 | 2008-08-08 17:12:47 +0200 | [diff] [blame] | 37 | if (snd_BUG_ON(!chip->ops->write_codec)) |
| 38 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | if (chip->chip_status & VX_STAT_IS_STALE) |
| 41 | return; |
| 42 | |
| 43 | spin_lock_irqsave(&chip->lock, flags); |
| 44 | chip->ops->write_codec(chip, codec, data); |
| 45 | spin_unlock_irqrestore(&chip->lock, flags); |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * Data type used to access the Codec |
| 50 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 51 | union vx_codec_data { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | u32 l; |
| 53 | #ifdef SNDRV_BIG_ENDIAN |
| 54 | struct w { |
| 55 | u16 h; |
| 56 | u16 l; |
| 57 | } w; |
| 58 | struct b { |
| 59 | u8 hh; |
| 60 | u8 mh; |
| 61 | u8 ml; |
| 62 | u8 ll; |
| 63 | } b; |
| 64 | #else /* LITTLE_ENDIAN */ |
| 65 | struct w { |
| 66 | u16 l; |
| 67 | u16 h; |
| 68 | } w; |
| 69 | struct b { |
| 70 | u8 ll; |
| 71 | u8 ml; |
| 72 | u8 mh; |
| 73 | u8 hh; |
| 74 | } b; |
| 75 | #endif |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 76 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | #define SET_CDC_DATA_SEL(di,s) ((di).b.mh = (u8) (s)) |
| 79 | #define SET_CDC_DATA_REG(di,r) ((di).b.ml = (u8) (r)) |
| 80 | #define SET_CDC_DATA_VAL(di,d) ((di).b.ll = (u8) (d)) |
| 81 | #define SET_CDC_DATA_INIT(di) ((di).l = 0L, SET_CDC_DATA_SEL(di,XX_CODEC_SELECTOR)) |
| 82 | |
| 83 | /* |
| 84 | * set up codec register and write the value |
| 85 | * @codec: the codec id, 0 or 1 |
| 86 | * @reg: register index |
| 87 | * @val: data value |
| 88 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 89 | 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] | 90 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 91 | union vx_codec_data data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* DAC control register */ |
| 93 | SET_CDC_DATA_INIT(data); |
| 94 | SET_CDC_DATA_REG(data, reg); |
| 95 | SET_CDC_DATA_VAL(data, val); |
| 96 | vx_write_codec_reg(chip, codec, data.l); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | /* |
| 101 | * vx_set_analog_output_level - set the output attenuation level |
| 102 | * @codec: the output codec, 0 or 1. (1 for VXP440 only) |
| 103 | * @left: left output level, 0 = mute |
| 104 | * @right: right output level |
| 105 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 106 | 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] | 107 | { |
| 108 | left = chip->hw->output_level_max - left; |
| 109 | right = chip->hw->output_level_max - right; |
| 110 | |
| 111 | if (chip->ops->akm_write) { |
| 112 | chip->ops->akm_write(chip, XX_CODEC_LEVEL_LEFT_REGISTER, left); |
| 113 | chip->ops->akm_write(chip, XX_CODEC_LEVEL_RIGHT_REGISTER, right); |
| 114 | } else { |
| 115 | /* convert to attenuation level: 0 = 0dB (max), 0xe3 = -113.5 dB (min) */ |
| 116 | vx_set_codec_reg(chip, codec, XX_CODEC_LEVEL_LEFT_REGISTER, left); |
| 117 | vx_set_codec_reg(chip, codec, XX_CODEC_LEVEL_RIGHT_REGISTER, right); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /* |
| 123 | * vx_toggle_dac_mute - mute/unmute DAC |
| 124 | * @mute: 0 = unmute, 1 = mute |
| 125 | */ |
| 126 | |
| 127 | #define DAC_ATTEN_MIN 0x08 |
| 128 | #define DAC_ATTEN_MAX 0x38 |
| 129 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 130 | void vx_toggle_dac_mute(struct vx_core *chip, int mute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
| 132 | unsigned int i; |
| 133 | for (i = 0; i < chip->hw->num_codecs; i++) { |
| 134 | if (chip->ops->akm_write) |
| 135 | chip->ops->akm_write(chip, XX_CODEC_DAC_CONTROL_REGISTER, mute); /* XXX */ |
| 136 | else |
| 137 | vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER, |
| 138 | mute ? DAC_ATTEN_MAX : DAC_ATTEN_MIN); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * vx_reset_codec - reset and initialize the codecs |
| 144 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 145 | void vx_reset_codec(struct vx_core *chip, int cold_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | unsigned int i; |
| 148 | int port = chip->type >= VX_TYPE_VXPOCKET ? 0x75 : 0x65; |
| 149 | |
| 150 | chip->ops->reset_codec(chip); |
| 151 | |
| 152 | /* AKM codecs should be initialized in reset_codec callback */ |
| 153 | if (! chip->ops->akm_write) { |
| 154 | /* initialize old codecs */ |
| 155 | for (i = 0; i < chip->hw->num_codecs; i++) { |
| 156 | /* DAC control register (change level when zero crossing + mute) */ |
| 157 | vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER, DAC_ATTEN_MAX); |
| 158 | /* ADC control register */ |
| 159 | vx_set_codec_reg(chip, i, XX_CODEC_ADC_CONTROL_REGISTER, 0x00); |
| 160 | /* Port mode register */ |
| 161 | vx_set_codec_reg(chip, i, XX_CODEC_PORT_MODE_REGISTER, port); |
| 162 | /* Clock control register */ |
| 163 | vx_set_codec_reg(chip, i, XX_CODEC_CLOCK_CONTROL_REGISTER, 0x00); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /* mute analog output */ |
| 168 | for (i = 0; i < chip->hw->num_codecs; i++) { |
| 169 | chip->output_level[i][0] = 0; |
| 170 | chip->output_level[i][1] = 0; |
| 171 | vx_set_analog_output_level(chip, i, 0, 0); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * change the audio input source |
| 177 | * @src: the target source (VX_AUDIO_SRC_XXX) |
| 178 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 179 | static void vx_change_audio_source(struct vx_core *chip, int src) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
| 181 | unsigned long flags; |
| 182 | |
| 183 | if (chip->chip_status & VX_STAT_IS_STALE) |
| 184 | return; |
| 185 | |
| 186 | spin_lock_irqsave(&chip->lock, flags); |
| 187 | chip->ops->change_audio_source(chip, src); |
| 188 | spin_unlock_irqrestore(&chip->lock, flags); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | /* |
| 193 | * change the audio source if necessary and possible |
| 194 | * returns 1 if the source is actually changed. |
| 195 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 196 | int vx_sync_audio_source(struct vx_core *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
| 198 | if (chip->audio_source_target == chip->audio_source || |
| 199 | chip->pcm_running) |
| 200 | return 0; |
| 201 | vx_change_audio_source(chip, chip->audio_source_target); |
| 202 | chip->audio_source = chip->audio_source_target; |
| 203 | return 1; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /* |
| 208 | * audio level, mute, monitoring |
| 209 | */ |
| 210 | struct vx_audio_level { |
| 211 | unsigned int has_level: 1; |
| 212 | unsigned int has_monitor_level: 1; |
| 213 | unsigned int has_mute: 1; |
| 214 | unsigned int has_monitor_mute: 1; |
| 215 | unsigned int mute; |
| 216 | unsigned int monitor_mute; |
| 217 | short level; |
| 218 | short monitor_level; |
| 219 | }; |
| 220 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 221 | 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] | 222 | struct vx_audio_level *info) |
| 223 | { |
| 224 | struct vx_rmh rmh; |
| 225 | |
| 226 | if (chip->chip_status & VX_STAT_IS_STALE) |
| 227 | return -EBUSY; |
| 228 | |
| 229 | vx_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST); |
| 230 | if (capture) |
| 231 | rmh.Cmd[0] |= COMMAND_RECORD_MASK; |
| 232 | /* Add Audio IO mask */ |
| 233 | rmh.Cmd[1] = 1 << audio; |
| 234 | rmh.Cmd[2] = 0; |
| 235 | if (info->has_level) { |
| 236 | rmh.Cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL; |
| 237 | rmh.Cmd[2] |= info->level; |
| 238 | } |
| 239 | if (info->has_monitor_level) { |
| 240 | rmh.Cmd[0] |= VALID_AUDIO_IO_MONITORING_LEVEL; |
| 241 | rmh.Cmd[2] |= ((unsigned int)info->monitor_level << 10); |
| 242 | } |
| 243 | if (info->has_mute) { |
| 244 | rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_LEVEL; |
| 245 | if (info->mute) |
| 246 | rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_LEVEL; |
| 247 | } |
| 248 | if (info->has_monitor_mute) { |
| 249 | /* validate flag for M2 at least to unmute it */ |
| 250 | rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_MONITORING_1 | VALID_AUDIO_IO_MUTE_MONITORING_2; |
| 251 | if (info->monitor_mute) |
| 252 | rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_MONITORING_1; |
| 253 | } |
| 254 | |
| 255 | return vx_send_msg(chip, &rmh); |
| 256 | } |
| 257 | |
| 258 | |
| 259 | #if 0 // not used |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 260 | 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] | 261 | struct vx_audio_level *info) |
| 262 | { |
| 263 | int err; |
| 264 | struct vx_rmh rmh; |
| 265 | |
| 266 | memset(info, 0, sizeof(*info)); |
| 267 | vx_init_rmh(&rmh, CMD_GET_AUDIO_LEVELS); |
| 268 | if (capture) |
| 269 | rmh.Cmd[0] |= COMMAND_RECORD_MASK; |
| 270 | /* Add Audio IO mask */ |
| 271 | rmh.Cmd[1] = 1 << audio; |
| 272 | err = vx_send_msg(chip, &rmh); |
| 273 | if (err < 0) |
| 274 | return err; |
| 275 | info.level = rmh.Stat[0] & MASK_DSP_WORD_LEVEL; |
| 276 | info.monitor_level = (rmh.Stat[0] >> 10) & MASK_DSP_WORD_LEVEL; |
| 277 | info.mute = (rmh.Stat[i] & AUDIO_IO_HAS_MUTE_LEVEL) ? 1 : 0; |
| 278 | info.monitor_mute = (rmh.Stat[i] & AUDIO_IO_HAS_MUTE_MONITORING_1) ? 1 : 0; |
| 279 | return 0; |
| 280 | } |
| 281 | #endif // not used |
| 282 | |
| 283 | /* |
| 284 | * set the monitoring level and mute state of the given audio |
| 285 | * no more static, because must be called from vx_pcm to demute monitoring |
| 286 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 287 | 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] | 288 | { |
| 289 | struct vx_audio_level info; |
| 290 | |
| 291 | memset(&info, 0, sizeof(info)); |
| 292 | info.has_monitor_level = 1; |
| 293 | info.monitor_level = level; |
| 294 | info.has_monitor_mute = 1; |
| 295 | info.monitor_mute = !active; |
| 296 | chip->audio_monitor[audio] = level; |
| 297 | chip->audio_monitor_active[audio] = active; |
| 298 | return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */ |
| 299 | } |
| 300 | |
| 301 | |
| 302 | /* |
| 303 | * set the mute status of the given audio |
| 304 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 305 | 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] | 306 | { |
| 307 | struct vx_audio_level info; |
| 308 | |
| 309 | memset(&info, 0, sizeof(info)); |
| 310 | info.has_mute = 1; |
| 311 | info.mute = !active; |
| 312 | chip->audio_active[audio] = active; |
| 313 | return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */ |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * set the mute status of the given audio |
| 318 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 319 | 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] | 320 | { |
| 321 | struct vx_audio_level info; |
| 322 | |
| 323 | memset(&info, 0, sizeof(info)); |
| 324 | info.has_level = 1; |
| 325 | info.level = level; |
| 326 | chip->audio_gain[capture][audio] = level; |
| 327 | return vx_adjust_audio_level(chip, audio, capture, &info); |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * reset all audio levels |
| 332 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 333 | static void vx_reset_audio_levels(struct vx_core *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
| 335 | unsigned int i, c; |
| 336 | struct vx_audio_level info; |
| 337 | |
| 338 | memset(chip->audio_gain, 0, sizeof(chip->audio_gain)); |
| 339 | memset(chip->audio_active, 0, sizeof(chip->audio_active)); |
| 340 | memset(chip->audio_monitor, 0, sizeof(chip->audio_monitor)); |
| 341 | memset(chip->audio_monitor_active, 0, sizeof(chip->audio_monitor_active)); |
| 342 | |
| 343 | for (c = 0; c < 2; c++) { |
| 344 | for (i = 0; i < chip->hw->num_ins * 2; i++) { |
| 345 | memset(&info, 0, sizeof(info)); |
| 346 | if (c == 0) { |
| 347 | info.has_monitor_level = 1; |
| 348 | info.has_mute = 1; |
| 349 | info.has_monitor_mute = 1; |
| 350 | } |
| 351 | info.has_level = 1; |
| 352 | info.level = CVAL_0DB; /* default: 0dB */ |
| 353 | vx_adjust_audio_level(chip, i, c, &info); |
| 354 | chip->audio_gain[c][i] = CVAL_0DB; |
| 355 | chip->audio_monitor[i] = CVAL_0DB; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | |
| 361 | /* |
| 362 | * VU, peak meter record |
| 363 | */ |
| 364 | |
| 365 | #define VU_METER_CHANNELS 2 |
| 366 | |
| 367 | struct vx_vu_meter { |
| 368 | int saturated; |
| 369 | int vu_level; |
| 370 | int peak_level; |
| 371 | }; |
| 372 | |
| 373 | /* |
| 374 | * get the VU and peak meter values |
| 375 | * @audio: the audio index |
| 376 | * @capture: 0 = playback, 1 = capture operation |
| 377 | * @info: the array of vx_vu_meter records (size = 2). |
| 378 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 379 | 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] | 380 | { |
| 381 | struct vx_rmh rmh; |
| 382 | int i, err; |
| 383 | |
| 384 | if (chip->chip_status & VX_STAT_IS_STALE) |
| 385 | return -EBUSY; |
| 386 | |
| 387 | vx_init_rmh(&rmh, CMD_AUDIO_VU_PIC_METER); |
| 388 | rmh.LgStat += 2 * VU_METER_CHANNELS; |
| 389 | if (capture) |
| 390 | rmh.Cmd[0] |= COMMAND_RECORD_MASK; |
| 391 | |
| 392 | /* Add Audio IO mask */ |
| 393 | rmh.Cmd[1] = 0; |
| 394 | for (i = 0; i < VU_METER_CHANNELS; i++) |
| 395 | rmh.Cmd[1] |= 1 << (audio + i); |
| 396 | err = vx_send_msg(chip, &rmh); |
| 397 | if (err < 0) |
| 398 | return err; |
| 399 | /* Read response */ |
| 400 | for (i = 0; i < 2 * VU_METER_CHANNELS; i +=2) { |
| 401 | info->saturated = (rmh.Stat[0] & (1 << (audio + i))) ? 1 : 0; |
| 402 | info->vu_level = rmh.Stat[i + 1]; |
| 403 | info->peak_level = rmh.Stat[i + 2]; |
| 404 | info++; |
| 405 | } |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | /* |
| 411 | * control API entries |
| 412 | */ |
| 413 | |
| 414 | /* |
| 415 | * output level control |
| 416 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 417 | 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] | 418 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 419 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 421 | uinfo->count = 2; |
| 422 | uinfo->value.integer.min = 0; |
| 423 | uinfo->value.integer.max = chip->hw->output_level_max; |
| 424 | return 0; |
| 425 | } |
| 426 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 427 | 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] | 428 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 429 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | int codec = kcontrol->id.index; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 431 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | ucontrol->value.integer.value[0] = chip->output_level[codec][0]; |
| 433 | ucontrol->value.integer.value[1] = chip->output_level[codec][1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 434 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | return 0; |
| 436 | } |
| 437 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 438 | 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] | 439 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 440 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | int codec = kcontrol->id.index; |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 442 | unsigned int val[2], vmax; |
| 443 | |
| 444 | vmax = chip->hw->output_level_max; |
| 445 | val[0] = ucontrol->value.integer.value[0]; |
| 446 | val[1] = ucontrol->value.integer.value[1]; |
| 447 | if (val[0] > vmax || val[1] > vmax) |
| 448 | return -EINVAL; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 449 | mutex_lock(&chip->mixer_mutex); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 450 | if (val[0] != chip->output_level[codec][0] || |
| 451 | val[1] != chip->output_level[codec][1]) { |
| 452 | vx_set_analog_output_level(chip, codec, val[0], val[1]); |
| 453 | chip->output_level[codec][0] = val[0]; |
| 454 | chip->output_level[codec][1] = val[1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 455 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return 1; |
| 457 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 458 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return 0; |
| 460 | } |
| 461 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 462 | static struct snd_kcontrol_new vx_control_output_level = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 464 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 465 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | .name = "Master Playback Volume", |
| 467 | .info = vx_output_level_info, |
| 468 | .get = vx_output_level_get, |
| 469 | .put = vx_output_level_put, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 470 | /* tlv will be filled later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | }; |
| 472 | |
| 473 | /* |
| 474 | * audio source select |
| 475 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 476 | 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] | 477 | { |
| 478 | static char *texts_mic[3] = { |
| 479 | "Digital", "Line", "Mic" |
| 480 | }; |
| 481 | static char *texts_vx2[2] = { |
| 482 | "Digital", "Analog" |
| 483 | }; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 484 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
| 486 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 487 | uinfo->count = 1; |
| 488 | if (chip->type >= VX_TYPE_VXPOCKET) { |
| 489 | uinfo->value.enumerated.items = 3; |
| 490 | if (uinfo->value.enumerated.item > 2) |
| 491 | uinfo->value.enumerated.item = 2; |
| 492 | strcpy(uinfo->value.enumerated.name, |
| 493 | texts_mic[uinfo->value.enumerated.item]); |
| 494 | } else { |
| 495 | uinfo->value.enumerated.items = 2; |
| 496 | if (uinfo->value.enumerated.item > 1) |
| 497 | uinfo->value.enumerated.item = 1; |
| 498 | strcpy(uinfo->value.enumerated.name, |
| 499 | texts_vx2[uinfo->value.enumerated.item]); |
| 500 | } |
| 501 | return 0; |
| 502 | } |
| 503 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 504 | 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] | 505 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 506 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | ucontrol->value.enumerated.item[0] = chip->audio_source_target; |
| 508 | return 0; |
| 509 | } |
| 510 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 511 | 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] | 512 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 513 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 514 | |
| 515 | if (chip->type >= VX_TYPE_VXPOCKET) { |
| 516 | if (ucontrol->value.enumerated.item[0] > 2) |
| 517 | return -EINVAL; |
| 518 | } else { |
| 519 | if (ucontrol->value.enumerated.item[0] > 1) |
| 520 | return -EINVAL; |
| 521 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 522 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) { |
| 524 | chip->audio_source_target = ucontrol->value.enumerated.item[0]; |
| 525 | vx_sync_audio_source(chip); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 526 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | return 1; |
| 528 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 529 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return 0; |
| 531 | } |
| 532 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 533 | static struct snd_kcontrol_new vx_control_audio_src = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 535 | .name = "Capture Source", |
| 536 | .info = vx_audio_src_info, |
| 537 | .get = vx_audio_src_get, |
| 538 | .put = vx_audio_src_put, |
| 539 | }; |
| 540 | |
| 541 | /* |
| 542 | * clock mode selection |
| 543 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 544 | 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] | 545 | { |
| 546 | static char *texts[3] = { |
| 547 | "Auto", "Internal", "External" |
| 548 | }; |
| 549 | |
| 550 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 551 | uinfo->count = 1; |
| 552 | uinfo->value.enumerated.items = 3; |
| 553 | if (uinfo->value.enumerated.item > 2) |
| 554 | uinfo->value.enumerated.item = 2; |
| 555 | strcpy(uinfo->value.enumerated.name, |
| 556 | texts[uinfo->value.enumerated.item]); |
| 557 | return 0; |
| 558 | } |
| 559 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 560 | 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] | 561 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 562 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | ucontrol->value.enumerated.item[0] = chip->clock_mode; |
| 564 | return 0; |
| 565 | } |
| 566 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 567 | 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] | 568 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 569 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 570 | |
| 571 | if (ucontrol->value.enumerated.item[0] > 2) |
| 572 | return -EINVAL; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 573 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | if (chip->clock_mode != ucontrol->value.enumerated.item[0]) { |
| 575 | chip->clock_mode = ucontrol->value.enumerated.item[0]; |
| 576 | vx_set_clock(chip, chip->freq); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 577 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | return 1; |
| 579 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 580 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | return 0; |
| 582 | } |
| 583 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 584 | static struct snd_kcontrol_new vx_control_clock_mode = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 586 | .name = "Clock Mode", |
| 587 | .info = vx_clock_mode_info, |
| 588 | .get = vx_clock_mode_get, |
| 589 | .put = vx_clock_mode_put, |
| 590 | }; |
| 591 | |
| 592 | /* |
| 593 | * Audio Gain |
| 594 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 595 | 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] | 596 | { |
| 597 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 598 | uinfo->count = 2; |
| 599 | uinfo->value.integer.min = 0; |
| 600 | uinfo->value.integer.max = CVAL_MAX; |
| 601 | return 0; |
| 602 | } |
| 603 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 604 | 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] | 605 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 606 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | int audio = kcontrol->private_value & 0xff; |
| 608 | int capture = (kcontrol->private_value >> 8) & 1; |
| 609 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 610 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio]; |
| 612 | ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 613 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | return 0; |
| 615 | } |
| 616 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 617 | 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] | 618 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 619 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | int audio = kcontrol->private_value & 0xff; |
| 621 | int capture = (kcontrol->private_value >> 8) & 1; |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 622 | unsigned int val[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 624 | val[0] = ucontrol->value.integer.value[0]; |
| 625 | val[1] = ucontrol->value.integer.value[1]; |
| 626 | if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) |
| 627 | return -EINVAL; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 628 | mutex_lock(&chip->mixer_mutex); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 629 | if (val[0] != chip->audio_gain[capture][audio] || |
| 630 | val[1] != chip->audio_gain[capture][audio+1]) { |
| 631 | vx_set_audio_gain(chip, audio, capture, val[0]); |
| 632 | vx_set_audio_gain(chip, audio+1, capture, val[1]); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 633 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return 1; |
| 635 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 636 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | return 0; |
| 638 | } |
| 639 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 640 | 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] | 641 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 642 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | int audio = kcontrol->private_value & 0xff; |
| 644 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 645 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | ucontrol->value.integer.value[0] = chip->audio_monitor[audio]; |
| 647 | ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 648 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return 0; |
| 650 | } |
| 651 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 652 | 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] | 653 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 654 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | int audio = kcontrol->private_value & 0xff; |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 656 | unsigned int val[2]; |
| 657 | |
| 658 | val[0] = ucontrol->value.integer.value[0]; |
| 659 | val[1] = ucontrol->value.integer.value[1]; |
| 660 | if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) |
| 661 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 663 | mutex_lock(&chip->mixer_mutex); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 664 | if (val[0] != chip->audio_monitor[audio] || |
| 665 | val[1] != chip->audio_monitor[audio+1]) { |
| 666 | vx_set_monitor_level(chip, audio, val[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | chip->audio_monitor_active[audio]); |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 668 | vx_set_monitor_level(chip, audio+1, val[1], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | chip->audio_monitor_active[audio+1]); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 670 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | return 1; |
| 672 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 673 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | return 0; |
| 675 | } |
| 676 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 677 | #define vx_audio_sw_info snd_ctl_boolean_stereo_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 679 | 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] | 680 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 681 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | int audio = kcontrol->private_value & 0xff; |
| 683 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 684 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | ucontrol->value.integer.value[0] = chip->audio_active[audio]; |
| 686 | ucontrol->value.integer.value[1] = chip->audio_active[audio+1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 687 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return 0; |
| 689 | } |
| 690 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 691 | 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] | 692 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 693 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | int audio = kcontrol->private_value & 0xff; |
| 695 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 696 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (ucontrol->value.integer.value[0] != chip->audio_active[audio] || |
| 698 | ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) { |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 699 | vx_set_audio_switch(chip, audio, |
| 700 | !!ucontrol->value.integer.value[0]); |
| 701 | vx_set_audio_switch(chip, audio+1, |
| 702 | !!ucontrol->value.integer.value[1]); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 703 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | return 1; |
| 705 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 706 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | return 0; |
| 708 | } |
| 709 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 710 | 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] | 711 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 712 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | int audio = kcontrol->private_value & 0xff; |
| 714 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 715 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio]; |
| 717 | ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1]; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 718 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 722 | 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] | 723 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 724 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | int audio = kcontrol->private_value & 0xff; |
| 726 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 727 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] || |
| 729 | ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) { |
| 730 | vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 731 | !!ucontrol->value.integer.value[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], |
Takashi Iwai | d05ab18 | 2007-11-15 16:13:32 +0100 | [diff] [blame] | 733 | !!ucontrol->value.integer.value[1]); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 734 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return 1; |
| 736 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 737 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | return 0; |
| 739 | } |
| 740 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 741 | 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] | 742 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 743 | static struct snd_kcontrol_new vx_control_audio_gain = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 745 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 746 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | /* name will be filled later */ |
| 748 | .info = vx_audio_gain_info, |
| 749 | .get = vx_audio_gain_get, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 750 | .put = vx_audio_gain_put, |
| 751 | .tlv = { .p = db_scale_audio_gain }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | }; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 753 | static struct snd_kcontrol_new vx_control_output_switch = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 755 | .name = "PCM Playback Switch", |
| 756 | .info = vx_audio_sw_info, |
| 757 | .get = vx_audio_sw_get, |
| 758 | .put = vx_audio_sw_put |
| 759 | }; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 760 | static struct snd_kcontrol_new vx_control_monitor_gain = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 762 | .name = "Monitoring Volume", |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 763 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 764 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | .info = vx_audio_gain_info, /* shared */ |
| 766 | .get = vx_audio_monitor_get, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 767 | .put = vx_audio_monitor_put, |
| 768 | .tlv = { .p = db_scale_audio_gain }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | }; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 770 | static struct snd_kcontrol_new vx_control_monitor_switch = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 772 | .name = "Monitoring Switch", |
| 773 | .info = vx_audio_sw_info, /* shared */ |
| 774 | .get = vx_monitor_sw_get, |
| 775 | .put = vx_monitor_sw_put |
| 776 | }; |
| 777 | |
| 778 | |
| 779 | /* |
| 780 | * IEC958 status bits |
| 781 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 782 | 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] | 783 | { |
| 784 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 785 | uinfo->count = 1; |
| 786 | return 0; |
| 787 | } |
| 788 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 789 | 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] | 790 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 791 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 793 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | ucontrol->value.iec958.status[0] = (chip->uer_bits >> 0) & 0xff; |
| 795 | ucontrol->value.iec958.status[1] = (chip->uer_bits >> 8) & 0xff; |
| 796 | ucontrol->value.iec958.status[2] = (chip->uer_bits >> 16) & 0xff; |
| 797 | ucontrol->value.iec958.status[3] = (chip->uer_bits >> 24) & 0xff; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 798 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | return 0; |
| 800 | } |
| 801 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 802 | 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] | 803 | { |
| 804 | ucontrol->value.iec958.status[0] = 0xff; |
| 805 | ucontrol->value.iec958.status[1] = 0xff; |
| 806 | ucontrol->value.iec958.status[2] = 0xff; |
| 807 | ucontrol->value.iec958.status[3] = 0xff; |
| 808 | return 0; |
| 809 | } |
| 810 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 811 | 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] | 812 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 813 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | unsigned int val; |
| 815 | |
| 816 | val = (ucontrol->value.iec958.status[0] << 0) | |
| 817 | (ucontrol->value.iec958.status[1] << 8) | |
| 818 | (ucontrol->value.iec958.status[2] << 16) | |
| 819 | (ucontrol->value.iec958.status[3] << 24); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 820 | mutex_lock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | if (chip->uer_bits != val) { |
| 822 | chip->uer_bits = val; |
| 823 | vx_set_iec958_status(chip, val); |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 824 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | return 1; |
| 826 | } |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 827 | mutex_unlock(&chip->mixer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | return 0; |
| 829 | } |
| 830 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 831 | static struct snd_kcontrol_new vx_control_iec958_mask = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
Clemens Ladisch | 5549d54 | 2005-08-03 13:50:30 +0200 | [diff] [blame] | 833 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), |
| 835 | .info = vx_iec958_info, /* shared */ |
| 836 | .get = vx_iec958_mask_get, |
| 837 | }; |
| 838 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 839 | static struct snd_kcontrol_new vx_control_iec958 = { |
Clemens Ladisch | 5549d54 | 2005-08-03 13:50:30 +0200 | [diff] [blame] | 840 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), |
| 842 | .info = vx_iec958_info, |
| 843 | .get = vx_iec958_get, |
| 844 | .put = vx_iec958_put |
| 845 | }; |
| 846 | |
| 847 | |
| 848 | /* |
| 849 | * VU meter |
| 850 | */ |
| 851 | |
| 852 | #define METER_MAX 0xff |
| 853 | #define METER_SHIFT 16 |
| 854 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 855 | 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] | 856 | { |
| 857 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 858 | uinfo->count = 2; |
| 859 | uinfo->value.integer.min = 0; |
| 860 | uinfo->value.integer.max = METER_MAX; |
| 861 | return 0; |
| 862 | } |
| 863 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 864 | 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] | 865 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 866 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | struct vx_vu_meter meter[2]; |
| 868 | int audio = kcontrol->private_value & 0xff; |
| 869 | int capture = (kcontrol->private_value >> 8) & 1; |
| 870 | |
| 871 | vx_get_audio_vu_meter(chip, audio, capture, meter); |
| 872 | ucontrol->value.integer.value[0] = meter[0].vu_level >> METER_SHIFT; |
| 873 | ucontrol->value.integer.value[1] = meter[1].vu_level >> METER_SHIFT; |
| 874 | return 0; |
| 875 | } |
| 876 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 877 | 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] | 878 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 879 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | struct vx_vu_meter meter[2]; |
| 881 | int audio = kcontrol->private_value & 0xff; |
| 882 | int capture = (kcontrol->private_value >> 8) & 1; |
| 883 | |
| 884 | vx_get_audio_vu_meter(chip, audio, capture, meter); |
| 885 | ucontrol->value.integer.value[0] = meter[0].peak_level >> METER_SHIFT; |
| 886 | ucontrol->value.integer.value[1] = meter[1].peak_level >> METER_SHIFT; |
| 887 | return 0; |
| 888 | } |
| 889 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 890 | #define vx_saturation_info snd_ctl_boolean_stereo_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 892 | 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] | 893 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 894 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | struct vx_vu_meter meter[2]; |
| 896 | int audio = kcontrol->private_value & 0xff; |
| 897 | |
| 898 | vx_get_audio_vu_meter(chip, audio, 1, meter); /* capture only */ |
| 899 | ucontrol->value.integer.value[0] = meter[0].saturated; |
| 900 | ucontrol->value.integer.value[1] = meter[1].saturated; |
| 901 | return 0; |
| 902 | } |
| 903 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 904 | static struct snd_kcontrol_new vx_control_vu_meter = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 906 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 907 | /* name will be filled later */ |
| 908 | .info = vx_vu_meter_info, |
| 909 | .get = vx_vu_meter_get, |
| 910 | }; |
| 911 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 912 | static struct snd_kcontrol_new vx_control_peak_meter = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 914 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 915 | /* name will be filled later */ |
| 916 | .info = vx_vu_meter_info, /* shared */ |
| 917 | .get = vx_peak_meter_get, |
| 918 | }; |
| 919 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 920 | static struct snd_kcontrol_new vx_control_saturation = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 922 | .name = "Input Saturation", |
| 923 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 924 | .info = vx_saturation_info, |
| 925 | .get = vx_saturation_get, |
| 926 | }; |
| 927 | |
| 928 | |
| 929 | |
| 930 | /* |
| 931 | * |
| 932 | */ |
| 933 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 934 | int snd_vx_mixer_new(struct vx_core *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
| 936 | unsigned int i, c; |
| 937 | int err; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 938 | struct snd_kcontrol_new temp; |
| 939 | struct snd_card *card = chip->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | char name[32]; |
| 941 | |
| 942 | strcpy(card->mixername, card->driver); |
| 943 | |
| 944 | /* output level controls */ |
| 945 | for (i = 0; i < chip->hw->num_outs; i++) { |
| 946 | temp = vx_control_output_level; |
| 947 | temp.index = i; |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 948 | temp.tlv.p = chip->hw->output_level_db_scale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 950 | return err; |
| 951 | } |
| 952 | |
| 953 | /* PCM volumes, switches, monitoring */ |
| 954 | for (i = 0; i < chip->hw->num_outs; i++) { |
| 955 | int val = i * 2; |
| 956 | temp = vx_control_audio_gain; |
| 957 | temp.index = i; |
| 958 | temp.name = "PCM Playback Volume"; |
| 959 | temp.private_value = val; |
| 960 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 961 | return err; |
| 962 | temp = vx_control_output_switch; |
| 963 | temp.index = i; |
| 964 | temp.private_value = val; |
| 965 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 966 | return err; |
| 967 | temp = vx_control_monitor_gain; |
| 968 | temp.index = i; |
| 969 | temp.private_value = val; |
| 970 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 971 | return err; |
| 972 | temp = vx_control_monitor_switch; |
| 973 | temp.index = i; |
| 974 | temp.private_value = val; |
| 975 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 976 | return err; |
| 977 | } |
| 978 | for (i = 0; i < chip->hw->num_outs; i++) { |
| 979 | temp = vx_control_audio_gain; |
| 980 | temp.index = i; |
| 981 | temp.name = "PCM Capture Volume"; |
| 982 | temp.private_value = (i * 2) | (1 << 8); |
| 983 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 984 | return err; |
| 985 | } |
| 986 | |
| 987 | /* Audio source */ |
| 988 | if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_audio_src, chip))) < 0) |
| 989 | return err; |
| 990 | /* clock mode */ |
| 991 | if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_clock_mode, chip))) < 0) |
| 992 | return err; |
| 993 | /* IEC958 controls */ |
| 994 | if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958_mask, chip))) < 0) |
| 995 | return err; |
| 996 | if ((err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958, chip))) < 0) |
| 997 | return err; |
| 998 | /* VU, peak, saturation meters */ |
| 999 | for (c = 0; c < 2; c++) { |
| 1000 | static char *dir[2] = { "Output", "Input" }; |
| 1001 | for (i = 0; i < chip->hw->num_ins; i++) { |
| 1002 | int val = (i * 2) | (c << 8); |
| 1003 | if (c == 1) { |
| 1004 | temp = vx_control_saturation; |
| 1005 | temp.index = i; |
| 1006 | temp.private_value = val; |
| 1007 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 1008 | return err; |
| 1009 | } |
| 1010 | sprintf(name, "%s VU Meter", dir[c]); |
| 1011 | temp = vx_control_vu_meter; |
| 1012 | temp.index = i; |
| 1013 | temp.name = name; |
| 1014 | temp.private_value = val; |
| 1015 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 1016 | return err; |
| 1017 | sprintf(name, "%s Peak Meter", dir[c]); |
| 1018 | temp = vx_control_peak_meter; |
| 1019 | temp.index = i; |
| 1020 | temp.name = name; |
| 1021 | temp.private_value = val; |
| 1022 | if ((err = snd_ctl_add(card, snd_ctl_new1(&temp, chip))) < 0) |
| 1023 | return err; |
| 1024 | } |
| 1025 | } |
| 1026 | vx_reset_audio_levels(chip); |
| 1027 | return 0; |
| 1028 | } |