]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.109/alsa-hda-enforces-runtime_resume-after-s3-and-s4-for-each-codec.patch
Linux 4.14.109
[thirdparty/kernel/stable-queue.git] / releases / 4.14.109 / alsa-hda-enforces-runtime_resume-after-s3-and-s4-for-each-codec.patch
1 From b5a236c175b0d984552a5f7c9d35141024c2b261 Mon Sep 17 00:00:00 2001
2 From: Hui Wang <hui.wang@canonical.com>
3 Date: Tue, 19 Mar 2019 09:28:44 +0800
4 Subject: ALSA: hda - Enforces runtime_resume after S3 and S4 for each codec
5
6 From: Hui Wang <hui.wang@canonical.com>
7
8 commit b5a236c175b0d984552a5f7c9d35141024c2b261 upstream.
9
10 Recently we found the audio jack detection stop working after suspend
11 on many machines with Realtek codec. Sometimes the audio selection
12 dialogue didn't show up after users plugged headhphone/headset into
13 the headset jack, sometimes after uses plugged headphone/headset, then
14 click the sound icon on the upper-right corner of gnome-desktop, it
15 also showed the speaker rather than the headphone.
16
17 The root cause is that before suspend, the codec already call the
18 runtime_suspend since this codec is not used by any apps, then in
19 resume, it will not call runtime_resume for this codec. But for some
20 realtek codec (so far, alc236, alc255 and alc891) with the specific
21 BIOS, if it doesn't run runtime_resume after suspend, all codec
22 functions including jack detection stop working anymore.
23
24 This problem existed for a long time, but it was not exposed, that is
25 because when problem happens, if users play sound or open
26 sound-setting to check audio device, this will trigger calling to
27 runtime_resume (via snd_hda_power_up), then the codec starts working
28 again before users notice this problem.
29
30 Since we don't know how many codec and BIOS combinations have this
31 problem, to fix it, let the driver call runtime_resume for all codecs
32 in pm_resume, maybe for some codecs, this is not needed, but it is
33 harmless. After a codec is runtime resumed, if it is not used by any
34 apps, it will be runtime suspended soon and furthermore we don't run
35 suspend frequently, this change will not add much power consumption.
36
37 Fixes: cc72da7d4d06 ("ALSA: hda - Use standard runtime PM for codec power-save control")
38 Signed-off-by: Hui Wang <hui.wang@canonical.com>
39 Signed-off-by: Takashi Iwai <tiwai@suse.de>
40 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
41
42 ---
43 sound/pci/hda/hda_codec.c | 20 +++++++++++++++++---
44 1 file changed, 17 insertions(+), 3 deletions(-)
45
46 --- a/sound/pci/hda/hda_codec.c
47 +++ b/sound/pci/hda/hda_codec.c
48 @@ -2934,6 +2934,20 @@ static int hda_codec_runtime_resume(stru
49 #endif /* CONFIG_PM */
50
51 #ifdef CONFIG_PM_SLEEP
52 +static int hda_codec_force_resume(struct device *dev)
53 +{
54 + int ret;
55 +
56 + /* The get/put pair below enforces the runtime resume even if the
57 + * device hasn't been used at suspend time. This trick is needed to
58 + * update the jack state change during the sleep.
59 + */
60 + pm_runtime_get_noresume(dev);
61 + ret = pm_runtime_force_resume(dev);
62 + pm_runtime_put(dev);
63 + return ret;
64 +}
65 +
66 static int hda_codec_pm_suspend(struct device *dev)
67 {
68 dev->power.power_state = PMSG_SUSPEND;
69 @@ -2943,7 +2957,7 @@ static int hda_codec_pm_suspend(struct d
70 static int hda_codec_pm_resume(struct device *dev)
71 {
72 dev->power.power_state = PMSG_RESUME;
73 - return pm_runtime_force_resume(dev);
74 + return hda_codec_force_resume(dev);
75 }
76
77 static int hda_codec_pm_freeze(struct device *dev)
78 @@ -2955,13 +2969,13 @@ static int hda_codec_pm_freeze(struct de
79 static int hda_codec_pm_thaw(struct device *dev)
80 {
81 dev->power.power_state = PMSG_THAW;
82 - return pm_runtime_force_resume(dev);
83 + return hda_codec_force_resume(dev);
84 }
85
86 static int hda_codec_pm_restore(struct device *dev)
87 {
88 dev->power.power_state = PMSG_RESTORE;
89 - return pm_runtime_force_resume(dev);
90 + return hda_codec_force_resume(dev);
91 }
92 #endif /* CONFIG_PM_SLEEP */
93