From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
To: Vinod Koul <vkoul@kernel.org>,
Bard Liao <yung-chuan.liao@linux.intel.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
Sanyog Kale <sanyog.r.kale@intel.com>,
Mark Brown <broonie@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>,
alsa-devel@alsa-project.org, linux-sound@vger.kernel.org,
linux-arm-msm@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/2] ASoC: qcom: sdw: use multi-direction stream lifecycle for prepare/hw_free
Date: Mon, 30 Nov 2026 22:40:18 +0000 [thread overview]
Message-ID: <20261130224018.20359-3-srinivas.kandagatla@oss.qualcomm.com> (raw)
In-Reply-To: <20261130224018.20359-1-srinivas.kandagatla@oss.qualcomm.com>
Replace the open-coded per-direction handling with the multi-direction
stream lifecycle API. Single-direction and multi_direction_codecs
dai_links go through the same path, and the hand-rolled rollback is
gone.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/sdw.c | 113 ++++++++++++++++++++++++-------------------
1 file changed, 62 insertions(+), 51 deletions(-)
diff --git a/sound/soc/qcom/sdw.c b/sound/soc/qcom/sdw.c
index 82f1c47a788c..1ddb6c3fbc0a 100644
--- a/sound/soc/qcom/sdw.c
+++ b/sound/soc/qcom/sdw.c
@@ -203,26 +203,50 @@ int qcom_snd_sdw_startup(struct snd_pcm_substream *substream)
}
EXPORT_SYMBOL_GPL(qcom_snd_sdw_startup);
-/* Prepare+enable the SDW stream for one direction. */
-static int qcom_snd_sdw_prepare_dir(struct snd_soc_pcm_runtime *rtd, int dir)
+/*
+ * Build a multi-stream covering every direction runtime that this
+ * dai_link uses. For a conventional single-direction link the multi-stream
+ * holds one stream; for a multi_direction_codecs link it holds both
+ * directions. The lifecycle (prepare/enable/disable/deprepare) is
+ * driven through the multi-stream API in all cases.
+ */
+static struct sdw_multi_direction_stream *
+qcom_snd_sdw_build_multi_direction_stream(struct snd_soc_pcm_runtime *rtd, int dir)
{
- struct sdw_stream_runtime *sruntime;
+ struct sdw_stream_runtime *sr;
+ struct sdw_multi_direction_stream *md;
int ret;
- sruntime = sdw_find_dir_stream(rtd, dir);
- if (!sruntime)
- return 0;
+ md = sdw_multi_direction_stream_alloc(rtd->dai_link->name);
+ if (!md)
+ return ERR_PTR(-ENOMEM);
- ret = sdw_prepare_stream(sruntime);
- if (ret)
- return ret;
+ sr = sdw_find_dir_stream(rtd, dir);
+ if (sr) {
+ ret = sdw_multi_direction_stream_add(md, sr);
+ if (ret)
+ goto err;
+ }
- ret = sdw_enable_stream(sruntime);
- if (ret) {
- sdw_deprepare_stream(sruntime);
- return ret;
+ if (rtd->dai_link->multi_direction_codecs) {
+ sr = sdw_find_dir_stream(rtd, dir ^ 1);
+ /* Skip if no slave registered at hw_params (e.g. VI off) */
+ if (sr && sr->state != SDW_STREAM_ALLOCATED) {
+ ret = sdw_multi_direction_stream_add(md, sr);
+ if (ret)
+ goto err;
+ }
}
- return 0;
+
+ if (!md->num_streams) {
+ sdw_multi_direction_stream_release(md);
+ return NULL;
+ }
+
+ return md;
+err:
+ sdw_multi_direction_stream_release(md);
+ return ERR_PTR(ret);
}
int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream,
@@ -230,6 +254,7 @@ int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream,
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+ struct sdw_multi_direction_stream *md;
int ret;
if (!qcom_snd_is_sdw_dai(cpu_dai->id))
@@ -245,32 +270,24 @@ int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream,
* accumulated resulting in Click/Pop Noise
* PA enable/mute are handled as part of codec DAPM and digital mute.
*/
- ret = qcom_snd_sdw_prepare_dir(rtd, substream->stream);
- if (ret)
- return ret;
-
- if (rtd->dai_link->multi_direction_codecs) {
- struct sdw_stream_runtime *sr_opp =
- sdw_find_dir_stream(rtd, substream->stream ^ 1);
+ md = qcom_snd_sdw_build_multi_direction_stream(rtd, substream->stream);
+ if (IS_ERR(md))
+ return PTR_ERR(md);
+ if (!md)
+ return 0;
- /* Skip if no slave registered at hw_params (e.g. VI off) */
- if (sr_opp && sr_opp->state != SDW_STREAM_ALLOCATED) {
- ret = qcom_snd_sdw_prepare_dir(rtd,
- substream->stream ^ 1);
- if (ret) {
- struct sdw_stream_runtime *sr =
- sdw_find_dir_stream(rtd, substream->stream);
- if (sr) {
- sdw_disable_stream(sr);
- sdw_deprepare_stream(sr);
- }
- return ret;
- }
- }
- }
+ ret = sdw_prepare_multi_direction_stream(md);
+ if (ret)
+ goto out;
- *stream_prepared = true;
- return 0;
+ ret = sdw_enable_multi_direction_stream(md);
+ if (ret)
+ sdw_deprepare_multi_direction_stream(md);
+ else
+ *stream_prepared = true;
+out:
+ sdw_multi_direction_stream_release(md);
+ return ret;
}
EXPORT_SYMBOL_GPL(qcom_snd_sdw_prepare);
@@ -310,7 +327,7 @@ int qcom_snd_sdw_hw_free(struct snd_pcm_substream *substream, bool *stream_prepa
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
- struct sdw_stream_runtime *sr;
+ struct sdw_multi_direction_stream *md;
if (!qcom_snd_is_sdw_dai(cpu_dai->id))
return 0;
@@ -318,19 +335,13 @@ int qcom_snd_sdw_hw_free(struct snd_pcm_substream *substream, bool *stream_prepa
if (!*stream_prepared)
return 0;
- sr = sdw_find_dir_stream(rtd, substream->stream);
- if (sr) {
- sdw_disable_stream(sr);
- sdw_deprepare_stream(sr);
- }
+ md = qcom_snd_sdw_build_multi_direction_stream(rtd, substream->stream);
+ if (IS_ERR_OR_NULL(md))
+ return 0;
- if (rtd->dai_link->multi_direction_codecs) {
- sr = sdw_find_dir_stream(rtd, substream->stream ^ 1);
- if (sr && sr->state != SDW_STREAM_ALLOCATED) {
- sdw_disable_stream(sr);
- sdw_deprepare_stream(sr);
- }
- }
+ sdw_disable_multi_direction_stream(md);
+ sdw_deprepare_multi_direction_stream(md);
+ sdw_multi_direction_stream_release(md);
*stream_prepared = false;
return 0;
--
2.53.0
next prev parent reply other threads:[~2026-11-30 22:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 22:40 [RFC PATCH 0/2] soundwire: multi-direction stream API Srinivas Kandagatla
2026-11-30 22:40 ` [PATCH] soundwire: stream: add multi-direction stream lifecycle API Srinivas Kandagatla
2026-11-30 23:24 ` Randy Dunlap
2026-11-30 22:40 ` Srinivas Kandagatla [this message]
2026-12-01 16:44 ` [RFC PATCH 0/2] soundwire: multi-direction stream API Pierre-Louis Bossart
2026-12-01 23:36 ` Srinivas Kandagatla
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=20261130224018.20359-3-srinivas.kandagatla@oss.qualcomm.com \
--to=srinivas.kandagatla@oss.qualcomm.com \
--cc=alsa-devel@alsa-project.org \
--cc=andersson@kernel.org \
--cc=broonie@kernel.org \
--cc=corbet@lwn.net \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=pierre-louis.bossart@linux.dev \
--cc=sanyog.r.kale@intel.com \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.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
all inboxes | Powered by JetHome®