ALSA: hda - Release assigned pin/cvt at error path of hdmi_pcm_open()
[pandora-kernel.git] / sound / pci / hda / patch_hdmi.c
index 0fcfa6f..1b3b4ee 100644 (file)
@@ -431,9 +431,11 @@ static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
        if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
                snd_hda_codec_write(codec, pin_nid, 0,
                                AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
-       /* Disable pin out until stream is active*/
+       /* Enable pin out: some machines with GM965 gets broken output when
+        * the pin is disabled or changed while using with HDMI
+        */
        snd_hda_codec_write(codec, pin_nid, 0,
-                           AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
+                           AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
 }
 
 static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
@@ -1098,8 +1100,12 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
        if (!static_hdmi_pcm && eld->eld_valid) {
                snd_hdmi_eld_update_pcm_info(eld, hinfo);
                if (hinfo->channels_min > hinfo->channels_max ||
-                   !hinfo->rates || !hinfo->formats)
+                   !hinfo->rates || !hinfo->formats) {
+                       per_cvt->assigned = 0;
+                       hinfo->nid = 0;
+                       snd_hda_spdif_ctls_unassign(codec, pin_idx);
                        return -ENODEV;
+               }
        }
 
        /* Store the updated parameters */
@@ -1341,7 +1347,6 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
        struct hdmi_spec *spec = codec->spec;
        int pin_idx = hinfo_to_pin_index(spec, hinfo);
        hda_nid_t pin_nid = spec->pins[pin_idx].pin_nid;
-       int pinctl;
        bool non_pcm;
 
        non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
@@ -1350,11 +1355,6 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
 
        hdmi_setup_audio_infoframe(codec, pin_idx, non_pcm, substream);
 
-       pinctl = snd_hda_codec_read(codec, pin_nid, 0,
-                                   AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
-       snd_hda_codec_write(codec, pin_nid, 0,
-                           AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl | PIN_OUT);
-
        return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
 }
 
@@ -1374,7 +1374,6 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
        int cvt_idx, pin_idx;
        struct hdmi_spec_per_cvt *per_cvt;
        struct hdmi_spec_per_pin *per_pin;
-       int pinctl;
 
        if (hinfo->nid) {
                cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
@@ -1391,11 +1390,6 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
                        return -EINVAL;
                per_pin = &spec->pins[pin_idx];
 
-               pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
-                                           AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
-               snd_hda_codec_write(codec, per_pin->pin_nid, 0,
-                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
-                                   pinctl & ~PIN_OUT);
                snd_hda_spdif_ctls_unassign(codec, pin_idx);
                per_pin->chmap_set = false;
                memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
@@ -1512,7 +1506,7 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
        ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
        substream = snd_pcm_chmap_substream(info, ctl_idx);
        if (!substream || !substream->runtime)
-               return -EBADFD;
+               return 0; /* just for avoiding error from alsactl restore */
        switch (substream->runtime->status->state) {
        case SNDRV_PCM_STATE_OPEN:
        case SNDRV_PCM_STATE_SETUP:
@@ -1691,6 +1685,30 @@ static const struct hda_codec_ops generic_hdmi_patch_ops = {
        .unsol_event            = hdmi_unsol_event,
 };
 
+static void intel_haswell_fixup_connect_list(struct hda_codec *codec)
+{
+       unsigned int vendor_param;
+       hda_nid_t list[3] = {0x2, 0x3, 0x4};
+
+       vendor_param = snd_hda_codec_read(codec, 0x08, 0, 0xf81, 0);
+       if (vendor_param == -1 || vendor_param & 0x02)
+               return;
+
+       /* enable DP1.2 mode */
+       vendor_param |= 0x02;
+       snd_hda_codec_read(codec, 0x08, 0, 0x781, vendor_param);
+
+       vendor_param = snd_hda_codec_read(codec, 0x08, 0, 0xf81, 0);
+       if (vendor_param == -1 || !(vendor_param & 0x02))
+               return;
+
+       /* override 3 pins connection list */
+       snd_hda_override_conn_list(codec, 0x05, 3, list);
+       snd_hda_override_conn_list(codec, 0x06, 3, list);
+       snd_hda_override_conn_list(codec, 0x07, 3, list);
+}
+
+
 static int patch_generic_hdmi(struct hda_codec *codec)
 {
        struct hdmi_spec *spec;
@@ -1700,6 +1718,10 @@ static int patch_generic_hdmi(struct hda_codec *codec)
                return -ENOMEM;
 
        codec->spec = spec;
+
+       if (codec->vendor_id == 0x80862807)
+               intel_haswell_fixup_connect_list(codec);
+
        if (hdmi_parse_codec(codec) < 0) {
                codec->spec = NULL;
                kfree(spec);