* [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx
@ 2026-12-01 12:47 Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
` (23 more replies)
0 siblings, 24 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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.
How it works:
1. The topology puts the speaker protection (SP) module in the playback
graph and the SP_VI module in a VI feedback graph fed by the WSA VI
sense ports, joined by a control link.
2. Starting playback on the WSA Playback link also starts the VI sense
capture (8 kHz, 32-bit, one V/I pair per speaker), so the DSP always
gets feedback while the speakers play.
3. Calibration, once per device with the speakers cold: userspace writes
"Speaker Protection Calibrate" and plays silence; the DSP makes its
own stimulus. The VI module measures each speaker's resistance (R0),
the driver records the amplifier die temperature (T0) with it, and
"Speaker Protection Calibration State" reports the result. The mode
auto-returns to Normal on terminal state or graph abort.
4. Userspace reads R0/T0 from "Speaker Protection R0T0" and saves them,
e.g. with alsactl store.
5. At boot the saved values are written back (alsactl restore). In
Normal mode the driver sends R0/T0 to the VI module, and the SP
module uses the live V/I feedback to keep each speaker within its
temperature and excursion limits.
Changes in v4:
- patch 01: pick up Morimoto-san's Acked-by.
- Rebased onto sound-next; patch 10 adopts the PCM_MAX_NUM_CHANNEL
rename (c3409cbf70ac).
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.
- there was a discussion with Pierre about introducing new
multi-directional soundwire stream apis, I will send that framwork
change as RFC for more discussions, I dont think we should block this
series for that api to evolve.
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 | 18 +-
include/sound/soc-dapm.h | 2 +
include/sound/soc.h | 7 +
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 | 105 +++
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 | 232 +++--
sound/soc/qcom/x1e80100.c | 100 +++
sound/soc/soc-core.c | 20 +-
sound/soc/soc-dai.c | 1 +
sound/soc/soc-dapm.c | 32 +
sound/soc/soc-pcm.c | 136 ++-
23 files changed, 2150 insertions(+), 142 deletions(-)
create mode 100644 Documentation/sound/soc/multi-direction-codecs.rst
base-commit: dc9d6bcd9a9d9da8b44ef1f5f4c6ed469ce843ae
--
2.53.0
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v4 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
` (22 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
` (21 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 | 7 +
sound/soc/soc-dapm.c | 32 ++++
sound/soc/soc-pcm.c | 136 ++++++++++++---
6 files changed, 314 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..c15559bb4a84 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -736,6 +736,10 @@ 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 +774,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..1160efe0b223 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,41 @@ 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 = 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 +1242,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] 40+ messages in thread
* [PATCH v4 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
` (20 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (2 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:19 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
` (19 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 | 232 +++++++++++++++++++++++++++++++++----------
1 file changed, 178 insertions(+), 54 deletions(-)
diff --git a/sound/soc/qcom/sdw.c b/sound/soc/qcom/sdw.c
index 6576b47a4c8c..82f1c47a788c 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) {
@@ -49,43 +95,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;
}
@@ -93,59 +138,106 @@ 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) {
+ qcom_snd_sdw_release_stream(
+ sdw_find_dir_stream(rtd, substream->stream));
+ 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
@@ -153,15 +245,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);
@@ -187,9 +296,13 @@ 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)
+ qcom_snd_sdw_release_stream(
+ sdw_find_dir_stream(rtd, substream->stream ^ 1));
}
EXPORT_SYMBOL_GPL(qcom_snd_sdw_shutdown);
@@ -197,18 +310,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] 40+ messages in thread
* [PATCH v4 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (3 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
` (18 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (4 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:03 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
` (17 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 | 95 ++++++++++++++++++++++++++++++++------
1 file changed, 80 insertions(+), 15 deletions(-)
diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
index f58ce92c46d4..91aa004d7137 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,27 @@ 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);
+
+ 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;
+
+ return sdw_stream_add_slave(wsa884x->slave, &wsa884x->vi_sconfig,
+ &wsa884x->vi_port_config, 1,
+ 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 +1804,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 +1831,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 +1870,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 +1906,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 +2154,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] 40+ messages in thread
* [PATCH v4 07/24] ASoC: codecs: wsa883x: add VI sense capture DAI
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (5 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:03 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
` (16 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (6 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:13 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
` (15 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 | 70 +++++++++++++++++++++++++++++++++++++-
1 file changed, 69 insertions(+), 1 deletion(-)
diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
index 91aa004d7137..d0a00aced220 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>
@@ -1935,8 +1936,10 @@ static int wsa884x_get_temp(struct wsa884x_priv *wsa884x, long *temp)
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;
}
@@ -2058,6 +2061,42 @@ 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;
+
+ /*
+ * 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;
+ return 0;
+ }
+ if (ret)
+ return ret;
+
+ *temp_mdeg = (int)mdeg;
+ return 0;
+}
+
+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;
@@ -2194,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,
+ NULL);
+ 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] 40+ messages in thread
* [PATCH v4 09/24] ASoC: qcom: audioreach: add control link support to graphs
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (7 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:09 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
` (14 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (8 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
` (13 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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/qcom/qdsp6/audioreach.c | 86 ++++++++++++++++++++++++-------
sound/soc/qcom/qdsp6/audioreach.h | 57 ++++++++++++++++++++
sound/soc/qcom/qdsp6/q6apm.c | 26 ++++++++++
3 files changed, 151 insertions(+), 18 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index f66d3ff68a44..aea482270c26 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -1436,6 +1436,18 @@ 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;
+
+ /* 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 +1456,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 +1495,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 +1536,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 +1548,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 +1630,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 +1639,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] 40+ messages in thread
* [PATCH v4 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (9 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
` (12 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (10 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:10 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
` (11 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 aea482270c26..c48ba63448db 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,16 +1456,112 @@ 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;
+
+ 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;
- /* 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);
+ 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,
@@ -1485,6 +1601,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)
@@ -1512,6 +1636,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] 40+ messages in thread
* [PATCH v4 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (11 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:12 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 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; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 | 69 ++++++++++++++++++++++++++-----
sound/soc/qcom/qdsp6/audioreach.h | 2 +
2 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index c48ba63448db..dd0b70013a0e 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,48 @@ 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_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)
+ pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
+}
+
+static void audioreach_sp_finish_calibration(void)
+{
+ WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
+ cancel_delayed_work(&sp_cal_watchdog);
+}
+
+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 ||
@@ -1562,14 +1607,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,
@@ -1613,6 +1660,7 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
const struct audioreach_module *module,
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;
@@ -1636,11 +1684,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. */
@@ -1664,7 +1714,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;
@@ -1755,8 +1805,7 @@ 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,
- PARAM_ID_SP_OP_MODE_CALIBRATION);
+ rc = audioreach_speaker_protection(graph, module);
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..bb632d3ca0a7 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -1113,6 +1113,8 @@ 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);
--
2.53.0
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v4 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (12 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:16 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
` (9 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 | 170 ++++++++++++++++++++++++++++++
sound/soc/qcom/qdsp6/audioreach.h | 21 ++++
2 files changed, 191 insertions(+)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index dd0b70013a0e..19e00563c783 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)
{
@@ -1542,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)
@@ -1606,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. */
@@ -1750,6 +1856,70 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
kfree(pkt);
+ if (rc)
+ return rc;
+
+ if (sp_operation_mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
+ struct apm_module_sp_th_vi_r0t0_cfg *r0t0_cfg;
+ int r0t0_sz;
+
+ guard(mutex)(&sp_vi_r0t0_cfg_lock);
+
+ if (!sp_vi_r0t0_cfg.num_ch)
+ return 0;
+
+ if (sp_vi_r0t0_cfg.num_ch != num_speakers) {
+ dev_err(graph->dev,
+ "SP R0T0 is for %u speakers, graph has %u\n",
+ sp_vi_r0t0_cfg.num_ch, num_speakers);
+ return -EINVAL;
+ }
+
+ 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);
+
+ 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 = 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;
+ }
+
+ 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",
+ 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(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,
+ sp_vi_r0t0_cfg.t0_cali_q6[i] / 64,
+ abs((sp_vi_r0t0_cfg.t0_cali_q6[i] % 64) * 1000 / 64));
+ }
+ }
+
return rc;
}
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index bb632d3ca0a7..1a79d51e4ea0 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);
--
2.53.0
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v4 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (13 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:16 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
` (8 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 19e00563c783..2c1ff8e65b67 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -1923,6 +1923,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)
@@ -1976,12 +2111,16 @@ 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);
break;
case MODULE_ID_SPEAKER_PROTECTION_VI:
rc = audioreach_speaker_protection_vi(graph, module, cfg);
+ 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] 40+ messages in thread
* [PATCH v4 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (14 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
` (7 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (15 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
` (6 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 2c1ff8e65b67..42e542f30591 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -2058,12 +2058,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] 40+ messages in thread
* [PATCH v4 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (16 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:23 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
` (5 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 | 66 ++++++++++++++++++++++++++++++-
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, 117 insertions(+), 2 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index 42e542f30591..3974191f9c53 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,50 @@ 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 */
+int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
+{
+ unsigned int i, n;
+
+ 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;
+ }
+ for (; i < count; i++)
+ vals[i] = 0;
+
+ 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 +1697,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 +1758,20 @@ 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; a zone that cannot be read gives T0 = 0.
+ */
if (success) {
+ audioreach_get_sp_vi_t0(t0_live, num_ch);
+
guard(mutex)(&sp_vi_r0t0_cfg_lock);
sp_vi_r0t0_cfg.num_ch = num_ch;
- for (i = 0; i < num_ch; i++)
+ 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");
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index 1a79d51e4ea0..2136075d0e87 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] 40+ messages in thread
* [PATCH v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (17 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:27 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
` (4 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 | 60 +++++++++++++++++++++++++++++
sound/soc/qcom/qdsp6/audioreach.h | 2 +
sound/soc/qcom/qdsp6/q6apm.c | 15 +++++++-
sound/soc/qcom/qdsp6/topology.c | 63 +++++++++++++++++++++++++++++++
4 files changed, 139 insertions(+), 1 deletion(-)
diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index 3974191f9c53..cf30c18fa25f 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;
@@ -1632,6 +1635,21 @@ int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
}
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 = {};
@@ -1718,6 +1736,8 @@ void audioreach_vi_calibration_event(struct device *dev,
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))
@@ -1780,6 +1800,46 @@ 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;
+
+ 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");
+
+ /* 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)
{
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index 2136075d0e87..27952835714d 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);
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..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] 40+ messages in thread
* [PATCH v4 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (18 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
` (3 subsequent siblings)
23 siblings, 0 replies; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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 c927672eaede..3262fa39ceb9 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 <sound/pcm.h>
+#include <sound/pcm_params.h>
#include <sound/jack.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
@@ -85,6 +86,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)
{
@@ -181,6 +204,20 @@ static const struct snd_soc_ops x1e80100_be_ops = {
.prepare = x1e80100_snd_prepare,
};
+/* 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;
@@ -193,6 +230,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] 40+ messages in thread
* [PATCH v4 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (19 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:24 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
` (2 subsequent siblings)
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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/x1e80100.c | 50 +++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
index 3262fa39ceb9..9401d4702432 100644
--- a/sound/soc/qcom/x1e80100.c
+++ b/sound/soc/qcom/x1e80100.c
@@ -5,6 +5,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/soundwire/sdw.h>
+#include <linux/thermal.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/jack.h>
@@ -12,6 +13,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"
@@ -24,6 +26,49 @@ struct x1e80100_snd_data {
bool jack_setup;
};
+/*
+ * 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);
@@ -34,6 +79,8 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)
switch (cpu_dai->id) {
case WSA_CODEC_DMA_RX_0:
+ x1e80100_register_sp_speakers(rtd);
+ fallthrough;
case WSA_CODEC_DMA_RX_1:
/*
* Set limit of -3 dB on Digital Volume and 0 dB on PA Volume
@@ -82,6 +129,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] 40+ messages in thread
* [PATCH v4 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (20 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:31 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 23/24] arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (21 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:30 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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] 40+ messages in thread
* [PATCH v4 24/24] arm64: dts: qcom: x1e78100-t14s: add WSA speaker protection VI feedback
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
` (22 preceding siblings ...)
2026-12-01 12:47 ` [PATCH v4 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
@ 2026-12-01 12:47 ` Srinivas Kandagatla
2026-12-01 13:27 ` sashiko-bot
23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 12:47 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>
---
.../qcom/x1e78100-lenovo-thinkpad-t14s.dtsi | 18 +++++++++++++++---
1 file changed, 15 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..c5fb20ef9f1c 100644
--- a/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
+++ b/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
@@ -477,8 +477,20 @@ cpu {
sound-dai = <&q6apmbedai WSA_CODEC_DMA_RX_0>;
};
+ /*
+ * WSA SPKR playback-side codec DAIs plus the WSA
+ * speaker-protection VI capture-side DAIs. 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 tplg handles
+ * the DSP-side pairing.
+ */
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 +1352,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 +1364,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] 40+ messages in thread
* Re: [PATCH v4 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI
2026-12-01 12:47 ` [PATCH v4 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
@ 2026-12-01 13:03 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:03 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ASoC: wsa884x: skip of sdw_stream_add_slave() in
wsa884x_vi_hw_params()
--
commit 5d2938219182b5ec30c59b2d10fc736bdd774d75
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: codecs: wsa884x: add VI sense capture DAI
This commit moves the VI sense port from the playback sink ports to a
dedicated source port and adds a VI capture DAI with its own SoundWire
stream runtime and DAI operations.
> diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
> index f58ce92c46d40..91aa004d7137b 100644
> --- a/sound/soc/codecs/wsa884x.c
> +++ b/sound/soc/codecs/wsa884x.c
[ ... ]
> @@ -1767,6 +1774,27 @@ 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);
> +
> + 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;
> +
> + return sdw_stream_add_slave(wsa884x->slave, &wsa884x->vi_sconfig,
> + &wsa884x->vi_port_config, 1,
> + wsa884x->vi_sruntime);
> +}
[Severity: High]
Does returning 0 early when wsa884x->port_enable[WSA884X_PORT_VISENSE] is
false leave wsa884x->vi_sruntime unconfigured and cause PCM prepare to fail
with -EINVAL?
Unlike wsa884x_hw_params(), which still calls sdw_stream_add_slave() with 0
ports, skipping sdw_stream_add_slave() here never transitions
vi_sruntime->state to SDW_STREAM_CONFIGURED. When the VISENSE Switch mixer
control is off (its default at probe), a direct capture prepare or a second
hw_params and prepare after hw_free on a multi_direction_codecs link will
find vi_sruntime->state in SDW_STREAM_ALLOCATED or 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);
...
}
After qcom_swrm_hw_free() -> sdw_stream_remove_master() sets
vi_sruntime->state to SDW_STREAM_RELEASED, qcom_snd_sdw_prepare() no longer
skips sr_opp and calls sdw_prepare_stream(), which rejects
SDW_STREAM_RELEASED with -EINVAL and tears down playback. In addition, if
hw_params is called again without an intervening hw_free after disabling
VISENSE Switch, returning early leaves the previously added slave port
attached to vi_sruntime.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=6
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 07/24] ASoC: codecs: wsa883x: add VI sense capture DAI
2026-12-01 12:47 ` [PATCH v4 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
@ 2026-12-01 13:03 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:03 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ASoC: codecs: wsa883x: missing port_enable check in
wsa883x_vi_hw_params()
--
commit fdbd630d2f5fa194ab1385415632917d5e5bef11
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: codecs: wsa883x: add VI sense capture DAI
This commit moves the VISENSE port to the SoundWire source port mask, adds
a dedicated VI capture DAI and stream configuration for it, and programs
SWRS_SCP_HOST_CLK_DIV2_CTL_BANK in a new bus_config callback.
> 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
[ ... ]
> @@ -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]
Should wsa883x_vi_hw_params() check
wsa883x->port_enable[WSA883X_PORT_VISENSE] before calling
sdw_stream_add_slave(), the way wsa884x_vi_hw_params() does?
Now that wsa883x_hw_params() skips WSA883X_PORT_VISENSE, nothing reads
port_enable[WSA883X_PORT_VISENSE], which leaves the "VISENSE Switch" mixer
control as a no-op and unconditionally configures and prepares the
SoundWire capture stream on multi_direction_codecs DAI links even when VI
sensing is off.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=7
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 09/24] ASoC: qcom: audioreach: add control link support to graphs
2026-12-01 12:47 ` [PATCH v4 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
@ 2026-12-01 13:09 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:09 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: qcom: audioreach: control link stride and param_size
mismatch
- [Medium] ASoC: qcom: audioreach: underflow and infinite loop in
audioreach_parse_cl_tokens()
- [Medium] ASoC: qcom: audioreach: control link leak on widget load
failure
--
commit 81c62eeed7c8f4aa7eb81d4000c3ddba0ee624c7
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: audioreach: add control link support to graphs
This commit parses control link tokens from the AudioReach topology into a
per-subgraph list and appends deduplicated control link configurations to
the APM_CMD_GRAPH_OPEN packet.
> 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
> @@ -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)
[ ... ]
> @@ -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]);
> + }
[ ... ]
> @@ -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;
> }
[ ... ]
> @@ -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;
[Severity: High]
Does indexing cl_data->link_obj[] with a fixed MAX_INTENTS array stride match
the variable-length intent_data.prop_size expected by the DSP?
struct apm_control_link_obj declares intent_id_list[MAX_INTENTS], giving each
link_obj entry a fixed 48-byte stride, whereas intent_data.prop_size only
counts the non-zero clink_obj->num_intents packed into intent_id_list[].
When a control link has fewer than MAX_INTENTS intents and multiple links are
present, the DSP advances past intent_data by prop_size bytes and reads the
trailing unused zero slots of intent_id_list[] as the header of the next
control link.
Also, audioreach_alloc_graph_pkt() sets param_data->param_size from the
pre-deduplication num_control_links count (and always emits the
APM_PARAM_ID_MODULE_CTRL_LINK_CFG section even when num_control_links is 0),
while audioreach_populate_graph() updates cl_data->num_ctrl_link_cfg = nlink
without updating cl_data->param_data.param_size, leaving param_size and
num_ctrl_link_cfg inconsistent whenever duplicate links are skipped.
> 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
[ ... ]
> @@ -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)) {
[ ... ]
> +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++;
> + }
> + }
> +}
[Severity: Medium]
Can le32_to_cpu(cl_array->num_elems) - 1 underflow in
audioreach_parse_cl_tokens() and audioreach_parse_control_link_tokens()?
le32_to_cpu() returns an unsigned 32-bit value, so when cl_array->num_elems
is 0 the subtraction wraps to U32_MAX, promoting tkn_count to unsigned and
reading past the end of cl_array->value.
In addition, if cl_array->size is 0 on a non-module-cfg array, sz never
advances and the outer loop in audioreach_parse_cl_tokens() spins forever
before audioreach_get_module_priv_data() is reached. Errors returned by
audioreach_tplg_alloc_control_link() are also silently ignored instead of
being propagated to audioreach_widget_load_module_common().
> @@ -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() in
audioreach_widget_load_module_common() leak the allocated
audioreach_control_link objects and their IDs in apm->control_links_idr?
If audioreach_parse_cont_tokens(), audioreach_parse_common_tokens() or
audioreach_get_module_priv_data() fails, audioreach_widget_load_module_common()
returns before setting w->dobj.private = mod. audioreach_widget_unload()
returns immediately when dobj->private is NULL, so any control links added to
sg->control_link_list and apm->control_links_idr for that widget are not
cleaned up if the subgraph has no other loaded containers or if a failed
container remains on sg->container_list.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=9
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker
2026-12-01 12:47 ` [PATCH v4 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
@ 2026-12-01 13:10 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:10 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: false calibration success when num_ch
is 0
- [Low] ASoC: qcom: audioreach: broken negative Q24 format in
sp_vi_q24_to_int_frac()
--
commit d42dd2e274b061eaf9d1d04ab1acceb12bc8b91c
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: cache VI calibration results per speaker
This commit adds a mutex-protected per-speaker cache for VI calibration
events so state transitions are logged once per speaker and the measured R0
values are recorded once all speakers reach a terminal state.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index aea482270c26a..c48ba63448dbd 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1436,16 +1456,112 @@ static int audioreach_gain_set(struct q6apm_graph *graph,
[ ... ]
> +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 wrongly when an
out-of-range negative R0 is logged on VI_CALIBRATION_STATE_FAILED?
For a negative two's-complement s32 with a fractional part, val >> 24
floors toward negative infinity and val & 0xffffff yields the positive
offset above that floor (1000 - |frac|), so -0.250 ohms (-0x00400000) is
printed via %d.%03d as -1.750 ohms.
> +
> +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;
> +
> + 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;
>
> - /* 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);
> + 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;
[Severity: Medium]
What happens in audioreach_vi_calibration_event() if num_ch is 0?
q6apm_vi_calibration_event() clamps num_ch from above by
MAX_SP_VI_SPEAKERS, but does not reject 0 when cali->num_ch is 0 or the
event payload carries no cali_param entry:
sound/soc/qcom/qdsp6/q6apm.c:q6apm_vi_calibration_event() {
...
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);
}
With num_ch == 0, the first-event check clears any previous sp_vi_r0
result, the per-channel loop executes zero iterations leaving decisive and
success true, and the run is disarmed and recorded as SP_VI_CALI_SUCCESS
with sp_vi_r0.num_ch = 0, causing later events from the run to be ignored.
Validating !num_ch || num_ch > MAX_SP_VI_SPEAKERS at the start of
audioreach_vi_calibration_event() would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=12
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
2026-12-01 12:47 ` [PATCH v4 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
@ 2026-12-01 13:12 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:12 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:
- [High] ASoC: qcom: audioreach: missing cancel_delayed_work_sync() on
module unload
- [Medium] ASoC: qcom: audioreach: watchdog race in
audioreach_sp_finish_calibration()
- [Medium] ASoC: qcom: audioreach: desynchronized calibration state on
timeout or error
- [Medium] ASoC: qcom: audioreach: split sp_operation_mode read across
SP and VI modules
--
commit 1f0f3a4d2d0ba4e2a629bbda935112fa18551e13
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
This commit introduces an internal speaker protection operation mode state
with an edge-triggered calibration helper and a 60-second watchdog timer to
return the mode to Normal.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index c48ba63448dbd..dd0b70013a0ec 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1456,6 +1459,48 @@ 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_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)
> + pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
> +}
> +
> +static void audioreach_sp_finish_calibration(void)
> +{
> + WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
> + cancel_delayed_work(&sp_cal_watchdog);
> +}
[Severity: Medium]
Can a concurrent audioreach_trigger_sp_calibration() race with
audioreach_sp_finish_calibration() and end up with no watchdog armed?
CPU0 CPU1
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
..._NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(&sp_operation_mode,
..._NORMAL, ..._CALIBRATION)
schedule_delayed_work(&sp_cal_watchdog,
...)
cancel_delayed_work(&sp_cal_watchdog)
<-- cancels CPU1's watchdog
Because sp_operation_mode is reset to PARAM_ID_SP_VI_OP_MODE_NORMAL before
cancel_delayed_work(&sp_cal_watchdog), CPU1 can re-enter calibration mode
while the previous delayed work is still pending or about to be cancelled.
This leaves sp_operation_mode in PARAM_ID_SP_VI_OP_MODE_CALIBRATION without
a running watchdog timer, so if no playback completes, all future triggers
fail with -EBUSY.
Similarly, because cancel_delayed_work() does not wait for an in-flight
audioreach_sp_cal_watchdog_fn() callback to finish, a callback that already
started for the finishing run can run cmpxchg() after CPU1 triggers a new
run and immediately flip the new run back to Normal.
> +
> +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: High]
What stops sp_cal_watchdog from firing after the snd-q6apm module is
unloaded?
CONFIG_SND_SOC_QDSP6_APM is tristate and builds audioreach.o into
snd-q6apm.ko, but neither apm_remove() nor a module exit path calls
cancel_delayed_work_sync(&sp_cal_watchdog). If calibration is triggered
and snd-q6apm is unloaded during the 60-second window, the timer expires
after the module text and data are freed and executes
audioreach_sp_cal_watchdog_fn() in unmapped memory (use-after-free).
> @@ -1562,14 +1607,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));
> }
[Severity: Medium]
Can MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI be
configured with different operation modes in the same graph?
q6apm_graph_media_format_pcm() configures each module in the graph in turn
and sleeps in q6apm_send_cmd_sync() on every command. Because
audioreach_speaker_protection() and audioreach_speaker_protection_vi() read
sp_operation_mode independently without serialization against
audioreach_trigger_sp_calibration() or audioreach_sp_cal_watchdog_fn(), a
trigger or watchdog timeout between the two calls configures one module in
Normal mode and the other in Calibration mode. If SP is in Normal mode
while VI is in Calibration mode, calibration fails with
VI_CALIBRATION_STATE_INCORRECT_OP_MODE; if SP is in Calibration mode while
VI is in Normal mode, sp_vi_r0 is never armed and calibration events are
not registered, leaving sp_operation_mode stuck in Calibration until the
watchdog expires.
[ ... ]
> @@ -1636,11 +1684,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 sp_vi_r0.armed stay out of sync with sp_operation_mode if the watchdog
fires or if VI setup fails?
When audioreach_sp_cal_watchdog_fn() times out after 60 seconds, it resets
sp_operation_mode to PARAM_ID_SP_VI_OP_MODE_NORMAL without taking
sp_vi_r0_lock to clear sp_vi_r0.armed or update sp_vi_r0.state. If a
calibration playback started near the end of the 60-second window or takes
longer than 60 seconds, the watchdog flips sp_operation_mode back to Normal
while sp_vi_r0.armed remains true; a new audioreach_trigger_sp_calibration()
call can then succeed and later be silently reset to Normal when a terminal
event from the earlier run reaches audioreach_vi_calibration_event() and
calls audioreach_sp_finish_calibration().
In addition, if audioreach_register_events(),
audioreach_alloc_apm_cmd_pkt(), or q6apm_send_cmd_sync() fails in
audioreach_speaker_protection_vi() after audioreach_arm_vi_calibration(),
the error path returns with sp_vi_r0.armed still set to true and
sp_operation_mode left in PARAM_ID_SP_VI_OP_MODE_CALIBRATION.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=13
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone
2026-12-01 12:47 ` [PATCH v4 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
@ 2026-12-01 13:13 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:13 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: codecs: wsa884x: duplicate hwmon registration in
wsa884x_probe()
- [Medium] ASoC: codecs: wsa884x: missing hw_init check in
wsa884x_get_temp()
- [Low] ASoC: codecs: wsa884x: 0 degC cache sentinel collision in
wsa884x_get_temp()
--
commit 00e0327ff20a8e4f0dd3f6d78b99d67cb9827c8e
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 die
temperature sensor and returns -EAGAIN to hwmon and THERMAL_TEMP_INVALID
to the thermal zone when no temperature reading is available yet.
> diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
> index 91aa004d7137b..d0a00aced2208 100644
> --- a/sound/soc/codecs/wsa884x.c
> +++ b/sound/soc/codecs/wsa884x.c
[ ... ]
> @@ -1935,8 +1936,10 @@ static int wsa884x_get_temp(struct wsa884x_priv *wsa884x, long *temp)
> 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 checking !wsa884x->temperature misidentify a valid cached 0 degC
reading as uncached? wsa884x_get_temp() accepts readings from
WSA884X_LOW_TEMP_THRESHOLD (-10) to WSA884X_HIGH_TEMP_THRESHOLD (150), so
if 0 degC was cached before the PA turned on, reads while pa_on is true
will return -EAGAIN to hwmon and THERMAL_TEMP_INVALID to the thermal zone.
Also, wsa884x->temperature is an unsigned int, so caching a valid negative
reading in [-10, -1] degC wraps around and overflows when multiplied by
1000 into signed long *temp.
> @@ -2058,6 +2061,42 @@ 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;
> +
> + /*
> + * 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;
> + return 0;
> + }
> + if (ret)
> + return ret;
> +
> + *temp_mdeg = (int)mdeg;
> + return 0;
> +}
[Severity: Medium]
Should the !wsa884x->hw_init check live inside wsa884x_get_temp() under
wsa884x->sp_lock (returning -EAGAIN) instead of only in
wsa884x_tz_get_temp()?
The commit message says hwmon returns -EAGAIN until the codec is
initialised, but wsa884x_hwmon_read() calls wsa884x_get_temp() directly
without checking hw_init. If userspace reads hwmon before the SoundWire
slave attaches (or after SDW_SLAVE_UNATTACHED clears hw_init),
wsa884x_get_temp() calls pm_runtime_resume_and_get() -- which in
wsa884x_runtime_resume() clears regcache_cache_only() and calls
regcache_sync() on an unattached slave once the autosuspend timer expires
-- and then returns -EINVAL when uncached OTP registers read as zero (d1
== d2 == 0), or caches a bogus reading from dmeas = 0 if the non-volatile
OTP registers were cached during an earlier attachment.
Checking hw_init in wsa884x_tz_get_temp() without sp_lock can also race
with wsa884x_update_status(SDW_SLAVE_UNATTACHED) and let
wsa884x_get_temp() return -EINVAL to thermal_zone_recheck(), scheduling
250 ms polling.
[ ... ]
> @@ -2194,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,
> + NULL);
[Severity: Medium]
Does passing NULL for tzp register a duplicate hwmon device for the same
sensor?
wsa884x_probe() already registers a hwmon device via
devm_hwmon_device_register_with_info(). When tzp is NULL,
thermal_zone_device_register_with_trips() calls thermal_add_hwmon_sysfs()
when CONFIG_THERMAL_HWMON is enabled, creating a second hwmon device that
causes userspace hwmon scanners to wake the codec and run the SoundWire
temperature read sequence twice per scan while seeing -ENODATA on the
thermal-hwmon bridge vs -EAGAIN on the native hwmon device. Passing a
struct thermal_zone_params with .no_hwmon = true avoids the duplicate
registration.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=8
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules
2026-12-01 12:47 ` [PATCH v4 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
@ 2026-12-01 13:16 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:16 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: OOB read in
audioreach_speaker_protection_send_chunk()
- [Medium] ASoC: qcom: audioreach: audioreach_sp_cfg_walk() rejects last
sub-word param
--
commit 7dba6d8b7f6739535dafe1bece50ca130cd713ea
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules
This commit walks the topology configuration blob of speaker protection
and VI modules and sends the parameters to the DSP in 8-byte aligned
APM_CMD_SET_CFG chunks.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 19e00563c7834..2c1ff8e65b67f 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
> @@ -1923,6 +1923,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);
[ ... ]
> +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]
Does this reject a payload-less sub-word parameter when it is the last
record in the blob?
When a sub-word parameter without a payload word is the final record
(num_words - pos == 4), avail is 0. Requiring avail != 0 here sends
execution into the else branch, where param_size > avail returns -EINVAL
and fails module setup. Checking (!avail || word[pos + 4] == iid) would
allow a trailing sub-word record without a payload word.
[ ... ]
> +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);
[Severity: Medium]
Can this fallback read past the end of module->data->data when
size % sizeof(u32) is non-zero?
In topology.c, audioreach_get_module_priv_data() allocates pdata->data[]
for only nwords = array_size / sizeof(__le32) 32-bit words while leaving
pdata->size set to the unrounded array_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 pdata slab
allocation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=15
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
2026-12-01 12:47 ` [PATCH v4 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
@ 2026-12-01 13:16 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13: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] ASoC: qcom: audioreach: stale mode read in
audioreach_speaker_protection_vi()
- [Medium] ASoC: qcom: audioreach: sp_vi_r0t0_cfg_lock held across
q6apm_send_cmd_sync()
- [Low] ASoC: qcom: audioreach: zero-channel event wipes cached R0/T0
calibration
--
commit df081ac561da2f8cde68c4521af0c5c828726b29
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 per-speaker R0/T0 calibration values from userspace or
successful VI calibration runs and sends them to the DSP via
PARAM_ID_SP_TH_VI_R0T0_CFG when configuring the VI module in normal mode.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index dd0b70013a0ec..19e00563c7834 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1606,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;
> + }
[Severity: Low]
Can an event with num_ch == 0 clear the cached sp_vi_r0t0_cfg calibration?
q6apm_vi_calibration_event() permits an event payload with zero cali_param
entries and passes num_ch = 0. In that case the channel loop does not run,
decisive and success stay true, and sp_vi_r0t0_cfg.num_ch is overwritten
with 0, causing later normal-mode runs to treat R0/T0 as unconfigured and
skip sending PARAM_ID_SP_TH_VI_R0T0_CFG.
> @@ -1750,6 +1856,70 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
>
> kfree(pkt);
>
> + if (rc)
> + return rc;
> +
> + if (sp_operation_mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
[Severity: Medium]
Should this check the local mode variable rather than re-reading
sp_operation_mode?
audioreach_speaker_protection_vi() snapshots mode =
READ_ONCE(sp_operation_mode) at entry and uses it to program
PARAM_ID_SP_VI_OP_MODE_CFG in the first q6apm_send_cmd_sync() call. If
sp_operation_mode changes while that blocking command is in flight (for
example via audioreach_trigger_sp_calibration() or the calibration
watchdog), this branch disagrees with the mode just configured on the DSP: a
normal-mode graph can skip sending PARAM_ID_SP_TH_VI_R0T0_CFG, or a
calibration-mode graph can receive normal-mode R0/T0 configuration.
> + struct apm_module_sp_th_vi_r0t0_cfg *r0t0_cfg;
> + int r0t0_sz;
> +
> + guard(mutex)(&sp_vi_r0t0_cfg_lock);
> +
> + if (!sp_vi_r0t0_cfg.num_ch)
> + return 0;
> +
> + if (sp_vi_r0t0_cfg.num_ch != num_speakers) {
> + dev_err(graph->dev,
> + "SP R0T0 is for %u speakers, graph has %u\n",
> + sp_vi_r0t0_cfg.num_ch, num_speakers);
> + return -EINVAL;
> + }
> +
> + 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);
> +
> + 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 = 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;
> + }
> +
> + rc = q6apm_send_cmd_sync(graph->apm, pkt, 0);
[Severity: Medium]
Can holding sp_vi_r0t0_cfg_lock across q6apm_send_cmd_sync() stall the
single-threaded apr->rxwq workqueue until the command times out?
All incoming GPR packets on apr->rx_list, including both
EVENT_ID_VI_PER_SPKR_CALIBRATION events and the GPR_BASIC_RSP_RESULT
response that wakes q6apm_send_cmd_sync(), are processed sequentially on the
single-threaded apr->rxwq workqueue:
CPU0 apr->rxwq
audioreach_speaker_protection_vi()
mutex_lock(&sp_vi_r0t0_cfg_lock)
q6apm_send_cmd_sync()
audioreach_send_cmd_sync()
apr_rxwq()
...
audioreach_vi_calibration_event()
mutex_lock(&sp_vi_r0t0_cfg_lock)
wait_event_timeout(apm->wait, ...) <-- waits 5s; response stuck on rxwq
Also, because sp_vi_r0t0_cfg.num_ch != num_speakers is checked only after
the first q6apm_send_cmd_sync() has already sent
PARAM_ID_SP_VI_OP_MODE_CFG, PARAM_ID_SP_VI_CHANNEL_MAP_CFG, and
PARAM_ID_SP_VI_EX_MODE_CFG, returning -EINVAL here still leaves the VI
module partly configured on the DSP. Validating and snapshotting
sp_vi_r0t0_cfg under sp_vi_r0t0_cfg_lock before sending the first command
would avoid both issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=14
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
2026-12-01 12:47 ` [PATCH v4 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
@ 2026-12-01 13:19 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:19 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: qcom: sdw: stream runtime and name leak in
qcom_snd_sdw_setup_dir()
- [Medium] ASoC: qcom: sdw: prepare failure after hw_free sets
SDW_STREAM_RELEASED
- [Low] ASoC: qcom: sdw: un-updated qcom_snd_sdw_get_stream() and
startup kernel-doc
--
commit 10caeb868a9089ee3f73cb421335ae8e657200ee
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
This commit splits the SoundWire startup, prepare, hw_free, and shutdown
helpers into per-direction helpers so that links with
multi_direction_codecs allocate and manage separate stream runtimes for
playback and capture.
> diff --git a/sound/soc/qcom/sdw.c b/sound/soc/qcom/sdw.c
> index 6576b47a4c8c3..82f1c47a788cb 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;
> +}
[ ... ]
> @@ -49,43 +95,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 qcom_snd_sdw_setup_dir() leak sruntime and sruntime->name when no
stream-valid codec DAI in dir implements .get_stream?
qcom_snd_sdw_setup_dir() allocates sruntime whenever any codec DAI is
stream-valid for dir, skips codec DAIs that are not stream-valid for dir,
and ignores -ENOTSUPP from snd_soc_dai_set_stream(). At shutdown,
sdw_find_dir_stream() only queries codec DAIs that are stream-valid for
dir via snd_soc_dai_get_stream(). On Qualcomm platforms, only the
qcom_swrm controller DAI implements .get_stream, while slave codecs only
implement .set_stream and LPASS macro or SLIMbus codec DAIs implement
neither.
If a link has no stream-valid qcom_swrm DAI in dir (for example,
va-dai-link using TX_CODEC_DMA_TX_3 with lpass_vamacro where all codec
DAIs return -ENOTSUPP, or WCD capture links referencing <&swr2 0> when
swr2 has qcom,dout-ports = <1> so qcom_swrm_register_dais() registers DAI
0 as playback-only), sdw_find_dir_stream() returns NULL and every PCM
open/close cycle leaks sruntime and sruntime->name (and on <&swr2 0>,
skipping the controller DAI also leaves its stream unset).
> @@ -93,59 +138,106 @@ int qcom_snd_sdw_startup(struct snd_pcm_substream *substream)
[ ... ]
> +/**
> + * 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)
[Severity: Low]
This isn't a bug in the active callers since this patch replaces all
in-tree calls to qcom_snd_sdw_get_stream() with sdw_find_dir_stream(),
leaving qcom_snd_sdw_get_stream() unused, but qcom_snd_sdw_get_stream()
still open-codes the codec DAI loop without checking
snd_soc_dai_stream_valid(). On a multi_direction_codecs link, calling
qcom_snd_sdw_get_stream() can return the opposite direction's stream
runtime because qcom_swrm_get_sdw_stream() ignores its direction
argument.
Also, the kernel-doc comment on qcom_snd_sdw_startup() still says that
shutdown() should call sdw_release_stream(), which would leak the
kasprintf()-allocated sr->name and any opposite-direction stream runtime
instead of releasing them via qcom_snd_sdw_shutdown().
[ ... ]
> @@ -153,15 +245,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);
[ ... ]
> @@ -197,18 +310,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;
> }
[Severity: Medium]
Can qcom_snd_sdw_prepare() fail with -EINVAL on a second
hw_params/prepare cycle of an open substream when the opposite-direction
slave is not enabled (such as when VI sense is off)?
During hw_params on a multi_direction_codecs link, even if the
opposite-direction slave codec DAI does not call sdw_stream_add_slave()
(leaving sr_opp->state unchanged), the SoundWire master DAI still calls
qcom_swrm_hw_params() -> sdw_stream_add_master() on sr_opp. When
hw_free subsequently runs on that substream, qcom_swrm_hw_free() calls
sdw_stream_remove_master(), which sets sr_opp->state to
SDW_STREAM_RELEASED:
drivers/soundwire/stream.c:sdw_stream_remove_master() {
...
if (list_empty(&stream->master_list))
stream->state = SDW_STREAM_RELEASED;
...
}
On a subsequent hw_params and prepare cycle on the same open substream
with VI sense still off, sr_opp->state remains SDW_STREAM_RELEASED.
Because qcom_snd_sdw_prepare() and qcom_snd_sdw_hw_free() only check
state != SDW_STREAM_ALLOCATED, qcom_snd_sdw_prepare() calls
sdw_prepare_stream(sr_opp) in SDW_STREAM_RELEASED state, which returns
-EINVAL and tears down the primary stream, and qcom_snd_sdw_hw_free()
similarly calls sdw_disable_stream() and sdw_deprepare_stream() on a
stream in SDW_STREAM_RELEASED state.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=4
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback
2026-12-01 12:47 ` [PATCH v4 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
@ 2026-12-01 13:23 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:23 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ASoC: qcom: audioreach: T0 read in
audioreach_vi_calibration_event() with PA on
--
commit d28517cfefa07bca8124d773d197683be8b7f061
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: audioreach: add live speaker temperature (T0) readback
This commit allows machine drivers to register speaker thermal zones in VI
channel order, exposes their live temperatures in Q6 format via a read-only
"Speaker Protection T0" control, and pairs the read T0 with R0 when speaker
calibration completes.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 42e542f305913..3974191f9c536 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1579,6 +1588,50 @@ 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 */
> +int audioreach_get_sp_vi_t0(long *vals, unsigned int count)
> +{
> + unsigned int i, n;
> +
> + 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;
> + }
> + for (; i < count; i++)
> + vals[i] = 0;
> +
> + return n;
> +}
> +EXPORT_SYMBOL_GPL(audioreach_get_sp_vi_t0);
[ ... ]
> @@ -1704,12 +1758,20 @@ 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; a zone that cannot be read gives T0 = 0.
> + */
> if (success) {
> + audioreach_get_sp_vi_t0(t0_live, num_ch);
> +
> guard(mutex)(&sp_vi_r0t0_cfg_lock);
> sp_vi_r0t0_cfg.num_ch = num_ch;
> - for (i = 0; i < num_ch; i++)
> + 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: Medium]
Can reading T0 in audioreach_vi_calibration_event() store 0.000 degC into
sp_vi_r0t0_cfg.t0_cali_q6[] on WSA884x speakers when calibration runs while
the power amplifier is active?
audioreach_vi_calibration_event() runs during active playback while the PA
is on. In wsa884x_get_temp(), hardware temperature registers cannot be read
while pa_on is true:
sound/soc/codecs/wsa884x.c:wsa884x_get_temp() {
...
if (wsa884x->pa_on) {
/*
* Reading temperature is possible only when Power Amplifier is
* off. Report last cached data if we have one, -EAGAIN otherwise.
*/
if (!wsa884x->temperature)
return -EAGAIN;
*temp = wsa884x->temperature * 1000;
return 0;
}
...
}
Because wsa884x_probe() enables its tripless thermal zone before SoundWire
attachment (while wsa884x->hw_init is false), wsa884x->temperature starts at
0 unless userspace manually reads the thermal zone while the codec is
initialized and the PA is off, and nothing primes T0 in
audioreach_arm_vi_calibration() during DAI prepare before DAPM powers on the
PA. When thermal_zone_get_temp() fails, audioreach_get_sp_vi_t0() falls back
to 0, which is a valid Q6 temperature (0.000 degC, within
SP_VI_T0_MIN_Q6..SP_VI_T0_MAX_Q6) that audioreach_speaker_protection_vi()
will then send to the DSP as the calibration reference temperature in normal
mode. In addition, t0_live[i] is not checked against
SP_VI_T0_MIN_Q6..SP_VI_T0_MAX_Q6 before storing, which would cause a later
audioreach_set_sp_vi_r0t0() restore to fail with -ERANGE if an out-of-range
value was read.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=18
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
2026-12-01 12:47 ` [PATCH v4 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
@ 2026-12-01 13:24 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:24 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ASoC: qcom: x1e80100: missing speaker map cleanup in
x1e80100_snd_init()
--
commit 3897ba8e67c4b2c7f9f0627795e0c22cc190e99c
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
This commit looks up the thermal zones of WSA884x VI DAIs on the WSA
Playback link and registers them with audioreach_sp_register_speaker_map(),
clearing the map when the link is torn down.
> diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
> index 3262fa39ceb94..9401d47024325 100644
> --- a/sound/soc/qcom/x1e80100.c
> +++ b/sound/soc/qcom/x1e80100.c
[ ... ]
> @@ -34,6 +79,8 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)
>
> switch (cpu_dai->id) {
> case WSA_CODEC_DMA_RX_0:
> + x1e80100_register_sp_speakers(rtd);
> + fallthrough;
> case WSA_CODEC_DMA_RX_1:
> /*
> * Set limit of -3 dB on Digital Volume and 0 dB on PA Volume
[Severity: Medium]
Can a failure in qcom_snd_wcd_jack_setup() at the end of x1e80100_snd_init()
leave sp_speaker_map populated with thermal_zone_device pointers that are
never cleared?
When snd_soc_link_init() returns an error in snd_soc_card_init_pcm_runtime(),
rtd->initialized is not set and snd_soc_link_exit() (x1e80100_snd_exit()) is
never called during card cleanup. If a wsa884x codec later unbinds and
unregisters its thermal zone, audioreach_get_sp_vi_t0() can dereference a
freed thermal_zone_device pointer. Calling x1e80100_register_sp_speakers()
only after qcom_snd_wcd_jack_setup() succeeds, or clearing the speaker map on
error, would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=21
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control
2026-12-01 12:47 ` [PATCH v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
@ 2026-12-01 13:27 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:27 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:
- [Medium] ASoC: qcom: audioreach: early return in
audioreach_vi_calibration_abort()
- [Medium] ASoC: qcom: audioreach: uncancelled sp_cal_watchdog work on
module removal
- [Medium] ASoC: qcom: audioreach: unsynchronized sp_operation_mode
reads across sleep
- [Low] ASoC: qcom: mode reset before cancel in
audioreach_sp_finish_calibration()
- [Low] ASoC: qcom: audioreach: commit message omits calibrate control
and abort logic
- [Low] ASoC: qcom: audioreach: stale last_state in
audioreach_vi_calibration_event()
--
commit 697d5e439356354d15a2690401fd91d27d7875e4
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: Low]
This isn't a bug, but the commit title and message only describe the
"Speaker Protection Calibration State" control and do not mention adding
the "Speaker Protection Calibrate" trigger control or the VI calibration
abort handling on graph stop and close.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 3974191f9c536..cf30c18fa25ff 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1718,6 +1736,8 @@ void audioreach_vi_calibration_event(struct device *dev,
> 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]
Does audioreach_vi_calibration_event() leave stale entries in
sp_vi_r0.last_state[] when a new run has fewer channels than a previous
run?
When the first event of a run arrives, audioreach_vi_calibration_event()
clears sp_vi_r0.r0_cali_q24, but not sp_vi_r0.last_state. The loop above
only updates slots 0 .. num_ch - 1, while audioreach_get_sp_vi_cal_state()
copies all MAX_SP_VI_SPEAKERS entries to userspace. Zeroing
sp_vi_r0.last_state alongside sp_vi_r0.r0_cali_q24 on the first event would
avoid reporting stale states for unused speaker slots.
> @@ -1780,6 +1800,46 @@ 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;
> +
> + 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]
Does returning here before audioreach_sp_finish_calibration() leave
sp_operation_mode stuck in PARAM_ID_SP_VI_OP_MODE_CALIBRATION when a run is
aborted before the first DSP event arrives?
When a graph is closed without ever starting (such as on a prepare failure
covered by q6apm_graph_close()) or stopped before the DSP sends its first
calibration event, sp_vi_r0.seen_states is all zeros. Returning early
skips audioreach_sp_finish_calibration(), leaving sp_operation_mode in
Calibration mode and sp_cal_watchdog pending for up to 60 seconds. During
that window, retrying "Speaker Protection Calibrate" fails with -EBUSY, and
any normal playback configures the DSP in Calibration mode without normal
R0/T0 thermal protection.
Calling audioreach_sp_finish_calibration() before the seen_states check
would reset the mode and cancel the watchdog while still keeping the
previous calibration result.
> 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
> @@ -1548,6 +1548,45 @@ static int audioreach_get_sp_t0(struct snd_kcontrol *kcontrol,
[ ... ]
> +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]
Can sp_cal_watchdog fire after snd-q6apm is unloaded?
Exposing audioreach_trigger_sp_calibration() through this control lets
userspace schedule the 60-second sp_cal_watchdog delayed work, but
apm_remove() does not call cancel_delayed_work_sync(&sp_cal_watchdog) on
driver teardown (and audioreach_sp_finish_calibration() only uses
cancel_delayed_work()). Unbinding and unloading snd-q6apm while the
watchdog is pending or running will execute audioreach_sp_cal_watchdog_fn()
in unmapped module memory.
[Severity: Low]
Can audioreach_sp_finish_calibration() cancel the watchdog of a newly
triggered calibration run or race with an in-flight watchdog callback?
sound/soc/qcom/qdsp6/audioreach.c:audioreach_sp_finish_calibration() {
WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
cancel_delayed_work(&sp_cal_watchdog);
}
Because sp_operation_mode is reset to NORMAL before cancel_delayed_work(),
a concurrent audioreach_put_sp_calibrate() can race as follows:
CPU0 CPU1
audioreach_vi_calibration_abort()
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
..._NORMAL)
audioreach_put_sp_calibrate()
audioreach_trigger_sp_calibration()
cmpxchg(&sp_operation_mode,
..._NORMAL,
..._CALIBRATION)
schedule_delayed_work(
&sp_cal_watchdog, ...)
cancel_delayed_work(&sp_cal_watchdog)
<-- cancels new run's watchdog
In addition, because cancel_delayed_work() does not wait for an executing
audioreach_sp_cal_watchdog_fn(), an in-flight watchdog from the old run can
cmpxchg sp_operation_mode back to NORMAL after CPU1 has armed the new run.
[Severity: Medium]
Can a concurrent sp_operation_mode change while graph setup sleeps leave
the DSP speaker protection modules inconsistently configured?
audioreach_put_sp_calibrate(), audioreach_vi_calibration_abort() and
audioreach_sp_cal_watchdog_fn() update sp_operation_mode without
serializing against graph preparation:
sound/soc/qcom/qdsp6/audioreach.c:audioreach_speaker_protection_vi() {
u32 mode = READ_ONCE(sp_operation_mode);
...
op_cfg->cfg.operation_mode = mode;
...
rc = q6apm_send_cmd_sync(graph->apm, pkt, 0);
...
if (sp_operation_mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
audioreach_speaker_protection_vi() snapshots sp_operation_mode into mode to
register events and send PARAM_ID_SP_VI_OP_MODE_CFG, then sleeps in
q6apm_send_cmd_sync(), and re-reads sp_operation_mode afterward. If
audioreach_put_sp_calibrate() switches sp_operation_mode from NORMAL to
CALIBRATION during that sleep, the VI module is placed in NORMAL mode
without calibration events registered, but the second check sees
CALIBRATION and skips sending PARAM_ID_SP_TH_VI_R0T0_CFG. Likewise,
audioreach_speaker_protection() and audioreach_speaker_protection_vi() read
sp_operation_mode independently across sleeping GPR commands, so the two
modules can be configured for different modes on the same graph.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=19
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 24/24] arm64: dts: qcom: x1e78100-t14s: add WSA speaker protection VI feedback
2026-12-01 12:47 ` [PATCH v4 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
@ 2026-12-01 13:27 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:27 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] arm64: dts: qcom: x1e78100-t14s: wsa-dai-link codec sound-dai
exceeds maxItems
--
commit 6af1c59f2e59cca09bc129347b90a78a9ba9b449
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
arm64: dts: qcom: x1e78100-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 Playback link, 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..c5fb20ef9f1ca 100644
> --- a/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
> +++ b/arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi
> @@ -477,8 +477,20 @@ cpu {
> sound-dai = <&q6apmbedai WSA_CODEC_DMA_RX_0>;
> };
>
> + /*
> + * WSA SPKR playback-side codec DAIs plus the WSA
> + * speaker-protection VI capture-side DAIs. 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 tplg handles
> + * the DSP-side pairing.
> + */
> 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>;
> };
[Severity: Low]
Does expanding sound-dai to 9 entries break dtbs_check validation against
Documentation/devicetree/bindings/sound/qcom,sm8250.yaml?
The sound node uses compatible = "qcom,x1e80100-sndcard", whose binding
caps codec sound-dai under ".*-dai-link$" at maxItems: 8.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=24
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 23/24] arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
2026-12-01 12:47 ` [PATCH v4 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
@ 2026-12-01 13:30 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:30 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] arm64: dts: qcom: mahua-t14s: wsa-dai-link codec sound-dai
exceeds maxItems 8
--
commit 3882118a6e67841f11f5957bcb7aa4ae37c14aa3
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
This commit adds the WSA8845 speaker V/I sense DAIs, SoundWire VI ports,
and the WSA macro VI capture DAI to the WSA playback DAI link on Lenovo
ThinkPad T14s Gen 7, and updates the speaker nodes to use
#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 adding 9 entries to codec/sound-dai here cause a dtbs_check schema
validation failure? The sound node uses compatible = "qcom,glymur-sndcard",
and Documentation/devicetree/bindings/sound/qcom,sm8250.yaml currently sets
maxItems: 8 on codec/sound-dai.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=23
^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v4 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
2026-12-01 12:47 ` [PATCH v4 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
@ 2026-12-01 13:31 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-12-01 13:31 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
binding maxItems
--
commit 477126efe46745458e2d4fe969c058eb7b3b6fc3
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
This commit adds the WSA8845 speaker V/I sense capture DAIs, SoundWire VI
ports, and WSA macro VI capture DAIs to the WSA Playback DAI link on
Glymur-CRD, and updates the 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>,
> + <&lpass_wsa2macro 2>;
> };
[Severity: Medium]
Should each SoundWire controller only list a single capture DAI on this link
instead of both <&swr0 12>, <&swr0 13> and <&swr3 12>, <&swr3 13>?
qcom_snd_sdw_setup_dir() attaches a single capture sdw_stream_runtime to
every capture codec DAI on the link, and a single call to
qcom_swrm_hw_params() -> qcom_swrm_stream_alloc_ports() already iterates all
slave runtimes on ctrl->bus and maps both master ports via slave->m_port_map
(just as <&swr0 0> and <&swr3 0> do for playback).
Listing two capture DAIs per SoundWire master controller runs
qcom_swrm_hw_params() -> sdw_stream_add_master() twice per bus on the same
capture stream:
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++;
}
...
}
When VISENSE Switch is disabled on a bus, wsa884x_vi_hw_params() adds no
slave ports, so num_ports is 0 and m_rt->port_list stays empty. The second
DAI on that bus (<&swr0 13> or <&swr3 13>) sees
!sdw_master_port_allocated(m_rt) still true and increments
stream->m_rt_count a second time for the same m_rt, while
sdw_stream_remove_master() in qcom_swrm_hw_free() only decrements it once.
When VISENSE Switch is enabled on only one bus (or after a
hw_params/hw_free cycle with VISENSE disabled on at least one bus),
stream->m_rt_count reaches 3 (>= bus->hw_sync_min_links), causing
sdw_bank_switch() -> sdw_transfer_defer() to fail playback prepare with
-ENOTSUPP.
[Severity: Low]
Does expanding wsa-dai-link/codec/sound-dai to 18 entries break
dtbs_check? Documentation/devicetree/bindings/sound/qcom,sm8250.yaml
(which validates qcom,glymur-sndcard) currently caps codec/sound-dai at
maxItems: 8.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=22
^ permalink raw reply [flat|nested] 40+ messages in thread
end of thread, other threads:[~2026-12-01 13:31 UTC | newest]
Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 12:47 [PATCH v4 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-12-01 13:19 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-12-01 13:03 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
2026-12-01 13:03 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-12-01 13:13 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-12-01 13:09 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-12-01 13:10 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
2026-12-01 13:12 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-12-01 13:16 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-12-01 13:16 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-12-01 13:23 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-12-01 13:27 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-12-01 13:24 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-12-01 13:31 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-12-01 13:30 ` sashiko-bot
2026-12-01 12:47 ` [PATCH v4 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
2026-12-01 13:27 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox