aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/oxygen/xonar_pcm179x.c110
1 files changed, 99 insertions, 11 deletions
diff --git a/sound/pci/oxygen/xonar_pcm179x.c b/sound/pci/oxygen/xonar_pcm179x.c
index e17ee5e8e510..cf94e4432a3f 100644
--- a/sound/pci/oxygen/xonar_pcm179x.c
+++ b/sound/pci/oxygen/xonar_pcm179x.c
@@ -173,6 +173,8 @@ struct xonar_pcm179x {
173 struct xonar_generic generic; 173 struct xonar_generic generic;
174 unsigned int dacs; 174 unsigned int dacs;
175 u8 pcm1796_regs[4][5]; 175 u8 pcm1796_regs[4][5];
176 bool hp_active;
177 s8 hp_gain_offset;
176 u8 cs2000_fun_cfg_1; 178 u8 cs2000_fun_cfg_1;
177}; 179};
178 180
@@ -249,13 +251,17 @@ static void pcm1796_registers_init(struct oxygen *chip)
249{ 251{
250 struct xonar_pcm179x *data = chip->model_data; 252 struct xonar_pcm179x *data = chip->model_data;
251 unsigned int i; 253 unsigned int i;
254 s8 gain_offset;
252 255
256 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
253 for (i = 0; i < data->dacs; ++i) { 257 for (i = 0; i < data->dacs; ++i) {
254 /* set ATLD before ATL/ATR */ 258 /* set ATLD before ATL/ATR */
255 pcm1796_write(chip, i, 18, 259 pcm1796_write(chip, i, 18,
256 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]); 260 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
257 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]); 261 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
258 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]); 262 + gain_offset);
263 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
264 + gain_offset);
259 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); 265 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
260 pcm1796_write(chip, i, 20, 266 pcm1796_write(chip, i, 20,
261 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]); 267 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
@@ -352,6 +358,7 @@ static void xonar_st_init_common(struct oxygen *chip)
352 data->generic.anti_pop_delay = 100; 358 data->generic.anti_pop_delay = 100;
353 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE; 359 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
354 data->dacs = chip->model.private_data ? 4 : 1; 360 data->dacs = chip->model.private_data ? 4 : 1;
361 data->hp_gain_offset = 2*-18;
355 362
356 pcm1796_init(chip); 363 pcm1796_init(chip);
357 364
@@ -495,10 +502,14 @@ static void update_pcm1796_volume(struct oxygen *chip)
495{ 502{
496 struct xonar_pcm179x *data = chip->model_data; 503 struct xonar_pcm179x *data = chip->model_data;
497 unsigned int i; 504 unsigned int i;
505 s8 gain_offset;
498 506
507 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
499 for (i = 0; i < data->dacs; ++i) { 508 for (i = 0; i < data->dacs; ++i) {
500 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]); 509 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
501 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]); 510 + gain_offset);
511 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
512 + gain_offset);
502 } 513 }
503} 514}
504 515
@@ -606,6 +617,7 @@ static int st_output_switch_put(struct snd_kcontrol *ctl,
606 struct snd_ctl_elem_value *value) 617 struct snd_ctl_elem_value *value)
607{ 618{
608 struct oxygen *chip = ctl->private_data; 619 struct oxygen *chip = ctl->private_data;
620 struct xonar_pcm179x *data = chip->model_data;
609 u16 gpio_old, gpio; 621 u16 gpio_old, gpio;
610 622
611 mutex_lock(&chip->mutex); 623 mutex_lock(&chip->mutex);
@@ -623,16 +635,83 @@ static int st_output_switch_put(struct snd_kcontrol *ctl,
623 break; 635 break;
624 } 636 }
625 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio); 637 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
638 data->hp_active = gpio & GPIO_ST_HP;
639 update_pcm1796_volume(chip);
626 mutex_unlock(&chip->mutex); 640 mutex_unlock(&chip->mutex);
627 return gpio != gpio_old; 641 return gpio != gpio_old;
628} 642}
629 643
630static const struct snd_kcontrol_new st_output_switch = { 644static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
631 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 645 struct snd_ctl_elem_info *info)
632 .name = "Analog Output", 646{
633 .info = st_output_switch_info, 647 static const char *const names[3] = {
634 .get = st_output_switch_get, 648 "< 64 ohms", "64-300 ohms", "300-600 ohms"
635 .put = st_output_switch_put, 649 };
650
651 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
652 info->count = 1;
653 info->value.enumerated.items = 3;
654 if (info->value.enumerated.item > 2)
655 info->value.enumerated.item = 2;
656 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
657 return 0;
658}
659
660static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
661 struct snd_ctl_elem_value *value)
662{
663 struct oxygen *chip = ctl->private_data;
664 struct xonar_pcm179x *data = chip->model_data;
665
666 mutex_lock(&chip->mutex);
667 if (data->hp_gain_offset < 2*-6)
668 value->value.enumerated.item[0] = 0;
669 else if (data->hp_gain_offset < 0)
670 value->value.enumerated.item[0] = 1;
671 else
672 value->value.enumerated.item[0] = 2;
673 mutex_unlock(&chip->mutex);
674 return 0;
675}
676
677
678static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
679 struct snd_ctl_elem_value *value)
680{
681 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
682 struct oxygen *chip = ctl->private_data;
683 struct xonar_pcm179x *data = chip->model_data;
684 s8 offset;
685 int changed;
686
687 if (value->value.enumerated.item[0] > 2)
688 return -EINVAL;
689 offset = offsets[value->value.enumerated.item[0]];
690 mutex_lock(&chip->mutex);
691 changed = offset != data->hp_gain_offset;
692 if (changed) {
693 data->hp_gain_offset = offset;
694 update_pcm1796_volume(chip);
695 }
696 mutex_unlock(&chip->mutex);
697 return changed;
698}
699
700static const struct snd_kcontrol_new st_controls[] = {
701 {
702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
703 .name = "Analog Output",
704 .info = st_output_switch_info,
705 .get = st_output_switch_get,
706 .put = st_output_switch_put,
707 },
708 {
709 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
710 .name = "Headphones Impedance Playback Enum",
711 .info = st_hp_volume_offset_info,
712 .get = st_hp_volume_offset_get,
713 .put = st_hp_volume_offset_put,
714 },
636}; 715};
637 716
638static void xonar_line_mic_ac97_switch(struct oxygen *chip, 717static void xonar_line_mic_ac97_switch(struct oxygen *chip,
@@ -671,7 +750,16 @@ static int xonar_d2_mixer_init(struct oxygen *chip)
671 750
672static int xonar_st_mixer_init(struct oxygen *chip) 751static int xonar_st_mixer_init(struct oxygen *chip)
673{ 752{
674 return snd_ctl_add(chip->card, snd_ctl_new1(&st_output_switch, chip)); 753 unsigned int i;
754 int err;
755
756 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
757 err = snd_ctl_add(chip->card,
758 snd_ctl_new1(&st_controls[i], chip));
759 if (err < 0)
760 return err;
761 }
762 return 0;
675} 763}
676 764
677static const struct oxygen_model model_xonar_d2 = { 765static const struct oxygen_model model_xonar_d2 = {