Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * C-Media CMI8788 driver - mixer code |
| 3 | * |
| 4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> |
| 5 | * |
| 6 | * |
| 7 | * This driver is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License, version 2. |
| 9 | * |
| 10 | * This driver is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this driver; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 20 | #include <linux/mutex.h> |
| 21 | #include <sound/ac97_codec.h> |
| 22 | #include <sound/asoundef.h> |
| 23 | #include <sound/control.h> |
| 24 | #include <sound/tlv.h> |
| 25 | #include "oxygen.h" |
| 26 | |
| 27 | static int dac_volume_info(struct snd_kcontrol *ctl, |
| 28 | struct snd_ctl_elem_info *info) |
| 29 | { |
| 30 | struct oxygen *chip = ctl->private_data; |
| 31 | |
| 32 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 33 | info->count = 8; |
| 34 | info->value.integer.min = chip->model->dac_minimum_volume; |
| 35 | info->value.integer.max = 0xff; |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static int dac_volume_get(struct snd_kcontrol *ctl, |
| 40 | struct snd_ctl_elem_value *value) |
| 41 | { |
| 42 | struct oxygen *chip = ctl->private_data; |
| 43 | unsigned int i; |
| 44 | |
| 45 | mutex_lock(&chip->mutex); |
| 46 | for (i = 0; i < 8; ++i) |
| 47 | value->value.integer.value[i] = chip->dac_volume[i]; |
| 48 | mutex_unlock(&chip->mutex); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int dac_volume_put(struct snd_kcontrol *ctl, |
| 53 | struct snd_ctl_elem_value *value) |
| 54 | { |
| 55 | struct oxygen *chip = ctl->private_data; |
| 56 | unsigned int i; |
| 57 | int changed; |
| 58 | |
| 59 | changed = 0; |
| 60 | mutex_lock(&chip->mutex); |
| 61 | for (i = 0; i < 8; ++i) |
| 62 | if (value->value.integer.value[i] != chip->dac_volume[i]) { |
| 63 | chip->dac_volume[i] = value->value.integer.value[i]; |
| 64 | changed = 1; |
| 65 | } |
| 66 | if (changed) |
| 67 | chip->model->update_dac_volume(chip); |
| 68 | mutex_unlock(&chip->mutex); |
| 69 | return changed; |
| 70 | } |
| 71 | |
| 72 | static int dac_mute_get(struct snd_kcontrol *ctl, |
| 73 | struct snd_ctl_elem_value *value) |
| 74 | { |
| 75 | struct oxygen *chip = ctl->private_data; |
| 76 | |
| 77 | mutex_lock(&chip->mutex); |
| 78 | value->value.integer.value[0] = !chip->dac_mute; |
| 79 | mutex_unlock(&chip->mutex); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int dac_mute_put(struct snd_kcontrol *ctl, |
| 84 | struct snd_ctl_elem_value *value) |
| 85 | { |
| 86 | struct oxygen *chip = ctl->private_data; |
| 87 | int changed; |
| 88 | |
| 89 | mutex_lock(&chip->mutex); |
| 90 | changed = !value->value.integer.value[0] != chip->dac_mute; |
| 91 | if (changed) { |
| 92 | chip->dac_mute = !value->value.integer.value[0]; |
| 93 | chip->model->update_dac_mute(chip); |
| 94 | } |
| 95 | mutex_unlock(&chip->mutex); |
| 96 | return changed; |
| 97 | } |
| 98 | |
| 99 | static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) |
| 100 | { |
| 101 | static const char *const names[3] = { |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 102 | "Front", "Front+Surround", "Front+Surround+Back" |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 103 | }; |
| 104 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 105 | info->count = 1; |
| 106 | info->value.enumerated.items = 3; |
| 107 | if (info->value.enumerated.item > 2) |
| 108 | info->value.enumerated.item = 2; |
| 109 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) |
| 114 | { |
| 115 | struct oxygen *chip = ctl->private_data; |
| 116 | |
| 117 | mutex_lock(&chip->mutex); |
| 118 | value->value.enumerated.item[0] = chip->dac_routing; |
| 119 | mutex_unlock(&chip->mutex); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | void oxygen_update_dac_routing(struct oxygen *chip) |
| 124 | { |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 125 | static const unsigned int reg_values[3] = { |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 126 | 0xe100, /* front <- 0, surround <- 1, center <- 2, back <- 3 */ |
| 127 | 0xe000, /* front <- 0, surround <- 0, center <- 2, back <- 3 */ |
| 128 | 0x2000 /* front <- 0, surround <- 0, center <- 2, back <- 0 */ |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 129 | }; |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 130 | u8 channels; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 131 | unsigned int reg_value; |
| 132 | |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 133 | channels = oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) & |
| 134 | OXYGEN_PLAY_CHANNELS_MASK; |
| 135 | if (channels == OXYGEN_PLAY_CHANNELS_2) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 136 | reg_value = reg_values[chip->dac_routing]; |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 137 | else if (channels == OXYGEN_PLAY_CHANNELS_8) |
| 138 | reg_value = 0x6c00; /* surround <- 3, back <- 1 */ |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 139 | else |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 140 | reg_value = 0xe100; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 141 | oxygen_write16_masked(chip, OXYGEN_PLAY_ROUTING, reg_value, 0xff00); |
| 142 | } |
| 143 | |
| 144 | static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) |
| 145 | { |
| 146 | struct oxygen *chip = ctl->private_data; |
| 147 | int changed; |
| 148 | |
| 149 | mutex_lock(&chip->mutex); |
| 150 | changed = value->value.enumerated.item[0] != chip->dac_routing; |
| 151 | if (changed) { |
| 152 | chip->dac_routing = min(value->value.enumerated.item[0], 2u); |
| 153 | spin_lock_irq(&chip->reg_lock); |
| 154 | oxygen_update_dac_routing(chip); |
| 155 | spin_unlock_irq(&chip->reg_lock); |
| 156 | } |
| 157 | mutex_unlock(&chip->mutex); |
| 158 | return changed; |
| 159 | } |
| 160 | |
| 161 | static int spdif_switch_get(struct snd_kcontrol *ctl, |
| 162 | struct snd_ctl_elem_value *value) |
| 163 | { |
| 164 | struct oxygen *chip = ctl->private_data; |
| 165 | |
| 166 | mutex_lock(&chip->mutex); |
| 167 | value->value.integer.value[0] = chip->spdif_playback_enable; |
| 168 | mutex_unlock(&chip->mutex); |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate) |
| 173 | { |
| 174 | switch (oxygen_rate) { |
| 175 | case OXYGEN_RATE_32000: |
| 176 | return IEC958_AES3_CON_FS_32000 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 177 | case OXYGEN_RATE_44100: |
| 178 | return IEC958_AES3_CON_FS_44100 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 179 | default: /* OXYGEN_RATE_48000 */ |
| 180 | return IEC958_AES3_CON_FS_48000 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 181 | case OXYGEN_RATE_64000: |
| 182 | return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 183 | case OXYGEN_RATE_88200: |
| 184 | return 0x8 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 185 | case OXYGEN_RATE_96000: |
| 186 | return 0xa << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 187 | case OXYGEN_RATE_176400: |
| 188 | return 0xc << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 189 | case OXYGEN_RATE_192000: |
| 190 | return 0xe << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void oxygen_update_spdif_source(struct oxygen *chip) |
| 195 | { |
| 196 | u32 old_control, new_control; |
| 197 | u16 old_routing, new_routing; |
| 198 | unsigned int oxygen_rate; |
| 199 | |
| 200 | old_control = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL); |
| 201 | old_routing = oxygen_read16(chip, OXYGEN_PLAY_ROUTING); |
| 202 | if (chip->pcm_active & (1 << PCM_SPDIF)) { |
| 203 | new_control = old_control | OXYGEN_SPDIF_OUT_ENABLE; |
| 204 | new_routing = (old_routing & ~0x00e0) | 0x0000; |
| 205 | oxygen_rate = (old_control >> OXYGEN_SPDIF_OUT_RATE_SHIFT) |
| 206 | & OXYGEN_I2S_RATE_MASK; |
| 207 | /* S/PDIF rate was already set by the caller */ |
| 208 | } else if ((chip->pcm_active & (1 << PCM_MULTICH)) && |
| 209 | chip->spdif_playback_enable) { |
| 210 | new_routing = (old_routing & ~0x00e0) | 0x0020; |
| 211 | oxygen_rate = oxygen_read16(chip, OXYGEN_I2S_MULTICH_FORMAT) |
| 212 | & OXYGEN_I2S_RATE_MASK; |
| 213 | new_control = (old_control & ~OXYGEN_SPDIF_OUT_RATE_MASK) | |
| 214 | (oxygen_rate << OXYGEN_SPDIF_OUT_RATE_SHIFT) | |
| 215 | OXYGEN_SPDIF_OUT_ENABLE; |
| 216 | } else { |
| 217 | new_control = old_control & ~OXYGEN_SPDIF_OUT_ENABLE; |
| 218 | new_routing = old_routing; |
| 219 | oxygen_rate = OXYGEN_RATE_44100; |
| 220 | } |
| 221 | if (old_routing != new_routing) { |
| 222 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, |
| 223 | new_control & ~OXYGEN_SPDIF_OUT_ENABLE); |
| 224 | oxygen_write16(chip, OXYGEN_PLAY_ROUTING, new_routing); |
| 225 | } |
| 226 | if (new_control & OXYGEN_SPDIF_OUT_ENABLE) |
| 227 | oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, |
| 228 | oxygen_spdif_rate(oxygen_rate) | |
| 229 | ((chip->pcm_active & (1 << PCM_SPDIF)) ? |
| 230 | chip->spdif_pcm_bits : chip->spdif_bits)); |
| 231 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, new_control); |
| 232 | } |
| 233 | |
| 234 | static int spdif_switch_put(struct snd_kcontrol *ctl, |
| 235 | struct snd_ctl_elem_value *value) |
| 236 | { |
| 237 | struct oxygen *chip = ctl->private_data; |
| 238 | int changed; |
| 239 | |
| 240 | mutex_lock(&chip->mutex); |
| 241 | changed = value->value.integer.value[0] != chip->spdif_playback_enable; |
| 242 | if (changed) { |
| 243 | chip->spdif_playback_enable = !!value->value.integer.value[0]; |
| 244 | spin_lock_irq(&chip->reg_lock); |
| 245 | oxygen_update_spdif_source(chip); |
| 246 | spin_unlock_irq(&chip->reg_lock); |
| 247 | } |
| 248 | mutex_unlock(&chip->mutex); |
| 249 | return changed; |
| 250 | } |
| 251 | |
| 252 | static int spdif_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) |
| 253 | { |
| 254 | info->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 255 | info->count = 1; |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | static void oxygen_to_iec958(u32 bits, struct snd_ctl_elem_value *value) |
| 260 | { |
| 261 | value->value.iec958.status[0] = |
| 262 | bits & (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C | |
| 263 | OXYGEN_SPDIF_PREEMPHASIS); |
| 264 | value->value.iec958.status[1] = /* category and original */ |
| 265 | bits >> OXYGEN_SPDIF_CATEGORY_SHIFT; |
| 266 | } |
| 267 | |
| 268 | static u32 iec958_to_oxygen(struct snd_ctl_elem_value *value) |
| 269 | { |
| 270 | u32 bits; |
| 271 | |
| 272 | bits = value->value.iec958.status[0] & |
| 273 | (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C | |
| 274 | OXYGEN_SPDIF_PREEMPHASIS); |
| 275 | bits |= value->value.iec958.status[1] << OXYGEN_SPDIF_CATEGORY_SHIFT; |
| 276 | if (bits & OXYGEN_SPDIF_NONAUDIO) |
| 277 | bits |= OXYGEN_SPDIF_V; |
| 278 | return bits; |
| 279 | } |
| 280 | |
| 281 | static inline void write_spdif_bits(struct oxygen *chip, u32 bits) |
| 282 | { |
| 283 | oxygen_write32_masked(chip, OXYGEN_SPDIF_OUTPUT_BITS, bits, |
| 284 | OXYGEN_SPDIF_NONAUDIO | |
| 285 | OXYGEN_SPDIF_C | |
| 286 | OXYGEN_SPDIF_PREEMPHASIS | |
| 287 | OXYGEN_SPDIF_CATEGORY_MASK | |
| 288 | OXYGEN_SPDIF_ORIGINAL | |
| 289 | OXYGEN_SPDIF_V); |
| 290 | } |
| 291 | |
| 292 | static int spdif_default_get(struct snd_kcontrol *ctl, |
| 293 | struct snd_ctl_elem_value *value) |
| 294 | { |
| 295 | struct oxygen *chip = ctl->private_data; |
| 296 | |
| 297 | mutex_lock(&chip->mutex); |
| 298 | oxygen_to_iec958(chip->spdif_bits, value); |
| 299 | mutex_unlock(&chip->mutex); |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | static int spdif_default_put(struct snd_kcontrol *ctl, |
| 304 | struct snd_ctl_elem_value *value) |
| 305 | { |
| 306 | struct oxygen *chip = ctl->private_data; |
| 307 | u32 new_bits; |
| 308 | int changed; |
| 309 | |
| 310 | new_bits = iec958_to_oxygen(value); |
| 311 | mutex_lock(&chip->mutex); |
| 312 | changed = new_bits != chip->spdif_bits; |
| 313 | if (changed) { |
| 314 | chip->spdif_bits = new_bits; |
| 315 | if (!(chip->pcm_active & (1 << PCM_SPDIF))) |
| 316 | write_spdif_bits(chip, new_bits); |
| 317 | } |
| 318 | mutex_unlock(&chip->mutex); |
| 319 | return changed; |
| 320 | } |
| 321 | |
| 322 | static int spdif_mask_get(struct snd_kcontrol *ctl, |
| 323 | struct snd_ctl_elem_value *value) |
| 324 | { |
| 325 | value->value.iec958.status[0] = IEC958_AES0_NONAUDIO | |
| 326 | IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS; |
| 327 | value->value.iec958.status[1] = |
| 328 | IEC958_AES1_CON_CATEGORY | IEC958_AES1_CON_ORIGINAL; |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | static int spdif_pcm_get(struct snd_kcontrol *ctl, |
| 333 | struct snd_ctl_elem_value *value) |
| 334 | { |
| 335 | struct oxygen *chip = ctl->private_data; |
| 336 | |
| 337 | mutex_lock(&chip->mutex); |
| 338 | oxygen_to_iec958(chip->spdif_pcm_bits, value); |
| 339 | mutex_unlock(&chip->mutex); |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static int spdif_pcm_put(struct snd_kcontrol *ctl, |
| 344 | struct snd_ctl_elem_value *value) |
| 345 | { |
| 346 | struct oxygen *chip = ctl->private_data; |
| 347 | u32 new_bits; |
| 348 | int changed; |
| 349 | |
| 350 | new_bits = iec958_to_oxygen(value); |
| 351 | mutex_lock(&chip->mutex); |
| 352 | changed = new_bits != chip->spdif_pcm_bits; |
| 353 | if (changed) { |
| 354 | chip->spdif_pcm_bits = new_bits; |
| 355 | if (chip->pcm_active & (1 << PCM_SPDIF)) |
| 356 | write_spdif_bits(chip, new_bits); |
| 357 | } |
| 358 | mutex_unlock(&chip->mutex); |
| 359 | return changed; |
| 360 | } |
| 361 | |
| 362 | static int spdif_input_mask_get(struct snd_kcontrol *ctl, |
| 363 | struct snd_ctl_elem_value *value) |
| 364 | { |
| 365 | value->value.iec958.status[0] = 0xff; |
| 366 | value->value.iec958.status[1] = 0xff; |
| 367 | value->value.iec958.status[2] = 0xff; |
| 368 | value->value.iec958.status[3] = 0xff; |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static int spdif_input_default_get(struct snd_kcontrol *ctl, |
| 373 | struct snd_ctl_elem_value *value) |
| 374 | { |
| 375 | struct oxygen *chip = ctl->private_data; |
| 376 | u32 bits; |
| 377 | |
| 378 | bits = oxygen_read32(chip, OXYGEN_SPDIF_INPUT_BITS); |
| 379 | value->value.iec958.status[0] = bits; |
| 380 | value->value.iec958.status[1] = bits >> 8; |
| 381 | value->value.iec958.status[2] = bits >> 16; |
| 382 | value->value.iec958.status[3] = bits >> 24; |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int ac97_switch_get(struct snd_kcontrol *ctl, |
| 387 | struct snd_ctl_elem_value *value) |
| 388 | { |
| 389 | struct oxygen *chip = ctl->private_data; |
| 390 | unsigned int index = ctl->private_value & 0xff; |
| 391 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; |
| 392 | int invert = ctl->private_value & (1 << 16); |
| 393 | u16 reg; |
| 394 | |
| 395 | mutex_lock(&chip->mutex); |
| 396 | reg = oxygen_read_ac97(chip, 0, index); |
| 397 | mutex_unlock(&chip->mutex); |
| 398 | if (!(reg & (1 << bitnr)) ^ !invert) |
| 399 | value->value.integer.value[0] = 1; |
| 400 | else |
| 401 | value->value.integer.value[0] = 0; |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static int ac97_switch_put(struct snd_kcontrol *ctl, |
| 406 | struct snd_ctl_elem_value *value) |
| 407 | { |
| 408 | struct oxygen *chip = ctl->private_data; |
| 409 | unsigned int index = ctl->private_value & 0xff; |
| 410 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; |
| 411 | int invert = ctl->private_value & (1 << 16); |
| 412 | u16 oldreg, newreg; |
| 413 | int change; |
| 414 | |
| 415 | mutex_lock(&chip->mutex); |
| 416 | oldreg = oxygen_read_ac97(chip, 0, index); |
| 417 | newreg = oldreg; |
| 418 | if (!value->value.integer.value[0] ^ !invert) |
| 419 | newreg |= 1 << bitnr; |
| 420 | else |
| 421 | newreg &= ~(1 << bitnr); |
| 422 | change = newreg != oldreg; |
| 423 | if (change) { |
| 424 | oxygen_write_ac97(chip, 0, index, newreg); |
| 425 | if (index == AC97_LINE) |
| 426 | oxygen_write_ac97_masked(chip, 0, 0x72, |
| 427 | !!(newreg & 0x8000), 0x0001); |
| 428 | } |
| 429 | mutex_unlock(&chip->mutex); |
| 430 | return change; |
| 431 | } |
| 432 | |
| 433 | static int ac97_volume_info(struct snd_kcontrol *ctl, |
| 434 | struct snd_ctl_elem_info *info) |
| 435 | { |
| 436 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 437 | info->count = 2; |
| 438 | info->value.integer.min = 0; |
| 439 | info->value.integer.max = 0x1f; |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int ac97_volume_get(struct snd_kcontrol *ctl, |
| 444 | struct snd_ctl_elem_value *value) |
| 445 | { |
| 446 | struct oxygen *chip = ctl->private_data; |
| 447 | unsigned int index = ctl->private_value; |
| 448 | u16 reg; |
| 449 | |
| 450 | mutex_lock(&chip->mutex); |
| 451 | reg = oxygen_read_ac97(chip, 0, index); |
| 452 | mutex_unlock(&chip->mutex); |
| 453 | value->value.integer.value[0] = 31 - (reg & 0x1f); |
| 454 | value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f); |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int ac97_volume_put(struct snd_kcontrol *ctl, |
| 459 | struct snd_ctl_elem_value *value) |
| 460 | { |
| 461 | struct oxygen *chip = ctl->private_data; |
| 462 | unsigned int index = ctl->private_value; |
| 463 | u16 oldreg, newreg; |
| 464 | int change; |
| 465 | |
| 466 | mutex_lock(&chip->mutex); |
| 467 | oldreg = oxygen_read_ac97(chip, 0, index); |
| 468 | newreg = oldreg; |
| 469 | newreg = (newreg & ~0x1f) | |
| 470 | (31 - (value->value.integer.value[0] & 0x1f)); |
| 471 | newreg = (newreg & ~0x1f00) | |
| 472 | ((31 - (value->value.integer.value[0] & 0x1f)) << 8); |
| 473 | change = newreg != oldreg; |
| 474 | if (change) |
| 475 | oxygen_write_ac97(chip, 0, index, newreg); |
| 476 | mutex_unlock(&chip->mutex); |
| 477 | return change; |
| 478 | } |
| 479 | |
| 480 | #define AC97_SWITCH(xname, index, bitnr, invert) { \ |
| 481 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 482 | .name = xname, \ |
| 483 | .info = snd_ctl_boolean_mono_info, \ |
| 484 | .get = ac97_switch_get, \ |
| 485 | .put = ac97_switch_put, \ |
| 486 | .private_value = ((invert) << 16) | ((bitnr) << 8) | (index), \ |
| 487 | } |
| 488 | #define AC97_VOLUME(xname, index) { \ |
| 489 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 490 | .name = xname, \ |
| 491 | .info = ac97_volume_info, \ |
| 492 | .get = ac97_volume_get, \ |
| 493 | .put = ac97_volume_put, \ |
| 494 | .tlv = { .p = ac97_db_scale, }, \ |
| 495 | .private_value = (index), \ |
| 496 | } |
| 497 | |
| 498 | static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0); |
| 499 | |
| 500 | static const struct snd_kcontrol_new controls[] = { |
| 501 | { |
| 502 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 503 | .name = "PCM Playback Volume", |
| 504 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 505 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
| 506 | .info = dac_volume_info, |
| 507 | .get = dac_volume_get, |
| 508 | .put = dac_volume_put, |
| 509 | .tlv = { |
| 510 | .p = NULL, /* set later */ |
| 511 | }, |
| 512 | }, |
| 513 | { |
| 514 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 515 | .name = "PCM Playback Switch", |
| 516 | .info = snd_ctl_boolean_mono_info, |
| 517 | .get = dac_mute_get, |
| 518 | .put = dac_mute_put, |
| 519 | }, |
| 520 | { |
| 521 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 522 | .name = "Stereo Upmixing", |
| 523 | .info = upmix_info, |
| 524 | .get = upmix_get, |
| 525 | .put = upmix_put, |
| 526 | }, |
| 527 | { |
| 528 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 529 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), |
| 530 | .info = snd_ctl_boolean_mono_info, |
| 531 | .get = spdif_switch_get, |
| 532 | .put = spdif_switch_put, |
| 533 | }, |
| 534 | { |
| 535 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 536 | .device = 1, |
| 537 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
| 538 | .info = spdif_info, |
| 539 | .get = spdif_default_get, |
| 540 | .put = spdif_default_put, |
| 541 | }, |
| 542 | { |
| 543 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 544 | .device = 1, |
| 545 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), |
| 546 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 547 | .info = spdif_info, |
| 548 | .get = spdif_mask_get, |
| 549 | }, |
| 550 | { |
| 551 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 552 | .device = 1, |
| 553 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), |
| 554 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 555 | SNDRV_CTL_ELEM_ACCESS_INACTIVE, |
| 556 | .info = spdif_info, |
| 557 | .get = spdif_pcm_get, |
| 558 | .put = spdif_pcm_put, |
| 559 | }, |
| 560 | { |
| 561 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 562 | .device = 1, |
| 563 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK), |
| 564 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 565 | .info = spdif_info, |
| 566 | .get = spdif_input_mask_get, |
| 567 | }, |
| 568 | { |
| 569 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 570 | .device = 1, |
| 571 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), |
| 572 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 573 | .info = spdif_info, |
| 574 | .get = spdif_input_default_get, |
| 575 | }, |
| 576 | AC97_VOLUME("Mic Capture Volume", AC97_MIC), |
| 577 | AC97_SWITCH("Mic Capture Switch", AC97_MIC, 15, 1), |
| 578 | AC97_SWITCH("Mic Boost (+20dB)", AC97_MIC, 6, 0), |
| 579 | AC97_SWITCH("Line Capture Switch", AC97_LINE, 15, 1), |
| 580 | AC97_VOLUME("CD Capture Volume", AC97_CD), |
| 581 | AC97_SWITCH("CD Capture Switch", AC97_CD, 15, 1), |
| 582 | AC97_VOLUME("Aux Capture Volume", AC97_AUX), |
| 583 | AC97_SWITCH("Aux Capture Switch", AC97_AUX, 15, 1), |
| 584 | }; |
| 585 | |
| 586 | static void oxygen_any_ctl_free(struct snd_kcontrol *ctl) |
| 587 | { |
| 588 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame^] | 589 | unsigned int i; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 590 | |
| 591 | /* I'm too lazy to write a function for each control :-) */ |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame^] | 592 | for (i = 0; i < ARRAY_SIZE(chip->controls); ++i) |
| 593 | chip->controls[i] = NULL; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | int oxygen_mixer_init(struct oxygen *chip) |
| 597 | { |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame^] | 598 | static const char *const known_ctl_names[CONTROL_COUNT] = { |
| 599 | [CONTROL_SPDIF_PCM] = |
| 600 | SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), |
| 601 | [CONTROL_SPDIF_INPUT_BITS] = |
| 602 | SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), |
| 603 | }; |
| 604 | unsigned int i, j; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 605 | struct snd_kcontrol *ctl; |
| 606 | int err; |
| 607 | |
| 608 | for (i = 0; i < ARRAY_SIZE(controls); ++i) { |
| 609 | ctl = snd_ctl_new1(&controls[i], chip); |
| 610 | if (!ctl) |
| 611 | return -ENOMEM; |
| 612 | if (!strcmp(ctl->id.name, "PCM Playback Volume")) |
| 613 | ctl->tlv.p = chip->model->dac_tlv; |
| 614 | else if (chip->model->cd_in_from_video_in && |
| 615 | !strncmp(ctl->id.name, "CD Capture ", 11)) |
| 616 | ctl->private_value ^= AC97_CD ^ AC97_VIDEO; |
| 617 | err = snd_ctl_add(chip->card, ctl); |
| 618 | if (err < 0) |
| 619 | return err; |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame^] | 620 | for (j = 0; j < CONTROL_COUNT; ++j) |
| 621 | if (!strcmp(ctl->id.name, known_ctl_names[j])) { |
| 622 | chip->controls[j] = ctl; |
| 623 | ctl->private_free = oxygen_any_ctl_free; |
| 624 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 625 | } |
| 626 | return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0; |
| 627 | } |