From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796129317; b=oJnbeu3m2QujPXO+x68quDLwcOkI3x2jY208Vijen0D4VXSYbbpOMVq/tufpulEGP5eI Lwp8XWM6LPXwLdYXCZgBUI1fAt5C0/87VUP0VURFTG0E2aGtXHF2XTTDSSRLjLUtV7dsL uNIZf/pCLSVX/5aR2Wq0g3VSwWIjiUodnFbGAtOupu2412yWs497B0slpV+IR+PVlANEm 5h9S6+9HU0FD5yvYMmW8FiBgkK4fA/nXaG2XSXhJa+GQiyfGG2k5OhjUpouo62r/967J7 4gTkBXlkIPrx37I+h4/rtCGy6caJr19QlN8OvQ6dBWJWqGJO/+A9yWveXfMGWAbWJow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129317; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Spam-Info:X-Authority-Analysis:X-Proofpoint-ORIG-GUID: X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=UPn/4mbL4iYL3naTNGMd2wGwwXbEF8O2JEiDeL3tgds=; b=tBNewPnS4wXe58ENRu/xMxUaJH3l9G8AL0WnD8SktYBqD+pWxod7KLElbN9+rohXujki OkYOah3MnIoN/aBOYxUzp5QHlXlcP0zoUqjRXh1loZtZWb9Vr2xZHXAx6i76CjWJemwxN d0J+GxPiueWSoqL3gaZOXdaRN5kGg2Zs0B04zj2AIDxMDdRtUhKp1xscKxd4M0i6/V3GU shQCvtaVeM71nwRJ0DXtTt7sIiU4HlI2Kr+y3VddDAVRre2hUOJ3tT1LNQ1OBwk8S7UiN lO2+WJvr+zL7ORWAwO9w36OjH313rmB/EVAC16wyYxheucusgvOn7GILvVxwhvKek3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=YbMrTkGX; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=Vis260K6; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90A4E60A261F for ; Tue, 1 Dec 2026 12:48:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 90A4E60A261F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=YbMrTkGX; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=Vis260K6 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1AQGWP827445 for ; Tue, 1 Dec 2026 12:48:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=UPn/4mbL4iY L3naTNGMd2wGwwXbEF8O2JEiDeL3tgds=; b=YbMrTkGXZhHPRxbPy0ap3do9GUa S4eeZlG1UqpYc9SIoTxG/qDeASvpoRKsy5RxtquSBdSqrDY7o50eZJBjHzWP1KJu 0kn/KcFToNrdCTOLa7IUS2KE2tU1s3fFBwfIDqPV9qKFjoGZEez1SiSBCeTpQEqJ H2/DquC49xF0Hl3o8CbhmV9VM/mzjH0lOmAKFEryragTvz57c3PwWpKKKs0w4P0f vb9MMuhzYiA2SiG9lI+K7LnB2HvlEVq9R8kM2v2aRuL2iPS57Wj0i3RGbR+iVuOa DAW3jPuXgV3VZBqKoiCWFgAF2+XkPzj8FlmkT+AXi87IejLxcNKyzf8brSg== Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9pts22a0-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 12:48:35 +0000 (GMT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-94975041698so2514035485a.0 for ; Tue, 01 Dec 2026 04:48:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796129315; x=1796734115; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UPn/4mbL4iYL3naTNGMd2wGwwXbEF8O2JEiDeL3tgds=; b=Vis260K6kSsSHwmDmMoDqqbzWzQERHqA9Q+vEMQMFeyQKs7RjwQqdFilhRZ0NU8amZ Ng50e5LWPHRlKLn69lSbW3MWr68EoKDP5DzBQCYDdtIdI5MsCg/i8ufy97TNSRKvIMu7 Bjzpt0LqPWbqkyWohSIyZhrodriwYaEtxdyv4z6zj2BqFjjni73Tcg82VhTyTsrYn6do NM4pfgaAw8EtLtQ0Ak9MDjWXknqKZ7TVemrdgu11t3LeHHeJTroocUCBWfKEyUtM0Lnw o/5pBlXzG5NQJD/NmkHkPs8f2PVh/Ji1MAy5d1h2fFZ6dqSYL+vqqWWkZJ5kmOZ0lWf+ 0vbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796129315; x=1796734115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=UPn/4mbL4iYL3naTNGMd2wGwwXbEF8O2JEiDeL3tgds=; b=UXAgaH+ya49G6zinCcMhQa7Yzla44AV3y9/+LIWyoM036DiNNBzYi+NWppcKKtuqdJ x4oEUX1eibem/yLEzU6quztDxG6akbVa6IVHpBlcK5a/Ql9PcIets4B9pnQnr/NwMw4H UoaaTq7l3NktZy/kAG5wAD6xRb16MGGNHPQHBHiifsTXXHDeIKI3nUkhfKRvMccOfpud qUCH3Yr4IorOP/yrwrMGHIV/6H0iGWHnTQNkfBs9kqFrkM9ikg0vwcBOfbyqRUYiV8Dh JWSf1hQ6T2BTE5DopTU5Rb3qTuuXa4TGEqZ2/m83kJDnz8KvPjyl4dF0pxEqnKVvoLMh RhLA== X-Forwarded-Encrypted: i=1; AL+hErEX7K5Z9wa+K4deh/oRW5CuEjf44k7rjdJq198Au6tBUmjtea0WrkjMMPqQHLVn5kq8q80E+XYklrbyOGM=@vger.kernel.org X-Gm-Message-State: APuU4Z8WSlD16OBybf0j5GKnMFOw4txjNTJoYNTKSL12fXaTc+A/vQzF x/6KQN2E9qUIIq13zsMmhZvwsD7H6LrHatw6sEhcEqZjfeZtShtFPftk7SOrYNif82u91wzqKJ6 bxQENVHcahFxRuf71uQiHSgrtsn0idkCmG9RyPfdpbKOl5XrYsEZ4b9dJJzzUvS0gPSo= X-Gm-Gg: AZFdTZd1BBS4WWMAW2kozkB7vzNxwQr0UVUGZvCwqLdSjVutj1wjho9t1hbozR4FMg2 hY1b9shH2thQvnGjhAMns7yHMyGzoX/40ZPE8lZO3WAF06Wn1rhZqDzk2AhiLOUUxzMXkavkRzr gm16b1l3xgPb6vzueH27fdYRkBeuRJIdZcX1zJrBBApkBGsnIBhqtS3NmBqlOsbYyInNDv3F7fs /1jHoSYov5NvZTeXHsNKi9DrmmOCNG8XB1pqA1wfZ3JvDUmjWTQ65OV7lbsqHWpG506AWuWQ2h4 GWtggR3PM2X/6dm0TUnsKJiefJZoo0emoBVnelbY0QwPkSJiO6+nOwIyu1XIBsqIEjjKLWDrqSb egRoPS6HuIrY9FcNE2dGoVsbiOSDG+42V34vcgljgXcsyjILYkI4dkRbIhVF/w3jn X-Received: by 2002:a05:620a:838e:b0:949:2fca:4a82 with SMTP id af79cd13be357-949b3618329mr6397682685a.32.1796129314811; Tue, 01 Dec 2026 04:48:34 -0800 (PST) X-Received: by 2002:a05:620a:838e:b0:949:2fca:4a82 with SMTP id af79cd13be357-949b3618329mr6397678285a.32.1796129314284; Tue, 01 Dec 2026 04:48:34 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9687sm1131892375e9.10.2026.12.01.04.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 04:48:33 -0800 (PST) From: Srinivas Kandagatla To: Mark Brown Cc: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto , Pierre-Louis Bossart , Bjorn Andersson , Konrad Dybcio , Abel Vesa , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Randy Dunlap , Shuah Khan , linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Date: Tue, 1 Dec 2026 12:47:48 +0000 Message-ID: <20261201124753.196748-20-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com> References: <20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX9vEiVXZ5gwqI QuSvoSik/DkS9yhwWRP4lHcaMJLlYy8FZjZe+/PPJBMt6ykikpSFwxc53vponG/zHNxKrTKvnwa obqHRs3aaPUEGIdF01oIBIJe63eE2L+qCJtQhdxOFdXJUVEssFIWFhDUcwhCbHLuY11LU+jhSCp 9EjciySpjbDA34mPspzZo7QCNm4mvf7Rv5MIoPs0dOc+VSINSnocqqyMj1iFcMAaG6aNCyQJDWV t9cb1yujXLHzuqOuLAaimsQALB0PwmYALlUOrm97t+6YA16NdRljdV64llYncttZgi5xe8vYR/l lVQHcAKMqbzjmK79eILnsSFalKxiJrlsCmj6QGhzOCSvjLb87ZMQE/E1XYGGFP90BT6MEsUl/Tr 32RVnC24sUVWuMbi6vUj2poHw93hevmgNvHPllQWj3poP7kcTZCDB6ovA/4fZa7vSnJ1WxXMpPD vKjjn4iUeAGUiHS0x0Q== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfXzvi7ztSKJaix UewzFZKK/TbcX6RuE4LmkDv/Cgjq7GJXOfHQca8bkoqL2wO3br6tJU4M42jl7/Xxp07SUphUV10 TfqQryngY/Ps86NLPjbWMbClySoaX1c= X-Authority-Analysis: v=2.4 cv=Cqoq4X4D c=1 sm=1 tr=0 ts=6b0ec223 cx=c_pps a=qKBjSQ1v91RyAK45QCPf5w==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=w_sgUqFDBmVKUPfu87UA:9 a=NFOGd7dJGGMPyQGDc5-O:22 X-Proofpoint-ORIG-GUID: kInU06jc-R2OVu8oTasejOS9IyA63or_ X-Proofpoint-GUID: kInU06jc-R2OVu8oTasejOS9IyA63or_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_02,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010050 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 --- sound/soc/qcom/qdsp6/audioreach.c | 60 +++++++++++++++++++++++++++++ sound/soc/qcom/qdsp6/audioreach.h | 2 + sound/soc/qcom/qdsp6/q6apm.c | 15 +++++++- sound/soc/qcom/qdsp6/topology.c | 63 +++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c index 3974191f9c53..cf30c18fa25f 100644 --- a/sound/soc/qcom/qdsp6/audioreach.c +++ b/sound/soc/qcom/qdsp6/audioreach.c @@ -23,6 +23,7 @@ enum sp_vi_cali_state { SP_VI_CALI_RUNNING, /* Events arriving, none decisive yet */ SP_VI_CALI_FAILED, /* Run finished, no usable R0 */ SP_VI_CALI_SUCCESS, /* Run finished, @r0_cali_q24 valid */ + SP_VI_CALI_ABORTED, /* Graph stopped before the run finished */ }; struct sp_vi_r0_result { @@ -32,6 +33,8 @@ struct sp_vi_r0_result { u32 num_ch; s32 r0_cali_q24[MAX_SP_VI_SPEAKERS]; u32 seen_states[MAX_SP_VI_SPEAKERS]; + /* Last calibration state per speaker (enum vi_calibration_state) */ + u32 last_state[MAX_SP_VI_SPEAKERS]; }; static struct sp_vi_r0_result sp_vi_r0; @@ -1632,6 +1635,21 @@ int audioreach_get_sp_vi_t0(long *vals, unsigned int count) } EXPORT_SYMBOL_GPL(audioreach_get_sp_vi_t0); +/* Latest calibration state per speaker, 0 before any event */ +int audioreach_get_sp_vi_cal_state(long *vals, unsigned int count) +{ + unsigned int i; + + guard(mutex)(&sp_vi_r0_lock); + + count = min(count, MAX_SP_VI_SPEAKERS); + for (i = 0; i < count; i++) + vals[i] = sp_vi_r0.last_state[i]; + + return count; +} +EXPORT_SYMBOL_GPL(audioreach_get_sp_vi_cal_state); + int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int count) { struct sp_vi_r0t0_cfg new = {}; @@ -1718,6 +1736,8 @@ void audioreach_vi_calibration_event(struct device *dev, for (i = 0; i < num_ch; i++) { u32 state = cali->cali_param[i].state; + sp_vi_r0.last_state[i] = state; + if (sp_vi_cali_state_is_failure(state)) success = false; else if (!sp_vi_cali_state_is_terminal(state)) @@ -1780,6 +1800,46 @@ void audioreach_vi_calibration_event(struct device *dev, audioreach_sp_finish_calibration(); } +/* A run cut short never reports a final state, close it out */ +void audioreach_vi_calibration_abort(struct device *dev) +{ + unsigned int i; + + guard(mutex)(&sp_vi_r0_lock); + + if (!sp_vi_r0.armed) + return; + + sp_vi_r0.armed = false; + + /* The DSP never reported on this run: keep the previous result */ + if (!memchr_inv(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states))) + return; + + sp_vi_r0.state = SP_VI_CALI_ABORTED; + + for (i = 0; i < MAX_SP_VI_SPEAKERS; i++) { + u32 state = sp_vi_r0.last_state[i]; + + /* Slot never reported: not part of this run */ + if (!sp_vi_r0.seen_states[i]) + continue; + + if (sp_vi_cali_state_is_terminal(state)) + continue; + + dev_info(dev, "VI calibration channel %u: aborted while %s\n", + i, sp_vi_cali_state_name(state)); + sp_vi_r0.last_state[i] = VI_CALIBRATION_STATE_INACTIVE; + } + + dev_info(dev, "VI calibration aborted: graph stopped before the DSP finished\n"); + + /* Edge-triggered: the mode auto-returns to Normal on abort too. */ + audioreach_sp_finish_calibration(); +} +EXPORT_SYMBOL_GPL(audioreach_vi_calibration_abort); + static int audioreach_speaker_protection(struct q6apm_graph *graph, const struct audioreach_module *module) { diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h index 2136075d0e87..27952835714d 100644 --- a/sound/soc/qcom/qdsp6/audioreach.h +++ b/sound/soc/qcom/qdsp6/audioreach.h @@ -1140,10 +1140,12 @@ int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsigned int int audioreach_sp_register_speaker_map(struct thermal_zone_device * const *tzs, unsigned int num); int audioreach_get_sp_vi_t0(long *vals, unsigned int count); +int audioreach_get_sp_vi_cal_state(long *vals, unsigned int count); int audioreach_add_sp_telemetry_controls(struct snd_soc_component *component); void audioreach_vi_calibration_event(struct device *dev, const struct event_id_vi_per_spkr_calibration *cali, u32 num_ch); +void audioreach_vi_calibration_abort(struct device *dev); int audioreach_compr_set_param(struct q6apm_graph *graph, const struct audioreach_module_config *mcfg); int audioreach_setup_push_pull(struct q6apm_graph *graph, phys_addr_t bphys, diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c index c410e2f6e6a3..35daf763287c 100644 --- a/sound/soc/qcom/qdsp6/q6apm.c +++ b/sound/soc/qcom/qdsp6/q6apm.c @@ -815,10 +815,19 @@ struct q6apm_graph *q6apm_graph_open(struct device *dev, q6apm_cb cb, } EXPORT_SYMBOL_GPL(q6apm_graph_open); +static void q6apm_graph_abort_vi_calibration(struct q6apm_graph *graph) +{ + if (q6apm_find_module_by_mid(graph, MODULE_ID_SPEAKER_PROTECTION_VI)) + audioreach_vi_calibration_abort(graph->dev); +} + int q6apm_graph_close(struct q6apm_graph *graph) { struct audioreach_graph *ar_graph = graph->ar_graph; + /* Covers a graph closed without ever being started, e.g. on prepare failure */ + q6apm_graph_abort_vi_calibration(graph); + graph->ar_graph = NULL; kref_put(&ar_graph->refcount, q6apm_put_audioreach_graph); gpr_free_port(graph->port); @@ -854,6 +863,7 @@ EXPORT_SYMBOL_GPL(q6apm_graph_start); int q6apm_graph_stop(struct q6apm_graph *graph) { struct audioreach_graph *ar_graph = graph->ar_graph; + int ret; if (ar_graph->start_count == 0) return 0; @@ -861,7 +871,10 @@ int q6apm_graph_stop(struct q6apm_graph *graph) if (--ar_graph->start_count > 0) return 0; - return audioreach_graph_mgmt_cmd(ar_graph, APM_CMD_GRAPH_STOP); + ret = audioreach_graph_mgmt_cmd(ar_graph, APM_CMD_GRAPH_STOP); + q6apm_graph_abort_vi_calibration(graph); + + return ret; } EXPORT_SYMBOL_GPL(q6apm_graph_stop); diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c index a8fdd73cdecd..16327961d6c1 100644 --- a/sound/soc/qcom/qdsp6/topology.c +++ b/sound/soc/qcom/qdsp6/topology.c @@ -1548,6 +1548,45 @@ static int audioreach_get_sp_t0(struct snd_kcontrol *kcontrol, return 0; } +static int audioreach_get_sp_cal_state(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + audioreach_get_sp_vi_cal_state(ucontrol->value.integer.value, + MAX_SP_VI_SPEAKERS); + + return 0; +} + +static int audioreach_info_sp_calibrate(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; + uinfo->count = 1; + uinfo->value.integer.min = 0; + uinfo->value.integer.max = 1; + + return 0; +} + +static int audioreach_get_sp_calibrate(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + /* Trigger reads back as 0 so alsactl restore of a stored value is + * a no-op; writing 1 arms a single calibration run. + */ + ucontrol->value.integer.value[0] = 0; + return 0; +} + +static int audioreach_put_sp_calibrate(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + if (!ucontrol->value.integer.value[0]) + return 0; + + return audioreach_trigger_sp_calibration() ? : 1; +} + static const struct snd_kcontrol_new audioreach_sp_telemetry_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, @@ -1557,6 +1596,30 @@ static const struct snd_kcontrol_new audioreach_sp_telemetry_controls[] = { .info = audioreach_info_sp_t0, .get = audioreach_get_sp_t0, }, + { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Speaker Protection Calibration State", + .access = SNDRV_CTL_ELEM_ACCESS_READ | + SNDRV_CTL_ELEM_ACCESS_VOLATILE, + /* Last calibration state per speaker (enum vi_calibration_state) */ + .info = audioreach_info_sp_t0, + .get = audioreach_get_sp_cal_state, + }, + { + /* + * Write-only edge trigger. Writing 1 arms a calibration run + * for the next (or current) WSA playback graph; the mode + * returns to Normal on its own once the DSP reports terminal + * state, on graph abort, or on the watchdog timeout. + */ + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Speaker Protection Calibrate", + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | + SNDRV_CTL_ELEM_ACCESS_VOLATILE, + .info = audioreach_info_sp_calibrate, + .get = audioreach_get_sp_calibrate, + .put = audioreach_put_sp_calibrate, + }, }; /* Kept apart from the topology SP controls, so FEs have them without it */ -- 2.53.0