ALSA: hda/realtek - Don't create alt-stream for capture when unnecessary
[pandora-kernel.git] / sound / pci / hda / patch_realtek.c
index f9d24c3..4468cb7 100644 (file)
@@ -116,6 +116,8 @@ struct alc_spec {
        const hda_nid_t *capsrc_nids;
        hda_nid_t dig_in_nid;           /* digital-in NID; optional */
        hda_nid_t mixer_nid;            /* analog-mixer NID */
+       DECLARE_BITMAP(vol_ctls, 0x20 << 1);
+       DECLARE_BITMAP(sw_ctls, 0x20 << 1);
 
        /* capture setup for dynamic dual-adc switch */
        hda_nid_t cur_adc;
@@ -2268,6 +2270,7 @@ static int alc_build_pcms(struct hda_codec *codec)
        struct alc_spec *spec = codec->spec;
        struct hda_pcm *info = spec->pcm_rec;
        const struct hda_pcm_stream *p;
+       bool have_multi_adcs;
        int i;
 
        codec->num_pcms = 1;
@@ -2346,8 +2349,11 @@ static int alc_build_pcms(struct hda_codec *codec)
        /* If the use of more than one ADC is requested for the current
         * model, configure a second analog capture-only PCM.
         */
+       have_multi_adcs = (spec->num_adc_nids > 1) &&
+               !spec->dyn_adc_switch && !spec->auto_mic &&
+               (!spec->input_mux || spec->input_mux->num_items > 1);
        /* Additional Analaog capture for index #2 */
-       if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
+       if (spec->alt_dac_nid || have_multi_adcs) {
                codec->num_pcms = 3;
                info = spec->pcm_rec + 2;
                info->name = spec->stream_name_analog;
@@ -2363,7 +2369,7 @@ static int alc_build_pcms(struct hda_codec *codec)
                                alc_pcm_null_stream;
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
                }
-               if (spec->num_adc_nids > 1) {
+               if (have_multi_adcs) {
                        p = spec->stream_analog_alt_capture;
                        if (!p)
                                p = &alc_pcm_analog_alt_capture;
@@ -2996,22 +3002,42 @@ static int alc_auto_fill_dac_nids(struct hda_codec *codec)
                }
        }
 
-       alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
+       if (cfg->line_out_type != AUTO_PIN_HP_OUT)
+               alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
                                 spec->multiout.hp_out_nid);
-       alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
+       if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
+               alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
                                 spec->multiout.extra_out_nid);
 
        return 0;
 }
 
+static inline unsigned int get_ctl_pos(unsigned int data)
+{
+       hda_nid_t nid = get_amp_nid_(data);
+       unsigned int dir = get_amp_direction_(data);
+       return (nid << 1) | dir;
+}
+
+#define is_ctl_used(bits, data) \
+       test_bit(get_ctl_pos(data), bits)
+#define mark_ctl_usage(bits, data) \
+       set_bit(get_ctl_pos(data), bits)
+
 static int alc_auto_add_vol_ctl(struct hda_codec *codec,
                              const char *pfx, int cidx,
                              hda_nid_t nid, unsigned int chs)
 {
+       struct alc_spec *spec = codec->spec;
+       unsigned int val;
        if (!nid)
                return 0;
+       val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
+       if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
+               return 0;
+       mark_ctl_usage(spec->vol_ctls, val);
        return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
-                                HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
+                                val);
 }
 
 #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
@@ -3024,6 +3050,7 @@ static int alc_auto_add_sw_ctl(struct hda_codec *codec,
                             const char *pfx, int cidx,
                             hda_nid_t nid, unsigned int chs)
 {
+       struct alc_spec *spec = codec->spec;
        int wid_type;
        int type;
        unsigned long val;
@@ -3040,6 +3067,9 @@ static int alc_auto_add_sw_ctl(struct hda_codec *codec,
                type = ALC_CTL_BIND_MUTE;
                val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
        }
+       if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
+               return 0;
+       mark_ctl_usage(spec->sw_ctls, val);
        return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
 }
 
@@ -3134,12 +3164,16 @@ static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
        int err;
 
        if (!dac) {
+               unsigned int val;
                /* the corresponding DAC is already occupied */
                if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
                        return 0; /* no way */
                /* create a switch only */
-               return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
-                                  HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
+               val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
+               if (is_ctl_used(spec->sw_ctls, val))
+                       return 0; /* already created */
+               mark_ctl_usage(spec->sw_ctls, val);
+               return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
        }
 
        sw = alc_look_for_out_mute_nid(codec, pin, dac);
@@ -3184,8 +3218,12 @@ static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
        if (!num_pins || !pins[0])
                return 0;
 
-       if (num_pins == 1)
-               return alc_auto_create_extra_out(codec, *pins, *dacs, pfx);
+       if (num_pins == 1) {
+               hda_nid_t dac = *dacs;
+               if (!dac)
+                       dac = spec->multiout.dac_nids[0];
+               return alc_auto_create_extra_out(codec, *pins, dac, pfx);
+       }
 
        if (dacs[num_pins - 1]) {
                /* OK, we have a multi-output system with individual volumes */
@@ -3315,6 +3353,8 @@ static void alc_auto_init_extra_out(struct hda_codec *codec)
        hda_nid_t pin, dac;
 
        for (i = 0; i < spec->autocfg.hp_outs; i++) {
+               if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
+                       break;
                pin = spec->autocfg.hp_pins[i];
                if (!pin)
                        break;
@@ -3328,6 +3368,8 @@ static void alc_auto_init_extra_out(struct hda_codec *codec)
                alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
        }
        for (i = 0; i < spec->autocfg.speaker_outs; i++) {
+               if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
+                       break;
                pin = spec->autocfg.speaker_pins[i];
                if (!pin)
                        break;
@@ -4106,6 +4148,7 @@ enum {
        PINFIX_LENOVO_Y530,
        PINFIX_PB_M5210,
        PINFIX_ACER_ASPIRE_7736,
+       PINFIX_ASUS_W90V,
 };
 
 static const struct alc_fixup alc882_fixups[] = {
@@ -4137,10 +4180,18 @@ static const struct alc_fixup alc882_fixups[] = {
                .type = ALC_FIXUP_SKU,
                .v.sku = ALC_FIXUP_SKU_IGNORE,
        },
+       [PINFIX_ASUS_W90V] = {
+               .type = ALC_FIXUP_PINS,
+               .v.pins = (const struct alc_pincfg[]) {
+                       { 0x16, 0x99130110 }, /* fix sequence for CLFE */
+                       { }
+               }
+       },
 };
 
 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
        SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
+       SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
        SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
        SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
        SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
@@ -5774,6 +5825,8 @@ static const struct hda_codec_preset snd_hda_preset_realtek[] = {
          .patch = patch_alc882 },
        { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
          .patch = patch_alc662 },
+       { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
+         .patch = patch_alc662 },
        { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
        { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
        { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },