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 193*cf218b2eSRoman Volkov /* capture volume for all sources */ 194*cf218b2eSRoman Volkov 195*cf218b2eSRoman Volkov static int input_volume_apply(struct oxygen *chip, char left, char right) 196*cf218b2eSRoman Volkov { 197*cf218b2eSRoman Volkov struct dg *data = chip->model_data; 198*cf218b2eSRoman Volkov int ret; 199*cf218b2eSRoman Volkov 200*cf218b2eSRoman Volkov data->cs4245_shadow[CS4245_PGA_A_CTRL] = left; 201*cf218b2eSRoman Volkov data->cs4245_shadow[CS4245_PGA_B_CTRL] = right; 202*cf218b2eSRoman Volkov ret = cs4245_write_spi(chip, CS4245_PGA_A_CTRL); 203*cf218b2eSRoman Volkov if (ret < 0) 204*cf218b2eSRoman Volkov return ret; 205*cf218b2eSRoman Volkov return cs4245_write_spi(chip, CS4245_PGA_B_CTRL); 206*cf218b2eSRoman Volkov } 207*cf218b2eSRoman 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; 239*cf218b2eSRoman 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) { 253*cf218b2eSRoman Volkov ret = input_volume_apply(chip, 254*cf218b2eSRoman Volkov data->input_vol[idx][0], 255041f26b6SRoman Volkov data->input_vol[idx][1]); 256041f26b6SRoman Volkov } 257*cf218b2eSRoman Volkov changed = ret >= 0 ? 1 : ret; 258041f26b6SRoman Volkov } 259041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 260041f26b6SRoman Volkov return changed; 261041f26b6SRoman Volkov } 262041f26b6SRoman Volkov 263041f26b6SRoman Volkov static int input_sel_info(struct snd_kcontrol *ctl, 264041f26b6SRoman Volkov struct snd_ctl_elem_info *info) 265041f26b6SRoman Volkov { 266041f26b6SRoman Volkov static const char *const names[4] = { 267041f26b6SRoman Volkov "Mic", "Aux", "Front Mic", "Line" 268041f26b6SRoman Volkov }; 269041f26b6SRoman Volkov 270041f26b6SRoman Volkov return snd_ctl_enum_info(info, 1, 4, names); 271041f26b6SRoman Volkov } 272041f26b6SRoman Volkov 273041f26b6SRoman Volkov static int input_sel_get(struct snd_kcontrol *ctl, 274041f26b6SRoman Volkov struct snd_ctl_elem_value *value) 275041f26b6SRoman Volkov { 276041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 277041f26b6SRoman Volkov struct dg *data = chip->model_data; 278041f26b6SRoman Volkov 279041f26b6SRoman Volkov mutex_lock(&chip->mutex); 280041f26b6SRoman Volkov value->value.enumerated.item[0] = data->input_sel; 281041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 282041f26b6SRoman Volkov return 0; 283041f26b6SRoman Volkov } 284041f26b6SRoman Volkov 285041f26b6SRoman Volkov static int input_sel_put(struct snd_kcontrol *ctl, 286041f26b6SRoman Volkov struct snd_ctl_elem_value *value) 287041f26b6SRoman Volkov { 288041f26b6SRoman Volkov static const u8 sel_values[4] = { 289041f26b6SRoman Volkov CS4245_SEL_MIC, 290041f26b6SRoman Volkov CS4245_SEL_INPUT_1, 291041f26b6SRoman Volkov CS4245_SEL_INPUT_2, 292041f26b6SRoman Volkov CS4245_SEL_INPUT_4 293041f26b6SRoman Volkov }; 294041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 295041f26b6SRoman Volkov struct dg *data = chip->model_data; 296041f26b6SRoman Volkov int changed; 297041f26b6SRoman Volkov 298041f26b6SRoman Volkov if (value->value.enumerated.item[0] > 3) 299041f26b6SRoman Volkov return -EINVAL; 300041f26b6SRoman Volkov 301041f26b6SRoman Volkov mutex_lock(&chip->mutex); 302041f26b6SRoman Volkov changed = value->value.enumerated.item[0] != data->input_sel; 303041f26b6SRoman Volkov if (changed) { 304041f26b6SRoman Volkov data->input_sel = value->value.enumerated.item[0]; 305041f26b6SRoman Volkov 306041f26b6SRoman Volkov cs4245_write(chip, CS4245_ANALOG_IN, 307041f26b6SRoman Volkov (data->cs4245_shadow[CS4245_ANALOG_IN] & 308041f26b6SRoman Volkov ~CS4245_SEL_MASK) | 309041f26b6SRoman Volkov sel_values[data->input_sel]); 310041f26b6SRoman Volkov 311041f26b6SRoman Volkov cs4245_write_cached(chip, CS4245_PGA_A_CTRL, 312041f26b6SRoman Volkov data->input_vol[data->input_sel][0]); 313041f26b6SRoman Volkov cs4245_write_cached(chip, CS4245_PGA_B_CTRL, 314041f26b6SRoman Volkov data->input_vol[data->input_sel][1]); 315041f26b6SRoman Volkov 316041f26b6SRoman Volkov oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 317041f26b6SRoman Volkov data->input_sel ? 0 : GPIO_INPUT_ROUTE, 318041f26b6SRoman Volkov GPIO_INPUT_ROUTE); 319041f26b6SRoman Volkov } 320041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 321041f26b6SRoman Volkov return changed; 322041f26b6SRoman Volkov } 323041f26b6SRoman Volkov 324041f26b6SRoman Volkov static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) 325041f26b6SRoman Volkov { 326041f26b6SRoman Volkov static const char *const names[2] = { "Active", "Frozen" }; 327041f26b6SRoman Volkov 328041f26b6SRoman Volkov return snd_ctl_enum_info(info, 1, 2, names); 329041f26b6SRoman Volkov } 330041f26b6SRoman Volkov 331041f26b6SRoman Volkov static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 332041f26b6SRoman Volkov { 333041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 334041f26b6SRoman Volkov struct dg *data = chip->model_data; 335041f26b6SRoman Volkov 336041f26b6SRoman Volkov value->value.enumerated.item[0] = 337041f26b6SRoman Volkov !!(data->cs4245_shadow[CS4245_ADC_CTRL] & CS4245_HPF_FREEZE); 338041f26b6SRoman Volkov return 0; 339041f26b6SRoman Volkov } 340041f26b6SRoman Volkov 341041f26b6SRoman Volkov static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 342041f26b6SRoman Volkov { 343041f26b6SRoman Volkov struct oxygen *chip = ctl->private_data; 344041f26b6SRoman Volkov struct dg *data = chip->model_data; 345041f26b6SRoman Volkov u8 reg; 346041f26b6SRoman Volkov int changed; 347041f26b6SRoman Volkov 348041f26b6SRoman Volkov mutex_lock(&chip->mutex); 349041f26b6SRoman Volkov reg = data->cs4245_shadow[CS4245_ADC_CTRL] & ~CS4245_HPF_FREEZE; 350041f26b6SRoman Volkov if (value->value.enumerated.item[0]) 351041f26b6SRoman Volkov reg |= CS4245_HPF_FREEZE; 352041f26b6SRoman Volkov changed = reg != data->cs4245_shadow[CS4245_ADC_CTRL]; 353041f26b6SRoman Volkov if (changed) 354041f26b6SRoman Volkov cs4245_write(chip, CS4245_ADC_CTRL, reg); 355041f26b6SRoman Volkov mutex_unlock(&chip->mutex); 356041f26b6SRoman Volkov return changed; 357041f26b6SRoman Volkov } 358041f26b6SRoman Volkov 359041f26b6SRoman Volkov #define INPUT_VOLUME(xname, index) { \ 360041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 361041f26b6SRoman Volkov .name = xname, \ 362*cf218b2eSRoman Volkov .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ 363*cf218b2eSRoman Volkov SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ 364041f26b6SRoman Volkov .info = input_vol_info, \ 365041f26b6SRoman Volkov .get = input_vol_get, \ 366041f26b6SRoman Volkov .put = input_vol_put, \ 367*cf218b2eSRoman Volkov .tlv = { .p = pga_db_scale }, \ 368041f26b6SRoman Volkov .private_value = index, \ 369041f26b6SRoman Volkov } 370c754639aSRoman Volkov static const DECLARE_TLV_DB_MINMAX(hp_db_scale, -12550, 0); 371*cf218b2eSRoman Volkov static const DECLARE_TLV_DB_MINMAX(pga_db_scale, -1200, 1200); 372041f26b6SRoman Volkov static const struct snd_kcontrol_new dg_controls[] = { 373041f26b6SRoman Volkov { 374041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 375041f26b6SRoman Volkov .name = "Analog Output Playback Enum", 3762809cb84SRoman Volkov .info = output_select_info, 3772809cb84SRoman Volkov .get = output_select_get, 3782809cb84SRoman Volkov .put = output_select_put, 379041f26b6SRoman Volkov }, 380041f26b6SRoman Volkov { 381041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 382c754639aSRoman Volkov .name = "Headphone Playback Volume", 383c754639aSRoman Volkov .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 384c754639aSRoman Volkov SNDRV_CTL_ELEM_ACCESS_TLV_READ, 385c754639aSRoman Volkov .info = hp_stereo_volume_info, 386c754639aSRoman Volkov .get = hp_stereo_volume_get, 387c754639aSRoman Volkov .put = hp_stereo_volume_put, 388c754639aSRoman Volkov .tlv = { .p = hp_db_scale, }, 389c754639aSRoman Volkov }, 390c754639aSRoman Volkov { 391c754639aSRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 392c754639aSRoman Volkov .name = "Headphone Playback Switch", 393c754639aSRoman Volkov .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 394c754639aSRoman Volkov .info = snd_ctl_boolean_mono_info, 395c754639aSRoman Volkov .get = hp_mute_get, 396c754639aSRoman Volkov .put = hp_mute_put, 397041f26b6SRoman Volkov }, 398041f26b6SRoman Volkov INPUT_VOLUME("Mic Capture Volume", 0), 399041f26b6SRoman Volkov INPUT_VOLUME("Aux Capture Volume", 1), 400041f26b6SRoman Volkov INPUT_VOLUME("Front Mic Capture Volume", 2), 401041f26b6SRoman Volkov INPUT_VOLUME("Line Capture Volume", 3), 402041f26b6SRoman Volkov { 403041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 404041f26b6SRoman Volkov .name = "Capture Source", 405041f26b6SRoman Volkov .info = input_sel_info, 406041f26b6SRoman Volkov .get = input_sel_get, 407041f26b6SRoman Volkov .put = input_sel_put, 408041f26b6SRoman Volkov }, 409041f26b6SRoman Volkov { 410041f26b6SRoman Volkov .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 411041f26b6SRoman Volkov .name = "ADC High-pass Filter Capture Enum", 412041f26b6SRoman Volkov .info = hpf_info, 413041f26b6SRoman Volkov .get = hpf_get, 414041f26b6SRoman Volkov .put = hpf_put, 415041f26b6SRoman Volkov }, 416041f26b6SRoman Volkov }; 417041f26b6SRoman Volkov 418041f26b6SRoman Volkov static int dg_control_filter(struct snd_kcontrol_new *template) 419041f26b6SRoman Volkov { 420041f26b6SRoman Volkov if (!strncmp(template->name, "Master Playback ", 16)) 421041f26b6SRoman Volkov return 1; 422041f26b6SRoman Volkov return 0; 423041f26b6SRoman Volkov } 424041f26b6SRoman Volkov 425041f26b6SRoman Volkov static int dg_mixer_init(struct oxygen *chip) 426041f26b6SRoman Volkov { 427041f26b6SRoman Volkov unsigned int i; 428041f26b6SRoman Volkov int err; 429041f26b6SRoman Volkov 430041f26b6SRoman Volkov for (i = 0; i < ARRAY_SIZE(dg_controls); ++i) { 431041f26b6SRoman Volkov err = snd_ctl_add(chip->card, 432041f26b6SRoman Volkov snd_ctl_new1(&dg_controls[i], chip)); 433041f26b6SRoman Volkov if (err < 0) 434041f26b6SRoman Volkov return err; 435041f26b6SRoman Volkov } 436041f26b6SRoman Volkov return 0; 437041f26b6SRoman Volkov } 438041f26b6SRoman Volkov 439041f26b6SRoman Volkov struct oxygen_model model_xonar_dg = { 440041f26b6SRoman Volkov .longname = "C-Media Oxygen HD Audio", 441041f26b6SRoman Volkov .chip = "CMI8786", 442041f26b6SRoman Volkov .init = dg_init, 443041f26b6SRoman Volkov .control_filter = dg_control_filter, 444041f26b6SRoman Volkov .mixer_init = dg_mixer_init, 445041f26b6SRoman Volkov .cleanup = dg_cleanup, 446041f26b6SRoman Volkov .suspend = dg_suspend, 447041f26b6SRoman Volkov .resume = dg_resume, 448041f26b6SRoman Volkov .set_dac_params = set_cs4245_dac_params, 449041f26b6SRoman Volkov .set_adc_params = set_cs4245_adc_params, 450041f26b6SRoman Volkov .adjust_dac_routing = adjust_dg_dac_routing, 451041f26b6SRoman Volkov .dump_registers = dump_cs4245_registers, 452041f26b6SRoman Volkov .model_data_size = sizeof(struct dg), 453041f26b6SRoman Volkov .device_config = PLAYBACK_0_TO_I2S | 454041f26b6SRoman Volkov PLAYBACK_1_TO_SPDIF | 4553dd77654SRoman Volkov CAPTURE_0_FROM_I2S_1 | 456041f26b6SRoman Volkov CAPTURE_1_FROM_SPDIF, 457041f26b6SRoman Volkov .dac_channels_pcm = 6, 458041f26b6SRoman Volkov .dac_channels_mixer = 0, 459041f26b6SRoman Volkov .function_flags = OXYGEN_FUNCTION_SPI, 460041f26b6SRoman Volkov .dac_mclks = OXYGEN_MCLKS(256, 128, 128), 461041f26b6SRoman Volkov .adc_mclks = OXYGEN_MCLKS(256, 128, 128), 462041f26b6SRoman Volkov .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 463041f26b6SRoman Volkov .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 464041f26b6SRoman Volkov }; 465