public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda: intel: Fix Optimus when GPU has no sound
@ 2024-09-04 20:39 Maxim Mikityanskiy
  2024-09-05 14:24 ` Takashi Iwai
  0 siblings, 1 reply; 13+ messages in thread
From: Maxim Mikityanskiy @ 2024-09-04 20:39 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai
  Cc: Pierre-Louis Bossart, Kai Vehmanen, Maarten Lankhorst,
	Peter Ujfalusi, Chaitanya Kumar Borah, Rui Salvaterra,
	Sui Jingfeng, Bjorn Helgaas, Peter Wu, Lukas Wunner, linux-sound,
	linux-kernel, Maxim Mikityanskiy

Lenovo IdeaPad Z570 with NVIDIA GeForce Ge 520M doesn't have sound on
the discrete GPU. snd_hda_intel probes the device and schedules
azx_probe_continue(), which fails at azx_first_init(). The driver ends
up probed, but calls azx_free() and stops the chip. However, from the
runtime PM point of view, the device remains active, because the PCI
subsystem makes it active on probe, and it's still bound. It prevents
vga_switcheroo from turning off the DGPU (pci_create_device_link() syncs
power management for the video and audio devices).

Fix it by forcing the device to the suspended state in azx_free().

Fixes: 07f4f97d7b4b ("vga_switcheroo: Use device link for HDA controller")
Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
---
 sound/pci/hda/hda_intel.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index b79020adce63..65fcb92e11c7 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1361,8 +1361,20 @@ static void azx_free(struct azx *chip)
 	if (use_vga_switcheroo(hda)) {
 		if (chip->disabled && hda->probe_continued)
 			snd_hda_unlock_devices(&chip->bus);
-		if (hda->vga_switcheroo_registered)
+		if (hda->vga_switcheroo_registered) {
 			vga_switcheroo_unregister_client(chip->pci);
+
+			/* Some GPUs don't have sound, and azx_first_init fails,
+			 * leaving the device probed but non-functional. As long
+			 * as it's probed, the PCI subsystem keeps its runtime
+			 * PM status as active. Force it to suspended (as we
+			 * actually stop the chip) to allow GPU to suspend via
+			 * vga_switcheroo.
+			 */
+			pm_runtime_disable(&pci->dev);
+			pm_runtime_set_suspended(&pci->dev);
+			pm_runtime_enable(&pci->dev);
+		}
 	}
 
 	if (bus->chip_init) {
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-09-30 10:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-04 20:39 [PATCH] ALSA: hda: intel: Fix Optimus when GPU has no sound Maxim Mikityanskiy
2024-09-05 14:24 ` Takashi Iwai
2024-09-06 18:05   ` Maxim Mikityanskiy
2024-09-07 10:06     ` Takashi Iwai
2024-09-07 13:45       ` Maxim Mikityanskiy
2024-09-07 15:49         ` Takashi Iwai
2024-09-07 17:24           ` Maxim Mikityanskiy
2024-09-07 18:10             ` Takashi Iwai
2024-09-21  8:10               ` Maxim Mikityanskiy
2024-09-30  6:43                 ` Takashi Iwai
2024-09-30  7:29                   ` Maxim Mikityanskiy
2024-09-30  9:15                     ` Lukas Wunner
2024-09-30 10:50                     ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox