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=1796129306; b=lj4g/ImyxqO+yR4JfNsOicsE26ayvexHrJbtDYFyz13jp8V+hADDVPrpIp5uF957ylXx qwzes1hTjH1U7Rk1P8i2f7ptgtZ1v653+m+C74GqG7+ntOtocToC0quqSYbEBHW9fQe8s hU1X+6DxwvK0CS8nLR9PQMbzus8+eqadYIT+73dNE/D+1l885Poe13oEwxmjfTfYMnOep pZcBrMFKv0vQUqhrmSB9jjGL2YO6g6TE/T93SZGF5vxcQwnOE5NtMUffk2MeBDhp+DDzu 46TNL/zkI8zqMSNPeNXTsKDdU9vBNlGs9UTNNtWeOdoBW4sWO7MpspQ8BMxdlbkYUDg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129306; 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-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Authority-Analysis:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=KETH4fO3OCkDGt3p0HEg0Hf1m/x8T8uf5QlO96KFSF4=; b=b8lJ6IM5UHvDgBSKXE8WdTwpSzhxr65DErmH16yuUwU1/ODYYHN1yzxp5GpYk4qXUB89 341t3lrPAEB4R/0boF9jSFL10UhstDgox7D6IEZQ38y+Yml9cUdH2SqlIBDNEkwAJrKKO Zz7wK/rhi/1MRvqolrFTg5znB258OGQBvyaPdQTSq/dgiIGJHOMPpyVSBtJldjMcirGOf UdJkavGAShje9eLNjYN2WsILe4HAcwv9S6Hzkj333+gs2PjLfJoNhOW4TRNR6LPQlIug4 pkcpkdLFtQgAyOqnGp4cqztejUOoUKq5S9KcLpTXF9glawe+Ln0w2hGYGMHhjqeYWEA== 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=W5KJhHdI; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=ezUEqAko; 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 532A560A5BD4 for ; Tue, 1 Dec 2026 12:48:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 532A560A5BD4 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=W5KJhHdI; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=ezUEqAko 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 6B1AQAhY3856967 for ; Tue, 1 Dec 2026 12:48:25 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=KETH4fO3OCk DGt3p0HEg0Hf1m/x8T8uf5QlO96KFSF4=; b=W5KJhHdILSmqss85J1Q6SYK6Yr6 R83DpfzIvfMOUt8PKECfhzlcHopvpK/FwJpk7KGu8QA9pQmrbLnf3mQv0EQXRa2s oyBJaqFJ9vTB6S4rhGow85AIot4r5CHBleEL7YEmlM19MOqU6o0crSOJjeQyJosw ATZFXvvo/jjdmLVopbAvyT8X968j3dX+zi8zvhvkxwYSw1SWx6eO9ug5St1t+b1U oUe+WNuCbx4gMyN933/aS2KwszohtQEDO2Vy6o0uL5unK6lNukTroeCWjF+RlGbT 88C7oOTz0Ta9wHZ55zcHwJEVJSdWNUcB1RxFt1Fc8Jdb7XQyD+AGFLO6N2w== Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9tng14jm-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 12:48:25 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-9308eafb465so2244698485a.2 for ; Tue, 01 Dec 2026 04:48:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796129304; x=1796734104; 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=KETH4fO3OCkDGt3p0HEg0Hf1m/x8T8uf5QlO96KFSF4=; b=ezUEqAkoMy1/9T/rI28VHFMWkVfMLTtFsAAzZumQA4Ll0dvu5UiGcf6lozyW+rtslJ 7GJ62+qTLcT8mHRFwnrGY0PZzIrfp9FD7Wvbi6mDL7fxBJJLXmWbV0aLMEIMYGKVr6Ux sp3qxnvuqdq7fBFjB8AUDMRiP06FHtxDCmO49jD+VOd71cSlFtC190mRVgYk9ZubHtCL /uabxwq3AsJli3hxMcGOIFMTDYXbZKHU9PTp8/F+cYAOqISj5MJeStbfbPUmClfMi/K8 Jm+5x86NuZ17Cf6M18Td5fEoK40AVrTlai0ickUVygIuu/rcOoC35BY2U8YkNU08rT/T okEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796129304; x=1796734104; 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=KETH4fO3OCkDGt3p0HEg0Hf1m/x8T8uf5QlO96KFSF4=; b=DL12g6WMaFOgVbOJAnNND1U3nx6LadZFsEQtVZBlfvQ3zxWOaNx+QhPG8+3FzvehVq CmUQ2PxS1EDIE+7NiuZBmh9S1eCPIcf8ylHfLLLOQb1kSXX7TY4GGQZmD2wPAl08yocQ QpuQPfkezhyZk++P8KgrMgfiH8J/SETxAgygutfwteQZuKbbf/MOgL/WjVz+URi9q3to RGRP+ycif87CoM8mJguBUORu1c9YpE581adIhlNnSwE+bAetYdokT/J/wqM6oF5mZ3qC N6+1X4oLi/tYowwZKVTD8zJRIOY6NvCrqnWHugiO1cxgzNr6KtcJd+1z89VJYpjaibNn 07jQ== X-Forwarded-Encrypted: i=1; AL+hErHmOkCzYxY3PS0LLiea5RBzPGjYsS6jIJU8NnYT/iT1H2wq05PKTM6vyuImXQE3DkHRIqmgVyMLnxDaejc=@vger.kernel.org X-Gm-Message-State: APuU4Z85ZA8/9WRPSU5/YRZb08f9D7U8ZGTSDRLikgGDM2uNfa3XZzD9 z+VvWYs3vtDUp27Z4K7S1FQLEF2IAO5dabkaeWNfl6NToAJbl3oev802qz6PUN7WiY6zb8+buks xebmWNRAzckRh9jih14h+j17H73OxvhVeHH/2dy7zhp0Jy3gz+e8kCj4vnZLhtmOIDkU= X-Gm-Gg: AZFdTZcpOIIbegn3I2mI8qjnW5XmpidqpXtjzlEX5hWMWZq+fZ1gKy7w3eG2kOhF0y8 7sJNYfiHpgi2i8n4pVFFiqMRSFwjEzSHs1JF9TxEa902nl+zRNuhnxS70JLr00fMjtOlQ2BdG6U si8L3faUeosd+wJB0OQCBdm7Dew1X4Jyp2enTAs8ewI6xhe9ErJX4BnvhPLN1D408LW3XclxpDQ gDdcw7vv+xyIU44YdG2RLYt9IaFpM5AOQ5/dV7JwCa6AdU92IfwYHLSKp70WVksFjTciFVo+dmB 1Ey1/dEtqhShhi2v3UEY+cNPFubMUzRajkcunXFQbtotpiV6arhQCkdTlMPq754ZR6fLzECgcGs oybOzGUlXrpPVHPGcJdJv8PLXpISpt5tr6rePYgXAR4rThrOPDTpzmtVUY5IFHBWu X-Received: by 2002:a05:620a:4408:b0:949:9cf0:bae5 with SMTP id af79cd13be357-949bab3d2f2mr6841780685a.69.1796129304389; Tue, 01 Dec 2026 04:48:24 -0800 (PST) X-Received: by 2002:a05:620a:4408:b0:949:9cf0:bae5 with SMTP id af79cd13be357-949bab3d2f2mr6841773685a.69.1796129303816; Tue, 01 Dec 2026 04:48:23 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9687sm1131892375e9.10.2026.12.01.04.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 04:48:23 -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, Ravi Hothi , Srinivas Kandagatla Subject: [PATCH v4 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Date: Tue, 1 Dec 2026 12:47:41 +0000 Message-ID: <20261201124753.196748-13-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-ORIG-GUID: ijimastv70Szag_8-rD4gLEgzTAgxPQn X-Proofpoint-GUID: ijimastv70Szag_8-rD4gLEgzTAgxPQn X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX9UyuHFhIyLDZ dT5lfjLIhvaGWNwnzXZhTK+KeyEB5JuzBTfUOQrHDqNZ1F+AXXkyXPeV+WwEpsq8RMUYanXjTdO gmpSZhVRI+ULVA4iuL9CzTJN9fn6DtpKXduiB/UI8D7FtOwzqoQdLk1ZLblEg33wDs+gQTrjtix /+Q2QhBzNS1oz0uJc50N1BM3xykn/gleNVB0+yLQhh8PNRkGt1efokUE7DU0IWRmg6+YYvjhX8v 1zOdsJXjTpSFORGrLVjAQV2WCk3MGGhuxn6DUMMJNqCpcIeMhcmgyvpRM2qx8RwfG5HUBA7zM+M hOZDC5jIy3He76rnhbaCnlQCbJj9qEH/Zrec877WMvNX84W0qMI022tW8Rn1ZmJD4vaijqrh7kx WzkIPFwZuG16QbqbTXffeFNLz/6VlinOvpTJ3qxiG7yOc8tv9ZrNneGmw2Oxxmm6euiH+jIQBbf n6r2pQyL05pqjEOAM2Q== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX6njV+dSjE+1J 9d0JzWydRfauwcACF1SXbSmLiHgc4+7zlqV60WENmJqqfFfFh//FtqFgZuol8CK+8gD/0zdztxq ULb7R+acHeWImArMpQt6v9SN79X20T8= X-Authority-Analysis: v=2.4 cv=O5ysLx9W c=1 sm=1 tr=0 ts=6b0ec219 cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=9ZV4jQrK44SIZejVWmoA:9 a=PEH46H7Ffwr30OY-TuGO:22 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 clxscore=1015 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 adultscore=0 impostorscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010050 From: Ravi Hothi 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 Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/qdsp6/audioreach.c | 134 +++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 4 deletions(-) diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c index aea482270c26..c48ba63448db 100644 --- a/sound/soc/qcom/qdsp6/audioreach.c +++ b/sound/soc/qcom/qdsp6/audioreach.c @@ -2,6 +2,7 @@ // Copyright (c) 2020, Linaro Limited #include +#include #include #include #include @@ -12,6 +13,25 @@ #include "q6apm.h" #include "audioreach.h" +enum sp_vi_cali_state { + SP_VI_CALI_IDLE, /* Not calibrating */ + SP_VI_CALI_RUNNING, /* Events arriving, none decisive yet */ + SP_VI_CALI_FAILED, /* Run finished, no usable R0 */ + SP_VI_CALI_SUCCESS, /* Run finished, @r0_cali_q24 valid */ +}; + +struct sp_vi_r0_result { + /* Set when a calibration run is armed, cleared when it ends */ + bool armed; + enum sp_vi_cali_state state; + u32 num_ch; + s32 r0_cali_q24[MAX_SP_VI_SPEAKERS]; + u32 seen_states[MAX_SP_VI_SPEAKERS]; +}; + +static struct sp_vi_r0_result sp_vi_r0; +static DEFINE_MUTEX(sp_vi_r0_lock); + /* SubGraph Config */ struct apm_sub_graph_data { struct apm_sub_graph_cfg sub_graph_cfg; @@ -1436,16 +1456,112 @@ static int audioreach_gain_set(struct q6apm_graph *graph, return q6apm_send_cmd_sync(graph->apm, pkt, 0); } +static bool sp_vi_cali_state_is_failure(u32 state) +{ + return state == VI_CALIBRATION_STATE_FAILED || + state == VI_CALIBRATION_STATE_VI_WAIT_TIMED_OUT; +} + +static bool sp_vi_cali_state_is_terminal(u32 state) +{ + return state == VI_CALIBRATION_STATE_SUCCESS || + sp_vi_cali_state_is_failure(state); +} + +#define SP_VI_CALI_UNKNOWN_STATE_BIT (VI_CALIBRATION_STATE_LOW_VI + 1) + +static const char *sp_vi_cali_state_name(u32 state) +{ + static const char * const names[] = { + [VI_CALIBRATION_STATE_INCORRECT_OP_MODE] = "not in calibration mode", + [VI_CALIBRATION_STATE_INACTIVE] = "inactive", + [VI_CALIBRATION_STATE_WARMUP] = "warming up", + [VI_CALIBRATION_STATE_INPROGRESS] = "in progress", + [VI_CALIBRATION_STATE_SUCCESS] = "success", + [VI_CALIBRATION_STATE_FAILED] = "failed, R0/T0 out of range", + [VI_CALIBRATION_STATE_WAIT_FOR_VI] = "waiting for V/I", + [VI_CALIBRATION_STATE_VI_WAIT_TIMED_OUT] = "failed, timed out waiting for V/I", + [VI_CALIBRATION_STATE_LOW_VI] = "V/I level too low", + }; + + if (state >= ARRAY_SIZE(names) || !names[state]) + return "unknown"; + + return names[state]; +} + +static int sp_vi_q24_to_int_frac(s32 val, int *frac) +{ + *frac = (int)(((s64)(val & 0xffffff) * 1000) >> 24); + + return val >> 24; +} + void audioreach_vi_calibration_event(struct device *dev, const struct event_id_vi_per_spkr_calibration *cali, u32 num_ch) { + bool decisive = true; + bool success = true; unsigned int i; + u32 bit; + + guard(mutex)(&sp_vi_r0_lock); + + if (!sp_vi_r0.armed) + return; + + /* First event of this run: drop the previous result */ + if (!memchr_inv(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states))) { + sp_vi_r0.state = SP_VI_CALI_RUNNING; + sp_vi_r0.num_ch = 0; + memset(sp_vi_r0.r0_cali_q24, 0, sizeof(sp_vi_r0.r0_cali_q24)); + } + + for (i = 0; i < num_ch; i++) { + u32 state = cali->cali_param[i].state; - /* Raised every frame; keep the per-event log at debug level */ - for (i = 0; i < num_ch; i++) - dev_dbg(dev, "VI calibration channel %u: state %u\n", - i, cali->cali_param[i].state); + if (sp_vi_cali_state_is_failure(state)) + success = false; + else if (!sp_vi_cali_state_is_terminal(state)) + decisive = false; + + bit = BIT(min_t(u32, state, SP_VI_CALI_UNKNOWN_STATE_BIT)); + if (!(sp_vi_r0.seen_states[i] & bit)) { + sp_vi_r0.seen_states[i] |= bit; + dev_info(dev, "VI calibration channel %u: %s\n", + i, sp_vi_cali_state_name(state)); + } + } + + if (!decisive) + return; + + sp_vi_r0.armed = false; + sp_vi_r0.state = success ? SP_VI_CALI_SUCCESS : SP_VI_CALI_FAILED; + sp_vi_r0.num_ch = num_ch; + + for (i = 0; i < num_ch; i++) { + int r0_int, r0_frac; + + if (cali->cali_param[i].state == VI_CALIBRATION_STATE_FAILED) { + r0_int = sp_vi_q24_to_int_frac(cali->cali_param[i].r0_cali_q24, + &r0_frac); + dev_warn(dev, "VI calibration channel %u: R0 %d.%03d ohms out of range\n", + i, r0_int, r0_frac); + continue; + } + if (sp_vi_cali_state_is_failure(cali->cali_param[i].state)) + continue; + + sp_vi_r0.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24; + + r0_int = sp_vi_q24_to_int_frac(sp_vi_r0.r0_cali_q24[i], &r0_frac); + dev_info(dev, "VI calibration channel %u: R0 %d.%03d ohms (Q24 %d)\n", + i, r0_int, r0_frac, sp_vi_r0.r0_cali_q24[i]); + } + + dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed"); } static int audioreach_speaker_protection(struct q6apm_graph *graph, @@ -1485,6 +1601,14 @@ static int audioreach_register_events(struct q6apm_graph *graph, return rc; } +static void audioreach_arm_vi_calibration(void) +{ + guard(mutex)(&sp_vi_r0_lock); + + sp_vi_r0.armed = true; + memset(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states)); +} + static int audioreach_speaker_protection_vi(struct q6apm_graph *graph, const struct audioreach_module *module, const struct audioreach_module_config *mcfg) @@ -1512,6 +1636,8 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph, return -EINVAL; } + audioreach_arm_vi_calibration(); + rc = audioreach_register_events(graph, module); if (rc) return rc; -- 2.53.0