| 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 | 860cffd | 2011-01-10 16:34:15 +0100 | [diff] [blame] | 437 | static int spdif_bit_switch_get(struct snd_kcontrol *ctl, | 
|  | 438 | struct snd_ctl_elem_value *value) | 
| Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 439 | { | 
|  | 440 | struct oxygen *chip = ctl->private_data; | 
| Clemens Ladisch | 860cffd | 2011-01-10 16:34:15 +0100 | [diff] [blame] | 441 | u32 bit = ctl->private_value; | 
| Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 442 |  | 
|  | 443 | value->value.integer.value[0] = | 
| Clemens Ladisch | 860cffd | 2011-01-10 16:34:15 +0100 | [diff] [blame] | 444 | !!(oxygen_read32(chip, OXYGEN_SPDIF_CONTROL) & bit); | 
| Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 445 | return 0; | 
|  | 446 | } | 
|  | 447 |  | 
| Clemens Ladisch | 860cffd | 2011-01-10 16:34:15 +0100 | [diff] [blame] | 448 | static int spdif_bit_switch_put(struct snd_kcontrol *ctl, | 
|  | 449 | struct snd_ctl_elem_value *value) | 
| Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 450 | { | 
|  | 451 | struct oxygen *chip = ctl->private_data; | 
| Clemens Ladisch | 860cffd | 2011-01-10 16:34:15 +0100 | [diff] [blame] | 452 | u32 bit = ctl->private_value; | 
| Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 453 | u32 oldreg, newreg; | 
|  | 454 | int changed; | 
|  | 455 |  | 
|  | 456 | spin_lock_irq(&chip->reg_lock); | 
|  | 457 | oldreg = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL); | 
|  | 458 | if (value->value.integer.value[0]) | 
| Clemens Ladisch | 860cffd | 2011-01-10 16:34:15 +0100 | [diff] [blame] | 459 | newreg = oldreg | bit; | 
| Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 460 | else | 
| 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 | changed = newreg != oldreg; | 
|  | 463 | if (changed) | 
|  | 464 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, newreg); | 
|  | 465 | spin_unlock_irq(&chip->reg_lock); | 
|  | 466 | return changed; | 
|  | 467 | } | 
|  | 468 |  | 
| Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 469 | static int monitor_volume_info(struct snd_kcontrol *ctl, | 
|  | 470 | struct snd_ctl_elem_info *info) | 
|  | 471 | { | 
|  | 472 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 
|  | 473 | info->count = 1; | 
|  | 474 | info->value.integer.min = 0; | 
|  | 475 | info->value.integer.max = 1; | 
|  | 476 | return 0; | 
|  | 477 | } | 
|  | 478 |  | 
|  | 479 | static int monitor_get(struct snd_kcontrol *ctl, | 
|  | 480 | struct snd_ctl_elem_value *value) | 
|  | 481 | { | 
|  | 482 | struct oxygen *chip = ctl->private_data; | 
|  | 483 | u8 bit = ctl->private_value; | 
|  | 484 | int invert = ctl->private_value & (1 << 8); | 
|  | 485 |  | 
|  | 486 | value->value.integer.value[0] = | 
|  | 487 | !!invert ^ !!(oxygen_read8(chip, OXYGEN_ADC_MONITOR) & bit); | 
|  | 488 | return 0; | 
|  | 489 | } | 
|  | 490 |  | 
|  | 491 | static int monitor_put(struct snd_kcontrol *ctl, | 
|  | 492 | struct snd_ctl_elem_value *value) | 
|  | 493 | { | 
|  | 494 | struct oxygen *chip = ctl->private_data; | 
|  | 495 | u8 bit = ctl->private_value; | 
|  | 496 | int invert = ctl->private_value & (1 << 8); | 
|  | 497 | u8 oldreg, newreg; | 
|  | 498 | int changed; | 
|  | 499 |  | 
|  | 500 | spin_lock_irq(&chip->reg_lock); | 
|  | 501 | oldreg = oxygen_read8(chip, OXYGEN_ADC_MONITOR); | 
|  | 502 | if ((!!value->value.integer.value[0] ^ !!invert) != 0) | 
|  | 503 | newreg = oldreg | bit; | 
|  | 504 | else | 
|  | 505 | newreg = oldreg & ~bit; | 
|  | 506 | changed = newreg != oldreg; | 
|  | 507 | if (changed) | 
|  | 508 | oxygen_write8(chip, OXYGEN_ADC_MONITOR, newreg); | 
|  | 509 | spin_unlock_irq(&chip->reg_lock); | 
|  | 510 | return changed; | 
|  | 511 | } | 
|  | 512 |  | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 513 | static int ac97_switch_get(struct snd_kcontrol *ctl, | 
|  | 514 | struct snd_ctl_elem_value *value) | 
|  | 515 | { | 
|  | 516 | struct oxygen *chip = ctl->private_data; | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 517 | unsigned int codec = (ctl->private_value >> 24) & 1; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 518 | unsigned int index = ctl->private_value & 0xff; | 
|  | 519 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; | 
|  | 520 | int invert = ctl->private_value & (1 << 16); | 
|  | 521 | u16 reg; | 
|  | 522 |  | 
|  | 523 | mutex_lock(&chip->mutex); | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 524 | reg = oxygen_read_ac97(chip, codec, index); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 525 | mutex_unlock(&chip->mutex); | 
|  | 526 | if (!(reg & (1 << bitnr)) ^ !invert) | 
|  | 527 | value->value.integer.value[0] = 1; | 
|  | 528 | else | 
|  | 529 | value->value.integer.value[0] = 0; | 
|  | 530 | return 0; | 
|  | 531 | } | 
|  | 532 |  | 
| Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 533 | static void mute_ac97_ctl(struct oxygen *chip, unsigned int control) | 
|  | 534 | { | 
| Clemens Ladisch | 3d839e5 | 2008-08-26 11:06:26 +0200 | [diff] [blame] | 535 | unsigned int priv_idx; | 
| Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 536 | u16 value; | 
|  | 537 |  | 
| Clemens Ladisch | 3d839e5 | 2008-08-26 11:06:26 +0200 | [diff] [blame] | 538 | if (!chip->controls[control]) | 
|  | 539 | return; | 
|  | 540 | priv_idx = chip->controls[control]->private_value & 0xff; | 
| Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 541 | value = oxygen_read_ac97(chip, 0, priv_idx); | 
|  | 542 | if (!(value & 0x8000)) { | 
|  | 543 | oxygen_write_ac97(chip, 0, priv_idx, value | 0x8000); | 
| Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 544 | if (chip->model.ac97_switch) | 
|  | 545 | chip->model.ac97_switch(chip, priv_idx, 0x8000); | 
| Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 546 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, | 
|  | 547 | &chip->controls[control]->id); | 
|  | 548 | } | 
|  | 549 | } | 
|  | 550 |  | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 551 | static int ac97_switch_put(struct snd_kcontrol *ctl, | 
|  | 552 | struct snd_ctl_elem_value *value) | 
|  | 553 | { | 
|  | 554 | struct oxygen *chip = ctl->private_data; | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 555 | unsigned int codec = (ctl->private_value >> 24) & 1; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 556 | unsigned int index = ctl->private_value & 0xff; | 
|  | 557 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; | 
|  | 558 | int invert = ctl->private_value & (1 << 16); | 
|  | 559 | u16 oldreg, newreg; | 
|  | 560 | int change; | 
|  | 561 |  | 
|  | 562 | mutex_lock(&chip->mutex); | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 563 | oldreg = oxygen_read_ac97(chip, codec, index); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 564 | newreg = oldreg; | 
|  | 565 | if (!value->value.integer.value[0] ^ !invert) | 
|  | 566 | newreg |= 1 << bitnr; | 
|  | 567 | else | 
|  | 568 | newreg &= ~(1 << bitnr); | 
|  | 569 | change = newreg != oldreg; | 
|  | 570 | if (change) { | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 571 | oxygen_write_ac97(chip, codec, index, newreg); | 
| Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 572 | if (codec == 0 && chip->model.ac97_switch) | 
|  | 573 | chip->model.ac97_switch(chip, index, newreg & 0x8000); | 
| Clemens Ladisch | e97f799 | 2008-04-01 10:02:18 +0200 | [diff] [blame] | 574 | if (index == AC97_LINE) { | 
|  | 575 | oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS, | 
|  | 576 | newreg & 0x8000 ? | 
|  | 577 | CM9780_GPO0 : 0, CM9780_GPO0); | 
|  | 578 | if (!(newreg & 0x8000)) { | 
|  | 579 | mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH); | 
|  | 580 | mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH); | 
|  | 581 | mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH); | 
|  | 582 | } | 
|  | 583 | } else if ((index == AC97_MIC || index == AC97_CD || | 
|  | 584 | index == AC97_VIDEO || index == AC97_AUX) && | 
|  | 585 | bitnr == 15 && !(newreg & 0x8000)) { | 
|  | 586 | mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH); | 
|  | 587 | oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS, | 
|  | 588 | CM9780_GPO0, CM9780_GPO0); | 
|  | 589 | } | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 590 | } | 
|  | 591 | mutex_unlock(&chip->mutex); | 
|  | 592 | return change; | 
|  | 593 | } | 
|  | 594 |  | 
|  | 595 | static int ac97_volume_info(struct snd_kcontrol *ctl, | 
|  | 596 | struct snd_ctl_elem_info *info) | 
|  | 597 | { | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 598 | int stereo = (ctl->private_value >> 16) & 1; | 
|  | 599 |  | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 600 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 601 | info->count = stereo ? 2 : 1; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 602 | info->value.integer.min = 0; | 
|  | 603 | info->value.integer.max = 0x1f; | 
|  | 604 | return 0; | 
|  | 605 | } | 
|  | 606 |  | 
|  | 607 | static int ac97_volume_get(struct snd_kcontrol *ctl, | 
|  | 608 | struct snd_ctl_elem_value *value) | 
|  | 609 | { | 
|  | 610 | struct oxygen *chip = ctl->private_data; | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 611 | unsigned int codec = (ctl->private_value >> 24) & 1; | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 612 | int stereo = (ctl->private_value >> 16) & 1; | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 613 | unsigned int index = ctl->private_value & 0xff; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 614 | u16 reg; | 
|  | 615 |  | 
|  | 616 | mutex_lock(&chip->mutex); | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 617 | reg = oxygen_read_ac97(chip, codec, index); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 618 | mutex_unlock(&chip->mutex); | 
|  | 619 | value->value.integer.value[0] = 31 - (reg & 0x1f); | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 620 | if (stereo) | 
|  | 621 | value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 622 | return 0; | 
|  | 623 | } | 
|  | 624 |  | 
|  | 625 | static int ac97_volume_put(struct snd_kcontrol *ctl, | 
|  | 626 | struct snd_ctl_elem_value *value) | 
|  | 627 | { | 
|  | 628 | struct oxygen *chip = ctl->private_data; | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 629 | unsigned int codec = (ctl->private_value >> 24) & 1; | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 630 | int stereo = (ctl->private_value >> 16) & 1; | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 631 | unsigned int index = ctl->private_value & 0xff; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 632 | u16 oldreg, newreg; | 
|  | 633 | int change; | 
|  | 634 |  | 
|  | 635 | mutex_lock(&chip->mutex); | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 636 | oldreg = oxygen_read_ac97(chip, codec, index); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 637 | newreg = oldreg; | 
|  | 638 | newreg = (newreg & ~0x1f) | | 
|  | 639 | (31 - (value->value.integer.value[0] & 0x1f)); | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 640 | if (stereo) | 
|  | 641 | newreg = (newreg & ~0x1f00) | | 
|  | 642 | ((31 - (value->value.integer.value[1] & 0x1f)) << 8); | 
|  | 643 | else | 
|  | 644 | newreg = (newreg & ~0x1f00) | ((newreg & 0x1f) << 8); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 645 | change = newreg != oldreg; | 
|  | 646 | if (change) | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 647 | oxygen_write_ac97(chip, codec, index, newreg); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 648 | mutex_unlock(&chip->mutex); | 
|  | 649 | return change; | 
|  | 650 | } | 
|  | 651 |  | 
| Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 652 | static int mic_fmic_source_info(struct snd_kcontrol *ctl, | 
|  | 653 | struct snd_ctl_elem_info *info) | 
|  | 654 | { | 
|  | 655 | static const char *const names[] = { "Mic Jack", "Front Panel" }; | 
|  | 656 |  | 
| Clemens Ladisch | 9600732 | 2011-01-10 16:25:44 +0100 | [diff] [blame] | 657 | return snd_ctl_enum_info(info, 1, 2, names); | 
| Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 658 | } | 
|  | 659 |  | 
|  | 660 | static int mic_fmic_source_get(struct snd_kcontrol *ctl, | 
|  | 661 | struct snd_ctl_elem_value *value) | 
|  | 662 | { | 
|  | 663 | struct oxygen *chip = ctl->private_data; | 
|  | 664 |  | 
|  | 665 | mutex_lock(&chip->mutex); | 
|  | 666 | value->value.enumerated.item[0] = | 
|  | 667 | !!(oxygen_read_ac97(chip, 0, CM9780_JACK) & CM9780_FMIC2MIC); | 
|  | 668 | mutex_unlock(&chip->mutex); | 
|  | 669 | return 0; | 
|  | 670 | } | 
|  | 671 |  | 
|  | 672 | static int mic_fmic_source_put(struct snd_kcontrol *ctl, | 
|  | 673 | struct snd_ctl_elem_value *value) | 
|  | 674 | { | 
|  | 675 | struct oxygen *chip = ctl->private_data; | 
|  | 676 | u16 oldreg, newreg; | 
|  | 677 | int change; | 
|  | 678 |  | 
|  | 679 | mutex_lock(&chip->mutex); | 
|  | 680 | oldreg = oxygen_read_ac97(chip, 0, CM9780_JACK); | 
|  | 681 | if (value->value.enumerated.item[0]) | 
|  | 682 | newreg = oldreg | CM9780_FMIC2MIC; | 
|  | 683 | else | 
|  | 684 | newreg = oldreg & ~CM9780_FMIC2MIC; | 
|  | 685 | change = newreg != oldreg; | 
|  | 686 | if (change) | 
|  | 687 | oxygen_write_ac97(chip, 0, CM9780_JACK, newreg); | 
|  | 688 | mutex_unlock(&chip->mutex); | 
|  | 689 | return change; | 
|  | 690 | } | 
|  | 691 |  | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 692 | static int ac97_fp_rec_volume_info(struct snd_kcontrol *ctl, | 
|  | 693 | struct snd_ctl_elem_info *info) | 
|  | 694 | { | 
|  | 695 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 
|  | 696 | info->count = 2; | 
|  | 697 | info->value.integer.min = 0; | 
|  | 698 | info->value.integer.max = 7; | 
|  | 699 | return 0; | 
|  | 700 | } | 
|  | 701 |  | 
|  | 702 | static int ac97_fp_rec_volume_get(struct snd_kcontrol *ctl, | 
|  | 703 | struct snd_ctl_elem_value *value) | 
|  | 704 | { | 
|  | 705 | struct oxygen *chip = ctl->private_data; | 
|  | 706 | u16 reg; | 
|  | 707 |  | 
|  | 708 | mutex_lock(&chip->mutex); | 
|  | 709 | reg = oxygen_read_ac97(chip, 1, AC97_REC_GAIN); | 
|  | 710 | mutex_unlock(&chip->mutex); | 
|  | 711 | value->value.integer.value[0] = reg & 7; | 
|  | 712 | value->value.integer.value[1] = (reg >> 8) & 7; | 
|  | 713 | return 0; | 
|  | 714 | } | 
|  | 715 |  | 
|  | 716 | static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl, | 
|  | 717 | struct snd_ctl_elem_value *value) | 
|  | 718 | { | 
|  | 719 | struct oxygen *chip = ctl->private_data; | 
|  | 720 | u16 oldreg, newreg; | 
|  | 721 | int change; | 
|  | 722 |  | 
|  | 723 | mutex_lock(&chip->mutex); | 
|  | 724 | oldreg = oxygen_read_ac97(chip, 1, AC97_REC_GAIN); | 
|  | 725 | newreg = oldreg & ~0x0707; | 
|  | 726 | newreg = newreg | (value->value.integer.value[0] & 7); | 
|  | 727 | newreg = newreg | ((value->value.integer.value[0] & 7) << 8); | 
|  | 728 | change = newreg != oldreg; | 
|  | 729 | if (change) | 
|  | 730 | oxygen_write_ac97(chip, 1, AC97_REC_GAIN, newreg); | 
|  | 731 | mutex_unlock(&chip->mutex); | 
|  | 732 | return change; | 
|  | 733 | } | 
|  | 734 |  | 
|  | 735 | #define AC97_SWITCH(xname, codec, index, bitnr, invert) { \ | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 736 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | 
|  | 737 | .name = xname, \ | 
|  | 738 | .info = snd_ctl_boolean_mono_info, \ | 
|  | 739 | .get = ac97_switch_get, \ | 
|  | 740 | .put = ac97_switch_put, \ | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 741 | .private_value = ((codec) << 24) | ((invert) << 16) | \ | 
|  | 742 | ((bitnr) << 8) | (index), \ | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 743 | } | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 744 | #define AC97_VOLUME(xname, codec, index, stereo) { \ | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 745 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | 
|  | 746 | .name = xname, \ | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 747 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ | 
|  | 748 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 749 | .info = ac97_volume_info, \ | 
|  | 750 | .get = ac97_volume_get, \ | 
|  | 751 | .put = ac97_volume_put, \ | 
|  | 752 | .tlv = { .p = ac97_db_scale, }, \ | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 753 | .private_value = ((codec) << 24) | ((stereo) << 16) | (index), \ | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 754 | } | 
|  | 755 |  | 
| Clemens Ladisch | 9a0b379 | 2010-10-04 13:25:13 +0200 | [diff] [blame] | 756 | static DECLARE_TLV_DB_SCALE(monitor_db_scale, -600, 600, 0); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 757 | static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0); | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 758 | static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 759 |  | 
|  | 760 | static const struct snd_kcontrol_new controls[] = { | 
|  | 761 | { | 
|  | 762 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | fb920b7 | 2008-01-15 08:39:06 +0100 | [diff] [blame] | 763 | .name = "Master Playback Volume", | 
| Clemens Ladisch | ccc80fb | 2008-01-16 08:32:08 +0100 | [diff] [blame] | 764 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 765 | .info = dac_volume_info, | 
|  | 766 | .get = dac_volume_get, | 
|  | 767 | .put = dac_volume_put, | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 768 | }, | 
|  | 769 | { | 
|  | 770 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | fb920b7 | 2008-01-15 08:39:06 +0100 | [diff] [blame] | 771 | .name = "Master Playback Switch", | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 772 | .info = snd_ctl_boolean_mono_info, | 
|  | 773 | .get = dac_mute_get, | 
|  | 774 | .put = dac_mute_put, | 
|  | 775 | }, | 
|  | 776 | { | 
|  | 777 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
|  | 778 | .name = "Stereo Upmixing", | 
|  | 779 | .info = upmix_info, | 
|  | 780 | .get = upmix_get, | 
|  | 781 | .put = upmix_put, | 
|  | 782 | }, | 
|  | 783 | { | 
|  | 784 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
|  | 785 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), | 
|  | 786 | .info = snd_ctl_boolean_mono_info, | 
|  | 787 | .get = spdif_switch_get, | 
|  | 788 | .put = spdif_switch_put, | 
|  | 789 | }, | 
|  | 790 | { | 
|  | 791 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | 
|  | 792 | .device = 1, | 
|  | 793 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), | 
|  | 794 | .info = spdif_info, | 
|  | 795 | .get = spdif_default_get, | 
|  | 796 | .put = spdif_default_put, | 
|  | 797 | }, | 
|  | 798 | { | 
|  | 799 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | 
|  | 800 | .device = 1, | 
|  | 801 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), | 
|  | 802 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | 
|  | 803 | .info = spdif_info, | 
|  | 804 | .get = spdif_mask_get, | 
|  | 805 | }, | 
|  | 806 | { | 
|  | 807 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | 
|  | 808 | .device = 1, | 
|  | 809 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), | 
|  | 810 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 
|  | 811 | SNDRV_CTL_ELEM_ACCESS_INACTIVE, | 
|  | 812 | .info = spdif_info, | 
|  | 813 | .get = spdif_pcm_get, | 
|  | 814 | .put = spdif_pcm_put, | 
|  | 815 | }, | 
| Clemens Ladisch | 1d98c7d | 2008-04-09 09:16:33 +0200 | [diff] [blame] | 816 | }; | 
|  | 817 |  | 
|  | 818 | static const struct snd_kcontrol_new spdif_input_controls[] = { | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 819 | { | 
|  | 820 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | 
|  | 821 | .device = 1, | 
|  | 822 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK), | 
|  | 823 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | 
|  | 824 | .info = spdif_info, | 
|  | 825 | .get = spdif_input_mask_get, | 
|  | 826 | }, | 
|  | 827 | { | 
|  | 828 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | 
|  | 829 | .device = 1, | 
|  | 830 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), | 
|  | 831 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | 
|  | 832 | .info = spdif_info, | 
|  | 833 | .get = spdif_input_default_get, | 
|  | 834 | }, | 
| Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 835 | { | 
|  | 836 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
|  | 837 | .name = SNDRV_CTL_NAME_IEC958("Loopback ", NONE, SWITCH), | 
|  | 838 | .info = snd_ctl_boolean_mono_info, | 
| Clemens Ladisch | 860cffd | 2011-01-10 16:34:15 +0100 | [diff] [blame] | 839 | .get = spdif_bit_switch_get, | 
|  | 840 | .put = spdif_bit_switch_put, | 
|  | 841 | .private_value = OXYGEN_SPDIF_LOOPBACK, | 
|  | 842 | }, | 
|  | 843 | { | 
|  | 844 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
|  | 845 | .name = SNDRV_CTL_NAME_IEC958("Validity Check ",CAPTURE,SWITCH), | 
|  | 846 | .info = snd_ctl_boolean_mono_info, | 
|  | 847 | .get = spdif_bit_switch_get, | 
|  | 848 | .put = spdif_bit_switch_put, | 
|  | 849 | .private_value = OXYGEN_SPDIF_SPDVALID, | 
| Clemens Ladisch | 02f21c9 | 2008-01-22 08:36:03 +0100 | [diff] [blame] | 850 | }, | 
| Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 851 | }; | 
|  | 852 |  | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 853 | static const struct { | 
|  | 854 | unsigned int pcm_dev; | 
|  | 855 | struct snd_kcontrol_new controls[2]; | 
|  | 856 | } monitor_controls[] = { | 
| Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 857 | { | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 858 | .pcm_dev = CAPTURE_0_FROM_I2S_1, | 
|  | 859 | .controls = { | 
|  | 860 | { | 
|  | 861 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 862 | .name = "Analog Input Monitor Playback Switch", | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 863 | .info = snd_ctl_boolean_mono_info, | 
|  | 864 | .get = monitor_get, | 
|  | 865 | .put = monitor_put, | 
|  | 866 | .private_value = OXYGEN_ADC_MONITOR_A, | 
|  | 867 | }, | 
|  | 868 | { | 
|  | 869 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 870 | .name = "Analog Input Monitor Playback Volume", | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 871 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 
|  | 872 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 
|  | 873 | .info = monitor_volume_info, | 
|  | 874 | .get = monitor_get, | 
|  | 875 | .put = monitor_put, | 
|  | 876 | .private_value = OXYGEN_ADC_MONITOR_A_HALF_VOL | 
|  | 877 | | (1 << 8), | 
|  | 878 | .tlv = { .p = monitor_db_scale, }, | 
|  | 879 | }, | 
|  | 880 | }, | 
| Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 881 | }, | 
|  | 882 | { | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 883 | .pcm_dev = CAPTURE_0_FROM_I2S_2, | 
|  | 884 | .controls = { | 
|  | 885 | { | 
|  | 886 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 887 | .name = "Analog Input Monitor Playback Switch", | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 888 | .info = snd_ctl_boolean_mono_info, | 
|  | 889 | .get = monitor_get, | 
|  | 890 | .put = monitor_put, | 
|  | 891 | .private_value = OXYGEN_ADC_MONITOR_B, | 
|  | 892 | }, | 
|  | 893 | { | 
|  | 894 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 895 | .name = "Analog Input Monitor Playback Volume", | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 896 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 
|  | 897 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 
|  | 898 | .info = monitor_volume_info, | 
|  | 899 | .get = monitor_get, | 
|  | 900 | .put = monitor_put, | 
|  | 901 | .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL | 
|  | 902 | | (1 << 8), | 
|  | 903 | .tlv = { .p = monitor_db_scale, }, | 
|  | 904 | }, | 
|  | 905 | }, | 
| Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 906 | }, | 
|  | 907 | { | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 908 | .pcm_dev = CAPTURE_2_FROM_I2S_2, | 
|  | 909 | .controls = { | 
|  | 910 | { | 
|  | 911 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 912 | .name = "Analog Input Monitor Playback Switch", | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 913 | .index = 1, | 
|  | 914 | .info = snd_ctl_boolean_mono_info, | 
|  | 915 | .get = monitor_get, | 
|  | 916 | .put = monitor_put, | 
|  | 917 | .private_value = OXYGEN_ADC_MONITOR_B, | 
|  | 918 | }, | 
|  | 919 | { | 
|  | 920 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 921 | .name = "Analog Input Monitor Playback Volume", | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 922 | .index = 1, | 
|  | 923 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 
|  | 924 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 
|  | 925 | .info = monitor_volume_info, | 
|  | 926 | .get = monitor_get, | 
|  | 927 | .put = monitor_put, | 
|  | 928 | .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL | 
|  | 929 | | (1 << 8), | 
|  | 930 | .tlv = { .p = monitor_db_scale, }, | 
|  | 931 | }, | 
|  | 932 | }, | 
| Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 933 | }, | 
|  | 934 | { | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 935 | .pcm_dev = CAPTURE_1_FROM_SPDIF, | 
|  | 936 | .controls = { | 
|  | 937 | { | 
|  | 938 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 939 | .name = "Digital Input Monitor Playback Switch", | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 940 | .info = snd_ctl_boolean_mono_info, | 
|  | 941 | .get = monitor_get, | 
|  | 942 | .put = monitor_put, | 
|  | 943 | .private_value = OXYGEN_ADC_MONITOR_C, | 
|  | 944 | }, | 
|  | 945 | { | 
|  | 946 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Clemens Ladisch | 62428f7 | 2009-09-28 11:22:18 +0200 | [diff] [blame] | 947 | .name = "Digital Input Monitor Playback Volume", | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 948 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 
|  | 949 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 
|  | 950 | .info = monitor_volume_info, | 
|  | 951 | .get = monitor_get, | 
|  | 952 | .put = monitor_put, | 
|  | 953 | .private_value = OXYGEN_ADC_MONITOR_C_HALF_VOL | 
|  | 954 | | (1 << 8), | 
|  | 955 | .tlv = { .p = monitor_db_scale, }, | 
|  | 956 | }, | 
|  | 957 | }, | 
| Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 958 | }, | 
|  | 959 | }; | 
|  | 960 |  | 
| Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 961 | static const struct snd_kcontrol_new ac97_controls[] = { | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 962 | AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC, 0), | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 963 | AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1), | 
|  | 964 | AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0), | 
| Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 965 | { | 
|  | 966 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
|  | 967 | .name = "Mic Source Capture Enum", | 
|  | 968 | .info = mic_fmic_source_info, | 
|  | 969 | .get = mic_fmic_source_get, | 
|  | 970 | .put = mic_fmic_source_put, | 
|  | 971 | }, | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 972 | AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1), | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 973 | AC97_VOLUME("CD Capture Volume", 0, AC97_CD, 1), | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 974 | AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1), | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 975 | AC97_VOLUME("Aux Capture Volume", 0, AC97_AUX, 1), | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 976 | AC97_SWITCH("Aux Capture Switch", 0, AC97_AUX, 15, 1), | 
|  | 977 | }; | 
|  | 978 |  | 
|  | 979 | static const struct snd_kcontrol_new ac97_fp_controls[] = { | 
| Clemens Ladisch | 14744d7 | 2009-06-25 14:28:49 +0200 | [diff] [blame] | 980 | AC97_VOLUME("Front Panel Playback Volume", 1, AC97_HEADPHONE, 1), | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 981 | AC97_SWITCH("Front Panel Playback Switch", 1, AC97_HEADPHONE, 15, 1), | 
|  | 982 | { | 
|  | 983 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
|  | 984 | .name = "Front Panel Capture Volume", | 
|  | 985 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 
|  | 986 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 
|  | 987 | .info = ac97_fp_rec_volume_info, | 
|  | 988 | .get = ac97_fp_rec_volume_get, | 
|  | 989 | .put = ac97_fp_rec_volume_put, | 
|  | 990 | .tlv = { .p = ac97_rec_db_scale, }, | 
|  | 991 | }, | 
|  | 992 | AC97_SWITCH("Front Panel Capture Switch", 1, AC97_REC_GAIN, 15, 1), | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 993 | }; | 
|  | 994 |  | 
|  | 995 | static void oxygen_any_ctl_free(struct snd_kcontrol *ctl) | 
|  | 996 | { | 
|  | 997 | struct oxygen *chip = ctl->private_data; | 
| Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 998 | unsigned int i; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 999 |  | 
|  | 1000 | /* I'm too lazy to write a function for each control :-) */ | 
| Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 1001 | for (i = 0; i < ARRAY_SIZE(chip->controls); ++i) | 
|  | 1002 | chip->controls[i] = NULL; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1003 | } | 
|  | 1004 |  | 
| Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1005 | static int add_controls(struct oxygen *chip, | 
|  | 1006 | const struct snd_kcontrol_new controls[], | 
|  | 1007 | unsigned int count) | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1008 | { | 
| Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 1009 | static const char *const known_ctl_names[CONTROL_COUNT] = { | 
|  | 1010 | [CONTROL_SPDIF_PCM] = | 
|  | 1011 | SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), | 
|  | 1012 | [CONTROL_SPDIF_INPUT_BITS] = | 
|  | 1013 | SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), | 
| Clemens Ladisch | 893e44b | 2008-01-14 08:57:05 +0100 | [diff] [blame] | 1014 | [CONTROL_MIC_CAPTURE_SWITCH] = "Mic Capture Switch", | 
|  | 1015 | [CONTROL_LINE_CAPTURE_SWITCH] = "Line Capture Switch", | 
|  | 1016 | [CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch", | 
|  | 1017 | [CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch", | 
| Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 1018 | }; | 
|  | 1019 | unsigned int i, j; | 
| Clemens Ladisch | ccc80fb | 2008-01-16 08:32:08 +0100 | [diff] [blame] | 1020 | struct snd_kcontrol_new template; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1021 | struct snd_kcontrol *ctl; | 
|  | 1022 | int err; | 
|  | 1023 |  | 
| Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1024 | for (i = 0; i < count; ++i) { | 
| Clemens Ladisch | ccc80fb | 2008-01-16 08:32:08 +0100 | [diff] [blame] | 1025 | template = controls[i]; | 
| Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 1026 | if (chip->model.control_filter) { | 
|  | 1027 | err = chip->model.control_filter(&template); | 
| Clemens Ladisch | 9f9115d | 2008-06-16 14:13:52 +0200 | [diff] [blame] | 1028 | if (err < 0) | 
|  | 1029 | return err; | 
|  | 1030 | if (err == 1) | 
|  | 1031 | continue; | 
|  | 1032 | } | 
| Clemens Ladisch | 75919d7 | 2009-09-28 11:15:49 +0200 | [diff] [blame] | 1033 | if (!strcmp(template.name, "Stereo Upmixing") && | 
| Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame] | 1034 | chip->model.dac_channels_pcm == 2) | 
| Clemens Ladisch | 75919d7 | 2009-09-28 11:15:49 +0200 | [diff] [blame] | 1035 | continue; | 
| Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 1036 | if (!strcmp(template.name, "Mic Source Capture Enum") && | 
|  | 1037 | !(chip->model.device_config & AC97_FMIC_SWITCH)) | 
|  | 1038 | continue; | 
| Clemens Ladisch | b6ca8ab | 2010-10-04 13:21:52 +0200 | [diff] [blame] | 1039 | if (!strncmp(template.name, "CD Capture ", 11) && | 
|  | 1040 | !(chip->model.device_config & AC97_CD_INPUT)) | 
|  | 1041 | continue; | 
| Clemens Ladisch | 4972a17 | 2008-04-16 09:15:45 +0200 | [diff] [blame] | 1042 | if (!strcmp(template.name, "Master Playback Volume") && | 
| Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 1043 | chip->model.dac_tlv) { | 
|  | 1044 | template.tlv.p = chip->model.dac_tlv; | 
| Clemens Ladisch | 4972a17 | 2008-04-16 09:15:45 +0200 | [diff] [blame] | 1045 | template.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; | 
|  | 1046 | } | 
| Clemens Ladisch | e9d88a8 | 2008-01-21 08:52:11 +0100 | [diff] [blame] | 1047 | ctl = snd_ctl_new1(&template, chip); | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1048 | if (!ctl) | 
|  | 1049 | return -ENOMEM; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1050 | err = snd_ctl_add(chip->card, ctl); | 
|  | 1051 | if (err < 0) | 
|  | 1052 | return err; | 
| Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 1053 | for (j = 0; j < CONTROL_COUNT; ++j) | 
|  | 1054 | if (!strcmp(ctl->id.name, known_ctl_names[j])) { | 
|  | 1055 | chip->controls[j] = ctl; | 
|  | 1056 | ctl->private_free = oxygen_any_ctl_free; | 
|  | 1057 | } | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1058 | } | 
| Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1059 | return 0; | 
|  | 1060 | } | 
|  | 1061 |  | 
|  | 1062 | int oxygen_mixer_init(struct oxygen *chip) | 
|  | 1063 | { | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 1064 | unsigned int i; | 
| Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1065 | int err; | 
|  | 1066 |  | 
|  | 1067 | err = add_controls(chip, controls, ARRAY_SIZE(controls)); | 
|  | 1068 | if (err < 0) | 
|  | 1069 | return err; | 
| Clemens Ladisch | d76596b | 2008-09-22 09:02:08 +0200 | [diff] [blame] | 1070 | if (chip->model.device_config & CAPTURE_1_FROM_SPDIF) { | 
| Clemens Ladisch | 1d98c7d | 2008-04-09 09:16:33 +0200 | [diff] [blame] | 1071 | err = add_controls(chip, spdif_input_controls, | 
|  | 1072 | ARRAY_SIZE(spdif_input_controls)); | 
|  | 1073 | if (err < 0) | 
|  | 1074 | return err; | 
|  | 1075 | } | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 1076 | for (i = 0; i < ARRAY_SIZE(monitor_controls); ++i) { | 
| Clemens Ladisch | d76596b | 2008-09-22 09:02:08 +0200 | [diff] [blame] | 1077 | if (!(chip->model.device_config & monitor_controls[i].pcm_dev)) | 
| Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 1078 | continue; | 
|  | 1079 | err = add_controls(chip, monitor_controls[i].controls, | 
|  | 1080 | ARRAY_SIZE(monitor_controls[i].controls)); | 
| Clemens Ladisch | fa5d810 | 2008-03-19 08:17:33 +0100 | [diff] [blame] | 1081 | if (err < 0) | 
|  | 1082 | return err; | 
|  | 1083 | } | 
| Clemens Ladisch | 31c7764 | 2008-01-16 08:28:17 +0100 | [diff] [blame] | 1084 | if (chip->has_ac97_0) { | 
|  | 1085 | err = add_controls(chip, ac97_controls, | 
|  | 1086 | ARRAY_SIZE(ac97_controls)); | 
|  | 1087 | if (err < 0) | 
|  | 1088 | return err; | 
|  | 1089 | } | 
| Clemens Ladisch | a360156 | 2008-01-28 08:35:20 +0100 | [diff] [blame] | 1090 | if (chip->has_ac97_1) { | 
|  | 1091 | err = add_controls(chip, ac97_fp_controls, | 
|  | 1092 | ARRAY_SIZE(ac97_fp_controls)); | 
|  | 1093 | if (err < 0) | 
|  | 1094 | return err; | 
|  | 1095 | } | 
| Clemens Ladisch | 9bd6a73 | 2008-09-22 08:55:19 +0200 | [diff] [blame] | 1096 | return chip->model.mixer_init ? chip->model.mixer_init(chip) : 0; | 
| Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1097 | } |