[PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection

From: Srinivas Kandagatla

Date: Fri Dec 04 2026 - 06:33:01 EST


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@xxxxxxxxxxxxxxxx>
---
sound/soc/qcom/qdsp6/audioreach.c | 13 +++----
sound/soc/qcom/x1e80100.c | 62 ++++++++++++++++++++++++++++++-
2 files changed, 67 insertions(+), 8 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index 166ce59347f8..cf30c18fa25f 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -1731,7 +1731,6 @@ void audioreach_vi_calibration_event(struct device *dev,
sp_vi_r0.state = SP_VI_CALI_RUNNING;
sp_vi_r0.num_ch = 0;
memset(sp_vi_r0.r0_cali_q24, 0, sizeof(sp_vi_r0.r0_cali_q24));
- memset(sp_vi_r0.last_state, 0, sizeof(sp_vi_r0.last_state));
}

for (i = 0; i < num_ch; i++) {
@@ -1806,9 +1805,6 @@ void audioreach_vi_calibration_abort(struct device *dev)
{
unsigned int i;

- /* Back to Normal before anything else, so a racing trigger is clean */
- audioreach_sp_finish_calibration();
-
guard(mutex)(&sp_vi_r0_lock);

if (!sp_vi_r0.armed)
@@ -1838,14 +1834,17 @@ void audioreach_vi_calibration_abort(struct device *dev)
}

dev_info(dev, "VI calibration aborted: graph stopped before the DSP finished\n");
+
+ /* Edge-triggered: the mode auto-returns to Normal on abort too. */
+ audioreach_sp_finish_calibration();
}
EXPORT_SYMBOL_GPL(audioreach_vi_calibration_abort);

static int audioreach_speaker_protection(struct q6apm_graph *graph,
- const struct audioreach_module *module,
- u32 mode)
+ const struct audioreach_module *module)
{
- return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE, mode);
+ return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE,
+ READ_ONCE(sp_operation_mode));
}

static int audioreach_register_events(struct q6apm_graph *graph,
diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
index 745975574658..938d444f0e4b 100644
--- a/sound/soc/qcom/x1e80100.c
+++ b/sound/soc/qcom/x1e80100.c
@@ -6,6 +6,7 @@
#include <linux/platform_device.h>
#include <linux/soundwire/sdw.h>
#include <linux/spinlock.h>
+#include <linux/thermal.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/jack.h>
@@ -13,6 +14,7 @@
#include <sound/soc-dapm.h>

#include "common.h"
+#include "qdsp6/audioreach.h"
#include "qdsp6/q6afe.h"
#include "qdsp6/q6dsp-common.h"
#include "sdw.h"
@@ -162,16 +164,63 @@ static int x1e80100_add_wsa_chmap_ctls(struct snd_soc_pcm_runtime *rtd,
return 0;
}

+/*
+ * Register the thermal zones of the link's wsa884x VI DAIs, in DT order,
+ * which is the VI channel order.
+ */
+static void x1e80100_register_sp_speakers(struct snd_soc_pcm_runtime *rtd)
+{
+ struct thermal_zone_device *tzs[MAX_SP_VI_SPEAKERS];
+ struct snd_soc_dai *codec_dai;
+ unsigned int num = 0;
+ int i;
+
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
+ struct snd_soc_component *component = codec_dai->component;
+ struct thermal_zone_device *tz;
+ struct sdw_slave *slave;
+ char tz_name[THERMAL_NAME_LENGTH];
+
+ if (strcmp(codec_dai->name, "VI"))
+ continue;
+ if (!component || !component->dev)
+ continue;
+ if (num >= ARRAY_SIZE(tzs))
+ break;
+
+ /* The name wsa884x registers its thermal zone under */
+ slave = dev_to_sdw_dev(component->dev);
+ scnprintf(tz_name, sizeof(tz_name), "wsa-%d-%u",
+ slave->bus->id, slave->id.unique_id);
+ tz = thermal_zone_get_zone_by_name(tz_name);
+ if (IS_ERR(tz)) {
+ dev_warn(rtd->dev,
+ "no thermal zone '%s' for %s (%ld); SP T0 kcontrol will read 0 for this slot\n",
+ tz_name, dev_name(component->dev),
+ PTR_ERR(tz));
+ tz = NULL;
+ }
+ tzs[num++] = tz;
+ }
+
+ /* Also drops the zones of a previous bind when none are found */
+ audioreach_sp_register_speaker_map(tzs, num);
+}
+
static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)
{
struct x1e80100_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
struct snd_soc_card *card = rtd->card;
struct snd_soc_jack *dp_jack = NULL;
+ bool register_sp = false;
int dp_pcm_id = 0;
+ int ret;

switch (cpu_dai->id) {
case WSA_CODEC_DMA_RX_0:
+ register_sp = true;
+ fallthrough;
case WSA_CODEC_DMA_RX_1:
/*
* Set limit of -3 dB on Digital Volume and 0 dB on PA Volume
@@ -204,7 +253,15 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)
if (dp_jack)
return qcom_snd_dp_jack_setup(rtd, dp_jack, dp_pcm_id);

- return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup);
+ ret = qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup);
+ if (ret)
+ return ret;
+
+ /* Only register once init cannot fail further, so snd_exit runs */
+ if (register_sp)
+ x1e80100_register_sp_speakers(rtd);
+
+ return 0;
}

static void x1e80100_snd_exit(struct snd_soc_pcm_runtime *rtd)
@@ -220,6 +277,9 @@ static void x1e80100_snd_exit(struct snd_soc_pcm_runtime *rtd)
break;
}

+ if (cpu_dai->id == WSA_CODEC_DMA_RX_0)
+ audioreach_sp_register_speaker_map(NULL, 0);
+
qcom_snd_headset_jack_cleanup(rtd);
data->jack_setup = false;
}
--
2.53.0