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=1796073828; b=HR9cecnHbacleq3+B+TRaG1Xse5axvoYGcwG0Q8V5ELi5x3qWdMTRud4wOHqi05uPk6A TQA3vlx6aKFkOW3zWI/EJB1AyzsL3UXNpCdOBO1D4zaHl996NDawQZbN4afz9Op8hIRWd U9OJ/KJF3KSFKHyebfoVCZo2WiCxZjABW4xKXsMOzuVUOmbIw6gjkQINAhzANBF2ZztKj U94Q1Gg0j6vhO2DxJztyGukB9eZ5GqdsyaEzDH//gehjZyt7zWS9bBwR3qecP1cVdBfCT 4CE+FDrtPqR3YPxAOzLG1oZw5DNKUTR+wl57NSym3hwMjVyRpYJQG7JEqwxZiN+S+Cg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073828; 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-Authority-Analysis:X-Proofpoint-ORIG-GUID: X-Proofpoint-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=DPSuZBKEHsBttV+8gV20FedpN+Hq/mAwMV4aFDPfRZ4=; b=qtl+/3mpi33PhCKr1k4r68W35sP2nK5ZzAN5P+hvo+5AR58j9Zxbcaa1owp+7TXjbWzC HjvotBLiFRc3DnxSKNzWKV3Q6WzAgTXqBeAckI/Wxjpr1fa2/htFnOuebcCnb2WPpxnGD eOoEI8MAZpo8pu3aT+COMxikt9yrsnqNl0oMBCwq4/e3g9hE7vsD+o+2VurO1DhcMhXjA sO+H9NPD8K2uWBBuv8zI9EorIUjDaMmALIx56KVXFueD+Z3zG94U+WkLemM7LuhqQJaxn MV1coDgyO9PsJbU0W4zjKjaOdmMHMOEyMsf623gVHOW03RV16JnJtkLvCrHAWUuA2aA== 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=kEBWxSdv; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=WF3LLB6s; 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 E9B0A606A330 for ; Mon, 30 Nov 2026 21:23:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E9B0A606A330 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=kEBWxSdv; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=WF3LLB6s Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUKQTeo2033596 for ; Mon, 30 Nov 2026 21:23:46 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=DPSuZBKEHsB ttV+8gV20FedpN+Hq/mAwMV4aFDPfRZ4=; b=kEBWxSdv+J6vdSO2P2KvMRNXY8z d9DNbt2EHfDbVa74VRTyH+0YfPkDfTPnaYSr96Ds2kdUGcXdwtfP7KPepquOTmnz ImSHLMpM6PFcu2+/LCawP2a/xYPEVB9ApR2H1uW0eO7kUGsj4dTapnZ1KIlM7Yql jB0MpZcW76Tg670XumJKxUG9cdkNqMhA9mWPzbyvgxE0zh+Dhgl7utg7dVCxMdh0 IFwQ3k1+IKnzsuLC9tEN+T9sbSeyTdmYo7jGMuYFf7Q4U+XP+ACLICzdSDi/h0ab OBbLY3JPjiCuRYaD1T9AJpdY/K5IkE5ba2+y+BREzl4QLwC+KDNUQpHL+iQ== 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 4j9enx0hmr-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 21:23:46 +0000 (GMT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-93f5844e383so1587227085a.1 for ; Mon, 30 Nov 2026 13:23:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796073825; x=1796678625; 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=DPSuZBKEHsBttV+8gV20FedpN+Hq/mAwMV4aFDPfRZ4=; b=WF3LLB6s5CYgA42wEUL0cQKs2J5xlxhXD+o3zlcgooqcE7E0Q8MJMnHFOey5mpWWkN g5UHdnvVyjIeTKusYhPKxcIKLrjUWdhoA1NR8C6LN1tWWAtaL2FA+5gfpshRATAt5wJa LqkR54hkwmpD6gGkumMFwIfLjOyxmBY1bhHPq37SqZOCVH5I8w7DGnajCxgDWR+ik9FW KjTL02tEgQKYR0yLOBOdIpDbVo0NLN6WQF2qc6t66tzOg00lBae4qK4WO3pgByLmKL/F xOg/RDlTUG99pRs/kAsfwAbLthN7NR6S3bFMhYCEEFEBxubfB378Ur5m5VZ0c++5lN/b LB+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073825; x=1796678625; 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=DPSuZBKEHsBttV+8gV20FedpN+Hq/mAwMV4aFDPfRZ4=; b=byMi/6VgAr478geuO9dlI3kT4QBJxCPl13J9is1qEdeq1fDxaQQ6fQSn7EXWC8o8qo qZb48JHdetNyGl/BxeR9AA0T3eL6yrDaxeRJKCXT5hxg+5srJ1tKgoqLZwb+hc+ch/Ut UneNJYAaObeFHwdP48MyHCiN81R/ZOkHEPiLa2l4QISSptFc9vA7p/9PP0Z8VLtMVGaW I1ScrFqkBR/0tkIKyPLavtGKx/HqzjWcnrX8tLY3Qi5RNtlRfVHrQZbZYvmBnoVAyvIo vrXJ9IBF/zD9fCi2yFiFgm3C+n5pRsEfP4oPXBGZqEFGbtGQ6qpdDzfM8uDJozd3XSp9 /qgg== X-Forwarded-Encrypted: i=1; AL+hErHHv4jbrzOi0ZVoAH7hmD0rXjnVTdFnzPWeh8OvsttcpuZx/x16pXwgkN3E6rxlJK26dL7TYKDATrzNI8k=@vger.kernel.org X-Gm-Message-State: APuU4Z+QjH9PpuD8qPxKD97TbvH7upiXSO5psDl5YlhH7efBWMRqCR+b cpqggnvkrRtpPmyBd8UM3ePZsSrwaAwKZYO8WuZNN64IS78agp6da8QgstWrmjHxD/YNoi2PnQZ 8y5vol3ZMGZIFmwJKpcLMmSMKch3eMjgUX0EHOC8NsVTcJviXEkoEtnKG1Sb2MxmcXd8= X-Gm-Gg: AZFdTZdxsvnEy8lOa1weQlfnWvYMyLTkdphKJr3w/4Qerlwrleo6xoiR2TqIgcEffCw kmtZrx48qh31HMMWIyzPUhVqp7Pnnf5CvubHEhuXN/wf44xwux+fuoy2RSNAyUNk1anaYLRtUXE An23flUClrnsUGcVrKG2KB6a3VKJtk/UPLs82T0mLTy4pyd+/Mh8Zeb9TYXrQR9NSyd69L4wAYo QXieUf4nJHqbbBk6RwZV8yLqoD2Um9NPOxVwKQ8FkmlhTuOr0NxeUaycfTq+fzRNNsuS4M5jZIl uztNa4DLBN03w1plUaJJgACHVMDBVO7ig7tDNn3VGTcH1kmMLQeKz7njjwEPB3BT3eLwo/rcesD 0WpInaKkRbNUaExo8w+ZtLoP5wgFUEfIXqMXaP4MKFz1EPf+fLkjgR2xvtbmc8Riz X-Received: by 2002:a05:620a:4551:b0:93e:94f2:ada5 with SMTP id af79cd13be357-949ba965b93mr6195350785a.25.1796073825136; Mon, 30 Nov 2026 13:23:45 -0800 (PST) X-Received: by 2002:a05:620a:4551:b0:93e:94f2:ada5 with SMTP id af79cd13be357-949ba965b93mr6195347285a.25.1796073824633; Mon, 30 Nov 2026 13:23:44 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm792580515e9.0.2026.11.30.13.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:23:43 -0800 (PST) From: Srinivas Kandagatla 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@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Date: Mon, 30 Nov 2026 21:22:53 +0000 Message-ID: <20261130212258.7376-20-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com> References: <20261130212258.7376-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-Authority-Analysis: v=2.4 cv=Lv0HWXdc c=1 sm=1 tr=0 ts=6b0de962 cx=c_pps a=qKBjSQ1v91RyAK45QCPf5w==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=w_sgUqFDBmVKUPfu87UA:9 a=NFOGd7dJGGMPyQGDc5-O:22 X-Proofpoint-ORIG-GUID: tAF6ZHPsRlFQSkwPd9a8V2NyObs3ia75 X-Proofpoint-GUID: tAF6ZHPsRlFQSkwPd9a8V2NyObs3ia75 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfXxS4vR4InvXp+ i5KKLEr+w+tPrqZ5UN/AYEYF1H6fU/IDO0+/4gfVmdrcpvhNdfd9DL1skZQtoki0KLUh8R2WBhh G+0zkUli5IsSuOsc7p83G0Y6OPFXfJs= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfX7cexyRVgmm2x XwL47ikgH1XQKa6thKFCdDho7KV0Ikkd6eyB98zPtowPAHzzobi/1E76muVN7mHghuc+fSvE3Ep jVuNFOPpHqa6tfiLYsipDIMdRvv54K+4m+BUf5iCR2FypqxgCsXhyu2iHj5D/melygxRb5A3hST CiJPC6AguYmZyY6fg0ZT6mMoj5BvxpeMoC8dLoLEvS9V3B/I6H9IlVzgCq9XQW7NSumFF4Bprvf cPwkmdfKSPHXwNLzwydSMDsmoCgNQpFhc7qwCgUeZeH6dRrU7gpuv9hf+TMp7gp5L4jYYJ+CJuR QYDc4haPqUwm+S4YlqbWgCjfBivWXD8sOys0x4e9uc+jc2OuqcNGLDyQCBdOEgLc0fShFJHzHe7 rfkFkGvBJnl0uKXooa/8ppW/cBsvJXizZqfAkJ7a0Bpxmhv9QUy+OVLlHvKnfUtiu1Tow+nIo3Q nSWE0JYWBGmzvttAFAQ== 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-11-30_05,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 spamscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300086 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 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