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=1796129308; b=xZoXAnBnwwMjuu3lpEGt5MebhfnxF3pOULNZl0QMx3JCLHbf8i21HyWn5QbLcDL3eAS1 OOksqONWBvXMN7FGaF6yDuh8VdBMuN1+4t2rkaXqVmyIbFbvwhj6O6oWP+pJeiBduuOH8 Ntm9Pl77bmAlGj5BpIxWjGTF4uJ1sIoog1HwsR8epFQTakdRmSRaAgb6M2JB/IyKn4cSN 0Np319RoeoCF9D3hMOHZcKqv1laL+A1d7bRjqxLmAw/QjzIhYz3lzTrOW7H79aUdCLHpP TpTZcV7A1Vpl/QTdDVd2ffQbVNH+0o3WuQaMvVYBlY4brAGoDiZmbJYGfd3Tc7kOR5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129308; 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=EYcqrSXqj7lFIKQnsCl0fbob+PO3R+PToOizoKrYky8=; b=qCtvjK1Gk1RxzLIVOaVz2a9rm5c6jL6lq1Nqy6Q6bZfE9ESMMN3WN7e+tq1rKdVsJK6a CLhyAFXnokG0FpziX6qAQVOSNh2iNL8ympwmLBGjed9dWx18EsI5XT0hY2JEaHC8wZjjF vjCgfVTa/ANlSEWVhZObRJkLglOsgg0xZAnYfIyu9gI4UN5gHABrCNVR846KZHn6hLP3g vt5wyln9CfA60z9yCJy4t6c/usXIVaOIhRCnkOMuZ8I0OChldbfG7tMuxv1pHqHQUC3lh Nyygsdotm2VeiaWodrNiXjkxj5TQFGoYNl8hJJxQHTp/O/WgkgY6uWZsrUcyJ+0jqpg== 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=MJJoEwih; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=XDWG6GjD; 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 83BFE60A5BE6 for ; Tue, 1 Dec 2026 12:48:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 83BFE60A5BE6 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=MJJoEwih; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=XDWG6GjD 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 6B1AQGWL827445 for ; Tue, 1 Dec 2026 12:48:27 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=EYcqrSXqj7l FIKQnsCl0fbob+PO3R+PToOizoKrYky8=; b=MJJoEwihcs5VXNdwbrnM82BPSV1 8o8whE1cHuCIjiG3ioN4LyJaEGoYnJIcyf3J0YNQQeMdtnZiuNOJIfD/cPQWhLwV asltu08ZbafK5+KGhU9uCq77l67Un1Jll7wl25JaUG74NVEQe8SbtCxYDXj/YIhI qQkyx3TDly7hJsskOvV7shHUWtl4Rlf8nM0VZSDc1OIzN3svTUsetw56XPJWYuzh AmKv6yh7Qx/Em7CtvbSzp82IxsdW4kTZIzKyOMGMPVvbkibS+1m+b1ssbqrnJ0bn WUPBi6bWAyR7ycCqrZ55Y5GQzWOP9l5piIQz3268EHMLVDjgFCstE41horA== 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 4j9pts228k-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 12:48:26 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-94970ad532bso1102602085a.0 for ; Tue, 01 Dec 2026 04:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796129306; x=1796734106; 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=EYcqrSXqj7lFIKQnsCl0fbob+PO3R+PToOizoKrYky8=; b=XDWG6GjDyMsCnZ7c1yN/8CAxmXwHrU/ZRCbAyTU159KOlESOgyOGNBhCdISKNJ+o7R 3cyPExnS0LiNY71mcPogirnEPh/G+nJoopeY1AGjcUmOBkF9UCtB8qHwP/TOt2RVUgS6 GxgM2Yvie+SQCKv9u/J+IOmUHJikOITwoCdA9XDv1k279G8NrqzdLT+waGKyvujsQ2S5 DBjcAxgoacIaR8/fFMYkjhaVtJh5xQqBTG3w3uiR7s4GlqhjZSCC1/RtVAZ4RadDEDry SebG+FtYL9PxnufQJOz1yEG8+dPycz0pNictTKhZSh536KjTGoGrLHGR641MKXneu/9r en4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796129306; x=1796734106; 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=EYcqrSXqj7lFIKQnsCl0fbob+PO3R+PToOizoKrYky8=; b=NfbdpQaX6GWrTapM3byz9tp60xDK4Mk5VgkbeqlzyEwx7miLnvG4OC3JxdVjK+F1hU Ti7f06nlM8cu8i39QcoQ9h+u0Daen+Ek+XoVBmfv3C0Fl4COp9RvXd/j5OPWwOq3V1KC S6TpeXRzFkizg4qVt9pVejkdA1Ck4ysMGU8CoBFPV24Hi8pdNZFOzvgAEAqgbf4w3dWG Fy4S05gCeaB99zPOxO+h4cmw5cdAIa8D9In+BRnWsNr40EkmUgs6jKtWW9Inm0yUOJ4p okfv18O36EX4MRaJ1ZOW8GeE9tgf0Z/6XmIM96ms+kxpkTuRtj1B/CjgJaniiQxY7iIa mxrg== X-Forwarded-Encrypted: i=1; AL+hErFE87jrFP3QfAMkfRZUICBJ6DvFMRJXfSgF4ekHINr9sLZojIlwMxDt9SffuEN+hEaKUAuvmgrwMAqeShg=@vger.kernel.org X-Gm-Message-State: APuU4Z/mETuQrQfCoI07b0YLTD4G2ZhcKpaXwiG27EVs1p4pdrRTTnJ2 UtfA4HlqghxyBdBzGPCE2vkWBXJK2QgSZG93AIQRjDN0cYI95hMRGON2T01zCRWVU8XwVsSmxoV BWFyPwq+HAEl0xlALr8W00A9cFpNemf9Smgqs6ucz3+tz8TdbsEkegxMLprkuSio1s/c= X-Gm-Gg: AZFdTZeblsIiog4aazgM8cRcbutJo34617DybfGQfZbwgkkhifFPoQJBKFLiQifGmVn 9x0e751TmQbuzL3Xo6qw6h0b9/TXQhE4N4yqvZ7rpNH2MCnh0Xim5uY1dyTMiMijKVRAzYD0oSH zSblMPARFiJ8Kd7NohImiEnGXQnSHM+LCqVYAgsjeNcfIQt6hAaI0BieNmwA0obqTbroZX+Nf/Y oysz9vYzASRQy1v02cekkvlvXU4hJmUW0VjQba1XhiumzbP8c6qGLi5gI26S7FScSSt8SzTfsFY ypy8UUJrsNW2AXRmZRxUQuDluSVvUyaPaesyUyqgO3kYbX+ufFEjJYUOn5ndcbQGsEOSTDbpILQ OuSoEfUo+w2KxSjsyjaDvyGbtWb2MnkyOjWbJ7qS+tmSxTZzJgBZZ3dP+DSxrIzXC X-Received: by 2002:a05:620a:2945:b0:949:6f9a:c049 with SMTP id af79cd13be357-949ba9e3599mr6749296585a.32.1796129305752; Tue, 01 Dec 2026 04:48:25 -0800 (PST) X-Received: by 2002:a05:620a:2945:b0:949:6f9a:c049 with SMTP id af79cd13be357-949ba9e3599mr6749292885a.32.1796129305283; Tue, 01 Dec 2026 04:48:25 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9687sm1131892375e9.10.2026.12.01.04.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 04:48:24 -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 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Date: Tue, 1 Dec 2026 12:47:42 +0000 Message-ID: <20261201124753.196748-14-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: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX55K3R/AWGZ+v MHK4pG9svuPMcgAu195nZvH1Zp8EuEXukL4g0ZTK6CtRJL+jZNSyFQn/7eUSrHTuig7RbKEA0u5 w1k2LJR7IqocjM5SiZEP5bTd2P7sgSw6lIMhJenemVmElAn5mNyw6rb60x6icn1G7K5JD1SVYDx KjQ/PMpqkgB+f+a8lKMur1sqDyH4Yj8Uscg+6CGKuM8RNaLVVZ14+gPaVRIUsDwH0oDMtBRfmYM r3Gg9u5EsIKu/GA4qj6bIfGmbE/Y7LoL6JsGk9hcUYuCbvoxOo0/z5JeNSkK0xP56QLtl4qrox6 zwBUyH5022oV8/dII2qablnCMvTpY2wKzkleoH3I0GcL5158ohfQ6OPIwhUyKm3BaSU69Kz16MV Tx7tufFcWULZXXjVIOZSdoPlxUZ9+J4RHBDxZbmlR87ldIXGBviuDEiR9yb7F699L1jRMm0Moft t+IkyQSVslwoCgUGAyQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfXxSIhKfNU25EF 97sBmaMRoMMgQjzAnXjGtfJaxcis58ISppX9vgL9xx/PLAsCI7MdLt2ph5DYDAU6PQO1sT72JZT 8TD8H1+dgD3b17p+cZeh0K9LCOm1POI= X-Authority-Analysis: v=2.4 cv=Cqoq4X4D c=1 sm=1 tr=0 ts=6b0ec21a 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=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=o0P8GHkSdPkt1DrcKHsA:9 a=PEH46H7Ffwr30OY-TuGO:22 X-Proofpoint-ORIG-GUID: 0_nlRhpoWjI0j1CpHY9wPghMOrSN8G4G X-Proofpoint-GUID: 0_nlRhpoWjI0j1CpHY9wPghMOrSN8G4G 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 From: Ravi Hothi 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 Signed-off-by: Srinivas Kandagatla --- 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 c48ba63448db..dd0b70013a0e 100644 --- a/sound/soc/qcom/qdsp6/audioreach.c +++ b/sound/soc/qcom/qdsp6/audioreach.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -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 */ @@ -1456,6 +1459,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 || @@ -1562,14 +1607,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, @@ -1613,6 +1660,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; @@ -1636,11 +1684,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. */ @@ -1664,7 +1714,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; @@ -1755,8 +1805,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 062727d09612..bb632d3ca0a7 100644 --- a/sound/soc/qcom/qdsp6/audioreach.h +++ b/sound/soc/qcom/qdsp6/audioreach.h @@ -1113,6 +1113,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