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=1796073815; b=P859HD3D2BuhFT9sRgmJq30GdUnMkcrwfAesxgTDkD0fTe2Ox3HtEE0kSeKebaVCfbaN Kl8KVqya0wVxFlPlvMeIPyem3y/ScjBGKIGG5S97ms4Jgqfo7gfSiE/Uuigi2qXGkL7Ho 7rewIgNIteOlvAOBN1Xd5FUIcZUi5GBN+a6a0G4fo4mfg2nO5NGIgR3kEOgIHAqVP/myn U1X7N0nOv/zwWnksBAJAJjmyAavrAUv0kyM0i6YBUkrUc0X+qWZLBq84GZ/jVy3BmG2Jm +W5vUHO5ThYvQ6k0YVwDuMcv4kV1x5MJViiVeONwcoIeaZhQO5HHNgnLpeZ6xC9/H7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073815; 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-Info:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=Bo02fidDDIi7RXVEkPJ4luywF9zI8GuniBVZtXjrWeI=; b=JwW+uecr2jFT9nOS6rJz2DxCYh95GZL72SHkvtf0PCCV/P4kEvR4/jVhvA97V+8QIhqx KMFINbzU3krFBzPA2tWNHVxd6Qet2FtJ6wiBgliyPqFW5Audz9PxmFTqhGs6fhouhB/a2 bHKW9lUUea4/jB3FnKzhPsyyBXoV8n9uPqZSgeCcOyhNskPIbFkXRdggG34J02NHZmPBP PH3O8UskhSZ19GOZUkd/yVIuSa4GytsR0yYDCG/h0U/g79kGSMaS3MXevtxxIsONlmGQI sBd2zOMsnfbypo8v2NCfr03AhPkcp946UKd1jMYzlF8PvneF1hUWql7uBU8myiNy90Q== 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=QGSphNYV; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=eWteFC69; 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 270B0606A6BD for ; Mon, 30 Nov 2026 21:23:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 270B0606A6BD 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=QGSphNYV; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=eWteFC69 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 6AUKQM6A3186521 for ; Mon, 30 Nov 2026 21:23:34 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=Bo02fidDDIi 7RXVEkPJ4luywF9zI8GuniBVZtXjrWeI=; b=QGSphNYVyXA9/Lm3QpD1jyqZnLj u2oD7fXOY2Ntl6xTJorowbi2ud5/cy5lTtk/iAMHHPnf8IKdOTdF7mu8UDMNLvvB v5UXDInOLVtaT0OjwkZ18RMcOpRE7uiVUYXp+ysnEnrqdpzufZpld54Lam8hqU6x fn9FJ27P8GKZ9ihGJHgQg9jNG2bh8cr3tBoj6Qay2I9uT7K0BbR5/ajgSPb2RKBz xB2ucINAgXn810Nupmcw3zqyfDfI2A/lHexSKs2QicAWQtBti+QLk2x1RDRXs0Zy 3eADqX/8JvQobZ9CwfjABE7sNJhcb1bhdQHMgazQi8VXxaZsgUPaCbT5a1A== 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 4j94wfu9vj-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 21:23:34 +0000 (GMT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-93f33438950so1791052185a.1 for ; Mon, 30 Nov 2026 13:23:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796073813; x=1796678613; 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=Bo02fidDDIi7RXVEkPJ4luywF9zI8GuniBVZtXjrWeI=; b=eWteFC69BI77k/xfthJO9lZgqQQj2g+3LU+JNuKzSqa3IuGL7cOk/ArEYsuew8rouC C4+9fzjw/PsKxSJb8iaqCXBkewYkNnIVrJOHGlD445axhjDoytHkZXuXbeb4JglK/GlF Mjobse7dBRg33LEl8M6QVezOs4e1Su0NejziOV8AVVLDGsLKcSGvq6sTh3ItArE51USE XEhuAqfB3esR61TCvZfvsxKmv+rNmnROfC4BqtXdNZBe3yo7J0vob3KtLTd42h3PpxqG pL6Z9bE4+td3k2a/yGZMxq4NH3RLi25IWTxxxfZEvLj6aEuNdxBn+fu4zed+ohCNXP0P l2AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073813; x=1796678613; 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=Bo02fidDDIi7RXVEkPJ4luywF9zI8GuniBVZtXjrWeI=; b=YTPkOHafPxj+cmWJ04JP12NL6x4nDp3aOei3dFGUkf1b6743HxWhSX/DOvF4yBega+ 0wKj/zKClXtU+taAym955CH5jKgJzE2axHO9a0GWUyP/3wWfEiHByUm5myCpwYR+OOTd FionaN0qJ97J8LtLP+YQwRccz9JvsO8QS/CzBB3QQpQhuAqHUorccMNj1pqpVIj9L4wH vWk9DyWA0e/LoxsASIQvau2RI27c5P8X7hRt/9ECEvixrq5X3k3sNiPwX3eu/I66ogj6 c4pvFsqbhXFQfOdyOy4e++LxZXQWMkzGzjf8+/0Wqn78TUvihB4fvEmYh0mnAq1zB3CX K7tw== X-Forwarded-Encrypted: i=1; AL+hErG+bnYker713fJqnxiIpV7T3TALCnXs2eqRHV8T1xGE8hw4ZNyg07BvJjH1XtAt9+zpycnQk8SbJFqSkG8=@vger.kernel.org X-Gm-Message-State: APuU4Z/YOZPnoy+TJZ+zQZzDEutKD2LvH8T7v1Y7WexTkK3TY+KSgkAT bTU+MgBZNoCXvqGOLNnndku8OV/Tjc1JqJS5qMJYF9Fvod/Adfi3PaI0OHVBVBtov5T6qykV7To vuL+sAyQ2Z6xISVTD0voiAeUYQmd0YgTlcJBuNudJJV7q2skNUpVXefFpB/Yy3QOd74E= X-Gm-Gg: AZFdTZehPNRrEzRcajfU7hP5uHlQqCcqkrSwhfiolqzuePPM/GlAiksWScFTUkPh6ZB W19/IFn5VJEp9YM7vbCBSH8Fv3zm6t6xOM45bhqfXw4X9+BOJeDXC6wEAAIbn2MJBWIpyr6dQo/ SxeoV6AD0E73fJU6BO2cHOhVVdmSGbTjgCxO0UNStyMdVdJRQwTED6Kgj4ZO+uArdeT/emWte1n cO0cJyL2IBrhpQKH2ZyCnEMk/wnSJ4T0l9JmRikxflKMomNNyoszKuWQFy5ljtwChQweH6Rb18q QXHHAvjTlgaI6oxber6t+jXCeQZrTmvqINT0eCyUrWhH6NVr2VicvJXzwokjJMFTLeYbqtfY7Bb tKm6nlOBIv7MQEeBXMLVPlV0fwYIYUO5KgF2paNHBdukDkmHlwwZPQfNL4DymPBsv X-Received: by 2002:a05:620a:46a5:b0:949:3f0b:4cd5 with SMTP id af79cd13be357-949bab1631fmr6221323385a.71.1796073813113; Mon, 30 Nov 2026 13:23:33 -0800 (PST) X-Received: by 2002:a05:620a:46a5:b0:949:3f0b:4cd5 with SMTP id af79cd13be357-949bab1631fmr6221318785a.71.1796073812652; Mon, 30 Nov 2026 13:23:32 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm792580515e9.0.2026.11.30.13.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:23:31 -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, Ravi Hothi Subject: [PATCH v3 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Date: Mon, 30 Nov 2026 21:22:47 +0000 Message-ID: <20261130212258.7376-14-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-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfXxTIcI+ojXwHa a/Qn4kBiWouX2gmd+fnIfPDjBNTIJBcLM4wGtb5T2KUUyFGKoiik8pPKCo2nRcnhV5bfJUeFSFZ ynuC86FcZmuex+otbc6vyiXp/4QNXBE= X-Authority-Analysis: v=2.4 cv=BZ1NQbt2 c=1 sm=1 tr=0 ts=6b0de956 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=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=5LjmXOTvIIUa77iOKnEA:9 a=NFOGd7dJGGMPyQGDc5-O:22 X-Proofpoint-ORIG-GUID: clXxwC4PxNdJYMTtX93Hz8GCLUieYap- X-Proofpoint-GUID: clXxwC4PxNdJYMTtX93Hz8GCLUieYap- X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfX7LsqiNkm6tHr taGYM1Z16bBtoYH5rNBBgRCQuaYsrd/QI8+aEpGaXssiO/9u9GdTE4cX4S3X9FZaTUNa9R+B5EZ Y5m8ttIHzJmPGsSyNcjgaNlZSLTVbvSWFqAFV1tJm90xM0F6NFra3OOZkPApXt+Vi/Bw8syeJBW En86w/vcKClDMLNjsC/IWuDWQJO98a9C1xGHKS8qRvRmgxriPYch2KoV6nxjdD4+wA0ILsAlsH8 qI4Kv9WmqLMwJu561SgUk3HRee6nR6GnpRzXCTroCCB67zETd11VYbZTfa4vJZxFNsKiDv4PszQ 2DinlnTVkB0QDsComSVpag9wy9XCEGNRdTnCHH33MTOqQ3qTp6h70CmWN6mWrCMeHrMk2xVeCF6 uMw2wC6pXA+JQ8lBsLUuSbCOvO1szBbCRCYuBk0MPFaOLi3YWwpieSDTAxARA0Buufdfp1LqpcE iEZFWMVdbP/j91LlTbA== 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 lowpriorityscore=0 priorityscore=1501 suspectscore=0 phishscore=0 bulkscore=0 malwarescore=0 impostorscore=0 clxscore=1015 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300086 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 2b5c083b8ae5..130298a28749 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 */ @@ -1482,6 +1485,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 || @@ -1588,14 +1633,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, @@ -1639,6 +1686,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; @@ -1662,11 +1710,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. */ @@ -1690,7 +1740,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; @@ -1781,8 +1831,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 9d9449062b83..baafd3bcd0c3 100644 --- a/sound/soc/qcom/qdsp6/audioreach.h +++ b/sound/soc/qcom/qdsp6/audioreach.h @@ -1114,6 +1114,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