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