* [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx
@ 2026-12-04 11:30 Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
` (23 more replies)
0 siblings, 24 replies; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
This series adds DSP Active speaker protection (SP) for WSA88xx speakers on
Qualcomm AudioReach platforms. It was tested on the Lenovo ThinkPad T14s
Gen 6 (2x WSA8845), T14s Gen 7 (2x WSA8845) and the Glymur CRD (4x WSA8845).
Speaker protection needs the amplifiers' V/I sense capture running
whenever the speakers play. Rather than a separate capture link that
userspace has to keep open, the VI codec DAIs sit on the WSA Playback BE
link, using a new multi_direction codec-codec link flag that makes the core
run .hw_params/.hw_free and stream events for codec DAIs of the other
direction. The V/I data never reaches userspace: the capture codec DAIs
power up their SoundWire capture ports and feed the DSP through a
codec-to-codec control link in the topology (the SP_VI module). The
per-direction SoundWire stream runtime needed to configure those capture
ports is added by the qcom sdw patch.
- ASoC core: bump the default ch_map cap to 18 (the WSA Playback link
on glymur-crd has 18 codec DAIs), and add the multi_direction_codecs
link flag (documented).
- qcom sdw: per-direction stream runtimes on such links.
- wsa883x/wsa884x: VI sense capture DAI, die temperature as a thermal
zone.
- AudioReach: control links, VI calibration run with per-speaker
events, R0/T0 cache and restore in normal mode, static cfg blobs,
mixer controls for status/R0T0/live T0/calibration state, and a
"Speaker Protection Calibrate" trigger to arm a run.
- x1e80100: VI feedback on the WSA Playback link, speaker thermal zones.
- DT: VI feedback for glymur-crd, mahua-t14s (Gen 7) and x1e78100-t14s
(Gen 6).
A topology with the SP and SP_VI modules is needed to use it.
Changes in v5 (addresses sashiko-bot feedback on v4):
- rebased on sound for-next
- patch 06: wsa884x_vi_hw_params always calls sdw_stream_add_slave,
with num_ports=0 when VISENSE is not enabled, so the master always
gets a VI slave entry for the stream.
- patch 08: suppress the duplicate hwmon device from
thermal_tripless_zone_device_register() with a no_hwmon
thermal_zone_params, and gate wsa884x_get_temp() on hw_init under
sp_lock (dropping the redundant check in wsa884x_tz_get_temp).
- patch 13: tighten sp_operation_mode + watchdog ordering: watchdog
also disarms the VI result, finish cancels the delayed work before
writing the mode, and an exported audioreach_sp_shutdown() lets
q6apm's module unload path release the watchdog work.
- patch 14: snapshot sp_vi_r0t0_cfg into a local before
q6apm_send_cmd_sync() so the mutex is dropped across the DSP call;
pass sp_operation_mode through as an argument from the caller.
- patch 18: audioreach_get_sp_vi_t0() returns -EAGAIN if any registered
zone is unreadable, and the event handler only caches R0/T0 when the
whole run succeeded, so a cold-boot zone failure cannot land a bogus
T0.
- patch 19: event handler guards against zero-length payloads and
zeros last_state alongside r0_cali_q24 on first event; abort finishes
calibration first before taking the mutex, and the duplicate finish
call is removed.
- patch 21: x1e80100_snd_init() registers the speaker thermal zones
only after qcom_snd_wcd_jack_setup() succeeds.
Changes in v4:
- patch 10: VI calibration event now scans every speaker, caches R0
per channel and records the terminal states so patches 13/18/19 can
expose status/R0T0 cleanly.
- patches 13, 18, 19: new controls and triggers for calibration state,
live T0 readback and arming a run.
- DT patches 22-24: carry Reviewed-by from Abel Vesa.
- Rebased onto next-20261201.
Changes in v3:
- patch 01: replace the devm "always allocate default ch_maps" rework
with a simple bump of MAX_DEFAULT_CH_MAP_SIZE from 12 to 18, per
Morimoto-san's suggestion that the cap is just a placeholder and
should be grown when needed. 18 is the exact width needed by the
glymur-crd WSA Playback link.
- patch 02: expand commit message to explain that V/I feedback never
reaches userspace; the capture codec DAIs power up their SoundWire
ports and feed the DSP via a codec-to-codec control link, and the
per-direction SoundWire stream runtime is added by the next qcom sdw
patch (addressing Pierre-Louis' review).
- patch 08: drop const from wsa884x_tz_ops to match the
thermal_tripless_zone_device_register() signature on configs where
it is not const (kernel test robot).
- patch 18: use div_s64() for the Q6 temperature conversion so the
module builds on 32-bit arches without __divdi3 (kernel test robot).
- DT patches 22-24: pick up Abel Vesa's Reviewed-by.
- Rebased onto next-20261130; no other code changes.
Tool use: an LLM coding assistant (Claude Code with Claude Opus) was
used for some of the patches in this series, to debug the bring-up and
to draft the code and commit messages.
My wip trees (kernel, topology, ucm):
https://github.com/Srinivas-Kandagatla/linux/tree/glymur
https://github.com/Srinivas-Kandagatla/audioreach-topology/tree/glymur
https://github.com/Srinivas-Kandagatla/alsa-ucm-conf/tree/glymur
Ravi Hothi (11):
ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell
ASoC: codecs: wsa884x: add VI sense capture DAI
ASoC: codecs: wsa883x: add VI sense capture DAI
ASoC: qcom: audioreach: run VI module in calibration mode with
per-speaker events
ASoC: qcom: q6apm-dai: add S32_LE format support
ASoC: qcom: audioreach: cache VI calibration results per speaker
ASoC: qcom: audioreach: add speaker protection calibration trigger
infrastructure
ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal
mode
ASoC: qcom: audioreach: send static cfg blobs to speaker protection
modules
ASoC: qcom: audioreach: add speaker protection mixer controls
arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
Srinivas Kandagatla (13):
ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18
ASoC: soc-pcm: add multi_direction_codecs link flag
ASoC: soc-dai: export snd_soc_dai_stream_valid
ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction
links
ASoC: codecs: wsa884x: register the die temperature as a thermal zone
ASoC: qcom: audioreach: add control link support to graphs
ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format
ASoC: qcom: audioreach: add live speaker temperature (T0) readback
ASoC: qcom: audioreach: add speaker protection calibration state
control
ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE
link
ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker
protection
arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
arm64: dts: qcom: x1e78100-t14s: add WSA speaker protection VI
feedback
.../bindings/sound/qcom,wsa8840.yaml | 5 +-
Documentation/sound/soc/index.rst | 1 +
.../sound/soc/multi-direction-codecs.rst | 156 ++++
arch/arm64/boot/dts/qcom/glymur-crd.dtsi | 20 +-
.../mahua-lenovo-thinkpad-t14s-gen7-lcd.dts | 11 +-
.../qcom/x1e78100-lenovo-thinkpad-t14s.dtsi | 10 +-
include/sound/soc-dapm.h | 2 +
include/sound/soc.h | 8 +
include/uapi/sound/snd_ar_tokens.h | 13 +
sound/soc/codecs/wsa883x.c | 77 +-
sound/soc/codecs/wsa884x.c | 165 +++-
sound/soc/qcom/qdsp6/audioreach.c | 819 +++++++++++++++++-
sound/soc/qcom/qdsp6/audioreach.h | 106 +++
sound/soc/qcom/qdsp6/q6apm-dai.c | 16 +-
sound/soc/qcom/qdsp6/q6apm.c | 42 +-
sound/soc/qcom/qdsp6/q6apm.h | 1 +
sound/soc/qcom/qdsp6/topology.c | 313 +++++++
sound/soc/qcom/sdw.c | 237 +++--
sound/soc/qcom/x1e80100.c | 112 ++-
sound/soc/soc-core.c | 20 +-
sound/soc/soc-dai.c | 1 +
sound/soc/soc-dapm.c | 32 +
sound/soc/soc-pcm.c | 139 ++-
23 files changed, 2163 insertions(+), 143 deletions(-)
create mode 100644 Documentation/sound/soc/multi-direction-codecs.rst
base-commit: 92c8b08bb15f44e23aa616700a380293a3eb0c35
--
2.53.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [PATCH v5 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
` (22 subsequent siblings)
23 siblings, 0 replies; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
The WSA Playback BE on glymur-crd carries 4 WSA speakers plus their V/I
sense feedback for speaker protection, which works out to 18 codec DAIs
on one link (4 speakers x 2 DAIs + 8 SoundWire ports + 2 WSA-macro
DAIs). The current 12-entry default ch_maps reject the link up front.
Grow the three default tables and the cap from 12 to 18.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
sound/soc/soc-core.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 894a81b2d983..29b1e7254f90 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -766,7 +766,7 @@ static int soc_dai_link_sanity_check(struct snd_soc_card *card,
return -EINVAL;
}
-#define MAX_DEFAULT_CH_MAP_SIZE 12
+#define MAX_DEFAULT_CH_MAP_SIZE 18
static struct snd_soc_dai_link_ch_map default_ch_map_sync[MAX_DEFAULT_CH_MAP_SIZE] = {
{ .cpu = 0, .codec = 0 },
{ .cpu = 1, .codec = 1 },
@@ -780,6 +780,12 @@ static struct snd_soc_dai_link_ch_map default_ch_map_sync[MAX_DEFAULT_CH_MAP_SIZ
{ .cpu = 9, .codec = 9 },
{ .cpu = 10, .codec = 10 },
{ .cpu = 11, .codec = 11 },
+ { .cpu = 12, .codec = 12 },
+ { .cpu = 13, .codec = 13 },
+ { .cpu = 14, .codec = 14 },
+ { .cpu = 15, .codec = 15 },
+ { .cpu = 16, .codec = 16 },
+ { .cpu = 17, .codec = 17 },
};
static struct snd_soc_dai_link_ch_map default_ch_map_1cpu[MAX_DEFAULT_CH_MAP_SIZE] = {
{ .cpu = 0, .codec = 0 },
@@ -794,6 +800,12 @@ static struct snd_soc_dai_link_ch_map default_ch_map_1cpu[MAX_DEFAULT_CH_MAP_SIZ
{ .cpu = 0, .codec = 9 },
{ .cpu = 0, .codec = 10 },
{ .cpu = 0, .codec = 11 },
+ { .cpu = 0, .codec = 12 },
+ { .cpu = 0, .codec = 13 },
+ { .cpu = 0, .codec = 14 },
+ { .cpu = 0, .codec = 15 },
+ { .cpu = 0, .codec = 16 },
+ { .cpu = 0, .codec = 17 },
};
static struct snd_soc_dai_link_ch_map default_ch_map_1codec[MAX_DEFAULT_CH_MAP_SIZE] = {
{ .cpu = 0, .codec = 0 },
@@ -808,6 +820,12 @@ static struct snd_soc_dai_link_ch_map default_ch_map_1codec[MAX_DEFAULT_CH_MAP_S
{ .cpu = 9, .codec = 0 },
{ .cpu = 10, .codec = 0 },
{ .cpu = 11, .codec = 0 },
+ { .cpu = 12, .codec = 0 },
+ { .cpu = 13, .codec = 0 },
+ { .cpu = 14, .codec = 0 },
+ { .cpu = 15, .codec = 0 },
+ { .cpu = 16, .codec = 0 },
+ { .cpu = 17, .codec = 0 },
};
static int snd_soc_compensate_channel_connection_map(struct snd_soc_card *card,
struct snd_soc_dai_link *dai_link)
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 12:01 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
` (21 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
Speaker protection needs the amplifiers' V/I sense capture running
whenever the speakers play. Putting the capture codec DAIs on the
playback BE link ties the two together, but the core skips codec DAIs
whose direction does not match the substream.
Add a multi_direction_codecs link flag. When set, the core also calls
.hw_params and .hw_free on codec DAIs of the other direction, with the
substream direction switched to theirs for the call under pcm_mutex,
and sends the matching stream events so their widgets power up and
down. An optional multi_direction_params_fixup callback lets the
machine driver set the parameters for those DAIs. Links without the
flag are unchanged.
There is no capture CPU DAI on such a link: the V/I feedback data
never reaches userspace. The capture codec DAIs power up their
SoundWire capture ports and feed the DSP through a codec-to-codec
control link in the topology (the SP_VI module in the AudioReach
case), so userspace just opens the playback FE. The per-direction
SoundWire stream runtime needed to configure those capture ports is
added by the following qcom sdw patch.
Document the flag in Documentation/sound/soc/multi-direction-codecs.rst.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
Documentation/sound/soc/index.rst | 1 +
.../sound/soc/multi-direction-codecs.rst | 156 ++++++++++++++++++
include/sound/soc-dapm.h | 2 +
include/sound/soc.h | 8 +
sound/soc/soc-dapm.c | 32 ++++
sound/soc/soc-pcm.c | 139 +++++++++++++---
6 files changed, 318 insertions(+), 20 deletions(-)
create mode 100644 Documentation/sound/soc/multi-direction-codecs.rst
diff --git a/Documentation/sound/soc/index.rst b/Documentation/sound/soc/index.rst
index 22878d73f7a5..62d01a0a6e52 100644
--- a/Documentation/sound/soc/index.rst
+++ b/Documentation/sound/soc/index.rst
@@ -18,4 +18,5 @@ The documentation is split into the following sections:-
jack
dpcm
codec-to-codec
+ multi-direction-codecs
usb
diff --git a/Documentation/sound/soc/multi-direction-codecs.rst b/Documentation/sound/soc/multi-direction-codecs.rst
new file mode 100644
index 000000000000..8d3fa62bb1c6
--- /dev/null
+++ b/Documentation/sound/soc/multi-direction-codecs.rst
@@ -0,0 +1,156 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===========================
+Multi-direction codec DAIs
+===========================
+
+Overview
+========
+
+An ASoC backend (BE) link that bundles **codec DAIs of both directions**
+on a **single-direction CPU DAI** can set
+``snd_soc_dai_link.multi_direction_codecs`` to tell the ASoC core to
+call ``.hw_params`` / ``.hw_free`` on opposite-direction codec DAIs with
+their own direction, instead of skipping them.
+
+Typical use case: a smart-amp speaker protection link where the CPU
+side is a playback-only DMA (e.g. ``WSA_CODEC_DMA_RX_0`` on Qualcomm
+AudioReach), but the codec side exposes both a playback SPKR DAI and a
+companion capture V/I-sense DAI on the same SoundWire bus. Opening the
+playback FE should bring up both the amplifier output chain *and* its
+V/I feedback capture chain atomically, without userspace having to open
+a secondary PCM.
+
+Without the flag, the second codec DAI's ``.hw_params`` is skipped
+because its native direction does not match ``substream->stream``;
+``snd_soc_dai_stream_valid()`` filters it out. With the flag set, the
+ASoC core:
+
+1. Still iterates every codec DAI on the link.
+2. For a codec DAI whose native direction is **opposite** the
+ substream's, calls its ``.hw_params`` / ``.hw_free`` with its own
+ direction (by briefly flipping the substream direction under
+ ``pcm_mutex``, encapsulated in ``soc_pcm_dai_hw_params_at_stream``).
+3. Optionally calls ``.multi_direction_params_fixup`` so the machine
+ driver can rewrite rate/format/channels on a per-codec copy of the
+ params (an 8 kHz / S32_LE V/I-sense codec DAI will not accept a
+ 48 kHz / S16_LE playback stream's params verbatim).
+4. Sends start and stop stream events for the opposite direction in
+ prepare and hw_free, so the stream widgets of those codec DAIs power
+ up and down with the link.
+
+Links that do not set the flag retain the pre-existing behaviour
+exactly.
+
+When to use this
+================
+
+Prefer ``multi_direction_codecs`` when:
+
+* the two directions are physically **inseparable** on the codec side
+ (same chip, same wire); and
+* a single open semantically covers both (speaker protection, playback
+ with feedback for echo-reference, haptic/boost feedback); and
+* you do not want userspace to see or manage two PCMs.
+
+Prefer **DPCM FE/BE pairs** when:
+
+* the two directions can be exercised independently; or
+* userspace legitimately needs to control each direction (classic
+ playback + microphone capture).
+
+Prefer a **DAPM supply widget** when:
+
+* only the DAPM power graph (clock, LDO, bias) needs linking, and
+* no ``.hw_params`` plumbing is required on the secondary direction.
+
+Interaction with DAPM
+=====================
+
+DAPM edges are directional and the flag does not change the graph. The
+opposite-direction codec DAIs' stream widgets are powered by the extra
+start and stop stream events the core sends for that direction in
+prepare and hw_free.
+
+Only ``.hw_params`` and ``.hw_free`` are called on the opposite-direction
+codec DAIs. Their ``.startup``, ``.prepare``, ``.trigger``,
+``.shutdown`` and mute callbacks are not, so a codec DAI used this way
+must not depend on them.
+
+Machine-driver example
+======================
+
+A machine driver that bundles V/I-sense capture codec DAIs onto a
+speaker-playback BE link::
+
+ static int wsa_vi_params_fixup(struct snd_soc_pcm_runtime *rtd,
+ struct snd_pcm_hw_params *params,
+ int stream)
+ {
+ if (stream != SNDRV_PCM_STREAM_CAPTURE)
+ return 0;
+ /* VI capture chain runs at 8kHz / S32_LE / 4ch */
+ hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = 8000;
+ hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = 8000;
+ hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min = 4;
+ hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max = 4;
+ snd_mask_none(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT));
+ snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
+ SNDRV_PCM_FORMAT_S32_LE);
+ return 0;
+ }
+
+ SND_SOC_DAILINK_DEFS(wsa_sp, ...);
+ SND_SOC_DAILINK_REG(wsa_sp);
+
+ static struct snd_soc_dai_link board_dai_links[] = {
+ {
+ .name = "WSA Playback",
+ .multi_direction_codecs = 1,
+ .multi_direction_params_fixup = wsa_vi_params_fixup,
+ SND_SOC_DAILINK_REG(wsa_sp),
+ /*
+ * codec DAIs include both the playback SPKR DAIs and
+ * their companion capture V/I-sense DAIs on the same
+ * SoundWire bus.
+ */
+ },
+ };
+
+Ordering with other fixups
+==========================
+
+``multi_direction_params_fixup`` runs per codec DAI inside
+``__soc_pcm_hw_params()``, after link-level params have been settled
+and after each codec has its own copy of ``params``::
+
+ snd_soc_link_hw_params() /* machine driver .hw_params */
+ be_hw_params_fixup() /* DPCM only, applied by FE */
+ for each codec DAI:
+ tmp_params = *params
+ if direction-flipped:
+ multi_direction_params_fixup(rtd, &tmp_params, codec_stream)
+ apply ch_map / TDM ch_mask narrowing
+ snd_soc_dai_hw_params(codec_dai, substream, &tmp_params)
+
+The fixup sees the stream's params after link / BE adjustments and
+may rewrite rate, format or channels for the flipped-direction codec
+DAI only. It does not affect the originating stream's params or
+other codecs' ``tmp_params``.
+
+Notes
+=====
+
+* ``multi_direction_params_fixup`` is called with the **flipped**
+ direction so the fixup logic can key off ``stream`` to decide
+ whether the params need rewriting.
+* ``snd_soc_dai_symmetric_set_params()`` runs after the flipped
+ ``.hw_params``. The symmetric-params tracking is per-DAI, so each
+ codec DAI records the format it was called with in its own
+ direction; nothing cross-contaminates.
+* The transient ``substream->stream`` flip is bounded to a single
+ codec DAI's ``.hw_params`` / ``.hw_free`` call and its DAPM update,
+ under ``pcm_mutex``. The codec DAI callbacks see the flipped value,
+ which is the purpose of the flip. ALSA core paths that do not take
+ ``pcm_mutex``, such as ``snd_pcm_info()``, can observe it during that
+ window.
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 33c4a3e9c1d4..90e527406a54 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -661,6 +661,8 @@ void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
/* dapm events */
void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, int event);
+void snd_soc_dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd,
+ int stream, int event);
void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream);
void snd_soc_dapm_shutdown(struct snd_soc_card *card);
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 5abebfa329b5..6fb83ced64fe 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -736,6 +736,11 @@ struct snd_soc_dai_link {
int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params);
+ /* Adjust params for codec DAIs of the other direction */
+ int (*multi_direction_params_fixup)(struct snd_soc_pcm_runtime *rtd,
+ struct snd_pcm_hw_params *params,
+ int stream);
+
/* machine stream operations */
const struct snd_soc_ops *ops;
const struct snd_soc_compr_ops *compr_ops;
@@ -770,6 +775,9 @@ struct snd_soc_dai_link {
/* This DAI link can route to other DAI links at runtime (Frontend)*/
unsigned int dynamic:1;
+ /* Also run codec DAIs of the other direction on this BE link */
+ unsigned int multi_direction_codecs:1;
+
/* DPCM used FE & BE merged format */
unsigned int dpcm_merged_format:1;
/* DPCM used FE & BE merged channel */
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 3ef13d2b1f5e..4bda3e5b930d 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -4670,6 +4670,18 @@ static void dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, int e
dapm_power_widgets(rtd->card, event, NULL);
}
+static void dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd,
+ int stream, int event)
+{
+ struct snd_soc_dai *codec_dai;
+ int i;
+
+ for_each_rtd_codec_dais(rtd, i, codec_dai)
+ dapm_dai_stream_event(codec_dai, stream, event);
+
+ dapm_power_widgets(rtd->card, event, NULL);
+}
+
/**
* snd_soc_dapm_stream_event - send a stream event to the dapm core
* @rtd: PCM runtime data
@@ -4691,6 +4703,26 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
snd_soc_dapm_mutex_unlock(card);
}
+/**
+ * snd_soc_dapm_codec_stream_event - stream event limited to codec-side DAIs
+ * @rtd: PCM runtime data
+ * @stream: stream direction
+ * @event: stream event
+ *
+ * Variant of snd_soc_dapm_stream_event() that only targets codec-side DAIs.
+ * Used by multi_direction_codecs links to power up/down the flipped-
+ * direction codec widgets without altering the CPU DAI's direction
+ * tracking.
+ */
+void snd_soc_dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd,
+ int stream, int event)
+{
+ snd_soc_dapm_mutex_lock(rtd->card);
+ dapm_codec_stream_event(rtd, stream, event);
+ snd_soc_dapm_mutex_unlock(rtd->card);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_codec_stream_event);
+
void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream)
{
if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index dac353fec4bc..c1b32c5f2f2d 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -986,6 +986,13 @@ static int __soc_pcm_prepare(struct snd_soc_pcm_runtime *rtd,
snd_soc_dapm_stream_event(rtd, substream->stream,
SND_SOC_DAPM_STREAM_START);
+ /*
+ * Only flip codec-side widgets; CPU DAIs must keep their recorded
+ * direction so later state that reads it stays consistent.
+ */
+ if (rtd->dai_link->multi_direction_codecs)
+ snd_soc_dapm_codec_stream_event(rtd, substream->stream ^ 1,
+ SND_SOC_DAPM_STREAM_START);
for_each_rtd_dais(rtd, i, dai) {
if (!snd_soc_dai_mute_is_ctrled_at_trigger(dai))
@@ -1032,6 +1039,59 @@ static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params,
interval->max = channels;
}
+/*
+ * Call .hw_params on a codec DAI of the other direction, with the substream
+ * direction switched to the DAI's under pcm_mutex.
+ *
+ * Only ->stream is flipped. ->runtime is not; codec .hw_params callbacks
+ * on multi_direction_codecs links read from @params, per convention.
+ */
+static int soc_pcm_dai_hw_params_at_stream(struct snd_soc_dai *dai,
+ struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ int stream)
+{
+ int saved_stream = substream->stream;
+ int ret;
+
+ if (stream == saved_stream)
+ return snd_soc_dai_hw_params(dai, substream, params);
+
+ substream->stream = stream;
+ ret = snd_soc_dai_hw_params(dai, substream, params);
+ substream->stream = saved_stream;
+ return ret;
+}
+
+/* hw_free counterpart to soc_pcm_dai_hw_params_at_stream(). */
+static void soc_pcm_dai_hw_free_at_stream(struct snd_soc_dai *dai,
+ struct snd_pcm_substream *substream,
+ int rollback, int stream)
+{
+ int saved_stream = substream->stream;
+
+ if (stream == saved_stream) {
+ snd_soc_dai_hw_free(dai, substream, rollback);
+ return;
+ }
+
+ substream->stream = stream;
+ snd_soc_dai_hw_free(dai, substream, rollback);
+ substream->stream = saved_stream;
+}
+
+/* DAPM counterpart, so the DAI's own direction widget gets updated */
+static void soc_pcm_dapm_update_dai_at_stream(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai, int stream)
+{
+ int saved_stream = substream->stream;
+
+ substream->stream = stream;
+ snd_soc_dapm_update_dai(substream, params, dai);
+ substream->stream = saved_stream;
+}
+
static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_substream *substream, int rollback)
{
@@ -1053,6 +1113,10 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd,
/* run the stream event */
snd_soc_dapm_stream_stop(rtd, substream->stream);
+ /* Flip only codec-side widgets; see __soc_pcm_prepare(). */
+ if (rtd->dai_link->multi_direction_codecs)
+ snd_soc_dapm_codec_stream_event(rtd, substream->stream ^ 1,
+ SND_SOC_DAPM_STREAM_STOP);
/* free any machine hw params */
snd_soc_link_hw_free(substream, rollback);
@@ -1060,11 +1124,30 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd,
/* free any component resources */
snd_soc_pcm_component_hw_free(substream, rollback);
- /* now free hw params for the DAIs */
- for_each_rtd_dais(rtd, i, dai)
+ /*
+ * CPU DAIs go through the unflipped path only, mirroring
+ * __soc_pcm_hw_params(). Only codec DAIs can be direction-flipped
+ * on a multi_direction_codecs link.
+ */
+ for_each_rtd_cpu_dais(rtd, i, dai)
if (snd_soc_dai_stream_valid(dai, substream->stream))
snd_soc_dai_hw_free(dai, substream, rollback);
+ for_each_rtd_codec_dais(rtd, i, dai) {
+ int codec_stream = substream->stream;
+
+ if (!snd_soc_dai_stream_valid(dai, codec_stream)) {
+ if (!rtd->dai_link->multi_direction_codecs)
+ continue;
+ codec_stream ^= 1;
+ if (!snd_soc_dai_stream_valid(dai, codec_stream))
+ continue;
+ }
+
+ soc_pcm_dai_hw_free_at_stream(dai, substream, rollback,
+ codec_stream);
+ }
+
return 0;
}
@@ -1114,30 +1197,44 @@ static int __soc_pcm_hw_params(struct snd_pcm_substream *substream,
goto out;
for_each_rtd_codec_dais(rtd, i, codec_dai) {
- unsigned int ch_mask = snd_soc_dai_tdm_mask_get(codec_dai, substream->stream);
+ int codec_stream = substream->stream;
+ unsigned int ch_mask;
struct snd_soc_dai_link_ch_map *ch_maps;
int j;
/*
* Skip CODECs which don't support the current stream type,
- * the idea being that if a CODEC is not used for the currently
- * set up transfer direction, it should not need to be
- * configured, especially since the configuration used might
- * not even be supported by that CODEC. There may be cases
- * however where a CODEC needs to be set up although it is
- * actually not being used for the transfer, e.g. if a
- * capture-only CODEC is acting as an LRCLK and/or BCLK master
- * for the DAI link including a playback-only CODEC.
- * If this becomes necessary, we will have to augment the
- * machine driver setup with information on how to act, so
- * we can do the right thing here.
+ * unless the link runs them in their own direction.
*/
- if (!snd_soc_dai_stream_valid(codec_dai, substream->stream))
- continue;
+ bool direction_flipped = false;
+
+ if (!snd_soc_dai_stream_valid(codec_dai, codec_stream)) {
+ if (!rtd->dai_link->multi_direction_codecs)
+ continue;
+ codec_stream ^= 1;
+ if (!snd_soc_dai_stream_valid(codec_dai, codec_stream))
+ continue;
+ direction_flipped = true;
+ }
+
+ ch_mask = snd_soc_dai_tdm_mask_get(codec_dai, codec_stream);
/* copy params for each codec */
tmp_params = *params;
+ /* The substream params describe the other direction */
+ if (direction_flipped && rtd->dai_link->multi_direction_params_fixup) {
+ int fret;
+
+ fret = rtd->dai_link->multi_direction_params_fixup(rtd,
+ &tmp_params,
+ codec_stream);
+ if (fret < 0) {
+ ret = fret;
+ goto out;
+ }
+ }
+
/* fixup params based on TDM or ch_map masks */
if (!ch_mask) {
for_each_rtd_ch_maps(rtd, j, ch_maps)
@@ -1148,13 +1245,15 @@ static int __soc_pcm_hw_params(struct snd_pcm_substream *substream,
if (ch_mask)
soc_pcm_codec_params_fixup(&tmp_params, ch_mask);
- ret = snd_soc_dai_hw_params(codec_dai, substream,
- &tmp_params);
- if(ret < 0)
+ ret = soc_pcm_dai_hw_params_at_stream(codec_dai, substream,
+ &tmp_params,
+ codec_stream);
+ if (ret < 0)
goto out;
snd_soc_dai_symmetric_set_params(codec_dai, &tmp_params);
- snd_soc_dapm_update_dai(substream, &tmp_params, codec_dai);
+ soc_pcm_dapm_update_dai_at_stream(substream, &tmp_params,
+ codec_dai, codec_stream);
}
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
` (20 subsequent siblings)
23 siblings, 0 replies; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
Modular users outside soc-core need this helper to filter DAIs by
direction (e.g. the qcom SoundWire machine driver, which iterates
codec DAIs on a multi_direction_codecs BE link to handle each
direction's stream runtime). Export it.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/soc-dai.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/sound/soc/soc-dai.c b/sound/soc/soc-dai.c
index 73aea7291fa7..8224f12d0fb1 100644
--- a/sound/soc/soc-dai.c
+++ b/sound/soc/soc-dai.c
@@ -706,6 +706,7 @@ bool snd_soc_dai_stream_valid(const struct snd_soc_dai *dai, int dir)
/* If the codec specifies any channels at all, it supports the stream */
return stream->channels_min;
}
+EXPORT_SYMBOL_GPL(snd_soc_dai_stream_valid);
void snd_soc_dai_active_update(struct snd_soc_dai *dai, int stream, int action)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (2 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 12:12 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
` (19 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
A SoundWire BE link with multi_direction_codecs carries codec DAIs of
both directions, and each direction needs its own sdw_stream_runtime.
Split startup, prepare, hw_free and shutdown into per-direction helpers
and run them for both directions on such links. Stream runtime names
are suffixed with "-Playback" / "-Capture" to keep debug output
unambiguous. A small sdw_find_dir_stream() helper centralises the
"find the stream for this direction" lookup that was previously
open-coded in each callback.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/sdw.c | 237 +++++++++++++++++++++++++++++++++----------
1 file changed, 183 insertions(+), 54 deletions(-)
diff --git a/sound/soc/qcom/sdw.c b/sound/soc/qcom/sdw.c
index e19adb7c750b..35b35f43d6fe 100644
--- a/sound/soc/qcom/sdw.c
+++ b/sound/soc/qcom/sdw.c
@@ -5,9 +5,55 @@
#include <dt-bindings/sound/qcom,lpass.h>
#include <dt-bindings/sound/qcom,q6afe.h>
#include <linux/module.h>
+#include <linux/slab.h>
#include <sound/soc.h>
#include "sdw.h"
+static struct sdw_stream_runtime *
+qcom_snd_sdw_alloc_stream(const char *cpu_name, int dir)
+{
+ const char *suffix = (dir == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "Playback" : "Capture";
+ struct sdw_stream_runtime *sr;
+ char *name;
+
+ name = kasprintf(GFP_KERNEL, "%s-%s", cpu_name, suffix);
+ if (!name)
+ return NULL;
+
+ sr = sdw_alloc_stream(name, SDW_STREAM_PCM);
+ if (!sr) {
+ kfree(name);
+ return NULL;
+ }
+ return sr;
+}
+
+static void qcom_snd_sdw_release_stream(struct sdw_stream_runtime *sr)
+{
+ if (!sr)
+ return;
+ kfree(sr->name);
+ sdw_release_stream(sr);
+}
+
+static struct sdw_stream_runtime *
+sdw_find_dir_stream(struct snd_soc_pcm_runtime *rtd, int dir)
+{
+ struct snd_soc_dai *codec_dai;
+ struct sdw_stream_runtime *sr;
+ int i;
+
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
+ if (!snd_soc_dai_stream_valid(codec_dai, dir))
+ continue;
+ sr = snd_soc_dai_get_stream(codec_dai, dir);
+ if (!IS_ERR(sr) && sr)
+ return sr;
+ }
+ return NULL;
+}
+
static bool qcom_snd_is_sdw_dai(int id)
{
switch (id) {
@@ -50,43 +96,42 @@ static bool qcom_snd_is_sdw_dai(int id)
return false;
}
-/**
- * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC audio card
- * @substream: The PCM substream from audio, as passed to snd_soc_ops->startup()
- *
- * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate and set
- * Soundwire stream runtime to each codec DAI.
- *
- * The shutdown() callback should call sdw_release_stream() on the same
- * sdw_stream_runtime.
- *
- * Return: 0 or errno
+/*
+ * Allocate a stream runtime for one direction and set it on the codec DAIs
+ * of that direction.
*/
-int qcom_snd_sdw_startup(struct snd_pcm_substream *substream)
+static int qcom_snd_sdw_setup_dir(struct snd_soc_pcm_runtime *rtd, int dir)
{
- 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);
- u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS];
+ const char *cpu_name = snd_soc_rtd_to_cpu(rtd, 0)->name;
struct sdw_stream_runtime *sruntime;
struct snd_soc_dai *codec_dai;
+ u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS];
u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
int ret, i, j;
+ bool used = false;
- if (!qcom_snd_is_sdw_dai(cpu_dai->id))
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
+ if (snd_soc_dai_stream_valid(codec_dai, dir)) {
+ used = true;
+ break;
+ }
+ }
+ if (!used)
return 0;
- sruntime = sdw_alloc_stream(cpu_dai->name, SDW_STREAM_PCM);
+ sruntime = qcom_snd_sdw_alloc_stream(cpu_name, dir);
if (!sruntime)
return -ENOMEM;
for_each_rtd_codec_dais(rtd, i, codec_dai) {
- ret = snd_soc_dai_set_stream(codec_dai, sruntime,
- substream->stream);
+ if (!snd_soc_dai_stream_valid(codec_dai, dir))
+ continue;
+
+ ret = snd_soc_dai_set_stream(codec_dai, sruntime, dir);
if (ret < 0 && ret != -ENOTSUPP) {
dev_err(rtd->dev, "Failed to set sdw stream on %s\n", codec_dai->name);
- goto err_set_stream;
+ goto err;
} else if (ret == -ENOTSUPP) {
- /* Ignore unsupported */
continue;
}
@@ -94,59 +139,108 @@ int qcom_snd_sdw_startup(struct snd_pcm_substream *substream)
&rx_ch_cnt, rx_ch);
if (ret != 0 && ret != -ENOTSUPP) {
dev_err(rtd->dev, "Failed to get codec chan map %s\n", codec_dai->name);
- goto err_set_stream;
- } else if (ret == -ENOTSUPP) {
- /* Ignore unsupported */
- continue;
+ goto err;
}
}
- switch (cpu_dai->id) {
+ switch (snd_soc_rtd_to_cpu(rtd, 0)->id) {
case RX_CODEC_DMA_RX_0:
case TX_CODEC_DMA_TX_3:
if (tx_ch_cnt || rx_ch_cnt) {
for_each_rtd_codec_dais(rtd, j, codec_dai) {
+ if (!snd_soc_dai_stream_valid(codec_dai, dir))
+ continue;
ret = snd_soc_dai_set_channel_map(codec_dai,
tx_ch_cnt, tx_ch,
rx_ch_cnt, rx_ch);
if (ret != 0 && ret != -ENOTSUPP)
- goto err_set_stream;
+ goto err;
}
}
}
return 0;
-
-err_set_stream:
- sdw_release_stream(sruntime);
-
+err:
+ qcom_snd_sdw_release_stream(sruntime);
return ret;
}
-EXPORT_SYMBOL_GPL(qcom_snd_sdw_startup);
-int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream,
- bool *stream_prepared)
+/**
+ * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC audio card
+ * @substream: The PCM substream from audio, as passed to snd_soc_ops->startup()
+ *
+ * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate and set
+ * Soundwire stream runtime to each codec DAI.
+ *
+ * The shutdown() callback should call sdw_release_stream() on the same
+ * sdw_stream_runtime.
+ *
+ * Return: 0 or errno
+ */
+int qcom_snd_sdw_startup(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_stream_runtime *sruntime;
int ret;
-
if (!qcom_snd_is_sdw_dai(cpu_dai->id))
return 0;
- sruntime = qcom_snd_sdw_get_stream(substream);
- if (!sruntime)
- return 0;
+ ret = qcom_snd_sdw_setup_dir(rtd, substream->stream);
+ if (ret)
+ return ret;
- if (*stream_prepared)
+ /* Also set up the stream of the other direction on such links */
+ if (rtd->dai_link->multi_direction_codecs) {
+ ret = qcom_snd_sdw_setup_dir(rtd, substream->stream ^ 1);
+ if (ret) {
+ struct sdw_stream_runtime *sr;
+
+ sr = sdw_find_dir_stream(rtd, substream->stream);
+ qcom_snd_sdw_release_stream(sr);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+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)
+{
+ struct sdw_stream_runtime *sruntime;
+ int ret;
+
+ sruntime = sdw_find_dir_stream(rtd, dir);
+ if (!sruntime)
return 0;
ret = sdw_prepare_stream(sruntime);
if (ret)
return ret;
+ ret = sdw_enable_stream(sruntime);
+ if (ret) {
+ sdw_deprepare_stream(sruntime);
+ return ret;
+ }
+ return 0;
+}
+
+int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream,
+ bool *stream_prepared)
+{
+ 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);
+ int ret;
+
+ if (!qcom_snd_is_sdw_dai(cpu_dai->id))
+ return 0;
+
+ if (*stream_prepared)
+ return 0;
+
/**
* NOTE: there is a strict hw requirement about the ordering of port
* enables and actual WSA881x PA enable. PA enable should only happen
@@ -154,15 +248,32 @@ 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 = sdw_enable_stream(sruntime);
- if (ret) {
- sdw_deprepare_stream(sruntime);
+ 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);
+
+ /* 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;
+ }
+ }
}
- *stream_prepared = true;
- return ret;
+ *stream_prepared = true;
+ return 0;
}
EXPORT_SYMBOL_GPL(qcom_snd_sdw_prepare);
@@ -188,9 +299,16 @@ EXPORT_SYMBOL_GPL(qcom_snd_sdw_get_stream);
void qcom_snd_sdw_shutdown(struct snd_pcm_substream *substream)
{
- struct sdw_stream_runtime *sruntime = qcom_snd_sdw_get_stream(substream);
+ struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+
+ qcom_snd_sdw_release_stream(sdw_find_dir_stream(rtd, substream->stream));
- sdw_release_stream(sruntime);
+ if (rtd->dai_link->multi_direction_codecs) {
+ struct sdw_stream_runtime *sr;
+
+ sr = sdw_find_dir_stream(rtd, substream->stream ^ 1);
+ qcom_snd_sdw_release_stream(sr);
+ }
}
EXPORT_SYMBOL_GPL(qcom_snd_sdw_shutdown);
@@ -198,18 +316,29 @@ 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 *sruntime;
+ struct sdw_stream_runtime *sr;
if (!qcom_snd_is_sdw_dai(cpu_dai->id))
return 0;
- sruntime = qcom_snd_sdw_get_stream(substream);
- if (sruntime && *stream_prepared) {
- sdw_disable_stream(sruntime);
- sdw_deprepare_stream(sruntime);
- *stream_prepared = false;
+ if (!*stream_prepared)
+ return 0;
+
+ sr = sdw_find_dir_stream(rtd, substream->stream);
+ if (sr) {
+ sdw_disable_stream(sr);
+ sdw_deprepare_stream(sr);
+ }
+
+ 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);
+ }
}
+ *stream_prepared = false;
return 0;
}
EXPORT_SYMBOL_GPL(qcom_snd_sdw_hw_free);
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (3 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
` (18 subsequent siblings)
23 siblings, 0 replies; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
The codec now has a VI sense capture DAI next to the playback DAI, so
boards which wire up speaker protection need to address them separately.
Allow '#sound-dai-cells' to be 1 for those, keeping 0 valid for the
boards which only use playback.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml b/Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml
index 866c5e780fb0..42ae6d60a874 100644
--- a/Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml
+++ b/Documentation/devicetree/bindings/sound/qcom,wsa8840.yaml
@@ -41,7 +41,10 @@ properties:
maxItems: 6
'#sound-dai-cells':
- const: 0
+ enum: [0, 1]
+ description:
+ Must be 1 on boards which use the VI sense capture DAI, so that the
+ playback and capture DAIs can be addressed separately.
vdd-1p8-supply: true
vdd-io-supply: true
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (4 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 12:38 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
` (17 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
The VI sense port carries the voltage and current sense data that DSP
speaker protection needs, but it is described as a sink port next to
the playback ports and has no DAI, so nothing can capture from it.
Make it a source port with its own capture DAI, ops and stream runtime,
and leave it out of the playback port list. sdw_get_slave_dpn_prop()
searches the sink port properties by count, so pack that array densely
now that VI sense is no longer in it.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/codecs/wsa884x.c | 97 ++++++++++++++++++++++++++++++++------
1 file changed, 82 insertions(+), 15 deletions(-)
diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
index f58ce92c46d4..abf9d88ec7a8 100644
--- a/sound/soc/codecs/wsa884x.c
+++ b/sound/soc/codecs/wsa884x.c
@@ -732,8 +732,11 @@ struct wsa884x_priv {
struct regulator_bulk_data supplies[WSA884X_SUPPLIES_NUM];
struct sdw_slave *slave;
struct sdw_stream_config sconfig;
+ struct sdw_stream_config vi_sconfig;
struct sdw_stream_runtime *sruntime;
+ struct sdw_stream_runtime *vi_sruntime;
struct sdw_port_config port_config[WSA884X_MAX_SWR_PORTS];
+ struct sdw_port_config vi_port_config;
struct gpio_desc *sd_n;
struct reset_control *sd_reset;
bool port_prepared[WSA884X_MAX_SWR_PORTS];
@@ -822,8 +825,8 @@ enum wsa884x_mode {
static const struct soc_enum wsa884x_dev_mode_enum =
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wsa884x_dev_mode_text), wsa884x_dev_mode_text);
-static struct sdw_dpn_prop wsa884x_sink_dpn_prop[WSA884X_MAX_SWR_PORTS] = {
- [WSA884X_PORT_DAC] = {
+static struct sdw_dpn_prop wsa884x_sink_dpn_prop[WSA884X_MAX_SWR_PORTS - 1] = {
+ {
.num = WSA884X_PORT_DAC + 1,
.type = SDW_DPN_SIMPLE,
.min_ch = 1,
@@ -831,7 +834,7 @@ static struct sdw_dpn_prop wsa884x_sink_dpn_prop[WSA884X_MAX_SWR_PORTS] = {
.simple_ch_prep_sm = true,
.read_only_wordlength = true,
},
- [WSA884X_PORT_COMP] = {
+ {
.num = WSA884X_PORT_COMP + 1,
.type = SDW_DPN_SIMPLE,
.min_ch = 1,
@@ -839,7 +842,7 @@ static struct sdw_dpn_prop wsa884x_sink_dpn_prop[WSA884X_MAX_SWR_PORTS] = {
.simple_ch_prep_sm = true,
.read_only_wordlength = true,
},
- [WSA884X_PORT_BOOST] = {
+ {
.num = WSA884X_PORT_BOOST + 1,
.type = SDW_DPN_SIMPLE,
.min_ch = 1,
@@ -847,7 +850,7 @@ static struct sdw_dpn_prop wsa884x_sink_dpn_prop[WSA884X_MAX_SWR_PORTS] = {
.simple_ch_prep_sm = true,
.read_only_wordlength = true,
},
- [WSA884X_PORT_PBR] = {
+ {
.num = WSA884X_PORT_PBR + 1,
.type = SDW_DPN_SIMPLE,
.min_ch = 1,
@@ -855,22 +858,25 @@ static struct sdw_dpn_prop wsa884x_sink_dpn_prop[WSA884X_MAX_SWR_PORTS] = {
.simple_ch_prep_sm = true,
.read_only_wordlength = true,
},
- [WSA884X_PORT_VISENSE] = {
- .num = WSA884X_PORT_VISENSE + 1,
+ {
+ .num = WSA884X_PORT_CPS + 1,
.type = SDW_DPN_SIMPLE,
.min_ch = 1,
- .max_ch = 2,
+ .max_ch = 1,
.simple_ch_prep_sm = true,
.read_only_wordlength = true,
- },
- [WSA884X_PORT_CPS] = {
- .num = WSA884X_PORT_CPS + 1,
+ }
+};
+
+static struct sdw_dpn_prop wsa884x_src_dpn_prop[] = {
+ {
+ .num = WSA884X_PORT_VISENSE + 1,
.type = SDW_DPN_SIMPLE,
.min_ch = 1,
- .max_ch = 1,
+ .max_ch = 2,
.simple_ch_prep_sm = true,
.read_only_wordlength = true,
- }
+ },
};
static const struct sdw_port_config wsa884x_pconfig[WSA884X_MAX_SWR_PORTS] = {
@@ -892,6 +898,7 @@ static const struct sdw_port_config wsa884x_pconfig[WSA884X_MAX_SWR_PORTS] = {
},
[WSA884X_PORT_VISENSE] = {
.num = WSA884X_PORT_VISENSE + 1,
+ /* V and I sense pair */
.ch_mask = 0x3,
},
[WSA884X_PORT_CPS] = {
@@ -1767,6 +1774,29 @@ static const struct snd_soc_component_driver wsa884x_component_drv = {
.num_dapm_routes = ARRAY_SIZE(wsa884x_audio_map),
};
+static int wsa884x_vi_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+ struct wsa884x_priv *wsa884x = dev_get_drvdata(dai->dev);
+ unsigned int num_ports = 0;
+
+ wsa884x->vi_sconfig.frame_rate = params_rate(params);
+ wsa884x->vi_sconfig.ch_count = 2;
+ wsa884x->vi_sconfig.bps = 1;
+ wsa884x->vi_sconfig.type = SDW_STREAM_PDM;
+ wsa884x->vi_sconfig.direction = SDW_DATA_DIR_TX;
+
+ if (wsa884x->port_enable[WSA884X_PORT_VISENSE]) {
+ wsa884x->vi_port_config = wsa884x_pconfig[WSA884X_PORT_VISENSE];
+ num_ports = 1;
+ }
+
+ return sdw_stream_add_slave(wsa884x->slave, &wsa884x->vi_sconfig,
+ &wsa884x->vi_port_config, num_ports,
+ wsa884x->vi_sruntime);
+}
+
static int wsa884x_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
@@ -1776,6 +1806,9 @@ static int wsa884x_hw_params(struct snd_pcm_substream *substream,
wsa884x->active_ports = 0;
for (i = 0; i < WSA884X_MAX_SWR_PORTS; i++) {
+ /* VISENSE is driven by the separate VI capture DAI */
+ if (i == WSA884X_PORT_VISENSE)
+ continue;
if (!wsa884x->port_enable[i])
continue;
@@ -1800,6 +1833,16 @@ static int wsa884x_hw_free(struct snd_pcm_substream *substream,
return 0;
}
+static int wsa884x_vi_hw_free(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct wsa884x_priv *wsa884x = dev_get_drvdata(dai->dev);
+
+ sdw_stream_remove_slave(wsa884x->slave, wsa884x->vi_sruntime);
+
+ return 0;
+}
+
static int wsa884x_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
{
struct snd_soc_component *component = dai->component;
@@ -1829,11 +1872,20 @@ static int wsa884x_set_stream(struct snd_soc_dai *dai,
{
struct wsa884x_priv *wsa884x = dev_get_drvdata(dai->dev);
- wsa884x->sruntime = stream;
+ if (direction == SNDRV_PCM_STREAM_CAPTURE)
+ wsa884x->vi_sruntime = stream;
+ else
+ wsa884x->sruntime = stream;
return 0;
}
+static const struct snd_soc_dai_ops wsa884x_vi_dai_ops = {
+ .hw_params = wsa884x_vi_hw_params,
+ .hw_free = wsa884x_vi_hw_free,
+ .set_stream = wsa884x_set_stream,
+};
+
static const struct snd_soc_dai_ops wsa884x_dai_ops = {
.hw_params = wsa884x_hw_params,
.hw_free = wsa884x_hw_free,
@@ -1856,6 +1908,19 @@ static struct snd_soc_dai_driver wsa884x_dais[] = {
},
.ops = &wsa884x_dai_ops,
},
+ {
+ .name = "VI",
+ .capture = {
+ .stream_name = "VI Capture",
+ .rates = WSA884X_RATES | WSA884X_FRAC_RATES,
+ .formats = WSA884X_FORMATS,
+ .rate_min = 8000,
+ .rate_max = 384000,
+ .channels_min = 1,
+ .channels_max = 2,
+ },
+ .ops = &wsa884x_vi_dai_ops,
+ },
};
static int wsa884x_get_temp(struct wsa884x_priv *wsa884x, long *temp)
@@ -2091,9 +2156,11 @@ static int wsa884x_probe(struct sdw_slave *pdev,
WSA884X_MAX_SWR_PORTS))
dev_dbg(dev, "Static Port mapping not specified\n");
- pdev->prop.sink_ports = GENMASK(WSA884X_MAX_SWR_PORTS - 1, 0);
+ pdev->prop.sink_ports = GENMASK(WSA884X_MAX_SWR_PORTS - 1, 0) & ~BIT(WSA884X_PORT_VISENSE);
+ pdev->prop.source_ports = BIT(WSA884X_PORT_VISENSE);
pdev->prop.simple_clk_stop_capable = true;
pdev->prop.sink_dpn_prop = wsa884x_sink_dpn_prop;
+ pdev->prop.src_dpn_prop = wsa884x_src_dpn_prop;
pdev->prop.scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY;
wsa884x_reset_deassert(wsa884x);
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 07/24] ASoC: codecs: wsa883x: add VI sense capture DAI
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (5 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 12:33 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
` (16 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
The speaker's VISENSE port carries the voltage and current sense data
the ADSP speaker protection VI module needs, but it was described as
a sink port alongside the playback ports and had no DAI, so nothing
could capture from it.
Move VISENSE into the source port mask with its own dpn property,
give it a capture DAI with its own ops and stream runtime, and skip
it when wsa883x_hw_params() builds the playback port list so the two
streams are configured independently.
Each VISENSE frame word carries the voltage sense in its low half
and the current sense in its high half, so this is a two channel
port; a single channel mask would deliver only half the pair to the
DSP. Matches what Qualcomm's own driver uses for both wsa883x and
wsa884x.
Also install a bus_config handler that programs SCP_HOST_CLK_DIV2 on
the next-bank slot: wsa883x needs this to agree with the controller
on the bus clock divider once a VI stream is enabled.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
sound/soc/codecs/wsa883x.c | 77 +++++++++++++++++++++++++++++++++++---
1 file changed, 71 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/wsa883x.c b/sound/soc/codecs/wsa883x.c
index 64391d654a08..6de669288d6a 100644
--- a/sound/soc/codecs/wsa883x.c
+++ b/sound/soc/codecs/wsa883x.c
@@ -437,6 +437,8 @@
#define WSA883X_VERSION_1_0 0
#define WSA883X_VERSION_1_1 1
+#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
+
#define WSA883X_MAX_SWR_PORTS 4
#define WSA883X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
@@ -468,8 +470,11 @@ struct wsa883x_priv {
struct regulator *vdd;
struct sdw_slave *slave;
struct sdw_stream_config sconfig;
+ struct sdw_stream_config vi_sconfig;
struct sdw_stream_runtime *sruntime;
+ struct sdw_stream_runtime *vi_sruntime;
struct sdw_port_config port_config[WSA883X_MAX_SWR_PORTS];
+ struct sdw_port_config vi_port_config;
struct gpio_desc *sd_n;
struct reset_control *sd_reset;
bool port_prepared[WSA883X_MAX_SWR_PORTS];
@@ -522,7 +527,7 @@ enum {
static const struct soc_enum wsa_dev_mode_enum =
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wsa_dev_mode_text), wsa_dev_mode_text);
-/* 4 ports */
+/* 3 sink ports, VISENSE is a source port */
static struct sdw_dpn_prop wsa_sink_dpn_prop[WSA883X_MAX_SWR_PORTS] = {
[WSA883X_PORT_DAC] = {
.num = WSA883X_PORT_DAC + 1,
@@ -548,14 +553,17 @@ static struct sdw_dpn_prop wsa_sink_dpn_prop[WSA883X_MAX_SWR_PORTS] = {
.simple_ch_prep_sm = true,
.read_only_wordlength = true,
},
- [WSA883X_PORT_VISENSE] = {
+};
+
+static struct sdw_dpn_prop wsa_src_dpn_prop[] = {
+ {
.num = WSA883X_PORT_VISENSE + 1,
.type = SDW_DPN_SIMPLE,
.min_ch = 1,
.max_ch = 2,
.simple_ch_prep_sm = true,
.read_only_wordlength = true,
- }
+ },
};
static const struct sdw_port_config wsa883x_pconfig[WSA883X_MAX_SWR_PORTS] = {
@@ -1125,8 +1133,16 @@ static int wsa883x_port_prep(struct sdw_slave *slave,
return 0;
}
+static int wsa883x_bus_config(struct sdw_slave *slave,
+ struct sdw_bus_params *params)
+{
+ sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01);
+ return 0;
+}
+
static const struct sdw_slave_ops wsa883x_slave_ops = {
.update_status = wsa883x_update_status,
+ .bus_config = wsa883x_bus_config,
.port_prep = wsa883x_port_prep,
};
@@ -1335,6 +1351,25 @@ static const struct snd_soc_component_driver wsa883x_component_drv = {
.num_dapm_routes = ARRAY_SIZE(wsa883x_audio_map),
};
+static int wsa883x_vi_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+ struct wsa883x_priv *wsa883x = dev_get_drvdata(dai->dev);
+
+ wsa883x->vi_port_config = wsa883x_pconfig[WSA883X_PORT_VISENSE];
+ wsa883x->vi_sconfig.frame_rate = params_rate(params);
+ /* VISENSE carries the V and I sense pair */
+ wsa883x->vi_sconfig.ch_count = 2;
+ wsa883x->vi_sconfig.bps = 1;
+ wsa883x->vi_sconfig.type = SDW_STREAM_PDM;
+ wsa883x->vi_sconfig.direction = SDW_DATA_DIR_TX;
+
+ return sdw_stream_add_slave(wsa883x->slave, &wsa883x->vi_sconfig,
+ &wsa883x->vi_port_config, 1,
+ wsa883x->vi_sruntime);
+}
+
static int wsa883x_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
@@ -1344,6 +1379,9 @@ static int wsa883x_hw_params(struct snd_pcm_substream *substream,
wsa883x->active_ports = 0;
for (i = 0; i < WSA883X_MAX_SWR_PORTS; i++) {
+ /* VISENSE is driven by the separate VI capture DAI */
+ if (i == WSA883X_PORT_VISENSE)
+ continue;
if (!wsa883x->port_enable[i])
continue;
@@ -1363,7 +1401,10 @@ static int wsa883x_hw_free(struct snd_pcm_substream *substream,
{
struct wsa883x_priv *wsa883x = dev_get_drvdata(dai->dev);
- sdw_stream_remove_slave(wsa883x->slave, wsa883x->sruntime);
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ sdw_stream_remove_slave(wsa883x->slave, wsa883x->vi_sruntime);
+ else
+ sdw_stream_remove_slave(wsa883x->slave, wsa883x->sruntime);
return 0;
}
@@ -1373,7 +1414,10 @@ static int wsa883x_set_sdw_stream(struct snd_soc_dai *dai,
{
struct wsa883x_priv *wsa883x = dev_get_drvdata(dai->dev);
- wsa883x->sruntime = stream;
+ if (direction == SNDRV_PCM_STREAM_CAPTURE)
+ wsa883x->vi_sruntime = stream;
+ else
+ wsa883x->sruntime = stream;
return 0;
}
@@ -1401,6 +1445,12 @@ static int wsa883x_digital_mute(struct snd_soc_dai *dai, int mute, int stream)
return 0;
}
+static const struct snd_soc_dai_ops wsa883x_vi_dai_ops = {
+ .hw_params = wsa883x_vi_hw_params,
+ .hw_free = wsa883x_hw_free,
+ .set_stream = wsa883x_set_sdw_stream,
+};
+
static const struct snd_soc_dai_ops wsa883x_dai_ops = {
.hw_params = wsa883x_hw_params,
.hw_free = wsa883x_hw_free,
@@ -1423,6 +1473,19 @@ static struct snd_soc_dai_driver wsa883x_dais[] = {
},
.ops = &wsa883x_dai_ops,
},
+ {
+ .name = "VI",
+ .capture = {
+ .stream_name = "VI Capture",
+ .rates = WSA883X_RATES | WSA883X_FRAC_RATES,
+ .formats = WSA883X_FORMATS,
+ .rate_min = 8000,
+ .rate_max = 352800,
+ .channels_min = 1,
+ .channels_max = 2,
+ },
+ .ops = &wsa883x_vi_dai_ops,
+ },
};
static int wsa883x_get_temp(struct wsa883x_priv *wsa883x, long *temp)
@@ -1636,9 +1699,11 @@ static int wsa883x_probe(struct sdw_slave *pdev,
WSA883X_MAX_SWR_PORTS))
dev_dbg(dev, "Static Port mapping not specified\n");
- pdev->prop.sink_ports = GENMASK(WSA883X_MAX_SWR_PORTS - 1, 0);
+ pdev->prop.sink_ports = GENMASK(WSA883X_PORT_BOOST, 0);
+ pdev->prop.source_ports = BIT(WSA883X_PORT_VISENSE);
pdev->prop.simple_clk_stop_capable = true;
pdev->prop.sink_dpn_prop = wsa_sink_dpn_prop;
+ pdev->prop.src_dpn_prop = wsa_src_dpn_prop;
pdev->prop.scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY;
wsa883x_reset_deassert(wsa883x);
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (6 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:34 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
` (15 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla,
kernel test robot
Speaker protection pairs each speaker's calibrated resistance with the
amplifier die temperature (T0) at the time, but an in-kernel user has
no way to read that temperature.
Register a tripless thermal zone over the existing temperature read,
named "wsa-<bus id>-<unique id>" so a user holding the codec's device
can find it with thermal_zone_get_zone_by_name(). Until the codec is
initialised, and while the PA is on with nothing cached yet, return
-EAGAIN to hwmon and no valid temperature to the thermal zone, instead
of a plausible looking zero. -EAGAIN would make the thermal core re-read
the zone every 250 ms and keep the codec awake.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/20261124071812.oiRgQnHg-lkp@intel.com/
---
sound/soc/codecs/wsa884x.c | 82 ++++++++++++++++++++++++++++++++++----
1 file changed, 74 insertions(+), 8 deletions(-)
diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
index abf9d88ec7a8..e5813ed139b3 100644
--- a/sound/soc/codecs/wsa884x.c
+++ b/sound/soc/codecs/wsa884x.c
@@ -23,6 +23,7 @@
#include <linux/soundwire/sdw_type.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
+#include <linux/thermal.h>
#include <sound/soc-dapm.h>
#include <sound/soc.h>
#include <sound/tlv.h>
@@ -1779,21 +1780,19 @@ static int wsa884x_vi_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct wsa884x_priv *wsa884x = dev_get_drvdata(dai->dev);
- unsigned int num_ports = 0;
+ if (!wsa884x->port_enable[WSA884X_PORT_VISENSE])
+ return 0;
+
+ wsa884x->vi_port_config = wsa884x_pconfig[WSA884X_PORT_VISENSE];
wsa884x->vi_sconfig.frame_rate = params_rate(params);
wsa884x->vi_sconfig.ch_count = 2;
wsa884x->vi_sconfig.bps = 1;
wsa884x->vi_sconfig.type = SDW_STREAM_PDM;
wsa884x->vi_sconfig.direction = SDW_DATA_DIR_TX;
- if (wsa884x->port_enable[WSA884X_PORT_VISENSE]) {
- wsa884x->vi_port_config = wsa884x_pconfig[WSA884X_PORT_VISENSE];
- num_ports = 1;
- }
-
return sdw_stream_add_slave(wsa884x->slave, &wsa884x->vi_sconfig,
- &wsa884x->vi_port_config, num_ports,
+ &wsa884x->vi_port_config, 1,
wsa884x->vi_sruntime);
}
@@ -1934,11 +1933,17 @@ static int wsa884x_get_temp(struct wsa884x_priv *wsa884x, long *temp)
guard(mutex)(&wsa884x->sp_lock);
+ /* OTP trims read back as zero until the codec is initialised. */
+ if (!wsa884x->hw_init)
+ return -EAGAIN;
+
if (wsa884x->pa_on) {
/*
* Reading temperature is possible only when Power Amplifier is
- * off. Report last cached data.
+ * off. Report last cached data if we have one, -EAGAIN otherwise.
*/
+ if (!wsa884x->temperature)
+ return -EAGAIN;
*temp = wsa884x->temperature * 1000;
return 0;
}
@@ -2060,6 +2065,38 @@ static const struct hwmon_chip_info wsa884x_hwmon_chip_info = {
.info = wsa884x_hwmon_info,
};
+static int wsa884x_tz_get_temp(struct thermal_zone_device *tz, int *temp_mdeg)
+{
+ struct wsa884x_priv *wsa884x = thermal_zone_device_priv(tz);
+ long mdeg;
+ int ret;
+
+ /* -EAGAIN means no reading yet; don't make the core poll the zone. */
+ ret = wsa884x_get_temp(wsa884x, &mdeg);
+ if (ret == -EAGAIN) {
+ *temp_mdeg = THERMAL_TEMP_INVALID;
+ return 0;
+ }
+ if (ret)
+ return ret;
+
+ *temp_mdeg = (int)mdeg;
+ return 0;
+}
+
+static const struct thermal_zone_params wsa884x_tzp = {
+ .no_hwmon = true,
+};
+
+static struct thermal_zone_device_ops wsa884x_tz_ops = {
+ .get_temp = wsa884x_tz_get_temp,
+};
+
+static void wsa884x_tz_unregister(void *data)
+{
+ thermal_zone_device_unregister(data);
+}
+
static void wsa884x_reset_powerdown(void *data)
{
struct wsa884x_priv *wsa884x = data;
@@ -2196,6 +2233,35 @@ static int wsa884x_probe(struct sdw_slave *pdev,
if (ret)
return ret;
+ if (IS_REACHABLE(CONFIG_THERMAL)) {
+ char tz_name[THERMAL_NAME_LENGTH];
+ struct thermal_zone_device *tz;
+
+ /*
+ * Register after runtime PM is enabled, as the zone is read
+ * right away. dev_name() is too long for a zone name.
+ */
+ scnprintf(tz_name, sizeof(tz_name), "wsa-%d-%u",
+ pdev->bus->id, pdev->id.unique_id);
+ tz = thermal_tripless_zone_device_register(tz_name,
+ wsa884x,
+ &wsa884x_tz_ops,
+ &wsa884x_tzp);
+ if (IS_ERR(tz)) {
+ dev_warn(dev,
+ "thermal zone '%s' registration failed (%ld); SP T0 kcontrol will read 0 for this codec\n",
+ tz_name, PTR_ERR(tz));
+ } else {
+ ret = devm_add_action_or_reset(dev,
+ wsa884x_tz_unregister,
+ tz);
+ if (ret)
+ return ret;
+
+ thermal_zone_device_enable(tz);
+ }
+ }
+
return devm_snd_soc_register_component(dev,
&wsa884x_component_drv,
wsa884x_dais,
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (7 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:35 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
` (14 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
The speaker protection modules exchange calibration state over a
control link, which the topology describes but the driver never sends
to the DSP.
Parse the control link tokens into a per-subgraph list and add them to
GRAPH_OPEN. Both subgraphs of a link usually declare it and the DSP
rejects a duplicate, so send each pair once.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
include/uapi/sound/snd_ar_tokens.h | 11 +++
sound/soc/qcom/qdsp6/audioreach.c | 90 +++++++++++++++++--
sound/soc/qcom/qdsp6/audioreach.h | 18 ++++
sound/soc/qcom/qdsp6/q6apm.c | 1 +
sound/soc/qcom/qdsp6/q6apm.h | 1 +
sound/soc/qcom/qdsp6/topology.c | 134 +++++++++++++++++++++++++++++
6 files changed, 250 insertions(+), 5 deletions(-)
diff --git a/include/uapi/sound/snd_ar_tokens.h b/include/uapi/sound/snd_ar_tokens.h
index cf8ab6b85e34..7ab8e11ca5c2 100644
--- a/include/uapi/sound/snd_ar_tokens.h
+++ b/include/uapi/sound/snd_ar_tokens.h
@@ -234,6 +234,17 @@ enum ar_event_types {
#define AR_TKN_U32_SUB_GRAPH_DIRECTION 4
#define AR_TKN_U32_SUB_GRAPH_SCENARIO_ID 5
+/* Control Link Tokens */
+#define AR_TKN_U32_CONTROL_LINK_IID 50
+#define AR_TKN_U32_CONTROL_LINK_PEER1_MOD_IID 51
+#define AR_TKN_U32_CONTROL_LINK_PEER1_MOD_PORT_ID 52
+#define AR_TKN_U32_CONTROL_LINK_PEER2_MOD_IID 53
+#define AR_TKN_U32_CONTROL_LINK_PEER2_MOD_PORT_ID 54
+#define AR_TKN_U32_CONTROL_LINK_INTENT0 55
+#define AR_TKN_U32_CONTROL_LINK_INTENT1 56
+#define AR_TKN_U32_CONTROL_LINK_INTENT2 57
+#define AR_TKN_U32_CONTROL_LINK_INTENT3 58
+
/* Container Tokens */
#define AR_TKN_U32_CONTAINER_INSTANCE_ID 100
#define AR_TKN_U32_CONTAINER_CAPABILITY_ID 101
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index 5b5289bf6d13..f66d3ff68a44 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -109,6 +109,26 @@ struct apm_mod_conn_list_params {
#define APM_MOD_CONN_PSIZE(p, n) ALIGN(struct_size(p, conn_obj, n), 8)
+/* Control Links */
+struct apm_control_link_obj {
+ u32 peer1_mod_inst_id;
+ u32 peer1_mod_port_id;
+ u32 peer2_mod_inst_id;
+ u32 peer2_mod_port_id;
+ u32 num_props;
+ struct apm_prop_data intent_data;
+ u32 num_intents;
+ u32 intent_id_list[MAX_INTENTS];
+} __packed;
+
+struct apm_mod_control_links_params {
+ struct apm_module_param_data param_data;
+ u32 num_ctrl_link_cfg;
+ struct apm_control_link_obj link_obj[];
+} __packed;
+
+#define APM_MOD_CTRL_LINK_PSIZE(p, n) ALIGN(struct_size(p, link_obj, n), 8)
+
struct apm_graph_open_params {
struct apm_cmd_header *cmd_header;
struct apm_sub_graph_params *sg_data;
@@ -116,6 +136,7 @@ struct apm_graph_open_params {
struct apm_module_list_params *mod_list_data;
struct apm_prop_list_params *mod_prop_data;
struct apm_mod_conn_list_params *mod_conn_list_data;
+ struct apm_mod_control_links_params *mod_control_links_data;
} __packed;
struct apm_pcm_module_media_fmt_cmd {
@@ -394,24 +415,26 @@ static void audioreach_populate_graph(struct q6apm *apm,
const struct list_head *sg_list,
int num_sub_graphs)
{
+ struct apm_mod_control_links_params *cl_data = open->mod_control_links_data;
struct apm_mod_conn_list_params *mc_data = open->mod_conn_list_data;
struct apm_module_list_params *ml_data = open->mod_list_data;
struct apm_prop_list_params *mp_data = open->mod_prop_data;
struct apm_container_params *c_data = open->cont_data;
struct apm_sub_graph_params *sg_data = open->sg_data;
- int ncontainer = 0, nmodule = 0, nconn = 0;
+ int ncontainer = 0, nmodule = 0, nconn = 0, nlink = 0;
struct apm_mod_prop_obj *module_prop_obj;
struct audioreach_container *container;
+ struct audioreach_control_link *clink;
+ struct apm_control_link_obj *clink_obj;
struct apm_module_conn_obj *conn_obj;
struct audioreach_module *module;
struct audioreach_sub_graph *sg;
struct apm_container_obj *cobj;
struct apm_mod_list_obj *mlobj;
- int i = 0;
+ int i = 0, j;
mlobj = &ml_data->mod_list_obj[0];
-
if (info->dst_mod_inst_id && info->src_mod_inst_id) {
conn_obj = &mc_data->conn_obj[nconn];
conn_obj->src_mod_inst_id = info->src_mod_inst_id;
@@ -426,6 +449,47 @@ static void audioreach_populate_graph(struct q6apm *apm,
apm_populate_sub_graph_config(sg_cfg, sg);
+ list_for_each_entry(clink, &sg->control_link_list, node) {
+ bool dup = false;
+ int k;
+
+ /* Both subgraphs usually declare the link, send it once */
+ for (k = 0; k < nlink; k++) {
+ struct apm_control_link_obj *o = &cl_data->link_obj[k];
+
+ if ((o->peer1_mod_inst_id == clink->peer1_mod_inst_id &&
+ o->peer2_mod_inst_id == clink->peer2_mod_inst_id) ||
+ (o->peer1_mod_inst_id == clink->peer2_mod_inst_id &&
+ o->peer2_mod_inst_id == clink->peer1_mod_inst_id)) {
+ dup = true;
+ break;
+ }
+ }
+ if (dup)
+ continue;
+
+ clink_obj = &cl_data->link_obj[nlink++];
+ clink_obj->peer1_mod_inst_id = clink->peer1_mod_inst_id;
+ clink_obj->peer1_mod_port_id = clink->peer1_mod_port_id;
+ clink_obj->peer2_mod_inst_id = clink->peer2_mod_inst_id;
+ clink_obj->peer2_mod_port_id = clink->peer2_mod_port_id;
+ clink_obj->intent_data.prop_id = APM_MODULE_PROP_ID_CTRL_LINK_INTENT_LIST;
+ clink_obj->num_props = 1;
+ clink_obj->num_intents = 0;
+
+ /* Pack the intents that are set into a dense list */
+ for (j = 0; j < MAX_INTENTS; j++) {
+ if (clink->intent[j])
+ clink_obj->intent_id_list[clink_obj->num_intents++] =
+ clink->intent[j];
+ }
+
+ /* The list length itself is part of the property payload */
+ clink_obj->intent_data.prop_size =
+ sizeof(clink_obj->num_intents) +
+ clink_obj->num_intents * sizeof(clink_obj->intent_id_list[0]);
+ }
+
list_for_each_entry(container, &sg->container_list, node) {
cobj = &c_data->cont_obj[ncontainer];
@@ -461,12 +525,16 @@ static void audioreach_populate_graph(struct q6apm *apm,
ncontainer++;
}
}
+
+ /* The dedupe above may have packed fewer links */
+ cl_data->num_ctrl_link_cfg = nlink;
}
void *audioreach_alloc_graph_pkt(struct q6apm *apm,
const struct audioreach_graph_info *info)
{
- int payload_size, sg_sz, cont_sz, ml_sz, mp_sz, mc_sz;
+ int payload_size, sg_sz, cl_sz, cont_sz, ml_sz, mp_sz, mc_sz;
+ struct apm_mod_control_links_params *clink_params;
struct apm_module_param_data *param_data;
struct apm_container_params *cont_params;
struct audioreach_container *container;
@@ -478,6 +546,7 @@ void *audioreach_alloc_graph_pkt(struct q6apm *apm,
struct audioreach_sub_graph *sgs;
struct apm_mod_list_obj *mlobj;
const struct list_head *sg_list;
+ int num_control_links = 0;
int num_connections = 0;
int num_containers = 0;
int num_sub_graphs = 0;
@@ -495,6 +564,7 @@ void *audioreach_alloc_graph_pkt(struct q6apm *apm,
list_for_each_entry(sgs, sg_list, node) {
num_sub_graphs++;
+ num_control_links += sgs->num_control_links;
list_for_each_entry(container, &sgs->container_list, node) {
num_containers++;
num_modules += container->num_modules;
@@ -510,13 +580,14 @@ void *audioreach_alloc_graph_pkt(struct q6apm *apm,
num_modules_list = num_containers;
sg_sz = APM_SUB_GRAPH_PSIZE(sg_params, num_sub_graphs);
cont_sz = APM_CONTAINER_PSIZE(cont_params, num_containers);
+ cl_sz = APM_MOD_CTRL_LINK_PSIZE(clink_params, num_control_links);
ml_sz = ALIGN(ml_sz, 8);
mp_sz = APM_MOD_PROP_PSIZE(mprop, num_modules);
mc_sz = APM_MOD_CONN_PSIZE(mcon, num_connections);
- payload_size = sg_sz + cont_sz + ml_sz + mp_sz + mc_sz;
+ payload_size = sg_sz + cl_sz + cont_sz + ml_sz + mp_sz + mc_sz;
pkt = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_GRAPH_OPEN, 0);
if (IS_ERR(pkt))
return pkt;
@@ -568,6 +639,15 @@ void *audioreach_alloc_graph_pkt(struct q6apm *apm,
params.mod_conn_list_data->num_connections = num_connections;
p += mc_sz;
+ /* Control Links */
+ params.mod_control_links_data = p;
+ param_data = ¶ms.mod_control_links_data->param_data;
+ param_data->module_instance_id = APM_MODULE_INSTANCE_ID;
+ param_data->param_id = APM_PARAM_ID_MODULE_CTRL_LINK_CFG;
+ param_data->param_size = cl_sz - APM_MODULE_PARAM_DATA_SIZE;
+ params.mod_control_links_data->num_ctrl_link_cfg = num_control_links;
+ p += cl_sz;
+
audioreach_populate_graph(apm, info, ¶ms, sg_list, num_sub_graphs);
return pkt;
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index 542775f493f1..ea8679e41488 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -172,6 +172,9 @@ struct apm_module_conn_obj {
uint32_t dst_mod_ip_port_id;
} __packed;
+#define APM_PARAM_ID_MODULE_CTRL_LINK_CFG 0x08001061
+#define APM_MODULE_PROP_ID_CTRL_LINK_INTENT_LIST 0x08001062
+
#define APM_PARAM_ID_GAIN 0x08001006
struct param_id_gain_cfg {
@@ -893,6 +896,19 @@ struct audioreach_graph_info {
uint32_t dst_mod_ip_port_id;
};
+#define MAX_INTENTS 4
+
+struct audioreach_control_link {
+ uint32_t id;
+ uint32_t peer1_mod_inst_id;
+ uint32_t peer1_mod_port_id;
+ uint32_t peer2_mod_inst_id;
+ uint32_t peer2_mod_port_id;
+ uint32_t intent[MAX_INTENTS];
+ struct list_head node;
+ struct audioreach_sub_graph *sub_graph;
+};
+
struct audioreach_sub_graph {
uint32_t sub_graph_id;
uint32_t perf_mode;
@@ -903,6 +919,8 @@ struct audioreach_sub_graph {
struct audioreach_graph_info *info;
uint32_t num_containers;
struct list_head container_list;
+ uint32_t num_control_links;
+ struct list_head control_link_list;
};
struct audioreach_container {
diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
index 4cb597d737b1..968fb7898aa4 100644
--- a/sound/soc/qcom/qdsp6/q6apm.c
+++ b/sound/soc/qcom/qdsp6/q6apm.c
@@ -900,6 +900,7 @@ static int apm_probe(gpr_device_t *gdev)
idr_init(&apm->graph_info_idr);
idr_init(&apm->sub_graphs_idr);
idr_init(&apm->containers_idr);
+ idr_init(&apm->control_links_idr);
idr_init(&apm->modules_idr);
diff --git a/sound/soc/qcom/qdsp6/q6apm.h b/sound/soc/qcom/qdsp6/q6apm.h
index 9092359ccf90..96409075b294 100644
--- a/sound/soc/qcom/qdsp6/q6apm.h
+++ b/sound/soc/qcom/qdsp6/q6apm.h
@@ -67,6 +67,7 @@ struct q6apm {
struct idr graph_info_idr;
struct idr sub_graphs_idr;
struct idr containers_idr;
+ struct idr control_links_idr;
struct idr modules_idr;
};
diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
index aa2ab2b058d0..5dd7f2c51d5c 100644
--- a/sound/soc/qcom/qdsp6/topology.c
+++ b/sound/soc/qcom/qdsp6/topology.c
@@ -97,6 +97,7 @@ static struct audioreach_sub_graph *audioreach_tplg_alloc_sub_graph(struct q6apm
return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&sg->container_list);
+ INIT_LIST_HEAD(&sg->control_link_list);
mutex_lock(&apm->lock);
ret = idr_alloc_u32(&apm->sub_graphs_idr, sg, &sub_graph_id, sub_graph_id, GFP_KERNEL);
@@ -113,6 +114,51 @@ static struct audioreach_sub_graph *audioreach_tplg_alloc_sub_graph(struct q6apm
return sg;
}
+static struct audioreach_control_link *audioreach_tplg_alloc_control_link(struct q6apm *apm,
+ struct audioreach_sub_graph *sg,
+ uint32_t control_link_id,
+ bool *found)
+{
+ struct audioreach_control_link *link;
+ int ret;
+
+ if (!control_link_id)
+ return ERR_PTR(-EINVAL);
+
+ mutex_lock(&apm->lock);
+ link = idr_find(&apm->control_links_idr, control_link_id);
+ mutex_unlock(&apm->lock);
+
+ if (link) {
+ *found = true;
+ return link;
+ }
+ *found = false;
+
+ link = kzalloc_obj(*link);
+ if (!link)
+ return ERR_PTR(-ENOMEM);
+
+ mutex_lock(&apm->lock);
+ ret = idr_alloc_u32(&apm->control_links_idr, link, &control_link_id, control_link_id,
+ GFP_KERNEL);
+ mutex_unlock(&apm->lock);
+
+ if (ret < 0) {
+ dev_err(apm->dev, "Failed to allocate Control Link ID (%x)\n", control_link_id);
+ kfree(link);
+ return ERR_PTR(ret);
+ }
+
+ link->id = control_link_id;
+ link->sub_graph = sg;
+ /* add to control link list */
+ list_add_tail(&link->node, &sg->control_link_list);
+ sg->num_control_links++;
+
+ return link;
+}
+
static struct audioreach_container *audioreach_tplg_alloc_container(struct q6apm *apm,
struct audioreach_sub_graph *sg,
uint32_t container_id,
@@ -348,6 +394,85 @@ audioreach_get_module_priv_data(const struct snd_soc_tplg_private *private)
return NULL;
}
+static void audioreach_parse_control_link_tokens(struct q6apm *apm,
+ struct audioreach_control_link *link,
+ const struct snd_soc_tplg_vendor_array *cl_array)
+{
+ const struct snd_soc_tplg_vendor_value_elem *cl_elem = cl_array->value;
+ int tkn_count = 0;
+
+ while (tkn_count <= (le32_to_cpu(cl_array->num_elems) - 1)) {
+ switch (le32_to_cpu(cl_elem->token)) {
+ case AR_TKN_U32_CONTROL_LINK_IID:
+ link->id = le32_to_cpu(cl_elem->value);
+ break;
+ case AR_TKN_U32_CONTROL_LINK_PEER1_MOD_IID:
+ link->peer1_mod_inst_id = le32_to_cpu(cl_elem->value);
+ break;
+ case AR_TKN_U32_CONTROL_LINK_PEER1_MOD_PORT_ID:
+ link->peer1_mod_port_id = le32_to_cpu(cl_elem->value);
+ break;
+ case AR_TKN_U32_CONTROL_LINK_PEER2_MOD_IID:
+ link->peer2_mod_inst_id = le32_to_cpu(cl_elem->value);
+ break;
+ case AR_TKN_U32_CONTROL_LINK_PEER2_MOD_PORT_ID:
+ link->peer2_mod_port_id = le32_to_cpu(cl_elem->value);
+ break;
+ case AR_TKN_U32_CONTROL_LINK_INTENT0:
+ link->intent[0] = le32_to_cpu(cl_elem->value);
+ break;
+ case AR_TKN_U32_CONTROL_LINK_INTENT1:
+ link->intent[1] = le32_to_cpu(cl_elem->value);
+ break;
+ case AR_TKN_U32_CONTROL_LINK_INTENT2:
+ link->intent[2] = le32_to_cpu(cl_elem->value);
+ break;
+ case AR_TKN_U32_CONTROL_LINK_INTENT3:
+ link->intent[3] = le32_to_cpu(cl_elem->value);
+ break;
+ default:
+ dev_err(apm->dev, "Not a valid token %d for control link graph\n",
+ le32_to_cpu(cl_elem->token));
+ break;
+ }
+ tkn_count++;
+ cl_elem++;
+ }
+}
+
+static void audioreach_parse_cl_tokens(struct q6apm *apm, struct audioreach_sub_graph *sg,
+ const struct snd_soc_tplg_private *private)
+{
+ const struct snd_soc_tplg_vendor_value_elem *cl_elem;
+ const struct snd_soc_tplg_vendor_array *cl_array;
+ struct audioreach_control_link *link;
+ int link_id, tkn_count, sz;
+ bool found = false;
+
+ for (sz = 0; sz < le32_to_cpu(private->size);) {
+ cl_array = (struct snd_soc_tplg_vendor_array *)((u8 *)private->array + sz);
+ cl_elem = cl_array->value;
+ sz = sz + le32_to_cpu(cl_array->size);
+ tkn_count = 0;
+
+ /* Module config blobs are not token tuples, stop here */
+ if (le32_to_cpu(cl_array->type) == SND_SOC_AR_TPLG_MODULE_CFG_TYPE)
+ break;
+
+ while (tkn_count <= (le32_to_cpu(cl_array->num_elems) - 1)) {
+ if (le32_to_cpu(cl_elem->token) == AR_TKN_U32_CONTROL_LINK_IID) {
+ link_id = le32_to_cpu(cl_elem->value);
+ link = audioreach_tplg_alloc_control_link(apm, sg, link_id, &found);
+ /* Skip on error or already parsed control link data */
+ if (!IS_ERR(link) && !found)
+ audioreach_parse_control_link_tokens(apm, link, cl_array);
+ }
+ tkn_count++;
+ cl_elem++;
+ }
+ }
+}
+
static struct audioreach_sub_graph *audioreach_parse_sg_tokens(struct q6apm *apm,
const struct snd_soc_tplg_private *private)
{
@@ -617,6 +742,8 @@ static int audioreach_widget_load_module_common(struct snd_soc_component *compon
if (IS_ERR(sg))
return PTR_ERR(sg);
+ audioreach_parse_cl_tokens(apm, sg, &tplg_w->priv);
+
cont = audioreach_parse_cont_tokens(apm, sg, &tplg_w->priv);
if (IS_ERR(cont))
return PTR_ERR(cont);
@@ -1108,6 +1235,13 @@ static int audioreach_widget_unload(struct snd_soc_component *scomp,
/* check if there are no more containers in the sub graph and remove it */
if (list_empty(&sg->container_list)) {
struct audioreach_graph_info *info = sg->info;
+ struct audioreach_control_link *link, *tmp;
+
+ list_for_each_entry_safe(link, tmp, &sg->control_link_list, node) {
+ idr_remove(&apm->control_links_idr, link->id);
+ list_del(&link->node);
+ kfree(link);
+ }
idr_remove(&apm->sub_graphs_idr, sg->sub_graph_id);
list_del(&sg->node);
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (8 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:32 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
` (13 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Put the speaker protection and VI modules in calibration mode, number
the V/I channel pairs consecutively (the VI capture packs one pair per
speaker without gaps), and support up to MAX_SP_VI_SPEAKERS (4) speakers
to cover laptops with four WSAs.
Register for EVENT_ID_VI_PER_SPKR_CALIBRATION on the VI module so each
speaker's state and measured resistance are reported on their own, and
dispatch the event from q6apm's graph callback into
audioreach_vi_calibration_event(). The initial handler just logs each
event at debug level; later patches add result caching and a userspace
trigger on top.
The module event registration is scoped to the graph: the DSP releases
it automatically when the graph is closed on stream close, so no explicit
unregister is needed on the driver side.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/codecs/wsa884x.c | 20 +++----
sound/soc/qcom/qdsp6/audioreach.c | 90 ++++++++++++++++++++++++-------
sound/soc/qcom/qdsp6/audioreach.h | 57 ++++++++++++++++++++
sound/soc/qcom/qdsp6/q6apm.c | 26 +++++++++
4 files changed, 165 insertions(+), 28 deletions(-)
diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
index e5813ed139b3..d0a00aced220 100644
--- a/sound/soc/codecs/wsa884x.c
+++ b/sound/soc/codecs/wsa884x.c
@@ -1933,10 +1933,6 @@ static int wsa884x_get_temp(struct wsa884x_priv *wsa884x, long *temp)
guard(mutex)(&wsa884x->sp_lock);
- /* OTP trims read back as zero until the codec is initialised. */
- if (!wsa884x->hw_init)
- return -EAGAIN;
-
if (wsa884x->pa_on) {
/*
* Reading temperature is possible only when Power Amplifier is
@@ -2071,7 +2067,15 @@ static int wsa884x_tz_get_temp(struct thermal_zone_device *tz, int *temp_mdeg)
long mdeg;
int ret;
- /* -EAGAIN means no reading yet; don't make the core poll the zone. */
+ /*
+ * OTP trims read back as zero until the codec is initialised. Report
+ * no reading rather than -EAGAIN, which makes the core poll the zone.
+ */
+ if (!wsa884x->hw_init) {
+ *temp_mdeg = THERMAL_TEMP_INVALID;
+ return 0;
+ }
+
ret = wsa884x_get_temp(wsa884x, &mdeg);
if (ret == -EAGAIN) {
*temp_mdeg = THERMAL_TEMP_INVALID;
@@ -2084,10 +2088,6 @@ static int wsa884x_tz_get_temp(struct thermal_zone_device *tz, int *temp_mdeg)
return 0;
}
-static const struct thermal_zone_params wsa884x_tzp = {
- .no_hwmon = true,
-};
-
static struct thermal_zone_device_ops wsa884x_tz_ops = {
.get_temp = wsa884x_tz_get_temp,
};
@@ -2246,7 +2246,7 @@ static int wsa884x_probe(struct sdw_slave *pdev,
tz = thermal_tripless_zone_device_register(tz_name,
wsa884x,
&wsa884x_tz_ops,
- &wsa884x_tzp);
+ NULL);
if (IS_ERR(tz)) {
dev_warn(dev,
"thermal zone '%s' registration failed (%ld); SP T0 kcontrol will read 0 for this codec\n",
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index f66d3ff68a44..c7444f8598c8 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -1436,6 +1436,22 @@ static int audioreach_gain_set(struct q6apm_graph *graph,
return q6apm_send_cmd_sync(graph->apm, pkt, 0);
}
+void audioreach_vi_calibration_event(struct device *dev,
+ const struct event_id_vi_per_spkr_calibration *cali,
+ u32 num_ch)
+{
+ unsigned int i;
+
+ /* A payload with no entries gives no new information */
+ if (!num_ch)
+ return;
+
+ /* Raised every frame; keep the per-event log at debug level */
+ for (i = 0; i < num_ch; i++)
+ dev_dbg(dev, "VI calibration channel %u: state %u\n",
+ i, cali->cali_param[i].state);
+}
+
static int audioreach_speaker_protection(struct q6apm_graph *graph,
const struct audioreach_module *module,
uint32_t operation_mode)
@@ -1444,6 +1460,35 @@ static int audioreach_speaker_protection(struct q6apm_graph *graph,
operation_mode);
}
+static int audioreach_register_events(struct q6apm_graph *graph,
+ const struct audioreach_module *module)
+{
+ struct apm_module_register_events *payload;
+ struct gpr_pkt *pkt;
+ int rc, payload_size;
+ void *p;
+
+ /* No event config payload, the packet is zeroed on allocation */
+ payload_size = ALIGN(sizeof(struct apm_module_register_events), 8);
+ pkt = audioreach_alloc_cmd_pkt(payload_size, APM_CMD_REGISTER_MODULE_EVENTS,
+ 0, graph->port->id, module->instance_id);
+ if (IS_ERR(pkt))
+ return PTR_ERR(pkt);
+
+ p = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
+
+ payload = p;
+ payload->module_instance_id = module->instance_id;
+ payload->event_id = EVENT_ID_VI_PER_SPKR_CALIBRATION;
+ payload->is_register = 1;
+
+ rc = audioreach_graph_send_cmd_sync(graph, pkt, 0);
+
+ kfree(pkt);
+
+ return rc;
+}
+
static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
const struct audioreach_module *module,
const struct audioreach_module_config *mcfg)
@@ -1454,18 +1499,30 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
struct apm_module_sp_vi_ex_mode_cfg *ex_cfg;
int op_sz, cm_sz, ex_sz;
struct apm_module_param_data *param_data;
- int rc, i, payload_size, j;
+ int rc, i, j, payload_size;
struct gpr_pkt *pkt;
+ u32 num_speakers;
void *p;
- if (num_channels > 2) {
+ if (num_channels > MAX_SP_VI_SPEAKERS) {
dev_err(graph->dev, "Error: Invalid channels (%d)!\n", num_channels);
return -EINVAL;
}
- op_sz = APM_SP_VI_OP_MODE_CFG_PSIZE(num_channels);
+ /* One 32-bit V/I word per speaker, so channels == speakers */
+ num_speakers = num_channels;
+ if (!num_speakers) {
+ dev_err(graph->dev, "Error: VI needs at least one channel\n");
+ return -EINVAL;
+ }
+
+ rc = audioreach_register_events(graph, module);
+ if (rc)
+ return rc;
+
+ op_sz = APM_SP_VI_OP_MODE_CFG_PSIZE(num_speakers);
/* Channel mapping for Isense and Vsense, thus twice number of speakers. */
- cm_sz = APM_SP_VI_CH_MAP_CFG_PSIZE(num_channels * 2);
+ cm_sz = APM_SP_VI_CH_MAP_CFG_PSIZE(num_speakers * 2);
ex_sz = APM_SP_VI_EX_MODE_CFG_PSIZE;
payload_size = op_sz + cm_sz + ex_sz;
@@ -1483,8 +1540,9 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
param_data->param_id = PARAM_ID_SP_VI_OP_MODE_CFG;
param_data->param_size = op_sz - APM_MODULE_PARAM_DATA_SIZE;
- op_cfg->cfg.num_channels = num_channels;
- op_cfg->cfg.operation_mode = PARAM_ID_SP_VI_OP_MODE_NORMAL;
+ /* The DSP calls this field num_speakers for the VI module */
+ op_cfg->cfg.num_channels = num_speakers;
+ op_cfg->cfg.operation_mode = PARAM_ID_SP_VI_OP_MODE_CALIBRATION;
p += op_sz;
cm_cfg = p;
@@ -1494,20 +1552,15 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
param_data->param_id = PARAM_ID_SP_VI_CHANNEL_MAP_CFG;
param_data->param_size = cm_sz - APM_MODULE_PARAM_DATA_SIZE;
- cm_cfg->cfg.num_channels = num_channels * 2;
- /* Convert the physical mapping to a logical mapping of the channels */
- for (i = 0, j = 0; i < PCM_MAX_NUM_CHANNEL && j < num_channels; i++) {
+ cm_cfg->cfg.num_channels = num_speakers * 2;
+ /* Number the V/I pairs consecutively, the capture has no gaps */
+ for (i = 0, j = 0; i < PCM_MAX_NUM_CHANNEL && j < num_speakers; i++) {
if (!mcfg->channel_map[i])
continue;
- /*
- * Map speakers into Vsense and then Isense of each channel.
- * E.g. for PCM_CHANNEL_FL and PCM_CHANNEL_FR to:
- * [1, 2, 3, 4]
- */
- cm_cfg->cfg.channel_mapping[2 * j] = (mcfg->channel_map[i] - 1) * 2 + 1;
- cm_cfg->cfg.channel_mapping[2 * j + 1] = (mcfg->channel_map[i] - 1) * 2 + 2;
- ++j;
+ cm_cfg->cfg.channel_mapping[2 * j] = 2 * j + 1;
+ cm_cfg->cfg.channel_mapping[2 * j + 1] = 2 * j + 2;
+ j++;
}
p += cm_sz;
@@ -1581,7 +1634,7 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
break;
case MODULE_ID_SPEAKER_PROTECTION:
rc = audioreach_speaker_protection(graph, module,
- PARAM_ID_SP_OP_MODE_NORMAL);
+ PARAM_ID_SP_OP_MODE_CALIBRATION);
if (!rc)
rc = audioreach_module_enable(graph, module, true);
@@ -1590,6 +1643,7 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
rc = audioreach_speaker_protection_vi(graph, module, cfg);
if (!rc)
rc = audioreach_module_enable(graph, module, true);
+
break;
case MODULE_ID_AUDIO_IF_SOURCE:
case MODULE_ID_AUDIO_IF_SINK:
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index ea8679e41488..062727d09612 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -697,6 +697,8 @@ struct param_id_sp_op_mode {
/* Speaker Protection VI */
+#define MAX_SP_VI_SPEAKERS 4
+
#define PARAM_ID_SP_VI_OP_MODE_CFG 0x080011f4
#define PARAM_ID_SP_VI_OP_MODE_NORMAL 0
#define PARAM_ID_SP_VI_OP_MODE_CALIBRATION 1
@@ -721,6 +723,58 @@ struct param_id_sp_vi_channel_map_cfg {
uint32_t channel_mapping[];
} __packed;
+/* VI per-speaker calibration event, raised every frame in calibration mode */
+#define EVENT_ID_VI_PER_SPKR_CALIBRATION 0x08001511
+
+/**
+ * enum vi_calibration_state - Calibration state of one speaker
+ * @VI_CALIBRATION_STATE_INCORRECT_OP_MODE: Not in calibration operation mode
+ * @VI_CALIBRATION_STATE_INACTIVE: Port not started
+ * @VI_CALIBRATION_STATE_WARMUP: Warming up
+ * @VI_CALIBRATION_STATE_INPROGRESS: Calibration running
+ * @VI_CALIBRATION_STATE_SUCCESS: R0/T0 within range
+ * @VI_CALIBRATION_STATE_FAILED: R0/T0 out of range
+ * @VI_CALIBRATION_STATE_WAIT_FOR_VI: Waiting for the V/I level to rise
+ * @VI_CALIBRATION_STATE_VI_WAIT_TIMED_OUT: Gave up waiting for the V/I level
+ * @VI_CALIBRATION_STATE_LOW_VI: V/I level fell below the threshold mid-run
+ *
+ * Reported by struct vi_per_spkr_calib_param.state. The DSP chooses these
+ * values, so they are fixed and must not be renumbered.
+ */
+enum vi_calibration_state {
+ VI_CALIBRATION_STATE_INCORRECT_OP_MODE = 0,
+ VI_CALIBRATION_STATE_INACTIVE = 1,
+ VI_CALIBRATION_STATE_WARMUP = 2,
+ VI_CALIBRATION_STATE_INPROGRESS = 3,
+ VI_CALIBRATION_STATE_SUCCESS = 4,
+ VI_CALIBRATION_STATE_FAILED = 5,
+ VI_CALIBRATION_STATE_WAIT_FOR_VI = 6,
+ VI_CALIBRATION_STATE_VI_WAIT_TIMED_OUT = 7,
+ VI_CALIBRATION_STATE_LOW_VI = 8,
+};
+
+/**
+ * struct vi_per_spkr_calib_param - Per-speaker calibration result
+ * @state: Calibration state of this speaker.
+ * @r0_cali_q24: Measured DC resistance in ohms, Q24. Filled in regardless of
+ * @state, so it is meaningful for both VI_CALIBRATION_STATE_SUCCESS
+ * and VI_CALIBRATION_STATE_FAILED.
+ */
+struct vi_per_spkr_calib_param {
+ uint32_t state;
+ int32_t r0_cali_q24;
+} __packed;
+
+/**
+ * struct event_id_vi_per_spkr_calibration - Per-speaker VI calibration result
+ * @num_ch: Number of speakers the result covers.
+ * @cali_param: Per-speaker calibration state and measured resistance.
+ */
+struct event_id_vi_per_spkr_calibration {
+ uint32_t num_ch;
+ struct vi_per_spkr_calib_param cali_param[];
+} __packed;
+
#define PARAM_ID_SAL_OUTPUT_CFG 0x08001016
struct param_id_sal_output_config {
uint32_t bits_per_sample;
@@ -1059,6 +1113,9 @@ int audioreach_gain_set_vol_ctrl(struct q6apm *apm,
int audioreach_send_u32_param(struct q6apm_graph *graph,
const struct audioreach_module *module,
uint32_t param_id, uint32_t param_val);
+void audioreach_vi_calibration_event(struct device *dev,
+ const struct event_id_vi_per_spkr_calibration *cali,
+ u32 num_ch);
int audioreach_compr_set_param(struct q6apm_graph *graph,
const struct audioreach_module_config *mcfg);
int audioreach_setup_push_pull(struct q6apm_graph *graph, phys_addr_t bphys,
diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
index 968fb7898aa4..c410e2f6e6a3 100644
--- a/sound/soc/qcom/qdsp6/q6apm.c
+++ b/sound/soc/qcom/qdsp6/q6apm.c
@@ -562,6 +562,29 @@ int q6apm_get_hw_pointer(struct q6apm_graph *graph, int dir)
}
EXPORT_SYMBOL_GPL(q6apm_get_hw_pointer);
+static void q6apm_vi_calibration_event(struct device *dev,
+ const struct apm_module_event *event,
+ int payload_size)
+{
+ const struct event_id_vi_per_spkr_calibration *cali;
+ u32 num_ch;
+
+ if (payload_size < 0 || payload_size < (int)(sizeof(*event) + sizeof(*cali))) {
+ dev_err(dev, "VI calibration event truncated (%d bytes)\n",
+ payload_size);
+ return;
+ }
+
+ cali = (const struct event_id_vi_per_spkr_calibration *)(event + 1);
+
+ /* Bound the array by the received payload, not by num_ch alone */
+ num_ch = (payload_size - sizeof(*event) - sizeof(*cali)) / sizeof(cali->cali_param[0]);
+ num_ch = min_t(u32, cali->num_ch, num_ch);
+ num_ch = min_t(u32, num_ch, MAX_SP_VI_SPEAKERS);
+
+ audioreach_vi_calibration_event(dev, cali, num_ch);
+}
+
static int graph_callback(const struct gpr_resp_pkt *data, void *priv, int op)
{
struct data_cmd_rsp_rd_sh_mem_ep_data_buffer_done_v2 *rd_done;
@@ -585,6 +608,9 @@ static int graph_callback(const struct gpr_resp_pkt *data, void *priv, int op)
client_event = APM_CLIENT_EVENT_WATERMARK_EVENT;
graph->cb(client_event, hdr->token, data->payload, graph->priv);
break;
+ case EVENT_ID_VI_PER_SPKR_CALIBRATION:
+ q6apm_vi_calibration_event(dev, event, data->payload_size);
+ break;
}
break;
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (9 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
` (12 subsequent siblings)
23 siblings, 0 replies; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
The speaker protection VI capture carries one 32-bit V/I word per
speaker. Add S32_LE to the q6apm-dai formats so it is not converted.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/qdsp6/q6apm-dai.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
index 3d667d7c612e..f7ac0b455b2d 100644
--- a/sound/soc/qcom/qdsp6/q6apm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
@@ -205,7 +205,8 @@ static const struct snd_pcm_hardware q6apm_dai_hardware_capture = {
SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
SNDRV_PCM_INFO_NO_REWINDS | SNDRV_PCM_INFO_SYNC_APPLPTR |
SNDRV_PCM_INFO_BATCH),
- .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE),
+ .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
+ SNDRV_PCM_FMTBIT_S32_LE),
.rates = SNDRV_PCM_RATE_8000_48000,
.rate_min = 8000,
.rate_max = 48000,
@@ -225,7 +226,8 @@ static const struct snd_pcm_hardware q6apm_dai_hardware_playback = {
SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
SNDRV_PCM_INFO_NO_REWINDS | SNDRV_PCM_INFO_SYNC_APPLPTR |
SNDRV_PCM_INFO_BATCH),
- .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE),
+ .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
+ SNDRV_PCM_FMTBIT_S32_LE),
.rates = SNDRV_PCM_RATE_8000_192000,
.rate_min = 8000,
.rate_max = 192000,
@@ -784,6 +786,9 @@ static int q6apm_dai_hw_params(struct snd_soc_component *component,
case SNDRV_PCM_FORMAT_S24_LE:
prtd->bits_per_sample = 24;
break;
+ case SNDRV_PCM_FORMAT_S32_LE:
+ prtd->bits_per_sample = 32;
+ break;
default:
return -EINVAL;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (10 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:32 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
` (11 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
The VI module reports EVENT_ID_VI_PER_SPKR_CALIBRATION every frame for
the whole run, which lets the earlier simple handler flood the log and
drop the measured resistance.
Keep a per-speaker cache (R0 and seen-states bitmap) protected by a
mutex, log each state once per speaker, and record the measured R0
once every speaker has reached a terminal state. Log R0 for a
successful speaker at info level and for a failed one as out of range.
The cache carries an explicit "armed" flag that is set at the start
of each configure of the VI module. The first event of a run clears
the previous result, so a graph prepared and stopped before the DSP
reports -- for example a sound server probing the PCM after a
calibration -- does not wipe a successful result. Turn the
pre-existing state names into an sp_vi_cali_state_name() helper and
add a Q24 formatter for the log output.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/qdsp6/audioreach.c | 134 +++++++++++++++++++++++++++++-
1 file changed, 130 insertions(+), 4 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index c7444f8598c8..a187e0b13633 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -2,6 +2,7 @@
// Copyright (c) 2020, Linaro Limited
#include <linux/kernel.h>
+#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/soc/qcom/apr.h>
#include <sound/soc.h>
@@ -12,6 +13,25 @@
#include "q6apm.h"
#include "audioreach.h"
+enum sp_vi_cali_state {
+ SP_VI_CALI_IDLE, /* Not calibrating */
+ SP_VI_CALI_RUNNING, /* Events arriving, none decisive yet */
+ SP_VI_CALI_FAILED, /* Run finished, no usable R0 */
+ SP_VI_CALI_SUCCESS, /* Run finished, @r0_cali_q24 valid */
+};
+
+struct sp_vi_r0_result {
+ /* Set when a calibration run is armed, cleared when it ends */
+ bool armed;
+ enum sp_vi_cali_state state;
+ u32 num_ch;
+ s32 r0_cali_q24[MAX_SP_VI_SPEAKERS];
+ u32 seen_states[MAX_SP_VI_SPEAKERS];
+};
+
+static struct sp_vi_r0_result sp_vi_r0;
+static DEFINE_MUTEX(sp_vi_r0_lock);
+
/* SubGraph Config */
struct apm_sub_graph_data {
struct apm_sub_graph_cfg sub_graph_cfg;
@@ -1436,20 +1456,116 @@ static int audioreach_gain_set(struct q6apm_graph *graph,
return q6apm_send_cmd_sync(graph->apm, pkt, 0);
}
+static bool sp_vi_cali_state_is_failure(u32 state)
+{
+ return state == VI_CALIBRATION_STATE_FAILED ||
+ state == VI_CALIBRATION_STATE_VI_WAIT_TIMED_OUT;
+}
+
+static bool sp_vi_cali_state_is_terminal(u32 state)
+{
+ return state == VI_CALIBRATION_STATE_SUCCESS ||
+ sp_vi_cali_state_is_failure(state);
+}
+
+#define SP_VI_CALI_UNKNOWN_STATE_BIT (VI_CALIBRATION_STATE_LOW_VI + 1)
+
+static const char *sp_vi_cali_state_name(u32 state)
+{
+ static const char * const names[] = {
+ [VI_CALIBRATION_STATE_INCORRECT_OP_MODE] = "not in calibration mode",
+ [VI_CALIBRATION_STATE_INACTIVE] = "inactive",
+ [VI_CALIBRATION_STATE_WARMUP] = "warming up",
+ [VI_CALIBRATION_STATE_INPROGRESS] = "in progress",
+ [VI_CALIBRATION_STATE_SUCCESS] = "success",
+ [VI_CALIBRATION_STATE_FAILED] = "failed, R0/T0 out of range",
+ [VI_CALIBRATION_STATE_WAIT_FOR_VI] = "waiting for V/I",
+ [VI_CALIBRATION_STATE_VI_WAIT_TIMED_OUT] = "failed, timed out waiting for V/I",
+ [VI_CALIBRATION_STATE_LOW_VI] = "V/I level too low",
+ };
+
+ if (state >= ARRAY_SIZE(names) || !names[state])
+ return "unknown";
+
+ return names[state];
+}
+
+static int sp_vi_q24_to_int_frac(s32 val, int *frac)
+{
+ *frac = (int)(((s64)(val & 0xffffff) * 1000) >> 24);
+
+ return val >> 24;
+}
+
void audioreach_vi_calibration_event(struct device *dev,
const struct event_id_vi_per_spkr_calibration *cali,
u32 num_ch)
{
+ bool decisive = true;
+ bool success = true;
unsigned int i;
+ u32 bit;
/* A payload with no entries gives no new information */
if (!num_ch)
return;
- /* Raised every frame; keep the per-event log at debug level */
- for (i = 0; i < num_ch; i++)
- dev_dbg(dev, "VI calibration channel %u: state %u\n",
- i, cali->cali_param[i].state);
+ guard(mutex)(&sp_vi_r0_lock);
+
+ if (!sp_vi_r0.armed)
+ return;
+
+ /* First event of this run: drop the previous result */
+ if (!memchr_inv(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states))) {
+ sp_vi_r0.state = SP_VI_CALI_RUNNING;
+ sp_vi_r0.num_ch = 0;
+ memset(sp_vi_r0.r0_cali_q24, 0, sizeof(sp_vi_r0.r0_cali_q24));
+ }
+
+ for (i = 0; i < num_ch; i++) {
+ u32 state = cali->cali_param[i].state;
+
+ if (sp_vi_cali_state_is_failure(state))
+ success = false;
+ else if (!sp_vi_cali_state_is_terminal(state))
+ decisive = false;
+
+ bit = BIT(min_t(u32, state, SP_VI_CALI_UNKNOWN_STATE_BIT));
+ if (!(sp_vi_r0.seen_states[i] & bit)) {
+ sp_vi_r0.seen_states[i] |= bit;
+ dev_info(dev, "VI calibration channel %u: %s\n",
+ i, sp_vi_cali_state_name(state));
+ }
+ }
+
+ if (!decisive)
+ return;
+
+ sp_vi_r0.armed = false;
+ sp_vi_r0.state = success ? SP_VI_CALI_SUCCESS : SP_VI_CALI_FAILED;
+ sp_vi_r0.num_ch = num_ch;
+
+ for (i = 0; i < num_ch; i++) {
+ int r0_int, r0_frac;
+
+ if (cali->cali_param[i].state == VI_CALIBRATION_STATE_FAILED) {
+ r0_int = sp_vi_q24_to_int_frac(cali->cali_param[i].r0_cali_q24,
+ &r0_frac);
+ dev_warn(dev, "VI calibration channel %u: R0 %d.%03d ohms out of range\n",
+ i, r0_int, r0_frac);
+ continue;
+ }
+ if (sp_vi_cali_state_is_failure(cali->cali_param[i].state))
+ continue;
+
+ sp_vi_r0.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
+
+ r0_int = sp_vi_q24_to_int_frac(sp_vi_r0.r0_cali_q24[i], &r0_frac);
+ dev_info(dev, "VI calibration channel %u: R0 %d.%03d ohms (Q24 %d)\n",
+ i, r0_int, r0_frac, sp_vi_r0.r0_cali_q24[i]);
+ }
+
+ dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed");
}
static int audioreach_speaker_protection(struct q6apm_graph *graph,
@@ -1489,6 +1605,14 @@ static int audioreach_register_events(struct q6apm_graph *graph,
return rc;
}
+static void audioreach_arm_vi_calibration(void)
+{
+ guard(mutex)(&sp_vi_r0_lock);
+
+ sp_vi_r0.armed = true;
+ memset(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states));
+}
+
static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
const struct audioreach_module *module,
const struct audioreach_module_config *mcfg)
@@ -1516,6 +1640,8 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
return -EINVAL;
}
+ audioreach_arm_vi_calibration();
+
rc = audioreach_register_events(graph, module);
if (rc)
return rc;
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (11 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:25 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
` (10 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Introduce the speaker protection operation mode as an internal state
(default Normal) and a write-only edge trigger to start a calibration
run:
- sp_operation_mode holds the current mode;
audioreach_get_sp_operation_mode() exposes it as read-only status
for userspace kcontrols.
- audioreach_trigger_sp_calibration() flips Normal -> Calibration via
cmpxchg, returning -EBUSY if a run is already in flight, and arms a
60 s watchdog to bound the armed state.
- On the DSP reporting terminal state for every speaker, the mode
auto-returns to Normal and the watchdog is cancelled. The VI module
path uses the current mode on the next configure.
The calibration run is edge-triggered rather than a user-visible mode
so a stale alsactl state file cannot flip the DSP into Calibration and
nothing can leave the system stuck there.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/qdsp6/audioreach.c | 91 ++++++++++++++++++++++++++-----
sound/soc/qcom/qdsp6/audioreach.h | 3 +
sound/soc/qcom/qdsp6/q6apm.c | 2 +
3 files changed, 82 insertions(+), 14 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index a187e0b13633..be37681f467f 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -5,6 +5,7 @@
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/soc/qcom/apr.h>
+#include <linux/workqueue.h>
#include <sound/soc.h>
#include <sound/soc-dai.h>
#include <sound/pcm.h>
@@ -13,6 +14,8 @@
#include "q6apm.h"
#include "audioreach.h"
+static u32 sp_operation_mode;
+
enum sp_vi_cali_state {
SP_VI_CALI_IDLE, /* Not calibrating */
SP_VI_CALI_RUNNING, /* Events arriving, none decisive yet */
@@ -1456,6 +1459,65 @@ static int audioreach_gain_set(struct q6apm_graph *graph,
return q6apm_send_cmd_sync(graph->apm, pkt, 0);
}
+u32 audioreach_get_sp_operation_mode(void)
+{
+ return READ_ONCE(sp_operation_mode);
+}
+
+/*
+ * Calibration is edge-triggered rather than a user-visible mode. Guard
+ * against a trigger write while a run is still in flight, and bound the
+ * armed state with a watchdog so a trigger without a matching playback
+ * does not leave the system in Calibration forever.
+ */
+#define SP_CAL_WATCHDOG_SECS 60
+
+static void audioreach_sp_cal_watchdog_fn(struct work_struct *work);
+static DECLARE_DELAYED_WORK(sp_cal_watchdog, audioreach_sp_cal_watchdog_fn);
+
+static void audioreach_sp_disarm_vi(void)
+{
+ guard(mutex)(&sp_vi_r0_lock);
+ sp_vi_r0.armed = false;
+}
+
+static void audioreach_sp_cal_watchdog_fn(struct work_struct *work)
+{
+ if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_CALIBRATION,
+ PARAM_ID_SP_VI_OP_MODE_NORMAL) !=
+ PARAM_ID_SP_VI_OP_MODE_CALIBRATION)
+ return;
+
+ audioreach_sp_disarm_vi();
+ pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
+}
+
+/* Finish before writing the mode so a trigger racing in cannot be clobbered */
+static void audioreach_sp_finish_calibration(void)
+{
+ cancel_delayed_work_sync(&sp_cal_watchdog);
+ WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
+}
+
+/* Release the delayed work from the module on unload so the timer cannot fire */
+void audioreach_sp_shutdown(void)
+{
+ cancel_delayed_work_sync(&sp_cal_watchdog);
+}
+EXPORT_SYMBOL_GPL(audioreach_sp_shutdown);
+
+int audioreach_trigger_sp_calibration(void)
+{
+ if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL,
+ PARAM_ID_SP_VI_OP_MODE_CALIBRATION) !=
+ PARAM_ID_SP_VI_OP_MODE_NORMAL)
+ return -EBUSY;
+
+ schedule_delayed_work(&sp_cal_watchdog,
+ SP_CAL_WATCHDOG_SECS * HZ);
+ return 0;
+}
+
static bool sp_vi_cali_state_is_failure(u32 state)
{
return state == VI_CALIBRATION_STATE_FAILED ||
@@ -1506,10 +1568,6 @@ void audioreach_vi_calibration_event(struct device *dev,
unsigned int i;
u32 bit;
- /* A payload with no entries gives no new information */
- if (!num_ch)
- return;
-
guard(mutex)(&sp_vi_r0_lock);
if (!sp_vi_r0.armed)
@@ -1566,14 +1624,16 @@ void audioreach_vi_calibration_event(struct device *dev,
}
dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed");
+
+ /* Edge-triggered: the mode auto-returns to Normal on terminal state. */
+ audioreach_sp_finish_calibration();
}
static int audioreach_speaker_protection(struct q6apm_graph *graph,
- const struct audioreach_module *module,
- uint32_t operation_mode)
+ const struct audioreach_module *module)
{
return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE,
- operation_mode);
+ READ_ONCE(sp_operation_mode));
}
static int audioreach_register_events(struct q6apm_graph *graph,
@@ -1615,7 +1675,8 @@ static void audioreach_arm_vi_calibration(void)
static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
const struct audioreach_module *module,
- const struct audioreach_module_config *mcfg)
+ const struct audioreach_module_config *mcfg,
+ u32 mode)
{
u32 num_channels = mcfg->num_channels;
struct apm_module_sp_vi_op_mode_cfg *op_cfg;
@@ -1640,11 +1701,13 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
return -EINVAL;
}
- audioreach_arm_vi_calibration();
+ if (mode == PARAM_ID_SP_VI_OP_MODE_CALIBRATION) {
+ audioreach_arm_vi_calibration();
- rc = audioreach_register_events(graph, module);
- if (rc)
- return rc;
+ rc = audioreach_register_events(graph, module);
+ if (rc)
+ return rc;
+ }
op_sz = APM_SP_VI_OP_MODE_CFG_PSIZE(num_speakers);
/* Channel mapping for Isense and Vsense, thus twice number of speakers. */
@@ -1668,7 +1731,7 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
/* The DSP calls this field num_speakers for the VI module */
op_cfg->cfg.num_channels = num_speakers;
- op_cfg->cfg.operation_mode = PARAM_ID_SP_VI_OP_MODE_CALIBRATION;
+ op_cfg->cfg.operation_mode = mode;
p += op_sz;
cm_cfg = p;
@@ -1760,7 +1823,7 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
break;
case MODULE_ID_SPEAKER_PROTECTION:
rc = audioreach_speaker_protection(graph, module,
- PARAM_ID_SP_OP_MODE_CALIBRATION);
+ READ_ONCE(sp_operation_mode));
if (!rc)
rc = audioreach_module_enable(graph, module, true);
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index 062727d09612..9f1ef0a3e510 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -1113,9 +1113,12 @@ int audioreach_gain_set_vol_ctrl(struct q6apm *apm,
int audioreach_send_u32_param(struct q6apm_graph *graph,
const struct audioreach_module *module,
uint32_t param_id, uint32_t param_val);
+u32 audioreach_get_sp_operation_mode(void);
+int audioreach_trigger_sp_calibration(void);
void audioreach_vi_calibration_event(struct device *dev,
const struct event_id_vi_per_spkr_calibration *cali,
u32 num_ch);
+void audioreach_sp_shutdown(void);
int audioreach_compr_set_param(struct q6apm_graph *graph,
const struct audioreach_module_config *mcfg);
int audioreach_setup_push_pull(struct q6apm_graph *graph, phys_addr_t bphys,
diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
index c410e2f6e6a3..6494eb80f089 100644
--- a/sound/soc/qcom/qdsp6/q6apm.c
+++ b/sound/soc/qcom/qdsp6/q6apm.c
@@ -950,6 +950,8 @@ static int apm_probe(gpr_device_t *gdev)
static void apm_remove(gpr_device_t *gdev)
{
+ /* Release the SP calibration watchdog before the module goes away */
+ audioreach_sp_shutdown();
g_apm = NULL;
of_platform_depopulate(&gdev->dev);
snd_soc_unregister_component(&gdev->dev);
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (12 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:43 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
` (9 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
In normal mode the VI module needs each speaker's calibrated resistance
and temperature, otherwise thermal protection has no reference.
Send the stored values with PARAM_ID_SP_TH_VI_R0T0_CFG in normal mode
and store the result of each successful calibration. Values written
from userspace are range checked, and a graph whose speaker count does
not match the stored set is refused instead of being partly configured.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/qdsp6/audioreach.c | 211 ++++++++++++++++++++++++++----
sound/soc/qcom/qdsp6/audioreach.h | 21 +++
sound/soc/qcom/qdsp6/q6apm.c | 2 -
3 files changed, 206 insertions(+), 28 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index be37681f467f..3555c97c2000 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -35,6 +35,15 @@ struct sp_vi_r0_result {
static struct sp_vi_r0_result sp_vi_r0;
static DEFINE_MUTEX(sp_vi_r0_lock);
+struct sp_vi_r0t0_cfg {
+ u32 num_ch;
+ s32 r0_cali_q24[MAX_SP_VI_SPEAKERS];
+ s16 t0_cali_q6[MAX_SP_VI_SPEAKERS];
+};
+
+static struct sp_vi_r0t0_cfg sp_vi_r0t0_cfg;
+static DEFINE_MUTEX(sp_vi_r0t0_cfg_lock);
+
/* SubGraph Config */
struct apm_sub_graph_data {
struct apm_sub_graph_cfg sub_graph_cfg;
@@ -285,6 +294,15 @@ struct apm_module_sp_vi_channel_map_cfg {
sizeof(struct apm_module_sp_vi_channel_map_cfg) + \
(ch) * sizeof(uint32_t), 8)
+struct apm_module_sp_th_vi_r0t0_cfg {
+ struct apm_module_param_data param_data;
+ struct param_id_sp_th_vi_r0t0_cfg cfg;
+} __packed;
+
+#define APM_SP_TH_VI_R0T0_CFG_PSIZE(ch) ALIGN( \
+ sizeof(struct apm_module_sp_th_vi_r0t0_cfg) + \
+ (ch) * sizeof(struct vi_r0t0_cfg), 8)
+
static void *__audioreach_alloc_pkt(int payload_size, uint32_t opcode, uint32_t token,
uint32_t src_port, uint32_t dest_port, bool has_cmd_hdr)
{
@@ -1475,37 +1493,20 @@ u32 audioreach_get_sp_operation_mode(void)
static void audioreach_sp_cal_watchdog_fn(struct work_struct *work);
static DECLARE_DELAYED_WORK(sp_cal_watchdog, audioreach_sp_cal_watchdog_fn);
-static void audioreach_sp_disarm_vi(void)
-{
- guard(mutex)(&sp_vi_r0_lock);
- sp_vi_r0.armed = false;
-}
-
static void audioreach_sp_cal_watchdog_fn(struct work_struct *work)
{
if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_CALIBRATION,
- PARAM_ID_SP_VI_OP_MODE_NORMAL) !=
+ PARAM_ID_SP_VI_OP_MODE_NORMAL) ==
PARAM_ID_SP_VI_OP_MODE_CALIBRATION)
- return;
-
- audioreach_sp_disarm_vi();
- pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
+ pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
}
-/* Finish before writing the mode so a trigger racing in cannot be clobbered */
static void audioreach_sp_finish_calibration(void)
{
- cancel_delayed_work_sync(&sp_cal_watchdog);
WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
+ cancel_delayed_work(&sp_cal_watchdog);
}
-/* Release the delayed work from the module on unload so the timer cannot fire */
-void audioreach_sp_shutdown(void)
-{
- cancel_delayed_work_sync(&sp_cal_watchdog);
-}
-EXPORT_SYMBOL_GPL(audioreach_sp_shutdown);
-
int audioreach_trigger_sp_calibration(void)
{
if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL,
@@ -1559,6 +1560,86 @@ static int sp_vi_q24_to_int_frac(s32 val, int *frac)
return val >> 24;
}
+#define SP_VI_R0_MIN_Q24 (1 << 22) /* 0.25 ohm */
+#define SP_VI_R0_MAX_Q24 (64 << 24) /* 64 ohms */
+
+#define SP_VI_T0_MIN_Q6 (-30 * 64)
+#define SP_VI_T0_MAX_Q6 (80 * 64)
+
+void audioreach_get_sp_vi_r0t0(long *vals, unsigned int count)
+{
+ unsigned int i;
+
+ memset(vals, 0, count * sizeof(*vals));
+
+ guard(mutex)(&sp_vi_r0t0_cfg_lock);
+ for (i = 0; i < sp_vi_r0t0_cfg.num_ch && 2 * i + 1 < count; i++) {
+ vals[2 * i] = sp_vi_r0t0_cfg.r0_cali_q24[i];
+ vals[2 * i + 1] = sp_vi_r0t0_cfg.t0_cali_q6[i];
+ }
+}
+
+int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int count)
+{
+ struct sp_vi_r0t0_cfg new = {};
+ unsigned int i, num_ch;
+
+ /* One R0 and one T0 per channel, so an odd count cannot be complete. */
+ if (!count || count % 2)
+ return -EINVAL;
+
+ num_ch = min(count / 2, (unsigned int)MAX_SP_VI_SPEAKERS);
+
+ /* A trailing all-zero pair is padding, as zero is not a plausible R0 */
+ while (num_ch && !vals[2 * (num_ch - 1)] && !vals[2 * (num_ch - 1) + 1])
+ num_ch--;
+
+ if (!num_ch) {
+ dev_err(dev, "SP R0T0 has no channels set\n");
+ return -EINVAL;
+ }
+
+ for (i = 0; i < num_ch; i++) {
+ long r0 = vals[2 * i];
+ long t0 = vals[2 * i + 1];
+ int r0_int, r0_frac;
+
+ if (r0 < SP_VI_R0_MIN_Q24 || r0 > SP_VI_R0_MAX_Q24) {
+ r0_int = sp_vi_q24_to_int_frac(r0, &r0_frac);
+ dev_err(dev, "Channel %u R0 %d.%03d ohms (Q24 %ld) out of range\n",
+ i, r0_int, r0_frac, r0);
+ return -ERANGE;
+ }
+
+ if (t0 < SP_VI_T0_MIN_Q6 || t0 > SP_VI_T0_MAX_Q6) {
+ dev_err(dev, "Channel %u T0 %ld.%03ld degC (Q6 %ld) out of range\n",
+ i, t0 / 64, abs((t0 % 64) * 1000 / 64), t0);
+ return -ERANGE;
+ }
+
+ new.r0_cali_q24[i] = r0;
+ new.t0_cali_q6[i] = t0;
+ }
+ new.num_ch = num_ch;
+
+ guard(mutex)(&sp_vi_r0t0_cfg_lock);
+
+ sp_vi_r0t0_cfg = new;
+
+ for (i = 0; i < num_ch; i++) {
+ int r0_int, r0_frac;
+
+ r0_int = sp_vi_q24_to_int_frac(new.r0_cali_q24[i], &r0_frac);
+ dev_info(dev, "SP channel %u: R0 %d.%03d ohms (Q24 %d), T0 %d.%03d degC (Q6 %d)\n",
+ i, r0_int, r0_frac, new.r0_cali_q24[i],
+ new.t0_cali_q6[i] / 64,
+ abs((new.t0_cali_q6[i] % 64) * 1000 / 64),
+ new.t0_cali_q6[i]);
+ }
+
+ return num_ch;
+}
+
void audioreach_vi_calibration_event(struct device *dev,
const struct event_id_vi_per_spkr_calibration *cali,
u32 num_ch)
@@ -1623,6 +1704,14 @@ void audioreach_vi_calibration_event(struct device *dev,
i, r0_int, r0_frac, sp_vi_r0.r0_cali_q24[i]);
}
+ /* Only a run where every speaker succeeded gives a usable R0/T0 set */
+ if (success) {
+ guard(mutex)(&sp_vi_r0t0_cfg_lock);
+ sp_vi_r0t0_cfg.num_ch = num_ch;
+ for (i = 0; i < num_ch; i++)
+ sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
+ }
+
dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed");
/* Edge-triggered: the mode auto-returns to Normal on terminal state. */
@@ -1675,9 +1764,9 @@ static void audioreach_arm_vi_calibration(void)
static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
const struct audioreach_module *module,
- const struct audioreach_module_config *mcfg,
- u32 mode)
+ const struct audioreach_module_config *mcfg)
{
+ u32 mode = READ_ONCE(sp_operation_mode);
u32 num_channels = mcfg->num_channels;
struct apm_module_sp_vi_op_mode_cfg *op_cfg;
struct apm_module_sp_vi_channel_map_cfg *cm_cfg;
@@ -1705,8 +1794,11 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
audioreach_arm_vi_calibration();
rc = audioreach_register_events(graph, module);
- if (rc)
+ if (rc) {
+ audioreach_sp_finish_calibration();
+ audioreach_sp_disarm_vi();
return rc;
+ }
}
op_sz = APM_SP_VI_OP_MODE_CFG_PSIZE(num_speakers);
@@ -1767,6 +1859,73 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
kfree(pkt);
+ if (rc)
+ return rc;
+
+ if (mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
+ struct apm_module_sp_th_vi_r0t0_cfg *r0t0_cfg;
+ struct sp_vi_r0t0_cfg snap;
+ int r0t0_sz;
+
+ /* Snapshot the cache so q6apm_send_cmd_sync runs with no locks held */
+ scoped_guard(mutex, &sp_vi_r0t0_cfg_lock)
+ snap = sp_vi_r0t0_cfg;
+
+ if (!snap.num_ch)
+ return 0;
+
+ if (snap.num_ch != num_speakers) {
+ dev_err(graph->dev,
+ "SP R0T0 is for %u speakers, graph has %u\n",
+ snap.num_ch, num_speakers);
+ return -EINVAL;
+ }
+
+ r0t0_sz = APM_SP_TH_VI_R0T0_CFG_PSIZE(snap.num_ch);
+ pkt = audioreach_alloc_apm_cmd_pkt(r0t0_sz, APM_CMD_SET_CFG, 0);
+ if (IS_ERR(pkt))
+ return PTR_ERR(pkt);
+
+ p = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
+
+ r0t0_cfg = p;
+ param_data = &r0t0_cfg->param_data;
+ param_data->module_instance_id = module->instance_id;
+ param_data->error_code = 0;
+ param_data->param_id = PARAM_ID_SP_TH_VI_R0T0_CFG;
+ param_data->param_size = r0t0_sz - APM_MODULE_PARAM_DATA_SIZE;
+
+ r0t0_cfg->cfg.num_ch = snap.num_ch;
+ for (i = 0; i < snap.num_ch; i++) {
+ r0t0_cfg->cfg.r0t0_cfg[i].r0_cali_q24 = snap.r0_cali_q24[i];
+ r0t0_cfg->cfg.r0t0_cfg[i].t0_cali_q6 = snap.t0_cali_q6[i];
+ r0t0_cfg->cfg.r0t0_cfg[i].reserved = 0;
+ }
+
+ rc = q6apm_send_cmd_sync(graph->apm, pkt, 0);
+
+ kfree(pkt);
+
+ if (rc) {
+ dev_err(graph->dev, "SP activation failed: %d\n", rc);
+ return rc;
+ }
+
+ /* Protection is now active on the DSP */
+ dev_info(graph->dev, "SP active in Normal mode (%u channels)\n",
+ snap.num_ch);
+ for (i = 0; i < snap.num_ch; i++) {
+ int r0_int, r0_frac;
+
+ r0_int = sp_vi_q24_to_int_frac(snap.r0_cali_q24[i], &r0_frac);
+ dev_info(graph->dev,
+ " SP ch%u: R0 %d.%03d ohms, T0 %d.%03d degC\n",
+ i, r0_int, r0_frac,
+ snap.t0_cali_q6[i] / 64,
+ abs((snap.t0_cali_q6[i] % 64) * 1000 / 64));
+ }
+ }
+
return rc;
}
@@ -1822,14 +1981,14 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
rc = audioreach_gapless_set_media_format(graph, module, cfg);
break;
case MODULE_ID_SPEAKER_PROTECTION:
- rc = audioreach_speaker_protection(graph, module,
- READ_ONCE(sp_operation_mode));
+ rc = audioreach_speaker_protection(graph, module);
if (!rc)
rc = audioreach_module_enable(graph, module, true);
break;
case MODULE_ID_SPEAKER_PROTECTION_VI:
- rc = audioreach_speaker_protection_vi(graph, module, cfg);
+ rc = audioreach_speaker_protection_vi(graph, module, cfg,
+ READ_ONCE(sp_operation_mode));
if (!rc)
rc = audioreach_module_enable(graph, module, true);
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index 9f1ef0a3e510..780d3df717d0 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -723,6 +723,25 @@ struct param_id_sp_vi_channel_map_cfg {
uint32_t channel_mapping[];
} __packed;
+#define PARAM_ID_SP_TH_VI_R0T0_CFG 0x080011f5
+
+/**
+ * struct vi_r0t0_cfg - Per-speaker calibrated R0/T0
+ * @r0_cali_q24: Calibrated DC resistance in ohms, Q24.
+ * @t0_cali_q6: Calibrated temperature in degrees C, Q6.
+ * @reserved: Padding, must be zero.
+ */
+struct vi_r0t0_cfg {
+ int32_t r0_cali_q24;
+ int16_t t0_cali_q6;
+ int16_t reserved;
+} __packed;
+
+struct param_id_sp_th_vi_r0t0_cfg {
+ uint32_t num_ch;
+ struct vi_r0t0_cfg r0t0_cfg[];
+} __packed;
+
/* VI per-speaker calibration event, raised every frame in calibration mode */
#define EVENT_ID_VI_PER_SPKR_CALIBRATION 0x08001511
@@ -1115,6 +1134,8 @@ int audioreach_send_u32_param(struct q6apm_graph *graph,
uint32_t param_id, uint32_t param_val);
u32 audioreach_get_sp_operation_mode(void);
int audioreach_trigger_sp_calibration(void);
+void audioreach_get_sp_vi_r0t0(long *vals, unsigned int count);
+int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int count);
void audioreach_vi_calibration_event(struct device *dev,
const struct event_id_vi_per_spkr_calibration *cali,
u32 num_ch);
diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
index 6494eb80f089..c410e2f6e6a3 100644
--- a/sound/soc/qcom/qdsp6/q6apm.c
+++ b/sound/soc/qcom/qdsp6/q6apm.c
@@ -950,8 +950,6 @@ static int apm_probe(gpr_device_t *gdev)
static void apm_remove(gpr_device_t *gdev)
{
- /* Release the SP calibration watchdog before the module goes away */
- audioreach_sp_shutdown();
g_apm = NULL;
of_platform_depopulate(&gdev->dev);
snd_soc_unregister_component(&gdev->dev);
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (13 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:50 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
` (8 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
The speaker protection modules need tuning parameters from the topology
cfg blob, which is never sent to the DSP.
Send it once the module is configured, in small SET_CFG commands split
on parameter boundaries, with each payload padded to 8 bytes as the DSP
expects. Every record is checked against the end of the blob, and a
malformed blob is rejected. A blob not laid out as parameter records is
sent whole.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/qdsp6/audioreach.c | 139 ++++++++++++++++++++++++++++++
1 file changed, 139 insertions(+)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index 3555c97c2000..fd803d6ceccd 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -1929,6 +1929,141 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
return rc;
}
+/* Keep each SET_CFG small; a larger single parameter is sent on its own */
+#define AR_SP_CFG_MAX_CHUNK_BYTES 512
+
+static int audioreach_speaker_protection_send_chunk(struct q6apm_graph *graph,
+ const char *tag,
+ const void *data, int size,
+ int chunk_idx)
+{
+ int rc;
+
+ struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_apm_cmd_pkt(size, APM_CMD_SET_CFG, 0);
+ if (IS_ERR(pkt))
+ return PTR_ERR(pkt);
+
+ memcpy((void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE, data, size);
+
+ rc = q6apm_send_cmd_sync(graph->apm, pkt, 0);
+ if (rc)
+ dev_err(graph->dev, "%s cfg blob: chunk %d (%d bytes) failed: %d\n",
+ tag, chunk_idx, size, rc);
+ else
+ dev_dbg(graph->dev, "%s cfg blob: chunk %d (%d bytes) sent\n",
+ tag, chunk_idx, size);
+
+ return rc;
+}
+
+/*
+ * Walk the parameter records of a cfg blob. Each starts with the module's
+ * instance id and a param_size, followed by its payload and optional zero
+ * padding; a parameter smaller than a word may come without a payload word.
+ * Each record is checked against the end of the blob. With @dst, the records
+ * are copied there with their payload padded to 8 bytes, as the DSP expects.
+ * Returns the packed size, or -EINVAL if the blob is malformed.
+ */
+static int audioreach_sp_cfg_walk(const u32 *word, u32 num_words, u32 iid,
+ u32 first, u32 *next, u8 *dst, u32 max_bytes)
+{
+ u32 pos = first, bytes = 0;
+
+ while (pos < num_words) {
+ u32 param_size, payload_words, avail, rec_bytes;
+
+ if (word[pos] != iid || num_words - pos < 4)
+ return -EINVAL;
+
+ param_size = word[pos + 2];
+ avail = (num_words - pos - 4) * sizeof(u32);
+ if (param_size < sizeof(u32) && avail && word[pos + 4] == iid) {
+ payload_words = 0;
+ } else {
+ if (param_size > avail)
+ return -EINVAL;
+ payload_words = DIV_ROUND_UP(param_size, sizeof(u32));
+ }
+
+ rec_bytes = APM_MODULE_PARAM_DATA_SIZE + ALIGN(param_size, 8);
+ if (bytes && bytes + rec_bytes > max_bytes)
+ break;
+
+ if (dst) {
+ memcpy(dst + bytes, &word[pos], APM_MODULE_PARAM_DATA_SIZE);
+ memset(dst + bytes + APM_MODULE_PARAM_DATA_SIZE, 0,
+ rec_bytes - APM_MODULE_PARAM_DATA_SIZE);
+ memcpy(dst + bytes + APM_MODULE_PARAM_DATA_SIZE, &word[pos + 4],
+ min(param_size, payload_words * (u32)sizeof(u32)));
+ }
+ bytes += rec_bytes;
+
+ pos += 4 + payload_words;
+ while (pos < num_words && !word[pos])
+ pos++;
+ }
+
+ if (next)
+ *next = pos;
+ return bytes;
+}
+
+static int audioreach_speaker_protection_send_static_cfg(struct q6apm_graph *graph,
+ const struct audioreach_module *module,
+ const char *tag)
+{
+ u32 size, num_words, pos = 0;
+ const u32 *word;
+ int total, rc = 0, chunk = 0;
+
+ if (!module->data || !module->data->size)
+ return 0;
+
+ size = le32_to_cpu(module->data->size);
+ word = (const u32 *)module->data->data;
+ num_words = size / sizeof(u32);
+
+ /* Not laid out as parameter records, so send it as the topology built it */
+ if (size % sizeof(u32) || !num_words || word[0] != module->instance_id)
+ return audioreach_speaker_protection_send_chunk(graph, tag, word, size, 0);
+
+ total = audioreach_sp_cfg_walk(word, num_words, module->instance_id, 0,
+ NULL, NULL, U32_MAX);
+ if (total < 0) {
+ dev_err(graph->dev, "%s cfg blob is malformed\n", tag);
+ return total;
+ }
+
+ u8 *packed __free(kfree) = kmalloc(total, GFP_KERNEL);
+ if (!packed)
+ return -ENOMEM;
+
+ while (pos < num_words && !rc) {
+ int bytes = audioreach_sp_cfg_walk(word, num_words, module->instance_id,
+ pos, &pos, packed,
+ AR_SP_CFG_MAX_CHUNK_BYTES);
+ if (bytes <= 0)
+ return bytes ? bytes : -EINVAL;
+
+ rc = audioreach_speaker_protection_send_chunk(graph, tag, packed, bytes,
+ chunk++);
+ }
+
+ return rc;
+}
+
+static int audioreach_speaker_protection_static_cfg(struct q6apm_graph *graph,
+ const struct audioreach_module *module)
+{
+ return audioreach_speaker_protection_send_static_cfg(graph, module, "SP");
+}
+
+static int audioreach_speaker_protection_vi_static_cfg(struct q6apm_graph *graph,
+ const struct audioreach_module *module)
+{
+ return audioreach_speaker_protection_send_static_cfg(graph, module, "VI");
+}
+
int audioreach_set_media_format(struct q6apm_graph *graph,
const struct audioreach_module *module,
const struct audioreach_module_config *cfg)
@@ -1982,6 +2117,8 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
break;
case MODULE_ID_SPEAKER_PROTECTION:
rc = audioreach_speaker_protection(graph, module);
+ if (!rc)
+ rc = audioreach_speaker_protection_static_cfg(graph, module);
if (!rc)
rc = audioreach_module_enable(graph, module, true);
@@ -1989,6 +2126,8 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
case MODULE_ID_SPEAKER_PROTECTION_VI:
rc = audioreach_speaker_protection_vi(graph, module, cfg,
READ_ONCE(sp_operation_mode));
+ if (!rc)
+ rc = audioreach_speaker_protection_vi_static_cfg(graph, module);
if (!rc)
rc = audioreach_module_enable(graph, module, true);
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (14 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 14:01 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
` (7 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Add topology mixer controls for the operation mode and the per-speaker
R0/T0 pairs, so userspace can run a calibration and restore its result.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
include/uapi/sound/snd_ar_tokens.h | 2 +
sound/soc/qcom/qdsp6/topology.c | 75 ++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/include/uapi/sound/snd_ar_tokens.h b/include/uapi/sound/snd_ar_tokens.h
index 7ab8e11ca5c2..db62dc7f9c8a 100644
--- a/include/uapi/sound/snd_ar_tokens.h
+++ b/include/uapi/sound/snd_ar_tokens.h
@@ -57,6 +57,8 @@ enum ar_event_types {
*/
#define SND_SOC_AR_TPLG_FE_BE_GRAPH_CTL_MIX 256
#define SND_SOC_AR_TPLG_VOL_CTL 257
+#define SND_SOC_AR_TPLG_SP_OP_MODE_CTL 258
+#define SND_SOC_AR_TPLG_SP_R0T0_CTL 259
/*
* %AR_TKN_U32_SUB_GRAPH_INSTANCE_ID: Sub Graph Instance Id
diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
index 5dd7f2c51d5c..f9a3e9cf4119 100644
--- a/sound/soc/qcom/qdsp6/topology.c
+++ b/sound/soc/qcom/qdsp6/topology.c
@@ -1465,6 +1465,68 @@ static int audioreach_put_vol_ctrl_audio_mixer(struct snd_kcontrol *kcontrol,
return 1;
}
+static int audioreach_get_sp_op_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.enumerated.item[0] = audioreach_get_sp_operation_mode();
+
+ return 0;
+}
+
+/*
+ * "Speaker Protection Operation Mode" is read-only status. Enter
+ * Calibration via the "Speaker Protection Calibrate" trigger instead,
+ * so a stale alsactl state file cannot flip the DSP into Calibration
+ * and nothing can leave the system stuck there.
+ */
+static int audioreach_put_sp_op_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ return -EACCES;
+}
+
+/* One R0/T0 pair per speaker, written as a whole set */
+#define AR_SP_R0T0_CTL_COUNT (MAX_SP_VI_SPEAKERS * 2)
+
+static int audioreach_info_sp_r0t0(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = AR_SP_R0T0_CTL_COUNT;
+ uinfo->value.integer.min = S32_MIN;
+ uinfo->value.integer.max = S32_MAX;
+
+ return 0;
+}
+
+static int audioreach_get_sp_r0t0(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ audioreach_get_sp_vi_r0t0(ucontrol->value.integer.value,
+ AR_SP_R0T0_CTL_COUNT);
+
+ return 0;
+}
+
+static int audioreach_put_sp_r0t0(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *scomp = snd_kcontrol_chip(kcontrol);
+ long cur[AR_SP_R0T0_CTL_COUNT];
+ int ret;
+
+ audioreach_get_sp_vi_r0t0(cur, AR_SP_R0T0_CTL_COUNT);
+ if (!memcmp(cur, ucontrol->value.integer.value, sizeof(cur)))
+ return 0;
+
+ ret = audioreach_set_sp_vi_r0t0(scomp->dev, ucontrol->value.integer.value,
+ AR_SP_R0T0_CTL_COUNT);
+ if (ret < 0)
+ return ret;
+
+ return 1;
+}
+
static int audioreach_control_load_mix(struct snd_soc_component *scomp,
struct snd_ar_control *scontrol,
struct snd_kcontrol_new *kc,
@@ -1505,6 +1567,7 @@ static int audioreach_control_load(struct snd_soc_component *scomp, int index,
{
struct snd_ar_control *scontrol;
struct soc_mixer_control *sm;
+ struct soc_enum *se;
struct snd_soc_dobj *dobj;
int ret = 0;
@@ -1524,6 +1587,14 @@ static int audioreach_control_load(struct snd_soc_component *scomp, int index,
sm = (struct soc_mixer_control *)kc->private_value;
dobj = &sm->dobj;
break;
+ case SND_SOC_AR_TPLG_SP_R0T0_CTL:
+ sm = (struct soc_mixer_control *)kc->private_value;
+ dobj = &sm->dobj;
+ break;
+ case SND_SOC_AR_TPLG_SP_OP_MODE_CTL:
+ se = (struct soc_enum *)kc->private_value;
+ dobj = &se->dobj;
+ break;
default:
dev_warn(scomp->dev, "control type not supported %d:%d:%d\n",
hdr->ops.get, hdr->ops.put, hdr->ops.info);
@@ -1550,6 +1621,10 @@ static const struct snd_soc_tplg_kcontrol_ops audioreach_io_ops[] = {
audioreach_put_audio_mixer, snd_soc_info_volsw},
{SND_SOC_AR_TPLG_VOL_CTL, audioreach_get_vol_ctrl_audio_mixer,
audioreach_put_vol_ctrl_audio_mixer, snd_soc_info_volsw},
+ {SND_SOC_AR_TPLG_SP_OP_MODE_CTL, audioreach_get_sp_op_mode,
+ audioreach_put_sp_op_mode, snd_soc_info_enum_double},
+ {SND_SOC_AR_TPLG_SP_R0T0_CTL, audioreach_get_sp_r0t0,
+ audioreach_put_sp_r0t0, audioreach_info_sp_r0t0},
};
static const struct snd_soc_tplg_ops audioreach_tplg_ops = {
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (15 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:56 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
` (6 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
With multi_direction_codecs the speaker protection VI subgraph is
opened with the playback stream's parameters, but the VI module and its
codec DMA source always run at 8 kHz and 32 bits.
Use those for the VI module and the codec DMA source in its subgraph,
and keep the channel count, which follows the number of speakers.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/qdsp6/audioreach.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index fd803d6ceccd..d1f6cd2b6635 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -2064,12 +2064,41 @@ static int audioreach_speaker_protection_vi_static_cfg(struct q6apm_graph *graph
return audioreach_speaker_protection_send_static_cfg(graph, module, "VI");
}
+static bool audioreach_sg_contains_sp_vi(const struct audioreach_sub_graph *sg)
+{
+ const struct audioreach_container *c;
+ const struct audioreach_module *m;
+
+ if (!sg)
+ return false;
+
+ list_for_each_entry(c, &sg->container_list, node)
+ list_for_each_entry(m, &c->modules_list, node)
+ if (m->module_id == MODULE_ID_SPEAKER_PROTECTION_VI)
+ return true;
+
+ return false;
+}
+
int audioreach_set_media_format(struct q6apm_graph *graph,
const struct audioreach_module *module,
const struct audioreach_module_config *cfg)
{
+ struct audioreach_module_config sp_vi_cfg;
int rc;
+ /* The VI module and its codec DMA source always run at 8 kHz, S32_LE */
+ if (module->module_id == MODULE_ID_SPEAKER_PROTECTION_VI ||
+ (module->module_id == MODULE_ID_CODEC_DMA_SOURCE &&
+ audioreach_sg_contains_sp_vi(module->container ?
+ module->container->sub_graph : NULL))) {
+ sp_vi_cfg = *cfg;
+ sp_vi_cfg.sample_rate = 8000;
+ sp_vi_cfg.bit_width = 32;
+ sp_vi_cfg.bits_per_sample = 32;
+ cfg = &sp_vi_cfg;
+ }
+
switch (module->module_id) {
case MODULE_ID_DATA_LOGGING:
rc = audioreach_module_enable(graph, module, true);
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (16 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 14:04 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
` (5 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla,
kernel test robot
A calibration needs each speaker's die temperature when R0 is measured,
so that the R0/T0 pair given back to the DSP is consistent.
Let the machine driver register the speakers' thermal zones in VI
channel order with audioreach_sp_register_speaker_map(), and expose
their temperatures in Q6 format as a read-only "Speaker Protection T0"
control. Record T0 with R0 when a calibration completes. A slot that
cannot be read reports 0.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202611231947.lq10qE2P-lkp@intel.com/
---
sound/soc/qcom/qdsp6/audioreach.c | 132 +++++++++++++++++++++++-------
sound/soc/qcom/qdsp6/audioreach.h | 5 ++
sound/soc/qcom/qdsp6/q6apm-dai.c | 7 ++
sound/soc/qcom/qdsp6/topology.c | 41 ++++++++++
4 files changed, 156 insertions(+), 29 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index d1f6cd2b6635..cf6c686f88bd 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -2,9 +2,11 @@
// Copyright (c) 2020, Linaro Limited
#include <linux/kernel.h>
+#include <linux/math64.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/soc/qcom/apr.h>
+#include <linux/thermal.h>
#include <linux/workqueue.h>
#include <sound/soc.h>
#include <sound/soc-dai.h>
@@ -44,6 +46,13 @@ struct sp_vi_r0t0_cfg {
static struct sp_vi_r0t0_cfg sp_vi_r0t0_cfg;
static DEFINE_MUTEX(sp_vi_r0t0_cfg_lock);
+/* Speakers' thermal zones in VI channel order, set by the machine driver */
+static struct {
+ struct thermal_zone_device *tz[MAX_SP_VI_SPEAKERS];
+ unsigned int num;
+} sp_speaker_map;
+static DEFINE_MUTEX(sp_speaker_map_lock);
+
/* SubGraph Config */
struct apm_sub_graph_data {
struct apm_sub_graph_cfg sub_graph_cfg;
@@ -1579,6 +1588,61 @@ void audioreach_get_sp_vi_r0t0(long *vals, unsigned int count)
}
}
+int audioreach_sp_register_speaker_map(struct thermal_zone_device * const *tzs,
+ unsigned int num)
+{
+ unsigned int i;
+
+ if (num > MAX_SP_VI_SPEAKERS)
+ return -EINVAL;
+
+ guard(mutex)(&sp_speaker_map_lock);
+
+ for (i = 0; i < num; i++)
+ sp_speaker_map.tz[i] = tzs[i];
+ for (; i < MAX_SP_VI_SPEAKERS; i++)
+ sp_speaker_map.tz[i] = NULL;
+ sp_speaker_map.num = num;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(audioreach_sp_register_speaker_map);
+
+/*
+ * Read each speaker's T0 in Q6 (degC * 64), 0 if its zone cannot be read.
+ * Returns the number of slots read, or -EAGAIN if any registered slot came
+ * back unreadable (e.g. the PA was on, so TADC was off). A partial reading
+ * must not be cached as a valid calibration reference.
+ */
+int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
+{
+ unsigned int i, n;
+ bool any_failed = false;
+
+ guard(mutex)(&sp_speaker_map_lock);
+
+ n = min(count, sp_speaker_map.num);
+ for (i = 0; i < n; i++) {
+ int mdeg;
+
+ if (sp_speaker_map.tz[i] &&
+ !thermal_zone_get_temp(sp_speaker_map.tz[i], &mdeg)) {
+ vals[i] = div_s64((s64)mdeg * 64, 1000);
+ } else {
+ vals[i] = 0;
+ any_failed = true;
+ }
+ }
+ for (; i < count; i++)
+ vals[i] = 0;
+
+ if (any_failed)
+ return -EAGAIN;
+
+ return n;
+}
+EXPORT_SYMBOL_GPL(audioreach_get_sp_vi_t0);
+
int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int count)
{
struct sp_vi_r0t0_cfg new = {};
@@ -1644,6 +1708,7 @@ void audioreach_vi_calibration_event(struct device *dev,
const struct event_id_vi_per_spkr_calibration *cali,
u32 num_ch)
{
+ long t0_live[MAX_SP_VI_SPEAKERS];
bool decisive = true;
bool success = true;
unsigned int i;
@@ -1704,12 +1769,28 @@ void audioreach_vi_calibration_event(struct device *dev,
i, r0_int, r0_frac, sp_vi_r0.r0_cali_q24[i]);
}
- /* Only a run where every speaker succeeded gives a usable R0/T0 set */
+ /*
+ * Only a run where every speaker succeeded gives a usable R0/T0 set.
+ * The DSP reports only R0, so pair it with the speakers' last T0
+ * reading. If any zone was unreadable (e.g. PA still on), skip the
+ * cache: a 0 degC Q6 would be stored as a valid calibration ref.
+ */
if (success) {
- guard(mutex)(&sp_vi_r0t0_cfg_lock);
- sp_vi_r0t0_cfg.num_ch = num_ch;
- for (i = 0; i < num_ch; i++)
- sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
+ int t0_rc = audioreach_get_sp_vi_t0(t0_live, num_ch);
+
+ if (t0_rc < 0) {
+ dev_warn(dev,
+ "VI calibration: T0 unreadable, not caching R0/T0 (%d)\n",
+ t0_rc);
+ success = false;
+ } else {
+ guard(mutex)(&sp_vi_r0t0_cfg_lock);
+ sp_vi_r0t0_cfg.num_ch = num_ch;
+ for (i = 0; i < num_ch; i++) {
+ sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
+ sp_vi_r0t0_cfg.t0_cali_q6[i] = (s16)t0_live[i];
+ }
+ }
}
dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed");
@@ -1794,11 +1875,8 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
audioreach_arm_vi_calibration();
rc = audioreach_register_events(graph, module);
- if (rc) {
- audioreach_sp_finish_calibration();
- audioreach_sp_disarm_vi();
+ if (rc)
return rc;
- }
}
op_sz = APM_SP_VI_OP_MODE_CFG_PSIZE(num_speakers);
@@ -1862,26 +1940,23 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
if (rc)
return rc;
- if (mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
+ if (sp_operation_mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
struct apm_module_sp_th_vi_r0t0_cfg *r0t0_cfg;
- struct sp_vi_r0t0_cfg snap;
int r0t0_sz;
- /* Snapshot the cache so q6apm_send_cmd_sync runs with no locks held */
- scoped_guard(mutex, &sp_vi_r0t0_cfg_lock)
- snap = sp_vi_r0t0_cfg;
+ guard(mutex)(&sp_vi_r0t0_cfg_lock);
- if (!snap.num_ch)
+ if (!sp_vi_r0t0_cfg.num_ch)
return 0;
- if (snap.num_ch != num_speakers) {
+ if (sp_vi_r0t0_cfg.num_ch != num_speakers) {
dev_err(graph->dev,
"SP R0T0 is for %u speakers, graph has %u\n",
- snap.num_ch, num_speakers);
+ sp_vi_r0t0_cfg.num_ch, num_speakers);
return -EINVAL;
}
- r0t0_sz = APM_SP_TH_VI_R0T0_CFG_PSIZE(snap.num_ch);
+ r0t0_sz = APM_SP_TH_VI_R0T0_CFG_PSIZE(sp_vi_r0t0_cfg.num_ch);
pkt = audioreach_alloc_apm_cmd_pkt(r0t0_sz, APM_CMD_SET_CFG, 0);
if (IS_ERR(pkt))
return PTR_ERR(pkt);
@@ -1895,10 +1970,10 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
param_data->param_id = PARAM_ID_SP_TH_VI_R0T0_CFG;
param_data->param_size = r0t0_sz - APM_MODULE_PARAM_DATA_SIZE;
- r0t0_cfg->cfg.num_ch = snap.num_ch;
- for (i = 0; i < snap.num_ch; i++) {
- r0t0_cfg->cfg.r0t0_cfg[i].r0_cali_q24 = snap.r0_cali_q24[i];
- r0t0_cfg->cfg.r0t0_cfg[i].t0_cali_q6 = snap.t0_cali_q6[i];
+ r0t0_cfg->cfg.num_ch = sp_vi_r0t0_cfg.num_ch;
+ for (i = 0; i < sp_vi_r0t0_cfg.num_ch; i++) {
+ r0t0_cfg->cfg.r0t0_cfg[i].r0_cali_q24 = sp_vi_r0t0_cfg.r0_cali_q24[i];
+ r0t0_cfg->cfg.r0t0_cfg[i].t0_cali_q6 = sp_vi_r0t0_cfg.t0_cali_q6[i];
r0t0_cfg->cfg.r0t0_cfg[i].reserved = 0;
}
@@ -1913,16 +1988,16 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
/* Protection is now active on the DSP */
dev_info(graph->dev, "SP active in Normal mode (%u channels)\n",
- snap.num_ch);
- for (i = 0; i < snap.num_ch; i++) {
+ sp_vi_r0t0_cfg.num_ch);
+ for (i = 0; i < sp_vi_r0t0_cfg.num_ch; i++) {
int r0_int, r0_frac;
- r0_int = sp_vi_q24_to_int_frac(snap.r0_cali_q24[i], &r0_frac);
+ r0_int = sp_vi_q24_to_int_frac(sp_vi_r0t0_cfg.r0_cali_q24[i], &r0_frac);
dev_info(graph->dev,
" SP ch%u: R0 %d.%03d ohms, T0 %d.%03d degC\n",
i, r0_int, r0_frac,
- snap.t0_cali_q6[i] / 64,
- abs((snap.t0_cali_q6[i] % 64) * 1000 / 64));
+ sp_vi_r0t0_cfg.t0_cali_q6[i] / 64,
+ abs((sp_vi_r0t0_cfg.t0_cali_q6[i] % 64) * 1000 / 64));
}
}
@@ -2153,8 +2228,7 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
break;
case MODULE_ID_SPEAKER_PROTECTION_VI:
- rc = audioreach_speaker_protection_vi(graph, module, cfg,
- READ_ONCE(sp_operation_mode));
+ rc = audioreach_speaker_protection_vi(graph, module, cfg);
if (!rc)
rc = audioreach_speaker_protection_vi_static_cfg(graph, module);
if (!rc)
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index 780d3df717d0..e60e9c656122 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -9,6 +9,7 @@
#include "q6dsp-common.h"
struct q6apm;
struct q6apm_graph;
+struct thermal_zone_device;
/* Module IDs */
#define MODULE_ID_WR_SHARED_MEM_EP 0x07001000
@@ -1136,6 +1137,10 @@ u32 audioreach_get_sp_operation_mode(void);
int audioreach_trigger_sp_calibration(void);
void audioreach_get_sp_vi_r0t0(long *vals, unsigned int count);
int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int count);
+int audioreach_sp_register_speaker_map(struct thermal_zone_device * const *tzs,
+ unsigned int num);
+int audioreach_get_sp_vi_t0(long *vals, unsigned int count);
+int audioreach_add_sp_telemetry_controls(struct snd_soc_component *component);
void audioreach_vi_calibration_event(struct device *dev,
const struct event_id_vi_per_spkr_calibration *cali,
u32 num_ch);
diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
index f7ac0b455b2d..c9edcc8c72ad 100644
--- a/sound/soc/qcom/qdsp6/q6apm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
@@ -20,6 +20,7 @@
#include <sound/soc-dapm.h>
#include <asm/div64.h>
#include <asm/dma.h>
+#include "audioreach.h"
#include "q6apm.h"
#include "q6dsp-common.h"
@@ -1328,8 +1329,14 @@ static const struct snd_compress_ops q6apm_dai_compress_ops = {
.copy = q6apm_compr_copy,
};
+static int q6apm_dai_component_probe(struct snd_soc_component *component)
+{
+ return audioreach_add_sp_telemetry_controls(component);
+}
+
static const struct snd_soc_component_driver q6apm_fe_dai_component = {
.name = DRV_NAME,
+ .probe = q6apm_dai_component_probe,
.open = q6apm_dai_open,
.close = q6apm_dai_close,
.prepare = q6apm_dai_prepare,
diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
index f9a3e9cf4119..a8fdd73cdecd 100644
--- a/sound/soc/qcom/qdsp6/topology.c
+++ b/sound/soc/qcom/qdsp6/topology.c
@@ -1527,6 +1527,47 @@ static int audioreach_put_sp_r0t0(struct snd_kcontrol *kcontrol,
return 1;
}
+/* Live T0 per speaker in Q6 (degC * 64), 0 if it cannot be read */
+static int audioreach_info_sp_t0(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = MAX_SP_VI_SPEAKERS;
+ uinfo->value.integer.min = S32_MIN;
+ uinfo->value.integer.max = S32_MAX;
+
+ return 0;
+}
+
+static int audioreach_get_sp_t0(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ audioreach_get_sp_vi_t0(ucontrol->value.integer.value,
+ MAX_SP_VI_SPEAKERS);
+
+ return 0;
+}
+
+static const struct snd_kcontrol_new audioreach_sp_telemetry_controls[] = {
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Speaker Protection T0",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ |
+ SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = audioreach_info_sp_t0,
+ .get = audioreach_get_sp_t0,
+ },
+};
+
+/* Kept apart from the topology SP controls, so FEs have them without it */
+int audioreach_add_sp_telemetry_controls(struct snd_soc_component *component)
+{
+ return snd_soc_add_component_controls(component,
+ audioreach_sp_telemetry_controls,
+ ARRAY_SIZE(audioreach_sp_telemetry_controls));
+}
+EXPORT_SYMBOL_GPL(audioreach_add_sp_telemetry_controls);
+
static int audioreach_control_load_mix(struct snd_soc_component *scomp,
struct snd_ar_control *scontrol,
struct snd_kcontrol_new *kc,
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (17 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 13:59 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
` (4 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
Add a read-only "Speaker Protection Calibration State" control with
each speaker's last calibration state, so userspace can follow a run.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/qdsp6/audioreach.c | 106 +++++++++++++++++++++---------
sound/soc/qcom/qdsp6/audioreach.h | 2 +
sound/soc/qcom/qdsp6/q6apm.c | 15 ++++-
sound/soc/qcom/qdsp6/topology.c | 63 ++++++++++++++++++
4 files changed, 153 insertions(+), 33 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index cf6c686f88bd..166ce59347f8 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -23,6 +23,7 @@ enum sp_vi_cali_state {
SP_VI_CALI_RUNNING, /* Events arriving, none decisive yet */
SP_VI_CALI_FAILED, /* Run finished, no usable R0 */
SP_VI_CALI_SUCCESS, /* Run finished, @r0_cali_q24 valid */
+ SP_VI_CALI_ABORTED, /* Graph stopped before the run finished */
};
struct sp_vi_r0_result {
@@ -32,6 +33,8 @@ struct sp_vi_r0_result {
u32 num_ch;
s32 r0_cali_q24[MAX_SP_VI_SPEAKERS];
u32 seen_states[MAX_SP_VI_SPEAKERS];
+ /* Last calibration state per speaker (enum vi_calibration_state) */
+ u32 last_state[MAX_SP_VI_SPEAKERS];
};
static struct sp_vi_r0_result sp_vi_r0;
@@ -1608,16 +1611,10 @@ int audioreach_sp_register_speaker_map(struct thermal_zone_device * const *tzs,
}
EXPORT_SYMBOL_GPL(audioreach_sp_register_speaker_map);
-/*
- * Read each speaker's T0 in Q6 (degC * 64), 0 if its zone cannot be read.
- * Returns the number of slots read, or -EAGAIN if any registered slot came
- * back unreadable (e.g. the PA was on, so TADC was off). A partial reading
- * must not be cached as a valid calibration reference.
- */
+/* Read each speaker's T0 in Q6 (degC * 64), 0 if its zone cannot be read */
int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
{
unsigned int i, n;
- bool any_failed = false;
guard(mutex)(&sp_speaker_map_lock);
@@ -1626,23 +1623,33 @@ int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
int mdeg;
if (sp_speaker_map.tz[i] &&
- !thermal_zone_get_temp(sp_speaker_map.tz[i], &mdeg)) {
+ !thermal_zone_get_temp(sp_speaker_map.tz[i], &mdeg))
vals[i] = div_s64((s64)mdeg * 64, 1000);
- } else {
+ else
vals[i] = 0;
- any_failed = true;
- }
}
for (; i < count; i++)
vals[i] = 0;
- if (any_failed)
- return -EAGAIN;
-
return n;
}
EXPORT_SYMBOL_GPL(audioreach_get_sp_vi_t0);
+/* Latest calibration state per speaker, 0 before any event */
+int audioreach_get_sp_vi_cal_state(long *vals, unsigned int count)
+{
+ unsigned int i;
+
+ guard(mutex)(&sp_vi_r0_lock);
+
+ count = min(count, MAX_SP_VI_SPEAKERS);
+ for (i = 0; i < count; i++)
+ vals[i] = sp_vi_r0.last_state[i];
+
+ return count;
+}
+EXPORT_SYMBOL_GPL(audioreach_get_sp_vi_cal_state);
+
int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int count)
{
struct sp_vi_r0t0_cfg new = {};
@@ -1724,11 +1731,14 @@ void audioreach_vi_calibration_event(struct device *dev,
sp_vi_r0.state = SP_VI_CALI_RUNNING;
sp_vi_r0.num_ch = 0;
memset(sp_vi_r0.r0_cali_q24, 0, sizeof(sp_vi_r0.r0_cali_q24));
+ memset(sp_vi_r0.last_state, 0, sizeof(sp_vi_r0.last_state));
}
for (i = 0; i < num_ch; i++) {
u32 state = cali->cali_param[i].state;
+ sp_vi_r0.last_state[i] = state;
+
if (sp_vi_cali_state_is_failure(state))
success = false;
else if (!sp_vi_cali_state_is_terminal(state))
@@ -1772,24 +1782,16 @@ void audioreach_vi_calibration_event(struct device *dev,
/*
* Only a run where every speaker succeeded gives a usable R0/T0 set.
* The DSP reports only R0, so pair it with the speakers' last T0
- * reading. If any zone was unreadable (e.g. PA still on), skip the
- * cache: a 0 degC Q6 would be stored as a valid calibration ref.
+ * reading; a zone that cannot be read gives T0 = 0.
*/
if (success) {
- int t0_rc = audioreach_get_sp_vi_t0(t0_live, num_ch);
+ audioreach_get_sp_vi_t0(t0_live, num_ch);
- if (t0_rc < 0) {
- dev_warn(dev,
- "VI calibration: T0 unreadable, not caching R0/T0 (%d)\n",
- t0_rc);
- success = false;
- } else {
- guard(mutex)(&sp_vi_r0t0_cfg_lock);
- sp_vi_r0t0_cfg.num_ch = num_ch;
- for (i = 0; i < num_ch; i++) {
- sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
- sp_vi_r0t0_cfg.t0_cali_q6[i] = (s16)t0_live[i];
- }
+ guard(mutex)(&sp_vi_r0t0_cfg_lock);
+ sp_vi_r0t0_cfg.num_ch = num_ch;
+ for (i = 0; i < num_ch; i++) {
+ sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
+ sp_vi_r0t0_cfg.t0_cali_q6[i] = (s16)t0_live[i];
}
}
@@ -1799,11 +1801,51 @@ void audioreach_vi_calibration_event(struct device *dev,
audioreach_sp_finish_calibration();
}
+/* A run cut short never reports a final state, close it out */
+void audioreach_vi_calibration_abort(struct device *dev)
+{
+ unsigned int i;
+
+ /* Back to Normal before anything else, so a racing trigger is clean */
+ audioreach_sp_finish_calibration();
+
+ guard(mutex)(&sp_vi_r0_lock);
+
+ if (!sp_vi_r0.armed)
+ return;
+
+ sp_vi_r0.armed = false;
+
+ /* The DSP never reported on this run: keep the previous result */
+ if (!memchr_inv(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states)))
+ return;
+
+ sp_vi_r0.state = SP_VI_CALI_ABORTED;
+
+ for (i = 0; i < MAX_SP_VI_SPEAKERS; i++) {
+ u32 state = sp_vi_r0.last_state[i];
+
+ /* Slot never reported: not part of this run */
+ if (!sp_vi_r0.seen_states[i])
+ continue;
+
+ if (sp_vi_cali_state_is_terminal(state))
+ continue;
+
+ dev_info(dev, "VI calibration channel %u: aborted while %s\n",
+ i, sp_vi_cali_state_name(state));
+ sp_vi_r0.last_state[i] = VI_CALIBRATION_STATE_INACTIVE;
+ }
+
+ dev_info(dev, "VI calibration aborted: graph stopped before the DSP finished\n");
+}
+EXPORT_SYMBOL_GPL(audioreach_vi_calibration_abort);
+
static int audioreach_speaker_protection(struct q6apm_graph *graph,
- const struct audioreach_module *module)
+ const struct audioreach_module *module,
+ u32 mode)
{
- return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE,
- READ_ONCE(sp_operation_mode));
+ return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE, mode);
}
static int audioreach_register_events(struct q6apm_graph *graph,
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index e60e9c656122..25d1f47a6c75 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -1140,10 +1140,12 @@ int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int
int audioreach_sp_register_speaker_map(struct thermal_zone_device * const *tzs,
unsigned int num);
int audioreach_get_sp_vi_t0(long *vals, unsigned int count);
+int audioreach_get_sp_vi_cal_state(long *vals, unsigned int count);
int audioreach_add_sp_telemetry_controls(struct snd_soc_component *component);
void audioreach_vi_calibration_event(struct device *dev,
const struct event_id_vi_per_spkr_calibration *cali,
u32 num_ch);
+void audioreach_vi_calibration_abort(struct device *dev);
void audioreach_sp_shutdown(void);
int audioreach_compr_set_param(struct q6apm_graph *graph,
const struct audioreach_module_config *mcfg);
diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
index c410e2f6e6a3..35daf763287c 100644
--- a/sound/soc/qcom/qdsp6/q6apm.c
+++ b/sound/soc/qcom/qdsp6/q6apm.c
@@ -815,10 +815,19 @@ struct q6apm_graph *q6apm_graph_open(struct device *dev, q6apm_cb cb,
}
EXPORT_SYMBOL_GPL(q6apm_graph_open);
+static void q6apm_graph_abort_vi_calibration(struct q6apm_graph *graph)
+{
+ if (q6apm_find_module_by_mid(graph, MODULE_ID_SPEAKER_PROTECTION_VI))
+ audioreach_vi_calibration_abort(graph->dev);
+}
+
int q6apm_graph_close(struct q6apm_graph *graph)
{
struct audioreach_graph *ar_graph = graph->ar_graph;
+ /* Covers a graph closed without ever being started, e.g. on prepare failure */
+ q6apm_graph_abort_vi_calibration(graph);
+
graph->ar_graph = NULL;
kref_put(&ar_graph->refcount, q6apm_put_audioreach_graph);
gpr_free_port(graph->port);
@@ -854,6 +863,7 @@ EXPORT_SYMBOL_GPL(q6apm_graph_start);
int q6apm_graph_stop(struct q6apm_graph *graph)
{
struct audioreach_graph *ar_graph = graph->ar_graph;
+ int ret;
if (ar_graph->start_count == 0)
return 0;
@@ -861,7 +871,10 @@ int q6apm_graph_stop(struct q6apm_graph *graph)
if (--ar_graph->start_count > 0)
return 0;
- return audioreach_graph_mgmt_cmd(ar_graph, APM_CMD_GRAPH_STOP);
+ ret = audioreach_graph_mgmt_cmd(ar_graph, APM_CMD_GRAPH_STOP);
+ q6apm_graph_abort_vi_calibration(graph);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(q6apm_graph_stop);
diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
index a8fdd73cdecd..16327961d6c1 100644
--- a/sound/soc/qcom/qdsp6/topology.c
+++ b/sound/soc/qcom/qdsp6/topology.c
@@ -1548,6 +1548,45 @@ static int audioreach_get_sp_t0(struct snd_kcontrol *kcontrol,
return 0;
}
+static int audioreach_get_sp_cal_state(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ audioreach_get_sp_vi_cal_state(ucontrol->value.integer.value,
+ MAX_SP_VI_SPEAKERS);
+
+ return 0;
+}
+
+static int audioreach_info_sp_calibrate(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 1;
+
+ return 0;
+}
+
+static int audioreach_get_sp_calibrate(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ /* Trigger reads back as 0 so alsactl restore of a stored value is
+ * a no-op; writing 1 arms a single calibration run.
+ */
+ ucontrol->value.integer.value[0] = 0;
+ return 0;
+}
+
+static int audioreach_put_sp_calibrate(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ if (!ucontrol->value.integer.value[0])
+ return 0;
+
+ return audioreach_trigger_sp_calibration() ? : 1;
+}
+
static const struct snd_kcontrol_new audioreach_sp_telemetry_controls[] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -1557,6 +1596,30 @@ static const struct snd_kcontrol_new audioreach_sp_telemetry_controls[] = {
.info = audioreach_info_sp_t0,
.get = audioreach_get_sp_t0,
},
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Speaker Protection Calibration State",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ |
+ SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ /* Last calibration state per speaker (enum vi_calibration_state) */
+ .info = audioreach_info_sp_t0,
+ .get = audioreach_get_sp_cal_state,
+ },
+ {
+ /*
+ * Write-only edge trigger. Writing 1 arms a calibration run
+ * for the next (or current) WSA playback graph; the mode
+ * returns to Normal on its own once the DSP reports terminal
+ * state, on graph abort, or on the watchdog timeout.
+ */
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Speaker Protection Calibrate",
+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+ SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .info = audioreach_info_sp_calibrate,
+ .get = audioreach_get_sp_calibrate,
+ .put = audioreach_put_sp_calibrate,
+ },
};
/* Kept apart from the topology SP controls, so FEs have them without it */
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (18 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 14:11 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
` (3 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
Speaker protection needs the WSA V/I sense capture running whenever the
speakers play.
Set multi_direction_codecs on the WSA Playback link so it can carry the
VI codec DAIs, with a params fixup for their 8 kHz, 32-bit format. The
core's capture stream events for such links power the VI widgets.
Nothing changes until the DT adds the VI DAIs to the link.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/x1e80100.c | 50 +++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
index 4fe86ec062c4..745975574658 100644
--- a/sound/soc/qcom/x1e80100.c
+++ b/sound/soc/qcom/x1e80100.c
@@ -7,6 +7,7 @@
#include <linux/soundwire/sdw.h>
#include <linux/spinlock.h>
#include <sound/pcm.h>
+#include <sound/pcm_params.h>
#include <sound/jack.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
@@ -223,6 +224,28 @@ static void x1e80100_snd_exit(struct snd_soc_pcm_runtime *rtd)
data->jack_setup = false;
}
+/* VI codec DAIs on the WSA playback link run at 8 kHz, 2 ch, S32_LE */
+static int x1e80100_wsa_vi_params_fixup(struct snd_soc_pcm_runtime *rtd,
+ struct snd_pcm_hw_params *params,
+ int stream)
+{
+ struct snd_interval *rate =
+ hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+ struct snd_interval *channels =
+ hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+ struct snd_mask *fmt =
+ hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
+
+ if (stream != SNDRV_PCM_STREAM_CAPTURE)
+ return 0;
+
+ rate->min = rate->max = 8000;
+ channels->min = channels->max = 2;
+ snd_mask_none(fmt);
+ snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
+ return 0;
+}
+
static int x1e80100_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params)
{
@@ -374,6 +397,20 @@ static int x1e80100_late_probe(struct snd_soc_card *card)
return 0;
}
+/* True if any codec DAI on this link has a capture stream (i.e. VI feedback). */
+static bool x1e80100_link_has_vi_codec(struct snd_soc_dai_link *link)
+{
+ int i;
+
+ for (i = 0; i < link->num_codecs; i++) {
+ const char *name = link->codecs[i].dai_name;
+
+ if (name && !strcmp(name, "VI"))
+ return true;
+ }
+ return false;
+}
+
static void x1e80100_add_be_ops(struct snd_soc_card *card)
{
struct snd_soc_dai_link *link;
@@ -386,6 +423,19 @@ static void x1e80100_add_be_ops(struct snd_soc_card *card)
link->be_hw_params_fixup = x1e80100_be_hw_params_fixup;
link->ops = &x1e80100_be_ops;
}
+
+ /*
+ * The WSA playback link also carries the VI codec DAIs when
+ * the DT wires them in. Only advertise multi_direction_codecs
+ * then, so stock setups without VI feedback do not pay the
+ * extra TX startup/prepare path.
+ */
+ if (link->id == WSA_CODEC_DMA_RX_0 &&
+ x1e80100_link_has_vi_codec(link)) {
+ link->multi_direction_codecs = 1;
+ link->multi_direction_params_fixup =
+ x1e80100_wsa_vi_params_fixup;
+ }
}
}
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (19 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 14:16 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
` (2 subsequent siblings)
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla
Look up the thermal zone of each WSA884x VI DAI on the WSA Playback
link, in DT order, and register them with
audioreach_sp_register_speaker_map() for the "Speaker Protection T0"
control. A missing zone is logged and leaves its slot reading 0. The
map is cleared when the link is torn down.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/qcom/qdsp6/audioreach.c | 13 +++----
sound/soc/qcom/x1e80100.c | 62 ++++++++++++++++++++++++++++++-
2 files changed, 67 insertions(+), 8 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index 166ce59347f8..cf30c18fa25f 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -1731,7 +1731,6 @@ void audioreach_vi_calibration_event(struct device *dev,
sp_vi_r0.state = SP_VI_CALI_RUNNING;
sp_vi_r0.num_ch = 0;
memset(sp_vi_r0.r0_cali_q24, 0, sizeof(sp_vi_r0.r0_cali_q24));
- memset(sp_vi_r0.last_state, 0, sizeof(sp_vi_r0.last_state));
}
for (i = 0; i < num_ch; i++) {
@@ -1806,9 +1805,6 @@ void audioreach_vi_calibration_abort(struct device *dev)
{
unsigned int i;
- /* Back to Normal before anything else, so a racing trigger is clean */
- audioreach_sp_finish_calibration();
-
guard(mutex)(&sp_vi_r0_lock);
if (!sp_vi_r0.armed)
@@ -1838,14 +1834,17 @@ void audioreach_vi_calibration_abort(struct device *dev)
}
dev_info(dev, "VI calibration aborted: graph stopped before the DSP finished\n");
+
+ /* Edge-triggered: the mode auto-returns to Normal on abort too. */
+ audioreach_sp_finish_calibration();
}
EXPORT_SYMBOL_GPL(audioreach_vi_calibration_abort);
static int audioreach_speaker_protection(struct q6apm_graph *graph,
- const struct audioreach_module *module,
- u32 mode)
+ const struct audioreach_module *module)
{
- return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE, mode);
+ return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE,
+ READ_ONCE(sp_operation_mode));
}
static int audioreach_register_events(struct q6apm_graph *graph,
diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
index 745975574658..938d444f0e4b 100644
--- a/sound/soc/qcom/x1e80100.c
+++ b/sound/soc/qcom/x1e80100.c
@@ -6,6 +6,7 @@
#include <linux/platform_device.h>
#include <linux/soundwire/sdw.h>
#include <linux/spinlock.h>
+#include <linux/thermal.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/jack.h>
@@ -13,6 +14,7 @@
#include <sound/soc-dapm.h>
#include "common.h"
+#include "qdsp6/audioreach.h"
#include "qdsp6/q6afe.h"
#include "qdsp6/q6dsp-common.h"
#include "sdw.h"
@@ -162,16 +164,63 @@ static int x1e80100_add_wsa_chmap_ctls(struct snd_soc_pcm_runtime *rtd,
return 0;
}
+/*
+ * Register the thermal zones of the link's wsa884x VI DAIs, in DT order,
+ * which is the VI channel order.
+ */
+static void x1e80100_register_sp_speakers(struct snd_soc_pcm_runtime *rtd)
+{
+ struct thermal_zone_device *tzs[MAX_SP_VI_SPEAKERS];
+ struct snd_soc_dai *codec_dai;
+ unsigned int num = 0;
+ int i;
+
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
+ struct snd_soc_component *component = codec_dai->component;
+ struct thermal_zone_device *tz;
+ struct sdw_slave *slave;
+ char tz_name[THERMAL_NAME_LENGTH];
+
+ if (strcmp(codec_dai->name, "VI"))
+ continue;
+ if (!component || !component->dev)
+ continue;
+ if (num >= ARRAY_SIZE(tzs))
+ break;
+
+ /* The name wsa884x registers its thermal zone under */
+ slave = dev_to_sdw_dev(component->dev);
+ scnprintf(tz_name, sizeof(tz_name), "wsa-%d-%u",
+ slave->bus->id, slave->id.unique_id);
+ tz = thermal_zone_get_zone_by_name(tz_name);
+ if (IS_ERR(tz)) {
+ dev_warn(rtd->dev,
+ "no thermal zone '%s' for %s (%ld); SP T0 kcontrol will read 0 for this slot\n",
+ tz_name, dev_name(component->dev),
+ PTR_ERR(tz));
+ tz = NULL;
+ }
+ tzs[num++] = tz;
+ }
+
+ /* Also drops the zones of a previous bind when none are found */
+ audioreach_sp_register_speaker_map(tzs, num);
+}
+
static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)
{
struct x1e80100_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
struct snd_soc_card *card = rtd->card;
struct snd_soc_jack *dp_jack = NULL;
+ bool register_sp = false;
int dp_pcm_id = 0;
+ int ret;
switch (cpu_dai->id) {
case WSA_CODEC_DMA_RX_0:
+ register_sp = true;
+ fallthrough;
case WSA_CODEC_DMA_RX_1:
/*
* Set limit of -3 dB on Digital Volume and 0 dB on PA Volume
@@ -204,7 +253,15 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)
if (dp_jack)
return qcom_snd_dp_jack_setup(rtd, dp_jack, dp_pcm_id);
- return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup);
+ ret = qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup);
+ if (ret)
+ return ret;
+
+ /* Only register once init cannot fail further, so snd_exit runs */
+ if (register_sp)
+ x1e80100_register_sp_speakers(rtd);
+
+ return 0;
}
static void x1e80100_snd_exit(struct snd_soc_pcm_runtime *rtd)
@@ -220,6 +277,9 @@ static void x1e80100_snd_exit(struct snd_soc_pcm_runtime *rtd)
break;
}
+ if (cpu_dai->id == WSA_CODEC_DMA_RX_0)
+ audioreach_sp_register_speaker_map(NULL, 0);
+
qcom_snd_headset_jack_cleanup(rtd);
data->jack_setup = false;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (20 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 14:18 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-12-04 11:31 ` [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Ravi Hothi,
Srinivas Kandagatla, Abel Vesa
From: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Add the V/I sense DAIs of the four WSA8845 speakers, the SoundWire VI
ports and the WSA macro VI capture DAIs to the WSA Playback link, for
speaker protection. The speakers now expose two DAIs, so give them a
'#sound-dai-cells' of 1 and address the playback DAI explicitly.
The playback-side WSA SPKR codec DAIs sit next to the speaker-
protection VI capture-side DAIs on both WSA (left) and WSA2 (right)
buses on the same WSA Playback link. One MM1 playback open brings up
both chains via the machine driver's multi_direction_codecs flag; the
SP<->SP_VI control link in the topology handles the DSP-side pairing.
Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reviewed-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
arch/arm64/boot/dts/qcom/glymur-crd.dtsi | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
index 58158b51fe29..93bee2a97e54 100644
--- a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
+++ b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
@@ -257,10 +257,16 @@ cpu {
};
codec {
- sound-dai = <&left_woofer>, <&left_tweeter>,
+ sound-dai = <&left_woofer 0>, <&left_tweeter 0>,
<&swr0 0>, <&lpass_wsamacro 0>,
- <&right_woofer>, <&right_tweeter>,
- <&swr3 0>, <&lpass_wsa2macro 0>;
+ <&left_woofer 1>, <&left_tweeter 1>,
+ <&swr0 12>, <&swr0 13>,
+ <&lpass_wsamacro 2>,
+ <&right_woofer 0>, <&right_tweeter 0>,
+ <&swr3 0>, <&lpass_wsa2macro 0>,
+ <&right_woofer 1>, <&right_tweeter 1>,
+ <&swr3 12>, <&swr3 13>,
+ <&lpass_wsa2macro 2>;
};
platform {
@@ -923,7 +929,7 @@ left_woofer: speaker@0,0 {
compatible = "sdw20217020400";
reg = <0 0>;
reset-gpios = <&lpass_tlmm 12 GPIO_ACTIVE_LOW>;
- #sound-dai-cells = <0>;
+ #sound-dai-cells = <1>;
sound-name-prefix = "WooferLeft";
vdd-1p8-supply = <&vreg_l15b_e0_1p8>;
vdd-io-supply = <&vreg_l18b_e0_1p2>;
@@ -935,7 +941,7 @@ left_tweeter: speaker@0,1 {
compatible = "sdw20217020400";
reg = <0 1>;
reset-gpios = <&lpass_tlmm 12 GPIO_ACTIVE_LOW>;
- #sound-dai-cells = <0>;
+ #sound-dai-cells = <1>;
sound-name-prefix = "TweeterLeft";
vdd-1p8-supply = <&vreg_l15b_e0_1p8>;
vdd-io-supply = <&vreg_l18b_e0_1p2>;
@@ -951,7 +957,7 @@ right_woofer: speaker@0,0 {
compatible = "sdw20217020400";
reg = <0 0>;
reset-gpios = <&lpass_tlmm 13 GPIO_ACTIVE_LOW>;
- #sound-dai-cells = <0>;
+ #sound-dai-cells = <1>;
sound-name-prefix = "WooferRight";
vdd-1p8-supply = <&vreg_l15b_e0_1p8>;
vdd-io-supply = <&vreg_l18b_e0_1p2>;
@@ -963,7 +969,7 @@ right_tweeter: speaker@0,1 {
compatible = "sdw20217020400";
reg = <0 1>;
reset-gpios = <&lpass_tlmm 13 GPIO_ACTIVE_LOW>;
- #sound-dai-cells = <0>;
+ #sound-dai-cells = <1>;
sound-name-prefix = "TweeterRight";
vdd-1p8-supply = <&vreg_l15b_e0_1p8>;
vdd-io-supply = <&vreg_l18b_e0_1p2>;
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (21 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
@ 2026-12-04 11:30 ` Srinivas Kandagatla
2026-12-04 14:16 ` sashiko-bot
2026-12-04 11:31 ` [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:30 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla,
Abel Vesa
Add the V/I sense DAIs of the two WSA8845 speakers, the SoundWire VI
ports and the WSA macro VI capture DAI to the WSA Playback link, for
speaker protection. The speakers now expose two DAIs, so give them a
'#sound-dai-cells' of 1 and address the playback DAI explicitly.
The playback-side WSA SPKR codec DAIs sit next to the speaker-
protection VI capture-side DAIs on the same WSA Playback link. One
MM1 playback open brings up both chains via the machine driver's
multi_direction_codecs flag; the SP<->SP_VI control link in the
topology handles the DSP-side pairing.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reviewed-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
.../dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/boot/dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts b/arch/arm64/boot/dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts
index 26d6d8285e04..35419545d715 100644
--- a/arch/arm64/boot/dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts
+++ b/arch/arm64/boot/dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts
@@ -269,8 +269,11 @@ cpu {
};
codec {
- sound-dai = <&left_spkr>, <&right_spkr>,
- <&swr0 0>, <&lpass_wsamacro 0>;
+ sound-dai = <&left_spkr 0>, <&right_spkr 0>,
+ <&swr0 0>, <&lpass_wsamacro 0>,
+ <&left_spkr 1>, <&right_spkr 1>,
+ <&swr0 12>, <&swr0 13>,
+ <&lpass_wsamacro 2>;
};
platform {
@@ -928,7 +931,7 @@ left_spkr: speaker@0,0 {
compatible = "sdw20217020400";
reg = <0 0>;
reset-gpios = <&lpass_tlmm 12 GPIO_ACTIVE_LOW>;
- #sound-dai-cells = <0>;
+ #sound-dai-cells = <1>;
sound-name-prefix = "SpkrLeft";
vdd-1p8-supply = <&vreg_l15b_e0_1p8>;
vdd-io-supply = <&vreg_l18b_e0_1p2>;
@@ -940,7 +943,7 @@ right_spkr: speaker@0,1 {
compatible = "sdw20217020400";
reg = <0 1>;
reset-gpios = <&lpass_tlmm 12 GPIO_ACTIVE_LOW>;
- #sound-dai-cells = <0>;
+ #sound-dai-cells = <1>;
sound-name-prefix = "SpkrRight";
vdd-1p8-supply = <&vreg_l15b_e0_1p8>;
vdd-io-supply = <&vreg_l18b_e0_1p2>;
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: add WSA speaker protection VI feedback
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (22 preceding siblings ...)
2026-12-04 11:30 ` [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
@ 2026-12-04 11:31 ` Srinivas Kandagatla
2026-12-04 14:24 ` sashiko-bot
23 siblings, 1 reply; 45+ messages in thread
From: Srinivas Kandagatla @ 2026-12-04 11:31 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Kuninori Morimoto,
Pierre-Louis Bossart, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
Randy Dunlap, Shuah Khan, linux-sound, linux-arm-msm, devicetree,
alsa-devel, linux-doc, linux-kernel, Srinivas Kandagatla,
Abel Vesa
Add the V/I sense DAIs of the two WSA8845 speakers, the SoundWire VI
ports and the WSA macro VI capture DAI to the WSA Playback link, for
speaker protection. The speakers now expose two DAIs, so give them a
'#sound-dai-cells' of 1 and address the playback DAI explicitly.
The VI sense master ports (10 and 11) are picked up from the VISENSE
slot of the per-speaker qcom,port-mapping, which differs from the
mahua-t14s Gen 7 layout (12/13).
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reviewed-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
.../boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi b/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
index 93c7e3a02041..2242bbe59d94 100644
--- a/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
+++ b/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
@@ -478,7 +478,11 @@ cpu {
};
codec {
- sound-dai = <&left_spkr>, <&right_spkr>, <&swr0 0>, <&lpass_wsamacro 0>;
+ sound-dai = <&left_spkr 0>, <&right_spkr 0>,
+ <&swr0 0>, <&lpass_wsamacro 0>,
+ <&left_spkr 1>, <&right_spkr 1>,
+ <&swr0 10>, <&swr0 11>,
+ <&lpass_wsamacro 2>;
};
platform {
@@ -1340,7 +1344,7 @@ left_spkr: speaker@0,0 {
compatible = "sdw20217020400";
reg = <0 0>;
reset-gpios = <&lpass_tlmm 12 GPIO_ACTIVE_LOW>;
- #sound-dai-cells = <0>;
+ #sound-dai-cells = <1>;
sound-name-prefix = "SpkrLeft";
vdd-1p8-supply = <&vreg_l15b_1p8>;
vdd-io-supply = <&vreg_l12b_1p2>;
@@ -1352,7 +1356,7 @@ right_spkr: speaker@0,1 {
compatible = "sdw20217020400";
reg = <0 1>;
reset-gpios = <&lpass_tlmm 12 GPIO_ACTIVE_LOW>;
- #sound-dai-cells = <0>;
+ #sound-dai-cells = <1>;
sound-name-prefix = "SpkrRight";
vdd-1p8-supply = <&vreg_l15b_1p8>;
vdd-io-supply = <&vreg_l12b_1p2>;
--
2.53.0
^ permalink raw reply related [flat|nested] 45+ messages in thread
* Re: [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag
2026-12-04 11:30 ` [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
@ 2026-12-04 12:01 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 12:01 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] ASoC: soc-dapm: dapm_codec_stream_event() affects unflipped
codec DAIs
- [Medium] ASoC: soc-pcm: opposite-direction codec DAIs still receive
mute_stream()
- [Medium] ASoC: soc-pcm: soc_pcm_dapm_update_dai_at_stream() always
writes stream
- [Medium] ASoC: soc-pcm: duplicate dapm_power_widgets() pass and
unneeded export
- [Medium] ASoC: soc-pcm: soc_pcm_hw_clean() ignores pmdown_time for
flipped codecs
- [Medium] ASoC: soc-pcm: flipped codec DAIs contaminate symmetry
constraints
- [Medium] ASoC: soc-pcm: substream->stream flip races with
dpcm_be_dai_trigger()
--
commit fcaf0cac3ec4ae2256dfd816dfc3e318cc74138a
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: soc-pcm: add multi_direction_codecs link flag
This commit adds a multi_direction_codecs flag and an optional
multi_direction_params_fixup callback to struct snd_soc_dai_link so
opposite-direction codec DAIs on a link have .hw_params, .hw_free, and DAPM
stream events run in their own direction.
> diff --git a/Documentation/sound/soc/multi-direction-codecs.rst b/Documentation/sound/soc/multi-direction-codecs.rst
> new file mode 100644
> index 0000000000000..8d3fa62bb1c6a
> --- /dev/null
> +++ b/Documentation/sound/soc/multi-direction-codecs.rst
[ ... ]
> +Only ``.hw_params`` and ``.hw_free`` are called on the opposite-direction
> +codec DAIs. Their ``.startup``, ``.prepare``, ``.trigger``,
> +``.shutdown`` and mute callbacks are not, so a codec DAI used this way
> +must not depend on them.
[Severity: Medium]
Are mute callbacks actually skipped for opposite-direction codec DAIs?
snd_soc_dai_digital_mute() does not check snd_soc_dai_stream_valid(), and
snd_soc_runtime_action() increments stream[stream].active on every DAI on
the link. __soc_pcm_prepare(), soc_pcm_hw_clean(),
snd_soc_pcm_dai_trigger(), and snd_soc_playback_digital_mute() iterate
for_each_rtd_dais(), so an opposite-direction codec DAI that defines
.mute_stream will still be called with the unflipped stream direction.
Also, the machine-driver example below describes a DPCM backend link but
omits .no_pcm = 1, which would instead register a userspace-exposed PCM.
[ ... ]
> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
> index 3ef13d2b1f5e9..4bda3e5b930d0 100644
> --- a/sound/soc/soc-dapm.c
> +++ b/sound/soc/soc-dapm.c
> @@ -4670,6 +4670,18 @@ static void dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, int e
> dapm_power_widgets(rtd->card, event, NULL);
> }
>
> +static void dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd,
> + int stream, int event)
> +{
> + struct snd_soc_dai *codec_dai;
> + int i;
> +
> + for_each_rtd_codec_dais(rtd, i, codec_dai)
> + dapm_dai_stream_event(codec_dai, stream, event);
> +
> + dapm_power_widgets(rtd->card, event, NULL);
> +}
[Severity: Medium]
Can dapm_codec_stream_event() toggle widgets on bidirectional codec DAIs
that were never direction-flipped?
__soc_pcm_hw_params() and soc_pcm_hw_clean() only flip a codec DAI when
!snd_soc_dai_stream_valid(codec_dai, substream->stream), so a codec DAI
supporting both directions stays unflipped. Because
dapm_codec_stream_event() iterates every codec DAI without that check and
dapm_dai_stream_event() uses non-refcounted w->active and w->is_ep flags,
__soc_pcm_prepare() will power up an unconfigured opposite-direction path
and soc_pcm_hw_clean() will power down an active stream in that direction.
Link instantiation also does not validate that a multi_direction_codecs
link is unidirectional, so setting the flag on a bidirectional link lets
one direction clobber the other's DAI and DAPM state.
[ ... ]
> @@ -4691,6 +4703,26 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
> snd_soc_dapm_mutex_unlock(card);
> }
>
> +/**
> + * snd_soc_dapm_codec_stream_event - stream event limited to codec-side DAIs
> + * @rtd: PCM runtime data
> + * @stream: stream direction
> + * @event: stream event
> + *
> + * Variant of snd_soc_dapm_stream_event() that only targets codec-side DAIs.
> + * Used by multi_direction_codecs links to power up/down the flipped-
> + * direction codec widgets without altering the CPU DAI's direction
> + * tracking.
> + */
> +void snd_soc_dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd,
> + int stream, int event)
> +{
> + snd_soc_dapm_mutex_lock(rtd->card);
> + dapm_codec_stream_event(rtd, stream, event);
> + snd_soc_dapm_mutex_unlock(rtd->card);
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_dapm_codec_stream_event);
[Severity: Medium]
Why is this a separate exported entry point instead of handling
multi_direction_codecs inside dapm_stream_event()?
Calling snd_soc_dapm_codec_stream_event() right after
snd_soc_dapm_stream_event() or snd_soc_dapm_stream_stop() takes
card->dapm_mutex twice and runs two full-card dapm_power_widgets() passes
(including duplicate bias-domain syncs, component stream_event callbacks,
and pop waits) on every prepare and hw_free, while also allowing other
DAPM work to interleave between powering up the two directions.
EXPORT_SYMBOL_GPL() is also unnecessary here since
snd_soc_dapm_stream_event() is unexported and soc-dapm.o and soc-pcm.o are
in the same snd-soc-core module.
[ ... ]
> diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
> index dac353fec4bcf..c1b32c5f2f2dc 100644
> --- a/sound/soc/soc-pcm.c
> +++ b/sound/soc/soc-pcm.c
[ ... ]
> +/* hw_free counterpart to soc_pcm_dai_hw_params_at_stream(). */
> +static void soc_pcm_dai_hw_free_at_stream(struct snd_soc_dai *dai,
> + struct snd_pcm_substream *substream,
> + int rollback, int stream)
> +{
> + int saved_stream = substream->stream;
> +
> + if (stream == saved_stream) {
> + snd_soc_dai_hw_free(dai, substream, rollback);
> + return;
> + }
> +
> + substream->stream = stream;
> + snd_soc_dai_hw_free(dai, substream, rollback);
> + substream->stream = saved_stream;
> +}
[Severity: Medium]
Can flipping be_substream->stream in soc_pcm_dai_hw_free_at_stream() race
with dpcm_be_dai_trigger()?
When two playback FEs (FE1, FE2) share a multi_direction_codecs BE (BE1)
and FE2 is also routed to a second BE (BE2), FE1 can be in
SND_SOC_DPCM_STATE_PREPARE while FE2 transitions BE1 to
SND_SOC_DPCM_STATE_STOP and then fails hw_params on BE2. Unlike
dpcm_be_dai_hw_free(), the unwind loop in dpcm_be_dai_hw_params() does not
skip BEs with users > 1 and allows SND_SOC_DPCM_STATE_STOP, so it calls
__soc_pcm_hw_free() under pcm_mutex without holding be_substream's stream
lock:
CPU0 (FE2 hw_params unwind) CPU1 (FE1 trigger start)
dpcm_be_dai_hw_params()
lock(&card->pcm_mutex)
__soc_pcm_hw_free(BE1, ...)
soc_pcm_dai_hw_free_at_stream()
be_substream->stream = CAPTURE
dai->ops->hw_free() (sleeps)
dpcm_be_dai_trigger(FE1, ...)
/* no pcm_mutex */
soc_pcm_trigger(be_substream, ...)
soc_dai_trigger()
reads be_substream->stream
<-- sees capture
Observing capture makes soc_dai_trigger() silently skip the playback-only
CPU and codec DAIs while still marking BE1 as started, and dispatches
SNDRV_PCM_TRIGGER_START to the capture-only codec DAIs.
> +/* DAPM counterpart, so the DAI's own direction widget gets updated */
> +static void soc_pcm_dapm_update_dai_at_stream(struct snd_pcm_substream *substream,
> + struct snd_pcm_hw_params *params,
> + struct snd_soc_dai *dai, int stream)
> +{
> + int saved_stream = substream->stream;
> +
> + substream->stream = stream;
> + snd_soc_dapm_update_dai(substream, params, dai);
> + substream->stream = saved_stream;
> +}
[Severity: Medium]
Should soc_pcm_dapm_update_dai_at_stream() check stream == saved_stream, or
pass stream directly to snd_soc_dapm_update_dai()?
Unlike its sibling helpers above, this function unconditionally writes
substream->stream twice for every codec DAI on every ASoC link, even when
multi_direction_codecs is not set. ALSA core paths such as snd_pcm_info()
and snd_pcm_poll() read substream->stream without card->pcm_mutex, so this
introduces a data race across all ASoC links.
Since snd_soc_dapm_update_dai() is an unexported helper whose callee
dapm_update_dai_unlocked() only copies substream->stream into a local dir
variable, passing stream as a parameter would avoid mutating
substream->stream altogether.
[ ... ]
> @@ -1053,6 +1113,10 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd,
>
> /* run the stream event */
> snd_soc_dapm_stream_stop(rtd, substream->stream);
> + /* Flip only codec-side widgets; see __soc_pcm_prepare(). */
> + if (rtd->dai_link->multi_direction_codecs)
> + snd_soc_dapm_codec_stream_event(rtd, substream->stream ^ 1,
> + SND_SOC_DAPM_STREAM_STOP);
[Severity: Medium]
Does this power down the opposite-direction codec widgets prematurely when
pmdown_time is active?
For playback streams without ignore_pmdown_time, snd_soc_dapm_stream_stop()
defers SND_SOC_DAPM_STREAM_STOP to rtd->delayed_work
(snd_soc_close_delayed_work()), whereas this call stops the companion codec
widgets synchronously in hw_free. Moving the multi_direction_codecs
handling into dapm_stream_event() would keep both directions aligned with
pmdown_time.
[ ... ]
> @@ -1148,13 +1245,15 @@ static int __soc_pcm_hw_params(struct snd_pcm_substream *substream,
> if (ch_mask)
> soc_pcm_codec_params_fixup(&tmp_params, ch_mask);
>
> - ret = snd_soc_dai_hw_params(codec_dai, substream,
> - &tmp_params);
> - if(ret < 0)
> + ret = soc_pcm_dai_hw_params_at_stream(codec_dai, substream,
> + &tmp_params,
> + codec_stream);
> + if (ret < 0)
> goto out;
>
> snd_soc_dai_symmetric_set_params(codec_dai, &tmp_params);
> - snd_soc_dapm_update_dai(substream, &tmp_params, codec_dai);
> + soc_pcm_dapm_update_dai_at_stream(substream, &tmp_params,
> + codec_dai, codec_stream);
> }
[Severity: Medium]
Can calling snd_soc_dai_symmetric_set_params() on a direction-flipped codec
DAI contaminate symmetry constraints for later playback streams?
Because __soc_pcm_open() marks every DAI on the link active and
snd_soc_dai_symmetric_apply() checks snd_soc_dai_active(dai) without
filtering by direction, storing rewritten opposite-direction params (such as
8 kHz / S32_LE from multi_direction_params_fixup) into codec_dai causes a
second stream opening the link to inherit those values as single-value
constraints when symmetric_{rate,channels,sample_bits} is enabled, failing
open with -EINVAL. This also contradicts the note in
Documentation/sound/soc/multi-direction-codecs.rst claiming symmetric-params
tracking cannot cross-contaminate.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
2026-12-04 11:30 ` [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
@ 2026-12-04 12:12 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 12:12 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] ASoC: qcom: sdw: leak and skipped master DAI in
qcom_snd_sdw_setup_dir()
- [High] ASoC: soc-dai: NULL ops dereference in
snd_soc_dai_get/set_stream()
- [High] ASoC: qcom: missing qcom_snd_is_sdw_dai() guard in
qcom_snd_sdw_shutdown()
- [Medium] ASoC: qcom: sdw: state check misses SDW_STREAM_RELEASED after
hw_free
- [Low] ASoC: qcom: sdw: un-updated qcom_snd_sdw_get_stream() and
startup kernel-doc
- [Low] ASoC: qcom: sdw: stale sdw_release_stream() doc in
qcom_snd_sdw_startup()
--
commit 4ced7dc60766c6a8522f7fc64244cb10f6e35c6f
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
This commit splits the Qualcomm SoundWire startup, prepare, hw_free, and
shutdown helpers into per-direction operations so that multi_direction_codecs
links allocate and manage separate sdw_stream_runtime instances for playback
and capture. It also adds a sdw_find_dir_stream() helper and suffixes
allocated stream names with "-Playback" or "-Capture".
> diff --git a/sound/soc/qcom/sdw.c b/sound/soc/qcom/sdw.c
> index e19adb7c750b0..35b35f43d6fed 100644
> --- a/sound/soc/qcom/sdw.c
> +++ b/sound/soc/qcom/sdw.c
[ ... ]
> +static struct sdw_stream_runtime *
> +sdw_find_dir_stream(struct snd_soc_pcm_runtime *rtd, int dir)
> +{
> + struct snd_soc_dai *codec_dai;
> + struct sdw_stream_runtime *sr;
> + int i;
> +
> + for_each_rtd_codec_dais(rtd, i, codec_dai) {
> + if (!snd_soc_dai_stream_valid(codec_dai, dir))
> + continue;
> + sr = snd_soc_dai_get_stream(codec_dai, dir);
> + if (!IS_ERR(sr) && sr)
> + return sr;
> + }
> + return NULL;
> +}
[Severity: High]
Can calling snd_soc_dai_get_stream() here cause a NULL pointer dereference
when a codec DAI leaves dai->driver->ops as NULL?
Unlike the other helpers in sound/soc/soc-dai.c, snd_soc_dai_get_stream()
and snd_soc_dai_set_stream() dereference dai->driver->ops->get_stream and
->set_stream without checking dai->driver->ops for NULL. Because
qcom_snd_sdw_shutdown() now calls sdw_find_dir_stream() without checking
qcom_snd_is_sdw_dai(), closing speaker playback on QCS8550 boards using
aw88166 (which has .ops == NULL on PRIMARY_MI2S_RX in
qcs8550-ayntec-common.dtsi) dereferences NULL dai->driver->ops and oopses.
[ ... ]
> @@ -50,43 +96,42 @@ static bool qcom_snd_is_sdw_dai(int id)
> return false;
> }
>
> -/**
> - * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC audio card
> - * @substream: The PCM substream from audio, as passed to snd_soc_ops->startup()
> - *
> - * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate and set
> - * Soundwire stream runtime to each codec DAI.
> - *
> - * The shutdown() callback should call sdw_release_stream() on the same
> - * sdw_stream_runtime.
> - *
> - * Return: 0 or errno
> +/*
> + * Allocate a stream runtime for one direction and set it on the codec DAIs
> + * of that direction.
> */
> -int qcom_snd_sdw_startup(struct snd_pcm_substream *substream)
> +static int qcom_snd_sdw_setup_dir(struct snd_soc_pcm_runtime *rtd, int dir)
> {
> - 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);
> - u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS];
> + const char *cpu_name = snd_soc_rtd_to_cpu(rtd, 0)->name;
> struct sdw_stream_runtime *sruntime;
> struct snd_soc_dai *codec_dai;
> + u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS];
> u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
> int ret, i, j;
> + bool used = false;
>
> - if (!qcom_snd_is_sdw_dai(cpu_dai->id))
> + for_each_rtd_codec_dais(rtd, i, codec_dai) {
> + if (snd_soc_dai_stream_valid(codec_dai, dir)) {
> + used = true;
> + break;
> + }
> + }
> + if (!used)
> return 0;
>
> - sruntime = sdw_alloc_stream(cpu_dai->name, SDW_STREAM_PCM);
> + sruntime = qcom_snd_sdw_alloc_stream(cpu_name, dir);
> if (!sruntime)
> return -ENOMEM;
>
> for_each_rtd_codec_dais(rtd, i, codec_dai) {
> - ret = snd_soc_dai_set_stream(codec_dai, sruntime,
> - substream->stream);
> + if (!snd_soc_dai_stream_valid(codec_dai, dir))
> + continue;
> +
> + ret = snd_soc_dai_set_stream(codec_dai, sruntime, dir);
> if (ret < 0 && ret != -ENOTSUPP) {
> dev_err(rtd->dev, "Failed to set sdw stream on %s\n", codec_dai->name);
> - goto err_set_stream;
> + goto err;
> } else if (ret == -ENOTSUPP) {
> - /* Ignore unsupported */
> continue;
> }
[Severity: High]
Does filtering by snd_soc_dai_stream_valid() here skip direction-mismatched
SoundWire master DAIs and leak sruntime and sruntime->name?
On SM8650 WCD Capture (wcd-capture-dai-link in sm8650-hdk.dts), swr2 has
qcom,dout-ports = <1>, so qcom_swrm_register_dais() registers DAI 0
(<&swr2 0>) as playback-only. Previously <&swr2 0> still received and
returned sruntime, whereas now both qcom_snd_sdw_setup_dir() and
sdw_find_dir_stream() skip it, breaking master stream assignment and leaving
sdw_find_dir_stream() to return NULL at shutdown because <&wcd939x 1> has no
.get_stream.
Links that match qcom_snd_is_sdw_dai() but only have non-SoundWire codecs
(such as va-dai-link on TX_CODEC_DMA_TX_3 with <&lpass_vamacro 0> in
sm8550-mtp.dts) also allocate sruntime and its kasprintf()-allocated name
here, skip every codec on -ENOTSUPP, and leak both allocations on every
open/close cycle.
[ ... ]
> +/**
> + * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC audio card
> + * @substream: The PCM substream from audio, as passed to snd_soc_ops->startup()
> + *
> + * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate and set
> + * Soundwire stream runtime to each codec DAI.
> + *
> + * The shutdown() callback should call sdw_release_stream() on the same
> + * sdw_stream_runtime.
> + *
> + * Return: 0 or errno
> + */
[Severity: Low]
Should this kernel-doc be updated to say that shutdown() must call
qcom_snd_sdw_shutdown() instead of sdw_release_stream()?
Now that qcom_snd_sdw_alloc_stream() allocates sr->name with kasprintf()
and qcom_snd_sdw_startup() can allocate a second runtime on
multi_direction_codecs links, calling sdw_release_stream() directly leaks
sr->name and any opposite-direction stream runtime.
[ ... ]
> + if (rtd->dai_link->multi_direction_codecs) {
> + struct sdw_stream_runtime *sr_opp =
> + sdw_find_dir_stream(rtd, substream->stream ^ 1);
> +
> + /* 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;
> + }
> + }
> }
[Severity: Medium]
Does checking sr_opp->state != SDW_STREAM_ALLOCATED fail on a second
hw_params/prepare cycle after hw_free when no opposite-direction slave
registers?
During hw_free (or hw_params error rollback), qcom_swrm_hw_free() calls
sdw_stream_remove_master(), which sets sr_opp->state to SDW_STREAM_RELEASED
once master_list is empty rather than back to SDW_STREAM_ALLOCATED. On the
next hw_params without an opposite-direction slave (for example, V/I sense
disabled), sdw_stream_add_master() leaves sr_opp->state as
SDW_STREAM_RELEASED, so qcom_snd_sdw_prepare() calls
sdw_prepare_stream(sr_opp), which fails with -EINVAL and tears down the
primary stream.
qcom_snd_sdw_hw_free() uses the same sr->state != SDW_STREAM_ALLOCATED
guard, so it can also invoke sdw_disable_stream() and sdw_deprepare_stream()
on an unprepared opposite-direction stream in SDW_STREAM_RELEASED or
SDW_STREAM_CONFIGURED state.
[ ... ]
> @@ -188,9 +299,16 @@ EXPORT_SYMBOL_GPL(qcom_snd_sdw_get_stream);
[Severity: Low]
Should qcom_snd_sdw_get_stream() also delegate to sdw_find_dir_stream()
instead of keeping its open-coded loop?
qcom_swrm_get_sdw_stream() ignores its direction argument and returns
ctrl->sruntime[dai->id], so without snd_soc_dai_stream_valid() filtering,
qcom_snd_sdw_get_stream() can return the opposite direction's stream on
multi_direction_codecs links. The startup kernel-doc also still directs
callers to sdw_release_stream() rather than qcom_snd_sdw_shutdown().
> void qcom_snd_sdw_shutdown(struct snd_pcm_substream *substream)
> {
> - struct sdw_stream_runtime *sruntime = qcom_snd_sdw_get_stream(substream);
> + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> +
> + qcom_snd_sdw_release_stream(sdw_find_dir_stream(rtd, substream->stream));
>
> - sdw_release_stream(sruntime);
> + if (rtd->dai_link->multi_direction_codecs) {
> + struct sdw_stream_runtime *sr;
> +
> + sr = sdw_find_dir_stream(rtd, substream->stream ^ 1);
> + qcom_snd_sdw_release_stream(sr);
> + }
> }
> EXPORT_SYMBOL_GPL(qcom_snd_sdw_shutdown);
[Severity: High]
Is a qcom_snd_is_sdw_dai(cpu_dai->id) guard missing at the start of
qcom_snd_sdw_shutdown()?
Previously qcom_snd_sdw_get_stream() returned NULL early for non-SoundWire
CPU DAIs. Because machine drivers like sc8280xp.c attach
qcom_snd_sdw_shutdown() to all BE links, removing that guard causes
sdw_find_dir_stream() to run on non-SoundWire links such as PRIMARY_MI2S_RX
with aw88166 (.ops == NULL) on QCS8550 boards (qcs8550-ayntec-common.dtsi),
triggering a NULL pointer dereference in snd_soc_dai_get_stream() while
closing PCM playback.
If any non-SoundWire codec DAI implements .get_stream, this would also pass
that foreign pointer to qcom_snd_sdw_release_stream() and free memory that
qcom_snd_sdw_startup() never allocated.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=4
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 07/24] ASoC: codecs: wsa883x: add VI sense capture DAI
2026-12-04 11:30 ` [PATCH v5 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
@ 2026-12-04 12:33 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 12:33 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ASoC: wsa883x: wsa883x_vi_hw_params() ignores
port_enable[VISENSE]
- [Medium] ASoC: wsa883x: wsa883x_bus_config() ignores sdw_write()
return value
- [Low] ASoC: dt-bindings: qcom,wsa883x: #sound-dai-cells const 0 blocks
VI DAI
- [Low] ASoC: wsa883x: VI capture DAI rate_max 352800 masks 384000 Hz
rate
--
commit 54b0b64fce8c3a9ee9f1ba2ef2f6b69f8d602b09
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: codecs: wsa883x: add VI sense capture DAI
This commit moves the WSA883x VISENSE port to a SoundWire source port, adds
a separate VI capture DAI with its own stream runtime and ops, and installs
a bus_config handler to program SCP_HOST_CLK_DIV2.
> diff --git a/sound/soc/codecs/wsa883x.c b/sound/soc/codecs/wsa883x.c
> index 64391d654a08b..6de669288d6aa 100644
> --- a/sound/soc/codecs/wsa883x.c
> +++ b/sound/soc/codecs/wsa883x.c
[ ... ]
> @@ -1125,8 +1133,16 @@ static int wsa883x_port_prep(struct sdw_slave *slave,
> return 0;
> }
>
> +static int wsa883x_bus_config(struct sdw_slave *slave,
> + struct sdw_bus_params *params)
> +{
> + sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01);
> + return 0;
> +}
[Severity: Medium]
Should wsa883x_bus_config() return the status of sdw_write() instead of
unconditionally returning 0?
sdw_notify_config() checks the return value of bus_config() to abort
stream configuration before the bank switch. Discarding a SoundWire write
failure here allows the bank switch to proceed with the amplifier's bus
clock divider unprogrammed.
[ ... ]
> @@ -1335,6 +1351,25 @@ static const struct snd_soc_component_driver wsa883x_component_drv = {
> .num_dapm_routes = ARRAY_SIZE(wsa883x_audio_map),
> };
>
> +static int wsa883x_vi_hw_params(struct snd_pcm_substream *substream,
> + struct snd_pcm_hw_params *params,
> + struct snd_soc_dai *dai)
> +{
> + struct wsa883x_priv *wsa883x = dev_get_drvdata(dai->dev);
> +
> + wsa883x->vi_port_config = wsa883x_pconfig[WSA883X_PORT_VISENSE];
> + wsa883x->vi_sconfig.frame_rate = params_rate(params);
> + /* VISENSE carries the V and I sense pair */
> + wsa883x->vi_sconfig.ch_count = 2;
> + wsa883x->vi_sconfig.bps = 1;
> + wsa883x->vi_sconfig.type = SDW_STREAM_PDM;
> + wsa883x->vi_sconfig.direction = SDW_DATA_DIR_TX;
> +
> + return sdw_stream_add_slave(wsa883x->slave, &wsa883x->vi_sconfig,
> + &wsa883x->vi_port_config, 1,
> + wsa883x->vi_sruntime);
> +}
> +
> static int wsa883x_hw_params(struct snd_pcm_substream *substream,
> struct snd_pcm_hw_params *params,
> struct snd_soc_dai *dai)
> @@ -1344,6 +1379,9 @@ static int wsa883x_hw_params(struct snd_pcm_substream *substream,
>
> wsa883x->active_ports = 0;
> for (i = 0; i < WSA883X_MAX_SWR_PORTS; i++) {
> + /* VISENSE is driven by the separate VI capture DAI */
> + if (i == WSA883X_PORT_VISENSE)
> + continue;
> if (!wsa883x->port_enable[i])
> continue;
[Severity: Medium]
Does wsa883x_vi_hw_params() need to check
wsa883x->port_enable[WSA883X_PORT_VISENSE] before registering the slave?
With wsa883x_hw_params() skipping WSA883X_PORT_VISENSE, nothing reads
port_enable[WSA883X_PORT_VISENSE] anymore, leaving the "VISENSE Switch"
mixer control a no-op.
Calling sdw_stream_add_slave() unconditionally also transitions
vi_sruntime->state out of SDW_STREAM_ALLOCATED, defeating the VI-off skip
in qcom_snd_sdw_prepare() even when VI feedback is disabled.
[ ... ]
> @@ -1423,6 +1473,19 @@ static struct snd_soc_dai_driver wsa883x_dais[] = {
> },
> .ops = &wsa883x_dai_ops,
> },
> + {
> + .name = "VI",
> + .capture = {
> + .stream_name = "VI Capture",
> + .rates = WSA883X_RATES | WSA883X_FRAC_RATES,
> + .formats = WSA883X_FORMATS,
> + .rate_min = 8000,
> + .rate_max = 352800,
[Severity: Low]
Should .rate_max be 384000 here to match WSA883X_RATES?
WSA883X_RATES includes SNDRV_PCM_RATE_384000, so capping .rate_max at
352800 causes soc_pcm_hw_update_rate() to clamp the maximum rate and mask
out 384 kHz.
> + .channels_min = 1,
> + .channels_max = 2,
> + },
> + .ops = &wsa883x_vi_dai_ops,
> + },
[Severity: Low]
Does Documentation/devicetree/bindings/sound/qcom,wsa883x.yaml also need
an update to allow #sound-dai-cells = <1>?
The binding currently enforces #sound-dai-cells: const: 0, which prevents
schema-valid Device Trees from addressing this second DAI at index 1.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=7
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI
2026-12-04 11:30 ` [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
@ 2026-12-04 12:38 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 12:38 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ASoC: wsa884x: wsa884x_vi_hw_params() early return restored in
later patch
- [Medium] ASoC: wsa884x: 0-based SoundWire port bitmasks in
wsa884x_probe()
- [Medium] ASoC: wsa884x: wsa884x_vi_hw_params() retains stale VI slave
on ON->OFF
--
commit 6c4b9dc62cf97c2e651c0b64607fa0cb3c6ee792
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: codecs: wsa884x: add VI sense capture DAI
This commit moves the WSA884x VI sense port from the sink port list to
the source port list and adds a separate VI capture DAI with its own
SoundWire stream runtime and DAI ops.
> diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
> index f58ce92c46d40..abf9d88ec7a8a 100644
> --- a/sound/soc/codecs/wsa884x.c
> +++ b/sound/soc/codecs/wsa884x.c
[ ... ]
> @@ -1767,6 +1774,29 @@ static const struct snd_soc_component_driver wsa884x_component_drv = {
> .num_dapm_routes = ARRAY_SIZE(wsa884x_audio_map),
> };
>
> +static int wsa884x_vi_hw_params(struct snd_pcm_substream *substream,
> + struct snd_pcm_hw_params *params,
> + struct snd_soc_dai *dai)
> +{
> + struct wsa884x_priv *wsa884x = dev_get_drvdata(dai->dev);
> + unsigned int num_ports = 0;
> +
> + wsa884x->vi_sconfig.frame_rate = params_rate(params);
> + wsa884x->vi_sconfig.ch_count = 2;
> + wsa884x->vi_sconfig.bps = 1;
> + wsa884x->vi_sconfig.type = SDW_STREAM_PDM;
> + wsa884x->vi_sconfig.direction = SDW_DATA_DIR_TX;
> +
> + if (wsa884x->port_enable[WSA884X_PORT_VISENSE]) {
> + wsa884x->vi_port_config = wsa884x_pconfig[WSA884X_PORT_VISENSE];
> + num_ports = 1;
> + }
> +
> + return sdw_stream_add_slave(wsa884x->slave, &wsa884x->vi_sconfig,
> + &wsa884x->vi_port_config, num_ports,
> + wsa884x->vi_sruntime);
> +}
[Severity: High]
Does commit "ASoC: codecs: wsa884x: register the die temperature as a
thermal zone" later in this series accidentally revert this block back to
returning 0 early when port_enable[WSA884X_PORT_VISENSE] is false?
With that early return restored, vi_sruntime is never configured when
VISENSE Switch is off (its default state after probe). After hw_free()
on an open substream, qcom_swrm_hw_free() calls sdw_stream_remove_master()
and transitions vi_sruntime->state to SDW_STREAM_RELEASED.
On the next hw_params() and prepare(), qcom_snd_sdw_prepare() only skips
SDW_STREAM_ALLOCATED and calls sdw_prepare_stream(vi_sruntime), which
rejects SDW_STREAM_RELEASED with -EINVAL and breaks speaker playback.
If empty VI streams should be skipped instead of adding a zero-port slave,
qcom_snd_sdw_prepare() and qcom_snd_sdw_hw_free() in commit "ASoC: qcom:
sdw: add per-direction stream runtimes for multi_direction links" should
skip both SDW_STREAM_ALLOCATED and SDW_STREAM_RELEASED.
[Severity: Medium]
Can repeated hw_params() calls without an intervening hw_free() leave the
WSA884x slave runtime and DP5 port attached to vi_sruntime after VISENSE
Switch is turned off?
ALSA core (hw_params_state_check()) and ASoC DPCM (dpcm_be_dai_hw_params())
allow consecutive hw_params() calls without hw_free(). If VISENSE Switch
is enabled on the first call and disabled before the second,
wsa884x_vi_hw_params() never calls sdw_stream_remove_slave().
In this patch, sdw_stream_add_slave() sees sdw_slave_port_allocated(s_rt)
is already true, keeps and reconfigures DP5 from the stale vi_port_config,
and double-counts ch_count in sdw_config_stream(). Even with the early
return later in the series, DP5 stays attached and enabled on prepare().
Calling sdw_stream_remove_slave(wsa884x->slave, wsa884x->vi_sruntime) when
port_enable[WSA884X_PORT_VISENSE] is false detaches any stale port cleanly.
[ ... ]
> @@ -2091,9 +2156,11 @@ static int wsa884x_probe(struct sdw_slave *pdev,
> WSA884X_MAX_SWR_PORTS))
> dev_dbg(dev, "Static Port mapping not specified\n");
>
> - pdev->prop.sink_ports = GENMASK(WSA884X_MAX_SWR_PORTS - 1, 0);
> + pdev->prop.sink_ports = GENMASK(WSA884X_MAX_SWR_PORTS - 1, 0) & ~BIT(WSA884X_PORT_VISENSE);
> + pdev->prop.source_ports = BIT(WSA884X_PORT_VISENSE);
> pdev->prop.simple_clk_stop_capable = true;
> pdev->prop.sink_dpn_prop = wsa884x_sink_dpn_prop;
> + pdev->prop.src_dpn_prop = wsa884x_src_dpn_prop;
> pdev->prop.scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY;
[Severity: Medium]
Should sink_ports and source_ports use 1-based SoundWire Data Port bit
positions instead of 0-based enum wsa884x_port_ids values?
SoundWire core defines source_ports and sink_ports as 1-based bitmasks
covering Data Ports 1..14, matching dpn_prop[].num (where VISENSE is
WSA884X_PORT_VISENSE + 1, or DP5). sdw_slave_sysfs_dpn_init() creates
dpN_src and dpN_sink sysfs groups directly from each set bit.
As written, source_ports sets bit 4 (dp4_src) instead of bit 5 (dp5_src),
and sink_ports exposes an invalid dp0_sink and a misnumbered dp5_sink.
Using GENMASK(WSA884X_MAX_SWR_PORTS, 1) & ~BIT(WSA884X_PORT_VISENSE + 1)
and BIT(WSA884X_PORT_VISENSE + 1) matches the 1-based dpn_prop numbers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=6
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
2026-12-04 11:30 ` [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
@ 2026-12-04 13:25 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:25 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] ASoC: qcom: audioreach: argument mismatch breaks compilation
- [High] ASoC: qcom: audioreach: AB-BA deadlock on sp_vi_r0_lock and
watchdog
- [High] ASoC: qcom: q6apm: sp_cal_watchdog UAF due to early shutdown in
apm_remove()
- [Medium] ASoC: qcom: audioreach: races across sp_operation_mode,
armed, and watchdog
- [Medium] ASoC: qcom: audioreach: empty VI event falsely completes
calibration
- [Medium] ASoC: qcom: audioreach: missing VI disarm on error and
watchdog desync
- [Medium] ASoC: qcom: audioreach: audioreach_sp_shutdown() leaves
calibration stuck
- [Medium] ASoC: qcom: audioreach: split sp_operation_mode reads during
graph setup
--
commit 32fbe7bee8c50fa2ff9735485256480782651b1a
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
This commit introduces a module-global sp_operation_mode state and an
edge-triggered calibration API guarded by a 60-second delayed work watchdog,
automatically returning the mode to Normal when VI calibration reaches a
terminal state.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index a187e0b136330..be37681f467fb 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1456,6 +1459,65 @@ static int audioreach_gain_set(struct q6apm_graph *graph,
[ ... ]
> +static void audioreach_sp_cal_watchdog_fn(struct work_struct *work)
> +{
> + if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_CALIBRATION,
> + PARAM_ID_SP_VI_OP_MODE_NORMAL) !=
> + PARAM_ID_SP_VI_OP_MODE_CALIBRATION)
> + return;
> +
> + audioreach_sp_disarm_vi();
> + pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
> +}
> +
> +/* Finish before writing the mode so a trigger racing in cannot be clobbered */
> +static void audioreach_sp_finish_calibration(void)
> +{
> + cancel_delayed_work_sync(&sp_cal_watchdog);
> + WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
> +}
> +
> +/* Release the delayed work from the module on unload so the timer cannot fire */
> +void audioreach_sp_shutdown(void)
> +{
> + cancel_delayed_work_sync(&sp_cal_watchdog);
> +}
> +EXPORT_SYMBOL_GPL(audioreach_sp_shutdown);
[Severity: Medium]
Can audioreach_sp_shutdown() leave sp_operation_mode wedged in Calibration
across an ADSP subsystem restart?
On an ADSP crash/restart, apr_pd_status() invokes apr_remove_device() ->
apm_remove() and later re-probes via apm_probe() while snd-q6apm.ko stays
loaded. Because audioreach_sp_shutdown() cancels sp_cal_watchdog without
resetting sp_operation_mode to Normal or clearing sp_vi_r0.armed, no timer
remains to revert the mode, leaving subsequent calibration triggers failing
with -EBUSY and normal playback configuring Calibration mode until reboot or
module reload.
> +
> +int audioreach_trigger_sp_calibration(void)
> +{
> + if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL,
> + PARAM_ID_SP_VI_OP_MODE_CALIBRATION) !=
> + PARAM_ID_SP_VI_OP_MODE_NORMAL)
> + return -EBUSY;
> +
> + schedule_delayed_work(&sp_cal_watchdog,
> + SP_CAL_WATCHDOG_SECS * HZ);
> + return 0;
> +}
[Severity: Medium]
Can lockless updates to sp_operation_mode race with sp_vi_r0.armed and
sp_cal_watchdog, causing a stale watchdog or completion to corrupt a new
calibration run?
CPU0 CPU1
---- ----
audioreach_sp_cal_watchdog_fn()
cmpxchg(&sp_operation_mode,
CALIBRATION, NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(..., NORMAL, CALIBRATION)
schedule_delayed_work(...)
audioreach_arm_vi_calibration()
sp_vi_r0.armed = true
audioreach_sp_disarm_vi()
sp_vi_r0.armed = false <-- disarms the new run
Because sp_operation_mode is mutated via cmpxchg/WRITE_ONCE outside
sp_vi_r0_lock, an expiring watchdog can disarm a newly triggered run so its
events are silently dropped.
Two related races share the same cause: if audioreach_sp_finish_calibration()
runs between cmpxchg() and schedule_delayed_work() in
audioreach_trigger_sp_calibration(), it leaves an orphaned watchdog pending
that will fire early on a later run (since schedule_delayed_work() does not
re-arm a pending timer). Likewise, audioreach_sp_finish_calibration()
unconditionally cancels sp_cal_watchdog and writes Normal without verifying
run ownership, which can clobber a newly triggered run if the watchdog
already expired or if audioreach_speaker_protection_vi() armed VI from a
stale mode snapshot. Protecting sp_operation_mode, sp_vi_r0.armed, and
watchdog scheduling under a shared lock or generation counter would close
these races.
[ ... ]
> @@ -1506,10 +1568,6 @@ void audioreach_vi_calibration_event(struct device *dev,
> unsigned int i;
> u32 bit;
>
> - /* A payload with no entries gives no new information */
> - if (!num_ch)
> - return;
> -
> guard(mutex)(&sp_vi_r0_lock);
[Severity: Medium]
Why was the zero-channel guard removed here?
q6apm_vi_calibration_event() does not reject num_ch == 0, and in
audioreach_vi_calibration_event() both decisive and success start as true.
An empty calibration event therefore skips the channel loop and falls through
to record SP_VI_CALI_SUCCESS with num_ch = 0, wiping cached R0 values,
disarming sp_vi_r0, and prematurely returning sp_operation_mode to Normal.
[ ... ]
> @@ -1566,14 +1624,16 @@ void audioreach_vi_calibration_event(struct device *dev,
> }
>
> dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed");
> +
> + /* Edge-triggered: the mode auto-returns to Normal on terminal state. */
> + audioreach_sp_finish_calibration();
> }
[Severity: High]
Does calling audioreach_sp_finish_calibration() while holding sp_vi_r0_lock
create an ABBA deadlock with sp_cal_watchdog?
CPU0 CPU1
---- ----
lock(&sp_vi_r0_lock)
lock(&sp_cal_watchdog)
lock(&sp_cal_watchdog)
lock(&sp_vi_r0_lock)
*** DEADLOCK ***
CPU0: audioreach_vi_calibration_event() -> audioreach_sp_finish_calibration()
-> cancel_delayed_work_sync(&sp_cal_watchdog)
CPU1: audioreach_sp_cal_watchdog_fn() -> audioreach_sp_disarm_vi()
audioreach_sp_finish_calibration() calls cancel_delayed_work_sync() before
clearing sp_operation_mode, so an overlapping watchdog succeeds in cmpxchg()
and blocks on sp_vi_r0_lock. Because audioreach_vi_calibration_event() runs
on the single-threaded qcom_apr_rx workqueue, this permanently stalls all
QDSP6 GPR/APR IPC and triggers a lockdep inversion warning on every terminal
calibration event. Note that commit "ASoC: qcom: audioreach: send cached
R0/T0 to the VI module in normal mode" later avoids this deadlock by dropping
audioreach_sp_disarm_vi() and switching to cancel_delayed_work(), which
reintroduces races with a newly triggered run.
>
> static int audioreach_speaker_protection(struct q6apm_graph *graph,
> - const struct audioreach_module *module,
> - uint32_t operation_mode)
> + const struct audioreach_module *module)
> {
> return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE,
> - operation_mode);
> + READ_ONCE(sp_operation_mode));
> }
[Severity: Medium]
Can reading sp_operation_mode separately for MODULE_ID_SPEAKER_PROTECTION
and MODULE_ID_SPEAKER_PROTECTION_VI configure the two modules in mismatched
modes?
q6apm_graph_media_format_pcm() calls audioreach_set_media_format() for each
module in the graph across sleeping q6apm_send_cmd_sync() IPCs without
snapshotting sp_operation_mode once per graph setup. A calibration trigger
or watchdog expiry between the two modules can put SP in Normal and VI in
Calibration (failing with VI_CALIBRATION_STATE_INCORRECT_OP_MODE), or SP in
Calibration while VI stays in Normal without arming or registering events.
[ ... ]
> @@ -1640,11 +1701,13 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
> return -EINVAL;
> }
>
> - audioreach_arm_vi_calibration();
> + if (mode == PARAM_ID_SP_VI_OP_MODE_CALIBRATION) {
> + audioreach_arm_vi_calibration();
>
> - rc = audioreach_register_events(graph, module);
> - if (rc)
> - return rc;
> + rc = audioreach_register_events(graph, module);
> + if (rc)
> + return rc;
> + }
[Severity: Medium]
Does returning an error after audioreach_arm_vi_calibration() leave
sp_vi_r0.armed set?
If audioreach_register_events(), audioreach_alloc_apm_cmd_pkt(), or
q6apm_send_cmd_sync() fails, sp_vi_r0.armed stays true (allowing subsequent
DSP events to wipe cached R0 values) while sp_operation_mode stays in
Calibration until the watchdog fires. On watchdog timeout,
audioreach_sp_disarm_vi() also leaves sp_vi_r0.state stuck in
SP_VI_CALI_RUNNING, and commit "ASoC: qcom: audioreach: send cached R0/T0 to
the VI module in normal mode" later drops audioreach_sp_disarm_vi()
altogether, leaving sp_vi_r0.armed set as well.
[ ... ]
> @@ -1760,7 +1823,7 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
> break;
> case MODULE_ID_SPEAKER_PROTECTION:
> rc = audioreach_speaker_protection(graph, module,
> - PARAM_ID_SP_OP_MODE_CALIBRATION);
> + READ_ONCE(sp_operation_mode));
> if (!rc)
> rc = audioreach_module_enable(graph, module, true);
[Severity: High]
Does this commit compile?
audioreach_speaker_protection() was changed to take 2 arguments, but this
call site still passes 3; conversely, audioreach_speaker_protection_vi() was
changed to take a 4th mode argument, but the MODULE_ID_SPEAKER_PROTECTION_VI
case right below still passes only 3. This breaks builds whenever
CONFIG_SND_SOC_QDSP6_APM is enabled and breaks git bisectability across the
series (later commits in the series also mismatch these signatures before
reconciling them).
> diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
> index c410e2f6e6a3f..6494eb80f0897 100644
> --- a/sound/soc/qcom/qdsp6/q6apm.c
> +++ b/sound/soc/qcom/qdsp6/q6apm.c
> @@ -950,6 +950,8 @@ static int apm_probe(gpr_device_t *gdev)
>
> static void apm_remove(gpr_device_t *gdev)
> {
> + /* Release the SP calibration watchdog before the module goes away */
> + audioreach_sp_shutdown();
> g_apm = NULL;
> of_platform_depopulate(&gdev->dev);
> snd_soc_unregister_component(&gdev->dev);
[Severity: High]
Can sp_cal_watchdog be re-scheduled after audioreach_sp_shutdown() and fire
after snd-q6apm.ko is unloaded?
CPU0 CPU1
---- ----
apm_remove()
audioreach_sp_shutdown()
cancel_delayed_work_sync(...)
audioreach_trigger_sp_calibration()
schedule_delayed_work(&sp_cal_watchdog)
of_platform_depopulate(...)
snd_soc_unregister_component(...)
snd-q6apm.ko unloaded
audioreach_sp_cal_watchdog_fn()
<-- use-after-free in freed module
Because audioreach_sp_shutdown() runs before of_platform_depopulate() and
snd_soc_unregister_component(), the kcontrols remain active and can arm the
60-second watchdog again before teardown completes. The error path in
apm_probe() when of_platform_populate() fails also calls
snd_soc_unregister_component() without calling audioreach_sp_shutdown().
Calling audioreach_sp_shutdown() after both teardown calls (and keeping it
rather than dropping it in commit "ASoC: qcom: audioreach: send cached R0/T0
to the VI module in normal mode") would prevent the use-after-free.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=13
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker
2026-12-04 11:30 ` [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
@ 2026-12-04 13:32 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:32 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ASoC: qcom: audioreach: audioreach_speaker_protection_vi()
fails to disarm
- [Low] ASoC: qcom: audioreach: misformatted negative Q24 in
sp_vi_q24_to_int_frac()
--
commit 526a49a4a17fcef52a050edcbb06e65ae2642deb
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: cache VI calibration results per speaker
This commit adds a per-speaker cache for VI calibration state and R0
resistance values, logging each state once per speaker and arming the
cache when configuring the VI module.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index c7444f8598c86..a187e0b136330 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> +static int sp_vi_q24_to_int_frac(s32 val, int *frac)
> +{
> + *frac = (int)(((s64)(val & 0xffffff) * 1000) >> 24);
> +
> + return val >> 24;
> +}
[Severity: Low]
Does sp_vi_q24_to_int_frac() format negative Q24 values accurately?
For a negative value like -0.5 ohms (-0x00800000), val >> 24 floors to -1
while val & 0xffffff gives the positive remainder (500), so the %d.%03d
log in audioreach_vi_calibration_event() prints -1.500 ohms instead of
-0.500 ohms.
Values in (-1.0, 0.0) also have integer magnitude 0, so %d drops the minus
sign unless the sign is formatted separately from the unsigned magnitude.
This corrupts the logged resistance when the DSP reports a negative
out-of-range r0_cali_q24 value.
[ ... ]
> @@ -1516,6 +1640,8 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
> return -EINVAL;
> }
>
> + audioreach_arm_vi_calibration();
> +
> rc = audioreach_register_events(graph, module);
> if (rc)
> return rc;
[Severity: Medium]
Can this leave sp_vi_r0.armed set if VI configuration fails?
audioreach_arm_vi_calibration() sets sp_vi_r0.armed and clears
sp_vi_r0.seen_states before audioreach_register_events(),
audioreach_alloc_apm_cmd_pkt(), q6apm_send_cmd_sync(), and
audioreach_module_enable() in audioreach_set_media_format().
If audioreach_register_events() succeeds and one of those later steps
fails on a capture back-end stream (q6apm_lpass_dai_prepare() skips
q6apm_graph_close() for capture) or a front-end stream, the graph stays
open with the event registered and sp_vi_r0.armed set.
Any event arriving from that graph then clears the cached sp_vi_r0 result.
Disarming sp_vi_r0.armed on error, or arming only after configuration and
module enablement succeed, would avoid leaving the cache armed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=12
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events
2026-12-04 11:30 ` [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
@ 2026-12-04 13:32 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:32 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: qcom: audioreach: unrelated wsa884x.c edits mixed into
commit
- [Medium] ASoC: wsa884x: duplicate hwmon registration in
wsa884x_probe()
- [Medium] ASoC: wsa884x: removing hw_init check in wsa884x_get_temp()
breaks hwmon
--
commit 3c5748e4794ffffa00c6acd6959787f2703883c6
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events
This commit configures the AudioReach speaker protection and VI modules in
calibration mode for up to four speakers and registers for per-speaker VI
calibration events in q6apm.
> diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
> index e5813ed139b34..d0a00aced2208 100644
> --- a/sound/soc/codecs/wsa884x.c
> +++ b/sound/soc/codecs/wsa884x.c
[Severity: Medium]
Were the changes to sound/soc/codecs/wsa884x.c squashed into this commit
by mistake?
The commit message only describes AudioReach speaker protection and VI
calibration events, and these hunks silently undo parts of earlier commit
"ASoC: codecs: wsa884x: register the die temperature as a thermal zone".
> @@ -1933,10 +1933,6 @@ static int wsa884x_get_temp(struct wsa884x_priv *wsa884x, long *temp)
>
> guard(mutex)(&wsa884x->sp_lock);
>
> - /* OTP trims read back as zero until the codec is initialised. */
> - if (!wsa884x->hw_init)
> - return -EAGAIN;
> -
> if (wsa884x->pa_on) {
> /*
> * Reading temperature is possible only when Power Amplifier is
> @@ -2071,7 +2067,15 @@ static int wsa884x_tz_get_temp(struct thermal_zone_device *tz, int *temp_mdeg)
> long mdeg;
> int ret;
>
> - /* -EAGAIN means no reading yet; don't make the core poll the zone. */
> + /*
> + * OTP trims read back as zero until the codec is initialised. Report
> + * no reading rather than -EAGAIN, which makes the core poll the zone.
> + */
> + if (!wsa884x->hw_init) {
> + *temp_mdeg = THERMAL_TEMP_INVALID;
> + return 0;
> + }
> +
> ret = wsa884x_get_temp(wsa884x, &mdeg);
> if (ret == -EAGAIN) {
> *temp_mdeg = THERMAL_TEMP_INVALID;
[Severity: Medium]
Does removing the !wsa884x->hw_init check from wsa884x_get_temp() break
wsa884x_hwmon_read() while the codec is uninitialized or unattached?
wsa884x_hwmon_read() calls wsa884x_get_temp() directly, bypassing the
guard moved into wsa884x_tz_get_temp().
Reading hwmon temp1_input while unattached now calls
pm_runtime_resume_and_get(), which can clear regcache_cache_only() in
wsa884x_runtime_resume(), dirty WSA884X_PA_FSM_BYP0 and
WSA884X_TADC_VALUE_CTL, and return -EINVAL instead of -EAGAIN.
Checking !wsa884x->hw_init outside sp_lock in wsa884x_tz_get_temp() also
widens the race with wsa884x_update_status() clearing hw_init on
SDW_SLAVE_UNATTACHED.
> @@ -2084,10 +2088,6 @@ static int wsa884x_tz_get_temp(struct thermal_zone_device *tz, int *temp_mdeg)
> return 0;
> }
>
> -static const struct thermal_zone_params wsa884x_tzp = {
> - .no_hwmon = true,
> -};
> -
> static struct thermal_zone_device_ops wsa884x_tz_ops = {
> .get_temp = wsa884x_tz_get_temp,
> };
> @@ -2246,7 +2246,7 @@ static int wsa884x_probe(struct sdw_slave *pdev,
> tz = thermal_tripless_zone_device_register(tz_name,
> wsa884x,
> &wsa884x_tz_ops,
> - &wsa884x_tzp);
> + NULL);
[Severity: Medium]
Does passing NULL instead of &wsa884x_tzp register a duplicate hwmon
device for each codec?
wsa884x_probe() already registers a hwmon sensor via
devm_hwmon_device_register_with_info(). With tzp NULL,
thermal_zone_device_register_with_trips() calls thermal_add_hwmon_sysfs(),
exposing a second hwmon device and doubling polling wakeups and regmap I/O.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=10
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone
2026-12-04 11:30 ` [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
@ 2026-12-04 13:34 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:34 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ASoC: codecs: wsa884x: data race and TOCTOU on hw_init in
wsa884x_get_temp()
- [Medium] ASoC: wsa884x: enabling tripless thermal zone wakes idle
codecs on resume
- [Low] ASoC: codecs: wsa884x: unrelated wsa884x_vi_hw_params() change
in commit
- [Low] ASoC: codecs: wsa884x: 0 degC cache sentinel collision in
wsa884x_get_temp()
--
commit 513c87fe3e3a0f98ef09430a4d09e5f54d857839
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: codecs: wsa884x: register the die temperature as a thermal zone
This commit registers a tripless thermal zone for the WSA884x amplifier
die temperature so in-kernel speaker protection can look it up by name,
and updates wsa884x_get_temp() to return -EAGAIN before initialization or
when the PA is on without a cached reading.
> diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
> index abf9d88ec7a8a..e5813ed139b34 100644
> --- a/sound/soc/codecs/wsa884x.c
> +++ b/sound/soc/codecs/wsa884x.c
[ ... ]
> @@ -1779,21 +1780,19 @@ static int wsa884x_vi_hw_params(struct snd_pcm_substream *substream,
> struct snd_soc_dai *dai)
> {
> struct wsa884x_priv *wsa884x = dev_get_drvdata(dai->dev);
> - unsigned int num_ports = 0;
>
> + if (!wsa884x->port_enable[WSA884X_PORT_VISENSE])
> + return 0;
> +
> + wsa884x->vi_port_config = wsa884x_pconfig[WSA884X_PORT_VISENSE];
> wsa884x->vi_sconfig.frame_rate = params_rate(params);
> wsa884x->vi_sconfig.ch_count = 2;
> wsa884x->vi_sconfig.bps = 1;
> wsa884x->vi_sconfig.type = SDW_STREAM_PDM;
> wsa884x->vi_sconfig.direction = SDW_DATA_DIR_TX;
>
> - if (wsa884x->port_enable[WSA884X_PORT_VISENSE]) {
> - wsa884x->vi_port_config = wsa884x_pconfig[WSA884X_PORT_VISENSE];
> - num_ports = 1;
> - }
> -
> return sdw_stream_add_slave(wsa884x->slave, &wsa884x->vi_sconfig,
> - &wsa884x->vi_port_config, num_ports,
> + &wsa884x->vi_port_config, 1,
> wsa884x->vi_sruntime);
> }
[Severity: Low]
This change to wsa884x_vi_hw_params() is unrelated to thermal zone
registration and is not mentioned in the commit message. Should it be
folded into commit "ASoC: codecs: wsa884x: add VI sense capture DAI" or
split into its own patch?
[ ... ]
> @@ -1934,11 +1933,17 @@ static int wsa884x_get_temp(struct wsa884x_priv *wsa884x, long *temp)
>
> guard(mutex)(&wsa884x->sp_lock);
>
> + /* OTP trims read back as zero until the codec is initialised. */
> + if (!wsa884x->hw_init)
> + return -EAGAIN;
[Severity: Medium]
Can wsa884x->hw_init race with SoundWire status updates here?
wsa884x_get_temp() reads hw_init under wsa884x->sp_lock, while
wsa884x_init() sets it and wsa884x_update_status() clears it under
slave->sdw_dev_lock:
CPU0 (temp read) CPU1 (SoundWire status)
wsa884x_get_temp()
mutex_lock(&wsa884x->sp_lock)
if (!wsa884x->hw_init)
sdw_update_slave_status()
mutex_lock(&slave->sdw_dev_lock)
wsa884x_update_status(...)
wsa884x->hw_init = false
regcache_cache_only(..., true)
mutex_unlock(&slave->sdw_dev_lock)
pm_runtime_resume_and_get()
regcache_sync() <-- runs on unattached slave
regmap_read(WSA884X_OTP_REG_*) <-- d1 == d2 == 0, returns -EINVAL
Returning -EINVAL from a thermal zone read also feeds into
thermal_zone_recheck(), which polls the zone with backoff until disabling
it. On an attach transition, the plain read also lacks acquire/release
ordering against wsa884x_init(). Note that taking sp_lock inside
wsa884x_update_status() would risk an ABBA deadlock with
pm_runtime_resume_and_get() -> swrm_runtime_resume() ->
sdw_handle_slave_status() -> sdw_update_slave_status().
> if (wsa884x->pa_on) {
> /*
> * Reading temperature is possible only when Power Amplifier is
> - * off. Report last cached data.
> + * off. Report last cached data if we have one, -EAGAIN otherwise.
> */
> + if (!wsa884x->temperature)
> + return -EAGAIN;
> *temp = wsa884x->temperature * 1000;
> return 0;
> }
[Severity: Low]
Does using zero as the uncached sentinel reject a valid cached reading of
0 degC?
wsa884x_get_temp() caches values across WSA884X_LOW_TEMP_THRESHOLD (-10)
to WSA884X_HIGH_TEMP_THRESHOLD (150), so a cached 0 degC reading fails
with -EAGAIN in hwmon and -ENODATA via thermal_zone_get_temp() while pa_on
is true. Because wsa884x->temperature is an unsigned int, cached negative
temperatures in [-10, -1] also wrap when multiplied by 1000 before
widening to long on 64-bit hwmon reads. Making temperature a signed int
with a separate bool validity flag (or initializing it to an out-of-range
sentinel such as THERMAL_TEMP_INVALID) avoids both issues.
[ ... ]
> @@ -2196,6 +2233,35 @@ static int wsa884x_probe(struct sdw_slave *pdev,
> if (ret)
> return ret;
>
> + if (IS_REACHABLE(CONFIG_THERMAL)) {
> + char tz_name[THERMAL_NAME_LENGTH];
> + struct thermal_zone_device *tz;
> +
> + /*
> + * Register after runtime PM is enabled, as the zone is read
> + * right away. dev_name() is too long for a zone name.
> + */
> + scnprintf(tz_name, sizeof(tz_name), "wsa-%d-%u",
> + pdev->bus->id, pdev->id.unique_id);
> + tz = thermal_tripless_zone_device_register(tz_name,
> + wsa884x,
> + &wsa884x_tz_ops,
> + &wsa884x_tzp);
> + if (IS_ERR(tz)) {
> + dev_warn(dev,
> + "thermal zone '%s' registration failed (%ld); SP T0 kcontrol will read 0 for this codec\n",
> + tz_name, PTR_ERR(tz));
> + } else {
> + ret = devm_add_action_or_reset(dev,
> + wsa884x_tz_unregister,
> + tz);
> + if (ret)
> + return ret;
> +
> + thermal_zone_device_enable(tz);
[Severity: Medium]
Does calling thermal_zone_device_enable(tz) wake every idle WSA884x
amplifier and its parent Qualcomm SoundWire controller on every system
resume?
Because wsa884x and qcom_swrm only implement runtime PM, an idle amplifier
stays runtime-suspended across system suspend/resume with hw_init true and
pa_on false. On every system resume, dpm_complete() ->
thermal_pm_complete() -> thermal_zone_device_resume() ->
__thermal_zone_device_update() invokes wsa884x_tz_get_temp() whenever
tz->mode is THERMAL_DEVICE_ENABLED, calling pm_runtime_resume_and_get()
only to discard the reading for a tripless zone.
If that resume read returns any error other than -EAGAIN (such as -EINVAL
or a runtime resume failure), __thermal_zone_device_update() also calls
thermal_zone_recheck(), repeatedly waking and polling the codec with
exponential backoff up to 120 seconds before disabling the zone. Leaving
the zone in its default THERMAL_DEVICE_DISABLED state avoids resume
updates while keeping thermal_zone_get_zone_by_name(),
thermal_zone_get_temp(), and sysfs temp reads working.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=8
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs
2026-12-04 11:30 ` [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
@ 2026-12-04 13:35 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:35 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] ASoC: qcom: audioreach: fixed link_obj stride mismatches
variable prop_size
- [Medium] ASoC: qcom: audioreach: control link dedup in
audioreach_populate_graph() drops links
- [Medium] ASoC: qcom: audioreach: global control_links_idr drops shared
control links
- [Medium] ASoC: qcom: audioreach: OOB read and hang in
audioreach_parse_cl_tokens()
- [Medium] ASoC: qcom: audioreach: link->id overwrite corrupts
control_links_idr
- [Medium] ASoC: qcom: audioreach: ignored errors in
audioreach_parse_cl_tokens()
- [Medium] ASoC: qcom: audioreach: control link leak on widget load
failure
--
commit 47c372c9486ab9218c7d3bbd81b6ac2224d34f0e
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: audioreach: add control link support to graphs
This commit parses control link tokens from topology files into a
per-subgraph list and appends deduplicated control link objects to the
APM_CMD_GRAPH_OPEN packet sent to the DSP.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 5b5289bf6d139..f66d3ff68a441 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -426,6 +449,47 @@ static void audioreach_populate_graph(struct q6apm *apm,
>
> apm_populate_sub_graph_config(sg_cfg, sg);
>
> + list_for_each_entry(clink, &sg->control_link_list, node) {
> + bool dup = false;
> + int k;
> +
> + /* Both subgraphs usually declare the link, send it once */
> + for (k = 0; k < nlink; k++) {
> + struct apm_control_link_obj *o = &cl_data->link_obj[k];
> +
> + if ((o->peer1_mod_inst_id == clink->peer1_mod_inst_id &&
> + o->peer2_mod_inst_id == clink->peer2_mod_inst_id) ||
> + (o->peer1_mod_inst_id == clink->peer2_mod_inst_id &&
> + o->peer2_mod_inst_id == clink->peer1_mod_inst_id)) {
> + dup = true;
> + break;
> + }
> + }
> + if (dup)
> + continue;
[Severity: Medium]
Does this deduplication drop distinct control links between the same two
module instances on different control ports?
The comparison only checks peer1_mod_inst_id and peer2_mod_inst_id, ignoring
peer1_mod_port_id and peer2_mod_port_id. If two modules share more than one
control link on separate ports, subsequent links are silently omitted from
APM_CMD_GRAPH_OPEN. Comparing both module instance IDs and their matching
port IDs in both peer orders would avoid dropping them.
> + clink_obj = &cl_data->link_obj[nlink++];
> + clink_obj->peer1_mod_inst_id = clink->peer1_mod_inst_id;
> + clink_obj->peer1_mod_port_id = clink->peer1_mod_port_id;
> + clink_obj->peer2_mod_inst_id = clink->peer2_mod_inst_id;
> + clink_obj->peer2_mod_port_id = clink->peer2_mod_port_id;
> + clink_obj->intent_data.prop_id = APM_MODULE_PROP_ID_CTRL_LINK_INTENT_LIST;
> + clink_obj->num_props = 1;
> + clink_obj->num_intents = 0;
> +
> + /* Pack the intents that are set into a dense list */
> + for (j = 0; j < MAX_INTENTS; j++) {
> + if (clink->intent[j])
> + clink_obj->intent_id_list[clink_obj->num_intents++] =
> + clink->intent[j];
> + }
> +
> + /* The list length itself is part of the property payload */
> + clink_obj->intent_data.prop_size =
> + sizeof(clink_obj->num_intents) +
> + clink_obj->num_intents * sizeof(clink_obj->intent_id_list[0]);
> + }
[Severity: High]
Can the fixed 48-byte stride of cl_data->link_obj[] misalign the wire layout
when a control link has fewer than MAX_INTENTS intents?
struct apm_control_link_obj embeds a fixed u32 intent_id_list[MAX_INTENTS],
so link_obj[nlink++] always advances by 48 bytes, while intent_data.prop_size
only accounts for num_intents entries. When a graph has two or more unique
control links and an earlier link has fewer than four intents, the DSP
advances past intent_data by prop_size and reads the trailing zero slots as
the next link's peer IDs, corrupting subsequent links or failing
APM_CMD_GRAPH_OPEN.
Using a flexible intent_id_list[] array and advancing a byte pointer per link
(as struct apm_mod_list_obj does in this file) would match the variable
prop_size.
[ ... ]
> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index aa2ab2b058d0f..5dd7f2c51d5cf 100644
> --- a/sound/soc/qcom/qdsp6/topology.c
> +++ b/sound/soc/qcom/qdsp6/topology.c
[ ... ]
> @@ -113,6 +114,51 @@ static struct audioreach_sub_graph *audioreach_tplg_alloc_sub_graph(struct q6apm
> return sg;
> }
>
> +static struct audioreach_control_link *audioreach_tplg_alloc_control_link(struct q6apm *apm,
> + struct audioreach_sub_graph *sg,
> + uint32_t control_link_id,
> + bool *found)
> +{
> + struct audioreach_control_link *link;
> + int ret;
> +
> + if (!control_link_id)
> + return ERR_PTR(-EINVAL);
> +
> + mutex_lock(&apm->lock);
> + link = idr_find(&apm->control_links_idr, control_link_id);
> + mutex_unlock(&apm->lock);
> +
> + if (link) {
> + *found = true;
> + return link;
> + }
[Severity: Medium]
Will the card-global apm->control_links_idr omit control links when two
subgraphs use the same AR_TKN_U32_CONTROL_LINK_IID?
When idr_find() matches an entry registered under a different subgraph, this
returns *found = true without adding the link to sg->control_link_list. Any
graph containing only that second subgraph then sends APM_CMD_GRAPH_OPEN
without the control link.
Since AR_TKN_U32_CONTROL_LINK_IID is never sent to the DSP and
apm->control_links_idr is unused elsewhere, searching sg->control_link_list
directly would scope deduplication per subgraph and avoid the global IDR.
[ ... ]
> @@ -348,6 +394,85 @@ audioreach_get_module_priv_data(const struct snd_soc_tplg_private *private)
> return NULL;
> }
>
> +static void audioreach_parse_control_link_tokens(struct q6apm *apm,
> + struct audioreach_control_link *link,
> + const struct snd_soc_tplg_vendor_array *cl_array)
> +{
> + const struct snd_soc_tplg_vendor_value_elem *cl_elem = cl_array->value;
> + int tkn_count = 0;
> +
> + while (tkn_count <= (le32_to_cpu(cl_array->num_elems) - 1)) {
> + switch (le32_to_cpu(cl_elem->token)) {
> + case AR_TKN_U32_CONTROL_LINK_IID:
> + link->id = le32_to_cpu(cl_elem->value);
> + break;
[Severity: Medium]
Can overwriting link->id here corrupt apm->control_links_idr?
audioreach_tplg_alloc_control_link() has already inserted link into
apm->control_links_idr under the original control_link_id. If a vendor array
contains a second AR_TKN_U32_CONTROL_LINK_IID token with a different value
(audioreach_parse_cl_tokens() also keeps looping after the first match),
link->id is overwritten, so audioreach_widget_unload() removes the wrong IDR
key and frees link, leaving a dangling pointer in apm->control_links_idr and
causing a use-after-free on later topology reloads.
[ ... ]
> +static void audioreach_parse_cl_tokens(struct q6apm *apm, struct audioreach_sub_graph *sg,
> + const struct snd_soc_tplg_private *private)
> +{
> + const struct snd_soc_tplg_vendor_value_elem *cl_elem;
> + const struct snd_soc_tplg_vendor_array *cl_array;
> + struct audioreach_control_link *link;
> + int link_id, tkn_count, sz;
> + bool found = false;
> +
> + for (sz = 0; sz < le32_to_cpu(private->size);) {
> + cl_array = (struct snd_soc_tplg_vendor_array *)((u8 *)private->array + sz);
> + cl_elem = cl_array->value;
> + sz = sz + le32_to_cpu(cl_array->size);
> + tkn_count = 0;
> +
> + /* Module config blobs are not token tuples, stop here */
> + if (le32_to_cpu(cl_array->type) == SND_SOC_AR_TPLG_MODULE_CFG_TYPE)
> + break;
> +
> + while (tkn_count <= (le32_to_cpu(cl_array->num_elems) - 1)) {
[Severity: Medium]
Can a malformed topology vendor array hang or read out of bounds in
audioreach_parse_cl_tokens() and audioreach_parse_control_link_tokens()?
soc_tplg_dapm_widget_elems_load() only checks widget->priv.size against
tplg->fw->size. A vendor array with cl_array->size == 0 loops forever here
(unlike audioreach_get_module_priv_data() above it), and num_elems == 0
underflows le32_to_cpu(cl_array->num_elems) - 1 to U32_MAX in both functions,
driving out-of-bounds reads past the firmware buffer.
The walk also does not check that cl_array->size and num_elems fit within the
remaining private->size, uses signed int sz which can overflow on a large
cl_array->size, and never verifies that cl_array->type is a value-tuple type
before indexing cl_array->value.
> + if (le32_to_cpu(cl_elem->token) == AR_TKN_U32_CONTROL_LINK_IID) {
> + link_id = le32_to_cpu(cl_elem->value);
> + link = audioreach_tplg_alloc_control_link(apm, sg, link_id, &found);
> + /* Skip on error or already parsed control link data */
> + if (!IS_ERR(link) && !found)
> + audioreach_parse_control_link_tokens(apm, link, cl_array);
> + }
[Severity: Medium]
Should audioreach_parse_cl_tokens() propagate errors from
audioreach_tplg_alloc_control_link() instead of returning void?
Ignoring ERR_PTR returns such as -ENOMEM or -EINVAL (for link_id == 0) lets
widget and topology loading succeed with missing control links, unlike
audioreach_parse_sg_tokens() and audioreach_parse_cont_tokens().
[ ... ]
> @@ -617,6 +742,8 @@ static int audioreach_widget_load_module_common(struct snd_soc_component *compon
> if (IS_ERR(sg))
> return PTR_ERR(sg);
>
> + audioreach_parse_cl_tokens(apm, sg, &tplg_w->priv);
> +
> cont = audioreach_parse_cont_tokens(apm, sg, &tplg_w->priv);
> if (IS_ERR(cont))
> return PTR_ERR(cont);
[Severity: Medium]
Does an error after audioreach_parse_cl_tokens() leak the newly allocated
control links and their apm->control_links_idr entries?
If audioreach_parse_cont_tokens(), audioreach_parse_common_tokens(), or
audioreach_get_module_priv_data() fails, this function returns before setting
dobj->private = mod. When topology loading unwinds, audioreach_widget_unload()
exits immediately on if (!mod) return 0 and never runs the
sg->control_link_list cleanup, leaking both the control link memory and the
IDR entries on the persistent q6apm instance across retries or reloads.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=9
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
2026-12-04 11:30 ` [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
@ 2026-12-04 13:43 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:43 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 13 potential
issues to consider:
- [High] ASoC: audioreach: call to deleted audioreach_sp_disarm_vi()
breaks build
- [High] ASoC: audioreach: argument mismatch calling
audioreach_speaker_protection_vi()
- [High] ASoC: qcom: audioreach: UAF on unload after removing
audioreach_sp_shutdown()
- [Medium] ASoC: audioreach: race in audioreach_sp_finish_calibration()
watchdog cancel
- [Medium] ASoC: audioreach: watchdog timeout leaves sp_vi_r0.armed set
- [Medium] ASoC: qcom: audioreach: VI speaker-count checked after
partial DSP config
- [Medium] ASoC: qcom: audioreach: TOCTOU race on sp_operation_mode
during VI setup
- [Medium] ASoC: qcom: audioreach: watchdog race in
audioreach_sp_finish_calibration()
- [Medium] ASoC: qcom: audioreach: watchdog timeout leaves
sp_vi_r0.armed set
- [Medium] ASoC: qcom: audioreach: calibration state not unwound on VI
config error
- [Medium] ASoC: qcom: missing num_ch check in
audioreach_vi_calibration_event()
- [Low] ASoC: qcom: audioreach: broken fixed-point R0/T0 diagnostic log
formatting
- [Low] ASoC: qcom: audioreach: zero-channel event wipes cached R0/T0
calibration
--
commit 0bca08e0faa877f7524d142ce001fdb361728129
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
This commit caches calibrated speaker R0/T0 values and sends them to the
VI module via PARAM_ID_SP_TH_VI_R0T0_CFG in normal mode. It also
removes audioreach_sp_disarm_vi() and audioreach_sp_shutdown(), changes
watchdog cancellation in audioreach_sp_finish_calibration(), and adjusts
the signature of audioreach_speaker_protection_vi().
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index be37681f467fb..3555c97c2000d 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1475,37 +1493,20 @@ u32 audioreach_get_sp_operation_mode(void)
> static void audioreach_sp_cal_watchdog_fn(struct work_struct *work);
> static DECLARE_DELAYED_WORK(sp_cal_watchdog, audioreach_sp_cal_watchdog_fn);
>
> -static void audioreach_sp_disarm_vi(void)
> -{
> - guard(mutex)(&sp_vi_r0_lock);
> - sp_vi_r0.armed = false;
> -}
> -
> static void audioreach_sp_cal_watchdog_fn(struct work_struct *work)
> {
> if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_CALIBRATION,
> - PARAM_ID_SP_VI_OP_MODE_NORMAL) !=
> + PARAM_ID_SP_VI_OP_MODE_NORMAL) ==
> PARAM_ID_SP_VI_OP_MODE_CALIBRATION)
> - return;
> -
> - audioreach_sp_disarm_vi();
> - pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
> + pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
> }
[Severity: Medium]
Does removing audioreach_sp_disarm_vi() from audioreach_sp_cal_watchdog_fn()
leave sp_vi_r0.armed set to true when the 60-second watchdog expires?
If a timed-out VI graph remains open and emits a late
EVENT_ID_VI_PER_SPKR_CALIBRATION event, audioreach_vi_calibration_event()
passes its sp_vi_r0.armed check, overwrites sp_vi_r0 and sp_vi_r0t0_cfg,
and calls audioreach_sp_finish_calibration(), aborting any newly triggered
calibration run.
>
> -/* Finish before writing the mode so a trigger racing in cannot be clobbered */
> static void audioreach_sp_finish_calibration(void)
> {
> - cancel_delayed_work_sync(&sp_cal_watchdog);
> WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
> + cancel_delayed_work(&sp_cal_watchdog);
> }
[Severity: Medium]
Can writing PARAM_ID_SP_VI_OP_MODE_NORMAL before calling
cancel_delayed_work() cancel a newly triggered calibration's watchdog?
CPU0 CPU1
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
..._NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(NORMAL -> CALIBRATION)
schedule_delayed_work(...)
cancel_delayed_work(&sp_cal_watchdog)
<-- cancels CPU1's watchdog
Without its watchdog, sp_operation_mode can remain stuck in calibration
mode indefinitely if no calibration playback completes, rejecting later
triggers with -EBUSY. If cancel_delayed_work_sync() is restored together
with disarming sp_vi_r0 under sp_vi_r0_lock in the watchdog, callers such
as audioreach_vi_calibration_event() must drop sp_vi_r0_lock before
calling audioreach_sp_finish_calibration() to avoid an ABBA deadlock.
[Severity: Medium]
Can switching from cancel_delayed_work_sync() to asynchronous
cancel_delayed_work() allow an already-running watchdog to abort a newly
triggered calibration run?
CPU0 kworker
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
..._NORMAL)
cancel_delayed_work(&sp_cal_watchdog)
(does not wait for running worker)
audioreach_sp_cal_watchdog_fn()
audioreach_trigger_sp_calibration()
cmpxchg(NORMAL -> CALIBRATION)
cmpxchg(CALIBRATION -> NORMAL)
<-- aborts new run
Cancelling synchronously before publishing Normal mode prevents the stale
worker from observing the new calibration state.
[ ... ]
> @@ -1559,6 +1560,86 @@ static int sp_vi_q24_to_int_frac(s32 val, int *frac)
> return val >> 24;
> }
[ ... ]
> + for (i = 0; i < num_ch; i++) {
> + long r0 = vals[2 * i];
> + long t0 = vals[2 * i + 1];
> + int r0_int, r0_frac;
> +
> + if (r0 < SP_VI_R0_MIN_Q24 || r0 > SP_VI_R0_MAX_Q24) {
> + r0_int = sp_vi_q24_to_int_frac(r0, &r0_frac);
> + dev_err(dev, "Channel %u R0 %d.%03d ohms (Q24 %ld) out of range\n",
> + i, r0_int, r0_frac, r0);
> + return -ERANGE;
> + }
> +
> + if (t0 < SP_VI_T0_MIN_Q6 || t0 > SP_VI_T0_MAX_Q6) {
> + dev_err(dev, "Channel %u T0 %ld.%03ld degC (Q6 %ld) out of range\n",
> + i, t0 / 64, abs((t0 % 64) * 1000 / 64), t0);
> + return -ERANGE;
> + }
> +
> + new.r0_cali_q24[i] = r0;
> + new.t0_cali_q6[i] = t0;
> + }
[Severity: Low]
Will these logs misformat negative fractional T0 values and out-of-range
R0 values?
For valid negative temperatures between -1 and 0 degC (t0 in [-63, -1]),
t0 / 64 is 0, so %d.%03d drops the minus sign (for example, -32 logs as
0.500 degC here and in audioreach_speaker_protection_vi()). When r0 is
out of range, passing a 64-bit long to sp_vi_q24_to_int_frac(s32, ...)
truncates values outside s32 range, and negative Q24 values are printed
with the wrong magnitude (for example, -(1 << 23) logs as -1.500 ohms).
[ ... ]
> @@ -1623,6 +1704,14 @@ void audioreach_vi_calibration_event(struct device *dev,
> i, r0_int, r0_frac, sp_vi_r0.r0_cali_q24[i]);
> }
>
> + /* Only a run where every speaker succeeded gives a usable R0/T0 set */
> + if (success) {
> + guard(mutex)(&sp_vi_r0t0_cfg_lock);
> + sp_vi_r0t0_cfg.num_ch = num_ch;
> + for (i = 0; i < num_ch; i++)
> + sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
> + }
> +
> dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed");
[Severity: Medium]
Can a zero-channel calibration event wipe a previously stored R0/T0 set
here?
q6apm_vi_calibration_event() forwards num_ch = 0 when cali->num_ch is 0
or the payload contains no cali_param entries. Without an early return
for !num_ch in audioreach_vi_calibration_event(), decisive and success
both stay true, so this block overwrites sp_vi_r0t0_cfg.num_ch with 0 and
ends the calibration run.
[ ... ]
> @@ -1675,9 +1764,9 @@ static void audioreach_arm_vi_calibration(void)
>
> static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
> const struct audioreach_module *module,
> - const struct audioreach_module_config *mcfg,
> - u32 mode)
> + const struct audioreach_module_config *mcfg)
> {
> + u32 mode = READ_ONCE(sp_operation_mode);
> u32 num_channels = mcfg->num_channels;
[Severity: Medium]
Is there a TOCTOU race between reading sp_operation_mode here and the
watchdog or SP module configuration?
CPU0 kworker
audioreach_speaker_protection_vi()
mode = READ_ONCE(sp_operation_mode)
(sees CALIBRATION)
audioreach_sp_cal_watchdog_fn()
cmpxchg(CALIBRATION -> NORMAL)
audioreach_arm_vi_calibration()
audioreach_register_events(...)
q6apm_send_cmd_sync(...)
<-- DSP runs in calibration mode
while mode is Normal
A subsequent audioreach_trigger_sp_calibration() can then start while
events from CPU0's run are arriving and prematurely finish the new run.
Separately, audioreach_speaker_protection() and
audioreach_speaker_protection_vi() each read sp_operation_mode
independently across blocking DSP IPCs, so the SP and VI modules in one
graph can be configured in mismatched modes.
[ ... ]
> @@ -1705,8 +1794,11 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
> audioreach_arm_vi_calibration();
>
> rc = audioreach_register_events(graph, module);
> - if (rc)
> + if (rc) {
> + audioreach_sp_finish_calibration();
> + audioreach_sp_disarm_vi();
> return rc;
> + }
> }
[Severity: High]
Does calling audioreach_sp_disarm_vi() here break the build now that this
commit deleted its only definition?
Commit "ASoC: qcom: audioreach: add live speaker temperature (T0)
readback" later removes this error path, so intermediate patches fail to
compile and break git bisect.
[Severity: Medium]
Even once audioreach_sp_disarm_vi() is restored, can calling
audioreach_sp_finish_calibration() before audioreach_sp_disarm_vi()
disarm a concurrently triggered calibration run?
Publishing Normal mode first lets another caller trigger and arm a new
calibration before this error path clears sp_vi_r0.armed; disarming first
avoids that race. Separately, audioreach_sp_cal_watchdog_fn() also needs
to clear sp_vi_r0.armed on timeout so late DSP events cannot pass the
armed check.
[ ... ]
> @@ -1767,6 +1859,73 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
>
> kfree(pkt);
>
> + if (rc)
> + return rc;
[Severity: Medium]
If audioreach_alloc_apm_cmd_pkt() or q6apm_send_cmd_sync() fails in
calibration mode, does returning here leave sp_operation_mode in
calibration mode and sp_vi_r0.armed set?
Calibration retries then fail with -EBUSY for up to 60 seconds and normal
playbacks run without R0/T0 protection, while capture callers that keep
the graph open on prepare failure leave sp_vi_r0.armed set.
> +
> + if (mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
> + struct apm_module_sp_th_vi_r0t0_cfg *r0t0_cfg;
> + struct sp_vi_r0t0_cfg snap;
> + int r0t0_sz;
> +
> + /* Snapshot the cache so q6apm_send_cmd_sync runs with no locks held */
> + scoped_guard(mutex, &sp_vi_r0t0_cfg_lock)
> + snap = sp_vi_r0t0_cfg;
> +
> + if (!snap.num_ch)
> + return 0;
[Severity: Low]
Because this treats snap.num_ch == 0 as unconfigured, won't a zero-channel
calibration event that overwrites sp_vi_r0t0_cfg.num_ch with 0 cause
Normal-mode playback to silently skip sending PARAM_ID_SP_TH_VI_R0T0_CFG?
Rejecting num_ch == 0 in audioreach_vi_calibration_event() prevents a
truncated or empty DSP event from disabling thermal protection.
> +
> + if (snap.num_ch != num_speakers) {
> + dev_err(graph->dev,
> + "SP R0T0 is for %u speakers, graph has %u\n",
> + snap.num_ch, num_speakers);
> + return -EINVAL;
> + }
[Severity: Medium]
Doesn't this speaker-count check run after the first q6apm_send_cmd_sync()
has already configured OP_MODE, CHANNEL_MAP, and EX_MODE on the DSP?
That contradicts the commit message's claim that a mismatched graph is
refused instead of being partly configured, and capture callers such as
q6apm_lpass_dai_prepare() leave the open graph intact on error.
Snapshotting and validating sp_vi_r0t0_cfg before sending the first
APM_CMD_SET_CFG avoids partial DSP configuration and allows bundling
PARAM_ID_SP_TH_VI_R0T0_CFG instead of taking a second synchronous IPC
round-trip under apm->lock.
[ ... ]
> @@ -1822,14 +1981,14 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
> rc = audioreach_gapless_set_media_format(graph, module, cfg);
> break;
> case MODULE_ID_SPEAKER_PROTECTION:
> - rc = audioreach_speaker_protection(graph, module,
> - READ_ONCE(sp_operation_mode));
> + rc = audioreach_speaker_protection(graph, module);
> if (!rc)
> rc = audioreach_module_enable(graph, module, true);
>
> break;
> case MODULE_ID_SPEAKER_PROTECTION_VI:
> - rc = audioreach_speaker_protection_vi(graph, module, cfg);
> + rc = audioreach_speaker_protection_vi(graph, module, cfg,
> + READ_ONCE(sp_operation_mode));
> if (!rc)
> rc = audioreach_module_enable(graph, module, true);
[Severity: High]
Does passing 4 arguments to audioreach_speaker_protection_vi() break the
build now that its definition above takes only 3 parameters?
Commit "ASoC: qcom: audioreach: add live speaker temperature (T0)
readback" later reverts this call site to 3 arguments, leaving the
intermediate commits unbuildable and breaking git bisect.
> diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
> index 6494eb80f0897..c410e2f6e6a3f 100644
> --- a/sound/soc/qcom/qdsp6/q6apm.c
> +++ b/sound/soc/qcom/qdsp6/q6apm.c
> @@ -950,8 +950,6 @@ static int apm_probe(gpr_device_t *gdev)
>
> static void apm_remove(gpr_device_t *gdev)
> {
> - /* Release the SP calibration watchdog before the module goes away */
> - audioreach_sp_shutdown();
> g_apm = NULL;
> of_platform_depopulate(&gdev->dev);
> snd_soc_unregister_component(&gdev->dev);
[Severity: High]
Can removing audioreach_sp_shutdown() cause a use-after-free when
snd-q6apm is unloaded while the 60-second sp_cal_watchdog is pending?
CPU0 kworker / timer
audioreach_trigger_sp_calibration()
schedule_delayed_work(&sp_cal_watchdog, ...)
apm_remove()
(sp_cal_watchdog not cancelled)
<module snd-q6apm unloaded>
audioreach_sp_cal_watchdog_fn()
<-- executes freed module text
CONFIG_SND_SOC_QDSP6_APM is tristate, so unloading the module within 60
seconds of triggering calibration crashes when the timer fires; deleting
the definition also leaves an orphaned audioreach_sp_shutdown() prototype
in audioreach.h. Restoring audioreach_sp_shutdown() after
of_platform_depopulate() and snd_soc_unregister_component() prevents
userspace controls from re-arming the watchdog after cancellation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=14
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules
2026-12-04 11:30 ` [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
@ 2026-12-04 13:50 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:50 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] ASoC: qcom: audioreach: sp_cal_watchdog never canceled on
module unload
- [Medium] ASoC: qcom: audioreach: OOB read in
audioreach_speaker_protection_send_chunk()
- [Medium] ASoC: qcom: audioreach: audioreach_sp_cfg_walk() rejects last
sub-word param
- [Medium] ASoC: qcom: audioreach: race in
audioreach_sp_finish_calibration()
- [Medium] ASoC: qcom: audioreach: audioreach_set_media_format() leaks
VI cal state
- [Low] ASoC: qcom: audioreach: raw cast drops __le32 in static cfg blob
parser
--
commit 8b5c2a066041593c52f189b47c51b9e22ea4e028
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules
This commit parses and sends topology static configuration blobs to the
speaker protection and VI sense modules in chunked APM_CMD_SET_CFG commands
padded to 8-byte boundaries, falling back to sending non-record blobs whole.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 3555c97c2000d..fd803d6ceccd0 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> +static int audioreach_sp_cfg_walk(const u32 *word, u32 num_words, u32 iid,
> + u32 first, u32 *next, u8 *dst, u32 max_bytes)
> +{
> + u32 pos = first, bytes = 0;
> +
> + while (pos < num_words) {
> + u32 param_size, payload_words, avail, rec_bytes;
> +
> + if (word[pos] != iid || num_words - pos < 4)
> + return -EINVAL;
> +
> + param_size = word[pos + 2];
> + avail = (num_words - pos - 4) * sizeof(u32);
> + if (param_size < sizeof(u32) && avail && word[pos + 4] == iid) {
> + payload_words = 0;
> + } else {
> + if (param_size > avail)
> + return -EINVAL;
> + payload_words = DIV_ROUND_UP(param_size, sizeof(u32));
> + }
[Severity: Medium]
Can a valid blob end with a sub-word parameter that omits its payload word?
When such a record is last in the blob (num_words - pos == 4), avail is 0,
so the if condition evaluates to false and the else branch returns -EINVAL
instead of setting payload_words to 0. Checking (!avail || word[pos + 4] ==
iid) handles the final record while still guarding word[pos + 4].
[ ... ]
> +static int audioreach_speaker_protection_send_static_cfg(struct q6apm_graph *graph,
> + const struct audioreach_module *module,
> + const char *tag)
> +{
> + u32 size, num_words, pos = 0;
> + const u32 *word;
> + int total, rc = 0, chunk = 0;
> +
> + if (!module->data || !module->data->size)
> + return 0;
> +
> + size = le32_to_cpu(module->data->size);
> + word = (const u32 *)module->data->data;
> + num_words = size / sizeof(u32);
[Severity: Low]
Does this cast drop the __le32 annotation on module->data->data?
struct audioreach_module_priv_data declares data[] as __le32, so casting it
to const u32 * triggers sparse warnings and reads header words (word[0],
word[pos], word[pos + 2], and word[pos + 4]) in host byte order without
le32_to_cpu(). On big-endian builds, valid parameter-record blobs either
fall back to unchunked sends or fail with -EINVAL. Keeping word as
const __le32 * and using le32_to_cpu() when inspecting header fields avoids
both.
> + /* Not laid out as parameter records, so send it as the topology built it */
> + if (size % sizeof(u32) || !num_words || word[0] != module->instance_id)
> + return audioreach_speaker_protection_send_chunk(graph, tag, word, size, 0);
[Severity: Medium]
Can this read past the end of module->data when size is not a multiple of 4?
audioreach_get_module_priv_data() truncates array_size down to whole __le32
words when allocating and copying pdata->data[], while leaving the unrounded
byte count in pdata->size:
sound/soc/qcom/qdsp6/topology.c:audioreach_get_module_priv_data() {
...
nwords = array_size / sizeof(__le32);
...
pdata = kzalloc_flex(*pdata, data, nwords);
if (!pdata)
return ERR_PTR(-ENOMEM);
memcpy(pdata, ((u8 *)private->data + sz),
struct_size(pdata, data, nwords));
...
}
Passing the unrounded size to audioreach_speaker_protection_send_chunk()
causes memcpy() to read 1 to 3 bytes past the end of the slab object,
triggering a KASAN slab-out-of-bounds report and sending adjacent heap bytes
to the DSP.
[ ... ]
> @@ -1989,6 +2126,8 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
> case MODULE_ID_SPEAKER_PROTECTION_VI:
> rc = audioreach_speaker_protection_vi(graph, module, cfg,
> READ_ONCE(sp_operation_mode));
> + if (!rc)
> + rc = audioreach_speaker_protection_vi_static_cfg(graph, module);
> if (!rc)
> rc = audioreach_module_enable(graph, module, true);
[Severity: Medium]
If audioreach_speaker_protection_vi_static_cfg() fails during calibration
mode, does this leak the armed calibration state?
audioreach_speaker_protection_vi() has already called
audioreach_arm_vi_calibration() and registered DSP events before returning 0.
Returning on a static cfg error leaves sp_operation_mode stuck in
PARAM_ID_SP_VI_OP_MODE_CALIBRATION for up to 60 seconds (causing calibration
retries to fail with -EBUSY and configuring subsequent normal streams into
calibration mode) and leaves sp_vi_r0.armed set.
Even with the later graph-close abort path in the series,
audioreach_vi_calibration_abort() returns early when sp_vi_r0.seen_states is
all zeros, which is always true when prepare fails before the module is
enabled. Unwinding calibration state on failure here (or sending the static
cfg blob before arming calibration) would avoid the leak.
As a minor side effect in normal mode, audioreach_speaker_protection_vi()
also logs "SP active in Normal mode" before the static cfg blob is validated
or the module is enabled.
[Severity: High]
In the surrounding speaker protection calibration state from commit "ASoC:
qcom: audioreach: send cached R0/T0 to the VI module in normal mode", is
sp_cal_watchdog ever canceled on module unload?
audioreach_trigger_sp_calibration() schedules the 60-second delayed work
sp_cal_watchdog without pinning snd-q6apm, while audioreach_sp_shutdown()
and its call from apm_remove() were dropped (leaving only the declaration in
audioreach.h). Unloading snd-q6apm while the watchdog is pending or running
causes a use-after-free when the timer fires into freed module text and
data. Restoring cancel_delayed_work_sync(&sp_cal_watchdog) on removal after
unregistering controls prevents this.
[Severity: Medium]
Also in commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module
in normal mode", can audioreach_sp_finish_calibration() race with a new
calibration trigger or an in-flight watchdog callback?
audioreach_sp_finish_calibration() clears sp_operation_mode before calling
non-synchronous cancel_delayed_work(&sp_cal_watchdog):
CPU0 CPU1
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(..., NORMAL, CALIBRATION)
schedule_delayed_work(...)
cancel_delayed_work(...) <-- cancels CPU1's watchdog
This leaves the new run stuck in PARAM_ID_SP_VI_OP_MODE_CALIBRATION
indefinitely if no playback completes. Because cancel_delayed_work() does
not wait for an executing callback, a stale audioreach_sp_cal_watchdog_fn()
can also run its cmpxchg after a new calibration starts and abort it back to
Normal mode. Canceling the work synchronously before clearing
sp_operation_mode closes both races, provided sp_vi_r0_lock is not held
across cancel_delayed_work_sync() if the callback ever acquires it.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=15
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format
2026-12-04 11:30 ` [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
@ 2026-12-04 13:56 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:56 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: qcom: TOCTOU race on sp_operation_mode across SP and VI
modules
- [Medium] ASoC: qcom: heap OOB read in
audioreach_speaker_protection_send_static_cfg()
- [Low] ASoC: qcom: dead sp_vi_cfg overrides in
audioreach_set_media_format()
--
commit 2e9d1aaa9d032e965bfa3fbbc815b46ec62787a1
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format
This commit overrides the sample rate and bit width to 8 kHz and 32 bits in
audioreach_set_media_format() for MODULE_ID_SPEAKER_PROTECTION_VI and for
any MODULE_ID_CODEC_DMA_SOURCE in a subgraph containing it.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index fd803d6ceccd0..d1f6cd2b66354 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
> @@ -2064,12 +2064,41 @@ static int audioreach_speaker_protection_vi_static_cfg(struct q6apm_graph *graph
> return audioreach_speaker_protection_send_static_cfg(graph, module, "VI");
> }
[Severity: Medium]
Can audioreach_speaker_protection_send_static_cfg() read past the end of
module->data when size is not a multiple of 4?
audioreach_get_module_priv_data() truncates the allocation to whole __le32
words while keeping the unrounded byte count in pdata->size:
sound/soc/qcom/qdsp6/topology.c:audioreach_get_module_priv_data() {
...
nwords = array_size / sizeof(__le32);
...
pdata = kzalloc_flex(*pdata, data, nwords);
...
}
When a speaker protection topology blob has a non-4-byte-aligned size,
audioreach_speaker_protection_send_static_cfg() hits its size % sizeof(u32)
fallback and passes the unrounded size to
audioreach_speaker_protection_send_chunk(), where memcpy() reads 1 to 3
bytes past the allocated slab object and sends them to the DSP.
[ ... ]
> int audioreach_set_media_format(struct q6apm_graph *graph,
> const struct audioreach_module *module,
> const struct audioreach_module_config *cfg)
> {
> + struct audioreach_module_config sp_vi_cfg;
> int rc;
>
> + /* The VI module and its codec DMA source always run at 8 kHz, S32_LE */
> + if (module->module_id == MODULE_ID_SPEAKER_PROTECTION_VI ||
> + (module->module_id == MODULE_ID_CODEC_DMA_SOURCE &&
> + audioreach_sg_contains_sp_vi(module->container ?
> + module->container->sub_graph : NULL))) {
> + sp_vi_cfg = *cfg;
> + sp_vi_cfg.sample_rate = 8000;
> + sp_vi_cfg.bit_width = 32;
> + sp_vi_cfg.bits_per_sample = 32;
> + cfg = &sp_vi_cfg;
> + }
[Severity: Low]
Are the MODULE_ID_SPEAKER_PROTECTION_VI check and the bits_per_sample
assignment needed here?
audioreach_speaker_protection_vi() only reads num_channels and
channel_map[] from cfg, ignoring sample_rate, bit_width, and
bits_per_sample, so copying *cfg for the VI module has no effect.
audioreach_codec_dma_set_media_format() also never reads bits_per_sample
(nothing in sound/soc/qcom/qdsp6/ does).
>
> switch (module->module_id) {
[Severity: Medium]
Can the speaker protection and VI modules in the same graph be programmed
with mismatched sp_operation_mode values?
q6apm_graph_media_format_pcm() calls audioreach_set_media_format() for each
module in sequence without snapshotting sp_operation_mode, and the SP and
VI handlers each perform an independent READ_ONCE() across sleeping DSP IPC
calls:
CPU0 CPU1
q6apm_graph_media_format_pcm()
audioreach_set_media_format(SP)
audioreach_speaker_protection()
READ_ONCE(sp_operation_mode)
/* sees Normal, sends IPC */
audioreach_trigger_sp_calibration()
/* switches to Calibration */
audioreach_set_media_format(VI)
audioreach_speaker_protection_vi()
READ_ONCE(sp_operation_mode) <-- sees Calibration
If calibration is triggered (or the calibration watchdog fires) during this
window, the coupled SP and VI modules end up in opposite modes, breaking
speaker protection or calibration. Snapshotting sp_operation_mode once per
graph prepare pass would keep both modules consistent.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=17
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control
2026-12-04 11:30 ` [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
@ 2026-12-04 13:59 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 13:59 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 15 potential
issues to consider:
- [High] ASoC: qcom: audioreach_speaker_protection() signature mismatch
breaks build
- [High] ASoC: qcom: audioreach: unreadable T0 silently cached as 0 degC
- [High] ASoC: qcom: audioreach: AB-BA deadlock on sp_vi_r0t0_cfg_lock
and mode TOCTOU
- [High] ASoC: qcom: audioreach: thermal_zone_get_temp()
deadlocks/stalls qcom_apr_rx
- [Medium] ASoC: qcom: audioreach: audioreach_vi_calibration_abort()
clobbers mode
- [Medium] ASoC: qcom: audioreach: calibration finish and watchdog races
- [Medium] ASoC: qcom: audioreach: unsynchronized sp_operation_mode
reads across sleep
- [Medium] ASoC: qcom: audioreach: uncancelled sp_cal_watchdog UAF on
module unload
- [Medium] ASoC: qcom: audioreach: watchdog cancel race and stale armed
flag on timeout
- [Medium] ASoC: qcom: audioreach: stale calibration state and private
enum UAPI
- [Medium] ASoC: qcom: audioreach: ALSA control naming, bounds, and
metadata bugs
- [Medium] ASoC: qcom: audioreach: commit message omits major diff
changes
- [Medium] ASoC: qcom: wrong finish ordering in
audioreach_vi_calibration_abort()
- [Low] ASoC: qcom: audioreach: zero-channel calibration event wipes
cached R0/T0
- [Low] ASoC: qcom: audioreach: stale last_state persists after patch 21
revert
--
commit 19afa322a5aa9b79ab842d41723d8a15d853a182
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ASoC: qcom: audioreach: add speaker protection calibration state control
>
> Add a read-only "Speaker Protection Calibration State" control with
> each speaker's last calibration state, so userspace can follow a run.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
[Severity: Medium]
Should this commit be split or its commit message updated to match the diff?
The title and description only mention adding the read-only "Speaker
Protection Calibration State" control, while the patch also adds the writable
"Speaker Protection Calibrate" trigger control, adds
audioreach_vi_calibration_abort() and its q6apm_graph_close() /
q6apm_graph_stop() hooks, reverts the unreadable-T0 -EAGAIN check in
audioreach_get_sp_vi_t0() and audioreach_vi_calibration_event(), and changes
the signature of audioreach_speaker_protection().
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index cf6c686f88bdd..166ce59347f8d 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1608,16 +1611,10 @@ int audioreach_sp_register_speaker_map(struct thermal_zone_device * const *tzs,
> }
> EXPORT_SYMBOL_GPL(audioreach_sp_register_speaker_map);
>
> -/*
> - * Read each speaker's T0 in Q6 (degC * 64), 0 if its zone cannot be read.
> - * Returns the number of slots read, or -EAGAIN if any registered slot came
> - * back unreadable (e.g. the PA was on, so TADC was off). A partial reading
> - * must not be cached as a valid calibration reference.
> - */
> +/* Read each speaker's T0 in Q6 (degC * 64), 0 if its zone cannot be read */
> int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
> {
> unsigned int i, n;
> - bool any_failed = false;
>
> guard(mutex)(&sp_speaker_map_lock);
>
> @@ -1626,23 +1623,33 @@ int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
> int mdeg;
>
> if (sp_speaker_map.tz[i] &&
> - !thermal_zone_get_temp(sp_speaker_map.tz[i], &mdeg)) {
> + !thermal_zone_get_temp(sp_speaker_map.tz[i], &mdeg))
> vals[i] = div_s64((s64)mdeg * 64, 1000);
> - } else {
> + else
> vals[i] = 0;
> - any_failed = true;
> - }
> }
> for (; i < count; i++)
> vals[i] = 0;
>
> - if (any_failed)
> - return -EAGAIN;
> -
> return n;
> }
> EXPORT_SYMBOL_GPL(audioreach_get_sp_vi_t0);
[Severity: High]
Does removing the -EAGAIN error path here and the t0_rc < 0 check in
audioreach_vi_calibration_event() allow unreadable temperatures to be cached
as 0 degC?
During calibration playback the WSA884x PA is on, so wsa884x_get_temp()
returns -EAGAIN when no prior temperature was cached. wsa884x_tz_get_temp()
maps that to THERMAL_TEMP_INVALID, which thermal_zone_get_temp() turns into
-ENODATA.
With the check removed, audioreach_vi_calibration_event() stores
t0_cali_q6 = 0 alongside the calibrated r0_cali_q24, shifting the DSP's
voice-coil temperature estimate downward by 25-40 degC on later Normal-mode
playback and undermining speaker thermal protection.
[ ... ]
> @@ -1724,11 +1731,14 @@ void audioreach_vi_calibration_event(struct device *dev,
> sp_vi_r0.state = SP_VI_CALI_RUNNING;
> sp_vi_r0.num_ch = 0;
> memset(sp_vi_r0.r0_cali_q24, 0, sizeof(sp_vi_r0.r0_cali_q24));
> + memset(sp_vi_r0.last_state, 0, sizeof(sp_vi_r0.last_state));
> }
[Severity: Low]
Later in the series, commit "ASoC: qcom: x1e80100: register WSA speaker
thermal zones for speaker protection" deletes this memset() of
sp_vi_r0.last_state. Because audioreach_get_sp_vi_cal_state() always copies
all MAX_SP_VI_SPEAKERS entries, a run with fewer channels after an earlier
run leaves stale states in slots >= num_ch.
>
> for (i = 0; i < num_ch; i++) {
> u32 state = cali->cali_param[i].state;
>
> + sp_vi_r0.last_state[i] = state;
> +
> if (sp_vi_cali_state_is_failure(state))
> success = false;
> else if (!sp_vi_cali_state_is_terminal(state))
[Severity: Low]
Can a zero-channel calibration event wipe the cached R0/T0 configuration?
q6apm_vi_calibration_event() still calls audioreach_vi_calibration_event()
when num_ch is 0 (for example on a header-only payload or cali->num_ch == 0).
This loop then executes zero iterations, leaving decisive and success true,
which disarms calibration, zeroes sp_vi_r0.last_state, and overwrites
sp_vi_r0t0_cfg.num_ch with 0.
[ ... ]
> @@ -1772,24 +1782,16 @@ void audioreach_vi_calibration_event(struct device *dev,
> /*
> * Only a run where every speaker succeeded gives a usable R0/T0 set.
> * The DSP reports only R0, so pair it with the speakers' last T0
> - * reading. If any zone was unreadable (e.g. PA still on), skip the
> - * cache: a 0 degC Q6 would be stored as a valid calibration ref.
> + * reading; a zone that cannot be read gives T0 = 0.
> */
> if (success) {
> - int t0_rc = audioreach_get_sp_vi_t0(t0_live, num_ch);
> + audioreach_get_sp_vi_t0(t0_live, num_ch);
[Severity: High]
Can calling audioreach_get_sp_vi_t0() synchronously from
audioreach_vi_calibration_event() self-deadlock the single-threaded
qcom_apr_rx workqueue?
qcom_apr_rx dispatches both q6apm events and q6prm clock responses. When
wsa884x->pa_on is false, thermal_zone_get_temp() resumes the WSA884x and
SoundWire controller, which prepares the q6prmcc macro clock via a
synchronous GPR command waiting on the same blocked workqueue:
qcom_apr_rx
audioreach_vi_calibration_event()
lock(&sp_vi_r0_lock)
audioreach_get_sp_vi_t0()
... -> wsa884x_get_temp()
pm_runtime_resume_and_get()
... -> clk_prepare_enable(wsa->macro)
q6prm_send_cmd_sync()
wait_event_timeout(&prm->wait, ...) <-- self-deadlock
That stalls all GPR traffic for 5 seconds per clock vote and causes T0
readback to fail (caching T0 = 0 degC); even without a clock vote, blocking
SoundWire regmap I/O here stalls PCM completion callbacks and sp_vi_r0_lock
readers.
> + guard(mutex)(&sp_vi_r0t0_cfg_lock);
> + sp_vi_r0t0_cfg.num_ch = num_ch;
> + for (i = 0; i < num_ch; i++) {
> + sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
> + sp_vi_r0t0_cfg.t0_cali_q6[i] = (s16)t0_live[i];
> }
> }
[Severity: High]
Can acquiring sp_vi_r0t0_cfg_lock here ABBA deadlock with
audioreach_speaker_protection_vi() across the single-threaded qcom_apr_rx
workqueue?
audioreach_speaker_protection_vi() holds sp_vi_r0t0_cfg_lock across
q6apm_send_cmd_sync(), which waits for apm_callback() on qcom_apr_rx:
CPU0 qcom_apr_rx
audioreach_speaker_protection_vi()
lock(&sp_vi_r0t0_cfg_lock)
q6apm_send_cmd_sync()
audioreach_vi_calibration_event()
lock(&sp_vi_r0t0_cfg_lock) <-- blocks
wait_event_timeout(&apm->wait) <-- waits for apm_callback()
If qcom_apr_rx dequeues a calibration event before the APM_CMD_SET_CFG
response (from a concurrent graph or via the unlocked re-read of
sp_operation_mode in audioreach_speaker_protection_vi()), all GPR traffic
stalls until the 5-second timeout expires and speaker protection activation
fails.
[ ... ]
> @@ -1799,11 +1801,51 @@ void audioreach_vi_calibration_event(struct device *dev,
> audioreach_sp_finish_calibration();
> }
>
> +/* A run cut short never reports a final state, close it out */
> +void audioreach_vi_calibration_abort(struct device *dev)
> +{
> + unsigned int i;
> +
> + /* Back to Normal before anything else, so a racing trigger is clean */
> + audioreach_sp_finish_calibration();
> +
> + guard(mutex)(&sp_vi_r0_lock);
> +
> + if (!sp_vi_r0.armed)
> + return;
> +
> + sp_vi_r0.armed = false;
> +
> + /* The DSP never reported on this run: keep the previous result */
> + if (!memchr_inv(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states)))
> + return;
[Severity: Medium]
Is audioreach_sp_finish_calibration() called in the right place here?
Calling it unconditionally before acquiring sp_vi_r0_lock and checking
sp_vi_r0.armed clears a pending calibration trigger whenever a Normal-mode
VI graph stops or closes, and opens a window where a newly armed run gets
immediately disarmed once sp_vi_r0_lock is acquired.
Commit "ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker
protection" later moves audioreach_sp_finish_calibration() to the end of this
function, after the seen_states early return, which leaves sp_operation_mode
stuck in Calibration for 60 seconds whenever prepare fails or the graph stops
before the first DSP event. Calling audioreach_sp_finish_calibration() under
sp_vi_r0_lock right after clearing sp_vi_r0.armed and before the seen_states
check avoids both bugs.
[ ... ]
> static int audioreach_speaker_protection(struct q6apm_graph *graph,
> - const struct audioreach_module *module)
> + const struct audioreach_module *module,
> + u32 mode)
> {
> - return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE,
> - READ_ONCE(sp_operation_mode));
> + return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE, mode);
> }
[Severity: High]
Does adding the third parameter to audioreach_speaker_protection() break the
build?
Its only caller in audioreach_set_media_format() still passes two arguments:
sound/soc/qcom/qdsp6/audioreach.c:audioreach_set_media_format() {
...
case MODULE_ID_SPEAKER_PROTECTION:
rc = audioreach_speaker_protection(graph, module);
...
}
This fails compilation whenever CONFIG_SND_SOC_QDSP6_APM is enabled and
breaks git bisect, even though commit "ASoC: qcom: x1e80100: register WSA
speaker thermal zones for speaker protection" later reverts this hunk.
> diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
> index c410e2f6e6a3f..35daf763287cc 100644
> --- a/sound/soc/qcom/qdsp6/q6apm.c
> +++ b/sound/soc/qcom/qdsp6/q6apm.c
> @@ -815,10 +815,19 @@ struct q6apm_graph *q6apm_graph_open(struct device *dev, q6apm_cb cb,
> }
> EXPORT_SYMBOL_GPL(q6apm_graph_open);
>
> +static void q6apm_graph_abort_vi_calibration(struct q6apm_graph *graph)
> +{
> + if (q6apm_find_module_by_mid(graph, MODULE_ID_SPEAKER_PROTECTION_VI))
> + audioreach_vi_calibration_abort(graph->dev);
> +}
> +
> int q6apm_graph_close(struct q6apm_graph *graph)
> {
> struct audioreach_graph *ar_graph = graph->ar_graph;
>
> + /* Covers a graph closed without ever being started, e.g. on prepare failure */
> + q6apm_graph_abort_vi_calibration(graph);
> +
> graph->ar_graph = NULL;
> kref_put(&ar_graph->refcount, q6apm_put_audioreach_graph);
> gpr_free_port(graph->port);
> @@ -854,6 +863,7 @@ EXPORT_SYMBOL_GPL(q6apm_graph_start);
> int q6apm_graph_stop(struct q6apm_graph *graph)
> {
> struct audioreach_graph *ar_graph = graph->ar_graph;
> + int ret;
>
> if (ar_graph->start_count == 0)
> return 0;
> @@ -861,7 +871,10 @@ int q6apm_graph_stop(struct q6apm_graph *graph)
> if (--ar_graph->start_count > 0)
> return 0;
>
> - return audioreach_graph_mgmt_cmd(ar_graph, APM_CMD_GRAPH_STOP);
> + ret = audioreach_graph_mgmt_cmd(ar_graph, APM_CMD_GRAPH_STOP);
> + q6apm_graph_abort_vi_calibration(graph);
> +
> + return ret;
> }
[Severity: Medium]
Can calling q6apm_graph_abort_vi_calibration() unconditionally on every VI
graph stop and close clobber an armed calibration run?
q6apm_lpass_dai_prepare() calls q6apm_graph_stop() on a running Normal-mode
port right before q6apm_graph_media_format_pcm(), so an unconditional abort
cancels a newly triggered calibration before the prepare path can consume it.
In addition, q6apm_graph_close() calls q6apm_graph_abort_vi_calibration()
before kref_put(&ar_graph->refcount, ...) without checking whether another
open handle still holds or is running the shared ar_graph.
> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index a8fdd73cdecdd..16327961d6c1b 100644
> --- a/sound/soc/qcom/qdsp6/topology.c
> +++ b/sound/soc/qcom/qdsp6/topology.c
[ ... ]
> +static int audioreach_put_sp_calibrate(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + if (!ucontrol->value.integer.value[0])
> + return 0;
> +
> + return audioreach_trigger_sp_calibration() ? : 1;
> +}
[Severity: Medium]
Now that audioreach_trigger_sp_calibration() is exposed to userspace, can
concurrent writes race with audioreach_sp_finish_calibration() and
audioreach_sp_cal_watchdog_fn()?
audioreach_sp_finish_calibration() writes PARAM_ID_SP_VI_OP_MODE_NORMAL
before calling non-synchronous cancel_delayed_work(&sp_cal_watchdog):
CPU0 CPU1
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(..., NORMAL, CALIBRATION)
schedule_delayed_work(&sp_cal_watchdog)
cancel_delayed_work(&sp_cal_watchdog) <-- cancels CPU1's watchdog
An already-running audioreach_sp_cal_watchdog_fn() can also clear a newly
triggered run back to Normal, and it resets sp_operation_mode without
clearing sp_vi_r0.armed so late events from the timed-out graph can still
invoke audioreach_sp_finish_calibration().
[Severity: Medium]
Does exposing audioreach_trigger_sp_calibration() also make the watchdog
cancel inversion and stale sp_vi_r0.armed flag reachable on timeout?
If a concurrent trigger re-arms calibration between WRITE_ONCE() and
cancel_delayed_work() in audioreach_sp_finish_calibration(), the new run's
watchdog is cancelled and sp_operation_mode stays stuck in Calibration if no
playback graph starts. Separately, when the 60-second watchdog expires while
a graph is armed, audioreach_sp_cal_watchdog_fn() leaves sp_vi_r0.armed set,
so late DSP events from the expired run are still accepted and overwrite
cached R0/T0 and calibration state.
[Severity: Medium]
Can unloading snd-q6apm while sp_cal_watchdog is pending cause a
use-after-free?
audioreach_put_sp_calibrate() is the first caller of
audioreach_trigger_sp_calibration(), making schedule_delayed_work() on the
module-static sp_cal_watchdog reachable from userspace. apm_remove() never
cancels sp_cal_watchdog synchronously (audioreach_sp_shutdown() is declared
in audioreach.h but neither defined nor called), so unloading snd-q6apm
within 60 seconds of a trigger lets the timer run against freed module
memory. Cancelling sp_cal_watchdog synchronously after
of_platform_depopulate() and snd_soc_unregister_component() would prevent
this.
[Severity: Medium]
Can concurrent writes to "Speaker Protection Calibrate" leave the DSP VI
module configured inconsistently across sleeping GPR calls?
audioreach_speaker_protection_vi() snapshots mode =
READ_ONCE(sp_operation_mode) for event registration and
PARAM_ID_SP_VI_OP_MODE_CFG, sleeps in q6apm_send_cmd_sync(), and then
re-reads global sp_operation_mode directly instead of checking local mode.
That can skip PARAM_ID_SP_TH_VI_R0T0_CFG in Normal mode (leaving speakers
unprotected) or send it in Calibration mode.
Furthermore, after commit "ASoC: qcom: x1e80100: register WSA speaker thermal
zones for speaker protection" reverts audioreach_speaker_protection(),
MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI in
q6apm_graph_media_format_pcm() read sp_operation_mode separately across
sleeping IPC calls and can receive different modes.
[ ... ]
> + {
> + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
> + .name = "Speaker Protection Calibration State",
> + .access = SNDRV_CTL_ELEM_ACCESS_READ |
> + SNDRV_CTL_ELEM_ACCESS_VOLATILE,
> + /* Last calibration state per speaker (enum vi_calibration_state) */
> + .info = audioreach_info_sp_t0,
> + .get = audioreach_get_sp_cal_state,
> + },
[Severity: Medium]
Can userspace polling "Speaker Protection Calibration State" read stale
terminal state from a previous run, and should this avoid exposing a private
kernel enum as raw integers?
Neither audioreach_trigger_sp_calibration() nor
audioreach_arm_vi_calibration() clears sp_vi_r0.last_state[], and
audioreach_vi_calibration_abort() returns early if no DSP events arrived, so
triggering a second run immediately shows the prior run's
VI_CALIBRATION_STATE_SUCCESS until the first DSP event arrives.
In addition, enum vi_calibration_state is defined only in private header
sound/soc/qcom/qdsp6/audioreach.h, where 0 means both an uninitialized slot
and VI_CALIBRATION_STATE_INCORRECT_OP_MODE, and abort overwrites non-terminal
slots with VI_CALIBRATION_STATE_INACTIVE (1), making an aborted run
indistinguishable from DSP-reported INACTIVE.
> + {
> + /*
> + * Write-only edge trigger. Writing 1 arms a calibration run
> + * for the next (or current) WSA playback graph; the mode
> + * returns to Normal on its own once the DSP reports terminal
> + * state, on graph abort, or on the watchdog timeout.
> + */
> + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
> + .name = "Speaker Protection Calibrate",
> + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
> + SNDRV_CTL_ELEM_ACCESS_VOLATILE,
> + .info = audioreach_info_sp_calibrate,
> + .get = audioreach_get_sp_calibrate,
> + .put = audioreach_put_sp_calibrate,
> + },
[Severity: Medium]
Do these new controls violate ALSA mixer naming, bounds, and metadata
conventions?
"Speaker Protection Calibrate" is a writable SNDRV_CTL_ELEM_TYPE_BOOLEAN
control whose name does not end in "Switch", which fails the naming check in
tools/testing/selftests/alsa/mixer-test.c.
audioreach_put_sp_calibrate() also only tests !ucontrol->value.integer.value[0]
without rejecting out-of-range values such as 2 or -1 with -EINVAL.
"Speaker Protection Calibration State" reuses audioreach_info_sp_t0,
advertising signed S32_MIN..S32_MAX temperature bounds for non-negative enum
vi_calibration_state values (0..8).
Finally, the comment above "Speaker Protection Calibrate" describes it as a
write-only trigger affecting the next or current graph, whereas its access is
READWRITE and sp_operation_mode is only applied during graph media-format
setup.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=19
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls
2026-12-04 11:30 ` [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
@ 2026-12-04 14:01 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 14:01 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] ASoC: qcom: audioreach: missing sp_cal_watchdog cancel in
apm_remove()
- [Medium] ASoC: qcom: audioreach: watchdog race in
audioreach_sp_finish_calibration()
- [Medium] ASoC: qcom: missing RO/volatile flags in
audioreach_control_load()
- [Medium] ASoC: qcom: unchecked hdr->type cast in
audioreach_control_load()
- [Medium] ASoC: qcom: unratelimited log flood via
audioreach_put_sp_r0t0()
- [Medium] ASoC: qcom: sp_op_mode enum count mismatch in
audioreach_get_sp_op_mode()
--
commit a161a89d518c1d4827e5dbf7333beb85038a9af6
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: add speaker protection mixer controls
This commit adds topology kcontrol IDs and handlers for the speaker
protection operation mode and per-speaker R0/T0 calibration values in
audioreach.
> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index 5dd7f2c51d5cf..f9a3e9cf4119e 100644
> --- a/sound/soc/qcom/qdsp6/topology.c
> +++ b/sound/soc/qcom/qdsp6/topology.c
> @@ -1465,6 +1465,68 @@ static int audioreach_put_vol_ctrl_audio_mixer(struct snd_kcontrol *kcontrol,
> return 1;
> }
>
> +static int audioreach_get_sp_op_mode(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + ucontrol->value.enumerated.item[0] = audioreach_get_sp_operation_mode();
> +
> + return 0;
> +}
[Severity: Medium]
Can snd_soc_info_enum_double() advertise a 2-channel enum while
audioreach_get_sp_op_mode() only populates item[0]?
In soc_tplg_control_denum_create(), se->shift_l and se->shift_r come from
tplg_chan_get_shift() for SNDRV_CHMAP_FL and SNDRV_CHMAP_FR. When a topology
defines only SNDRV_CHMAP_FL, se->shift_r is assigned (unsigned char)-EINVAL,
so se->shift_l != se->shift_r and snd_soc_info_enum_double() reports
uinfo->count = 2. Because item[1] is left untouched from the caller buffer,
reads echo stale caller data or fail with -EINVAL under CONFIG_SND_CTL_DEBUG
in sanity_check_elem_value().
Normalizing se->shift_r = se->shift_l in audioreach_control_load() (or using
a single-channel enum info callback) avoids the mismatch.
[Severity: High]
Does unloading snd-q6apm while sp_cal_watchdog is pending cause a
use-after-free?
audioreach_trigger_sp_calibration() schedules the module-static
sp_cal_watchdog delayed work for 60 seconds, but commit "ASoC: qcom:
audioreach: send cached R0/T0 to the VI module in normal mode" removed
audioreach_sp_shutdown() and its call from apm_remove() in
sound/soc/qcom/qdsp6/q6apm.c. If snd-q6apm is unloaded within 60 seconds of
triggering calibration, sp_cal_watchdog fires against freed module text and
data.
Calling cancel_delayed_work_sync(&sp_cal_watchdog) from apm_remove() avoids
leaving the timer active across unbind and module unload.
[Severity: Medium]
Can audioreach_sp_finish_calibration() cancel a newly started calibration's
watchdog or race with a running watchdog callback?
In sound/soc/qcom/qdsp6/audioreach.c, audioreach_sp_finish_calibration()
resets sp_operation_mode to Normal before calling non-synchronous
cancel_delayed_work(&sp_cal_watchdog):
CPU0 CPU1
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(NORMAL -> CALIBRATION)
schedule_delayed_work(
&sp_cal_watchdog, ...)
cancel_delayed_work(
&sp_cal_watchdog) <-- cancels CPU1's watchdog
That leaves CPU1's calibration running with no timeout guard. In addition,
because cancel_delayed_work() does not wait for an in-flight
audioreach_sp_cal_watchdog_fn(), an older watchdog callback can run its
cmpxchg(CALIBRATION -> NORMAL) and prematurely abort a newly triggered
calibration.
> +/*
> + * "Speaker Protection Operation Mode" is read-only status. Enter
> + * Calibration via the "Speaker Protection Calibrate" trigger instead,
> + * so a stale alsactl state file cannot flip the DSP into Calibration
> + * and nothing can leave the system stuck there.
> + */
> +static int audioreach_put_sp_op_mode(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + return -EACCES;
> +}
[Severity: Medium]
Should audioreach_control_load() enforce read-only access on
SND_SOC_AR_TPLG_SP_OP_MODE_CTL instead of returning -EACCES from put?
When a topology omits hdr.access (0), snd_ctl_new1() defaults it to
SNDRV_CTL_ELEM_ACCESS_READWRITE, so alsactl saves and tries to restore the
control and fails with -EACCES (and ALSA read-only controls are expected to
reject writes with -EPERM in snd_ctl_elem_write()). Stripping
SNDRV_CTL_ELEM_ACCESS_WRITE, setting SNDRV_CTL_ELEM_ACCESS_READ |
SNDRV_CTL_ELEM_ACCESS_VOLATILE, and clearing kc->put = NULL in
audioreach_control_load() gives standard read-only semantics.
Because both sp_operation_mode and sp_vi_r0t0_cfg change asynchronously from
DSP events and timers without snd_ctl_notify(), SND_SOC_AR_TPLG_SP_R0T0_CTL
should also set SNDRV_CTL_ELEM_ACCESS_VOLATILE.
[ ... ]
> +static int audioreach_put_sp_r0t0(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + struct snd_soc_component *scomp = snd_kcontrol_chip(kcontrol);
> + long cur[AR_SP_R0T0_CTL_COUNT];
> + int ret;
> +
> + audioreach_get_sp_vi_r0t0(cur, AR_SP_R0T0_CTL_COUNT);
> + if (!memcmp(cur, ucontrol->value.integer.value, sizeof(cur)))
> + return 0;
> +
> + ret = audioreach_set_sp_vi_r0t0(scomp->dev, ucontrol->value.integer.value,
> + AR_SP_R0T0_CTL_COUNT);
> + if (ret < 0)
> + return ret;
> +
> + return 1;
> +}
[Severity: Medium]
Can userspace flood the kernel log through audioreach_put_sp_r0t0()?
audioreach_set_sp_vi_r0t0() emits unratelimited dev_err() messages on invalid
values and up to MAX_SP_VI_SPEAKERS unratelimited dev_info() lines on each
valid change, so any user with access to /dev/snd/controlC* can flood dmesg
at ioctl speed by repeating out-of-range writes or alternating two valid
R0/T0 sets. Using dev_err_ratelimited() and dev_dbg() in
audioreach_set_sp_vi_r0t0() avoids unbounded kernel logging.
[ ... ]
> @@ -1524,6 +1587,14 @@ static int audioreach_control_load(struct snd_soc_component *scomp, int index,
> sm = (struct soc_mixer_control *)kc->private_value;
> dobj = &sm->dobj;
> break;
> + case SND_SOC_AR_TPLG_SP_R0T0_CTL:
> + sm = (struct soc_mixer_control *)kc->private_value;
> + dobj = &sm->dobj;
> + break;
> + case SND_SOC_AR_TPLG_SP_OP_MODE_CTL:
> + se = (struct soc_enum *)kc->private_value;
> + dobj = &se->dobj;
> + break;
> default:
> dev_warn(scomp->dev, "control type not supported %d:%d:%d\n",
> hdr->ops.get, hdr->ops.put, hdr->ops.info);
> @@ -1550,6 +1621,10 @@ static const struct snd_soc_tplg_kcontrol_ops audioreach_io_ops[] = {
> audioreach_put_audio_mixer, snd_soc_info_volsw},
> {SND_SOC_AR_TPLG_VOL_CTL, audioreach_get_vol_ctrl_audio_mixer,
> audioreach_put_vol_ctrl_audio_mixer, snd_soc_info_volsw},
> + {SND_SOC_AR_TPLG_SP_OP_MODE_CTL, audioreach_get_sp_op_mode,
> + audioreach_put_sp_op_mode, snd_soc_info_enum_double},
> + {SND_SOC_AR_TPLG_SP_R0T0_CTL, audioreach_get_sp_r0t0,
> + audioreach_put_sp_r0t0, audioreach_info_sp_r0t0},
> };
[Severity: Medium]
Can a mismatched hdr->type cause type confusion and an out-of-bounds write in
audioreach_control_load()?
soc_tplg_kcontrol_elems_load() allocates kc->private_value according to
control_hdr->type, whereas audioreach_control_load() casts kc->private_value
to struct soc_mixer_control or struct soc_enum based only on hdr->ops.get.
If a topology pairs SND_SOC_AR_TPLG_SP_R0T0_CTL or
SND_SOC_AR_TPLG_SP_OP_MODE_CTL with SND_SOC_TPLG_TYPE_BYTES, writing
dobj->private = scontrol writes 8 bytes past the end of the smaller struct
soc_bytes_ext allocation and leaks scontrol on unload.
In addition, pairing SND_SOC_AR_TPLG_SP_OP_MODE_CTL with
SND_SOC_TPLG_TYPE_MIXER lets soc_tplg_kcontrol_bind_io() bind
snd_soc_info_enum_double() onto a struct soc_mixer_control (dereferencing
mixer fields as e->texts), while legitimate SND_SOC_TPLG_TYPE_ENUM controls
cannot use vendor ops.info ID 258 because soc_tplg_control_denum_create()
rejects non-standard enum info IDs first. Checking le32_to_cpu(hdr->type)
against SND_SOC_TPLG_TYPE_MIXER or SND_SOC_TPLG_TYPE_ENUM before casting
prevents this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=16
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback
2026-12-04 11:30 ` [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
@ 2026-12-04 14:04 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 14:04 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 12 potential
issues to consider:
- [High] ASoC: qcom: audioreach: deadlock holding sp_vi_r0t0_cfg_lock
across GPR IPC
- [High] ASoC: qcom: audioreach: thermal read in calibration callback
can deadlock
- [High] ASoC: qcom: audioreach: uncancelled sp_cal_watchdog work on
unload
- [High] ASoC: qcom: audioreach: sp_cal_watchdog not cancelled on module
unload
- [High] ASoC: qcom: audioreach: audioreach_vi_calibration_event()
caches 0 degC T0
- [Medium] ASoC: qcom: audioreach: TOCTOU race on sp_operation_mode in
VI setup
- [Medium] ASoC: qcom: audioreach: missing calibration teardown on VI
setup errors
- [Medium] ASoC: qcom: audioreach: T0 read with PA active and missing
count check
- [Medium] ASoC: qcom: audioreach: watchdog race in
audioreach_sp_finish_calibration()
- [Low] ASoC: qcom: audioreach: unchecked T0 range and s16 cast on
calibration
- [Low] ASoC: qcom: audioreach: commit omits regressive VI and lock
changes
- [Low] ASoC: qcom: audioreach: zero-channel VI event treated as
calibration success
--
commit 56bf9ae64c86f85671795a9786fef3749d76fe65
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ASoC: qcom: audioreach: add live speaker temperature (T0) readback
>
> A calibration needs each speaker's die temperature when R0 is measured,
> so that the R0/T0 pair given back to the DSP is consistent.
>
> Let the machine driver register the speakers' thermal zones in VI
> channel order with audioreach_sp_register_speaker_map(), and expose
> their temperatures in Q6 format as a read-only "Speaker Protection T0"
> control. Record T0 with R0 when a calibration completes. A slot that
> cannot be read reports 0.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202611231947.lq10qE2P-lkp@intel.com/
[Severity: Low]
Does the commit message omit several unrelated changes to
audioreach_speaker_protection_vi() and audioreach_set_media_format()?
Beyond adding T0 readback, this patch drops the sp_vi_r0t0_cfg snapshot so
sp_vi_r0t0_cfg_lock is held across q6apm_send_cmd_sync(), deletes error
cleanup after audioreach_register_events(), switches back from local mode
to sp_operation_mode, and fixes the mismatched 4-argument call site left
by commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in
normal mode". Those look like an accidental rebase or conflict
resolution.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index d1f6cd2b66354..cf6c686f88bdd 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> +int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
> +{
> + unsigned int i, n;
> + bool any_failed = false;
> +
> + guard(mutex)(&sp_speaker_map_lock);
> +
> + n = min(count, sp_speaker_map.num);
> + for (i = 0; i < n; i++) {
> + int mdeg;
> +
> + if (sp_speaker_map.tz[i] &&
> + !thermal_zone_get_temp(sp_speaker_map.tz[i], &mdeg)) {
> + vals[i] = div_s64((s64)mdeg * 64, 1000);
> + } else {
> + vals[i] = 0;
> + any_failed = true;
> + }
> + }
> + for (; i < count; i++)
> + vals[i] = 0;
> +
> + if (any_failed)
> + return -EAGAIN;
> +
> + return n;
> +}
[Severity: High]
Can calling audioreach_get_sp_vi_t0() from audioreach_vi_calibration_event()
deadlock the single-threaded qcom_apr_rx workqueue?
When a WSA884x PA is off and the SoundWire controller or WSA macro is
runtime-suspended, thermal_zone_get_temp() resumes the hardware and sends
a synchronous Q6PRM clock request whose response is processed on the same
qcom_apr_rx workqueue:
qcom_apr_rx (single-threaded wq)
graph_callback()
audioreach_vi_calibration_event()
audioreach_get_sp_vi_t0()
thermal_zone_get_temp()
wsa884x_get_temp()
pm_runtime_resume_and_get()
swrm_runtime_resume()
clk_prepare_enable(ctrl->hclk)
wsa_macro_enable_clocks()
q6prm_send_cmd_sync()
wait_event_timeout(&prm->wait) <-- waits for
prm_callback()
on this same wq
A concurrent userspace read of "Speaker Protection T0" or thermal sysfs
holding sp_speaker_map_lock, tz->lock, or wsa884x->sp_lock inside
q6prm_send_cmd_sync() also stalls qcom_apr_rx for the 5-second timeout,
blocking all GPR responses and PCM callbacks. Sampling T0 outside the
GPR RX workqueue avoids this.
[ ... ]
> @@ -1704,12 +1769,28 @@ void audioreach_vi_calibration_event(struct device *dev,
> if (success) {
> - guard(mutex)(&sp_vi_r0t0_cfg_lock);
> - sp_vi_r0t0_cfg.num_ch = num_ch;
> - for (i = 0; i < num_ch; i++)
> - sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
> + int t0_rc = audioreach_get_sp_vi_t0(t0_live, num_ch);
> +
> + if (t0_rc < 0) {
> + dev_warn(dev,
> + "VI calibration: T0 unreadable, not caching R0/T0 (%d)\n",
> + t0_rc);
> + success = false;
> + } else {
[Severity: High]
Can this still cache 0 degC for T0 when fewer than num_ch speaker thermal
zones are registered?
audioreach_get_sp_vi_t0() zero-fills slots past sp_speaker_map.num without
setting any_failed and returns n >= 0, so the t0_rc < 0 check passes
whenever sp_speaker_map.num < num_ch (for example on machine drivers that
do not call audioreach_sp_register_speaker_map()). Storing 0 degC
alongside a room-temperature R0 makes the DSP underestimate voice-coil
temperature by 25 to 40 degC, defeating thermal limiting.
Note that later commit "ASoC: qcom: audioreach: add speaker protection
calibration state control" also removes the any_failed/-EAGAIN return and
the t0_rc < 0 check altogether, which causes unreadable zones to cache
0 degC as well. Requiring num_ch > 0 and t0_rc == (int)num_ch (and
keeping the -EAGAIN check) prevents caching invalid T0 values.
[Severity: Medium]
Can audioreach_get_sp_vi_t0() read live hardware temperature here while
the speaker PA is active?
audioreach_vi_calibration_event() runs during active playback when
wsa884x->pa_on is true, and wsa884x_get_temp() cannot sample TADC while
the PA is on: it returns -EAGAIN on a fresh boot before any off-state
read, or returns an arbitrarily stale cached temperature from earlier.
Priming T0 before DAPM enables the PA (for instance during DAI prepare in
audioreach_speaker_protection_vi()) would pair R0 with a fresh reading.
Note that later commit "ASoC: qcom: audioreach: add speaker protection
calibration state control" also drops the -EAGAIN check, turning the
cold-boot failure into silently cached 0 degC values.
[Severity: Low]
What happens if the DSP sends a calibration event with num_ch == 0?
q6apm_vi_calibration_event() allows cali->num_ch == 0 or a payload with no
cali_param entries to reach audioreach_vi_calibration_event() with
num_ch == 0. With zero iterations, decisive and success stay true and
audioreach_get_sp_vi_t0(t0_live, 0) returns 0, overwriting
sp_vi_r0t0_cfg.num_ch with 0 and wiping any previously cached R0/T0.
> + guard(mutex)(&sp_vi_r0t0_cfg_lock);
> + sp_vi_r0t0_cfg.num_ch = num_ch;
> + for (i = 0; i < num_ch; i++) {
> + sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
> + sp_vi_r0t0_cfg.t0_cali_q6[i] = (s16)t0_live[i];
> + }
> + }
> }
[Severity: Low]
Should t0_live[i] be range-checked against [SP_VI_T0_MIN_Q6,
SP_VI_T0_MAX_Q6] before narrowing to s16?
WSA884x thermal zones can legitimately report up to 150 degC, which
exceeds SP_VI_T0_MAX_Q6 (80 degC), so caching it unchecked sends an
out-of-range T0 to the DSP and causes subsequent restore via
audioreach_set_sp_vi_r0t0() to fail with -ERANGE. Out-of-range thermal
readings outside s16 bounds would also silently wrap on the cast.
[ ... ]
> @@ -1794,11 +1875,8 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
> audioreach_arm_vi_calibration();
>
> rc = audioreach_register_events(graph, module);
> - if (rc) {
> - audioreach_sp_finish_calibration();
> - audioreach_sp_disarm_vi();
> + if (rc)
> return rc;
> - }
> }
[Severity: Medium]
Does removing the cleanup here leave calibration armed and stuck in
Calibration mode when audioreach_register_events(), packet allocation, or
q6apm_send_cmd_sync() fails?
sp_operation_mode stays in PARAM_ID_SP_VI_OP_MODE_CALIBRATION for up to
60 seconds (causing retries to return -EBUSY and intervening playback to
configure Calibration mode), and sp_vi_r0.armed remains true indefinitely
because audioreach_sp_cal_watchdog_fn() never clears it. Even with
audioreach_vi_calibration_abort() added later in the series, returning
early when no DSP events have arrived still leaves sp_operation_mode stuck
in Calibration mode.
[Severity: Medium]
Can audioreach_sp_finish_calibration() race with a concurrent
audioreach_trigger_sp_calibration() and cancel the new run's watchdog?
audioreach_sp_finish_calibration() writes PARAM_ID_SP_VI_OP_MODE_NORMAL
before calling cancel_delayed_work(&sp_cal_watchdog):
CPU0 CPU1
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(..., NORMAL, CALIBRATION)
schedule_delayed_work(&sp_cal_watchdog)
cancel_delayed_work(
&sp_cal_watchdog) <-- cancels CPU1's watchdog
An already-running audioreach_sp_cal_watchdog_fn() can also abort CPU1's
new calibration run back to Normal because cancel_delayed_work() does not
wait for it. Calling cancel_delayed_work_sync(&sp_cal_watchdog) before
resetting sp_operation_mode closes both windows.
[ ... ]
> @@ -1862,26 +1940,23 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
> if (rc)
> return rc;
>
> - if (mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
> + if (sp_operation_mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
[Severity: Medium]
Does re-reading sp_operation_mode here introduce a data race and a TOCTOU
mismatch with the local mode already sent to the DSP?
sp_operation_mode is updated concurrently via cmpxchg() and WRITE_ONCE(),
and q6apm_send_cmd_sync() sleeps just above. If calibration is triggered
while q6apm_send_cmd_sync() sleeps, a Normal-mode VI module skips
PARAM_ID_SP_TH_VI_R0T0_CFG; conversely, if calibration finishes or times
out in that window, Normal-mode R0/T0 config is sent to a Calibration-mode
module. Checking the snapshotted local mode avoids both.
> struct apm_module_sp_th_vi_r0t0_cfg *r0t0_cfg;
> - struct sp_vi_r0t0_cfg snap;
> int r0t0_sz;
>
> - /* Snapshot the cache so q6apm_send_cmd_sync runs with no locks held */
> - scoped_guard(mutex, &sp_vi_r0t0_cfg_lock)
> - snap = sp_vi_r0t0_cfg;
> + guard(mutex)(&sp_vi_r0t0_cfg_lock);
[Severity: High]
Can holding sp_vi_r0t0_cfg_lock across q6apm_send_cmd_sync() deadlock the
single-threaded qcom_apr_rx workqueue?
audioreach_vi_calibration_event() runs on qcom_apr_rx and acquires
sp_vi_r0t0_cfg_lock, while q6apm_send_cmd_sync() waits for apm_callback()
on the same workqueue:
CPU0 (DAI prepare) qcom_apr_rx (single-threaded wq)
------------------ --------------------------------
audioreach_speaker_protection_vi()
lock(&sp_vi_r0t0_cfg_lock)
q6apm_send_cmd_sync()
wait_event_timeout(&apm->wait)
graph_callback()
audioreach_vi_calibration_event()
lock(&sp_vi_r0t0_cfg_lock) <-- blocks
apm_callback() <-- cannot run to wake
&apm->wait
This stalls all GPR responses and PCM callbacks for the 5-second command
timeout and causes speaker protection activation to fail with -ETIMEDOUT.
Keeping the stack snapshot under scoped_guard(mutex, &sp_vi_r0t0_cfg_lock)
avoids holding the lock across IPC.
[ ... ]
> diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
> index 780d3df717d0e..e60e9c6561223 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.h
> +++ b/sound/soc/qcom/qdsp6/audioreach.h
> @@ -1136,6 +1137,10 @@ u32 audioreach_get_sp_operation_mode(void);
> int audioreach_trigger_sp_calibration(void);
> void audioreach_get_sp_vi_r0t0(long *vals, unsigned int count);
> int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int count);
> +int audioreach_sp_register_speaker_map(struct thermal_zone_device * const *tzs,
> + unsigned int num);
> +int audioreach_get_sp_vi_t0(long *vals, unsigned int count);
> +int audioreach_add_sp_telemetry_controls(struct snd_soc_component *component);
> void audioreach_vi_calibration_event(struct device *dev,
> const struct event_id_vi_per_spkr_calibration *cali,
> u32 num_ch);
[Severity: High]
Is sp_cal_watchdog left pending on module unload?
audioreach_trigger_sp_calibration() schedules the 60-second module-global
sp_cal_watchdog delayed work, and audioreach.h still declares
audioreach_sp_shutdown(), but its implementation and call in apm_remove()
were dropped by commit "ASoC: qcom: audioreach: send cached R0/T0 to the
VI module in normal mode". Unloading snd-q6apm while the timer is pending
leads to a use-after-free when audioreach_sp_cal_watchdog_fn() runs in
freed module memory.
[Severity: High]
Can unloading snd-q6apm within 60 seconds of a calibration trigger crash
the kernel when sp_cal_watchdog fires?
apm_remove() unregisters the component without calling
cancel_delayed_work_sync(&sp_cal_watchdog), leaving the timer queued on
system_wq after module text and static data are freed. Restoring
audioreach_sp_shutdown() and calling it in apm_remove() after component
and child teardown prevents both the use-after-free and re-arming from
userspace kcontrol writes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=18
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link
2026-12-04 11:30 ` [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
@ 2026-12-04 14:11 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 14:11 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ASoC: qcom: sdw: SDW_STREAM_RELEASED breaks multi-direction VI
prepare
- [High] ASoC: qcom: sdw VI stream state and m_rt_count break on
hw_free/hw_params
--
commit fcb4d5953ce1c17d2a685b1658cf4d75828397a0
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link
This commit enables multi_direction_codecs and a capture params fixup on
the WSA_CODEC_DMA_RX_0 BE link when VI codec DAIs are present so speaker
V/I sense feedback runs alongside playback.
> diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
> index 4fe86ec062c40..745975574658c 100644
> --- a/sound/soc/qcom/x1e80100.c
> +++ b/sound/soc/qcom/x1e80100.c
[ ... ]
> @@ -386,6 +423,19 @@ static void x1e80100_add_be_ops(struct snd_soc_card *card)
> link->be_hw_params_fixup = x1e80100_be_hw_params_fixup;
> link->ops = &x1e80100_be_ops;
> }
> +
> + /*
> + * The WSA playback link also carries the VI codec DAIs when
> + * the DT wires them in. Only advertise multi_direction_codecs
> + * then, so stock setups without VI feedback do not pay the
> + * extra TX startup/prepare path.
> + */
> + if (link->id == WSA_CODEC_DMA_RX_0 &&
> + x1e80100_link_has_vi_codec(link)) {
> + link->multi_direction_codecs = 1;
> + link->multi_direction_params_fixup =
> + x1e80100_wsa_vi_params_fixup;
> + }
> }
> }
[Severity: High]
Can enabling multi_direction_codecs cause speaker playback prepare to fail
with -EINVAL after an hw_free/hw_params cycle while the VISENSE Switch is
off?
On hw_free without closing the PCM, qcom_swrm_hw_free() calls
sdw_stream_remove_master(), which sets the VI capture stream's state to
SDW_STREAM_RELEASED. On the next hw_params with VISENSE Switch off (the
wsa884x default), wsa884x_vi_hw_params() skips sdw_stream_add_slave() and
qcom_swrm_hw_params() leaves sr_opp->state at SDW_STREAM_RELEASED.
sound/soc/qcom/sdw.c:qcom_snd_sdw_prepare() {
...
/* 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);
...
}
Because SDW_STREAM_RELEASED != SDW_STREAM_ALLOCATED, qcom_snd_sdw_prepare()
calls sdw_prepare_stream(sr_opp), which rejects SDW_STREAM_RELEASED with
-EINVAL and aborts playback prepare.
qcom_snd_sdw_hw_free() has the same state != SDW_STREAM_ALLOCATED check and
will also call sdw_disable_stream() and sdw_deprepare_stream() on an
unconfigured released stream. Checking for the configured/active states
instead of != SDW_STREAM_ALLOCATED would avoid both.
[Severity: High]
Does enabling multi_direction_codecs also leak stream->m_rt_count on the
VI capture stream across hw_params/hw_free cycles when multiple capture
DAIs share a SoundWire controller?
With VISENSE Switch off, wsa884x_vi_hw_params() returns early without
adding a slave, but qcom_swrm_stream_alloc_ports() still calls
sdw_stream_add_master() with nports = 0 for each capture DAI on the bus.
drivers/soundwire/stream.c:sdw_stream_add_master() {
...
if (!sdw_master_port_allocated(m_rt)) {
ret = sdw_master_port_alloc(m_rt, num_ports);
if (ret)
goto alloc_error;
stream->m_rt_count++;
}
...
}
Because sdw_master_port_allocated() tests !list_empty(&m_rt->port_list),
which remains false when num_ports is 0, each extra capture DAI on the
same controller increments stream->m_rt_count again while reusing the
single m_rt. On hw_free, sdw_stream_remove_master() decrements m_rt_count
only once per bus, leaking +1 per extra capture DAI per cycle.
Once the leaked m_rt_count reaches bus->hw_sync_min_links (3 on SWRM
v2.0.0+), a later prepare with VISENSE Switch turned on takes the
multi-link path in sdw_bank_switch() -> sdw_transfer_defer(), which fails
with -ENOTSUPP because qcom_swrm_ops does not implement .xfer_msg_defer,
breaking playback until the PCM is closed and reopened.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=20
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
2026-12-04 11:30 ` [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
@ 2026-12-04 14:16 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 14:16 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] ASoC: qcom: sp_cal_watchdog not cancelled on apm_remove()
causing unload UAF
- [High] ASoC: qcom: deadlock on qcom_apr_rx via
audioreach_get_sp_vi_t0()
- [High] ASoC: qcom: deadlock holding sp_vi_r0t0_cfg_lock across
q6apm_send_cmd_sync()
- [Medium] ASoC: qcom: undocumented audioreach.c edits mixed into
x1e80100 commit
- [Medium] ASoC: qcom: audioreach_vi_calibration_abort() skips mode
reset on early abort
- [Medium] ASoC: qcom: audioreach_vi_calibration_event() leaves stale
last_state entries
- [Medium] ASoC: qcom: audioreach_vi_calibration_event() treats num_ch
== 0 as success
- [Medium] ASoC: qcom: audioreach_sp_finish_calibration() races with
calibration trigger
- [Medium] ASoC: qcom: races in audioreach_sp_finish_calibration() and
watchdog
- [Medium] ASoC: qcom: TOCTOU races from repeated sp_operation_mode
reads
- [Medium] ASoC: qcom: audioreach_vi_calibration_event() caches 0 degC
when T0 unread
--
commit 1e72e7acf4cbfb553e5573406d950d671352b644
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
>
> Look up the thermal zone of each WSA884x VI DAI on the WSA Playback
> link, in DT order, and register them with
> audioreach_sp_register_speaker_map() for the "Speaker Protection T0"
> control. A missing zone is logged and leaves its slot reading 0. The
> map is cleared when the link is torn down.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
[Severity: Medium]
Should the sound/soc/qcom/qdsp6/audioreach.c changes be split out of this
commit? The commit message only describes registering WSA884x thermal zones
in x1e80100.c, while the diff also makes three unmentioned edits to
audioreach.c.
In particular, reverting audioreach_speaker_protection() back to two
arguments silently fixes a build failure introduced by commit "ASoC: qcom:
audioreach: add speaker protection calibration state control", where
audioreach_set_media_format() still passes two arguments. Folding that
signature fix into the introducing commit keeps git bisect buildable across
the series.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 166ce59347f8d..cf30c18fa25ff 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
> @@ -1731,7 +1731,6 @@ void audioreach_vi_calibration_event(struct device *dev,
> sp_vi_r0.state = SP_VI_CALI_RUNNING;
> sp_vi_r0.num_ch = 0;
> memset(sp_vi_r0.r0_cali_q24, 0, sizeof(sp_vi_r0.r0_cali_q24));
> - memset(sp_vi_r0.last_state, 0, sizeof(sp_vi_r0.last_state));
> }
[Severity: Medium]
Does removing this memset() leave stale calibration states in
sp_vi_r0.last_state[]? Nothing else clears last_state before a run, and the
loop below only writes indices 0..num_ch - 1, while
audioreach_get_sp_vi_cal_state() returns all MAX_SP_VI_SPEAKERS slots to
userspace.
If a 2-channel calibration runs after a 4-channel calibration, slots 2 and 3
will still report the previous run's terminal states through the Speaker
Protection Calibration State control.
> for (i = 0; i < num_ch; i++) {
[Severity: Medium]
Can audioreach_vi_calibration_event() treat a zero-channel DSP event as a
successful calibration and wipe the cached R0/T0 values?
q6apm_vi_calibration_event() can pass num_ch == 0 when cali->num_ch is 0 or
the payload carries no cali_param entries. With decisive and success
initialized to true, the loop runs zero times and execution falls through to
set sp_vi_r0t0_cfg.num_ch = 0, discarding any valid cached R0/T0 data. The
if (!num_ch) return guard from commit "ASoC: qcom: audioreach: cache VI
calibration results per speaker" was dropped in commit "ASoC: qcom:
audioreach: add speaker protection calibration trigger infrastructure".
[ ... ]
> @@ -1806,9 +1805,6 @@ void audioreach_vi_calibration_abort(struct device *dev)
> {
> unsigned int i;
>
> - /* Back to Normal before anything else, so a racing trigger is clean */
> - audioreach_sp_finish_calibration();
> -
> guard(mutex)(&sp_vi_r0_lock);
>
> if (!sp_vi_r0.armed)
> @@ -1838,14 +1834,17 @@ void audioreach_vi_calibration_abort(struct device *dev)
> }
>
> dev_info(dev, "VI calibration aborted: graph stopped before the DSP finished\n");
> +
> + /* Edge-triggered: the mode auto-returns to Normal on abort too. */
> + audioreach_sp_finish_calibration();
> }
[Severity: Medium]
Does moving audioreach_sp_finish_calibration() here skip resetting
sp_operation_mode when a calibration run aborts before the first DSP event?
If prepare fails after audioreach_arm_vi_calibration() or the graph stops
before any event arrives, sp_vi_r0.seen_states is still all zeroes, so
audioreach_vi_calibration_abort() clears sp_vi_r0.armed and returns early
without calling audioreach_sp_finish_calibration(). sp_operation_mode then
stays in PARAM_ID_SP_VI_OP_MODE_CALIBRATION for up to 60 seconds, causing
retries to fail with -EBUSY and normal playback to configure the DSP in
calibration mode. Calling audioreach_sp_finish_calibration() right after
clearing sp_vi_r0.armed avoids this.
[Severity: High]
Can unloading snd-q6apm while sp_cal_watchdog is pending cause a
use-after-free?
audioreach_trigger_sp_calibration() schedules the module-static delayed work
sp_cal_watchdog for 60 seconds, but apm_remove() never cancels it
synchronously (audioreach_sp_shutdown() is still declared in audioreach.h,
after its definition and call were dropped in commit "ASoC: qcom: audioreach:
send cached R0/T0 to the VI module in normal mode").
CPU0 kworker
audioreach_trigger_sp_calibration()
schedule_delayed_work(&sp_cal_watchdog, ...)
rmmod snd-q6apm
apm_remove() (watchdog still pending)
module text and .bss freed
audioreach_sp_cal_watchdog_fn()
<-- use-after-free
Calling cancel_delayed_work_sync(&sp_cal_watchdog) from apm_remove() closes
this window.
[Severity: Medium]
Can audioreach_sp_finish_calibration() cancel the watchdog of a newly
triggered calibration run?
Because WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL) runs
before cancel_delayed_work(&sp_cal_watchdog), a concurrent trigger can arm a
new calibration and lose its watchdog:
CPU0 CPU1
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode, NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(NORMAL -> CALIBRATION)
schedule_delayed_work(&sp_cal_watchdog)
cancel_delayed_work(&sp_cal_watchdog) <-- cancels CPU1's watchdog
Calibration then stays armed indefinitely if no playback runs.
[Severity: Medium]
Can an in-flight audioreach_sp_cal_watchdog_fn() prematurely abort a new
calibration run or leave sp_vi_r0.armed desynchronized?
Because audioreach_sp_finish_calibration() uses asynchronous
cancel_delayed_work(), a watchdog callback that is already running can
execute cmpxchg(CALIBRATION -> NORMAL) after a fresh
audioreach_trigger_sp_calibration() succeeds. In addition, when the watchdog
fires after audioreach_arm_vi_calibration(), it resets sp_operation_mode to
NORMAL without taking sp_vi_r0_lock or clearing sp_vi_r0.armed, leaving the
two state flags out of sync.
> static int audioreach_speaker_protection(struct q6apm_graph *graph,
> - const struct audioreach_module *module,
> - u32 mode)
> + const struct audioreach_module *module)
> {
> - return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE, mode);
> + return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE,
> + READ_ONCE(sp_operation_mode));
> }
[Severity: Medium]
Can reading sp_operation_mode separately in audioreach_speaker_protection()
and audioreach_speaker_protection_vi() program the two speaker protection
modules into mismatched modes?
During audioreach_set_media_format(), blocking GPR commands run between
configuring MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI.
If calibration is triggered or the watchdog expires in between, one module
gets Normal mode and the other gets Calibration mode. In addition,
audioreach_speaker_protection_vi() later re-reads global sp_operation_mode
without READ_ONCE() instead of checking its local mode snapshot, so it can
either omit PARAM_ID_SP_TH_VI_R0T0_CFG in Normal mode or send it after
configuring Calibration mode. Snapshotting sp_operation_mode once per graph
prepare avoids both races.
[Severity: High]
Can holding sp_vi_r0t0_cfg_lock across q6apm_send_cmd_sync() in
audioreach_speaker_protection_vi() deadlock with qcom_apr_rx?
q6apm_send_cmd_sync() waits for apm_callback() to run on the single-threaded
qcom_apr_rx workqueue, while audioreach_vi_calibration_event() runs on that
same workqueue and acquires sp_vi_r0t0_cfg_lock on calibration completion:
CPU0 qcom_apr_rx
---- -----------
audioreach_speaker_protection_vi()
lock(&sp_vi_r0t0_cfg_lock)
q6apm_send_cmd_sync()
wait_event_timeout(&apm->wait)
audioreach_vi_calibration_event()
lock(&sp_vi_r0t0_cfg_lock) <-- blocks
If a decisive calibration event is queued ahead of the APM_CMD_SET_CFG
response, qcom_apr_rx stalls until the 5-second command timeout expires and
speaker protection activation fails with -ETIMEDOUT. Copying sp_vi_r0t0_cfg
under the lock and releasing it before calling q6apm_send_cmd_sync() breaks
the dependency.
> diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
> index 745975574658c..938d444f0e4bc 100644
> --- a/sound/soc/qcom/x1e80100.c
> +++ b/sound/soc/qcom/x1e80100.c
[ ... ]
> + /* Also drops the zones of a previous bind when none are found */
> + audioreach_sp_register_speaker_map(tzs, num);
> +}
[Severity: High]
Can registering WSA884x thermal zones here deadlock the single-threaded
qcom_apr_rx workqueue when audioreach_get_sp_vi_t0() reads a zone whose PA
is off?
When wsa884x->pa_on is false, thermal_zone_get_temp() -> wsa884x_get_temp()
calls pm_runtime_resume_and_get(wsa884x->dev), which resumes the SoundWire
controller and lpass_wsamacro -> q6prmcc -> q6prm_send_cmd_sync(). Because
q6apm and q6prm share the single-threaded qcom_apr_rx workqueue, two
deadlocks occur:
qcom_apr_rx
audioreach_vi_calibration_event()
audioreach_get_sp_vi_t0()
thermal_zone_get_temp()
wsa884x_get_temp()
pm_runtime_resume_and_get() -> ... -> q6prm_send_cmd_sync()
wait_event_timeout(&prm->wait) <-- waits on qcom_apr_rx
A userspace Speaker Protection T0 read can also ABBA deadlock with
qcom_apr_rx by holding sp_speaker_map_lock while waiting in
q6prm_send_cmd_sync() as qcom_apr_rx blocks on sp_speaker_map_lock inside
audioreach_vi_calibration_event(). Either path stalls all GPR responses for
5 seconds per clock vote and causes calibration to record 0 degC as T0.
[Severity: Medium]
Will calibration on a freshly booted system silently cache 0 degC as the
reference temperature T0?
Before any PA-off temperature read has happened, wsa884x->temperature is 0.
During calibration playback wsa884x->pa_on is true, so wsa884x_get_temp()
returns -EAGAIN and thermal_zone_get_temp() fails with -ENODATA.
audioreach_get_sp_vi_t0() converts that failure to 0 without returning an
error, and audioreach_vi_calibration_event() then stores t0_cali_q6 = 0
(0 degC) in sp_vi_r0t0_cfg, introducing roughly a 25 degC offset error into
the DSP thermal protection model on subsequent playbacks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=21
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
2026-12-04 11:30 ` [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
@ 2026-12-04 14:16 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 14:16 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] arm64: dts: qcom: mahua-t14s: duplicate swr0 capture DAI
leaks m_rt_count
- [Medium] ASoC: qcom: sdw: qcom_snd_sdw_prepare() fails with -EINVAL on
reconfiguration
- [Low] arm64: dts: qcom: mahua-t14s: wsa-dai-link codec sound-dai
exceeds maxItems 8
--
commit 9bbeecb4a8d74299d3e25546aee9dc3a76f8fd40
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
This commit adds the WSA8845 V/I sense DAIs, SoundWire VI ports, and WSA
macro VI capture DAI to the wsa-dai-link codec list on the ThinkPad T14s
Gen 7, and updates the speaker nodes to #sound-dai-cells = <1>.
> diff --git a/arch/arm64/boot/dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts b/arch/arm64/boot/dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts
> index 26d6d8285e040..35419545d7156 100644
> --- a/arch/arm64/boot/dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts
> +++ b/arch/arm64/boot/dts/qcom/mahua-lenovo-thinkpad-t14s-gen7-lcd.dts
> @@ -269,8 +269,11 @@ cpu {
> };
>
> codec {
> - sound-dai = <&left_spkr>, <&right_spkr>,
> - <&swr0 0>, <&lpass_wsamacro 0>;
> + sound-dai = <&left_spkr 0>, <&right_spkr 0>,
> + <&swr0 0>, <&lpass_wsamacro 0>,
> + <&left_spkr 1>, <&right_spkr 1>,
> + <&swr0 12>, <&swr0 13>,
> + <&lpass_wsamacro 2>;
> };
[Severity: Low]
Does this break dtbs_check against the binding?
Documentation/devicetree/bindings/sound/qcom,sm8250.yaml constrains
codec/sound-dai to maxItems: 8 for qcom,glymur-sndcard, while this expands
wsa-dai-link to 9 entries.
[Severity: Medium]
Can listing both <&swr0 12> and <&swr0 13> leak stream->m_rt_count on the
capture stream?
qcom_swrm_stream_alloc_ports() already allocates master ports for every
slave on ctrl->bus regardless of dai->id and calls sdw_stream_add_master()
even when nports is 0. With VISENSE disabled (the default),
wsa884x_vi_hw_params() skips sdw_stream_add_slave(), leaving
m_rt->port_list empty:
drivers/soundwire/stream.c:sdw_stream_add_master() {
if (!sdw_master_port_allocated(m_rt)) {
ret = sdw_master_port_alloc(m_rt, num_ports);
if (ret)
goto alloc_error;
stream->m_rt_count++;
}
}
Because !sdw_master_port_allocated(m_rt) stays true when num_ports is 0,
the second swr0 DAI increments stream->m_rt_count twice for a single m_rt,
while sdw_stream_remove_master() only decrements it once during hw_free.
Once repeated hw_params/hw_free cycles push m_rt_count to
hw_sync_min_links (3 on qcom,soundwire-v3.1.0), sdw_bank_switch() calls
sdw_transfer_defer(), which fails with -ENOTSUPP since qcom_swrm_ops has
no .xfer_msg_defer.
Listing a single swr0 capture DAI avoids the duplicate registration and
keeps codec/sound-dai within 8 entries.
[Severity: Medium]
Does enabling multi_direction_codecs on wsa-dai-link cause playback
prepare to fail with -EINVAL after a hw_free reconfiguration?
With VISENSE disabled, hw_free on an open playback substream calls
qcom_swrm_hw_free() -> sdw_stream_remove_master(), moving the capture
stream sr_opp->state to SDW_STREAM_RELEASED. A subsequent hw_params on
the same open substream leaves sr_opp->state in SDW_STREAM_RELEASED.
In commit "ASoC: qcom: sdw: add per-direction stream runtimes for
multi_direction links", qcom_snd_sdw_prepare() only skips
SDW_STREAM_ALLOCATED, so it calls sdw_prepare_stream(sr_opp), which
rejects SDW_STREAM_RELEASED with -EINVAL and aborts playback prepare.
qcom_snd_sdw_hw_free() has the same != SDW_STREAM_ALLOCATED check and
would also try to disable and deprepare a SDW_STREAM_RELEASED stream.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=23
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
2026-12-04 11:30 ` [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
@ 2026-12-04 14:18 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 14:18 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] arm64: dts: qcom: glymur-crd: duplicate swr capture DAIs
corrupt m_rt_count
- [Low] arm64: dts: qcom: glymur-crd: wsa-dai-link sound-dai exceeds
maxItems 8
--
commit 9edf854ed04ec9661b034e307113813304c4887f
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
This commit adds the WSA8845 V/I sense speaker DAIs, SoundWire VI ports, and
WSA macro VI capture DAIs to the WSA Playback DAI link in glymur-crd.dtsi,
and updates the four speaker nodes to use #sound-dai-cells = <1>.
> diff --git a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
> index 58158b51fe295..93bee2a97e548 100644
> --- a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
> +++ b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
> @@ -257,10 +257,16 @@ cpu {
> };
>
> codec {
> - sound-dai = <&left_woofer>, <&left_tweeter>,
> + sound-dai = <&left_woofer 0>, <&left_tweeter 0>,
> <&swr0 0>, <&lpass_wsamacro 0>,
> - <&right_woofer>, <&right_tweeter>,
> - <&swr3 0>, <&lpass_wsa2macro 0>;
> + <&left_woofer 1>, <&left_tweeter 1>,
> + <&swr0 12>, <&swr0 13>,
> + <&lpass_wsamacro 2>,
> + <&right_woofer 0>, <&right_tweeter 0>,
> + <&swr3 0>, <&lpass_wsa2macro 0>,
> + <&right_woofer 1>, <&right_tweeter 1>,
> + <&swr3 12>, <&swr3 13>,
[Severity: Medium]
Should wsa-dai-link list only one capture DAI per SoundWire controller
instead of two (<&swr0 12>, <&swr0 13> and <&swr3 12>, <&swr3 13>)?
qcom_swrm_hw_params() allocates all mapped master ports for every slave on
the controller regardless of dai->id, matching why the playback side only
lists <&swr0 0> and <&swr3 0>. It also calls sdw_stream_add_master()
unconditionally even when nports is 0.
When VISENSE Switch is disabled on a bus, wsa884x_vi_hw_params() skips
sdw_stream_add_slave(), leaving nports == 0 and m_rt->port_list empty.
Because sdw_master_port_allocated() checks !list_empty(&m_rt->port_list),
the duplicate DAI increments stream->m_rt_count twice for one m_rt.
With VISENSE Switch enabled on only one bus, m_rt_count reaches
bus->hw_sync_min_links (3 on SoundWire v3.1.0), so sdw_bank_switch() enters
multi-link mode and calls sdw_transfer_defer(). Because qcom_swrm_ops has
no .xfer_msg_defer, this returns -ENOTSUPP and fails WSA Playback prepare.
> + <&lpass_wsa2macro 2>;
> };
[Severity: Low]
Does expanding codec/sound-dai to 18 entries break dtbs_check against
Documentation/devicetree/bindings/sound/qcom,sm8250.yaml?
That binding validates qcom,glymur-sndcard and caps codec/sound-dai at
maxItems: 8, so make dtbs_check fails on glymur-crd.dtb and mahua-crd.dtb.
Even after removing the two duplicate SoundWire capture DAIs, sound-dai
would still have 16 entries and need maxItems updated in the binding.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=22
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: add WSA speaker protection VI feedback
2026-12-04 11:31 ` [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
@ 2026-12-04 14:24 ` sashiko-bot
0 siblings, 0 replies; 45+ messages in thread
From: sashiko-bot @ 2026-12-04 14:24 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] arm64: dts: qcom: x1e78100-t14s: duplicate swr0 capture DAIs
leak m_rt_count
- [Medium] ASoC: qcom: sdw: VI stream left in SDW_STREAM_RELEASED breaks
prepare after hw_free
- [Low] arm64: dts: qcom: x1e78100-t14s: wsa-dai-link codec sound-dai
exceeds maxItems
- [Low] arm64: dts: qcom: x1e78100-t14s: off-by-one swr0 VI DAI indices
--
commit fbe15e25019853415d9375e16b2bb7773629c92a
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
arm64: dts: qcom: x1e78100-t14s: add WSA speaker protection VI feedback
This commit wires up the WSA8845 speaker V/I sense DAIs, SoundWire VI
capture ports, and WSA macro VI capture DAI on the WSA Playback link in
the ThinkPad T14s Gen 6 devicetree, and sets #sound-dai-cells to 1 on
both speaker nodes.
> diff --git a/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi b/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
> index 93c7e3a02041c..2242bbe59d94e 100644
> --- a/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
> +++ b/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
> @@ -478,7 +478,11 @@ cpu {
> };
>
> codec {
> - sound-dai = <&left_spkr>, <&right_spkr>, <&swr0 0>, <&lpass_wsamacro 0>;
> + sound-dai = <&left_spkr 0>, <&right_spkr 0>,
> + <&swr0 0>, <&lpass_wsamacro 0>,
> + <&left_spkr 1>, <&right_spkr 1>,
> + <&swr0 10>, <&swr0 11>,
> + <&lpass_wsamacro 2>;
> };
>
> platform {
[Severity: Medium]
Can listing two swr0 capture DAIs on wsa-dai-link leak stream->m_rt_count?
qcom_swrm_stream_alloc_ports() already iterates all slaves on ctrl->bus
and allocates every mapped master port in one sdw_stream_add_master()
call, which is why playback only lists <&swr0 0>.
With both <&swr0 10> and <&swr0 11>, qcom_swrm_hw_params() calls
sdw_stream_add_master() twice per hw_params on the same capture stream.
When VISENSE Switch is off (the boot default), both calls pass
num_ports = 0 and leave m_rt->port_list empty:
drivers/soundwire/stream.c:sdw_stream_add_master() {
...
if (!sdw_master_port_allocated(m_rt)) {
ret = sdw_master_port_alloc(m_rt, num_ports);
if (ret)
goto alloc_error;
stream->m_rt_count++;
}
...
}
Both calls increment stream->m_rt_count for the same m_rt, while
qcom_swrm_hw_free() decrements it once, leaking +1 per hw_params/hw_free
cycle on an open PCM.
Once m_rt_count reaches hw_sync_min_links (3 on qcom,soundwire-v2.0.0),
preparing the stream after enabling VI sense enters the multi_link path in
sdw_bank_switch() -> sdw_transfer_defer() and fails with -ENOTSUPP because
qcom_swrm_ops lacks xfer_msg_defer, breaking WSA playback. Using a single
swr0 capture DAI avoids the duplicate master registration.
[Severity: Low]
Are the swr0 VI DAI indices off by one here?
In hamoa.dtsi, swr0 has 9 DOUT ports and 4 DIN ports, and
qcom_swrm_get_port_config() maps 0-based index i to 1-based master port
i + 1. Without .of_xlate_dai_name on qcom_swrm_dai_component,
snd_soc_get_dlc() resolves the sound-dai cell as a 0-based DAI index.
Passing the 1-based port numbers from qcom,port-mapping as <&swr0 10> and
<&swr0 11> binds SDW Pin10 (port 11) and SDW Pin11 (unconfigured port 12)
while omitting SDW Pin9 (port 10), instead of 0-based indices 9 and 10.
While qcom.c currently reads the hardware port numbers from
slave->m_port_map[], this mixes 0-based and 1-based indexing in the
devicetree ABI and binds an unconfigured port's DAI.
[Severity: Low]
Does expanding sound-dai to nine entries break dtbs_check?
The sound node uses compatible = "qcom,x1e80100-sndcard", whose binding in
Documentation/devicetree/bindings/sound/qcom,sm8250.yaml constrains codec
sound-dai to maxItems: 8.
Either dropping the duplicate swr0 capture DAI or updating maxItems in the
binding is needed for dtbs_check to pass on
x1e78100-lenovo-thinkpad-t14s.dtb and
x1e78100-lenovo-thinkpad-t14s-oled.dtb.
[Severity: Medium]
Will enabling multi_direction_codecs on wsa-dai-link break prepare after
hw_free when VISENSE is off?
With <&left_spkr 1> and <&right_spkr 1> added, x1e80100_add_be_ops() sets
multi_direction_codecs on WSA_CODEC_DMA_RX_0. When hw_free runs on an
open playback substream with VISENSE off, qcom_swrm_hw_free() ->
sdw_stream_remove_master() moves the capture stream to SDW_STREAM_RELEASED.
On a subsequent hw_params with VISENSE still disabled,
wsa884x_vi_hw_params() returns early without adding a slave and
sdw_stream_add_master() leaves stream->state at SDW_STREAM_RELEASED:
sound/soc/qcom/sdw.c:qcom_snd_sdw_prepare() {
...
if (sr_opp && sr_opp->state != SDW_STREAM_ALLOCATED) {
ret = qcom_snd_sdw_prepare_dir(rtd,
substream->stream ^ 1);
...
}
Because qcom_snd_sdw_prepare() only skips SDW_STREAM_ALLOCATED, it calls
sdw_prepare_stream() on the released capture stream, which fails with
-EINVAL and tears down playback until the PCM is closed and reopened.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=24
^ permalink raw reply [flat|nested] 45+ messages in thread
end of thread, other threads:[~2026-12-04 14:24 UTC | newest]
Thread overview: 45+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-12-04 12:01 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-12-04 12:12 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-12-04 12:38 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
2026-12-04 12:33 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-12-04 13:34 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-12-04 13:35 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-12-04 13:32 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-12-04 13:32 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
2026-12-04 13:25 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-12-04 13:43 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-12-04 13:50 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-12-04 14:01 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-12-04 13:56 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-12-04 14:04 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-12-04 13:59 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-12-04 14:11 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-12-04 14:16 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-12-04 14:18 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-12-04 14:16 ` sashiko-bot
2026-12-04 11:31 ` [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
2026-12-04 14:24 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox