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