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" |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 26 | #include "cm9780.h" |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 27 | |
| 28 | static int dac_volume_info(struct snd_kcontrol *ctl, |
| 29 | struct snd_ctl_elem_info *info) |
| 30 | { |
Clemens Ladisch | 976cd62 | 2008-01-25 08:37:49 +0100 | [diff] [blame] | 31 | struct oxygen *chip = ctl->private_data; |
| 32 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 33 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame] | 34 | info->count = chip->model.dac_channels_mixer; |
Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 35 | info->value.integer.min = chip->model.dac_volume_min; |
| 36 | info->value.integer.max = chip->model.dac_volume_max; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int dac_volume_get(struct snd_kcontrol *ctl, |
| 41 | struct snd_ctl_elem_value *value) |
| 42 | { |
| 43 | struct oxygen *chip = ctl->private_data; |
| 44 | unsigned int i; |
| 45 | |
| 46 | mutex_lock(&chip->mutex); |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame] | 47 | for (i = 0; i < chip->model.dac_channels_mixer; ++i) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 48 | value->value.integer.value[i] = chip->dac_volume[i]; |
| 49 | mutex_unlock(&chip->mutex); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int dac_volume_put(struct snd_kcontrol *ctl, |
| 54 | struct snd_ctl_elem_value *value) |
| 55 | { |
| 56 | struct oxygen *chip = ctl->private_data; |
| 57 | unsigned int i; |
| 58 | int changed; |
| 59 | |
| 60 | changed = 0; |
| 61 | mutex_lock(&chip->mutex); |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame] | 62 | for (i = 0; i < chip->model.dac_channels_mixer; ++i) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 63 | if (value->value.integer.value[i] != chip->dac_volume[i]) { |
| 64 | chip->dac_volume[i] = value->value.integer.value[i]; |
| 65 | changed = 1; |
| 66 | } |
| 67 | if (changed) |
Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 68 | chip->model.update_dac_volume(chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 69 | mutex_unlock(&chip->mutex); |
| 70 | return changed; |
| 71 | } |
| 72 | |
| 73 | static int dac_mute_get(struct snd_kcontrol *ctl, |
| 74 | struct snd_ctl_elem_value *value) |
| 75 | { |
| 76 | struct oxygen *chip = ctl->private_data; |
| 77 | |
| 78 | mutex_lock(&chip->mutex); |
| 79 | value->value.integer.value[0] = !chip->dac_mute; |
| 80 | mutex_unlock(&chip->mutex); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int dac_mute_put(struct snd_kcontrol *ctl, |
| 85 | struct snd_ctl_elem_value *value) |
| 86 | { |
| 87 | struct oxygen *chip = ctl->private_data; |
| 88 | int changed; |
| 89 | |
| 90 | mutex_lock(&chip->mutex); |
| 91 | changed = !value->value.integer.value[0] != chip->dac_mute; |
| 92 | if (changed) { |
| 93 | chip->dac_mute = !value->value.integer.value[0]; |
Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 94 | chip->model.update_dac_mute(chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 95 | } |
| 96 | mutex_unlock(&chip->mutex); |
| 97 | return changed; |
| 98 | } |
| 99 | |
Clemens Ladisch | 66410bf | 2011-01-10 16:20:29 +0100 | [diff] [blame] | 100 | static unsigned int upmix_item_count(struct oxygen *chip) |
| 101 | { |
| 102 | if (chip->model.dac_channels_pcm < 8) |
| 103 | return 2; |
| 104 | else if (chip->model.update_center_lfe_mix) |
| 105 | return 5; |
| 106 | else |
| 107 | return 3; |
| 108 | } |
| 109 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 110 | static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) |
| 111 | { |
Clemens Ladisch | 3d8bb45 | 2009-09-28 11:16:41 +0200 | [diff] [blame] | 112 | static const char *const names[5] = { |
| 113 | "Front", |
| 114 | "Front+Surround", |
| 115 | "Front+Surround+Back", |
| 116 | "Front+Surround+Center/LFE", |
| 117 | "Front+Surround+Center/LFE+Back", |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 118 | }; |
Clemens Ladisch | 976cd62 | 2008-01-25 08:37:49 +0100 | [diff] [blame] | 119 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | 66410bf | 2011-01-10 16:20:29 +0100 | [diff] [blame] | 120 | unsigned int count = upmix_item_count(chip); |
Clemens Ladisch | 976cd62 | 2008-01-25 08:37:49 +0100 | [diff] [blame] | 121 | |
Clemens Ladisch | 9600732 | 2011-01-10 16:25:44 +0100 | [diff] [blame^] | 122 | return snd_ctl_enum_info(info, 1, count, names); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) |
| 126 | { |
| 127 | struct oxygen *chip = ctl->private_data; |
| 128 | |
| 129 | mutex_lock(&chip->mutex); |
| 130 | value->value.enumerated.item[0] = chip->dac_routing; |
| 131 | mutex_unlock(&chip->mutex); |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | void oxygen_update_dac_routing(struct oxygen *chip) |
| 136 | { |
Clemens Ladisch | c9946b2 | 2008-01-21 08:44:24 +0100 | [diff] [blame] | 137 | /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */ |
Clemens Ladisch | 3d8bb45 | 2009-09-28 11:16:41 +0200 | [diff] [blame] | 138 | static const unsigned int reg_values[5] = { |
Clemens Ladisch | c9946b2 | 2008-01-21 08:44:24 +0100 | [diff] [blame] | 139 | /* stereo -> front */ |
| 140 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | |
| 141 | (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
| 142 | (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | |
| 143 | (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), |
| 144 | /* stereo -> front+surround */ |
| 145 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | |
| 146 | (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
| 147 | (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | |
| 148 | (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), |
| 149 | /* stereo -> front+surround+back */ |
| 150 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | |
| 151 | (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
| 152 | (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | |
| 153 | (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), |
Clemens Ladisch | 3d8bb45 | 2009-09-28 11:16:41 +0200 | [diff] [blame] | 154 | /* stereo -> front+surround+center/LFE */ |
| 155 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | |
| 156 | (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
| 157 | (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | |
| 158 | (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), |
| 159 | /* stereo -> front+surround+center/LFE+back */ |
| 160 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | |
| 161 | (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
| 162 | (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | |
| 163 | (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 164 | }; |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 165 | u8 channels; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 166 | unsigned int reg_value; |
| 167 | |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 168 | channels = oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) & |
| 169 | OXYGEN_PLAY_CHANNELS_MASK; |
| 170 | if (channels == OXYGEN_PLAY_CHANNELS_2) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 171 | reg_value = reg_values[chip->dac_routing]; |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 172 | else if (channels == OXYGEN_PLAY_CHANNELS_8) |
Clemens Ladisch | c9946b2 | 2008-01-21 08:44:24 +0100 | [diff] [blame] | 173 | /* in 7.1 mode, "rear" channels go to the "back" jack */ |
| 174 | reg_value = (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | |
| 175 | (3 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
| 176 | (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | |
| 177 | (1 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 178 | else |
Clemens Ladisch | c9946b2 | 2008-01-21 08:44:24 +0100 | [diff] [blame] | 179 | reg_value = (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | |
| 180 | (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
| 181 | (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | |
| 182 | (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT); |
| 183 | oxygen_write16_masked(chip, OXYGEN_PLAY_ROUTING, reg_value, |
| 184 | OXYGEN_PLAY_DAC0_SOURCE_MASK | |
| 185 | OXYGEN_PLAY_DAC1_SOURCE_MASK | |
| 186 | OXYGEN_PLAY_DAC2_SOURCE_MASK | |
| 187 | OXYGEN_PLAY_DAC3_SOURCE_MASK); |
Clemens Ladisch | 3d8bb45 | 2009-09-28 11:16:41 +0200 | [diff] [blame] | 188 | if (chip->model.update_center_lfe_mix) |
| 189 | chip->model.update_center_lfe_mix(chip, chip->dac_routing > 2); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) |
| 193 | { |
| 194 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | 66410bf | 2011-01-10 16:20:29 +0100 | [diff] [blame] | 195 | unsigned int count = upmix_item_count(chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 196 | int changed; |
| 197 | |
Clemens Ladisch | 3d8bb45 | 2009-09-28 11:16:41 +0200 | [diff] [blame] | 198 | if (value->value.enumerated.item[0] >= count) |
| 199 | return -EINVAL; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 200 | mutex_lock(&chip->mutex); |
| 201 | changed = value->value.enumerated.item[0] != chip->dac_routing; |
| 202 | if (changed) { |
Clemens Ladisch | 3d8bb45 | 2009-09-28 11:16:41 +0200 | [diff] [blame] | 203 | chip->dac_routing = value->value.enumerated.item[0]; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 204 | oxygen_update_dac_routing(chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 205 | } |
| 206 | mutex_unlock(&chip->mutex); |
| 207 | return changed; |
| 208 | } |
| 209 | |
| 210 | static int spdif_switch_get(struct snd_kcontrol *ctl, |
| 211 | struct snd_ctl_elem_value *value) |
| 212 | { |
| 213 | struct oxygen *chip = ctl->private_data; |
| 214 | |
| 215 | mutex_lock(&chip->mutex); |
| 216 | value->value.integer.value[0] = chip->spdif_playback_enable; |
| 217 | mutex_unlock(&chip->mutex); |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate) |
| 222 | { |
| 223 | switch (oxygen_rate) { |
| 224 | case OXYGEN_RATE_32000: |
| 225 | return IEC958_AES3_CON_FS_32000 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 226 | case OXYGEN_RATE_44100: |
| 227 | return IEC958_AES3_CON_FS_44100 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 228 | default: /* OXYGEN_RATE_48000 */ |
| 229 | return IEC958_AES3_CON_FS_48000 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 230 | case OXYGEN_RATE_64000: |
| 231 | return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT; |
| 232 | case OXYGEN_RATE_88200: |
Clemens Ladisch | 6627bea | 2008-09-22 08:53:31 +0200 | [diff] [blame] | 233 | return IEC958_AES3_CON_FS_88200 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 234 | case OXYGEN_RATE_96000: |
Clemens Ladisch | 6627bea | 2008-09-22 08:53:31 +0200 | [diff] [blame] | 235 | return IEC958_AES3_CON_FS_96000 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 236 | case OXYGEN_RATE_176400: |
Clemens Ladisch | 6627bea | 2008-09-22 08:53:31 +0200 | [diff] [blame] | 237 | return IEC958_AES3_CON_FS_176400 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 238 | case OXYGEN_RATE_192000: |
Clemens Ladisch | 6627bea | 2008-09-22 08:53:31 +0200 | [diff] [blame] | 239 | return IEC958_AES3_CON_FS_192000 << OXYGEN_SPDIF_CS_RATE_SHIFT; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | void oxygen_update_spdif_source(struct oxygen *chip) |
| 244 | { |
| 245 | u32 old_control, new_control; |
| 246 | u16 old_routing, new_routing; |
| 247 | unsigned int oxygen_rate; |
| 248 | |
| 249 | old_control = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL); |
| 250 | old_routing = oxygen_read16(chip, OXYGEN_PLAY_ROUTING); |
| 251 | if (chip->pcm_active & (1 << PCM_SPDIF)) { |
| 252 | new_control = old_control | OXYGEN_SPDIF_OUT_ENABLE; |
Clemens Ladisch | c9946b2 | 2008-01-21 08:44:24 +0100 | [diff] [blame] | 253 | new_routing = (old_routing & ~OXYGEN_PLAY_SPDIF_MASK) |
| 254 | | OXYGEN_PLAY_SPDIF_SPDIF; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 255 | oxygen_rate = (old_control >> OXYGEN_SPDIF_OUT_RATE_SHIFT) |
| 256 | & OXYGEN_I2S_RATE_MASK; |
| 257 | /* S/PDIF rate was already set by the caller */ |
| 258 | } else if ((chip->pcm_active & (1 << PCM_MULTICH)) && |
| 259 | chip->spdif_playback_enable) { |
Clemens Ladisch | c9946b2 | 2008-01-21 08:44:24 +0100 | [diff] [blame] | 260 | new_routing = (old_routing & ~OXYGEN_PLAY_SPDIF_MASK) |
| 261 | | OXYGEN_PLAY_SPDIF_MULTICH_01; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 262 | oxygen_rate = oxygen_read16(chip, OXYGEN_I2S_MULTICH_FORMAT) |
| 263 | & OXYGEN_I2S_RATE_MASK; |
| 264 | new_control = (old_control & ~OXYGEN_SPDIF_OUT_RATE_MASK) | |
| 265 | (oxygen_rate << OXYGEN_SPDIF_OUT_RATE_SHIFT) | |
| 266 | OXYGEN_SPDIF_OUT_ENABLE; |
| 267 | } else { |
| 268 | new_control = old_control & ~OXYGEN_SPDIF_OUT_ENABLE; |
| 269 | new_routing = old_routing; |
| 270 | oxygen_rate = OXYGEN_RATE_44100; |
| 271 | } |
| 272 | if (old_routing != new_routing) { |
| 273 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, |
| 274 | new_control & ~OXYGEN_SPDIF_OUT_ENABLE); |
| 275 | oxygen_write16(chip, OXYGEN_PLAY_ROUTING, new_routing); |
| 276 | } |
| 277 | if (new_control & OXYGEN_SPDIF_OUT_ENABLE) |
| 278 | oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, |
| 279 | oxygen_spdif_rate(oxygen_rate) | |
| 280 | ((chip->pcm_active & (1 << PCM_SPDIF)) ? |
| 281 | chip->spdif_pcm_bits : chip->spdif_bits)); |
| 282 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, new_control); |
| 283 | } |
| 284 | |
| 285 | static int spdif_switch_put(struct snd_kcontrol *ctl, |
| 286 | struct snd_ctl_elem_value *value) |
| 287 | { |
| 288 | struct oxygen *chip = ctl->private_data; |
| 289 | int changed; |
| 290 | |
| 291 | mutex_lock(&chip->mutex); |
| 292 | changed = value->value.integer.value[0] != chip->spdif_playback_enable; |
| 293 | if (changed) { |
| 294 | chip->spdif_playback_enable = !!value->value.integer.value[0]; |
| 295 | spin_lock_irq(&chip->reg_lock); |
| 296 | oxygen_update_spdif_source(chip); |
| 297 | spin_unlock_irq(&chip->reg_lock); |
| 298 | } |
| 299 | mutex_unlock(&chip->mutex); |
| 300 | return changed; |
| 301 | } |
| 302 | |
| 303 | static int spdif_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) |
| 304 | { |
| 305 | info->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 306 | info->count = 1; |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static void oxygen_to_iec958(u32 bits, struct snd_ctl_elem_value *value) |
| 311 | { |
| 312 | value->value.iec958.status[0] = |
| 313 | bits & (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C | |
| 314 | OXYGEN_SPDIF_PREEMPHASIS); |
| 315 | value->value.iec958.status[1] = /* category and original */ |
| 316 | bits >> OXYGEN_SPDIF_CATEGORY_SHIFT; |
| 317 | } |
| 318 | |
| 319 | static u32 iec958_to_oxygen(struct snd_ctl_elem_value *value) |
| 320 | { |
| 321 | u32 bits; |
| 322 | |
| 323 | bits = value->value.iec958.status[0] & |
| 324 | (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C | |
| 325 | OXYGEN_SPDIF_PREEMPHASIS); |
| 326 | bits |= value->value.iec958.status[1] << OXYGEN_SPDIF_CATEGORY_SHIFT; |
| 327 | if (bits & OXYGEN_SPDIF_NONAUDIO) |
| 328 | bits |= OXYGEN_SPDIF_V; |
| 329 | return bits; |
| 330 | } |
| 331 | |
| 332 | static inline void write_spdif_bits(struct oxygen *chip, u32 bits) |
| 333 | { |
| 334 | oxygen_write32_masked(chip, OXYGEN_SPDIF_OUTPUT_BITS, bits, |
| 335 | OXYGEN_SPDIF_NONAUDIO | |
| 336 | OXYGEN_SPDIF_C | |
| 337 | OXYGEN_SPDIF_PREEMPHASIS | |
| 338 | OXYGEN_SPDIF_CATEGORY_MASK | |
| 339 | OXYGEN_SPDIF_ORIGINAL | |
| 340 | OXYGEN_SPDIF_V); |
| 341 | } |
| 342 | |
| 343 | static int spdif_default_get(struct snd_kcontrol *ctl, |
| 344 | struct snd_ctl_elem_value *value) |
| 345 | { |
| 346 | struct oxygen *chip = ctl->private_data; |
| 347 | |
| 348 | mutex_lock(&chip->mutex); |
| 349 | oxygen_to_iec958(chip->spdif_bits, value); |
| 350 | mutex_unlock(&chip->mutex); |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static int spdif_default_put(struct snd_kcontrol *ctl, |
| 355 | struct snd_ctl_elem_value *value) |
| 356 | { |
| 357 | struct oxygen *chip = ctl->private_data; |
| 358 | u32 new_bits; |
| 359 | int changed; |
| 360 | |
| 361 | new_bits = iec958_to_oxygen(value); |
| 362 | mutex_lock(&chip->mutex); |
| 363 | changed = new_bits != chip->spdif_bits; |
| 364 | if (changed) { |
| 365 | chip->spdif_bits = new_bits; |
| 366 | if (!(chip->pcm_active & (1 << PCM_SPDIF))) |
| 367 | write_spdif_bits(chip, new_bits); |
| 368 | } |
| 369 | mutex_unlock(&chip->mutex); |
| 370 | return changed; |
| 371 | } |
| 372 | |
| 373 | static int spdif_mask_get(struct snd_kcontrol *ctl, |
| 374 | struct snd_ctl_elem_value *value) |
| 375 | { |
| 376 | value->value.iec958.status[0] = IEC958_AES0_NONAUDIO | |
| 377 | IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS; |
| 378 | value->value.iec958.status[1] = |
| 379 | IEC958_AES1_CON_CATEGORY | IEC958_AES1_CON_ORIGINAL; |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | static int spdif_pcm_get(struct snd_kcontrol *ctl, |
| 384 | struct snd_ctl_elem_value *value) |
| 385 | { |
| 386 | struct oxygen *chip = ctl->private_data; |
| 387 | |
| 388 | mutex_lock(&chip->mutex); |
| 389 | oxygen_to_iec958(chip->spdif_pcm_bits, value); |
| 390 | mutex_unlock(&chip->mutex); |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static int spdif_pcm_put(struct snd_kcontrol *ctl, |
| 395 | struct snd_ctl_elem_value *value) |
| 396 | { |
| 397 | struct oxygen *chip = ctl->private_data; |
| 398 | u32 new_bits; |
| 399 | int changed; |
| 400 | |
| 401 | new_bits = iec958_to_oxygen(value); |
| 402 | mutex_lock(&chip->mutex); |
| 403 | changed = new_bits != chip->spdif_pcm_bits; |
| 404 | if (changed) { |
| 405 | chip->spdif_pcm_bits = new_bits; |
| 406 | if (chip->pcm_active & (1 << PCM_SPDIF)) |
| 407 | write_spdif_bits(chip, new_bits); |
| 408 | } |
| 409 | mutex_unlock(&chip->mutex); |
| 410 | return changed; |
| 411 | } |
| 412 | |
| 413 | static int spdif_input_mask_get(struct snd_kcontrol *ctl, |
| 414 | struct snd_ctl_elem_value *value) |
| 415 | { |
| 416 | value->value.iec958.status[0] = 0xff; |
| 417 | value->value.iec958.status[1] = 0xff; |
| 418 | value->value.iec958.status[2] = 0xff; |
| 419 | value->value.iec958.status[3] = 0xff; |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | static int spdif_input_default_get(struct snd_kcontrol *ctl, |
| 424 | struct snd_ctl_elem_value *value) |
| 425 | { |
| 426 | struct oxygen *chip = ctl->private_data; |
| 427 | u32 bits; |
| 428 | |
| 429 | bits = oxygen_read32(chip, OXYGEN_SPDIF_INPUT_BITS); |
| 430 | value->value.iec958.status[0] = bits; |
| 431 | value->value.iec958.status[1] = bits >> 8; |
| 432 | value->value.iec958.status[2] = bits >> 16; |
| 433 | value->value.iec958.status[3] = bits >> 24; |
| 434 | return 0; |
| 435 | } |
| 436 | |
Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 437 | static int spdif_loopback_get(struct snd_kcontrol *ctl, |
| 438 | struct snd_ctl_elem_value *value) |
| 439 | { |
| 440 | struct oxygen *chip = ctl->private_data; |
| 441 | |
| 442 | value->value.integer.value[0] = |
| 443 | !!(oxygen_read32(chip, OXYGEN_SPDIF_CONTROL) |
| 444 | & OXYGEN_SPDIF_LOOPBACK); |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int spdif_loopback_put(struct snd_kcontrol *ctl, |
| 449 | struct snd_ctl_elem_value *value) |
| 450 | { |
| 451 | struct oxygen *chip = ctl->private_data; |
| 452 | u32 oldreg, newreg; |
| 453 | int changed; |
| 454 | |
| 455 | spin_lock_irq(&chip->reg_lock); |
| 456 | oldreg = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL); |
| 457 | if (value->value.integer.value[0]) |
| 458 | newreg = oldreg | OXYGEN_SPDIF_LOOPBACK; |
| 459 | else |
| 460 | newreg = oldreg & ~OXYGEN_SPDIF_LOOPBACK; |
| 461 | changed = newreg != oldreg; |
| 462 | if (changed) |
| 463 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, newreg); |
| 464 | spin_unlock_irq(&chip->reg_lock); |
| 465 | return changed; |
| 466 | } |
| 467 | |
Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 468 | static int monitor_volume_info(struct snd_kcontrol *ctl, |
| 469 | struct snd_ctl_elem_info *info) |
| 470 | { |
| 471 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 472 | info->count = 1; |
| 473 | info->value.integer.min = 0; |
| 474 | info->value.integer.max = 1; |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | static int monitor_get(struct snd_kcontrol *ctl, |
| 479 | struct snd_ctl_elem_value *value) |
| 480 | { |
| 481 | struct oxygen *chip = ctl->private_data; |
| 482 | u8 bit = ctl->private_value; |
| 483 | int invert = ctl->private_value & (1 << 8); |
| 484 | |
| 485 | value->value.integer.value[0] = |
| 486 | !!invert ^ !!(oxygen_read8(chip, OXYGEN_ADC_MONITOR) & bit); |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | static int monitor_put(struct snd_kcontrol *ctl, |
| 491 | struct snd_ctl_elem_value *value) |
| 492 | { |
| 493 | struct oxygen *chip = ctl->private_data; |
| 494 | u8 bit = ctl->private_value; |
| 495 | int invert = ctl->private_value & (1 << 8); |
| 496 | u8 oldreg, newreg; |
| 497 | int changed; |
| 498 | |
| 499 | spin_lock_irq(&chip->reg_lock); |
| 500 | oldreg = oxygen_read8(chip, OXYGEN_ADC_MONITOR); |
| 501 | if ((!!value->value.integer.value[0] ^ !!invert) != 0) |
| 502 | newreg = oldreg | bit; |
| 503 | else |
| 504 | newreg = oldreg & ~bit; |
| 505 | changed = newreg != oldreg; |
| 506 | if (changed) |
| 507 | oxygen_write8(chip, OXYGEN_ADC_MONITOR, newreg); |
| 508 | spin_unlock_irq(&chip->reg_lock); |
| 509 | return changed; |
| 510 | } |
| 511 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 512 | static int ac97_switch_get(struct snd_kcontrol *ctl, |
| 513 | struct snd_ctl_elem_value *value) |
| 514 | { |
| 515 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 516 | unsigned int codec = (ctl->private_value >> 24) & 1; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 517 | unsigned int index = ctl->private_value & 0xff; |
| 518 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; |
| 519 | int invert = ctl->private_value & (1 << 16); |
| 520 | u16 reg; |
| 521 | |
| 522 | mutex_lock(&chip->mutex); |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 523 | reg = oxygen_read_ac97(chip, codec, index); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 524 | mutex_unlock(&chip->mutex); |
| 525 | if (!(reg & (1 << bitnr)) ^ !invert) |
| 526 | value->value.integer.value[0] = 1; |
| 527 | else |
| 528 | value->value.integer.value[0] = 0; |
| 529 | return 0; |
| 530 | } |
| 531 | |
Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 532 | static void mute_ac97_ctl(struct oxygen *chip, unsigned int control) |
| 533 | { |
Clemens Ladisch | 3d839e5 | 2008-08-26 11:06:26 +0200 | [diff] [blame] | 534 | unsigned int priv_idx; |
Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 535 | u16 value; |
| 536 | |
Clemens Ladisch | 3d839e5 | 2008-08-26 11:06:26 +0200 | [diff] [blame] | 537 | if (!chip->controls[control]) |
| 538 | return; |
| 539 | priv_idx = chip->controls[control]->private_value & 0xff; |
Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 540 | value = oxygen_read_ac97(chip, 0, priv_idx); |
| 541 | if (!(value & 0x8000)) { |
| 542 | oxygen_write_ac97(chip, 0, priv_idx, value | 0x8000); |
Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 543 | if (chip->model.ac97_switch) |
| 544 | chip->model.ac97_switch(chip, priv_idx, 0x8000); |
Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 545 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 546 | &chip->controls[control]->id); |
| 547 | } |
| 548 | } |
| 549 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 550 | static int ac97_switch_put(struct snd_kcontrol *ctl, |
| 551 | struct snd_ctl_elem_value *value) |
| 552 | { |
| 553 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 554 | unsigned int codec = (ctl->private_value >> 24) & 1; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 555 | unsigned int index = ctl->private_value & 0xff; |
| 556 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; |
| 557 | int invert = ctl->private_value & (1 << 16); |
| 558 | u16 oldreg, newreg; |
| 559 | int change; |
| 560 | |
| 561 | mutex_lock(&chip->mutex); |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 562 | oldreg = oxygen_read_ac97(chip, codec, index); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 563 | newreg = oldreg; |
| 564 | if (!value->value.integer.value[0] ^ !invert) |
| 565 | newreg |= 1 << bitnr; |
| 566 | else |
| 567 | newreg &= ~(1 << bitnr); |
| 568 | change = newreg != oldreg; |
| 569 | if (change) { |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 570 | oxygen_write_ac97(chip, codec, index, newreg); |
Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 571 | if (codec == 0 && chip->model.ac97_switch) |
| 572 | chip->model.ac97_switch(chip, index, newreg & 0x8000); |
Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 573 | if (index == AC97_LINE) { |
| 574 | oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS, |
| 575 | newreg & 0x8000 ? |
| 576 | CM9780_GPO0 : 0, CM9780_GPO0); |
| 577 | if (!(newreg & 0x8000)) { |
| 578 | mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH); |
| 579 | mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH); |
| 580 | mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH); |
| 581 | } |
| 582 | } else if ((index == AC97_MIC || index == AC97_CD || |
| 583 | index == AC97_VIDEO || index == AC97_AUX) && |
| 584 | bitnr == 15 && !(newreg & 0x8000)) { |
| 585 | mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH); |
| 586 | oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS, |
| 587 | CM9780_GPO0, CM9780_GPO0); |
| 588 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 589 | } |
| 590 | mutex_unlock(&chip->mutex); |
| 591 | return change; |
| 592 | } |
| 593 | |
| 594 | static int ac97_volume_info(struct snd_kcontrol *ctl, |
| 595 | struct snd_ctl_elem_info *info) |
| 596 | { |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 597 | int stereo = (ctl->private_value >> 16) & 1; |
| 598 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 599 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 600 | info->count = stereo ? 2 : 1; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 601 | info->value.integer.min = 0; |
| 602 | info->value.integer.max = 0x1f; |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | static int ac97_volume_get(struct snd_kcontrol *ctl, |
| 607 | struct snd_ctl_elem_value *value) |
| 608 | { |
| 609 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 610 | unsigned int codec = (ctl->private_value >> 24) & 1; |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 611 | int stereo = (ctl->private_value >> 16) & 1; |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 612 | unsigned int index = ctl->private_value & 0xff; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 613 | u16 reg; |
| 614 | |
| 615 | mutex_lock(&chip->mutex); |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 616 | reg = oxygen_read_ac97(chip, codec, index); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 617 | mutex_unlock(&chip->mutex); |
| 618 | value->value.integer.value[0] = 31 - (reg & 0x1f); |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 619 | if (stereo) |
| 620 | value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | static int ac97_volume_put(struct snd_kcontrol *ctl, |
| 625 | struct snd_ctl_elem_value *value) |
| 626 | { |
| 627 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 628 | unsigned int codec = (ctl->private_value >> 24) & 1; |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 629 | int stereo = (ctl->private_value >> 16) & 1; |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 630 | unsigned int index = ctl->private_value & 0xff; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 631 | u16 oldreg, newreg; |
| 632 | int change; |
| 633 | |
| 634 | mutex_lock(&chip->mutex); |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 635 | oldreg = oxygen_read_ac97(chip, codec, index); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 636 | newreg = oldreg; |
| 637 | newreg = (newreg & ~0x1f) | |
| 638 | (31 - (value->value.integer.value[0] & 0x1f)); |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 639 | if (stereo) |
| 640 | newreg = (newreg & ~0x1f00) | |
| 641 | ((31 - (value->value.integer.value[1] & 0x1f)) << 8); |
| 642 | else |
| 643 | newreg = (newreg & ~0x1f00) | ((newreg & 0x1f) << 8); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 644 | change = newreg != oldreg; |
| 645 | if (change) |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 646 | oxygen_write_ac97(chip, codec, index, newreg); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 647 | mutex_unlock(&chip->mutex); |
| 648 | return change; |
| 649 | } |
| 650 | |
Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 651 | static int mic_fmic_source_info(struct snd_kcontrol *ctl, |
| 652 | struct snd_ctl_elem_info *info) |
| 653 | { |
| 654 | static const char *const names[] = { "Mic Jack", "Front Panel" }; |
| 655 | |
Clemens Ladisch | 9600732 | 2011-01-10 16:25:44 +0100 | [diff] [blame^] | 656 | return snd_ctl_enum_info(info, 1, 2, names); |
Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static int mic_fmic_source_get(struct snd_kcontrol *ctl, |
| 660 | struct snd_ctl_elem_value *value) |
| 661 | { |
| 662 | struct oxygen *chip = ctl->private_data; |
| 663 | |
| 664 | mutex_lock(&chip->mutex); |
| 665 | value->value.enumerated.item[0] = |
| 666 | !!(oxygen_read_ac97(chip, 0, CM9780_JACK) & CM9780_FMIC2MIC); |
| 667 | mutex_unlock(&chip->mutex); |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | static int mic_fmic_source_put(struct snd_kcontrol *ctl, |
| 672 | struct snd_ctl_elem_value *value) |
| 673 | { |
| 674 | struct oxygen *chip = ctl->private_data; |
| 675 | u16 oldreg, newreg; |
| 676 | int change; |
| 677 | |
| 678 | mutex_lock(&chip->mutex); |
| 679 | oldreg = oxygen_read_ac97(chip, 0, CM9780_JACK); |
| 680 | if (value->value.enumerated.item[0]) |
| 681 | newreg = oldreg | CM9780_FMIC2MIC; |
| 682 | else |
| 683 | newreg = oldreg & ~CM9780_FMIC2MIC; |
| 684 | change = newreg != oldreg; |
| 685 | if (change) |
| 686 | oxygen_write_ac97(chip, 0, CM9780_JACK, newreg); |
| 687 | mutex_unlock(&chip->mutex); |
| 688 | return change; |
| 689 | } |
| 690 | |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 691 | static int ac97_fp_rec_volume_info(struct snd_kcontrol *ctl, |
| 692 | struct snd_ctl_elem_info *info) |
| 693 | { |
| 694 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 695 | info->count = 2; |
| 696 | info->value.integer.min = 0; |
| 697 | info->value.integer.max = 7; |
| 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | static int ac97_fp_rec_volume_get(struct snd_kcontrol *ctl, |
| 702 | struct snd_ctl_elem_value *value) |
| 703 | { |
| 704 | struct oxygen *chip = ctl->private_data; |
| 705 | u16 reg; |
| 706 | |
| 707 | mutex_lock(&chip->mutex); |
| 708 | reg = oxygen_read_ac97(chip, 1, AC97_REC_GAIN); |
| 709 | mutex_unlock(&chip->mutex); |
| 710 | value->value.integer.value[0] = reg & 7; |
| 711 | value->value.integer.value[1] = (reg >> 8) & 7; |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl, |
| 716 | struct snd_ctl_elem_value *value) |
| 717 | { |
| 718 | struct oxygen *chip = ctl->private_data; |
| 719 | u16 oldreg, newreg; |
| 720 | int change; |
| 721 | |
| 722 | mutex_lock(&chip->mutex); |
| 723 | oldreg = oxygen_read_ac97(chip, 1, AC97_REC_GAIN); |
| 724 | newreg = oldreg & ~0x0707; |
| 725 | newreg = newreg | (value->value.integer.value[0] & 7); |
| 726 | newreg = newreg | ((value->value.integer.value[0] & 7) << 8); |
| 727 | change = newreg != oldreg; |
| 728 | if (change) |
| 729 | oxygen_write_ac97(chip, 1, AC97_REC_GAIN, newreg); |
| 730 | mutex_unlock(&chip->mutex); |
| 731 | return change; |
| 732 | } |
| 733 | |
| 734 | #define AC97_SWITCH(xname, codec, index, bitnr, invert) { \ |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 735 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 736 | .name = xname, \ |
| 737 | .info = snd_ctl_boolean_mono_info, \ |
| 738 | .get = ac97_switch_get, \ |
| 739 | .put = ac97_switch_put, \ |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 740 | .private_value = ((codec) << 24) | ((invert) << 16) | \ |
| 741 | ((bitnr) << 8) | (index), \ |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 742 | } |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 743 | #define AC97_VOLUME(xname, codec, index, stereo) { \ |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 744 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 745 | .name = xname, \ |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 746 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 747 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 748 | .info = ac97_volume_info, \ |
| 749 | .get = ac97_volume_get, \ |
| 750 | .put = ac97_volume_put, \ |
| 751 | .tlv = { .p = ac97_db_scale, }, \ |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 752 | .private_value = ((codec) << 24) | ((stereo) << 16) | (index), \ |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 753 | } |
| 754 | |
Clemens Ladisch | 9a0b379 | 2010-10-04 13:25:13 +0200 | [diff] [blame] | 755 | static DECLARE_TLV_DB_SCALE(monitor_db_scale, -600, 600, 0); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 756 | static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0); |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 757 | static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 758 | |
| 759 | static const struct snd_kcontrol_new controls[] = { |
| 760 | { |
| 761 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | fb920b7 | 2008-01-15 08:39:06 +0100 | [diff] [blame] | 762 | .name = "Master Playback Volume", |
Clemens Ladisch | ccc80fb | 2008-01-16 08:32:08 +0100 | [diff] [blame] | 763 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 764 | .info = dac_volume_info, |
| 765 | .get = dac_volume_get, |
| 766 | .put = dac_volume_put, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 767 | }, |
| 768 | { |
| 769 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | fb920b7 | 2008-01-15 08:39:06 +0100 | [diff] [blame] | 770 | .name = "Master Playback Switch", |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 771 | .info = snd_ctl_boolean_mono_info, |
| 772 | .get = dac_mute_get, |
| 773 | .put = dac_mute_put, |
| 774 | }, |
| 775 | { |
| 776 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 777 | .name = "Stereo Upmixing", |
| 778 | .info = upmix_info, |
| 779 | .get = upmix_get, |
| 780 | .put = upmix_put, |
| 781 | }, |
| 782 | { |
| 783 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 784 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), |
| 785 | .info = snd_ctl_boolean_mono_info, |
| 786 | .get = spdif_switch_get, |
| 787 | .put = spdif_switch_put, |
| 788 | }, |
| 789 | { |
| 790 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 791 | .device = 1, |
| 792 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
| 793 | .info = spdif_info, |
| 794 | .get = spdif_default_get, |
| 795 | .put = spdif_default_put, |
| 796 | }, |
| 797 | { |
| 798 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 799 | .device = 1, |
| 800 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), |
| 801 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 802 | .info = spdif_info, |
| 803 | .get = spdif_mask_get, |
| 804 | }, |
| 805 | { |
| 806 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 807 | .device = 1, |
| 808 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), |
| 809 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 810 | SNDRV_CTL_ELEM_ACCESS_INACTIVE, |
| 811 | .info = spdif_info, |
| 812 | .get = spdif_pcm_get, |
| 813 | .put = spdif_pcm_put, |
| 814 | }, |
Clemens Ladisch | 1d98c7d | 2008-04-09 09:16:33 +0200 | [diff] [blame] | 815 | }; |
| 816 | |
| 817 | static const struct snd_kcontrol_new spdif_input_controls[] = { |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 818 | { |
| 819 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 820 | .device = 1, |
| 821 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK), |
| 822 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 823 | .info = spdif_info, |
| 824 | .get = spdif_input_mask_get, |
| 825 | }, |
| 826 | { |
| 827 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 828 | .device = 1, |
| 829 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), |
| 830 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 831 | .info = spdif_info, |
| 832 | .get = spdif_input_default_get, |
| 833 | }, |
Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 834 | { |
| 835 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 836 | .name = SNDRV_CTL_NAME_IEC958("Loopback ", NONE, SWITCH), |
| 837 | .info = snd_ctl_boolean_mono_info, |
| 838 | .get = spdif_loopback_get, |
| 839 | .put = spdif_loopback_put, |
| 840 | }, |
Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 841 | }; |
| 842 | |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 843 | static const struct { |
| 844 | unsigned int pcm_dev; |
| 845 | struct snd_kcontrol_new controls[2]; |
| 846 | } monitor_controls[] = { |
Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 847 | { |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 848 | .pcm_dev = CAPTURE_0_FROM_I2S_1, |
| 849 | .controls = { |
| 850 | { |
| 851 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 852 | .name = "Analog Input Monitor Playback Switch", |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 853 | .info = snd_ctl_boolean_mono_info, |
| 854 | .get = monitor_get, |
| 855 | .put = monitor_put, |
| 856 | .private_value = OXYGEN_ADC_MONITOR_A, |
| 857 | }, |
| 858 | { |
| 859 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 860 | .name = "Analog Input Monitor Playback Volume", |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 861 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 862 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
| 863 | .info = monitor_volume_info, |
| 864 | .get = monitor_get, |
| 865 | .put = monitor_put, |
| 866 | .private_value = OXYGEN_ADC_MONITOR_A_HALF_VOL |
| 867 | | (1 << 8), |
| 868 | .tlv = { .p = monitor_db_scale, }, |
| 869 | }, |
| 870 | }, |
Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 871 | }, |
| 872 | { |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 873 | .pcm_dev = CAPTURE_0_FROM_I2S_2, |
| 874 | .controls = { |
| 875 | { |
| 876 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 877 | .name = "Analog Input Monitor Playback Switch", |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 878 | .info = snd_ctl_boolean_mono_info, |
| 879 | .get = monitor_get, |
| 880 | .put = monitor_put, |
| 881 | .private_value = OXYGEN_ADC_MONITOR_B, |
| 882 | }, |
| 883 | { |
| 884 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 885 | .name = "Analog Input Monitor Playback Volume", |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 886 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 887 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
| 888 | .info = monitor_volume_info, |
| 889 | .get = monitor_get, |
| 890 | .put = monitor_put, |
| 891 | .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL |
| 892 | | (1 << 8), |
| 893 | .tlv = { .p = monitor_db_scale, }, |
| 894 | }, |
| 895 | }, |
Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 896 | }, |
| 897 | { |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 898 | .pcm_dev = CAPTURE_2_FROM_I2S_2, |
| 899 | .controls = { |
| 900 | { |
| 901 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 902 | .name = "Analog Input Monitor Playback Switch", |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 903 | .index = 1, |
| 904 | .info = snd_ctl_boolean_mono_info, |
| 905 | .get = monitor_get, |
| 906 | .put = monitor_put, |
| 907 | .private_value = OXYGEN_ADC_MONITOR_B, |
| 908 | }, |
| 909 | { |
| 910 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 911 | .name = "Analog Input Monitor Playback Volume", |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 912 | .index = 1, |
| 913 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 914 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
| 915 | .info = monitor_volume_info, |
| 916 | .get = monitor_get, |
| 917 | .put = monitor_put, |
| 918 | .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL |
| 919 | | (1 << 8), |
| 920 | .tlv = { .p = monitor_db_scale, }, |
| 921 | }, |
| 922 | }, |
Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 923 | }, |
| 924 | { |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 925 | .pcm_dev = CAPTURE_1_FROM_SPDIF, |
| 926 | .controls = { |
| 927 | { |
| 928 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 929 | .name = "Digital Input Monitor Playback Switch", |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 930 | .info = snd_ctl_boolean_mono_info, |
| 931 | .get = monitor_get, |
| 932 | .put = monitor_put, |
| 933 | .private_value = OXYGEN_ADC_MONITOR_C, |
| 934 | }, |
| 935 | { |
| 936 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 937 | .name = "Digital Input Monitor Playback Volume", |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 938 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 939 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
| 940 | .info = monitor_volume_info, |
| 941 | .get = monitor_get, |
| 942 | .put = monitor_put, |
| 943 | .private_value = OXYGEN_ADC_MONITOR_C_HALF_VOL |
| 944 | | (1 << 8), |
| 945 | .tlv = { .p = monitor_db_scale, }, |
| 946 | }, |
| 947 | }, |
Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 948 | }, |
| 949 | }; |
| 950 | |
Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 951 | static const struct snd_kcontrol_new ac97_controls[] = { |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 952 | AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC, 0), |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 953 | AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1), |
| 954 | AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0), |
Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 955 | { |
| 956 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 957 | .name = "Mic Source Capture Enum", |
| 958 | .info = mic_fmic_source_info, |
| 959 | .get = mic_fmic_source_get, |
| 960 | .put = mic_fmic_source_put, |
| 961 | }, |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 962 | AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1), |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 963 | AC97_VOLUME("CD Capture Volume", 0, AC97_CD, 1), |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 964 | AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1), |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 965 | AC97_VOLUME("Aux Capture Volume", 0, AC97_AUX, 1), |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 966 | AC97_SWITCH("Aux Capture Switch", 0, AC97_AUX, 15, 1), |
| 967 | }; |
| 968 | |
| 969 | static const struct snd_kcontrol_new ac97_fp_controls[] = { |
Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 970 | AC97_VOLUME("Front Panel Playback Volume", 1, AC97_HEADPHONE, 1), |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 971 | AC97_SWITCH("Front Panel Playback Switch", 1, AC97_HEADPHONE, 15, 1), |
| 972 | { |
| 973 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 974 | .name = "Front Panel Capture Volume", |
| 975 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 976 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
| 977 | .info = ac97_fp_rec_volume_info, |
| 978 | .get = ac97_fp_rec_volume_get, |
| 979 | .put = ac97_fp_rec_volume_put, |
| 980 | .tlv = { .p = ac97_rec_db_scale, }, |
| 981 | }, |
| 982 | AC97_SWITCH("Front Panel Capture Switch", 1, AC97_REC_GAIN, 15, 1), |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 983 | }; |
| 984 | |
| 985 | static void oxygen_any_ctl_free(struct snd_kcontrol *ctl) |
| 986 | { |
| 987 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 988 | unsigned int i; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 989 | |
| 990 | /* I'm too lazy to write a function for each control :-) */ |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 991 | for (i = 0; i < ARRAY_SIZE(chip->controls); ++i) |
| 992 | chip->controls[i] = NULL; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 993 | } |
| 994 | |
Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 995 | static int add_controls(struct oxygen *chip, |
| 996 | const struct snd_kcontrol_new controls[], |
| 997 | unsigned int count) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 998 | { |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 999 | static const char *const known_ctl_names[CONTROL_COUNT] = { |
| 1000 | [CONTROL_SPDIF_PCM] = |
| 1001 | SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), |
| 1002 | [CONTROL_SPDIF_INPUT_BITS] = |
| 1003 | SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), |
Clemens Ladisch | 893e44b | 2008-01-14 08:57:05 +0100 | [diff] [blame] | 1004 | [CONTROL_MIC_CAPTURE_SWITCH] = "Mic Capture Switch", |
| 1005 | [CONTROL_LINE_CAPTURE_SWITCH] = "Line Capture Switch", |
| 1006 | [CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch", |
| 1007 | [CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch", |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 1008 | }; |
| 1009 | unsigned int i, j; |
Clemens Ladisch | ccc80fb | 2008-01-16 08:32:08 +0100 | [diff] [blame] | 1010 | struct snd_kcontrol_new template; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1011 | struct snd_kcontrol *ctl; |
| 1012 | int err; |
| 1013 | |
Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1014 | for (i = 0; i < count; ++i) { |
Clemens Ladisch | ccc80fb | 2008-01-16 08:32:08 +0100 | [diff] [blame] | 1015 | template = controls[i]; |
Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 1016 | if (chip->model.control_filter) { |
| 1017 | err = chip->model.control_filter(&template); |
Clemens Ladisch | 9f9115d | 2008-06-16 14:13:52 +0200 | [diff] [blame] | 1018 | if (err < 0) |
| 1019 | return err; |
| 1020 | if (err == 1) |
| 1021 | continue; |
| 1022 | } |
Clemens Ladisch | 75919d7 | 2009-09-28 11:15:49 +0200 | [diff] [blame] | 1023 | if (!strcmp(template.name, "Stereo Upmixing") && |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame] | 1024 | chip->model.dac_channels_pcm == 2) |
Clemens Ladisch | 75919d7 | 2009-09-28 11:15:49 +0200 | [diff] [blame] | 1025 | continue; |
Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 1026 | if (!strcmp(template.name, "Mic Source Capture Enum") && |
| 1027 | !(chip->model.device_config & AC97_FMIC_SWITCH)) |
| 1028 | continue; |
Clemens Ladisch | b6ca8ab | 2010-10-04 13:21:52 +0200 | [diff] [blame] | 1029 | if (!strncmp(template.name, "CD Capture ", 11) && |
| 1030 | !(chip->model.device_config & AC97_CD_INPUT)) |
| 1031 | continue; |
Clemens Ladisch | 4972a17 | 2008-04-16 09:15:45 +0200 | [diff] [blame] | 1032 | if (!strcmp(template.name, "Master Playback Volume") && |
Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 1033 | chip->model.dac_tlv) { |
| 1034 | template.tlv.p = chip->model.dac_tlv; |
Clemens Ladisch | 4972a17 | 2008-04-16 09:15:45 +0200 | [diff] [blame] | 1035 | template.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; |
| 1036 | } |
Clemens Ladisch | e9d88a8 | 2008-01-21 08:52:11 +0100 | [diff] [blame] | 1037 | ctl = snd_ctl_new1(&template, chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1038 | if (!ctl) |
| 1039 | return -ENOMEM; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1040 | err = snd_ctl_add(chip->card, ctl); |
| 1041 | if (err < 0) |
| 1042 | return err; |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 1043 | for (j = 0; j < CONTROL_COUNT; ++j) |
| 1044 | if (!strcmp(ctl->id.name, known_ctl_names[j])) { |
| 1045 | chip->controls[j] = ctl; |
| 1046 | ctl->private_free = oxygen_any_ctl_free; |
| 1047 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1048 | } |
Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1049 | return 0; |
| 1050 | } |
| 1051 | |
| 1052 | int oxygen_mixer_init(struct oxygen *chip) |
| 1053 | { |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 1054 | unsigned int i; |
Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1055 | int err; |
| 1056 | |
| 1057 | err = add_controls(chip, controls, ARRAY_SIZE(controls)); |
| 1058 | if (err < 0) |
| 1059 | return err; |
Clemens Ladisch | d76596b | 2008-09-22 09:02:08 +0200 | [diff] [blame] | 1060 | if (chip->model.device_config & CAPTURE_1_FROM_SPDIF) { |
Clemens Ladisch | 1d98c7d | 2008-04-09 09:16:33 +0200 | [diff] [blame] | 1061 | err = add_controls(chip, spdif_input_controls, |
| 1062 | ARRAY_SIZE(spdif_input_controls)); |
| 1063 | if (err < 0) |
| 1064 | return err; |
| 1065 | } |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 1066 | for (i = 0; i < ARRAY_SIZE(monitor_controls); ++i) { |
Clemens Ladisch | d76596b | 2008-09-22 09:02:08 +0200 | [diff] [blame] | 1067 | if (!(chip->model.device_config & monitor_controls[i].pcm_dev)) |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 1068 | continue; |
| 1069 | err = add_controls(chip, monitor_controls[i].controls, |
| 1070 | ARRAY_SIZE(monitor_controls[i].controls)); |
Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 1071 | if (err < 0) |
| 1072 | return err; |
| 1073 | } |
Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1074 | if (chip->has_ac97_0) { |
| 1075 | err = add_controls(chip, ac97_controls, |
| 1076 | ARRAY_SIZE(ac97_controls)); |
| 1077 | if (err < 0) |
| 1078 | return err; |
| 1079 | } |
Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 1080 | if (chip->has_ac97_1) { |
| 1081 | err = add_controls(chip, ac97_fp_controls, |
| 1082 | ARRAY_SIZE(ac97_fp_controls)); |
| 1083 | if (err < 0) |
| 1084 | return err; |
| 1085 | } |
Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 1086 | return chip->model.mixer_init ? chip->model.mixer_init(chip) : 0; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1087 | } |