Re: [RFC PATCH 0/2] soundwire: multi-direction stream API
From: Pierre-Louis Bossart
Date: Tue Dec 01 2026 - 12:31:26 EST
On 11/30/26 11:40 PM, Srinivas Kandagatla wrote:
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.
Thanks for starting this!
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).
Humm, maybe before we start looking further, can you clarify if the feedback has the same format as the playback PCM? I vaguely recall that some amplifiers use custom formats, e.g. 10bits, for IV sense. The resolution doesn't need to be as precise as for PCM, does it?
I initially thought that we could combine all ports for all 'constituents', but if they transport different data formats we do have to stick with the rule 'one stream - one data format'.
The second question is whether the goal is to only deal with the direction problem, or if we want a way to 'link' or 'bind' data streams that need to be prepared together and later activated together. In that case you could simplify the API to 'sdw_multi_stream' and forget about the direction?
The feedback in your example does flow in the opposite direction, but for companion amps the data comes from the main amp. SDCA also has a concept of a DSP-generated 'enhancement' stream that would flow in parallel to the main playback stream.
One important point is also that the concept of multiple streams is 'hidden' below the ASoC dailink level, where I don't think we can work-around the direction. This API would only be for low-level data that is not exposed to userspace, ever. IOW the Linux drivers would provide configuration capability but no PCM devices/DMA support for those auxiliary streams.
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.
sorry, I am confused by the prepare/enable notation. Did you mean that all streams are prepared in all-or-nothing manner, and separately that the enable is also all-or-nothing? we're not combining prepare and enable, are we?
edit: the patch2 does suggest combining prepare and enable in the same routine, that's how I understand qcom_snd_sdw_build_multi_direction_stream()
This isn't how the Intel/AMD implementations work, see sound/soc/sdw_utils/soc_sdw_utils.c. There are different callbacks for prepare and trigger, not sure how they could ever be combined.
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.
I think you mean that all 'constituents' of a multi_stream would start at the same time on the same frame boundary?
I wonder how difficult that would be - in theory it's a broadcast write command that doesn't depend on the number of ports, directions or configuration.
One could push-back and argue that a single bank switch isn't really needed, given the internal delays inside the peripherals and the lower resolution of those additional data streams. Another point is that no one will have a test rig to check if the synchronous start is actually happening.
Ironically I think the prepare case is more complicated. One could have a first pass to configure the bandwidth needs for the regular stream, then a second pass for the next constituent. If that requires a clock scaling or the use of another data lane this could be interesting to unroll.
At any rate, this is a very interesting extension indeed, thanks again for starting this thread.