Skip to content

Commit c4c8dd6

Browse files
committed
ALSA: hda: Skip controller resume if not needed
The HD-audio controller does system-suspend and resume operations by directly calling its helpers __azx_runtime_suspend() and __azx_runtime_resume(). However, in general, we don't have to resume always the device fully at the system resume; typically, if a device has been runtime-suspended, we can leave it to runtime resume. Usually for achieving this, the driver would call pm_runtime_force_suspend() and pm_runtime_force_resume() pairs in the system suspend and resume ops. Unfortunately, this doesn't work for the resume path in our case. For handling the jack detection at the system resume, a child codec device may need the (literally) forcibly resume even if it's been runtime-suspended, and for that, the controller device must be also resumed even if it's been suspended. This patch is an attempt to improve the situation. It replaces the direct __azx_runtime_suspend()/_resume() calls with with pm_runtime_force_suspend() and pm_runtime_force_resume() with a slight trick as we've done for the codec side. More exactly: - azx_has_pm_runtime() check is dropped from azx_runtime_suspend() and azx_runtime_resume(), so that it can be properly executed from the system-suspend/resume path - The WAKEEN handling depends on the card's power state now; it's set and cleared only for the runtime-suspend - azx_resume() checks whether any codec may need the forcible resume beforehand. If the forcible resume is required, it does temporary PM refcount up/down for actually triggering the runtime resume. - A new helper function, hda_codec_need_resume(), is introduced for checking whether the codec needs a forcible runtime-resume, and the existing code is rewritten with that. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=207043 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 9479e75 commit c4c8dd6

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

include/sound/hda_codec.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ void snd_hda_update_power_acct(struct hda_codec *codec);
494494
static inline void snd_hda_set_power_save(struct hda_bus *bus, int delay) {}
495495
#endif
496496

497+
static inline bool hda_codec_need_resume(struct hda_codec *codec)
498+
{
499+
return !codec->relaxed_resume && codec->jacktbl.used;
500+
}
501+
497502
#ifdef CONFIG_SND_HDA_PATCH_LOADER
498503
/*
499504
* patch firmware

sound/pci/hda/hda_codec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ static int hda_codec_runtime_resume(struct device *dev)
29512951
static int hda_codec_force_resume(struct device *dev)
29522952
{
29532953
struct hda_codec *codec = dev_to_hda_codec(dev);
2954-
bool forced_resume = !codec->relaxed_resume && codec->jacktbl.used;
2954+
bool forced_resume = hda_codec_need_resume(codec);
29552955
int ret;
29562956

29572957
/* The get/put pair below enforces the runtime resume even if the

sound/pci/hda/hda_intel.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ static int azx_suspend(struct device *dev)
10271027
chip = card->private_data;
10281028
bus = azx_bus(chip);
10291029
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1030-
__azx_runtime_suspend(chip);
1030+
pm_runtime_force_suspend(dev);
10311031
if (bus->irq >= 0) {
10321032
free_irq(bus->irq, chip);
10331033
bus->irq = -1;
@@ -1044,7 +1044,9 @@ static int azx_suspend(struct device *dev)
10441044
static int azx_resume(struct device *dev)
10451045
{
10461046
struct snd_card *card = dev_get_drvdata(dev);
1047+
struct hda_codec *codec;
10471048
struct azx *chip;
1049+
bool forced_resume = false;
10481050

10491051
if (!azx_is_pm_ready(card))
10501052
return 0;
@@ -1055,7 +1057,20 @@ static int azx_resume(struct device *dev)
10551057
chip->msi = 0;
10561058
if (azx_acquire_irq(chip, 1) < 0)
10571059
return -EIO;
1058-
__azx_runtime_resume(chip, false);
1060+
1061+
/* check for the forced resume */
1062+
list_for_each_codec(codec, &chip->bus) {
1063+
if (hda_codec_need_resume(codec)) {
1064+
forced_resume = true;
1065+
break;
1066+
}
1067+
}
1068+
1069+
if (forced_resume)
1070+
pm_runtime_get_noresume(dev);
1071+
pm_runtime_force_resume(dev);
1072+
if (forced_resume)
1073+
pm_runtime_put(dev);
10591074
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
10601075

10611076
trace_azx_resume(chip);
@@ -1102,12 +1117,12 @@ static int azx_runtime_suspend(struct device *dev)
11021117
if (!azx_is_pm_ready(card))
11031118
return 0;
11041119
chip = card->private_data;
1105-
if (!azx_has_pm_runtime(chip))
1106-
return 0;
11071120

11081121
/* enable controller wake up event */
1109-
azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
1110-
STATESTS_INT_MASK);
1122+
if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0) {
1123+
azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
1124+
STATESTS_INT_MASK);
1125+
}
11111126

11121127
__azx_runtime_suspend(chip);
11131128
trace_azx_runtime_suspend(chip);
@@ -1118,17 +1133,18 @@ static int azx_runtime_resume(struct device *dev)
11181133
{
11191134
struct snd_card *card = dev_get_drvdata(dev);
11201135
struct azx *chip;
1136+
bool from_rt = snd_power_get_state(card) == SNDRV_CTL_POWER_D0;
11211137

11221138
if (!azx_is_pm_ready(card))
11231139
return 0;
11241140
chip = card->private_data;
1125-
if (!azx_has_pm_runtime(chip))
1126-
return 0;
1127-
__azx_runtime_resume(chip, true);
1141+
__azx_runtime_resume(chip, from_rt);
11281142

11291143
/* disable controller Wake Up event*/
1130-
azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
1131-
~STATESTS_INT_MASK);
1144+
if (from_rt) {
1145+
azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
1146+
~STATESTS_INT_MASK);
1147+
}
11321148

11331149
trace_azx_runtime_resume(chip);
11341150
return 0;

0 commit comments

Comments
 (0)