ALSA: hda - Re-setup HDMI pin and audio infoframe on stream switches
PATCH 1/1 ALSA: hda - Re-setup HDMI pin and audio infoframe on stream switches
When the transcoder:port mapping on Haswell HDMI/DP audio is changed during the stream playback, the sound gets lost. Typically this problem is seen when the user switches the graphics mode from eDP+DP to DP-only configuration, where CRTC 1 is used for DP in the former while CRTC 0 is used for the latter.
The graphics controller notifies the change via the normal ELD update procedure, so we get the intrinsic event. For enabling the sound again, the HDMI audio driver needs to reset the pin and set up the audio infoframe again.
This patch achieves it by:
- keep the current status of channels and info frame setup in per_pin struct,
- check the reconnection in the intrinsic event handler,
- reset the pin and the re-invoke hdmi_setup_audio_infoframe() accordingly.
The hdmi_setup_audio_infoframe() function has been changed, too, so that it can be invoked without passing the substream instance.
The patch is mostly based on the work by Mengdong Lin.
--- sound/pci/hda/patch_hdmi.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)
sound/pci/hda/patch_hdmi.c +31 -10
@@ -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 */
@@ -879,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 ;
@@ -1341,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,
@@ -1350,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);
@@ -1522,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); }
@@ -1569,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 ;
@@ -1704,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 ; }
Signature · 1 line
1.8.3.4
Quoted 10 lines · Takashi Iwai
When the transcoder:port mapping on Haswell HDMI/DP audio is changed during the stream playback, the sound gets lost. Typically this problem is seen when the user switches the graphics mode from eDP+DP to DP-only configuration, where CRTC 1 is used for DP in the former while CRTC 0 is used for the latter.
The graphics controller notifies the change via the normal ELD update procedure, so we get the intrinsic event. For enabling the sound again, the HDMI audio driver needs to reset the pin and set up the audio infoframe again.
Thanks for working on this!
See a review comment below.
Quoted 70 lines
This patch achieves it by:
- keep the current status of channels and info frame setup inper_pinstruct,
- check the reconnection in the intrinsic event handler,
- reset the pin and the re-invokehdmi_setup_audio_infoframe()accordingly.The
hdmi_setup_audio_infoframe()function has been changed, too, so that it can be invoked without passing the substream instance.The patch is mostly based on the work by Mengdong Lin.
Cc Mengdong Lin <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- sound/pci/hda/patch_hdmi.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)sound/pci/hda/patch_hdmi.c +10
-6@@ -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 */ @@ -879,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 ;@@ -1341,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,@@ -1350,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;
sound/pci/hda/patch_hdmi.c static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) · line 1365
Quoted 10 lines
sound/pci/hda/patch_hdmi.c +9
-0pin_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 );
If the system is deliberately muted by turning off "IEC958 Playback Switch", are we now ignoring that and turning it back on?
Also, this looks a bit like the workaround I added a while back (83f26ad2c909083fa6 - ALSA: hda - fixup D3 pin and right channel mute on Haswell HDMI audio) is there a possibility we need to fix up D3 as well here? I e, call haswell_verify_pin_D0 rather than just setting the mute? Or perhaps move the call to haswell_verify_pin_D0 from hdmi_setup_stream to hdme_setup_audio_infoframe ?
Quoted 47 lines
sound/pci/hda/patch_hdmi.c +12
-4+hdmi_setup_audio_infoframe (codec, per_pin, + per_pin->non_pcm); + } }mutex_unlock (&pin_eld->lock);@@ -1522,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); }@@ -1569,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 ;@@ -1704,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 ; }
Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic
At Tue, 03 Sep 2013 13:10:43 +0200,
Quoted 92 lines · David Henningsson
Quoted 10 lines · Takashi Iwai
When the transcoder:port mapping on Haswell HDMI/DP audio is changed during the stream playback, the sound gets lost. Typically this problem is seen when the user switches the graphics mode from eDP+DP to DP-only configuration, where CRTC 1 is used for DP in the former while CRTC 0 is used for the latter.
The graphics controller notifies the change via the normal ELD update procedure, so we get the intrinsic event. For enabling the sound again, the HDMI audio driver needs to reset the pin and set up the audio infoframe again.
Thanks for working on this!
See a review comment below.
Quoted 75 lines
This patch achieves it by:
- keep the current status of channels and info frame setup inper_pinstruct,
- check the reconnection in the intrinsic event handler,
- reset the pin and the re-invokehdmi_setup_audio_infoframe()accordingly.The
hdmi_setup_audio_infoframe()function has been changed, too, so that it can be invoked without passing the substream instance.The patch is mostly based on the work by Mengdong Lin.
Cc Mengdong Lin <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- sound/pci/hda/patch_hdmi.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)sound/pci/hda/patch_hdmi.c +14
-6@@ -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 */ @@ -879,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 ;@@ -1341,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,@@ -1350,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 +*/
Quoted 8 lines
sound/pci/hda/patch_hdmi.c static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) · line 1365
Quoted 5 lines
sound/pci/hda/patch_hdmi.c +5
-0+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 );If the system is deliberately muted by turning off "IEC958 Playback Switch", are we now ignoring that and turning it back on?
The pin amp is always unmuted. The IEC958 Playback Switch is controlled via IEC958 status bits instead.
Quoted 6 lines
Also, this looks a bit like the workaround I added a while back (
83f26ad2c909083fa6- ALSA: hda - fixup D3 pin and right channel mute on Haswell HDMI audio) is there a possibility we need to fix up D3 as well here? I e, callhaswell_verify_pin_D0rather than just setting the mute? Or perhaps move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdme_setup_audio_infoframe?
The power state is fine in this case, but just to reset the amp state by some reason. It's not enough to update the info frame, as far as I tested.
thanks,
Takashi
Quoted 103 lines · Takashi Iwai
At Tue, 03 Sep 2013 13:10:43 +0200,
Quoted 92 lines · David Henningsson
Quoted 10 lines · Takashi Iwai
When the transcoder:port mapping on Haswell HDMI/DP audio is changed during the stream playback, the sound gets lost. Typically this problem is seen when the user switches the graphics mode from eDP+DP to DP-only configuration, where CRTC 1 is used for DP in the former while CRTC 0 is used for the latter.
The graphics controller notifies the change via the normal ELD update procedure, so we get the intrinsic event. For enabling the sound again, the HDMI audio driver needs to reset the pin and set up the audio infoframe again.
Thanks for working on this!
See a review comment below.
Quoted 75 lines
This patch achieves it by:
- keep the current status of channels and info frame setup inper_pinstruct,
- check the reconnection in the intrinsic event handler,
- reset the pin and the re-invokehdmi_setup_audio_infoframe()accordingly.The
hdmi_setup_audio_infoframe()function has been changed, too, so that it can be invoked without passing the substream instance.The patch is mostly based on the work by Mengdong Lin.
Cc Mengdong Lin <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- sound/pci/hda/patch_hdmi.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)sound/pci/hda/patch_hdmi.c +14
-6@@ -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 */ @@ -879,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 ;@@ -1341,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,@@ -1350,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 +*/ Quoted 8 lines
sound/pci/hda/patch_hdmi.c static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) · line 1365
Quoted 5 lines
sound/pci/hda/patch_hdmi.c +5
-0+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 );If the system is deliberately muted by turning off "IEC958 Playback Switch", are we now ignoring that and turning it back on?
Quoted 2 lines
The pin amp is always unmuted. The IEC958 Playback Switch is controlled via IEC958 status bits instead.
Ok.
Quoted 11 lines
Quoted 7 lines
Also, this looks a bit like the workaround I added a while back (
83f26ad2c909083fa6- ALSA: hda - fixup D3 pin and right channel mute on Haswell HDMI audio) is there a possibility we need to fix up D3 as well here? I e, callhaswell_verify_pin_D0rather than just setting the mute? Or perhaps move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdme_setup_audio_infoframe?The power state is fine in this case, but just to reset the amp state by some reason. It's not enough to update the info frame, as far as I tested.
Ok - maybe Mengdong can comment more on this, if it's the same scenario as I was working around earlier (right channel muted and pin in D3), or if this is something different.
If it's the same issue, I was thinking that we could
1) skip the extra snd_hda_codec_write here, and
2) move the call to haswell_verify_pin_D0 from hdmi_setup_stream tohdmi_setup_audio_infoframe?
Also, if the pin amp is always unmuted, we could speed up haswell_verify_pin_D0 to always unmute instead of read-then-write.
Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic
At Tue, 03 Sep 2013 14:36:13 +0200,
Quoted 122 lines · David Henningsson
Quoted 103 lines · Takashi Iwai
At Tue, 03 Sep 2013 13:10:43 +0200,
Quoted 92 lines · David Henningsson
Quoted 10 lines · Takashi Iwai
When the transcoder:port mapping on Haswell HDMI/DP audio is changed during the stream playback, the sound gets lost. Typically this problem is seen when the user switches the graphics mode from eDP+DP to DP-only configuration, where CRTC 1 is used for DP in the former while CRTC 0 is used for the latter.
The graphics controller notifies the change via the normal ELD update procedure, so we get the intrinsic event. For enabling the sound again, the HDMI audio driver needs to reset the pin and set up the audio infoframe again.
Thanks for working on this!
See a review comment below.
Quoted 75 lines
This patch achieves it by:
- keep the current status of channels and info frame setup inper_pinstruct,
- check the reconnection in the intrinsic event handler,
- reset the pin and the re-invokehdmi_setup_audio_infoframe()accordingly.The
hdmi_setup_audio_infoframe()function has been changed, too, so that it can be invoked without passing the substream instance.The patch is mostly based on the work by Mengdong Lin.
Cc Mengdong Lin <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- sound/pci/hda/patch_hdmi.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)sound/pci/hda/patch_hdmi.c +14
-6@@ -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 */ @@ -879,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 ;@@ -1341,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,@@ -1350,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 +*/ Quoted 8 lines
sound/pci/hda/patch_hdmi.c static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) · line 1365
Quoted 5 lines
sound/pci/hda/patch_hdmi.c +5
-0+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 );If the system is deliberately muted by turning off "IEC958 Playback Switch", are we now ignoring that and turning it back on?
Quoted 2 lines
The pin amp is always unmuted. The IEC958 Playback Switch is controlled via IEC958 status bits instead.
Ok.
Quoted 11 lines
Quoted 7 lines
Also, this looks a bit like the workaround I added a while back (
83f26ad2c909083fa6- ALSA: hda - fixup D3 pin and right channel mute on Haswell HDMI audio) is there a possibility we need to fix up D3 as well here? I e, callhaswell_verify_pin_D0rather than just setting the mute? Or perhaps move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdme_setup_audio_infoframe?The power state is fine in this case, but just to reset the amp state by some reason. It's not enough to update the info frame, as far as I tested.
Quoted 8 lines
Ok - maybe Mengdong can comment more on this, if it's the same scenario as I was working around earlier (right channel muted and pin in D3), or if this is something different.
If it's the same issue, I was thinking that we could
1) skip the extrasnd_hda_codec_writehere, and
2) move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdmi_setup_audio_infoframe?
That makes sense. Though, I'd like to merge the working patch now and improve later on, as it's already in 3.12 merge window now.
Quoted 2 lines
Also, if the pin amp is always unmuted, we could speed up
haswell_verify_pin_D0to always unmute instead of read-then-write.
Yes.
Takashi
Quoted 128 lines · Takashi Iwai
At Tue, 03 Sep 2013 14:36:13 +0200,
Quoted 126 lines · David Henningsson
Quoted 103 lines · Takashi Iwai
At Tue, 03 Sep 2013 13:10:43 +0200,
Quoted 92 lines · David Henningsson
Quoted 10 lines · Takashi Iwai
When the transcoder:port mapping on Haswell HDMI/DP audio is changed during the stream playback, the sound gets lost. Typically this problem is seen when the user switches the graphics mode from eDP+DP to DP-only configuration, where CRTC 1 is used for DP in the former while CRTC 0 is used for the latter.
The graphics controller notifies the change via the normal ELD update procedure, so we get the intrinsic event. For enabling the sound again, the HDMI audio driver needs to reset the pin and set up the audio infoframe again.
Thanks for working on this!
See a review comment below.
Quoted 75 lines
This patch achieves it by:
- keep the current status of channels and info frame setup inper_pinstruct,
- check the reconnection in the intrinsic event handler,
- reset the pin and the re-invokehdmi_setup_audio_infoframe()accordingly.The
hdmi_setup_audio_infoframe()function has been changed, too, so that it can be invoked without passing the substream instance.The patch is mostly based on the work by Mengdong Lin.
Cc Mengdong Lin <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- sound/pci/hda/patch_hdmi.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)sound/pci/hda/patch_hdmi.c +14
-6@@ -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 */ @@ -879,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 ;@@ -1341,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,@@ -1350,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 +*/ Quoted 8 lines
sound/pci/hda/patch_hdmi.c static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) · line 1365
Quoted 5 lines
sound/pci/hda/patch_hdmi.c +5
-0+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 );If the system is deliberately muted by turning off "IEC958 Playback Switch", are we now ignoring that and turning it back on?
Quoted 2 lines
The pin amp is always unmuted. The IEC958 Playback Switch is controlled via IEC958 status bits instead.
Ok.
Quoted 11 lines
Quoted 7 lines
Also, this looks a bit like the workaround I added a while back (
83f26ad2c909083fa6- ALSA: hda - fixup D3 pin and right channel mute on Haswell HDMI audio) is there a possibility we need to fix up D3 as well here? I e, callhaswell_verify_pin_D0rather than just setting the mute? Or perhaps move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdme_setup_audio_infoframe?The power state is fine in this case, but just to reset the amp state by some reason. It's not enough to update the info frame, as far as I tested.
Ok - maybe Mengdong can comment more on this, if it's the same scenario as I was working around earlier (right channel muted and pin in D3), or if this is something different.
Quoted 7 lines
Quoted 4 lines
If it's the same issue, I was thinking that we could
1) skip the extrasnd_hda_codec_writehere, and
2) move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdmi_setup_audio_infoframe?That makes sense. Though, I'd like to merge the working patch now and improve later on, as it's already in 3.12 merge window now.
Sure, no problem.
Quoted 9 lines
Quoted 3 lines
Also, if the pin amp is always unmuted, we could speed up
haswell_verify_pin_D0to always unmute instead of read-then-write.Yes.
Takashi
Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic
Hi David and Takashi,
Quoted 12 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of David Henningsson
Sent: Tuesday, September 03, 2013 8:36 PMQuoted 7 lines
Quoted 6 lines
Also, this looks a bit like the workaround I added a while back (
83f26ad2c909083fa6- ALSA: hda - fixup D3 pin and right channel mute on Haswell HDMI audio) is there a possibility we need to fix up D3 as well here? I e, callhaswell_verify_pin_D0rather than just setting the mute? Or perhaps move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdme_setup_audio_infoframe?
Quoted 7 lines
Quoted 3 lines
The power state is fine in this case, but just to reset the amp state by some reason. It's not enough to update the info frame, as far as I tested.
Ok - maybe Mengdong can comment more on this, if it's the same scenario as I was working around earlier (right channel muted and pin in D3), or if this is something different.
They're same in nature, although the pin power state can be affected or not.
S3, hot-plug and Gfx mode switch can all make Gfx reconnect the port, maybe to the same or a different transcoder. During this process , audio will be disabled and re-enabled again in Gfx driver side.
As a result, pin mute status, inforframe transmission, power state need to be re-setup.
Till now, we only observed pin in D3 after boot. But considering Gfx is implement runtime PM, it would be better to always check/fix pin power state.
Since the ELD valid unsolicited response is a signal to indicate Gfx driver has finished audio re-enabling, the audio driver could fix things in hdmi_present_sense() triggered by the HDMI intrinsic event handler.
Quoted 8 lines
If it's the same issue, I was thinking that we could
1) skip the extrasnd_hda_codec_writehere, and
2) move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdmi_setup_audio_infoframe?Also, if the pin amp is always unmuted, we could speed up
haswell_verify_pin_D0to always unmute instead of read-then-write.
I'll try to merge the Haswell fixing into hdmi_present_sense() and verify it today.
BTW, I've asked Canonical test engineers through Lauchpad to verify current patch.
Thanks
Mengdong
Quoted 29 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Lin, Mengdong
Sent: Wednesday, September 04, 2013 9:30 AMQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Also, this looks a bit like the workaround I added a while back (
83f26ad2c909083fa6- ALSA: hda - fixup D3 pin and right channel mute on Haswell HDMI audio) is there a possibility we need to fix up D3 as well here? I e, callhaswell_verify_pin_D0rather than just settingthe mute?
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
Or perhaps move the call to
haswell_verify_pin_D0fromhdmi_setup_streamtohdme_setup_audio_infoframe?The power state is fine in this case, but just to reset the amp state by some reason. It's not enough to update the info frame, as far as I tested.
Ok - maybe Mengdong can comment more on this, if it's the same scenario as I was working around earlier (right channel muted and pin in D3), or if this is something different.
They're same in nature, although the pin power state can be affected or not. S3, hot-plug and Gfx mode switch can all make Gfx reconnect the port, maybe to the same or a different transcoder.
During this process , audio will be disabled and re-enabled again in Gfx driver side.
As a result, pin mute status, inforframe transmission, power state need to be re-setup.
Quoted 2 lines
Till now, we only observed pin in D3 after boot. But considering Gfx is implement runtime PM, it would be better to always check/fix pin power state.
Fix typo: We only observe pin in D3 after boot and S3, i.e. the pin (port) is used for 1st time after GPU change state to D0. In this display mode switch case, the pin power state remains in D0, although Gfx driver disables and re-enables the port.
Quoted 11 lines
Since the ELD valid unsolicited response is a signal to indicate Gfx driver has finished audio re-enabling, the audio driver could fix things in
hdmi_present_sense()triggered by the HDMI intrinsic event handler.Quoted 8 lines
If it's the same issue, I was thinking that we could
1) skip the extrasnd_hda_codec_writehere, and
2) move the call tohaswell_verify_pin_D0fromhdmi_setup_streamtohdmi_setup_audio_infoframe?Also, if the pin amp is always unmuted, we could speed up
haswell_verify_pin_D0to always unmute instead of read-then-write.
I've submitted a patch for this, with subject 'ALSA: hda - unmute pin amplifier in infoframe setup for Haswell'. Could you have a look?
But haswell_verify_pin_D0 is still called in hdmi_setup_stream() and only unmuting pin amp is moved to hdmi_setup_audio_infoframe(). It's because ELDV unsol event may come in codec D3, and pin should not be set to D0 in the event handler for this case. So the new patch still fixes pin power state when preparing the stream.
Thanks
Mengdong