Merge branch 'fix/hda' into topic/hda
[pandora-kernel.git] / sound / pci / hda / patch_sigmatel.c
index 3457f61..742b9c8 100644 (file)
@@ -40,6 +40,7 @@ enum {
        STAC_INSERT_EVENT,
        STAC_PWR_EVENT,
        STAC_HP_EVENT,
+       STAC_LO_EVENT,
        STAC_MIC_EVENT,
 };
 
@@ -77,6 +78,7 @@ enum {
        STAC_92HD73XX_AUTO,
        STAC_92HD73XX_NO_JD, /* no jack-detection */
        STAC_92HD73XX_REF,
+       STAC_92HD73XX_INTEL,
        STAC_DELL_M6_AMIC,
        STAC_DELL_M6_DMIC,
        STAC_DELL_M6_BOTH,
@@ -358,14 +360,9 @@ static unsigned long stac92hd73xx_capvols[] = {
 };
 #define stac92hd73xx_capsws    stac92hd73xx_capvols
 
-#define STAC92HD83XXX_NUM_DMICS        2
-static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
-       0x11, 0x12, 0
-};
-
 #define STAC92HD83_DAC_COUNT 3
 
-static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
+static hda_nid_t stac92hd83xxx_mux_nids[2] = {
        0x17, 0x18,
 };
 
@@ -385,10 +382,6 @@ static unsigned int stac92hd83xxx_pwr_mapping[4] = {
        0x03, 0x0c, 0x20, 0x40,
 };
 
-static hda_nid_t stac92hd83xxx_amp_nids[1] = {
-       0xc,
-};
-
 #define STAC92HD83XXX_NUM_CAPS 2
 static unsigned long stac92hd83xxx_capvols[] = {
        HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
@@ -1211,26 +1204,6 @@ static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
 };
 
 
-static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
-       HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
-       HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
-       HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
-
-       HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
-       HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
-
-       /*
-       HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
-       */
-       { } /* end */
-};
-
 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
        STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
 };
@@ -1774,6 +1747,7 @@ static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
        [STAC_92HD73XX_AUTO] = "auto",
        [STAC_92HD73XX_NO_JD] = "no-jd",
        [STAC_92HD73XX_REF] = "ref",
+       [STAC_92HD73XX_INTEL] = "intel",
        [STAC_DELL_M6_AMIC] = "dell-m6-amic",
        [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
        [STAC_DELL_M6_BOTH] = "dell-m6",
@@ -1786,6 +1760,10 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
                                "DFI LanParty", STAC_92HD73XX_REF),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
                                "DFI LanParty", STAC_92HD73XX_REF),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
+                               "Intel DG45ID", STAC_92HD73XX_INTEL),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
+                               "Intel DG45FC", STAC_92HD73XX_INTEL),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
                                "Dell Studio 1535", STAC_DELL_M6_DMIC),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
@@ -1806,6 +1784,8 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
                                "Dell Studio 1537", STAC_DELL_M6_DMIC),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
                                "Dell Studio 17", STAC_DELL_M6_DMIC),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
+                               "Dell Studio 1555", STAC_DELL_M6_DMIC),
        {} /* terminator */
 };
 
@@ -1916,6 +1896,8 @@ static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
                      "HP mini 1000", STAC_HP_M4),
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
                      "HP HDX", STAC_HP_HDX),  /* HDX16 */
+       SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
+                     "HP", STAC_HP_DV5),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
                                "unknown Dell", STAC_DELL_M4_1),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
@@ -2261,7 +2243,7 @@ static struct snd_pci_quirk stac927x_cfg_tbl[] = {
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0227, "Dell Vostro 1400  ", STAC_DELL_BIOS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022e, "Dell     ", STAC_DELL_BIOS),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0242, "Dell     ", STAC_DELL_BIOS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0243, "Dell     ", STAC_DELL_BIOS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x02ff, "Dell     ", STAC_DELL_BIOS),
@@ -3320,11 +3302,11 @@ static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
 {
        int err;
        err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
-                                      "Captuer Volume", vol);
+                                      "Capture Volume", vol);
        if (err < 0)
                return err;
        err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
-                                      "Captuer Switch", sw);
+                                      "Capture Switch", sw);
        if (err < 0)
                return err;
        return 0;
@@ -3516,19 +3498,33 @@ static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec = codec->spec;
-       int wcaps, nid, i, err = 0;
+       int i, j, err = 0;
 
        for (i = 0; i < spec->num_muxes; i++) {
+               hda_nid_t nid;
+               unsigned int wcaps;
+               unsigned long val;
+
                nid = spec->mux_nids[i];
                wcaps = get_wcaps(codec, nid);
+               if (!(wcaps & AC_WCAP_OUT_AMP))
+                       continue;
 
-               if (wcaps & AC_WCAP_OUT_AMP) {
-                       err = stac92xx_add_control_idx(spec,
-                               STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
-                               HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
-                       if (err < 0)
-                               return err;
+               /* check whether already the same control was created as
+                * normal Capture Volume.
+                */
+               val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
+               for (j = 0; j < spec->num_caps; j++) {
+                       if (spec->capvols[j] == val)
+                               break;
                }
+               if (j < spec->num_caps)
+                       continue;
+
+               err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
+                                              "Mux Capture Volume", val);
+               if (err < 0)
+                       return err;
        }
        return 0;
 };
@@ -3583,6 +3579,24 @@ static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
        return -1;
 }
 
+/* create a volume assigned to the given pin (only if supported) */
+static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
+                                  const char *label)
+{
+       unsigned int caps, nums;
+       char name[32];
+
+       if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
+               return 0;
+       caps = query_amp_caps(codec, nid, HDA_OUTPUT);
+       nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
+       if (!nums)
+               return 0;
+       snprintf(name, sizeof(name), "%s Capture Volume", label);
+       return stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
+                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
+}
+
 /* create playback/capture controls for input pins on dmic capable codecs */
 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
                                                const struct auto_pin_cfg *cfg)
@@ -3592,7 +3606,6 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
        struct hda_input_mux *dimux = &spec->private_dimux;
        int err, i, active_mics;
        unsigned int def_conf;
-       char name[32];
 
        dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
        dimux->items[dimux->num_items].index = 0;
@@ -3600,6 +3613,10 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
 
        active_mics = 0;
        for (i = 0; i < spec->num_dmics; i++) {
+               /* check the validity: sometimes it's a dead vendor-spec node */
+               if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
+                   != AC_WID_PIN)
+                       continue;
                def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
                if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
                        active_mics++;
@@ -3608,14 +3625,15 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
        for (i = 0; i < spec->num_dmics; i++) {
                hda_nid_t nid;
                int index;
-               unsigned int wcaps;
                const char *label;
 
-               def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
+               nid = spec->dmic_nids[i];
+               if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
+                       continue;
+               def_conf = snd_hda_codec_get_pincfg(codec, nid);
                if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
                        continue;
 
-               nid = spec->dmic_nids[i];
                index = get_connection_index(codec, spec->dmux_nids[0], nid);
                if (index < 0)
                        continue;
@@ -3625,21 +3643,9 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
                else
                        label = stac92xx_dmic_labels[dimux->num_items];
 
-               wcaps = get_wcaps(codec, nid) &
-                       (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
-
-               if (wcaps) {
-                       sprintf(name, "%s Capture Volume", label);
-
-                       err = stac92xx_add_control(spec,
-                               STAC_CTL_WIDGET_VOL,
-                               name,
-                               HDA_COMPOSE_AMP_VAL(nid, 3, 0,
-                               (wcaps & AC_WCAP_OUT_AMP) ?
-                               HDA_OUTPUT : HDA_INPUT));
-                       if (err < 0)
-                               return err;
-               }
+               err = create_elem_capture_vol(codec, nid, label);
+               if (err < 0)
+                       return err;
 
                dimux->items[dimux->num_items].label = label;
                dimux->items[dimux->num_items].index = index;
@@ -3696,7 +3702,7 @@ static int set_mic_route(struct hda_codec *codec,
                if (i < 0)
                        return -1;
                mic->mux_idx = i;
-       }  else {
+       }  else if (spec->dmux_nids) {
                /* digital pin */
                mic->mux_idx = 0;
                i = get_connection_index(codec, spec->dmux_nids[0], pin);
@@ -3741,29 +3747,29 @@ static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const
 {
        struct sigmatel_spec *spec = codec->spec;
        struct hda_input_mux *imux = &spec->private_imux;
-       hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
-       int i, j, k;
+       int i, j;
 
        for (i = 0; i < AUTO_PIN_LAST; i++) {
-               int index;
+               hda_nid_t nid = cfg->input_pins[i];
+               int index, err;
 
-               if (!cfg->input_pins[i])
+               if (!nid)
                        continue;
                index = -1;
                for (j = 0; j < spec->num_muxes; j++) {
-                       int num_cons;
-                       num_cons = snd_hda_get_connections(codec,
-                                                          spec->mux_nids[j],
-                                                          con_lst,
-                                                          HDA_MAX_NUM_INPUTS);
-                       for (k = 0; k < num_cons; k++)
-                               if (con_lst[k] == cfg->input_pins[i]) {
-                                       index = k;
-                                       goto found;
-                               }
+                       index = get_connection_index(codec, spec->mux_nids[j],
+                                                    nid);
+                       if (index >= 0)
+                               break;
                }
-               continue;
-       found:
+               if (index < 0)
+                       continue;
+
+               err = create_elem_capture_vol(codec, nid,
+                                             auto_pin_cfg_labels[i]);
+               if (err < 0)
+                       return err;
+
                imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
                imux->items[imux->num_items].index = index;
                imux->num_items++;
@@ -4376,6 +4382,15 @@ static int stac92xx_init(struct hda_codec *codec)
                        hda_nid_t nid = cfg->hp_pins[i];
                        enable_pin_detect(codec, nid, STAC_HP_EVENT);
                }
+               if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
+                   cfg->speaker_outs > 0) {
+                       /* enable pin-detect for line-outs as well */
+                       for (i = 0; i < cfg->line_outs; i++) {
+                               hda_nid_t nid = cfg->line_out_pins[i];
+                               enable_pin_detect(codec, nid, STAC_LO_EVENT);
+                       }
+               }
+
                /* force to enable the first line-out; the others are set up
                 * in unsol_event
                 */
@@ -4391,7 +4406,8 @@ static int stac92xx_init(struct hda_codec *codec)
        }
        if (spec->auto_mic) {
                /* initialize connection to analog input */
-               snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
+               if (spec->dmux_nids)
+                       snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
                                          AC_VERB_SET_CONNECT_SEL, 0);
                if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
                        stac_issue_unsol_event(codec, spec->ext_mic.pin);
@@ -4574,6 +4590,48 @@ static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
        return 0;
 }
 
+static void stac92xx_line_out_detect(struct hda_codec *codec,
+                                    int presence)
+{
+       struct sigmatel_spec *spec = codec->spec;
+       struct auto_pin_cfg *cfg = &spec->autocfg;
+       int i;
+
+       for (i = 0; i < cfg->line_outs; i++) {
+               if (presence)
+                       break;
+               presence = get_pin_presence(codec, cfg->line_out_pins[i]);
+               if (presence) {
+                       unsigned int pinctl;
+                       pinctl = snd_hda_codec_read(codec,
+                                                   cfg->line_out_pins[i], 0,
+                                           AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
+                       if (pinctl & AC_PINCTL_IN_EN)
+                               presence = 0; /* mic- or line-input */
+               }
+       }
+
+       if (presence) {
+               /* disable speakers */
+               for (i = 0; i < cfg->speaker_outs; i++)
+                       stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
+                                               AC_PINCTL_OUT_EN);
+               if (spec->eapd_mask && spec->eapd_switch)
+                       stac_gpio_set(codec, spec->gpio_mask,
+                               spec->gpio_dir, spec->gpio_data &
+                               ~spec->eapd_mask);
+       } else {
+               /* enable speakers */
+               for (i = 0; i < cfg->speaker_outs; i++)
+                       stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
+                                               AC_PINCTL_OUT_EN);
+               if (spec->eapd_mask && spec->eapd_switch)
+                       stac_gpio_set(codec, spec->gpio_mask,
+                               spec->gpio_dir, spec->gpio_data |
+                               spec->eapd_mask);
+       }
+} 
+
 /* return non-zero if the hp-pin of the given array index isn't
  * a jack-detection target
  */
@@ -4626,13 +4684,6 @@ static void stac92xx_hp_detect(struct hda_codec *codec)
                for (i = 0; i < cfg->line_outs; i++)
                        stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
                                                AC_PINCTL_OUT_EN);
-               for (i = 0; i < cfg->speaker_outs; i++)
-                       stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
-                                               AC_PINCTL_OUT_EN);
-               if (spec->eapd_mask && spec->eapd_switch)
-                       stac_gpio_set(codec, spec->gpio_mask,
-                               spec->gpio_dir, spec->gpio_data &
-                               ~spec->eapd_mask);
        } else {
                /* enable lineouts */
                if (spec->hp_switch)
@@ -4641,14 +4692,8 @@ static void stac92xx_hp_detect(struct hda_codec *codec)
                for (i = 0; i < cfg->line_outs; i++)
                        stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
                                                AC_PINCTL_OUT_EN);
-               for (i = 0; i < cfg->speaker_outs; i++)
-                       stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
-                                               AC_PINCTL_OUT_EN);
-               if (spec->eapd_mask && spec->eapd_switch)
-                       stac_gpio_set(codec, spec->gpio_mask,
-                               spec->gpio_dir, spec->gpio_data |
-                               spec->eapd_mask);
        }
+       stac92xx_line_out_detect(codec, presence);
        /* toggle hp outs */
        for (i = 0; i < cfg->hp_outs; i++) {
                unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
@@ -4773,6 +4818,7 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
 
        switch (event->type) {
        case STAC_HP_EVENT:
+       case STAC_LO_EVENT:
                stac92xx_hp_detect(codec);
                break;
        case STAC_MIC_EVENT:
@@ -4782,6 +4828,7 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
 
        switch (event->type) {
        case STAC_HP_EVENT:
+       case STAC_LO_EVENT:
        case STAC_MIC_EVENT:
        case STAC_INSERT_EVENT:
        case STAC_PWR_EVENT:
@@ -5253,22 +5300,17 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
        codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
        spec->mono_nid = 0x19;
        spec->digbeep_nid = 0x21;
-       spec->dmic_nids = stac92hd83xxx_dmic_nids;
-       spec->dmux_nids = stac92hd83xxx_dmux_nids;
+       spec->mux_nids = stac92hd83xxx_mux_nids;
+       spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
        spec->adc_nids = stac92hd83xxx_adc_nids;
+       spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
        spec->pwr_nids = stac92hd83xxx_pwr_nids;
-       spec->amp_nids = stac92hd83xxx_amp_nids;
        spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
        spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
        spec->multiout.dac_nids = spec->dac_nids;
 
        spec->init = stac92hd83xxx_core_init;
-       spec->mixer = stac92hd83xxx_mixer;
        spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
-       spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
-       spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
-       spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
-       spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
        spec->pin_nids = stac92hd83xxx_pin_nids;
        spec->num_caps = STAC92HD83XXX_NUM_CAPS;
        spec->capvols = stac92hd83xxx_capvols;
@@ -5776,6 +5818,13 @@ static int patch_stac927x(struct hda_codec *codec)
                /* GPIO2 High = Enable EAPD */
                spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
                spec->gpio_data = 0x04;
+               switch (codec->subsystem_id) {
+               case 0x1028022f:
+                       /* correct EAPD to be GPIO0 */
+                       spec->eapd_mask = spec->gpio_mask = 0x01;
+                       spec->gpio_dir = spec->gpio_data = 0x01;
+                       break;
+               };
                spec->dmic_nids = stac927x_dmic_nids;
                spec->num_dmics = STAC927X_NUM_DMICS;