Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp291694lqp; Wed, 12 Jun 2024 01:26:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFxmYucstfWdSMefYRaIk0GUbNftgdTYMW/F8ksdF2gnFP1V2tJUNxPEzuIlSAYu/9YGp2RmMzRPW2qjrUOFSG72Hpf6cFPd4HtH1Qfg== X-Google-Smtp-Source: AGHT+IGBeKuRxuGMwpTe5O3rwk94Ih7B+5YeYi2IN3xIeRG093yg7ktZInzRRo0unLRIua3sXo5D X-Received: by 2002:a17:906:c109:b0:a6f:728:e11a with SMTP id a640c23a62f3a-a6f4801c010mr87549966b.74.1718180736184; Wed, 12 Jun 2024 01:25:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718180736; cv=pass; d=google.com; s=arc-20160816; b=FxzUAZY7ftXJM5gw7MmvdbmsxexwE885EsoUSDjNzq0PW6JAAOg8kNoBrHAi3Q3mMP YsuyVoyJg6tLZpSCmjJh2+B1ESMM3Tv8hNIExRZjxJJF9u8Dp1VwdY6U2/KsFNuxL7ro M7i2Q6rBJop616UEH0pFBVUKC80djQh/FBf4TJHxk76ynwPF9c1K+i2ittI2qNkz/4C1 IdbVxBVl/kvYuePZw0dpzPua5fdmaqPA0Cmht8nS+8pMD3JqZBHFCq6qArm2TLjT5x6g Pfjm3GhEHrx9sQ7r+P4/uckOb8uktVZYcshJqSxDtW9RoywoxV8qfqjOVBmuua/WOQ6/ Z56w== 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=SXg9W8qnUhziZySsDuvS+9nZfVaC8vrFqmChdl2skTM=; fh=RT4363P6BmPt6bNBzCvqul30ZXuIeBsAu95f0oTDR5o=; b=JHmzCg0FSOdToR4n9Re781uTOQo9BphTb8NItRLQvWW6IEcPxbCyGtRzAP21auKswq 3jx9fJaHFoXIQHrRNwYBUCc0DHSnI7DkVPqXNuB2mukpzPHGwNcBa0SlOSal1Mp9bh6q PCdz7yCEQIn4NB70u8yHy4CwjObpuXpptaoRurKuH0jg5qSwa0SYfN3lsHOVvRXBR3OY Tp2vZ0PrmjZbq8wx5GEBDw0Z7W/wjzWsiod5+vrA4/LIh774W0ys7+GjEsTrFDqTXKF8 f9J8R5hO2kKBy7PAeM7X5aAgO+77/XzblpHIfm6LY5pl2PIQ35LvYSAClyyHPIy43Jor 1fxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=p7hrNP3E; 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-211179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211179-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f4b5b8999si22950766b.230.2024.06.12.01.25.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:25:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=p7hrNP3E; 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-211179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211179-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B81621F28039 for ; Wed, 12 Jun 2024 08:25:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16B7E16C875; Wed, 12 Jun 2024 08:25:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="p7hrNP3E" Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 00639156228 for ; Wed, 12 Jun 2024 08:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180728; cv=none; b=t/abHPrVkrDyfRoveHVOcedCG9QT/AHrTMUijUg1Ztkh0njUMSgz+22jhw95kj8dZ5suPxDV9axtu6EjkhlXPRW+EWJX14qBafEbeHuTYnuKXGFO2uBXLCLTBFpxH9VTK70YPT7DU5fCc8G3uF42U5L7NHwbITSQHLRVAwkYw+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180728; c=relaxed/simple; bh=j4IikM/8f0WxPsoP5Y1ret6QW1ddPJ5haXColS9GWeI=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fGLuJ4GdVHK26Ydlety7kJU3cqkiZRWEPzsUD2dUnWt3qW03TJWbjl0xbFBxkCe36+zEhqPcNOHhPp4aDZRK4mNn+hP8+kCZVt67HI+YtU0ytozp9GtEPSg1D7m1ZW1cAwfQp9nZkL3m5j/fat++aewZCqw2pp4PTzoWr/t+pqg= 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=p7hrNP3E; arc=none smtp.client-ip=198.47.19.142 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 fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 45C8NjE6123708; Wed, 12 Jun 2024 03:23:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1718180625; bh=SXg9W8qnUhziZySsDuvS+9nZfVaC8vrFqmChdl2skTM=; h=From:To:CC:Subject:Date; b=p7hrNP3EEz95Ebp8fUg/AlR8Y0Jy0hA+jKms+EJ86h8zAcsK9hKXinUHIwWruo8ck m0l5mq1FO8bF+/AQuV+Bi6dUHjSu/QVuD3WEpXChd3OPW+cQlsXgl1RN9zHdediTrs ZIFyo+eIuwl2yqfpzqPtoHtqYPKVWObUpv8Fdprg= Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 45C8NjT0048263 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 12 Jun 2024 03:23:45 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Wed, 12 Jun 2024 03:23:45 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE108.ent.ti.com (157.170.170.38) 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; Wed, 12 Jun 2024 03:23:45 -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 45C8NZhi099797; Wed, 12 Jun 2024 03:23:35 -0500 From: Shenghao Ding To: CC: , , , , <13916275206@139.com>, , , , , , , , , , , , , , , , , , , , , , , , , Shenghao Ding Subject: [RESEND PATCH v4] ASoc: tas2781: Enable RCA-based playback without DSP firmware download Date: Wed, 12 Jun 2024 16:23:30 +0800 Message-ID: <20240612082332.1407-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 In only RCA (Reconfigurable Architecture) binary case, no DSP program will be working inside tas2563/tas2781, that is dsp-bypass mode, do not support speaker protection, and audio acoustic algorithms in this mode. Fixes: ef3bcde75d06 ("ASoC: tas2781: Add tas2781 driver") Signed-off-by: Shenghao Ding --- v4: - add a description of what the state machine looks like. - Remove TASDEVICE_DSP_FW_NONE because of unused. - Remove stray change. - Fix broken indentation. v3: - Add description on RCA is Reconfigurable Architecture. - Add the description on enabling - Reword the commit - Remove question mark in the comments. - Add spaces in comments. v2: - Correct comment. - Add Fixes. - Move header file to the first. v1: - Split out the different logical changes into different patches. - rename tasdevice_dsp_fw_state -> tasdevice_fw_state, the fw are not only DSP fw, but also RCA(Reconfigurable data, such as acoustic data and register setting, etc). - Add TASDEVICE_RCA_FW_OK in tasdevice_fw_state to identify the state that only RCA binary file has been download successfully, but DSP fw is not loaded or loading failure. - Add the this strategy into tasdevice_tuning_switch. - If one side of the if/else has a braces both should in tasdevice_tuning_switch. - Identify whehter both RCA and DSP have been loaded or only RCA has been loaded in tasdevice_fw_ready. - Add check fw load status in tasdevice_startup. - remove ret in tasdevice_startup to make the code neater. --- include/sound/tas2781-dsp.h | 11 ++++++++-- sound/soc/codecs/tas2781-fmwlib.c | 18 +++++++++++----- sound/soc/codecs/tas2781-i2c.c | 34 +++++++++++++++++++------------ 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/include/sound/tas2781-dsp.h b/include/sound/tas2781-dsp.h index 7fba7ea26a4b..3cda9da14f6d 100644 --- a/include/sound/tas2781-dsp.h +++ b/include/sound/tas2781-dsp.h @@ -117,10 +117,17 @@ struct tasdevice_fw { struct device *dev; }; -enum tasdevice_dsp_fw_state { - TASDEVICE_DSP_FW_NONE = 0, +enum tasdevice_fw_state { + /* Driver in startup mode, not load any firmware. */ TASDEVICE_DSP_FW_PENDING, + /* DSP firmware in the system, but parsing error. */ TASDEVICE_DSP_FW_FAIL, + /* + * Only RCA (Reconfigurable Architecture) firmware load + * successfully. + */ + TASDEVICE_RCA_FW_OK, + /* Both RCA and DSP firmware load successfully. */ TASDEVICE_DSP_FW_ALL_OK, }; diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-fmwlib.c index 265a8ca25cbb..838d29fead96 100644 --- a/sound/soc/codecs/tas2781-fmwlib.c +++ b/sound/soc/codecs/tas2781-fmwlib.c @@ -2324,14 +2324,21 @@ void tasdevice_tuning_switch(void *context, int state) struct tasdevice_fw *tas_fmw = tas_priv->fmw; int profile_cfg_id = tas_priv->rcabin.profile_cfg_id; - if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) { - dev_err(tas_priv->dev, "DSP bin file not loaded\n"); + /* + * Only RCA-based Playback can still work with no dsp program running + * inside the chip. + */ + switch (tas_priv->fw_state) { + case TASDEVICE_RCA_FW_OK: + case TASDEVICE_DSP_FW_ALL_OK: + break; + default: return; } if (state == 0) { - if (tas_priv->cur_prog < tas_fmw->nr_programs) { - /*dsp mode or tuning mode*/ + if (tas_fmw && tas_priv->cur_prog < tas_fmw->nr_programs) { + /* dsp mode or tuning mode */ profile_cfg_id = tas_priv->rcabin.profile_cfg_id; tasdevice_select_tuningprm_cfg(tas_priv, tas_priv->cur_prog, tas_priv->cur_conf, @@ -2340,9 +2347,10 @@ void tasdevice_tuning_switch(void *context, int state) tasdevice_select_cfg_blk(tas_priv, profile_cfg_id, TASDEVICE_BIN_BLK_PRE_POWER_UP); - } else + } else { tasdevice_select_cfg_blk(tas_priv, profile_cfg_id, TASDEVICE_BIN_BLK_PRE_SHUTDOWN); + } } EXPORT_SYMBOL_NS_GPL(tasdevice_tuning_switch, SND_SOC_TAS2781_FMWLIB); diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c index 9350972dfefe..9c3c89cb36de 100644 --- a/sound/soc/codecs/tas2781-i2c.c +++ b/sound/soc/codecs/tas2781-i2c.c @@ -380,23 +380,32 @@ static void tasdevice_fw_ready(const struct firmware *fmw, mutex_lock(&tas_priv->codec_lock); ret = tasdevice_rca_parser(tas_priv, fmw); - if (ret) + if (ret) { + tasdevice_config_info_remove(tas_priv); goto out; + } tasdevice_create_control(tas_priv); tasdevice_dsp_remove(tas_priv); tasdevice_calbin_remove(tas_priv); - tas_priv->fw_state = TASDEVICE_DSP_FW_PENDING; + tas_priv->fw_state = TASDEVICE_RCA_FW_OK; scnprintf(tas_priv->coef_binaryname, 64, "%s_coef.bin", tas_priv->dev_name); ret = tasdevice_dsp_parser(tas_priv); if (ret) { dev_err(tas_priv->dev, "dspfw load %s error\n", tas_priv->coef_binaryname); - tas_priv->fw_state = TASDEVICE_DSP_FW_FAIL; goto out; } - tasdevice_dsp_create_ctrls(tas_priv); + + /* + * If no dsp-related kcontrol created, the dsp resource will be freed. + */ + ret = tasdevice_dsp_create_ctrls(tas_priv); + if (ret) { + dev_err(tas_priv->dev, "dsp controls error\n"); + goto out; + } tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK; @@ -417,9 +426,8 @@ static void tasdevice_fw_ready(const struct firmware *fmw, tasdevice_prmg_load(tas_priv, 0); tas_priv->cur_prog = 0; out: - if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) { - /*If DSP FW fail, kcontrol won't be created */ - tasdevice_config_info_remove(tas_priv); + if (tas_priv->fw_state == TASDEVICE_RCA_FW_OK) { + /* If DSP FW fail, DSP kcontrol won't be created. */ tasdevice_dsp_remove(tas_priv); } mutex_unlock(&tas_priv->codec_lock); @@ -466,14 +474,14 @@ static int tasdevice_startup(struct snd_pcm_substream *substream, { struct snd_soc_component *codec = dai->component; struct tasdevice_priv *tas_priv = snd_soc_component_get_drvdata(codec); - int ret = 0; - if (tas_priv->fw_state != TASDEVICE_DSP_FW_ALL_OK) { - dev_err(tas_priv->dev, "DSP bin file not loaded\n"); - ret = -EINVAL; + switch (tas_priv->fw_state) { + case TASDEVICE_RCA_FW_OK: + case TASDEVICE_DSP_FW_ALL_OK: + return 0; + default: + return -EINVAL; } - - return ret; } static int tasdevice_hw_params(struct snd_pcm_substream *substream, -- 2.34.1