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=1796129303; b=N0D2iqRJOUwy0s0xFoNzX68rxQGbEzdtbtBHGf0qIZut/ffre6R277mWd+rVyAb/8+Mk rjDASPhy4229F38G6x4mkHlOYl/NQTO9OdAcv0S7wkqib6wuH28g9vziwYfOc8qSfJmX9 3LIWGvKVPRHxW4vNCE+kA0X7s1PE3n9uaYowGrhi78sUOtsFqAdMtd0onvxYRdmvcFm39 Q7Q46P2CY/62/5B+j8TkFPm/uqVV1dZup+YqYrd+wwxB+S6uwLBj1YjWPKJwQ3+w8sAUU 6jDMRp8VGjRTta/Oc2xPjtzi83aSjbStuPJrhCIVsbLtqp+LICwLpFC1ZR11OVQVdAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129303; 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-Proofpoint-Spam-Details-Enc:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=S8EF2oBMICJmFsJgOHFVQWYbcV+2xVqcvtLehHajSUs=; b=I3FmW2uViksd56vQetWIOdCCv67V18GD2/UbdhYuHTYGZb6a5+tf8a6f3Ts5dOUOKr1E TpAYWkIDT3150hUPSo10oMmZz4TT8Hz+HmOIMiEykWypeZWoHFr1DnyXgS+c3A3LtKXN+ 7fep9cqk5SyGYbFZ5bBFk2/8IYVcj1XJJ75iWO510h7GaUuRX48zDoUXJe60Vzh5MlMv3 Qap03odp6Ps4YHaEXUYA/B/u7DRLKMZQRUAb0zi+GdaXeFKaifNrSllbXIgRkKciA0F0Q vrodRhsrIeI6jSByEWutwjguDP6pdIvWhKbW6RysbYYP54jjdZQB8zTfR8g1OTK7GwQ== 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=eBecoK8b; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=SQm+nEo8; 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 42A1260A3829 for ; Tue, 1 Dec 2026 12:48:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 42A1260A3829 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=eBecoK8b; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=SQm+nEo8 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1AQPM32313359 for ; Tue, 1 Dec 2026 12:48:22 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=S8EF2oBMICJ mFsJgOHFVQWYbcV+2xVqcvtLehHajSUs=; b=eBecoK8bzkqtPjS66wo4neSdXMy NNCoUXSCC5qTWakgTtqSwOficPmvdCL+HKuHT2vwsw8F014n6fNOLOMHO25fMYbD ulspYhIskoKRL06yg4l/WG2+xQCgsQOvIfD7w9hGEIkcHl7niu85SFapvLBtsSBc vYH77uEuEIMhobtK0vAusxxIk2btZBVYzzvi4yvWItRpx2QBvKf+FB4IE7xUWVq4 9J+6MBo0eUFJHoOtY6OVmSslezk2d0FRZ53f+7bR5C3kY5OYVV8l+j/LfvB2dzJC kl2CTL+WIQlj/2ezQH+Fhs3Xjwc4R5/x5La7puNAfoVBWxXR9j/nw5FNxRg== Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9nb62c5x-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 12:48:22 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-93f37c94ceeso1978112485a.1 for ; Tue, 01 Dec 2026 04:48:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796129301; x=1796734101; 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=S8EF2oBMICJmFsJgOHFVQWYbcV+2xVqcvtLehHajSUs=; b=SQm+nEo84cwoNFdlayXfp4qs6mCrDoJNCNI8EL9/5MlaZxJcxsenIeuwcTGu5sCMjC bFBpzUmRiXxOi7grBMaua7witNzaM/0eXgVe/K538oEf1/95mUd9IyCmDs9QQBb/98/L kzTI8dYVe+NOPwMcAdxS1PKT4Dfz16+KWHr5bo01r6CAQ3TMoL3U3YRuxKTlQ/U2r60p cD4JSZpca9pHsqMP/R+yif87y3YFppGBuR1MgfYbv5uEb82VGaaA4F7751/JyPTsmW2B 27av2S0PM3L5gK8hFTSgH/BfqzpH3leqwZ2xxqmG8XIuqO2exHWXbj9w9XqRwd6xLNA6 h9tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796129301; x=1796734101; 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=S8EF2oBMICJmFsJgOHFVQWYbcV+2xVqcvtLehHajSUs=; b=QmvakjnSc3Qyh6mpheyL1qTDmLHGTeNUGn6Pv93hwSuj/D0yPvFIps1PxxPWJJ9eY6 XxayDCI/8PcYh1/vYgmyIMxj26rhuEf+JhsvTyxqABFBmGOa8Ac+aydr5FyOEu+FUsiL 8Fed+qeY2q3vPZBl+93jSLfm/YxbdCS4Wts/ZaCWiJyULkMJI/P/lg7+dJZpt5t+lCnm qUIhvdYdJJ7jhIyIiwmkTfhfSdNOk7hlj6I8MgjFNmM2gEGga/a3QwlWX2LOZ3x9T0cq sYn9LOQD5fS7fZ9mQynRVSQJ9Id/nTp+Y/527aNjosWd2llNJbiMf9l2N6CK4IV9H3t/ cacQ== X-Forwarded-Encrypted: i=1; AL+hErFaT9FOLA3WyU+LX31oer8UgpBL9c8s0AS0FuyJl+djv2LkB4XBwk9l0bVHw/OEMQdLGiZXM1P1xBFn/bA=@vger.kernel.org X-Gm-Message-State: APuU4Z+718mVcrzfE2vM8ltkWPeIvWYuDG9OPPBsYK9E/L8mX52ROo+j UqpHw4obS80hPdE5MrPCalydxldkzHx3fOEf/0kHtyiQ+SF70Z+xnWW+Pk7kc03doMwO8Q+DTwM x6h+psN4w8bwSwV91uYtj36veY3TRVkhZkGCqyKJGeNRrMLFm8kp92euB4ZZaxWORNp4= X-Gm-Gg: AZFdTZeRxU9X4QcoI5N44yeHEd4yzOikzfdp5jYyEScIaUC7LgcrA0CNyNhQYeYSBoi 3KIJQ9gZvoHhP127gqXVnqGUQ+T9O+m9tQR4Va2eytLJ9lAKGMTlp5bAcxWNNWUoHmVj5oXieKD IRSYOuImzJdteY8P3ucBelQ93hU9YnAlj5q6gX5GGtndNQrBTaBfNt3MWPrxEzHCE6dzxicXxDx dpuI4DZ42CwAARldyPX/d8ncOOaGvuxe8sxWy9XFSm1KYw2IAYJi4kGBUVuo9i0f04fo7w5Sy6L g791Wk2DpPTpcMIZ1d7/JghBW5pCnee4e5USH1vKC0M+Ka1EDCJ0TNaDUx7jWPyycZNvlE/1JFb ZazShkZmoDedxOb5V2b87mim5b51SeOvwKwUBDJQTibL6ST5g7BrlJKXpCV69z6EI X-Received: by 2002:a05:620a:2986:b0:949:aceb:b799 with SMTP id af79cd13be357-949b357272amr6710602985a.13.1796129301414; Tue, 01 Dec 2026 04:48:21 -0800 (PST) X-Received: by 2002:a05:620a:2986:b0:949:aceb:b799 with SMTP id af79cd13be357-949b357272amr6710597385a.13.1796129300836; Tue, 01 Dec 2026 04:48:20 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9687sm1131892375e9.10.2026.12.01.04.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 04:48:20 -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 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Date: Tue, 1 Dec 2026 12:47:39 +0000 Message-ID: <20261201124753.196748-11-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-Info: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX8tuFumpSsBPX Rwu9Cuixxp3vSlY8cEVWw18TyIyjVuZs8iwumhL7Qs5/OWbZZSv9HPVoEKxruVCyNY0Dvyx/G3Z UgcDZPHBFJ+UFJ8oH8ig/hvZrUwzP5E= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX3zRKnSpQvVc9 xGNo+6g7OLEA3JumDx+sEVUOZ+qv62U4lPwEtdq1fLsIpn/Wi5XlAaQTtXNxrOAQZrIgorqo0+c JcC/8hTyYvA0F+3xcw99VBUZHwFk3/U8XBJQGvKNgi9E1LAdslK8njkssXQwdQD/HVHT/yQFZlC qa+aRPOFJ8PkSOxYT2iZHexKyzanwz509dY1L+n59okCXOdIY323ACkoqdoDMAZlGwkKLHOz39a M5EnU0fpSWrUNYL8REwXMKkYdhuVnafXx8mCVYLklJL7uWvWFlVtnExMSHjIhGd6LmNq7zazsss wHiw8BriUQeEWrAfEgxGQBEMCxRYJhpOAoKj3jFCaBLNYUCItLO5cKDKOpzXo+T0AdfYi6Pm/Dm XWJ373mvwHHoq2kg6uAzMgYwHqU65V6bbVrnYTOvMZWst41OEX329PIrSMAQWSY6r5ZbjUlkZTN NTdZ46LoNymUV6T99QA== X-Authority-Analysis: v=2.4 cv=fc44WEQF c=1 sm=1 tr=0 ts=6b0ec216 cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=5EnwkQkph5nfVeabW8IA:9 a=bTQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-ORIG-GUID: N8SAEo5wf_Xk07fwzyGuh59_ERo3Bh5k X-Proofpoint-GUID: N8SAEo5wf_Xk07fwzyGuh59_ERo3Bh5k 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 malwarescore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 clxscore=1015 bulkscore=0 priorityscore=1501 spamscore=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 Put the speaker protection and VI modules in calibration mode, number the V/I channel pairs consecutively (the VI capture packs one pair per speaker without gaps), and support up to MAX_SP_VI_SPEAKERS (4) speakers to cover laptops with four WSAs. Register for EVENT_ID_VI_PER_SPKR_CALIBRATION on the VI module so each speaker's state and measured resistance are reported on their own, and dispatch the event from q6apm's graph callback into audioreach_vi_calibration_event(). The initial handler just logs each event at debug level; later patches add result caching and a userspace trigger on top. The module event registration is scoped to the graph: the DSP releases it automatically when the graph is closed on stream close, so no explicit unregister is needed on the driver side. Signed-off-by: Ravi Hothi Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/qdsp6/audioreach.c | 86 ++++++++++++++++++++++++------- sound/soc/qcom/qdsp6/audioreach.h | 57 ++++++++++++++++++++ sound/soc/qcom/qdsp6/q6apm.c | 26 ++++++++++ 3 files changed, 151 insertions(+), 18 deletions(-) diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c index f66d3ff68a44..aea482270c26 100644 --- a/sound/soc/qcom/qdsp6/audioreach.c +++ b/sound/soc/qcom/qdsp6/audioreach.c @@ -1436,6 +1436,18 @@ static int audioreach_gain_set(struct q6apm_graph *graph, return q6apm_send_cmd_sync(graph->apm, pkt, 0); } +void audioreach_vi_calibration_event(struct device *dev, + const struct event_id_vi_per_spkr_calibration *cali, + u32 num_ch) +{ + unsigned int i; + + /* 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); +} + static int audioreach_speaker_protection(struct q6apm_graph *graph, const struct audioreach_module *module, uint32_t operation_mode) @@ -1444,6 +1456,35 @@ static int audioreach_speaker_protection(struct q6apm_graph *graph, operation_mode); } +static int audioreach_register_events(struct q6apm_graph *graph, + const struct audioreach_module *module) +{ + struct apm_module_register_events *payload; + struct gpr_pkt *pkt; + int rc, payload_size; + void *p; + + /* No event config payload, the packet is zeroed on allocation */ + payload_size = ALIGN(sizeof(struct apm_module_register_events), 8); + pkt = audioreach_alloc_cmd_pkt(payload_size, APM_CMD_REGISTER_MODULE_EVENTS, + 0, graph->port->id, module->instance_id); + if (IS_ERR(pkt)) + return PTR_ERR(pkt); + + p = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; + + payload = p; + payload->module_instance_id = module->instance_id; + payload->event_id = EVENT_ID_VI_PER_SPKR_CALIBRATION; + payload->is_register = 1; + + rc = audioreach_graph_send_cmd_sync(graph, pkt, 0); + + kfree(pkt); + + return rc; +} + static int audioreach_speaker_protection_vi(struct q6apm_graph *graph, const struct audioreach_module *module, const struct audioreach_module_config *mcfg) @@ -1454,18 +1495,30 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph, struct apm_module_sp_vi_ex_mode_cfg *ex_cfg; int op_sz, cm_sz, ex_sz; struct apm_module_param_data *param_data; - int rc, i, payload_size, j; + int rc, i, j, payload_size; struct gpr_pkt *pkt; + u32 num_speakers; void *p; - if (num_channels > 2) { + if (num_channels > MAX_SP_VI_SPEAKERS) { dev_err(graph->dev, "Error: Invalid channels (%d)!\n", num_channels); return -EINVAL; } - op_sz = APM_SP_VI_OP_MODE_CFG_PSIZE(num_channels); + /* One 32-bit V/I word per speaker, so channels == speakers */ + num_speakers = num_channels; + if (!num_speakers) { + dev_err(graph->dev, "Error: VI needs at least one channel\n"); + return -EINVAL; + } + + 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. */ - cm_sz = APM_SP_VI_CH_MAP_CFG_PSIZE(num_channels * 2); + cm_sz = APM_SP_VI_CH_MAP_CFG_PSIZE(num_speakers * 2); ex_sz = APM_SP_VI_EX_MODE_CFG_PSIZE; payload_size = op_sz + cm_sz + ex_sz; @@ -1483,8 +1536,9 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph, param_data->param_id = PARAM_ID_SP_VI_OP_MODE_CFG; param_data->param_size = op_sz - APM_MODULE_PARAM_DATA_SIZE; - op_cfg->cfg.num_channels = num_channels; - op_cfg->cfg.operation_mode = PARAM_ID_SP_VI_OP_MODE_NORMAL; + /* 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; p += op_sz; cm_cfg = p; @@ -1494,20 +1548,15 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph, param_data->param_id = PARAM_ID_SP_VI_CHANNEL_MAP_CFG; param_data->param_size = cm_sz - APM_MODULE_PARAM_DATA_SIZE; - cm_cfg->cfg.num_channels = num_channels * 2; - /* Convert the physical mapping to a logical mapping of the channels */ - for (i = 0, j = 0; i < PCM_MAX_NUM_CHANNEL && j < num_channels; i++) { + cm_cfg->cfg.num_channels = num_speakers * 2; + /* Number the V/I pairs consecutively, the capture has no gaps */ + for (i = 0, j = 0; i < PCM_MAX_NUM_CHANNEL && j < num_speakers; i++) { if (!mcfg->channel_map[i]) continue; - /* - * Map speakers into Vsense and then Isense of each channel. - * E.g. for PCM_CHANNEL_FL and PCM_CHANNEL_FR to: - * [1, 2, 3, 4] - */ - cm_cfg->cfg.channel_mapping[2 * j] = (mcfg->channel_map[i] - 1) * 2 + 1; - cm_cfg->cfg.channel_mapping[2 * j + 1] = (mcfg->channel_map[i] - 1) * 2 + 2; - ++j; + cm_cfg->cfg.channel_mapping[2 * j] = 2 * j + 1; + cm_cfg->cfg.channel_mapping[2 * j + 1] = 2 * j + 2; + j++; } p += cm_sz; @@ -1581,7 +1630,7 @@ int audioreach_set_media_format(struct q6apm_graph *graph, break; case MODULE_ID_SPEAKER_PROTECTION: rc = audioreach_speaker_protection(graph, module, - PARAM_ID_SP_OP_MODE_NORMAL); + PARAM_ID_SP_OP_MODE_CALIBRATION); if (!rc) rc = audioreach_module_enable(graph, module, true); @@ -1590,6 +1639,7 @@ int audioreach_set_media_format(struct q6apm_graph *graph, rc = audioreach_speaker_protection_vi(graph, module, cfg); if (!rc) rc = audioreach_module_enable(graph, module, true); + break; case MODULE_ID_AUDIO_IF_SOURCE: case MODULE_ID_AUDIO_IF_SINK: diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h index ea8679e41488..062727d09612 100644 --- a/sound/soc/qcom/qdsp6/audioreach.h +++ b/sound/soc/qcom/qdsp6/audioreach.h @@ -697,6 +697,8 @@ struct param_id_sp_op_mode { /* Speaker Protection VI */ +#define MAX_SP_VI_SPEAKERS 4 + #define PARAM_ID_SP_VI_OP_MODE_CFG 0x080011f4 #define PARAM_ID_SP_VI_OP_MODE_NORMAL 0 #define PARAM_ID_SP_VI_OP_MODE_CALIBRATION 1 @@ -721,6 +723,58 @@ struct param_id_sp_vi_channel_map_cfg { uint32_t channel_mapping[]; } __packed; +/* VI per-speaker calibration event, raised every frame in calibration mode */ +#define EVENT_ID_VI_PER_SPKR_CALIBRATION 0x08001511 + +/** + * enum vi_calibration_state - Calibration state of one speaker + * @VI_CALIBRATION_STATE_INCORRECT_OP_MODE: Not in calibration operation mode + * @VI_CALIBRATION_STATE_INACTIVE: Port not started + * @VI_CALIBRATION_STATE_WARMUP: Warming up + * @VI_CALIBRATION_STATE_INPROGRESS: Calibration running + * @VI_CALIBRATION_STATE_SUCCESS: R0/T0 within range + * @VI_CALIBRATION_STATE_FAILED: R0/T0 out of range + * @VI_CALIBRATION_STATE_WAIT_FOR_VI: Waiting for the V/I level to rise + * @VI_CALIBRATION_STATE_VI_WAIT_TIMED_OUT: Gave up waiting for the V/I level + * @VI_CALIBRATION_STATE_LOW_VI: V/I level fell below the threshold mid-run + * + * Reported by struct vi_per_spkr_calib_param.state. The DSP chooses these + * values, so they are fixed and must not be renumbered. + */ +enum vi_calibration_state { + VI_CALIBRATION_STATE_INCORRECT_OP_MODE = 0, + VI_CALIBRATION_STATE_INACTIVE = 1, + VI_CALIBRATION_STATE_WARMUP = 2, + VI_CALIBRATION_STATE_INPROGRESS = 3, + VI_CALIBRATION_STATE_SUCCESS = 4, + VI_CALIBRATION_STATE_FAILED = 5, + VI_CALIBRATION_STATE_WAIT_FOR_VI = 6, + VI_CALIBRATION_STATE_VI_WAIT_TIMED_OUT = 7, + VI_CALIBRATION_STATE_LOW_VI = 8, +}; + +/** + * struct vi_per_spkr_calib_param - Per-speaker calibration result + * @state: Calibration state of this speaker. + * @r0_cali_q24: Measured DC resistance in ohms, Q24. Filled in regardless of + * @state, so it is meaningful for both VI_CALIBRATION_STATE_SUCCESS + * and VI_CALIBRATION_STATE_FAILED. + */ +struct vi_per_spkr_calib_param { + uint32_t state; + int32_t r0_cali_q24; +} __packed; + +/** + * struct event_id_vi_per_spkr_calibration - Per-speaker VI calibration result + * @num_ch: Number of speakers the result covers. + * @cali_param: Per-speaker calibration state and measured resistance. + */ +struct event_id_vi_per_spkr_calibration { + uint32_t num_ch; + struct vi_per_spkr_calib_param cali_param[]; +} __packed; + #define PARAM_ID_SAL_OUTPUT_CFG 0x08001016 struct param_id_sal_output_config { uint32_t bits_per_sample; @@ -1059,6 +1113,9 @@ 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); +void audioreach_vi_calibration_event(struct device *dev, + const struct event_id_vi_per_spkr_calibration *cali, + u32 num_ch); 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 968fb7898aa4..c410e2f6e6a3 100644 --- a/sound/soc/qcom/qdsp6/q6apm.c +++ b/sound/soc/qcom/qdsp6/q6apm.c @@ -562,6 +562,29 @@ int q6apm_get_hw_pointer(struct q6apm_graph *graph, int dir) } EXPORT_SYMBOL_GPL(q6apm_get_hw_pointer); +static void q6apm_vi_calibration_event(struct device *dev, + const struct apm_module_event *event, + int payload_size) +{ + const struct event_id_vi_per_spkr_calibration *cali; + u32 num_ch; + + if (payload_size < 0 || payload_size < (int)(sizeof(*event) + sizeof(*cali))) { + dev_err(dev, "VI calibration event truncated (%d bytes)\n", + payload_size); + return; + } + + cali = (const struct event_id_vi_per_spkr_calibration *)(event + 1); + + /* Bound the array by the received payload, not by num_ch alone */ + num_ch = (payload_size - sizeof(*event) - sizeof(*cali)) / sizeof(cali->cali_param[0]); + num_ch = min_t(u32, cali->num_ch, num_ch); + num_ch = min_t(u32, num_ch, MAX_SP_VI_SPEAKERS); + + audioreach_vi_calibration_event(dev, cali, num_ch); +} + static int graph_callback(const struct gpr_resp_pkt *data, void *priv, int op) { struct data_cmd_rsp_rd_sh_mem_ep_data_buffer_done_v2 *rd_done; @@ -585,6 +608,9 @@ static int graph_callback(const struct gpr_resp_pkt *data, void *priv, int op) client_event = APM_CLIENT_EVENT_WATERMARK_EVENT; graph->cb(client_event, hdr->token, data->payload, graph->priv); break; + case EVENT_ID_VI_PER_SPKR_CALIBRATION: + q6apm_vi_calibration_event(dev, event, data->payload_size); + break; } break; -- 2.53.0