Merge tag 'sound-3.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
[firefly-linux-kernel-4.4.55.git] / sound / pci / hda / patch_hdmi.c
index 9f35862768713899cad3ba865bb9d13b3cee796a..9a58893d52a7c6325a69837ccae7f049087747e1 100644 (file)
@@ -67,6 +67,8 @@ struct hdmi_spec_per_pin {
        struct delayed_work work;
        struct snd_kcontrol *eld_ctl;
        int repoll_count;
+       bool setup; /* the stream has been set up by prepare callback */
+       int channels; /* current number of channels */
        bool non_pcm;
        bool chmap_set;         /* channel-map override by ALSA API? */
        unsigned char chmap[8]; /* ALSA API channel-map */
@@ -551,6 +553,17 @@ static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
                }
        }
 
+       if (!ca) {
+               /* if there was no match, select the regular ALSA channel
+                * allocation with the matching number of channels */
+               for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
+                       if (channels == channel_allocations[i].channels) {
+                               ca = channel_allocations[i].ca_index;
+                               break;
+                       }
+               }
+       }
+
        snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf));
        snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
                    ca, channels, buf);
@@ -868,18 +881,19 @@ static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
        return true;
 }
 
-static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
-                                      bool non_pcm,
-                                      struct snd_pcm_substream *substream)
+static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
+                                      struct hdmi_spec_per_pin *per_pin,
+                                      bool non_pcm)
 {
-       struct hdmi_spec *spec = codec->spec;
-       struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
        hda_nid_t pin_nid = per_pin->pin_nid;
-       int channels = substream->runtime->channels;
+       int channels = per_pin->channels;
        struct hdmi_eld *eld;
        int ca;
        union audio_infoframe ai;
 
+       if (!channels)
+               return;
+
        eld = &per_pin->sink_eld;
        if (!eld->monitor_present)
                return;
@@ -959,6 +973,7 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
        int pin_nid;
        int pin_idx;
        struct hda_jack_tbl *jack;
+       int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
 
        jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
        if (!jack)
@@ -967,8 +982,8 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
        jack->jack_dirty = 1;
 
        _snd_printd(SND_PR_VERBOSE,
-               "HDMI hot plug event: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
-               codec->addr, pin_nid,
+               "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
+               codec->addr, pin_nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
                !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
 
        pin_idx = pin_nid_to_pin_index(spec, pin_nid);
@@ -1329,6 +1344,7 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
                eld_changed = true;
        }
        if (update_eld) {
+               bool old_eld_valid = pin_eld->eld_valid;
                pin_eld->eld_valid = eld->eld_valid;
                eld_changed = pin_eld->eld_size != eld->eld_size ||
                              memcmp(pin_eld->eld_buffer, eld->eld_buffer,
@@ -1338,6 +1354,18 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
                               eld->eld_size);
                pin_eld->eld_size = eld->eld_size;
                pin_eld->info = eld->info;
+
+               /* Haswell-specific workaround: re-setup when the transcoder is
+                * changed during the stream playback
+                */
+               if (codec->vendor_id == 0x80862807 &&
+                   eld->eld_valid && !old_eld_valid && per_pin->setup) {
+                       snd_hda_codec_write(codec, pin_nid, 0,
+                                           AC_VERB_SET_AMP_GAIN_MUTE,
+                                           AMP_OUT_UNMUTE);
+                       hdmi_setup_audio_infoframe(codec, per_pin,
+                                                  per_pin->non_pcm);
+               }
        }
        mutex_unlock(&pin_eld->lock);
 
@@ -1510,14 +1538,17 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
        hda_nid_t cvt_nid = hinfo->nid;
        struct hdmi_spec *spec = codec->spec;
        int pin_idx = hinfo_to_pin_index(spec, hinfo);
-       hda_nid_t pin_nid = get_pin(spec, pin_idx)->pin_nid;
+       struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
+       hda_nid_t pin_nid = per_pin->pin_nid;
        bool non_pcm;
 
        non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
+       per_pin->channels = substream->runtime->channels;
+       per_pin->setup = true;
 
        hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
 
-       hdmi_setup_audio_infoframe(codec, pin_idx, non_pcm, substream);
+       hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
 
        return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
 }
@@ -1557,6 +1588,9 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
                snd_hda_spdif_ctls_unassign(codec, pin_idx);
                per_pin->chmap_set = false;
                memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
+
+               per_pin->setup = false;
+               per_pin->channels = 0;
        }
 
        return 0;
@@ -1692,8 +1726,7 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
        per_pin->chmap_set = true;
        memcpy(per_pin->chmap, chmap, sizeof(chmap));
        if (prepared)
-               hdmi_setup_audio_infoframe(codec, pin_idx, per_pin->non_pcm,
-                                          substream);
+               hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
 
        return 0;
 }
@@ -1992,8 +2025,10 @@ static int patch_generic_hdmi(struct hda_codec *codec)
                return -EINVAL;
        }
        codec->patch_ops = generic_hdmi_patch_ops;
-       if (codec->vendor_id == 0x80862807)
+       if (codec->vendor_id == 0x80862807) {
                codec->patch_ops.set_power_state = haswell_set_power_state;
+               codec->dp_mst = true;
+       }
 
        generic_hdmi_init_per_pins(codec);