1041f26b6SRoman Volkov /* 2041f26b6SRoman Volkov * Mixer controls for the Xonar DG/DGX 3041f26b6SRoman Volkov * 4041f26b6SRoman Volkov * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 5041f26b6SRoman Volkov * Copyright (c) Roman Volkov <v1ron@mail.ru> 6041f26b6SRoman Volkov * 7041f26b6SRoman Volkov * This driver is free software; you can redistribute it and/or modify 8041f26b6SRoman Volkov * it under the terms of the GNU General Public License, version 2. 9041f26b6SRoman Volkov * 10041f26b6SRoman Volkov * This driver is distributed in the hope that it will be useful, 11041f26b6SRoman Volkov * but WITHOUT ANY WARRANTY; without even the implied warranty of 12041f26b6SRoman Volkov * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13041f26b6SRoman Volkov * GNU General Public License for more details. 14041f26b6SRoman Volkov * 15041f26b6SRoman Volkov * You should have received a copy of the GNU General Public License 16041f26b6SRoman Volkov * along with this driver; if not, see <http://www.gnu.org/licenses/>. 17041f26b6SRoman Volkov */ 18041f26b6SRoman Volkov 19041f26b6SRoman Volkov #include <linux/pci.h> 20041f26b6SRoman Volkov #include <linux/delay.h> 21041f26b6SRoman Volkov #include <sound/control.h> 22041f26b6SRoman Volkov #include <sound/core.h> 23041f26b6SRoman Volkov #include <sound/info.h> 24041f26b6SRoman Volkov #include <sound/pcm.h> 25041f26b6SRoman Volkov #include <sound/tlv.h> 26041f26b6SRoman Volkov #include "oxygen.h" 27041f26b6SRoman Volkov #include "xonar_dg.h" 28041f26b6SRoman Volkov #include "cs4245.h" 29041f26b6SRoman Volkov 302809cb84SRoman Volkov /* analog output select */ 312809cb84SRoman Volkov 322809cb84SRoman Volkov static int output_select_apply(struct oxygen *chip) 332809cb84SRoman Volkov { 342809cb84SRoman Volkov struct dg *data = chip->model_data; 352809cb84SRoman Volkov 362809cb84SRoman Volkov data->cs4245_shadow[CS4245_SIGNAL_SEL] &= ~CS4245_A_OUT_SEL_MASK; 372809cb84SRoman Volkov if (data->output_sel == PLAYBACK_DST_HP) { 382809cb84SRoman Volkov /* mute FP (aux output) amplifier, switch rear jack to CS4245 */ 392809cb84SRoman Volkov oxygen_set_bits8(chip, OXYGEN_GPIO_DATA, GPIO_HP_REAR); 402809cb84SRoman Volkov } else if (data->output_sel == PLAYBACK_DST_HP_FP) { 412809cb84SRoman Volkov /* 422809cb84SRoman Volkov * Unmute FP amplifier, switch rear jack to CS4361; 432809cb84SRoman Volkov * I2S channels 2,3,4 should be inactive. 442809cb84SRoman Volkov */ 452809cb84SRoman Volkov oxygen_clear_bits8(chip, OXYGEN_GPIO_DATA, GPIO_HP_REAR); 462809cb84SRoman Volkov data->cs4245_shadow[CS4245_SIGNAL_SEL] |= CS4245_A_OUT_SEL_DAC; 472809cb84SRoman Volkov } else { 482809cb84SRoman Volkov /* 492809cb84SRoman Volkov * 2.0, 4.0, 5.1: switch to CS4361, mute FP amp., 502809cb84SRoman Volkov * and change playback routing. 512809cb84SRoman Volkov */ 522809cb84SRoman Volkov oxygen_clear_bits8(chip, OXYGEN_GPIO_DATA, GPIO_HP_REAR); 532809cb84SRoman Volkov } 542809cb84SRoman Volkov return cs4245_write_spi(chip, CS4245_SIGNAL_SEL); 552809cb84SRoman Volkov } 562809cb84SRoman Volkov 572809cb84SRoman Volkov static int output_select_info(struct snd_kcontrol *ctl, 58041f26b6SRoman Volkov struct snd_ctl_elem_info *info) 59041f26b6SRoman Volkov { 60041f26b6SRoman Volkov static const char *const names[3] = { 612809cb84SRoman Volkov "Stereo Headphones", 622809cb84SRoman Volkov "Stereo Headphones FP", 632809cb84SRoman Volkov "Multichannel", 64041f26b6SRoman Volkov }; 65041f26b6SRoman Volkov 66041f26b6SRoman Volkov return snd_ctl_enum_info(info, 1, 3, names); 67041f26b6SRoman Volkov } 68041f26b6SRoman Volkov 692809cb84SRoman Volkov static int output_select_get(struct snd_kcontrol *ctl, 70041f26b6SRoman Volkov struct snd_ctl_elem_value *value) 71041f26b6SRoman Volkov { 72041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 73041f26b6SRoman Volkov struct dg *data = chip->model_data; 74041f26b6SRoman Volkov 75041f26b6SRoman Volkov mutex_lock(&chip->mutex); 76041f26b6SRoman Volkov value->value.enumerated.item[0] = data->output_sel; 77041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 78041f26b6SRoman Volkov return 0; 79041f26b6SRoman Volkov } 80041f26b6SRoman Volkov 812809cb84SRoman Volkov static int output_select_put(struct snd_kcontrol *ctl, 82041f26b6SRoman Volkov struct snd_ctl_elem_value *value) 83041f26b6SRoman Volkov { 84041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 85041f26b6SRoman Volkov struct dg *data = chip->model_data; 862809cb84SRoman Volkov unsigned int new = value->value.enumerated.item[0]; 872809cb84SRoman Volkov int changed = 0; 882809cb84SRoman Volkov int ret; 89041f26b6SRoman Volkov 90041f26b6SRoman Volkov mutex_lock(&chip->mutex); 912809cb84SRoman Volkov if (data->output_sel != new) { 922809cb84SRoman Volkov data->output_sel = new; 932809cb84SRoman Volkov ret = output_select_apply(chip); 942809cb84SRoman Volkov changed = ret >= 0 ? 1 : ret; 952809cb84SRoman Volkov oxygen_update_dac_routing(chip); 96041f26b6SRoman Volkov } 97041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 982809cb84SRoman Volkov 99041f26b6SRoman Volkov return changed; 100041f26b6SRoman Volkov } 101041f26b6SRoman Volkov 102c754639aSRoman Volkov /* CS4245 Headphone Channels A&B Volume Control */ 103c754639aSRoman Volkov 104c754639aSRoman Volkov static int hp_stereo_volume_info(struct snd_kcontrol *ctl, 105041f26b6SRoman Volkov struct snd_ctl_elem_info *info) 106041f26b6SRoman Volkov { 107c754639aSRoman Volkov info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 108c754639aSRoman Volkov info->count = 2; 109c754639aSRoman Volkov info->value.integer.min = 0; 110c754639aSRoman Volkov info->value.integer.max = 255; 111c754639aSRoman Volkov return 0; 112041f26b6SRoman Volkov } 113041f26b6SRoman Volkov 114c754639aSRoman Volkov static int hp_stereo_volume_get(struct snd_kcontrol *ctl, 115c754639aSRoman Volkov struct snd_ctl_elem_value *val) 116041f26b6SRoman Volkov { 117041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 118041f26b6SRoman Volkov struct dg *data = chip->model_data; 119c754639aSRoman Volkov unsigned int tmp; 120041f26b6SRoman Volkov 121041f26b6SRoman Volkov mutex_lock(&chip->mutex); 122c754639aSRoman Volkov tmp = (~data->cs4245_shadow[CS4245_DAC_A_CTRL]) & 255; 123c754639aSRoman Volkov val->value.integer.value[0] = tmp; 124c754639aSRoman Volkov tmp = (~data->cs4245_shadow[CS4245_DAC_B_CTRL]) & 255; 125c754639aSRoman Volkov val->value.integer.value[1] = tmp; 126041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 127041f26b6SRoman Volkov return 0; 128041f26b6SRoman Volkov } 129041f26b6SRoman Volkov 130c754639aSRoman Volkov static int hp_stereo_volume_put(struct snd_kcontrol *ctl, 131c754639aSRoman Volkov struct snd_ctl_elem_value *val) 132041f26b6SRoman Volkov { 133041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 134041f26b6SRoman Volkov struct dg *data = chip->model_data; 135c754639aSRoman Volkov int ret; 136c754639aSRoman Volkov int changed = 0; 137c754639aSRoman Volkov long new1 = val->value.integer.value[0]; 138c754639aSRoman Volkov long new2 = val->value.integer.value[1]; 139c754639aSRoman Volkov 140c754639aSRoman Volkov if ((new1 > 255) || (new1 < 0) || (new2 > 255) || (new2 < 0)) 141c754639aSRoman Volkov return -EINVAL; 142c754639aSRoman Volkov 143c754639aSRoman Volkov mutex_lock(&chip->mutex); 144c754639aSRoman Volkov if ((data->cs4245_shadow[CS4245_DAC_A_CTRL] != ~new1) || 145c754639aSRoman Volkov (data->cs4245_shadow[CS4245_DAC_B_CTRL] != ~new2)) { 146c754639aSRoman Volkov data->cs4245_shadow[CS4245_DAC_A_CTRL] = ~new1; 147c754639aSRoman Volkov data->cs4245_shadow[CS4245_DAC_B_CTRL] = ~new2; 148c754639aSRoman Volkov ret = cs4245_write_spi(chip, CS4245_DAC_A_CTRL); 149c754639aSRoman Volkov if (ret >= 0) 150c754639aSRoman Volkov ret = cs4245_write_spi(chip, CS4245_DAC_B_CTRL); 151c754639aSRoman Volkov changed = ret >= 0 ? 1 : ret; 152c754639aSRoman Volkov } 153c754639aSRoman Volkov mutex_unlock(&chip->mutex); 154c754639aSRoman Volkov 155c754639aSRoman Volkov return changed; 156c754639aSRoman Volkov } 157c754639aSRoman Volkov 158c754639aSRoman Volkov /* Headphone Mute */ 159c754639aSRoman Volkov 160c754639aSRoman Volkov static int hp_mute_get(struct snd_kcontrol *ctl, 161c754639aSRoman Volkov struct snd_ctl_elem_value *val) 162c754639aSRoman Volkov { 163c754639aSRoman Volkov struct oxygen *chip = ctl->private_data; 164c754639aSRoman Volkov struct dg *data = chip->model_data; 165c754639aSRoman Volkov 166c754639aSRoman Volkov mutex_lock(&chip->mutex); 167c754639aSRoman Volkov val->value.integer.value[0] = 168c754639aSRoman Volkov !(data->cs4245_shadow[CS4245_DAC_CTRL_1] & CS4245_MUTE_DAC); 169c754639aSRoman Volkov mutex_unlock(&chip->mutex); 170c754639aSRoman Volkov return 0; 171c754639aSRoman Volkov } 172c754639aSRoman Volkov 173c754639aSRoman Volkov static int hp_mute_put(struct snd_kcontrol *ctl, 174c754639aSRoman Volkov struct snd_ctl_elem_value *val) 175c754639aSRoman Volkov { 176c754639aSRoman Volkov struct oxygen *chip = ctl->private_data; 177c754639aSRoman Volkov struct dg *data = chip->model_data; 178c754639aSRoman Volkov int ret; 179041f26b6SRoman Volkov int changed; 180041f26b6SRoman Volkov 181c754639aSRoman Volkov if (val->value.integer.value[0] > 1) 182041f26b6SRoman Volkov return -EINVAL; 183041f26b6SRoman Volkov mutex_lock(&chip->mutex); 184c754639aSRoman Volkov data->cs4245_shadow[CS4245_DAC_CTRL_1] &= ~CS4245_MUTE_DAC; 185c754639aSRoman Volkov data->cs4245_shadow[CS4245_DAC_CTRL_1] |= 186c754639aSRoman Volkov (~val->value.integer.value[0] << 2) & CS4245_MUTE_DAC; 187c754639aSRoman Volkov ret = cs4245_write_spi(chip, CS4245_DAC_CTRL_1); 188c754639aSRoman Volkov changed = ret >= 0 ? 1 : ret; 189041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 190041f26b6SRoman Volkov return changed; 191041f26b6SRoman Volkov } 192041f26b6SRoman Volkov 193cf218b2eSRoman Volkov /* capture volume for all sources */ 194cf218b2eSRoman Volkov 195cf218b2eSRoman Volkov static int input_volume_apply(struct oxygen *chip, char left, char right) 196cf218b2eSRoman Volkov { 197cf218b2eSRoman Volkov struct dg *data = chip->model_data; 198cf218b2eSRoman Volkov int ret; 199cf218b2eSRoman Volkov 200cf218b2eSRoman Volkov data->cs4245_shadow[CS4245_PGA_A_CTRL] = left; 201cf218b2eSRoman Volkov data->cs4245_shadow[CS4245_PGA_B_CTRL] = right; 202cf218b2eSRoman Volkov ret = cs4245_write_spi(chip, CS4245_PGA_A_CTRL); 203cf218b2eSRoman Volkov if (ret < 0) 204cf218b2eSRoman Volkov return ret; 205cf218b2eSRoman Volkov return cs4245_write_spi(chip, CS4245_PGA_B_CTRL); 206cf218b2eSRoman Volkov } 207cf218b2eSRoman Volkov 208041f26b6SRoman Volkov static int input_vol_info(struct snd_kcontrol *ctl, 209041f26b6SRoman Volkov struct snd_ctl_elem_info *info) 210041f26b6SRoman Volkov { 211041f26b6SRoman Volkov info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 212041f26b6SRoman Volkov info->count = 2; 213041f26b6SRoman Volkov info->value.integer.min = 2 * -12; 214041f26b6SRoman Volkov info->value.integer.max = 2 * 12; 215041f26b6SRoman Volkov return 0; 216041f26b6SRoman Volkov } 217041f26b6SRoman Volkov 218041f26b6SRoman Volkov static int input_vol_get(struct snd_kcontrol *ctl, 219041f26b6SRoman Volkov struct snd_ctl_elem_value *value) 220041f26b6SRoman Volkov { 221041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 222041f26b6SRoman Volkov struct dg *data = chip->model_data; 223041f26b6SRoman Volkov unsigned int idx = ctl->private_value; 224041f26b6SRoman Volkov 225041f26b6SRoman Volkov mutex_lock(&chip->mutex); 226041f26b6SRoman Volkov value->value.integer.value[0] = data->input_vol[idx][0]; 227041f26b6SRoman Volkov value->value.integer.value[1] = data->input_vol[idx][1]; 228041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 229041f26b6SRoman Volkov return 0; 230041f26b6SRoman Volkov } 231041f26b6SRoman Volkov 232041f26b6SRoman Volkov static int input_vol_put(struct snd_kcontrol *ctl, 233041f26b6SRoman Volkov struct snd_ctl_elem_value *value) 234041f26b6SRoman Volkov { 235041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 236041f26b6SRoman Volkov struct dg *data = chip->model_data; 237041f26b6SRoman Volkov unsigned int idx = ctl->private_value; 238041f26b6SRoman Volkov int changed = 0; 239cf218b2eSRoman Volkov int ret = 0; 240041f26b6SRoman Volkov 241041f26b6SRoman Volkov if (value->value.integer.value[0] < 2 * -12 || 242041f26b6SRoman Volkov value->value.integer.value[0] > 2 * 12 || 243041f26b6SRoman Volkov value->value.integer.value[1] < 2 * -12 || 244041f26b6SRoman Volkov value->value.integer.value[1] > 2 * 12) 245041f26b6SRoman Volkov return -EINVAL; 246041f26b6SRoman Volkov mutex_lock(&chip->mutex); 247041f26b6SRoman Volkov changed = data->input_vol[idx][0] != value->value.integer.value[0] || 248041f26b6SRoman Volkov data->input_vol[idx][1] != value->value.integer.value[1]; 249041f26b6SRoman Volkov if (changed) { 250041f26b6SRoman Volkov data->input_vol[idx][0] = value->value.integer.value[0]; 251041f26b6SRoman Volkov data->input_vol[idx][1] = value->value.integer.value[1]; 252041f26b6SRoman Volkov if (idx == data->input_sel) { 253cf218b2eSRoman Volkov ret = input_volume_apply(chip, 254cf218b2eSRoman Volkov data->input_vol[idx][0], 255041f26b6SRoman Volkov data->input_vol[idx][1]); 256041f26b6SRoman Volkov } 257cf218b2eSRoman Volkov changed = ret >= 0 ? 1 : ret; 258041f26b6SRoman Volkov } 259041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 260041f26b6SRoman Volkov return changed; 261041f26b6SRoman Volkov } 262041f26b6SRoman Volkov 26370e0d82dSRoman Volkov /* Capture Source */ 26470e0d82dSRoman Volkov 26570e0d82dSRoman Volkov static int input_source_apply(struct oxygen *chip) 26670e0d82dSRoman Volkov { 26770e0d82dSRoman Volkov struct dg *data = chip->model_data; 26870e0d82dSRoman Volkov 26970e0d82dSRoman Volkov data->cs4245_shadow[CS4245_ANALOG_IN] &= ~CS4245_SEL_MASK; 27070e0d82dSRoman Volkov if (data->input_sel == CAPTURE_SRC_FP_MIC) 27170e0d82dSRoman Volkov data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_2; 27270e0d82dSRoman Volkov else if (data->input_sel == CAPTURE_SRC_LINE) 27370e0d82dSRoman Volkov data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_4; 27470e0d82dSRoman Volkov else if (data->input_sel != CAPTURE_SRC_MIC) 27570e0d82dSRoman Volkov data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_1; 27670e0d82dSRoman Volkov return cs4245_write_spi(chip, CS4245_ANALOG_IN); 27770e0d82dSRoman Volkov } 27870e0d82dSRoman Volkov 279041f26b6SRoman Volkov static int input_sel_info(struct snd_kcontrol *ctl, 280041f26b6SRoman Volkov struct snd_ctl_elem_info *info) 281041f26b6SRoman Volkov { 282041f26b6SRoman Volkov static const char *const names[4] = { 28370e0d82dSRoman Volkov "Mic", "Front Mic", "Line", "Aux" 284041f26b6SRoman Volkov }; 285041f26b6SRoman Volkov 286041f26b6SRoman Volkov return snd_ctl_enum_info(info, 1, 4, names); 287041f26b6SRoman Volkov } 288041f26b6SRoman Volkov 289041f26b6SRoman Volkov static int input_sel_get(struct snd_kcontrol *ctl, 290041f26b6SRoman Volkov struct snd_ctl_elem_value *value) 291041f26b6SRoman Volkov { 292041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 293041f26b6SRoman Volkov struct dg *data = chip->model_data; 294041f26b6SRoman Volkov 295041f26b6SRoman Volkov mutex_lock(&chip->mutex); 296041f26b6SRoman Volkov value->value.enumerated.item[0] = data->input_sel; 297041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 298041f26b6SRoman Volkov return 0; 299041f26b6SRoman Volkov } 300041f26b6SRoman Volkov 301041f26b6SRoman Volkov static int input_sel_put(struct snd_kcontrol *ctl, 302041f26b6SRoman Volkov struct snd_ctl_elem_value *value) 303041f26b6SRoman Volkov { 304041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 305041f26b6SRoman Volkov struct dg *data = chip->model_data; 306041f26b6SRoman Volkov int changed; 30770e0d82dSRoman Volkov int ret; 308041f26b6SRoman Volkov 309041f26b6SRoman Volkov if (value->value.enumerated.item[0] > 3) 310041f26b6SRoman Volkov return -EINVAL; 311041f26b6SRoman Volkov 312041f26b6SRoman Volkov mutex_lock(&chip->mutex); 313041f26b6SRoman Volkov changed = value->value.enumerated.item[0] != data->input_sel; 314041f26b6SRoman Volkov if (changed) { 315041f26b6SRoman Volkov data->input_sel = value->value.enumerated.item[0]; 316041f26b6SRoman Volkov 31770e0d82dSRoman Volkov ret = input_source_apply(chip); 31870e0d82dSRoman Volkov if (ret >= 0) 31970e0d82dSRoman Volkov ret = input_volume_apply(chip, 32070e0d82dSRoman Volkov data->input_vol[data->input_sel][0], 321041f26b6SRoman Volkov data->input_vol[data->input_sel][1]); 32270e0d82dSRoman Volkov changed = ret >= 0 ? 1 : ret; 323041f26b6SRoman Volkov } 324041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 325041f26b6SRoman Volkov return changed; 326041f26b6SRoman Volkov } 327041f26b6SRoman Volkov 328fc114e9fSRoman Volkov /* ADC high-pass filter */ 329fc114e9fSRoman Volkov 330041f26b6SRoman Volkov static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) 331041f26b6SRoman Volkov { 332041f26b6SRoman Volkov static const char *const names[2] = { "Active", "Frozen" }; 333041f26b6SRoman Volkov 334041f26b6SRoman Volkov return snd_ctl_enum_info(info, 1, 2, names); 335041f26b6SRoman Volkov } 336041f26b6SRoman Volkov 337041f26b6SRoman Volkov static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 338041f26b6SRoman Volkov { 339041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 340041f26b6SRoman Volkov struct dg *data = chip->model_data; 341041f26b6SRoman Volkov 342041f26b6SRoman Volkov value->value.enumerated.item[0] = 343041f26b6SRoman Volkov !!(data->cs4245_shadow[CS4245_ADC_CTRL] & CS4245_HPF_FREEZE); 344041f26b6SRoman Volkov return 0; 345041f26b6SRoman Volkov } 346041f26b6SRoman Volkov 347041f26b6SRoman Volkov static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 348041f26b6SRoman Volkov { 349041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 350041f26b6SRoman Volkov struct dg *data = chip->model_data; 351041f26b6SRoman Volkov u8 reg; 352041f26b6SRoman Volkov int changed; 353041f26b6SRoman Volkov 354041f26b6SRoman Volkov mutex_lock(&chip->mutex); 355041f26b6SRoman Volkov reg = data->cs4245_shadow[CS4245_ADC_CTRL] & ~CS4245_HPF_FREEZE; 356041f26b6SRoman Volkov if (value->value.enumerated.item[0]) 357041f26b6SRoman Volkov reg |= CS4245_HPF_FREEZE; 358041f26b6SRoman Volkov changed = reg != data->cs4245_shadow[CS4245_ADC_CTRL]; 359fc114e9fSRoman Volkov if (changed) { 360fc114e9fSRoman Volkov data->cs4245_shadow[CS4245_ADC_CTRL] = reg; 361fc114e9fSRoman Volkov cs4245_write_spi(chip, CS4245_ADC_CTRL); 362fc114e9fSRoman Volkov } 363041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 364041f26b6SRoman Volkov return changed; 365041f26b6SRoman Volkov } 366041f26b6SRoman Volkov 367041f26b6SRoman Volkov #define INPUT_VOLUME(xname, index) { \ 368041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 369041f26b6SRoman Volkov .name = xname, \ 370cf218b2eSRoman Volkov .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ 371cf218b2eSRoman Volkov SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ 372041f26b6SRoman Volkov .info = input_vol_info, \ 373041f26b6SRoman Volkov .get = input_vol_get, \ 374041f26b6SRoman Volkov .put = input_vol_put, \ 375cf218b2eSRoman Volkov .tlv = { .p = pga_db_scale }, \ 376041f26b6SRoman Volkov .private_value = index, \ 377041f26b6SRoman Volkov } 378c754639aSRoman Volkov static const DECLARE_TLV_DB_MINMAX(hp_db_scale, -12550, 0); 379cf218b2eSRoman Volkov static const DECLARE_TLV_DB_MINMAX(pga_db_scale, -1200, 1200); 380041f26b6SRoman Volkov static const struct snd_kcontrol_new dg_controls[] = { 381041f26b6SRoman Volkov { 382041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 383041f26b6SRoman Volkov .name = "Analog Output Playback Enum", 3842809cb84SRoman Volkov .info = output_select_info, 3852809cb84SRoman Volkov .get = output_select_get, 3862809cb84SRoman Volkov .put = output_select_put, 387041f26b6SRoman Volkov }, 388041f26b6SRoman Volkov { 389041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 390c754639aSRoman Volkov .name = "Headphone Playback Volume", 391c754639aSRoman Volkov .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 392c754639aSRoman Volkov SNDRV_CTL_ELEM_ACCESS_TLV_READ, 393c754639aSRoman Volkov .info = hp_stereo_volume_info, 394c754639aSRoman Volkov .get = hp_stereo_volume_get, 395c754639aSRoman Volkov .put = hp_stereo_volume_put, 396c754639aSRoman Volkov .tlv = { .p = hp_db_scale, }, 397c754639aSRoman Volkov }, 398c754639aSRoman Volkov { 399c754639aSRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 400c754639aSRoman Volkov .name = "Headphone Playback Switch", 401c754639aSRoman Volkov .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 402c754639aSRoman Volkov .info = snd_ctl_boolean_mono_info, 403c754639aSRoman Volkov .get = hp_mute_get, 404c754639aSRoman Volkov .put = hp_mute_put, 405041f26b6SRoman Volkov }, 40670e0d82dSRoman Volkov INPUT_VOLUME("Mic Capture Volume", CAPTURE_SRC_MIC), 40770e0d82dSRoman Volkov INPUT_VOLUME("Front Mic Capture Volume", CAPTURE_SRC_FP_MIC), 40870e0d82dSRoman Volkov INPUT_VOLUME("Line Capture Volume", CAPTURE_SRC_LINE), 40970e0d82dSRoman Volkov INPUT_VOLUME("Aux Capture Volume", CAPTURE_SRC_AUX), 410041f26b6SRoman Volkov { 411041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 412041f26b6SRoman Volkov .name = "Capture Source", 413041f26b6SRoman Volkov .info = input_sel_info, 414041f26b6SRoman Volkov .get = input_sel_get, 415041f26b6SRoman Volkov .put = input_sel_put, 416041f26b6SRoman Volkov }, 417041f26b6SRoman Volkov { 418041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 419041f26b6SRoman Volkov .name = "ADC High-pass Filter Capture Enum", 420041f26b6SRoman Volkov .info = hpf_info, 421041f26b6SRoman Volkov .get = hpf_get, 422041f26b6SRoman Volkov .put = hpf_put, 423041f26b6SRoman Volkov }, 424041f26b6SRoman Volkov }; 425041f26b6SRoman Volkov 426041f26b6SRoman Volkov static int dg_control_filter(struct snd_kcontrol_new *template) 427041f26b6SRoman Volkov { 428041f26b6SRoman Volkov if (!strncmp(template->name, "Master Playback ", 16)) 429041f26b6SRoman Volkov return 1; 430041f26b6SRoman Volkov return 0; 431041f26b6SRoman Volkov } 432041f26b6SRoman Volkov 433041f26b6SRoman Volkov static int dg_mixer_init(struct oxygen *chip) 434041f26b6SRoman Volkov { 435041f26b6SRoman Volkov unsigned int i; 436041f26b6SRoman Volkov int err; 437041f26b6SRoman Volkov 438*3f49a66fSRoman Volkov output_select_apply(chip); 439*3f49a66fSRoman Volkov input_source_apply(chip); 440*3f49a66fSRoman Volkov oxygen_update_dac_routing(chip); 441*3f49a66fSRoman Volkov 442041f26b6SRoman Volkov for (i = 0; i < ARRAY_SIZE(dg_controls); ++i) { 443041f26b6SRoman Volkov err = snd_ctl_add(chip->card, 444041f26b6SRoman Volkov snd_ctl_new1(&dg_controls[i], chip)); 445041f26b6SRoman Volkov if (err < 0) 446041f26b6SRoman Volkov return err; 447041f26b6SRoman Volkov } 448*3f49a66fSRoman Volkov 449041f26b6SRoman Volkov return 0; 450041f26b6SRoman Volkov } 451041f26b6SRoman Volkov 452041f26b6SRoman Volkov struct oxygen_model model_xonar_dg = { 453041f26b6SRoman Volkov .longname = "C-Media Oxygen HD Audio", 454041f26b6SRoman Volkov .chip = "CMI8786", 455041f26b6SRoman Volkov .init = dg_init, 456041f26b6SRoman Volkov .control_filter = dg_control_filter, 457041f26b6SRoman Volkov .mixer_init = dg_mixer_init, 458041f26b6SRoman Volkov .cleanup = dg_cleanup, 459041f26b6SRoman Volkov .suspend = dg_suspend, 460041f26b6SRoman Volkov .resume = dg_resume, 461041f26b6SRoman Volkov .set_dac_params = set_cs4245_dac_params, 462041f26b6SRoman Volkov .set_adc_params = set_cs4245_adc_params, 463041f26b6SRoman Volkov .adjust_dac_routing = adjust_dg_dac_routing, 464041f26b6SRoman Volkov .dump_registers = dump_cs4245_registers, 465041f26b6SRoman Volkov .model_data_size = sizeof(struct dg), 466041f26b6SRoman Volkov .device_config = PLAYBACK_0_TO_I2S | 467041f26b6SRoman Volkov PLAYBACK_1_TO_SPDIF | 4683dd77654SRoman Volkov CAPTURE_0_FROM_I2S_1 | 469041f26b6SRoman Volkov CAPTURE_1_FROM_SPDIF, 470041f26b6SRoman Volkov .dac_channels_pcm = 6, 471041f26b6SRoman Volkov .dac_channels_mixer = 0, 472041f26b6SRoman Volkov .function_flags = OXYGEN_FUNCTION_SPI, 473041f26b6SRoman Volkov .dac_mclks = OXYGEN_MCLKS(256, 128, 128), 474041f26b6SRoman Volkov .adc_mclks = OXYGEN_MCLKS(256, 128, 128), 475041f26b6SRoman Volkov .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 476041f26b6SRoman Volkov .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 477041f26b6SRoman Volkov }; 478