Skip to contentSkip to conversation

ALSA: hda/acpi: add runtime PM suspend/resume to the ACPI controller

PATCH Applied David Cemin 2 participants 2 messages Sep 12 – Sep 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda/acpi: add runtime PM suspend/resume to the ACPI controller

The hda-acpi platform driver never enables runtime PM, so pm_runtime_force_suspend() in hda_acpi_suspend() skips the runtime callbacks. On resume the controller is therefore never re-initialised:
azx_init_chip() is called only at probe time, so after S3 the codec verbs time out and audio is dead until the driver is rebound.

Add explicit runtime_suspend/runtime_resume callbacks and invoke them from the system-sleep paths, mirroring the pattern used by snd-hda-intel. Tested on an arm64 platform with the NVDA2014 controller: resume latency drops from 81.5 s to 3.6 s and audio is live immediately after wake.

---
 sound/hda/controllers/acpi.c | 41 ++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
sound/hda/controllers/acpi.c +41 -0
index 505cc97e0ee9..04b261dde22e 100644
@@ -266,6 +266,38 @@ static void hda_acpi_shutdown(struct platform_device *pdev)
 		azx_stop_chip(chip);
 }
 
+static int hda_acpi_runtime_suspend(struct device *dev)
+{
+	struct snd_card *card = dev_get_drvdata(dev);
+	struct azx *chip = card->private_data;
+
+	if (chip && chip->running) {
+		/* enable controller wake up event */
+		azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
+			   STATESTS_INT_MASK);
+
+		azx_stop_chip(chip);
+		azx_enter_link_reset(chip);
+	}
+
+	return 0;
+}
+
+static int hda_acpi_runtime_resume(struct device *dev)
+{
+	struct snd_card *card = dev_get_drvdata(dev);
+	struct azx *chip = card->private_data;
+
+	if (chip && chip->running) {
+		azx_init_chip(chip, 1);
+		/* disable controller wake up event */
+		azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
+			   ~STATESTS_INT_MASK);
+	}
+
+	return 0;
+}
+
 static int hda_acpi_suspend(struct device *dev)
 {
 	struct snd_card *card = dev_get_drvdata(dev);
@@ -274,6 +306,12 @@ static int hda_acpi_suspend(struct device *dev)
 	rc = pm_runtime_force_suspend(dev);
 	if (rc < 0)
 		return rc;
+	/*
+	 * Runtime PM is never enabled for this device, so the force_suspend
+	 * above does not reach the runtime callback; stop the controller
+	 * explicitly.
+	 */
+	hda_acpi_runtime_suspend(dev);
 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
 
 	return 0;
@@ -287,6 +325,8 @@ static int hda_acpi_resume(struct device *dev)
 	rc = pm_runtime_force_resume(dev);
 	if (rc < 0)
 		return rc;
+	/* See hda_acpi_suspend(): re-init the controller explicitly. */
+	hda_acpi_runtime_resume(dev);
 	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
 
 	return 0;
@@ -294,6 +334,7 @@ static int hda_acpi_resume(struct device *dev)
 
 static const struct dev_pm_ops hda_acpi_pm = {
 	SYSTEM_SLEEP_PM_OPS(hda_acpi_suspend, hda_acpi_resume)
+	RUNTIME_PM_OPS(hda_acpi_runtime_suspend, hda_acpi_runtime_resume, NULL)
 };
 
 static const struct hda_data nvidia_hda_data = {

base-commit: 841e384b841a3d89c50b4b2d6c5bb6abab1a7e39

Signature · 1 line
2.55.0
Applied
#1 lore raw
Quoted 7 lines · David Cemin

The hda-acpi platform driver never enables runtime PM, so pm_runtime_force_suspend() in hda_acpi_suspend() skips the runtime callbacks. On resume the controller is therefore never re-initialised:
azx_init_chip() is called only at probe time, so after S3 the codec verbs time out and audio is dead until the driver is rebound.

Quoted 6 lines

Add explicit runtime_suspend/runtime_resume callbacks and invoke them from the system-sleep paths, mirroring the pattern used by snd-hda-intel. Tested on an arm64 platform with the NVDA2014 controller: resume latency drops from 81.5 s to 3.6 s and audio is live immediately after wake.

Applied to for-next branch. Thanks.

Takashi