Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: David Rhodes <david.rhodes@cirrus.com>,
	Richard Fitzgerald <rf@opensource.cirrus.com>,
	patches@opensource.cirrus.com,
	Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
	Baojun Xu <baojun.xu@ti.com>
Subject: [PATCH 05/25] ALSA: hda/common: Use cleanup macros for PM controls
Date: Mon, 11 Aug 2025 12:07:39 +0200	[thread overview]
Message-ID: <20250811100807.7962-6-tiwai@suse.de> (raw)
In-Reply-To: <20250811100807.7962-1-tiwai@suse.de>

The new macro CLASS(snd_hda_power_pm) can replace the manual
snd_hda_power_up_pm() and _down() calls gracefully.

A part of the code in codec_exec_verb() is factored out to a function,
so that the auto-cleanup can be well scoped.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/hda/common/codec.c | 30 +++++++++++++++++++-----------
 sound/hda/common/proc.c  |  4 +---
 sound/hda/common/sysfs.c | 11 ++++-------
 3 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index eb268d442201..28cdbf6dd98a 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -31,6 +31,23 @@
 #define codec_has_clkstop(codec) \
 	((codec)->core.power_caps & AC_PWRST_CLKSTOP)
 
+static int call_exec_verb(struct hda_bus *bus, struct hda_codec *codec,
+			  unsigned int cmd, unsigned int flags,
+			  unsigned int *res)
+{
+	int err;
+
+	CLASS(snd_hda_power_pm, pm)(codec);
+	mutex_lock(&bus->core.cmd_mutex);
+	if (flags & HDA_RW_NO_RESPONSE_FALLBACK)
+		bus->no_response_fallback = 1;
+	err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr,
+					      cmd, res);
+	bus->no_response_fallback = 0;
+	mutex_unlock(&bus->core.cmd_mutex);
+	return err;
+}
+
 /*
  * Send and receive a verb - passed to exec_verb override for hdac_device
  */
@@ -45,15 +62,7 @@ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd,
 		return -1;
 
  again:
-	snd_hda_power_up_pm(codec);
-	mutex_lock(&bus->core.cmd_mutex);
-	if (flags & HDA_RW_NO_RESPONSE_FALLBACK)
-		bus->no_response_fallback = 1;
-	err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr,
-					      cmd, res);
-	bus->no_response_fallback = 0;
-	mutex_unlock(&bus->core.cmd_mutex);
-	snd_hda_power_down_pm(codec);
+	err = call_exec_verb(bus, codec, cmd, flags, res);
 	if (!codec_in_pm(codec) && res && err == -EAGAIN) {
 		if (bus->response_reset) {
 			codec_dbg(codec,
@@ -634,12 +643,11 @@ static void hda_jackpoll_work(struct work_struct *work)
 		return;
 
 	/* the power-up/down sequence triggers the runtime resume */
-	snd_hda_power_up(codec);
+	CLASS(snd_hda_power, pm)(codec);
 	/* update jacks manually if polling is required, too */
 	snd_hda_jack_set_dirty_all(codec);
 	snd_hda_jack_poll_all(codec);
 	schedule_delayed_work(&codec->jackpoll_work, codec->jackpoll_interval);
-	snd_hda_power_down(codec);
 }
 
 /* release all pincfg lists */
diff --git a/sound/hda/common/proc.c b/sound/hda/common/proc.c
index 00c2eeb2c472..55dd70332e40 100644
--- a/sound/hda/common/proc.c
+++ b/sound/hda/common/proc.c
@@ -782,7 +782,7 @@ static void print_codec_info(struct snd_info_entry *entry,
 	fg = codec->core.afg;
 	if (!fg)
 		return;
-	snd_hda_power_up(codec);
+	CLASS(snd_hda_power, pm)(codec);
 	snd_iprintf(buffer, "Default PCM:\n");
 	print_pcm_caps(buffer, codec, fg);
 	snd_iprintf(buffer, "Default Amp-In caps: ");
@@ -795,7 +795,6 @@ static void print_codec_info(struct snd_info_entry *entry,
 	nodes = snd_hda_get_sub_nodes(codec, fg, &nid);
 	if (! nid || nodes < 0) {
 		snd_iprintf(buffer, "Invalid AFG subtree\n");
-		snd_hda_power_down(codec);
 		return;
 	}
 
@@ -932,7 +931,6 @@ static void print_codec_info(struct snd_info_entry *entry,
 
 		kfree(conn);
 	}
-	snd_hda_power_down(codec);
 }
 
 /*
diff --git a/sound/hda/common/sysfs.c b/sound/hda/common/sysfs.c
index 140e24bf4d7f..0d464d4dd7c9 100644
--- a/sound/hda/common/sysfs.c
+++ b/sound/hda/common/sysfs.c
@@ -129,21 +129,18 @@ static int reconfig_codec(struct hda_codec *codec)
 {
 	int err;
 
-	snd_hda_power_up(codec);
+	CLASS(snd_hda_power, pm)(codec);
 	codec_info(codec, "hda-codec: reconfiguring\n");
 	err = snd_hda_codec_reset(codec);
 	if (err < 0) {
 		codec_err(codec,
 			   "The codec is being used, can't reconfigure.\n");
-		goto error;
+		return err;
 	}
 	err = device_reprobe(hda_codec_dev(codec));
 	if (err < 0)
-		goto error;
-	err = snd_card_register(codec->card);
- error:
-	snd_hda_power_down(codec);
-	return err;
+		return err;
+	return snd_card_register(codec->card);
 }
 
 /*
-- 
2.50.1


  parent reply	other threads:[~2025-08-11 10:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 10:07 [PATCH 00/25] ALSA: hda: Use auto-cleanup macros Takashi Iwai
2025-08-11 10:07 ` [PATCH 01/25] ALSA: hda: Introduce auto cleanup macros for PM Takashi Iwai
2025-08-11 10:07 ` [PATCH 02/25] ALSA: hda/ca0132: Use cleanup macros for PM controls Takashi Iwai
2025-08-11 10:07 ` [PATCH 03/25] ALSA: hda/hdmi: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 04/25] ALSA: hda/realtek: " Takashi Iwai
2025-08-11 10:07 ` Takashi Iwai [this message]
2025-08-11 10:07 ` [PATCH 06/25] ALSA: hda: Use auto cleanup macros for DSP loader locks Takashi Iwai
2025-08-11 10:07 ` [PATCH 07/25] ALSA: hda/common: Use guard() for mutex locks Takashi Iwai
2025-08-11 10:07 ` [PATCH 08/25] ALSA: hda/core: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 09/25] ALSA: hda/ca0132: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 10/25] ALSA: hda/hdmi: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 11/25] ALSA: hda/realtek: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 12/25] ALSA: hda/cs35l41: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 13/25] ALSA: hda/tas2781: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 14/25] ALSA: hda/cs8409: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 15/25] ALSA: hda/component: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 16/25] ALSA: hda/generic: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 17/25] ALSA: hda/analog: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 18/25] ALSA: hda/intel: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 19/25] ALSA: hda/common: Use auto cleanup for temporary buffers Takashi Iwai
2025-08-11 10:07 ` [PATCH 20/25] ALSA: hda/realtek: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 21/25] ALSA: hda/generic: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 22/25] ALSA: hda/ext: Use guard() for spinlocks Takashi Iwai
2025-08-11 10:07 ` [PATCH 23/25] ALSA: hda/core: " Takashi Iwai
2025-08-13 14:07   ` Andy Shevchenko
2025-08-13 14:10     ` Andy Shevchenko
2025-08-13 14:19       ` Takashi Iwai
2025-08-11 10:07 ` [PATCH 24/25] ALSA: hda/common: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 25/25] ALSA: hda/intel: " Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250811100807.7962-6-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=baojun.xu@ti.com \
    --cc=david.rhodes@cirrus.com \
    --cc=kevin-lu@ti.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=rf@opensource.cirrus.com \
    --cc=shenghao-ding@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox