[RFC PATCH 0/2] soundwire: multi-direction stream API
From: Srinivas Kandagatla
Date: Mon Nov 30 2026 - 17:40:36 EST
During Speaker Protection patches for Qualcomm SoCs, Pierre suggested
that we should add support to multi-direction in sdw_stream.
This patchset is to start that discussion on how these apis should look
like.
Some SoundWire codec-codec links drive more than one direction on the
same BE and the two directions are coupled on the bus: they share a
bring-up sequence and want to fail or succeed together. The first
in-tree case is WSA playback plus V/I-sense feedback on the same BE
(DSP speaker protection and thermal/excursion feedback).
Today callers like sound/soc/qcom/sdw.c hand-roll that: call
sdw_prepare_stream() / sdw_enable_stream() per direction, open-code
rollback when the second direction fails. The branching lives in
every driver that wants a multi-direction codec-codec link.
-- DO NOT APPLY THIS PATCH ---
This RFC proposes a small first-class object for the concept, so the
coupling is expressed in the type rather than left to caller
discipline:
struct sdw_multi_direction_stream;
void sdw_multi_direction_stream_init (struct sdw_multi_direction_stream *md,
const char *name);
struct sdw_multi_direction_stream *
sdw_multi_direction_stream_alloc (const char *name);
void sdw_multi_direction_stream_release(struct sdw_multi_direction_stream *md);
int sdw_multi_direction_stream_add (struct sdw_multi_direction_stream *md,
struct sdw_stream_runtime *stream);
int sdw_prepare_multi_direction_stream (struct sdw_multi_direction_stream *md);
int sdw_enable_multi_direction_stream (struct sdw_multi_direction_stream *md);
int sdw_disable_multi_direction_stream (struct sdw_multi_direction_stream *md);
int sdw_deprepare_multi_direction_stream(struct sdw_multi_direction_stream *md);
A group with one constituent behaves exactly like calling the matching
sdw_prepare_stream() / ... directly, so callers can use this
unconditionally instead of branching on dai_link->multi_direction_codecs.
prepare/enable do all-or-nothing rollback: on failure at step N the
earlier streams are torn down in reverse order. disable/deprepare are
best-effort (first error returned, all entries walked) so the bus
always ends up quiesced.
sdw_multi_direction_stream_init() exists for callers that want to
embed the handle in their own state (dai_link drvdata) and avoid any
allocation on the PCM hot path; _alloc() is kept for callers that
prefer a heap handle. Both expose the same lifecycle entry points.
Patch 2 illustrates the shape at the call site by converting
sound/soc/qcom/sdw.c. qcom_snd_sdw_prepare() and _hw_free() lose their
hand-rolled rollback and funnel single-direction and multi-direction
links through the same code. Patch 2 depends on the WSA
speaker-protection series for the multi_direction_codecs dai_link
flag; it is included here to validate the API shape and is not
intended to land through the SoundWire tree.
Open questions
--------------
1. Future: coalescing the bank switch.
2. SDW_MULTI_DIRECTION_STREAM_MAX is set to 4 - comfortably covers
WSA+VI (2) and leaves headroom for future TX+RX+companion-amp
topologies. Let me know if a different ceiling or a growable
backing array is preferred.
3. Bank switching.
Build-tested and exercised on Qualcomm X1E (Glymur CRD) and Lenovo
ThinkPad T14s Gen 7 with the WSA speaker-protection series, which
is the first in-tree user of a multi-direction codec-codec link.
Srinivas Kandagatla (2):
soundwire: stream: add multi-direction stream lifecycle API
ASoC: qcom: sdw: use multi-direction stream lifecycle for
prepare/hw_free
Documentation/driver-api/soundwire/stream.rst | 50 +++++
drivers/soundwire/stream.c | 202 ++++++++++++++++++
include/linux/soundwire/sdw.h | 39 ++++
sound/soc/qcom/sdw.c | 113 +++++-----
4 files changed, 353 insertions(+), 51 deletions(-)
base-commit: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8
--
2.53.0