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=1796073810; b=jbrl03a72JZ9j3t+WsnqEraY8O9z1ZCqsNyz1qPPNedYtPNcednEQo7LjaJjoFHp5xI2 vZ0CoiDwr2vD6Qesq0Zpt7h1cdj9AFiJJQnkHE6x+SgwmhXfFK/muwjBawJ7psCc6kPUE oUT13PawU8GiyLgza6bvJrQ8q7FLPXoupfe0nu2Zxh0XVQWWvKcUjHXjfdSwhgUH90CW8 Jsvvynghj7oUzWaeZLroMtkaUUFx4DIVOuYULl2BEMCAeY5KEIyPLXAv1XiGhErsWpsUc LooaITgPVKjbEl6CPhD+Yi0IoAulD/e5+Lopp2NbYGdsBnaflR2TUE87Ah3Th/MZbXQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073810; 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=Wf89pT31Kdh1yExYrq6GyJjLDWu7pImGlA1nLeczhnc=; b=VR98pqy+i+TeE3p/mJDss2YgmKshojUKEz0zkHriwXL+G4ZOAjUevOh6M4MofC7AoBpq eUuSWgaMacXXSl4lo/5lpK8mK13RCvYlI+RL65wpmhqYFbEAiQR3VdSsfzUD3WX1Gn+SI kt6COkem9M1ye7UTnNr75jF1BepaXIVoxoZjNK+DoPQhb783+z/AcaHCla6yOVTAEkWw1 t/Q2hB63LVMHVUBQv/0L7B8NtCbdeL60wERYNPEJr9Uhy1O92GTKd5BC6W1YqOtWnVaxT go+EeWm1FNkZfWSi6gj0mY2Cn7fc7Y6zyJA1ZxZ2baCWzY1McebV0QgwzaPVCIsJMQw== 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=ilzA5k0o; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b="Ns82zY//"; 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 31473606A338 for ; Mon, 30 Nov 2026 21:23:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 31473606A338 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=ilzA5k0o; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=Ns82zY// 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 6AUKQOUI3186566 for ; Mon, 30 Nov 2026 21:23:28 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=Wf89pT31Kdh 1yExYrq6GyJjLDWu7pImGlA1nLeczhnc=; b=ilzA5k0oTWe+fst1ksAYdzzGN0h aAuOU1I0bayJaVlp24KuMkGojdPpLSaYfA2wzVWihwySjkOEBIzS0rincJttnQxy OCBAYziwUCOvodFjALLjLenR/h0nhyBLs0lrsP/KbHpVC0LxwQKbDJwPFt+iJZVw NoE6bE4Q+u1/2i5jhWsFj3+vKkTNvisJy3vGkjw5Qhv9hSsXYazo2e9XYR2R5idP Xk3Y9RL2y2HQmSYmaETAnn5BDg7K84Pemb5oyAg1IP/zeRrTRDBGpH2JjQywI/up ef/8vLnku6jDdBGehucZZ4zgzygQ0w11MlithkYpxaLvwGkF9ou+SQH0UqA== 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 4j94wfu9ur-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 21:23:28 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-94967c6d4f4so1237322485a.2 for ; Mon, 30 Nov 2026 13:23:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796073807; x=1796678607; 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=Wf89pT31Kdh1yExYrq6GyJjLDWu7pImGlA1nLeczhnc=; b=Ns82zY//bJHQfciANL5kX6MFY36jnrQMT1IN/98GWmOe3iiaWobgiAs7KFRGpO7DCx YdYfbs+GFnILY2e+dzc+Ab/VWR2vtH7815YtVHirD0xvPRP5uqjjXLa0RVdm4hHsKDgO ngAGBTJZTaLEDOZgd2DeC69q9igWSbv7aFVZ0vYHpdsPOS5yiCpR0+c6WhdMxNV/yR0V ZjBX0tnpYWlxlg3avoXAE/XMifQCrcUScVDNHEcLa5IcJCVqz6H0ubgPkH1LNTJobncu t///WrJd457qUiSw7HPp8kb0MsUU97cicplJamuFEav4Su+c6bcszJnr1wNlEuRRVS+Y 2f1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073807; x=1796678607; 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=Wf89pT31Kdh1yExYrq6GyJjLDWu7pImGlA1nLeczhnc=; b=XyFPsSYLMyjjYtReHppC1RPI2FdnUK1V1ndxSxqKkpw90LVJFrqkLyd0UygKvSGXcD fSJxQNa7GGX1EEdG1rUystvaaWHPfROnmdV1jspVlI4RwXe5swIOxf7dxXK/fx3Nq+1f JpSeEmb1wUd8rVBROqKHgGOuRDK+h40d521t6gdx0mBMio+AYyzrWSlxC80eNp3ga4h4 sFCJlngfakDfzai8U0YAdYlCQanZHbsZFxUGSNIPdZ6Qcmz0/PdY9MScwxnOwQH8tTs6 TaW16v0iwEldqlJlDVcFEmRvJmII+dHuAgS9AxLCSaF4cuRy8V/vJ8bDrw9+tNpIPVAA VYTg== X-Forwarded-Encrypted: i=1; AL+hErGCPPQf51RF8N+8JIA9JY+ptjuT/ZSzwYjvJH1G2r1shWJ7A2sfZBtq4ohT2lkIw+zQ6aHWipG9DoiY/Ms=@vger.kernel.org X-Gm-Message-State: APuU4Z82dY+7knP3ex2mVF69DFdGi8V5iUgzZRqsHBYdRsyR0EhIgDZP Qt3+EUD995U7/i/U7i/o4ZcJWAh9wn3IQU6sSu0y1WV4gZNITYpJ7s9ZCvHkEdSnDyEIlrPC8kE R4cnu57tG8OGEhaVCOWvwvOhqDSvLnU1vuJf2GhAyyOWWWWJ03vwyoFpMaahXxjcoXOM= X-Gm-Gg: AZFdTZf3vejiV0VsUh2DoL6gCha0KgWcFkN+ZAamq8oorw7laVHSWO1hEing5/U8F2r 0re0LqfofIsroHlied5qVpmWuN30GfsUt+U/z56OBTNIonsi2FqYO4+5VRJ78huYhHascEvyT2Z MP9EeIQKx88h7u7NPbRBP8/Nb++8lORClRqZRPMIe0XsjmSBWTuwCiqQtSiX/ZZJ9Jbd2wxG/Vi jodzY7jdfE+Vv7Pr+2UnyE9WKktOQughlH1KmzMS2Yh2RORErzL78QHbx+E4pj42u5lvrj0XKHR dj55ZDgXWXArXOuQeHxOW/q4DL5R1H6rBFccH6vMr4dI4etTzx9ch8tjV9uQr3+D+iyGg0lKTEW hsEsj0W+dcCsSn1nBu9dJ1o7TJIPayxiLARBeYM/kX+FvGL0miXmlxMNabbQK3Fwe X-Received: by 2002:a05:620a:7209:b0:949:ea91:b4e3 with SMTP id af79cd13be357-949ea91b849mr3747365085a.50.1796073807385; Mon, 30 Nov 2026 13:23:27 -0800 (PST) X-Received: by 2002:a05:620a:7209:b0:949:ea91:b4e3 with SMTP id af79cd13be357-949ea91b849mr3747360185a.50.1796073806782; Mon, 30 Nov 2026 13:23:26 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm792580515e9.0.2026.11.30.13.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:23:25 -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 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Date: Mon, 30 Nov 2026 21:22:44 +0000 Message-ID: <20261130212258.7376-11-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: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfXxJ8UTyriPYJM yvoeeWVtzdVcV0C1XStXJK4CZCzYEynaD3AcC3VJhCJfhySd16adxRenciZ/ZPFUd9s5C2DLdyb e93VR/Z0gkE5oURKmb842jv7gSBtI4o= X-Authority-Analysis: v=2.4 cv=BZ1NQbt2 c=1 sm=1 tr=0 ts=6b0de950 cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==: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=5EnwkQkph5nfVeabW8IA:9 a=PEH46H7Ffwr30OY-TuGO:22 X-Proofpoint-ORIG-GUID: QPcSd1CFGanh-k1TFVuhMnzm5f9Vl6Sp X-Proofpoint-GUID: QPcSd1CFGanh-k1TFVuhMnzm5f9Vl6Sp X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfX4Bj0py+lHuxT Sht6nR9YesbLKkQLyJdiXhV7PiUnAZ/k+kzsaIm/LIRhO2n1m4rutrXLVp0tukvkikx9dHLaLVs bP9yTe5vxrKFJ1QfTE+88JCyWmp7Jxq5gKRhOg+d7jJwwCuX0ehrNQXTrmY7GsP5yG+bQpUToPx /Me8/+NONR33dRMRnQbhUs/CqhZDQVzIdmVuZ1c3dkUkp9z9bJ3mahd4FjoTVEARXKSvel/KUFj utnf4LCUtzgWwySkGHBiBBGTOB2mbDC+sVb5R5+e6d4eEfqk9gcMhwuiK9PTaRUdbOubYQizPx0 1qGOLMzz+SkauLToYs0nKEpVsgEKSLfdDL+C4ZrGVoIAHBpmo7jdzXaij1lzDpPuYCg/tNimLDo ysRnGQJXkM6rlmv0aeT5olZKwGDDmqPR/VHeJ8rODDtGnwx7fq/xH9BGE54u+cJ+8bYBlKyPCLs 242sXtrvCF8XmHaQxQA== 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 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 afa8e0159570..fbb9e3c4b84a 100644 --- a/sound/soc/qcom/qdsp6/audioreach.c +++ b/sound/soc/qcom/qdsp6/audioreach.c @@ -1462,6 +1462,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) @@ -1470,6 +1482,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) @@ -1480,18 +1521,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; @@ -1509,8 +1562,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; @@ -1520,20 +1574,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 < AR_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 < AR_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; @@ -1607,7 +1656,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); @@ -1616,6 +1665,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 0ea035fa630c..9d9449062b83 100644 --- a/sound/soc/qcom/qdsp6/audioreach.h +++ b/sound/soc/qcom/qdsp6/audioreach.h @@ -696,6 +696,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 @@ -720,6 +722,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; @@ -1060,6 +1114,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