ALSA: hda: fix jack detection with Realtek codecs when in D3
PATCH 1/1 ALSA: hda: fix jack detection with Realtek codecs when in D3
In case HDA controller is active, but codec is runtime suspended, jack detection is not successful and no interrupt is raised. This has been observed with multiple Realtek codecs and HDA controllers from different vendors. Bug does not occur if both codec and controller are active, or both are in suspend. Bug can be easily hit on desktop systems with no built-in speaker.
The problem can be fixed by powering up the codec once after every controller runtime resume. Even if codec goes back to suspend, the jack detection will now work. Add a flag to 'hda_codec' to describe codecs that require this flow from the controller driver. Mark all Realtek codecs with this flag.
--- include/sound/hda_codec.h | 1 + sound/pci/hda/hda_intel.c | 8 ++++++-- sound/pci/hda/patch_realtek.c | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-)
include/sound/hda_codec.h +1 -0
@@ -253,6 +253,7 @@ struct hda_codec { unsigned int force_pin_prefix:1; /* Add location prefix */ unsigned int link_down_at_suspend:1; /* link down at runtime suspend */ unsigned int relaxed_resume:1; /* don't resume forcibly for jack */ + unsigned int forced_resume:1; /* forced resume for jack */ unsigned int mst_no_extra_pcms:1; /* no backup PCMs for DP-MST */#ifdef CONFIG_PM
sound/pci/hda/hda_intel.c +6 -2
@@ -1002,12 +1002,16 @@ static void __azx_runtime_resume(struct azx *chip, bool from_rt)azx_init_pci (chip);hda_intel_init_chip (chip, true); -if (status && from_rt) { -list_for_each_codec (codec, &chip->bus) +if (from_rt) { +list_for_each_codec (codec, &chip->bus) { +if (codec->forced_resume &&pm_runtime_suspended (hda_codec_dev (codec))) +pm_request_resume (hda_codec_dev (codec)); +if (!codec->relaxed_resume && (status & (1 << codec->addr)))schedule_delayed_work (&codec->jackpoll_work, codec->jackpoll_interval); + } }/* power down again for link-controlled chips */
sound/pci/hda/patch_realtek.c +6 -0
@@ -849,6 +849,12 @@ static int alc_build_controls(struct hda_codec *codec)static void alc_pre_init (struct hda_codec *codec) {alc_fill_eapd_coef (codec); + +/* +* if controller is resumed from suspend, while codec remains in D3, codec +* needs to be woken up once or otherwise jack detection does not work +*/ + codec->forced_resume =1 ; }#define is_s3_resume (codec) \
Signature · 1 line
2.28.0
Quoted 48 lines · Kai Vehmanen
In case HDA controller is active, but codec is runtime suspended, jack detection is not successful and no interrupt is raised. This has been observed with multiple Realtek codecs and HDA controllers from different vendors. Bug does not occur if both codec and controller are active, or both are in suspend. Bug can be easily hit on desktop systems with no built-in speaker.
The problem can be fixed by powering up the codec once after every controller runtime resume. Even if codec goes back to suspend, the jack detection will now work. Add a flag to '
hda_codec' to describe codecs that require this flow from the controller driver. Mark all Realtek codecs with this flag.Cc Kailang Yang <[email protected]>Co-developed-by Kai-Heng Feng <[email protected]>Signed-off-by Kai-Heng Feng <[email protected]>Signed-off-by Kai Vehmanen <[email protected]>--- include/sound/hda_codec.h | 1 + sound/pci/hda/hda_intel.c | 8 ++++++-- sound/pci/hda/patch_realtek.c | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-)include/sound/hda_codec.h +1
-0@@ -253,6 +253,7 @@ struct hda_codec { unsigned int force_pin_prefix:1; /* Add location prefix */ unsigned int link_down_at_suspend:1; /* link down at runtime suspend */ unsigned int relaxed_resume:1; /* don't resume forcibly for jack */ + unsigned int forced_resume:1; /* forced resume for jack */ unsigned int mst_no_extra_pcms:1; /* no backup PCMs for DP-MST */#ifdef CONFIG_PM sound/pci/hda/hda_intel.c +1
-2@@ -1002,12 +1002,16 @@ static void __azx_runtime_resume(struct azx *chip, bool from_rt)azx_init_pci (chip);hda_intel_init_chip (chip, true); -if (status && from_rt) { -list_for_each_codec (codec, &chip->bus) +if (from_rt) {
sound/pci/hda/hda_intel.c static void __azx_runtime_resume(struct azx *chip, bool from_rt) · line 1015
Quoted 10 lines
sound/pci/hda/hda_intel.c +5
-0+list_for_each_codec (codec, &chip->bus) { +if (codec->forced_resume &&pm_runtime_suspended (hda_codec_dev (codec))) +pm_request_resume (hda_codec_dev (codec)); +if (!codec->relaxed_resume && (status & (1 << codec->addr)))schedule_delayed_work (&codec->jackpoll_work, codec->jackpoll_interval); + } }
Basically both pm_request_resume() and the jackpoll_work do the equivalent task, hence no need to do twice differently. Actually pm_request_resume() looks like a better choice as it's clearer about what it does, so let's replace with it.
Also, the pm_runtime_suspend() can be skipped here; the codec must have been suspended at this moment because of the pm-dependency.
So, it'll be like:
if (from_rt) {
list_for_each_codec(codec, &chip->bus) {
if (codec->relaxed_resume)
continue;
if (codec->forced_resume ||
(status & (1 << codec->addr)))
pm_request_resume(hda_codec_dev(codec));
}
}Could you check whether this still works?
thanks,
Takashi
Hi,
Quoted 11 lines · Takashi Iwai
Quoted 10 lines · Kai Vehmanen
sound/pci/hda/hda_intel.c +5
-2-if (status && from_rt) { -list_for_each_codec (codec, &chip->bus) +if (from_rt) { +list_for_each_codec (codec, &chip->bus) { +if (codec->forced_resume &&pm_runtime_suspended (hda_codec_dev (codec))) +pm_request_resume (hda_codec_dev (codec)); +if (!codec->relaxed_resume && (status & (1 << codec->addr))) schedule_delayed_work(&codec->jackpoll_work,
Quoted 8 lines
sound/pci/hda/hda_intel.c static void __azx_runtime_resume(struct azx *chip, bool from_rt) · line 1015
Quoted 3 lines
sound/pci/hda/hda_intel.c +1
-0codec->jackpoll_interval); + } }Basically both
pm_request_resume()and thejackpoll_workdo the equivalent task, hence no need to do twice differently. Actuallypm_request_resume()looks like a better choice as it's clearer about what it does, so let's replace with it.
ack. I was unsure whether the other actions in jackpoll_work would be needed in some case (when jackpoll_interval>0), but I guess if interval is non-zero, the workqueue is kicked from the codec driver, so no need to do it here. Will change.
Quoted 2 lines
Also, the
pm_runtime_suspend()can be skipped here; the codec must have been suspended at this moment because of the pm-dependency.
Oh, true, you are right.
Quoted 11 lines
So, it'll be like:
if (from_rt) { list_for_each_codec(codec, &chip->bus) { if (codec->relaxed_resume) continue; if (codec->forced_resume || (status & (1 << codec->addr))) pm_request_resume(hda_codec_dev(codec)); } }
[..]
Quoted 1 line
Could you check whether this still works?
Sure, not necessarily today, but I'll get back with the test results.
PS And Pierre, indeed it is sufficient to just power the codec on.
Even if it then goes back to suspend, jack detection still works. And if controller never goes to suspend, then there's no problem either. I'll update the commit message for v2.
Br, Kai
Quoted 7 lines · Kai Vehmanen
In case HDA controller is active, but codec is runtime suspended, jack detection is not successful and no interrupt is raised. This has been observed with multiple Realtek codecs and HDA controllers from different vendors. Bug does not occur if both codec and controller are active, or both are in suspend. Bug can be easily hit on desktop systems with no built-in speaker.
Quoted 5 lines
The problem can be fixed by powering up the codec once after every controller runtime resume. Even if codec goes back to suspend, the jack detection will now work. Add a flag to '
hda_codec' to describe codecs that require this flow from the controller driver. Mark all Realtek codecs with this flag.
It does make sense to request the codec to resume when the controller resumes, we did the same for SoundWire IIRC.
I am still confused on what happens if e.g. the controller resumes and remains active, e.g. capturing from the DMIC. The codec would become suspended after a while and then we would be back to the same problem, wouldn't we?
Or are you saying that this initial resume of the codec is enough?
Quoted 65 lines
Cc Kailang Yang <[email protected]>Co-developed-by Kai-Heng Feng <[email protected]>Signed-off-by Kai-Heng Feng <[email protected]>Signed-off-by Kai Vehmanen <[email protected]>--- include/sound/hda_codec.h | 1 + sound/pci/hda/hda_intel.c | 8 ++++++-- sound/pci/hda/patch_realtek.c | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-)include/sound/hda_codec.h +1
-0@@ -253,6 +253,7 @@ struct hda_codec { unsigned int force_pin_prefix:1; /* Add location prefix */ unsigned int link_down_at_suspend:1; /* link down at runtime suspend */ unsigned int relaxed_resume:1; /* don't resume forcibly for jack */ + unsigned int forced_resume:1; /* forced resume for jack */ unsigned int mst_no_extra_pcms:1; /* no backup PCMs for DP-MST */#ifdef CONFIG_PM sound/pci/hda/hda_intel.c +6
-2@@ -1002,12 +1002,16 @@ static void __azx_runtime_resume(struct azx *chip, bool from_rt)azx_init_pci (chip);hda_intel_init_chip (chip, true); -if (status && from_rt) { -list_for_each_codec (codec, &chip->bus) +if (from_rt) { +list_for_each_codec (codec, &chip->bus) { +if (codec->forced_resume &&pm_runtime_suspended (hda_codec_dev (codec))) +pm_request_resume (hda_codec_dev (codec)); +if (!codec->relaxed_resume && (status & (1 << codec->addr)))schedule_delayed_work (&codec->jackpoll_work, codec->jackpoll_interval); + } }/* power down again for link-controlled chips */ sound/pci/hda/patch_realtek.c +6
-0@@ -849,6 +849,12 @@ static int alc_build_controls(struct hda_codec *codec)static void alc_pre_init (struct hda_codec *codec) {alc_fill_eapd_coef (codec); + +/* +* if controller is resumed from suspend, while codec remains in D3, codec +* needs to be woken up once or otherwise jack detection does not work +*/ + codec->forced_resume =1 ; }#define is_s3_resume (codec) \
Quoted 20 lines · Pierre-Louis Bossart
Quoted 7 lines · Kai Vehmanen
In case HDA controller is active, but codec is runtime suspended, jack detection is not successful and no interrupt is raised. This has been observed with multiple Realtek codecs and HDA controllers from different vendors. Bug does not occur if both codec and controller are active, or both are in suspend. Bug can be easily hit on desktop systems with no built-in speaker.
Quoted 5 lines
The problem can be fixed by powering up the codec once after every controller runtime resume. Even if codec goes back to suspend, the jack detection will now work. Add a flag to '
hda_codec' to describe codecs that require this flow from the controller driver. Mark all Realtek codecs with this flag.It does make sense to request the codec to resume when the controller resumes, we did the same for SoundWire IIRC.
Quoted 6 lines
I am still confused on what happens if e.g. the controller resumes and remains active, e.g. capturing from the DMIC. The codec would become suspended after a while and then we would be back to the same problem, wouldn't we?
Or are you saying that this initial resume of the codec is enough?
When the controller is active and the codec goes to runtime suspend, the codec will be woken up via the unsolicited event per jack change. So it seems that the problem is only about the wake up from the controller's runtime suspend.
thanks,
Takashi
Quoted 23 lines
Quoted 23 lines · Kai Vehmanen
Quoted 7 lines
In case HDA controller is active, but codec is runtime suspended, jack detection is not successful and no interrupt is raised. This has been observed with multiple Realtek codecs and HDA controllers from different vendors. Bug does not occur if both codec and controller are active, or both are in suspend. Bug can be easily hit on desktop systems with no built-in speaker.
Quoted 5 lines
The problem can be fixed by powering up the codec once after every controller runtime resume. Even if codec goes back to suspend, the jack detection will now work. Add a flag to '
hda_codec' to describe codecs that require this flow from the controller driver. Mark all Realtek codecs with this flag.It does make sense to request the codec to resume when the controller resumes, we did the same for SoundWire IIRC.
I am still confused on what happens if e.g. the controller resumes and remains active, e.g. capturing from the DMIC. The codec would become suspended after a while and then we would be back to the same problem, wouldn't we?
Quoted 6 lines
Quoted 1 line
Or are you saying that this initial resume of the codec is enough?
When the controller is active and the codec goes to runtime suspend, the codec will be woken up via the unsolicited event per jack change. So it seems that the problem is only about the wake up from the controller's runtime suspend.
Right, I guess the first sentence in commit message could be updated as
"In case HDA controller becomes active, but codec is runtime suspended, jack detection is not successful and no interrupt is raised."