Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx
@ 2026-11-30 21:22 Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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 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: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH v3 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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>
---
 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 v3 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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..2af61598dd7b
--- /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 v3 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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 v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (2 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:59   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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 v3 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (3 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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 v3 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (4 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:36   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
                   ` (17 subsequent siblings)
  23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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 v3 07/24] ASoC: codecs: wsa883x: add VI sense capture DAI
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (5 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:36   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, 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 v3 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (6 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:39   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, 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 v3 09/24] ASoC: qcom: audioreach: add control link support to graphs
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (7 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:41   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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 aa1f4e296764..afa8e0159570 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 {
@@ -410,24 +431,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;
@@ -442,6 +465,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];
 
@@ -477,12 +541,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;
@@ -494,6 +562,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;
@@ -511,6 +580,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;
@@ -526,13 +596,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;
@@ -584,6 +655,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 = &params.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, &params, sg_list, num_sub_graphs);
 
 	return pkt;
diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h
index 0a50b9337738..0ea035fa630c 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -171,6 +171,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 v3 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (8 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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 afa8e0159570..fbb9e3c4b84a 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -1462,6 +1462,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)
@@ -1470,6 +1482,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)
@@ -1480,18 +1521,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;
@@ -1509,8 +1562,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;
@@ -1520,20 +1574,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 < AR_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 < AR_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;
@@ -1607,7 +1656,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);
 
@@ -1616,6 +1665,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 0ea035fa630c..9d9449062b83 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -696,6 +696,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
@@ -720,6 +722,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;
@@ -1060,6 +1114,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 v3 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (9 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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 362f30679020..09d10b005e64 100644
--- a/sound/soc/qcom/qdsp6/q6apm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
@@ -204,7 +204,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,
@@ -224,7 +225,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,
@@ -780,6 +782,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 v3 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (10 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:31   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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 fbb9e3c4b84a..2b5c083b8ae5 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;
@@ -1462,16 +1482,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,
@@ -1511,6 +1627,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)
@@ -1538,6 +1662,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 v3 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (11 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:34   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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 2b5c083b8ae5..130298a28749 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 */
@@ -1482,6 +1485,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 ||
@@ -1588,14 +1633,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,
@@ -1639,6 +1686,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;
@@ -1662,11 +1710,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. */
@@ -1690,7 +1740,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;
@@ -1781,8 +1831,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 9d9449062b83..baafd3bcd0c3 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -1114,6 +1114,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 v3 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (12 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:36   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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 130298a28749..070100627809 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)
 {
@@ -1568,6 +1586,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)
@@ -1632,6 +1730,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. */
@@ -1776,6 +1882,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 baafd3bcd0c3..713bf3ba5b6f 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -722,6 +722,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
 
@@ -1116,6 +1135,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 v3 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (13 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:41   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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 070100627809..436d33ea568e 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -1949,6 +1949,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)
@@ -2002,12 +2137,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 v3 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (14 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi

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..c07a27bdd3a2 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 v3 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (15 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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 436d33ea568e..97d8585a287b 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -2084,12 +2084,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 v3 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (16 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:39   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, 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 97d8585a287b..789f9fc3c979 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;
@@ -1605,6 +1614,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 = {};
@@ -1670,6 +1723,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;
@@ -1730,12 +1784,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 713bf3ba5b6f..fb3f2f61e2b1 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -8,6 +8,7 @@
 #include <sound/soc.h>
 struct q6apm;
 struct q6apm_graph;
+struct thermal_zone_device;
 
 /* Module IDs */
 #define MODULE_ID_WR_SHARED_MEM_EP	0x07001000
@@ -1137,6 +1138,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 09d10b005e64..731828fa7d95 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"
 
 #define DRV_NAME "q6apm-dai"
@@ -1322,8 +1323,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 c07a27bdd3a2..0e28c68c735d 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 v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (17 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:47   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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 789f9fc3c979..0a6c881f5cd4 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;
@@ -1658,6 +1661,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 = {};
@@ -1744,6 +1762,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))
@@ -1806,6 +1826,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 fb3f2f61e2b1..4db93c7f8829 100644
--- a/sound/soc/qcom/qdsp6/audioreach.h
+++ b/sound/soc/qcom/qdsp6/audioreach.h
@@ -1141,10 +1141,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 0e28c68c735d..a19efbb889a8 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 v3 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (18 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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 v3 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (19 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:41   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 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-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel

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 v3 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (20 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:43   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
  2026-11-30 21:22 ` [PATCH v3 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
  23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, Ravi Hothi, 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 cdc24b273877..8da2d51127c8 100644
--- a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
+++ b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
@@ -255,10 +255,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 {
@@ -810,7 +816,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_l15b0>;
 		vdd-io-supply = <&vreg_l18b0>;
@@ -822,7 +828,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_l15b0>;
 		vdd-io-supply = <&vreg_l18b0>;
@@ -838,7 +844,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_l15b0>;
 		vdd-io-supply = <&vreg_l18b0>;
@@ -850,7 +856,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_l15b0>;
 		vdd-io-supply = <&vreg_l18b0>;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v3 23/24] arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (21 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:43   ` sashiko-bot
  2026-11-30 21:22 ` [PATCH v3 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
  23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, 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 34ec5a52aa02..627c665eef43 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
@@ -267,8 +267,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 {
@@ -775,7 +778,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_l15b0>;
 		vdd-io-supply = <&vreg_l18b0>;
@@ -787,7 +790,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_l15b0>;
 		vdd-io-supply = <&vreg_l18b0>;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v3 24/24] arm64: dts: qcom: x1e78100-t14s: add WSA speaker protection VI feedback
  2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
                   ` (22 preceding siblings ...)
  2026-11-30 21:22 ` [PATCH v3 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
@ 2026-11-30 21:22 ` Srinivas Kandagatla
  2026-11-30 21:45   ` sashiko-bot
  23 siblings, 1 reply; 40+ messages in thread
From: Srinivas Kandagatla @ 2026-11-30 21:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Ravi Hothi, Jaroslav Kysela, Liam Girdwood,
	Takashi Iwai, Pierre-Louis Bossart, Kuninori Morimoto,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-sound, linux-arm-msm,
	devicetree, alsa-devel, linux-kernel, 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 1536ad8d4793..2c7166e15097 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 {
@@ -1452,7 +1464,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>;
@@ -1464,7 +1476,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 v3 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker
  2026-11-30 21:22 ` [PATCH v3 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
@ 2026-11-30 21:31   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21: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] ASoC: qcom: audioreach: false success on num_ch == 0 in
  audioreach_vi_calibration_event()
- [Low] ASoC: qcom: audioreach: negative Q24 misformatting in
  sp_vi_q24_to_int_frac()
--

commit d2345fffe188cfdf8d7406ef014a481b337ee1a8
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
is recorded when all speakers reach a terminal state.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index fbb9e3c4b84ae..2b5c083b8ae56 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1462,16 +1482,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() misformat negative Q24 values?  For a negative
s32 with a non-zero fractional part, val >> 24 rounds toward negative
infinity and val & 0xffffff extracts the positive two's-complement offset
above that floor, so -0.250 ohms (-0x00400000) is split into -1 and 750 and
logged as -1.750 ohms when an out-of-range R0 is reported on
VI_CALIBRATION_STATE_FAILED.

> +
> +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]
Can an event with num_ch == 0 wipe the cached R0 values and prematurely
finish an armed run as SP_VI_CALI_SUCCESS?

q6apm_vi_calibration_event() clamps num_ch from above to MAX_SP_VI_SPEAKERS
but does not reject num_ch == 0 when cali->num_ch is 0 or the payload has
no cali_param entries.  Because decisive and success start as true, a call
with num_ch == 0 clears sp_vi_r0.r0_cali_q24, skips the per-channel loop,
disarms sp_vi_r0.armed so later events from the run are ignored, and
records SP_VI_CALI_SUCCESS with sp_vi_r0.num_ch = 0.  Guarding against
!num_ch || num_ch > MAX_SP_VI_SPEAKERS at the top of
audioreach_vi_calibration_event() would also protect the fixed-size
sp_vi_r0 arrays from direct callers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=12

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
  2026-11-30 21:22 ` [PATCH v3 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
@ 2026-11-30 21:34   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:34 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [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 be3dacbf17b1806a48e11abe0048fb2d600d3603
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>

ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure

This commit adds internal speaker protection operation mode state, an
edge-triggered calibration start helper with a 60-second watchdog, and
automatic reset to Normal mode on calibration completion.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 2b5c083b8ae56..130298a287496 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1482,6 +1485,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 audioreach_sp_finish_calibration() cancel or abort a newly triggered
calibration run?

Because sp_operation_mode is reset to PARAM_ID_SP_VI_OP_MODE_NORMAL
before cancel_delayed_work(&sp_cal_watchdog), a concurrent
audioreach_trigger_sp_calibration() can re-arm sp_operation_mode in the
window between the two statements:

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 new run's watchdog

If the new run is never followed by playback, sp_operation_mode stays in
PARAM_ID_SP_VI_OP_MODE_CALIBRATION permanently and every future trigger
returns -EBUSY.  Similarly, because cancel_delayed_work() is not
synchronous, an already-dequeued audioreach_sp_cal_watchdog_fn() from
the old run can execute its cmpxchg() after CPU1 re-triggers and flip
the new run back to Normal immediately.

> +
> +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]
Can sp_cal_watchdog remain queued on system_percpu_wq 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 q6apm_audio_remove() calls
cancel_delayed_work_sync(&sp_cal_watchdog).  Unloading the module while
the 60-second watchdog is pending leaves the timer and work item active
in freed module memory, causing a use-after-free when the timer fires.

[ ... ]

> @@ -1639,6 +1686,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;
> @@ -1662,11 +1710,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]
Can sp_operation_mode and sp_vi_r0.armed get out of sync when the
watchdog fires or when VI module setup fails?

If audioreach_sp_cal_watchdog_fn() fires while a calibration stream is
already armed (for example, playback starts near the end of the
60-second window and runs past it), the watchdog resets
sp_operation_mode to Normal without clearing sp_vi_r0.armed.  A second
audioreach_trigger_sp_calibration() call can then succeed while the
first run is still active on the DSP, and when the first run reaches a
terminal event, audioreach_vi_calibration_event() calls
audioreach_sp_finish_calibration() and silently disarms the second
trigger.

In addition, if audioreach_register_events(),
audioreach_alloc_apm_cmd_pkt(), or q6apm_send_cmd_sync() fails in
audioreach_speaker_protection_vi(), the error path returns with
sp_vi_r0.armed still set to true.

[ ... ]

> @@ -1781,8 +1831,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);

[Severity: Medium]
Can MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI be
configured with different operation modes during the same graph setup?

q6apm_graph_media_format_pcm() iterates over the modules in a graph and
sleeps in q6apm_send_cmd_sync() for each one.  Because
audioreach_speaker_protection() and audioreach_speaker_protection_vi()
each do their own unlocked READ_ONCE(sp_operation_mode), a concurrent
audioreach_trigger_sp_calibration() or watchdog timeout between the two
calls configures one module in Normal mode and the other in Calibration
mode.  That either causes the DSP to fail calibration with
VI_CALIBRATION_STATE_INCORRECT_OP_MODE or leaves MODULE_ID_SPEAKER_PROTECTION
in Calibration mode while VI runs in Normal mode without arming
sp_vi_r0.armed or registering calibration events.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=13

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
  2026-11-30 21:22 ` [PATCH v3 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
@ 2026-11-30 21:36   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:36 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: inconsistent mode check 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 VI event wipes cached R0/T0
  in audioreach_vi_calibration_event()
--

commit b2b7f0ee63ba7619972f12d82d084b408eebb459
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 values from userspace or successful VI
calibration runs and sends them via PARAM_ID_SP_TH_VI_R0T0_CFG when
configuring the VI module in normal operation mode.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 130298a287496..0701006278094 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c

[ ... ]

> @@ -1632,6 +1730,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. */

[Severity: Low]
Can a zero-channel calibration event wipe out a valid cached
sp_vi_r0t0_cfg?

q6apm_vi_calibration_event() allows payloads with zero cali_param entries
or cali->num_ch == 0 and passes num_ch == 0 to
audioreach_vi_calibration_event():

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);
}

When num_ch is 0, the per-channel loop does not run, leaving both decisive
and success true.  That overwrites sp_vi_r0t0_cfg.num_ch with 0, causing
later normal-mode setups to treat R0/T0 as unconfigured and silently skip
sending PARAM_ID_SP_TH_VI_R0T0_CFG.

> @@ -1776,6 +1882,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 configure
PARAM_ID_SP_VI_OP_MODE_CFG before blocking in q6apm_send_cmd_sync().  If
audioreach_trigger_sp_calibration() or the calibration watchdog changes
sp_operation_mode while that first IPC is in flight, this second check acts
on a different mode than the one just programmed into the DSP VI module,
either skipping PARAM_ID_SP_TH_VI_R0T0_CFG for a module configured in
normal mode or sending normal-mode R0/T0 to a module configured for
calibration.

> +		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 APR
RX workqueue until the command times out?

All incoming GPR packets on apr->rx_list are dispatched sequentially by a
single work item on apr->rxwq, including both EVENT_ID_VI_PER_SPKR_CALIBRATION
events and the command response that wakes q6apm_send_cmd_sync():

CPU0                                  kworker (apr->rxwq)
audioreach_speaker_protection_vi()
  mutex_lock(&sp_vi_r0t0_cfg_lock)
  q6apm_send_cmd_sync()
    wait_event_timeout(apm->wait, ...)
                                      apr_rxwq()
                                        ...
                                          audioreach_vi_calibration_event()
                                            mutex_lock(&sp_vi_r0t0_cfg_lock)
                                            <-- blocks apr->rxwq; cannot
                                                deliver apm->wait response

If a decisive calibration event arrives ahead of the APM_CMD_SET_CFG
response (for example, if the calibration watchdog resets sp_operation_mode
to normal while a calibration run is finishing), apr->rxwq blocks on
sp_vi_r0t0_cfg_lock and q6apm_send_cmd_sync() fails with -ETIMEDOUT after 5
seconds.  Snapshotting sp_vi_r0t0_cfg into a local copy under
sp_vi_r0t0_cfg_lock before sending the packet avoids holding the mutex
across the IPC.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=14

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI
  2026-11-30 21:22 ` [PATCH v3 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
@ 2026-11-30 21:36   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:36 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 2fa2f14769a60d3a9ba8b264a65cae8eba72c5d8
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>

ASoC: codecs: wsa884x: add VI sense capture DAI

This commit moves the WSA884x VI sense port from the sink port list to a
source port with its own capture DAI, ops, and SoundWire stream runtime.

> 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 early when port_enable[WSA884X_PORT_VISENSE] is false
leave vi_sruntime unconfigured and break stream preparation?

sdw_stream_add_slave() is what transitions a SoundWire stream runtime to
SDW_STREAM_CONFIGURED (note that wsa884x_hw_params() calls it even when
active_ports is 0).  When the VISENSE Switch control is off,
qcom_swrm_hw_params() still adds the master runtime to vi_sruntime, and a
subsequent hw_free transitions vi_sruntime->state to SDW_STREAM_RELEASED
in sdw_stream_remove_master().  If hw_params and prepare then run again
on that substream while VISENSE is still off, wsa884x_vi_hw_params()
leaves vi_sruntime in SDW_STREAM_RELEASED:

sound/soc/qcom/sdw.c:qcom_snd_sdw_prepare() {
    ...
	if (rtd->dai_link->multi_direction_codecs) {
		struct sdw_stream_runtime *sr_opp =
			sruntime[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);
    ...
}

Because sr_opp->state is SDW_STREAM_RELEASED rather than
SDW_STREAM_ALLOCATED (or on a direct capture substream where the primary
direction is prepared unconditionally), qcom_snd_sdw_prepare_dir() calls
sdw_prepare_stream(), which rejects the unconfigured state with -EINVAL
and tears down playback.  In addition, if hw_params is called again
without an intervening hw_free after VISENSE Switch is turned from on to
off, returning 0 early leaves the previously added slave runtime and
VISENSE port attached to vi_sruntime.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=6

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 07/24] ASoC: codecs: wsa883x: add VI sense capture DAI
  2026-11-30 21:22 ` [PATCH v3 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
@ 2026-11-30 21:36   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:36 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 da1918f2dca4e2889b9a754a96cbf9f3750c03ce
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 runtime, and implements a bus_config
callback for WSA883x.

> 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() return early when
wsa883x->port_enable[WSA883X_PORT_VISENSE] is false, as
wsa884x_vi_hw_params() does?

Because wsa883x_hw_params() now skips WSA883X_PORT_VISENSE, nothing checks
port_enable[WSA883X_PORT_VISENSE] during stream setup.  The "VISENSE
Switch" mixer control becomes a no-op, and sdw_stream_add_slave() always
registers the VISENSE port and transitions vi_sruntime out of
SDW_STREAM_ALLOCATED, causing qcom_snd_sdw_prepare() to prepare and enable
the VI capture stream on the SoundWire bus even when VI sensing is turned
off.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=7

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback
  2026-11-30 21:22 ` [PATCH v3 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
@ 2026-11-30 21:39   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:39 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 1ea299adc65629d4c142c003f2e13f6cd633aa9e
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 a read-only "Speaker Protection T0" mixer control,
and records T0 alongside R0 when speaker protection VI calibration
completes.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 97d8585a287ba..789f9fc3c9795 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c

[ ... ]

> @@ -1730,12 +1784,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() record 0.000 degC as
sp_vi_r0t0_cfg.t0_cali_q6[] on WSA884x speaker amplifiers?

Calibration events arrive during active playback while the speaker PA is
on.  WSA884x cannot measure die temperature while pa_on is true, and its
initial thermal zone read during probe happens before SoundWire hardware
initialization sets hw_init:

sound/soc/codecs/wsa884x.c:wsa884x_get_temp() {
    ...
	if (wsa884x->pa_on) {
		if (!wsa884x->temperature)
			return -EAGAIN;
		*temp = wsa884x->temperature * 1000;
		return 0;
	}
    ...
}

Unless userspace has read the thermal zone while the codec was initialized
and idle, thermal_zone_get_temp() fails here and audioreach_get_sp_vi_t0()
returns 0.  Because 0 in Q6 format is 0.000 degC, which is within
[SP_VI_T0_MIN_Q6, SP_VI_T0_MAX_Q6], later normal-mode playback sends 0.000
degC to the DSP as the calibrated reference temperature.

Sampling the thermal zones when arming calibration in DAI prepare (before
DAPM powers up the PA) would ensure wsa884x->temperature is populated
while the PA is still off.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=18

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone
  2026-11-30 21:22 ` [PATCH v3 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
@ 2026-11-30 21:39   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:39 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: missing hw_init check in
  wsa884x_get_temp()
- [Medium] ASoC: codecs: wsa884x: duplicate hwmon registration in
  wsa884x_probe()
- [Low] ASoC: codecs: wsa884x: 0 degC cache sentinel collision in
  wsa884x_get_temp()
--

commit eeb28091eb55a0c81338c5cbd1905079de782166
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 or THERMAL_TEMP_INVALID when a
valid temperature reading is not available.

> 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 treat a valid cached 0 degC reading as
uninitialised?

wsa884x_get_temp() accepts measured temperatures in
[WSA884X_LOW_TEMP_THRESHOLD, WSA884X_HIGH_TEMP_THRESHOLD] ([-10, 150]
degC), so a 0 degC measurement cached before the PA turns on will make
subsequent reads while pa_on is true fail with -EAGAIN for hwmon and
THERMAL_TEMP_INVALID for the thermal zone.  Also, because
wsa884x->temperature is an unsigned int, caching a valid negative reading
in [-10, -1] degC wraps to a large unsigned value before multiplying by
1000 and widening to 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);

[Severity: Medium]
Should the !wsa884x->hw_init check live inside wsa884x_get_temp() under
wsa884x->sp_lock 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 wsa884x->hw_init.  Reading hwmon while hw_init is false
calls pm_runtime_resume_and_get() (which in wsa884x_runtime_resume()
disables regcache_cache_only() and runs regcache_sync() on an unattached
SoundWire slave if the device has runtime-suspended), attempts register
accesses, and either 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 wsa884x->hw_init outside sp_lock also races with
wsa884x_update_status() clearing hw_init on SDW_SLAVE_UNATTACHED, allowing
wsa884x_get_temp() to return -EINVAL to the thermal core.

[ ... ]
> @@ -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 this
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 for
the same die temperature sensor that wakes the codec a second time on
hwmon scans and returns -ENODATA instead of -EAGAIN when no reading is
available.  Passing a struct thermal_zone_params with .no_hwmon = true
avoids the duplicate registration.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=8

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules
  2026-11-30 21:22 ` [PATCH v3 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
@ 2026-11-30 21:41   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:41 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() fails on
  last sub-word param
--

commit a2ac38e54e671bee64442aeeeeb762fae56eebb2
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>

ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules

This commit parses static topology configuration blobs for the speaker
protection modules into 8-byte-padded parameter chunks and sends them to
the DSP via APM_CMD_SET_CFG commands before enabling the modules.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 0701006278094..436d33ea568e3 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c

[ ... ]

> +static int audioreach_sp_cfg_walk(const u32 *word, u32 num_words, u32 iid,
> +				  u32 first, u32 *next, u8 *dst, u32 max_bytes)
> +{
> +	u32 pos = first, bytes = 0;
> +
> +	while (pos < num_words) {
> +		u32 param_size, payload_words, avail, rec_bytes;
> +
> +		if (word[pos] != iid || num_words - pos < 4)
> +			return -EINVAL;
> +
> +		param_size = word[pos + 2];
> +		avail = (num_words - pos - 4) * sizeof(u32);
> +		if (param_size < sizeof(u32) && avail && word[pos + 4] == iid) {
> +			payload_words = 0;
> +		} else {
> +			if (param_size > avail)
> +				return -EINVAL;
> +			payload_words = DIV_ROUND_UP(param_size, sizeof(u32));
> +		}

[Severity: Medium]
Does audioreach_sp_cfg_walk() reject a blob whose last parameter is smaller
than a word and has no payload word?

When such a record is at the end of the blob (pos + 4 == num_words), avail
is 0, so the check enters the else branch and fails param_size > avail with
-EINVAL.  Checking (!avail || word[pos + 4] == iid) would handle the
trailing record as well.

[ ... ]

> +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 read past the end of module->data->data when size is not a
multiple of sizeof(u32)?

audioreach_get_module_priv_data() rounds the allocation down to full
32-bit words while keeping pdata->size unrounded:

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));
    ...
}

When size % sizeof(u32) is non-zero (including 1 <= size <= 3 where
num_words is 0), passing size to audioreach_speaker_protection_send_chunk()
causes memcpy() to read 1 to 3 bytes past the end of the module->data slab
buffer and send them to the DSP.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=15

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 09/24] ASoC: qcom: audioreach: add control link support to graphs
  2026-11-30 21:22 ` [PATCH v3 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
@ 2026-11-30 21:41   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:41 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 79d56824195656faded237187b75357136cd2fac
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 topology into a
per-subgraph list and appends deduplicated control link configurations to
the APM_CMD_GRAPH_OPEN command packet.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index aa1f4e2967647..afa8e0159570e 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;

[ ... ]

> @@ -442,6 +465,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]);
> +		}

[ ... ]

> +	/* The dedupe above may have packed fewer links */
> +	cl_data->num_ctrl_link_cfg = nlink;
>  }

[Severity: High]
Does indexing cl_data->link_obj[nlink++] at a fixed MAX_INTENTS stride
misalign subsequent control link entries and leave
cl_data->param_data.param_size mismatched?

struct apm_control_link_obj embeds u32 intent_id_list[MAX_INTENTS], giving
each link_obj[] element a constant 48-byte stride, whereas
intent_data.prop_size is computed from the packed clink_obj->num_intents
count.  When a link defines fewer than MAX_INTENTS intents and multiple
links are present, the DSP advances past intent_data by prop_size bytes
and reads the trailing zero-padded intent_id_list[] slots as the header of
the next control link, causing GRAPH_OPEN to be rejected.

In addition, audioreach_alloc_graph_pkt() sets param_data->param_size from
the pre-deduplication num_control_links count and fixed MAX_INTENTS size,
and audioreach_populate_graph() updates cl_data->num_ctrl_link_cfg = nlink
without updating cl_data->param_data.param_size.

> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index aa2ab2b058d0f..5dd7f2c51d5cf 100644
> --- a/sound/soc/qcom/qdsp6/topology.c
> +++ b/sound/soc/qcom/qdsp6/topology.c

[ ... ]

> @@ -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)) {

[ ... ]

> +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 audioreach_parse_cl_tokens() underflow when cl_array->num_elems is 0
or spin forever when cl_array->size is 0?

le32_to_cpu(cl_array->num_elems) returns an unsigned 32-bit integer, so
when num_elems is 0, subtracting 1 wraps to U32_MAX and both while loops
read past the end of the topology buffer.  Also, unlike
audioreach_get_module_priv_data(), the outer loop does not check for a
zero cl_array->size before advancing sz, so a zero-sized vendor array will
loop indefinitely.  Finally, if audioreach_tplg_alloc_control_link()
returns an ERR_PTR, the error is silently dropped 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]
If audioreach_parse_cont_tokens(), audioreach_parse_common_tokens() or
audioreach_get_module_priv_data() fails after audioreach_parse_cl_tokens()
has allocated a control link, does this leak the link and its entry in
apm->control_links_idr?

audioreach_widget_load_module_common() returns before setting
dobj->private = mod, so audioreach_widget_unload() bails out at if (!mod)
return 0; without freeing sg->control_link_list or removing link->id from
apm->control_links_idr, which also blocks later topology reloads using the
same control link ID.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=9

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
  2026-11-30 21:22 ` [PATCH v3 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
@ 2026-11-30 21:41   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:41 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 221f37a103220ac379312f74ed2387dafb0f054f
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 the WSA884x VI DAIs on the
WSA_CODEC_DMA_RX_0 link and registers them with
audioreach_sp_register_speaker_map(), clearing the map on link exit.

> 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]
Does this leave thermal_zone_device pointers registered in sp_speaker_map
if qcom_snd_wcd_jack_setup() fails at the end of x1e80100_snd_init()?

When snd_soc_link_init() returns an error, snd_soc_card_init_pcm_runtime()
returns before setting rtd->initialized, so x1e80100_snd_exit() is not
called during card teardown to clear the map. If a wsa884x codec later
unbinds and unregisters its thermal zone, audioreach_get_sp_vi_t0() can
dereference a freed thermal_zone_device pointer.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=21

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 23/24] arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback
  2026-11-30 21:22 ` [PATCH v3 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
@ 2026-11-30 21:43   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:43 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 3d6a43340a840399f3b68292ad81d695df18d252
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

arm64: dts: qcom: mahua-t14s: add WSA speaker protection VI feedback

This commit adds the WSA8845 V/I sense DAIs, SoundWire VI ports, and WSA
macro VI capture DAI to the WSA Playback link on Lenovo ThinkPad T14s
Gen 7 for speaker protection.

> 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 2d6578edcc823..81799b38711ad 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
> @@ -254,8 +254,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 expanding wsa-dai-link/codec/sound-dai to 9 entries fail dtbs_check?
The sound node uses compatible = "qcom,glymur-sndcard", and
Documentation/devicetree/bindings/sound/qcom,sm8250.yaml limits
codec/sound-dai under ".*-dai-link$" to maxItems: 8.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=23

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback
  2026-11-30 21:22 ` [PATCH v3 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
@ 2026-11-30 21:43   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:43 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: glymur-crd wsa-dai-link sound-dai exceeds
  binding maxItems
--

commit 2a778915dc5bdc63d8e8fc8b3e7d72d6309b53d4
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>

arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback

This commit adds the WSA8845 V/I sense DAIs, SoundWire VI ports, and WSA
macro VI capture DAIs to the WSA Playback link in glymur-crd.dtsi, and
sets #sound-dai-cells to 1 on the four WSA8845 speaker nodes.

> diff --git a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
> index 3a9cd5f3ec2b8..8b477df6901a0 100644
> --- a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
> +++ b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
> @@ -252,10 +252,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: Low]
Does expanding codec sound-dai to 18 entries cause dtbs_check to fail
against Documentation/devicetree/bindings/sound/qcom,sm8250.yaml?

The sound node uses compatible "qcom,glymur-sndcard", whose binding
schema constrains codec/sound-dai under .*-dai-link$ to maxItems: 8.
Should Documentation/devicetree/bindings/sound/qcom,sm8250.yaml be
updated to raise maxItems to 18?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=22

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 24/24] arm64: dts: qcom: x1e78100-t14s: add WSA speaker protection VI feedback
  2026-11-30 21:22 ` [PATCH v3 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
@ 2026-11-30 21:45   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:45 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 f59e719ef83cc20d4f1e115929999321b25a2b79
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 the
WSA macro VI capture DAI to the WSA playback link for speaker protection on
the Lenovo ThinkPad T14s.

> 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 1536ad8d47933..2c7166e15097d 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 against
Documentation/devicetree/bindings/sound/qcom,sm8250.yaml?  That binding
validates qcom,x1e80100-sndcard and caps codec sound-dai at maxItems: 8.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=24

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control
  2026-11-30 21:22 ` [PATCH v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
@ 2026-11-30 21:47   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:47 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-sound, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] ASoC: qcom: audioreach: early return in
  audioreach_vi_calibration_abort()
- [Medium] ASoC: qcom: audioreach: unsynchronized sp_operation_mode
  reads across sleep
- [Medium] ASoC: qcom: audioreach: uncancelled sp_cal_watchdog work on
  module removal
- [Low] ASoC: qcom: mode reset before cancel in
  audioreach_sp_finish_calibration()
- [Low] ASoC: qcom: audioreach: commit message omits calibrate control
  and abort logic
--

commit c58591aa133913ac270206bd175386cd596ee808
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 message only mentions the read-only
"Speaker Protection Calibration State" control while the patch also adds
the "Speaker Protection Calibrate" trigger control and 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 789f9fc3c9795..0a6c881f5cd46 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1806,6 +1826,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 calling audioreach_sp_finish_calibration()
leave sp_operation_mode stuck in PARAM_ID_SP_VI_OP_MODE_CALIBRATION when
a graph is closed or stopped before the first DSP event arrives?

When q6apm_graph_close() aborts an armed graph that was never started
(or q6apm_graph_stop() runs before any EVENT_ID_VI_PER_SPKR_CALIBRATION
event is received), sp_vi_r0.seen_states is still all zeros.  Returning
after clearing sp_vi_r0.armed skips audioreach_sp_finish_calibration(),
so sp_operation_mode remains in calibration mode until the 60-second
sp_cal_watchdog expires: retries of "Speaker Protection Calibrate" fail
with -EBUSY, and any normal playback started in the meantime configures
the DSP in calibration mode without sending PARAM_ID_SP_TH_VI_R0T0_CFG.

Calling audioreach_sp_finish_calibration() before returning when
seen_states is all zeros avoids leaving calibration mode active.

> +
> +	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();
> +}

[Severity: Low]
Can audioreach_sp_finish_calibration() cancel the watchdog of a newly
triggered calibration run if userspace writes to "Speaker Protection
Calibrate" concurrently?

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()
runs, a concurrent audioreach_put_sp_calibrate() call can pass the
cmpxchg() in audioreach_trigger_sp_calibration() and schedule
sp_cal_watchdog, only for the finishing context to cancel it:

CPU0                                  CPU1
audioreach_sp_finish_calibration()
  WRITE_ONCE(sp_operation_mode,
             ..._NORMAL)
                                      audioreach_put_sp_calibrate()
                                        audioreach_trigger_sp_calibration()
                                          cmpxchg(&sp_operation_mode, ...)
                                          schedule_delayed_work(
                                            &sp_cal_watchdog, ...)
  cancel_delayed_work(&sp_cal_watchdog)
    <-- cancels new run's watchdog

Also, because cancel_delayed_work() does not wait for an in-flight
audioreach_sp_cal_watchdog_fn() callback, an expiring watchdog from the
previous run can execute its cmpxchg() right after CPU1 re-arms
sp_operation_mode and reset the new run back to NORMAL.

> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index 0e28c68c735d2..a19efbb889a8e 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 toggling sp_operation_mode from userspace while
q6apm_graph_media_format_pcm() is sleeping in synchronous GPR commands
configure the speaker protection modules inconsistently?

In audioreach_speaker_protection_vi(), sp_operation_mode is snapshotted
into mode at function entry, but re-read from the global variable after
q6apm_send_cmd_sync() sleeps:

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) {
		...
}

If audioreach_put_sp_calibrate() flips sp_operation_mode from NORMAL to
CALIBRATION while q6apm_send_cmd_sync() is waiting, the DSP receives
NORMAL in PARAM_ID_SP_VI_OP_MODE_CFG (without calibration events
registered), while the post-sleep check sees CALIBRATION and skips
sending PARAM_ID_SP_TH_VI_R0T0_CFG.  Similarly, because
q6apm_graph_media_format_pcm() calls audioreach_speaker_protection() and
audioreach_speaker_protection_vi() across sleeping GPR commands without
a shared mode snapshot, MODULE_ID_SPEAKER_PROTECTION and
MODULE_ID_SPEAKER_PROTECTION_VI can be configured in different modes for
the same graph.

> @@ -1557,6 +1596,30 @@ static const struct snd_kcontrol_new audioreach_sp_telemetry_controls[] = {
[ ... ]
> +	{
> +		/*
> +		 * Write-only edge trigger.  Writing 1 arms a calibration run
> +		 * for the next (or current) WSA playback graph; the mode
> +		 * returns to Normal on its own once the DSP reports terminal
> +		 * state, on graph abort, or on the watchdog timeout.
> +		 */
> +		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
> +		.name	= "Speaker Protection Calibrate",
> +		.access	= SNDRV_CTL_ELEM_ACCESS_READWRITE |
> +			  SNDRV_CTL_ELEM_ACCESS_VOLATILE,
> +		.info	= audioreach_info_sp_calibrate,
> +		.get	= audioreach_get_sp_calibrate,
> +		.put	= audioreach_put_sp_calibrate,
> +	},
>  };

[Severity: Medium]
Can unloading snd-q6apm after arming "Speaker Protection Calibrate"
cause a use-after-free when sp_cal_watchdog fires?

Writing 1 to this control schedules the static 60-second sp_cal_watchdog
delayed work in audioreach_trigger_sp_calibration(), but neither
apm_remove() nor module teardown calls
cancel_delayed_work_sync(&sp_cal_watchdog).  If snd-q6apm is unloaded
while the watchdog timer is still pending or its work callback is in
flight, audioreach_sp_cal_watchdog_fn() will execute after the module
text and data have been unmapped.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=19

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links
  2026-11-30 21:22 ` [PATCH v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
@ 2026-11-30 21:59   ` sashiko-bot
  0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-30 21:59 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 a22b440aefca0499037c2fa2afd6614e48af6f03
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links

This commit splits SoundWire stream startup, prepare, hw_free, and shutdown
into per-direction helpers so that links with multi_direction_codecs
allocate and manage a separate sdw_stream_runtime for each direction.

> 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 none
of the stream-valid codec DAIs in dir implement .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,
qcom_snd_sdw_shutdown() relies on sdw_find_dir_stream(rtd, dir) to find
and free sruntime, which only queries stream-valid codec DAIs via
snd_soc_dai_get_stream().

On Qualcomm platforms, only the qcom_swrm master DAI implements
.get_stream; slave codecs only implement .set_stream, and LPASS macro
codec DAIs return -ENOTSUPP.  On links where no codec DAI in dir supports
SoundWire streams (such as TX_CODEC_DMA_TX_3 with lpass_vamacro on
va-dai-link), or on WCD capture links where the swr master DAI is
registered as playback-only (such as <&swr2 0> when qcom,dout-ports = <1>
on sm8650 and sm8750) and is skipped by snd_soc_dai_stream_valid(),
sdw_find_dir_stream() returns NULL and leaks sruntime and sruntime->name
on every open/close cycle (while also leaving the stream unset on
<&swr2 0>).

> @@ -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
> + */

[Severity: Low]
This isn't a bug, but this patch replaces all in-tree callers of
qcom_snd_sdw_get_stream() with sdw_find_dir_stream(), leaving the
exported qcom_snd_sdw_get_stream() unused and still open-coding the
codec DAI loop without checking snd_soc_dai_stream_valid() (which can
return the wrong direction's stream on a multi_direction_codecs link
because qcom_swrm_get_sdw_stream() ignores its direction argument).
Also, the kernel-doc above still tells callers to use
sdw_release_stream() in shutdown() instead of qcom_snd_sdw_shutdown(),
which would leak sr->name and the opposite-direction stream.

[ ... ]

> @@ -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);

[ ... ]

> @@ -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);

[Severity: Medium]
Can qcom_snd_sdw_prepare() fail with -EINVAL on a second hw_params/prepare
cycle when no slave registers on sr_opp?

During hw_params on a multi_direction_codecs link, qcom_swrm_hw_params()
adds the master runtime to sr_opp->master_list even when the opposite-
direction slave (such as VI sense) is off and does not call
sdw_stream_add_slave().  When hw_free later runs on that open 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;
    ...
}

If another hw_params and prepare cycle runs on the same open substream
while VI sense is still off, sr_opp->state remains SDW_STREAM_RELEASED.
Both qcom_snd_sdw_prepare() and qcom_snd_sdw_hw_free() only check
state != SDW_STREAM_ALLOCATED, so qcom_snd_sdw_prepare() calls
sdw_prepare_stream(sr_opp) in SDW_STREAM_RELEASED state, which returns
-EINVAL and tears down the primary stream.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com?part=4

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2026-11-30 21:59 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 21:22 [PATCH v3 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-11-30 21:59   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-11-30 21:36   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
2026-11-30 21:36   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-11-30 21:39   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-11-30 21:41   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-11-30 21:31   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
2026-11-30 21:34   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-11-30 21:36   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-11-30 21:41   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-11-30 21:39   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-11-30 21:47   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-11-30 21:22 ` [PATCH v3 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-11-30 21:41   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-11-30 21:43   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-11-30 21:43   ` sashiko-bot
2026-11-30 21:22 ` [PATCH v3 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
2026-11-30 21:45   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox