Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1533870lqo; Sat, 18 May 2024 07:17:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVAkpZfnc7Yg32sdAT3LnBhxWW4bEpPLASVPye6UwFQCO8sW/2Cn5niheq0BwSyjfOAdowm2mLOSysPA3GAkP40jCazn0JP9lWuK9R68Q== X-Google-Smtp-Source: AGHT+IE9IpKcWwlKAQ/DNy9nNZLzmrJAj74xcv1n/gWsYDCYEdLnDeyvmclE/0zstbYcgi3XY/Ol X-Received: by 2002:a05:6830:44f:b0:6f0:5a46:702c with SMTP id 46e09a7af769-6f0e91175e3mr29179912a34.12.1716041873153; Sat, 18 May 2024 07:17:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716041873; cv=pass; d=google.com; s=arc-20160816; b=m7VUonEwC1TSIvw9NtnIyGTh67+ch3EpLCq3+EXUgzNBjVZjx5H+iAmCp+igVlwxHs 1cQmfXVN82K38x0UZDOImoGo9aFqZg30cDouboh8q+8htZTExy/EaWYhaFNi5h8RZwrg q+mf7OshgCNd4aFPbc7C2dSEgRMCPhVcTZbzQMitx20xM8lMMZMhMqHcNJ8iN79mI08K NBAVqaggWYiVtX6r6isCDu+EvSaiYxSsfP00UMecFY/xAiJ/6r5zUZMrC7kUz4cQHoSF FMFdbRaUIxLWinKY10LWVRiz4p1M+tcclv2Mc46R/zpMR3AiDdFvmqYUgVt3qnl5VmcW 60sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=hE7bJWGco1/V2achyvapsMHYTWD7SY5fsWVMayfRq60=; fh=ABd84OJQRUrD+A12QMz3wVb/zHQYobBaZgm1K44zlcc=; b=P4UErJBMByYiSkb8R5BEpc9PXKcMI7WpT6H8CZOX0PWmH1mCJQL0PdmKfkfI1fzrY1 qYgqC1fEcFm+7c84hLKuBSP9OmN0GnmpX6Jkr78Al4kqIMV35t2vLtNxDG3y2fNzTyen C/KzTvM7cKAhR43O/MjDQITNdz12n4otYpghycnZL2qlnyAhH/wJAoI3niM7CV6Hp7Mx 2n2MceSpz9iqTu4seINix2GJwy0w2oVsPqlLXrmSqw3NeXIDQaCgHCVPXVPbW/paJ6LC J8ZNfHOhtty8gHfAldcFE/wyQYP0uO8aAxqh1SEb6ACRqh6OzMrmTacR+R5rVXiqcz8s z8dA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=JqedQlvj; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-182893-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182893-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-7930ce8f21bsi513500685a.342.2024.05.18.07.17.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 May 2024 07:17:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182893-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=JqedQlvj; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-182893-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182893-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B9B991C20C9D for ; Sat, 18 May 2024 14:17:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2A1B4501B; Sat, 18 May 2024 14:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="JqedQlvj" Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7F6544C68 for ; Sat, 18 May 2024 14:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716041864; cv=none; b=MZ25cXAew8osrxJeTDqKgji8FoCllKDUjx+do6JQNwUZtfvt2OQcK/6qvYUzIhJCURNVzD24hWDBE8HRbn7+iiE87BHMCu09waJFBsw879wqMvCqtZvBLWk3EfB+8KpAodOXuoWpZjmDdFZcHBGUvnFbjJQi+Iep8qQVD+kvWL0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716041864; c=relaxed/simple; bh=XBTbPk6LUCg/+KF7yZ3YUKGPU4HVOYeWWP4dER/DvP0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=rwxx4IeUwshqZBAx04qn9uFmcWmuSNmee/Vozvv+fS3ayjWW/8iB5plp9VSsal3TOaLybEg0UJ/hO9CNrjLVmmtS4WN52hsbrmAFv02LF7Gi87UfbArykJj+c0F8f+lgyi2IEiE7qLz4Kqe9D2dsUHZm8rydy4htz/k8Qs0zgIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=JqedQlvj; arc=none smtp.client-ip=198.47.19.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 44IEGLoI017554; Sat, 18 May 2024 09:16:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1716041781; bh=hE7bJWGco1/V2achyvapsMHYTWD7SY5fsWVMayfRq60=; h=From:To:CC:Subject:Date; b=JqedQlvjazZ7Wtvm4tLQmQ5v3QI0s07YunyeQh386vEAu3M53zUD2L3/qDxbuBHiK K992PU3i0G0n9huGIs9qaTCH+pB8YFNQc+b+NRvPPiy75B4/+fdQUWdaOGbxZVR/8I ybF6AN8XF179AK5mkkmwTr6QM8kZQG5dk2Y25vwY= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 44IEGLZb055620 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 18 May 2024 09:16:21 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sat, 18 May 2024 09:16:21 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sat, 18 May 2024 09:16:21 -0500 Received: from LT5CG31242FY.dhcp.ti.com ([10.250.160.158]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 44IEGFfa038647; Sat, 18 May 2024 09:16:15 -0500 From: Shenghao Ding To: CC: , , , , <13916275206@139.com>, , , , , , , , , , , , Shenghao Ding Subject: [PATCH v6] ASoC: tas2781: Fix wrong loading calibrated data sequence Date: Sat, 18 May 2024 22:15:46 +0800 Message-ID: <20240518141546.1742-1-shenghao-ding@ti.com> X-Mailer: git-send-email 2.33.0.windows.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Calibrated data will be set to default after loading DSP config params, which will cause speaker protection work abnormally. Reload calibrated data after loading DSP config params. Remove declaration of unused API which load calibrated data in wrong sequence, changed the copyright year and correct file name in license header. Fixes: ef3bcde75d06 ("ASoc: tas2781: Add tas2781 driver") Signed-off-by: Shenghao Ding --- v6: - Merge into one patch v5: - correct changelog has no much relationship with the patch v4: - Use the the culprit of the bug itself as the fixes tag - Better variant for tasdev_load_calibrated_data in order to much easier to read and understand and maintain, as it makes harder to squeeze the code. - Fix the indentation and move operator to the previous line. v3: - No changes. - Remove redundant return in tasdev_load_calibrated_data - Put the second function parameter into the previous line for tasdev_load_calibrated_data v2: - In the Subject, fixed --> Fix - Add Fixes tag - dsp --> DSP - Changed the copyright year to 2024 in the related files - In tas2781-dsp.h, __TASDEVICE_DSP_H__ --> __TAS2781_DSP_H__ v1: - Download calibrated data after loading the new DSP config params - Remove tasdevice_prmg_calibdata_load, because it is unnecessary to load calibrated data after loading DSP program. - call tasdevice_prmg_load instead of tasdevice_prmg_calibdata_load, it is unnecessary to load calibrated data after loading DSP program. Load it after loading DSP config params each time. --- include/sound/tas2781-dsp.h | 7 +- sound/soc/codecs/tas2781-fmwlib.c | 103 ++++++++---------------------- sound/soc/codecs/tas2781-i2c.c | 4 +- 3 files changed, 32 insertions(+), 82 deletions(-) diff --git a/include/sound/tas2781-dsp.h b/include/sound/tas2781-dsp.h index ea9af2726a53..7fba7ea26a4b 100644 --- a/include/sound/tas2781-dsp.h +++ b/include/sound/tas2781-dsp.h @@ -2,7 +2,7 @@ // // ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier // -// Copyright (C) 2022 - 2023 Texas Instruments Incorporated +// Copyright (C) 2022 - 2024 Texas Instruments Incorporated // https://www.ti.com // // The TAS2781 driver implements a flexible and configurable @@ -13,8 +13,8 @@ // Author: Kevin Lu // -#ifndef __TASDEVICE_DSP_H__ -#define __TASDEVICE_DSP_H__ +#ifndef __TAS2781_DSP_H__ +#define __TAS2781_DSP_H__ #define MAIN_ALL_DEVICES 0x0d #define MAIN_DEVICE_A 0x01 @@ -180,7 +180,6 @@ void tasdevice_calbin_remove(void *context); int tasdevice_select_tuningprm_cfg(void *context, int prm, int cfg_no, int rca_conf_no); int tasdevice_prmg_load(void *context, int prm_no); -int tasdevice_prmg_calibdata_load(void *context, int prm_no); void tasdevice_tuning_switch(void *context, int state); int tas2781_load_calibration(void *context, char *file_name, unsigned short i); diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-fmwlib.c index a6be81adcb83..265a8ca25cbb 100644 --- a/sound/soc/codecs/tas2781-fmwlib.c +++ b/sound/soc/codecs/tas2781-fmwlib.c @@ -2151,6 +2151,24 @@ static int tasdevice_load_data(struct tasdevice_priv *tas_priv, return ret; } +static void tasdev_load_calibrated_data(struct tasdevice_priv *priv, int i) +{ + struct tasdevice_calibration *cal; + struct tasdevice_fw *cal_fmw; + + cal_fmw = priv->tasdevice[i].cali_data_fmw; + + /* No calibrated data for current devices, playback will go ahead. */ + if (!cal_fmw) + return; + + cal = cal_fmw->calibrations; + if (cal) + return; + + load_calib_data(priv, &cal->dev_data); +} + int tasdevice_select_tuningprm_cfg(void *context, int prm_no, int cfg_no, int rca_conf_no) { @@ -2210,21 +2228,9 @@ int tasdevice_select_tuningprm_cfg(void *context, int prm_no, for (i = 0; i < tas_priv->ndev; i++) { if (tas_priv->tasdevice[i].is_loaderr == true) continue; - else if (tas_priv->tasdevice[i].is_loaderr == false - && tas_priv->tasdevice[i].is_loading == true) { - struct tasdevice_fw *cal_fmw = - tas_priv->tasdevice[i].cali_data_fmw; - - if (cal_fmw) { - struct tasdevice_calibration - *cal = cal_fmw->calibrations; - - if (cal) - load_calib_data(tas_priv, - &(cal->dev_data)); - } + if (tas_priv->tasdevice[i].is_loaderr == false && + tas_priv->tasdevice[i].is_loading == true) tas_priv->tasdevice[i].cur_prog = prm_no; - } } } @@ -2245,11 +2251,15 @@ int tasdevice_select_tuningprm_cfg(void *context, int prm_no, tasdevice_load_data(tas_priv, &(conf->dev_data)); for (i = 0; i < tas_priv->ndev; i++) { if (tas_priv->tasdevice[i].is_loaderr == true) { - status |= 1 << (i + 4); + status |= BIT(i + 4); continue; - } else if (tas_priv->tasdevice[i].is_loaderr == false - && tas_priv->tasdevice[i].is_loading == true) + } + + if (tas_priv->tasdevice[i].is_loaderr == false && + tas_priv->tasdevice[i].is_loading == true) { + tasdev_load_calibrated_data(tas_priv, i); tas_priv->tasdevice[i].cur_conf = cfg_no; + } } } else dev_dbg(tas_priv->dev, "%s: Unneeded loading dsp conf %d\n", @@ -2308,65 +2318,6 @@ int tasdevice_prmg_load(void *context, int prm_no) } EXPORT_SYMBOL_NS_GPL(tasdevice_prmg_load, SND_SOC_TAS2781_FMWLIB); -int tasdevice_prmg_calibdata_load(void *context, int prm_no) -{ - struct tasdevice_priv *tas_priv = (struct tasdevice_priv *) context; - struct tasdevice_fw *tas_fmw = tas_priv->fmw; - struct tasdevice_prog *program; - int prog_status = 0; - int i; - - if (!tas_fmw) { - dev_err(tas_priv->dev, "%s: Firmware is NULL\n", __func__); - goto out; - } - - if (prm_no >= tas_fmw->nr_programs) { - dev_err(tas_priv->dev, - "%s: prm(%d) is not in range of Programs %u\n", - __func__, prm_no, tas_fmw->nr_programs); - goto out; - } - - for (i = 0, prog_status = 0; i < tas_priv->ndev; i++) { - if (prm_no >= 0 && tas_priv->tasdevice[i].cur_prog != prm_no) { - tas_priv->tasdevice[i].cur_conf = -1; - tas_priv->tasdevice[i].is_loading = true; - prog_status++; - } - tas_priv->tasdevice[i].is_loaderr = false; - } - - if (prog_status) { - program = &(tas_fmw->programs[prm_no]); - tasdevice_load_data(tas_priv, &(program->dev_data)); - for (i = 0; i < tas_priv->ndev; i++) { - if (tas_priv->tasdevice[i].is_loaderr == true) - continue; - else if (tas_priv->tasdevice[i].is_loaderr == false - && tas_priv->tasdevice[i].is_loading == true) { - struct tasdevice_fw *cal_fmw = - tas_priv->tasdevice[i].cali_data_fmw; - - if (cal_fmw) { - struct tasdevice_calibration *cal = - cal_fmw->calibrations; - - if (cal) - load_calib_data(tas_priv, - &(cal->dev_data)); - } - tas_priv->tasdevice[i].cur_prog = prm_no; - } - } - } - -out: - return prog_status; -} -EXPORT_SYMBOL_NS_GPL(tasdevice_prmg_calibdata_load, - SND_SOC_TAS2781_FMWLIB); - void tasdevice_tuning_switch(void *context, int state) { struct tasdevice_priv *tas_priv = (struct tasdevice_priv *) context; diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c index b5abff230e43..9350972dfefe 100644 --- a/sound/soc/codecs/tas2781-i2c.c +++ b/sound/soc/codecs/tas2781-i2c.c @@ -2,7 +2,7 @@ // // ALSA SoC Texas Instruments TAS2563/TAS2781 Audio Smart Amplifier // -// Copyright (C) 2022 - 2023 Texas Instruments Incorporated +// Copyright (C) 2022 - 2024 Texas Instruments Incorporated // https://www.ti.com // // The TAS2563/TAS2781 driver implements a flexible and configurable @@ -414,7 +414,7 @@ static void tasdevice_fw_ready(const struct firmware *fmw, __func__, tas_priv->cal_binaryname[i]); } - tasdevice_prmg_calibdata_load(tas_priv, 0); + tasdevice_prmg_load(tas_priv, 0); tas_priv->cur_prog = 0; out: if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) { -- 2.34.1