From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EC45C10F05 for ; Thu, 7 Dec 2023 00:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441858AbjLGAAD (ORCPT ); Wed, 6 Dec 2023 19:00:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230449AbjLFX77 (ORCPT ); Wed, 6 Dec 2023 18:59:59 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 282CA11F for ; Wed, 6 Dec 2023 16:00:04 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716E3.0000000065710B02.00118FFF; Thu, 07 Dec 2023 01:00:02 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 01/16] ASoC: tas2781: add support for fw version 0x0503 Date: Thu, 7 Dec 2023 00:59:42 +0100 Message-ID: <868fc7939c142a65e1a5d9d42063e6a17aaf420e.1701906455.git.soyer@irl.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It is compatible with the fw version 0x0502. Already supported by TI's tas2781-linux-driver tree. https://git.ti.com/cgit/tas2781-linux-drivers/tas2781-linux-driver Signed-off-by: Gergo Koteles --- sound/soc/codecs/tas2781-fmwlib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-f= mwlib.c index eb55abae0d7b..20dc2df034e9 100644 --- a/sound/soc/codecs/tas2781-fmwlib.c +++ b/sound/soc/codecs/tas2781-fmwlib.c @@ -2012,6 +2012,7 @@ static int tasdevice_dspfw_ready(const struct firmwar= e *fmw, case 0x301: case 0x302: case 0x502: + case 0x503: tas_priv->fw_parse_variable_header =3D fw_parse_variable_header_kernel; tas_priv->fw_parse_program_data =3D --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8B94C4167B for ; Thu, 7 Dec 2023 00:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232308AbjLGAAA (ORCPT ); Wed, 6 Dec 2023 19:00:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjLFX77 (ORCPT ); Wed, 6 Dec 2023 18:59:59 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3648A19E for ; Wed, 6 Dec 2023 16:00:05 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716DF.0000000065710B02.00119017; Thu, 07 Dec 2023 01:00:02 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 02/16] ALSA: hda/tas2781: leave hda_component in usable state Date: Thu, 7 Dec 2023 00:59:43 +0100 Message-ID: <1be369f5a007c9f77bce7a33748ef428152894d7.1701906455.git.soyer@irl.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Unloading then loading the module causes a panic. Set only previously modified fields to null. Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index fb802802939e..077a01521eef 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -613,8 +613,11 @@ static void tas2781_hda_unbind(struct device *dev, struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); struct hda_component *comps =3D master_data; =20 - if (comps[tas_priv->index].dev =3D=3D dev) - memset(&comps[tas_priv->index], 0, sizeof(*comps)); + if (comps[tas_priv->index].dev =3D=3D dev) { + comps[tas_priv->index].dev =3D NULL; + strscpy(comps->name, "", sizeof(comps->name)); + comps[tas_priv->index].playback_hook =3D NULL; + } =20 tasdevice_config_info_remove(tas_priv); tasdevice_dsp_remove(tas_priv); --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01663C10DC1 for ; Thu, 7 Dec 2023 00:00:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441865AbjLGAAH (ORCPT ); Wed, 6 Dec 2023 19:00:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230452AbjLFX77 (ORCPT ); Wed, 6 Dec 2023 18:59:59 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7372DD44 for ; Wed, 6 Dec 2023 16:00:05 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716E7.0000000065710B03.00119029; Thu, 07 Dec 2023 01:00:03 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 03/16] ASoC: tas2781: disable regmap regcache Date: Thu, 7 Dec 2023 00:59:44 +0100 Message-ID: <21a183b5a08cb23b193af78d4b1114cc59419272.1701906455.git.soyer@irl.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The amp has 3 level addressing (BOOK, PAGE, REG). The regcache couldn't handle it. Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 17 +---------------- sound/soc/codecs/tas2781-comlib.c | 2 +- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index 077a01521eef..d272d3d08b29 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -717,8 +717,6 @@ static int tas2781_runtime_suspend(struct device *dev) tas_priv->tasdevice[i].cur_conf =3D -1; } =20 - regcache_cache_only(tas_priv->regmap, true); - regcache_mark_dirty(tas_priv->regmap); =20 mutex_unlock(&tas_priv->codec_lock); =20 @@ -730,20 +728,11 @@ static int tas2781_runtime_resume(struct device *dev) struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); unsigned long calib_data_sz =3D tas_priv->ndev * TASDEVICE_SPEAKER_CALIBRATION_SIZE; - int ret; =20 dev_dbg(tas_priv->dev, "Runtime Resume\n"); =20 mutex_lock(&tas_priv->codec_lock); =20 - regcache_cache_only(tas_priv->regmap, false); - ret =3D regcache_sync(tas_priv->regmap); - if (ret) { - dev_err(tas_priv->dev, - "Failed to restore register cache: %d\n", ret); - goto out; - } - tasdevice_prmg_load(tas_priv, tas_priv->cur_prog); =20 /* If calibrated data occurs error, dsp will still works with default @@ -752,10 +741,9 @@ static int tas2781_runtime_resume(struct device *dev) if (tas_priv->cali_data.total_sz > calib_data_sz) tas2781_apply_calib(tas_priv); =20 -out: mutex_unlock(&tas_priv->codec_lock); =20 - return ret; + return 0; } =20 static int tas2781_system_suspend(struct device *dev) @@ -770,10 +758,7 @@ static int tas2781_system_suspend(struct device *dev) return ret; =20 /* Shutdown chip before system suspend */ - regcache_cache_only(tas_priv->regmap, false); tasdevice_tuning_switch(tas_priv, 1); - regcache_cache_only(tas_priv->regmap, true); - regcache_mark_dirty(tas_priv->regmap); =20 /* * Reset GPIO may be shared, so cannot reset here. diff --git a/sound/soc/codecs/tas2781-comlib.c b/sound/soc/codecs/tas2781-c= omlib.c index ffb26e4a7e2f..933cd008e9f5 100644 --- a/sound/soc/codecs/tas2781-comlib.c +++ b/sound/soc/codecs/tas2781-comlib.c @@ -39,7 +39,7 @@ static const struct regmap_range_cfg tasdevice_ranges[] = =3D { static const struct regmap_config tasdevice_regmap =3D { .reg_bits =3D 8, .val_bits =3D 8, - .cache_type =3D REGCACHE_RBTREE, + .cache_type =3D REGCACHE_NONE, .ranges =3D tasdevice_ranges, .num_ranges =3D ARRAY_SIZE(tasdevice_ranges), .max_register =3D 256 * 128, --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 544D2C4167B for ; Thu, 7 Dec 2023 00:00:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441881AbjLGAAM (ORCPT ); Wed, 6 Dec 2023 19:00:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231264AbjLGAAA (ORCPT ); Wed, 6 Dec 2023 19:00:00 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9025111F for ; Wed, 6 Dec 2023 16:00:06 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716EA.0000000065710B04.00119040; Thu, 07 Dec 2023 01:00:03 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 04/16] ALSA: hda/tas2781: handle missing calibration data Date: Thu, 7 Dec 2023 00:59:45 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Also check the return value of the first get_variable call. Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index d272d3d08b29..7c286802b273 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -455,9 +455,9 @@ static int tas2781_save_calibration(struct tasdevice_pr= iv *tas_priv) status =3D efi.get_variable(efi_name, &efi_guid, &attr, &tas_priv->cali_data.total_sz, tas_priv->cali_data.data); - if (status !=3D EFI_SUCCESS) - return -EINVAL; } + if (status !=3D EFI_SUCCESS) + return -EINVAL; =20 tmp_val =3D (unsigned int *)tas_priv->cali_data.data; =20 --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D3C2C4167B for ; Thu, 7 Dec 2023 00:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441878AbjLGAAJ (ORCPT ); Wed, 6 Dec 2023 19:00:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232274AbjLGAAA (ORCPT ); Wed, 6 Dec 2023 19:00:00 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDED3137 for ; Wed, 6 Dec 2023 16:00:06 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716ED.0000000065710B04.00119052; Thu, 07 Dec 2023 01:00:04 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 05/16] ALSA: hda/tas2781: fix typos in comment Date: Thu, 7 Dec 2023 00:59:46 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Correct typos. Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index 7c286802b273..70085177230e 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -421,9 +421,9 @@ static void tas2781_apply_calib(struct tasdevice_priv *= tas_priv) } } =20 -/* Update the calibrate data, including speaker impedance, f0, etc, into a= lgo. +/* Update the calibration data, including speaker impedance, f0, etc, into= algo. * Calibrate data is done by manufacturer in the factory. These data are u= sed - * by Algo for calucating the speaker temperature, speaker membrance excur= sion + * by Algo for calcucating the speaker temperature, speaker membrane excur= sion * and f0 in real time during playback. */ static int tas2781_save_calibration(struct tasdevice_priv *tas_priv) --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91F38C4167B for ; Thu, 7 Dec 2023 00:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232333AbjLGAAT (ORCPT ); Wed, 6 Dec 2023 19:00:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441822AbjLGAAB (ORCPT ); Wed, 6 Dec 2023 19:00:01 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D9D21A5 for ; Wed, 6 Dec 2023 16:00:07 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716F0.0000000065710B04.00119059; Thu, 07 Dec 2023 01:00:04 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 06/16] ASoC: tas2781: add ptrs to calibration functions Date: Thu, 7 Dec 2023 00:59:47 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" rename save_calibration to load_calibration Signed-off-by: Gergo Koteles --- include/sound/tas2781.h | 5 +++++ sound/pci/hda/tas2781_hda_i2c.c | 28 ++++++++++++---------------- sound/soc/codecs/tas2781-comlib.c | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/include/sound/tas2781.h b/include/sound/tas2781.h index a6c808b22318..1d3c71d7e68d 100644 --- a/include/sound/tas2781.h +++ b/include/sound/tas2781.h @@ -131,6 +131,9 @@ struct tasdevice_priv { const struct firmware *fmw, int offset); int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv, struct tasdev_blk *block); + + int (*load_calibration)(struct tasdevice_priv *tas_priv); + void (*apply_calibration)(struct tasdevice_priv *tas_priv); }; =20 void tas2781_reset(struct tasdevice_priv *tas_dev); @@ -139,6 +142,8 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void= *codec, struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c); int tasdevice_init(struct tasdevice_priv *tas_priv); void tasdevice_remove(struct tasdevice_priv *tas_priv); +int tasdevice_load_calibration(struct tasdevice_priv *tas_priv); +void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv); int tasdevice_dev_read(struct tasdevice_priv *tas_priv, unsigned short chn, unsigned int reg, unsigned int *value); int tasdevice_dev_write(struct tasdevice_priv *tas_priv, diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index 70085177230e..2b5031e4dda3 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -395,7 +395,7 @@ static const struct snd_kcontrol_new tas2781_dsp_conf_c= trl =3D { .put =3D tasdevice_config_put, }; =20 -static void tas2781_apply_calib(struct tasdevice_priv *tas_priv) +static void tas2781_apply_calibration(struct tasdevice_priv *tas_priv) { static const unsigned char page_array[CALIB_MAX] =3D { 0x17, 0x18, 0x18, 0x0d, 0x18 @@ -426,7 +426,7 @@ static void tas2781_apply_calib(struct tasdevice_priv *= tas_priv) * by Algo for calcucating the speaker temperature, speaker membrane excur= sion * and f0 in real time during playback. */ -static int tas2781_save_calibration(struct tasdevice_priv *tas_priv) +static int load_calibration_efi_1(struct tasdevice_priv *tas_priv) { efi_guid_t efi_guid =3D EFI_GUID(0x02f9af02, 0x7734, 0x4233, 0xb4, 0x3d, 0x93, 0xfe, 0x5a, 0xa3, 0x5d, 0xb3); @@ -547,7 +547,7 @@ static void tasdev_fw_ready(const struct firmware *fmw,= void *context) /* If calibrated data occurs error, dsp will still works with default * calibrated data inside algo. */ - tas2781_save_calibration(tas_priv); + tasdevice_load_calibration(tas_priv); =20 out: if (tas_priv->fw_state =3D=3D TASDEVICE_DSP_FW_FAIL) { @@ -650,15 +650,17 @@ static int tas2781_hda_i2c_probe(struct i2c_client *c= lt) const char *device_name; int ret; =20 - if (strstr(dev_name(&clt->dev), "TIAS2781")) - device_name =3D "TIAS2781"; - else - return -ENODEV; - tas_priv =3D tasdevice_kzalloc(clt); if (!tas_priv) return -ENOMEM; =20 + if (strstr(dev_name(&clt->dev), "TIAS2781")) { + device_name =3D "TIAS2781"; + tas_priv->load_calibration =3D load_calibration_efi_1; + tas_priv->apply_calibration =3D tas2781_apply_calibration; + } else + return -ENODEV; + tas_priv->irq_info.irq =3D clt->irq; ret =3D tas2781_read_acpi(tas_priv, device_name); if (ret) @@ -726,8 +728,6 @@ static int tas2781_runtime_suspend(struct device *dev) static int tas2781_runtime_resume(struct device *dev) { struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); - unsigned long calib_data_sz =3D - tas_priv->ndev * TASDEVICE_SPEAKER_CALIBRATION_SIZE; =20 dev_dbg(tas_priv->dev, "Runtime Resume\n"); =20 @@ -738,8 +738,7 @@ static int tas2781_runtime_resume(struct device *dev) /* If calibrated data occurs error, dsp will still works with default * calibrated data inside algo. */ - if (tas_priv->cali_data.total_sz > calib_data_sz) - tas2781_apply_calib(tas_priv); + tasdevice_apply_calibration(tas_priv); =20 mutex_unlock(&tas_priv->codec_lock); =20 @@ -770,8 +769,6 @@ static int tas2781_system_suspend(struct device *dev) static int tas2781_system_resume(struct device *dev) { struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); - unsigned long calib_data_sz =3D - tas_priv->ndev * TASDEVICE_SPEAKER_CALIBRATION_SIZE; int i, ret; =20 dev_dbg(tas_priv->dev, "System Resume\n"); @@ -793,8 +790,7 @@ static int tas2781_system_resume(struct device *dev) /* If calibrated data occurs error, dsp will still work with default * calibrated data inside algo. */ - if (tas_priv->cali_data.total_sz > calib_data_sz) - tas2781_apply_calib(tas_priv); + tasdevice_apply_calibration(tas_priv); mutex_unlock(&tas_priv->codec_lock); =20 return 0; diff --git a/sound/soc/codecs/tas2781-comlib.c b/sound/soc/codecs/tas2781-c= omlib.c index 933cd008e9f5..f914123c7284 100644 --- a/sound/soc/codecs/tas2781-comlib.c +++ b/sound/soc/codecs/tas2781-comlib.c @@ -414,6 +414,21 @@ void tasdevice_remove(struct tasdevice_priv *tas_priv) } EXPORT_SYMBOL_GPL(tasdevice_remove); =20 +int tasdevice_load_calibration(struct tasdevice_priv *tas_priv) +{ + if (tas_priv->load_calibration) + return tas_priv->load_calibration(tas_priv); + return -EINVAL; +} +EXPORT_SYMBOL_GPL(tasdevice_load_calibration); + +void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv) +{ + if (tas_priv->apply_calibration && tas_priv->cali_data.total_sz) + tas_priv->apply_calibration(tas_priv); +} +EXPORT_SYMBOL_GPL(tasdevice_apply_calibration); + static int tasdevice_clamp(int val, int max, unsigned int invert) { if (val > max) --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29FD5C4167B for ; Thu, 7 Dec 2023 00:00:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441893AbjLGAAP (ORCPT ); Wed, 6 Dec 2023 19:00:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232333AbjLGAAA (ORCPT ); Wed, 6 Dec 2023 19:00:00 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7422B19E for ; Wed, 6 Dec 2023 16:00:07 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716F3.0000000065710B05.0011905D; Thu, 07 Dec 2023 01:00:05 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 07/16] ALSA: hda/tas2781: load_calibration just load Date: Thu, 7 Dec 2023 00:59:48 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move the apply_calibration outside to make it clearer. Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index 2b5031e4dda3..c82ed2413fcb 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -470,7 +470,6 @@ static int load_calibration_efi_1(struct tasdevice_priv= *tas_priv) dev_dbg(tas_priv->dev, "%4ld-%2d-%2d, %2d:%2d:%2d\n", tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); - tas2781_apply_calib(tas_priv); } else tas_priv->cali_data.total_sz =3D 0; =20 @@ -548,6 +547,7 @@ static void tasdev_fw_ready(const struct firmware *fmw,= void *context) * calibrated data inside algo. */ tasdevice_load_calibration(tas_priv); + tasdevice_apply_calibration(tas_priv); =20 out: if (tas_priv->fw_state =3D=3D TASDEVICE_DSP_FW_FAIL) { --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85EADC4167B for ; Thu, 7 Dec 2023 00:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441908AbjLGAAV (ORCPT ); Wed, 6 Dec 2023 19:00:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441806AbjLGAAB (ORCPT ); Wed, 6 Dec 2023 19:00:01 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DEF511F for ; Wed, 6 Dec 2023 16:00:07 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716E1.0000000065710B05.00119062; Thu, 07 Dec 2023 01:00:05 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 08/16] ASoC: tas2781: add configurable global_addr Date: Thu, 7 Dec 2023 00:59:49 +0100 Message-ID: <80d655881e1ef744a680f617b2b1105c44b62bad.1701906455.git.soyer@irl.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add ability to handle global_addr of different chip versions. Signed-off-by: Gergo Koteles --- include/sound/tas2781.h | 2 ++ sound/pci/hda/tas2781_hda_i2c.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/sound/tas2781.h b/include/sound/tas2781.h index 1d3c71d7e68d..5f364e4d8995 100644 --- a/include/sound/tas2781.h +++ b/include/sound/tas2781.h @@ -121,6 +121,8 @@ struct tasdevice_priv { bool force_fwload_status; bool playback_started; bool isacpi; + unsigned int global_addr; + int (*fw_parse_variable_header)(struct tasdevice_priv *tas_priv, const struct firmware *fmw, int offset); int (*fw_parse_program_data)(struct tasdevice_priv *tas_priv, diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index c82ed2413fcb..7ebf5d7e4aac 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -72,7 +72,7 @@ static int tas2781_get_i2c_res(struct acpi_resource *ares= , void *data) =20 if (i2c_acpi_get_i2c_resource(ares, &sb)) { if (tas_priv->ndev < TASDEVICE_MAX_CHANNELS && - sb->slave_address !=3D TAS2781_GLOBAL_ADDR) { + sb->slave_address !=3D tas_priv->global_addr) { tas_priv->tasdevice[tas_priv->ndev].dev_addr =3D (unsigned int)sb->slave_address; tas_priv->ndev++; --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E0AFC4167B for ; Thu, 7 Dec 2023 00:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441914AbjLGAAY (ORCPT ); Wed, 6 Dec 2023 19:00:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441854AbjLGAAC (ORCPT ); Wed, 6 Dec 2023 19:00:02 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E01E137 for ; Wed, 6 Dec 2023 16:00:07 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716F9.0000000065710B06.00119065; Thu, 07 Dec 2023 01:00:06 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 09/16] ALSA: hda/tas2781: add TAS2563 support for 14ARB7 Date: Thu, 7 Dec 2023 00:59:50 +0100 Message-ID: <1efa4849a6c7fef0fafa000fe558a2633548bba0.1701906455.git.soyer@irl.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The INT8866 belongs to the Lenovo Yoga 7 Gen 7 AMD 14ARB7 laptop. It has two TAS2563 amplifier. Add the ACPI UID and calibration functions to handle them. Signed-off-by: Gergo Koteles --- include/sound/tas2781.h | 1 + sound/pci/hda/tas2781_hda_i2c.c | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/include/sound/tas2781.h b/include/sound/tas2781.h index 5f364e4d8995..afe9584daa65 100644 --- a/include/sound/tas2781.h +++ b/include/sound/tas2781.h @@ -22,6 +22,7 @@ #define TAS2781_DRV_VER 1 #define SMARTAMP_MODULE_NAME "tas2781" #define TAS2781_GLOBAL_ADDR 0x40 +#define TAS2563_GLOBAL_ADDR 0x48 #define TASDEVICE_RATES (SNDRV_PCM_RATE_44100 |\ SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\ SNDRV_PCM_RATE_88200) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index 7ebf5d7e4aac..f28383597ca8 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -65,6 +65,24 @@ enum calib_data { CALIB_MAX }; =20 +#define TAS2563_MAX_CHANNELS 4 + +#define TAS2563_CAL_POWER TASDEVICE_REG(0, 0x0d, 0x3c) +#define TAS2563_CAL_R0 TASDEVICE_REG(0, 0x0f, 0x34) +#define TAS2563_CAL_INVR0 TASDEVICE_REG(0, 0x0f, 0x40) +#define TAS2563_CAL_R0_LOW TASDEVICE_REG(0, 0x0f, 0x48) +#define TAS2563_CAL_TLIM TASDEVICE_REG(0, 0x10, 0x14) +#define TAS2563_CAL_N 5 +#define TAS2563_CAL_DATA_SIZE 4 +#define TAS2563_CAL_CH_SIZE 20 +#define TAS2563_CAL_ARRAY_SIZE 80 + +static unsigned int cal_regs[TAS2563_CAL_N] =3D { + TAS2563_CAL_POWER, TAS2563_CAL_R0, TAS2563_CAL_INVR0, + TAS2563_CAL_R0_LOW, TAS2563_CAL_TLIM, +}; + + static int tas2781_get_i2c_res(struct acpi_resource *ares, void *data) { struct tasdevice_priv *tas_priv =3D data; @@ -395,6 +413,68 @@ static const struct snd_kcontrol_new tas2781_dsp_conf_= ctrl =3D { .put =3D tasdevice_config_put, }; =20 +static void tas2563_apply_calibration(struct tasdevice_priv *tas_priv) +{ + unsigned int data; + int offset =3D 0; + int ret; + + for (int i =3D 0; i < tas_priv->ndev; i++) { + for (int j =3D 0; j < TAS2563_CAL_N; ++j) { + data =3D cpu_to_be32( + *(uint32_t *)&tas_priv->cali_data.data[offset]); + ret =3D tasdevice_dev_bulk_write(tas_priv, i, cal_regs[j], + (unsigned char *)&data, TAS2563_CAL_DATA_SIZE); + if (ret) + dev_err(tas_priv->dev, + "Error writing calib regs\n"); + offset +=3D TAS2563_CAL_DATA_SIZE; + } + } +} + +static int load_calibration_efi_2(struct tasdevice_priv *tas_priv) +{ + static efi_guid_t efi_guid =3D EFI_GUID(0x1f52d2a1, 0xbb3a, 0x457d, 0xbc, + 0x09, 0x43, 0xa3, 0xf4, 0x31, 0x0a, 0x92); + + static efi_char16_t *efi_vars[TAS2563_MAX_CHANNELS][TAS2563_CAL_N] =3D { + { L"Power_1", L"R0_1", L"InvR0_1", L"R0_Low_1", L"TLim_1" }, + { L"Power_2", L"R0_2", L"InvR0_2", L"R0_Low_2", L"TLim_2" }, + { L"Power_3", L"R0_3", L"InvR0_3", L"R0_Low_3", L"TLim_3" }, + { L"Power_4", L"R0_4", L"InvR0_4", L"R0_Low_4", L"TLim_4" }, + }; + + unsigned long max_size =3D TAS2563_CAL_DATA_SIZE; + unsigned int offset =3D 0; + efi_status_t status; + unsigned int attr; + + tas_priv->cali_data.data =3D devm_kzalloc(tas_priv->dev, + TAS2563_CAL_ARRAY_SIZE, GFP_KERNEL); + if (!tas_priv->cali_data.data) + return -ENOMEM; + + for (int i =3D 0; i < tas_priv->ndev; ++i) { + for (int j =3D 0; j < TAS2563_CAL_N; ++j) { + status =3D efi.get_variable(efi_vars[i][j], + &efi_guid, &attr, &max_size, + &tas_priv->cali_data.data[offset]); + if (status !=3D EFI_SUCCESS || + max_size !=3D TAS2563_CAL_DATA_SIZE) { + dev_warn(tas_priv->dev, + "Calibration data read failed %ld\n", status); + return -EINVAL; + } + offset +=3D TAS2563_CAL_DATA_SIZE; + } + } + + tas_priv->cali_data.total_sz =3D offset; + + return 0; +} + static void tas2781_apply_calibration(struct tasdevice_priv *tas_priv) { static const unsigned char page_array[CALIB_MAX] =3D { @@ -658,6 +738,12 @@ static int tas2781_hda_i2c_probe(struct i2c_client *cl= t) device_name =3D "TIAS2781"; tas_priv->load_calibration =3D load_calibration_efi_1; tas_priv->apply_calibration =3D tas2781_apply_calibration; + tas_priv->global_addr =3D TAS2781_GLOBAL_ADDR; + } else if (strstr(dev_name(&clt->dev), "INT8866")) { + device_name =3D "INT8866"; + tas_priv->load_calibration =3D load_calibration_efi_2; + tas_priv->apply_calibration =3D tas2563_apply_calibration; + tas_priv->global_addr =3D TAS2563_GLOBAL_ADDR; } else return -ENODEV; =20 @@ -808,6 +894,7 @@ static const struct i2c_device_id tas2781_hda_i2c_id[] = =3D { =20 static const struct acpi_device_id tas2781_acpi_hda_match[] =3D { {"TIAS2781", 0 }, + {"INT8866", 0 }, {} }; MODULE_DEVICE_TABLE(acpi, tas2781_acpi_hda_match); --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 583CFC4167B for ; Thu, 7 Dec 2023 00:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441813AbjLGAE6 (ORCPT ); Wed, 6 Dec 2023 19:04:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232538AbjLGAEm (ORCPT ); Wed, 6 Dec 2023 19:04:42 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92F17D53 for ; Wed, 6 Dec 2023 16:04:38 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716E7.0000000065710C14.001190BA; Thu, 07 Dec 2023 01:04:36 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 10/16] ASoC: tas2781: check negative indexes Date: Thu, 7 Dec 2023 01:04:26 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Negative indexes are not valid here. Signed-off-by: Gergo Koteles --- sound/soc/codecs/tas2781-fmwlib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-f= mwlib.c index 20dc2df034e9..aa5f56f9ad33 100644 --- a/sound/soc/codecs/tas2781-fmwlib.c +++ b/sound/soc/codecs/tas2781-fmwlib.c @@ -2198,21 +2198,21 @@ int tasdevice_select_tuningprm_cfg(void *context, i= nt prm_no, goto out; } =20 - if (cfg_no >=3D tas_fmw->nr_configurations) { + if (cfg_no < 0 || cfg_no >=3D tas_fmw->nr_configurations) { dev_err(tas_priv->dev, "%s: cfg(%d) is not in range of conf %u\n", __func__, cfg_no, tas_fmw->nr_configurations); goto out; } =20 - if (prm_no >=3D tas_fmw->nr_programs) { + if (prm_no < 0 || prm_no >=3D 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; } =20 - if (rca_conf_no >=3D rca->ncfgs || rca_conf_no < 0 || + if (rca_conf_no < 0 || rca_conf_no >=3D rca->ncfgs || !cfg_info) { dev_err(tas_priv->dev, "conf_no:%d should be in range from 0 to %u\n", @@ -2304,7 +2304,7 @@ int tasdevice_prmg_load(void *context, int prm_no) goto out; } =20 - if (prm_no >=3D tas_fmw->nr_programs) { + if (prm_no < 0 || prm_no >=3D 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); @@ -2349,7 +2349,7 @@ int tasdevice_prmg_calibdata_load(void *context, int = prm_no) goto out; } =20 - if (prm_no >=3D tas_fmw->nr_programs) { + if (prm_no < 0 || prm_no >=3D 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); --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7979C10F05 for ; Thu, 7 Dec 2023 00:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231442AbjLGAFA (ORCPT ); Wed, 6 Dec 2023 19:05:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232511AbjLGAEm (ORCPT ); Wed, 6 Dec 2023 19:04:42 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FAE1D5A for ; Wed, 6 Dec 2023 16:04:38 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716F4.0000000065710C14.001190BB; Thu, 07 Dec 2023 01:04:36 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 11/16] ASoC: tas2781: use 0 as default prog/conf index Date: Thu, 7 Dec 2023 01:04:27 +0100 Message-ID: <88229933b7aaf0777cbe611979712e4e144b1ca1.1701906455.git.soyer@irl.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Invalid indexes are not the best default values. Signed-off-by: Gergo Koteles --- sound/soc/codecs/tas2781-comlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/tas2781-comlib.c b/sound/soc/codecs/tas2781-c= omlib.c index f914123c7284..635f97db033b 100644 --- a/sound/soc/codecs/tas2781-comlib.c +++ b/sound/soc/codecs/tas2781-comlib.c @@ -307,8 +307,8 @@ int tasdevice_init(struct tasdevice_priv *tas_priv) goto out; } =20 - tas_priv->cur_prog =3D -1; - tas_priv->cur_conf =3D -1; + tas_priv->cur_prog =3D 0; + tas_priv->cur_conf =3D 0; =20 for (i =3D 0; i < tas_priv->ndev; i++) { tas_priv->tasdevice[i].cur_book =3D -1; --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04BBFC4167B for ; Thu, 7 Dec 2023 00:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441833AbjLGAFD (ORCPT ); Wed, 6 Dec 2023 19:05:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232657AbjLGAEm (ORCPT ); Wed, 6 Dec 2023 19:04:42 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F30E10C2 for ; Wed, 6 Dec 2023 16:04:39 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716FB.0000000065710C15.001190CD; Thu, 07 Dec 2023 01:04:37 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 12/16] ASoC: tas2781: move set_drv_data outside tasdevice_init Date: Thu, 7 Dec 2023 01:04:28 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" allow driver specific driver data in tas2781-hda-ic2c and tas2781-i2c Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 2 ++ sound/soc/codecs/tas2781-comlib.c | 2 -- sound/soc/codecs/tas2781-i2c.c | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index f28383597ca8..290c41194139 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -734,6 +734,8 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt) if (!tas_priv) return -ENOMEM; =20 + dev_set_drvdata(&clt->dev, tas_priv); + if (strstr(dev_name(&clt->dev), "TIAS2781")) { device_name =3D "TIAS2781"; tas_priv->load_calibration =3D load_calibration_efi_1; diff --git a/sound/soc/codecs/tas2781-comlib.c b/sound/soc/codecs/tas2781-c= omlib.c index 635f97db033b..0c04735dd575 100644 --- a/sound/soc/codecs/tas2781-comlib.c +++ b/sound/soc/codecs/tas2781-comlib.c @@ -316,8 +316,6 @@ int tasdevice_init(struct tasdevice_priv *tas_priv) tas_priv->tasdevice[i].cur_conf =3D -1; } =20 - dev_set_drvdata(tas_priv->dev, tas_priv); - mutex_init(&tas_priv->codec_lock); =20 out: diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c index 55cd5e3c23a5..917b1c15f71d 100644 --- a/sound/soc/codecs/tas2781-i2c.c +++ b/sound/soc/codecs/tas2781-i2c.c @@ -689,6 +689,8 @@ static int tasdevice_i2c_probe(struct i2c_client *i2c) if (!tas_priv) return -ENOMEM; =20 + dev_set_drvdata(&i2c->dev, tas_priv); + if (ACPI_HANDLE(&i2c->dev)) { acpi_id =3D acpi_match_device(i2c->dev.driver->acpi_match_table, &i2c->dev); --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE0D5C10DC1 for ; Thu, 7 Dec 2023 00:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441872AbjLGAFN (ORCPT ); Wed, 6 Dec 2023 19:05:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235160AbjLGAEo (ORCPT ); Wed, 6 Dec 2023 19:04:44 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 771F410C8 for ; Wed, 6 Dec 2023 16:04:39 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000716FF.0000000065710C16.001190E2; Thu, 07 Dec 2023 01:04:37 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 13/16] ALSA: hda/tas2781: remove sound controls in unbind Date: Thu, 7 Dec 2023 01:04:29 +0100 Message-ID: <8f16576930682297fd08bba5e063a9a1f3150388.1701906455.git.soyer@irl.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove sound controls in hda_unbind to make module loadable after module unload. Add a driver specific struct (tas2781_hda) to store the controls. Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 234 +++++++++++++++++++------------- 1 file changed, 136 insertions(+), 98 deletions(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index 290c41194139..0972345c15e5 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -82,6 +82,14 @@ static unsigned int cal_regs[TAS2563_CAL_N] =3D { TAS2563_CAL_R0_LOW, TAS2563_CAL_TLIM, }; =20 +struct tas2781_hda { + struct device *dev; + struct tasdevice_priv *priv; + struct snd_kcontrol *dsp_prog_ctl; + struct snd_kcontrol *dsp_conf_ctl; + struct snd_kcontrol *prof_ctl; + struct snd_kcontrol *snd_ctls[3]; +}; =20 static int tas2781_get_i2c_res(struct acpi_resource *ares, void *data) { @@ -143,26 +151,26 @@ static int tas2781_read_acpi(struct tasdevice_priv *p= , const char *hid) =20 static void tas2781_hda_playback_hook(struct device *dev, int action) { - struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); + struct tas2781_hda *tas_hda =3D dev_get_drvdata(dev); =20 - dev_dbg(tas_priv->dev, "%s: action =3D %d\n", __func__, action); + dev_dbg(tas_hda->dev, "%s: action =3D %d\n", __func__, action); switch (action) { case HDA_GEN_PCM_ACT_OPEN: pm_runtime_get_sync(dev); - mutex_lock(&tas_priv->codec_lock); - tasdevice_tuning_switch(tas_priv, 0); - mutex_unlock(&tas_priv->codec_lock); + mutex_lock(&tas_hda->priv->codec_lock); + tasdevice_tuning_switch(tas_hda->priv, 0); + mutex_unlock(&tas_hda->priv->codec_lock); break; case HDA_GEN_PCM_ACT_CLOSE: - mutex_lock(&tas_priv->codec_lock); - tasdevice_tuning_switch(tas_priv, 1); - mutex_unlock(&tas_priv->codec_lock); + mutex_lock(&tas_hda->priv->codec_lock); + tasdevice_tuning_switch(tas_hda->priv, 1); + mutex_unlock(&tas_hda->priv->codec_lock); =20 pm_runtime_mark_last_busy(dev); pm_runtime_put_autosuspend(dev); break; default: - dev_dbg(tas_priv->dev, "Playback action not supported: %d\n", + dev_dbg(tas_hda->dev, "Playback action not supported: %d\n", action); break; } @@ -556,9 +564,28 @@ static int load_calibration_efi_1(struct tasdevice_pri= v *tas_priv) return 0; } =20 +static void tas2781_hda_remove_controls(struct tas2781_hda *tas_hda) +{ + struct hda_codec *codec =3D tas_hda->priv->codec; + + if (tas_hda->dsp_prog_ctl) + snd_ctl_remove(codec->card, tas_hda->dsp_prog_ctl); + + if (tas_hda->dsp_conf_ctl) + snd_ctl_remove(codec->card, tas_hda->dsp_conf_ctl); + + for (int i =3D ARRAY_SIZE(tas_hda->snd_ctls) - 1; i >=3D 0; i--) + if (tas_hda->snd_ctls[i]) + snd_ctl_remove(codec->card, tas_hda->snd_ctls[i]); + + if (tas_hda->prof_ctl) + snd_ctl_remove(codec->card, tas_hda->prof_ctl); +} + static void tasdev_fw_ready(const struct firmware *fmw, void *context) { struct tasdevice_priv *tas_priv =3D context; + struct tas2781_hda *tas_hda =3D dev_get_drvdata(tas_priv->dev); struct hda_codec *codec =3D tas_priv->codec; int i, ret; =20 @@ -569,8 +596,8 @@ static void tasdev_fw_ready(const struct firmware *fmw,= void *context) if (ret) goto out; =20 - ret =3D snd_ctl_add(codec->card, - snd_ctl_new1(&tas2781_prof_ctrl, tas_priv)); + tas_hda->prof_ctl =3D snd_ctl_new1(&tas2781_prof_ctrl, tas_priv); + ret =3D snd_ctl_add(codec->card, tas_hda->prof_ctl); if (ret) { dev_err(tas_priv->dev, "Failed to add KControl %s =3D %d\n", @@ -579,8 +606,9 @@ static void tasdev_fw_ready(const struct firmware *fmw,= void *context) } =20 for (i =3D 0; i < ARRAY_SIZE(tas2781_snd_controls); i++) { - ret =3D snd_ctl_add(codec->card, - snd_ctl_new1(&tas2781_snd_controls[i], tas_priv)); + tas_hda->snd_ctls[i] =3D snd_ctl_new1(&tas2781_snd_controls[i], + tas_priv); + ret =3D snd_ctl_add(codec->card, tas_hda->snd_ctls[i]); if (ret) { dev_err(tas_priv->dev, "Failed to add KControl %s =3D %d\n", @@ -602,8 +630,9 @@ static void tasdev_fw_ready(const struct firmware *fmw,= void *context) goto out; } =20 - ret =3D snd_ctl_add(codec->card, - snd_ctl_new1(&tas2781_dsp_prog_ctrl, tas_priv)); + tas_hda->dsp_prog_ctl =3D snd_ctl_new1(&tas2781_dsp_prog_ctrl, + tas_priv); + ret =3D snd_ctl_add(codec->card, tas_hda->dsp_prog_ctl); if (ret) { dev_err(tas_priv->dev, "Failed to add KControl %s =3D %d\n", @@ -611,8 +640,9 @@ static void tasdev_fw_ready(const struct firmware *fmw,= void *context) goto out; } =20 - ret =3D snd_ctl_add(codec->card, - snd_ctl_new1(&tas2781_dsp_conf_ctrl, tas_priv)); + tas_hda->dsp_conf_ctl =3D snd_ctl_new1(&tas2781_dsp_conf_ctrl, + tas_priv); + ret =3D snd_ctl_add(codec->card, tas_hda->dsp_conf_ctl); if (ret) { dev_err(tas_priv->dev, "Failed to add KControl %s =3D %d\n", @@ -635,27 +665,27 @@ static void tasdev_fw_ready(const struct firmware *fm= w, void *context) tasdevice_config_info_remove(tas_priv); tasdevice_dsp_remove(tas_priv); } - mutex_unlock(&tas_priv->codec_lock); + mutex_unlock(&tas_hda->priv->codec_lock); if (fmw) release_firmware(fmw); - pm_runtime_mark_last_busy(tas_priv->dev); - pm_runtime_put_autosuspend(tas_priv->dev); + pm_runtime_mark_last_busy(tas_hda->dev); + pm_runtime_put_autosuspend(tas_hda->dev); } =20 static int tas2781_hda_bind(struct device *dev, struct device *master, void *master_data) { - struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); + struct tas2781_hda *tas_hda =3D dev_get_drvdata(dev); struct hda_component *comps =3D master_data; struct hda_codec *codec; unsigned int subid; int ret; =20 - if (!comps || tas_priv->index < 0 || - tas_priv->index >=3D HDA_MAX_COMPONENTS) + if (!comps || tas_hda->priv->index < 0 || + tas_hda->priv->index >=3D HDA_MAX_COMPONENTS) return -EINVAL; =20 - comps =3D &comps[tas_priv->index]; + comps =3D &comps[tas_hda->priv->index]; if (comps->dev) return -EBUSY; =20 @@ -664,10 +694,10 @@ static int tas2781_hda_bind(struct device *dev, struc= t device *master, =20 switch (subid) { case 0x17aa: - tas_priv->catlog_id =3D LENOVO; + tas_hda->priv->catlog_id =3D LENOVO; break; default: - tas_priv->catlog_id =3D OTHERS; + tas_hda->priv->catlog_id =3D OTHERS; break; } =20 @@ -677,7 +707,7 @@ static int tas2781_hda_bind(struct device *dev, struct = device *master, =20 strscpy(comps->name, dev_name(dev), sizeof(comps->name)); =20 - ret =3D tascodec_init(tas_priv, codec, tasdev_fw_ready); + ret =3D tascodec_init(tas_hda->priv, codec, tasdev_fw_ready); if (!ret) comps->playback_hook =3D tas2781_hda_playback_hook; =20 @@ -690,19 +720,21 @@ static int tas2781_hda_bind(struct device *dev, struc= t device *master, static void tas2781_hda_unbind(struct device *dev, struct device *master, void *master_data) { - struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); + struct tas2781_hda *tas_hda =3D dev_get_drvdata(dev); struct hda_component *comps =3D master_data; =20 - if (comps[tas_priv->index].dev =3D=3D dev) { - comps[tas_priv->index].dev =3D NULL; + if (comps[tas_hda->priv->index].dev =3D=3D dev) { + comps[tas_hda->priv->index].dev =3D NULL; strscpy(comps->name, "", sizeof(comps->name)); - comps[tas_priv->index].playback_hook =3D NULL; + comps[tas_hda->priv->index].playback_hook =3D NULL; } =20 - tasdevice_config_info_remove(tas_priv); - tasdevice_dsp_remove(tas_priv); + tas2781_hda_remove_controls(tas_hda); =20 - tas_priv->fw_state =3D TASDEVICE_DSP_FW_PENDING; + tasdevice_config_info_remove(tas_hda->priv); + tasdevice_dsp_remove(tas_hda->priv); + + tas_hda->priv->fw_state =3D TASDEVICE_DSP_FW_PENDING; } =20 static const struct component_ops tas2781_hda_comp_ops =3D { @@ -712,70 +744,75 @@ static const struct component_ops tas2781_hda_comp_op= s =3D { =20 static void tas2781_hda_remove(struct device *dev) { - struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); + struct tas2781_hda *tas_hda =3D dev_get_drvdata(dev); =20 - pm_runtime_get_sync(tas_priv->dev); - pm_runtime_disable(tas_priv->dev); + pm_runtime_get_sync(tas_hda->dev); + pm_runtime_disable(tas_hda->dev); =20 - component_del(tas_priv->dev, &tas2781_hda_comp_ops); + component_del(tas_hda->dev, &tas2781_hda_comp_ops); =20 - pm_runtime_put_noidle(tas_priv->dev); + pm_runtime_put_noidle(tas_hda->dev); =20 - tasdevice_remove(tas_priv); + tasdevice_remove(tas_hda->priv); } =20 static int tas2781_hda_i2c_probe(struct i2c_client *clt) { - struct tasdevice_priv *tas_priv; + struct tas2781_hda *tas_hda; const char *device_name; int ret; =20 - tas_priv =3D tasdevice_kzalloc(clt); - if (!tas_priv) + tas_hda =3D devm_kzalloc(&clt->dev, sizeof(*tas_hda), GFP_KERNEL); + if (!tas_hda) return -ENOMEM; =20 - dev_set_drvdata(&clt->dev, tas_priv); + dev_set_drvdata(&clt->dev, tas_hda); + tas_hda->dev =3D &clt->dev; + + tas_hda->priv =3D tasdevice_kzalloc(clt); + if (!tas_hda->priv) + return -ENOMEM; =20 - if (strstr(dev_name(&clt->dev), "TIAS2781")) { + if (strstr(dev_name(tas_hda->dev), "TIAS2781")) { device_name =3D "TIAS2781"; - tas_priv->load_calibration =3D load_calibration_efi_1; - tas_priv->apply_calibration =3D tas2781_apply_calibration; - tas_priv->global_addr =3D TAS2781_GLOBAL_ADDR; - } else if (strstr(dev_name(&clt->dev), "INT8866")) { + tas_hda->priv->load_calibration =3D load_calibration_efi_1; + tas_hda->priv->apply_calibration =3D tas2781_apply_calibration; + tas_hda->priv->global_addr =3D TAS2781_GLOBAL_ADDR; + } else if (strstr(dev_name(tas_hda->dev), "INT8866")) { device_name =3D "INT8866"; - tas_priv->load_calibration =3D load_calibration_efi_2; - tas_priv->apply_calibration =3D tas2563_apply_calibration; - tas_priv->global_addr =3D TAS2563_GLOBAL_ADDR; + tas_hda->priv->load_calibration =3D load_calibration_efi_2; + tas_hda->priv->apply_calibration =3D tas2563_apply_calibration; + tas_hda->priv->global_addr =3D TAS2563_GLOBAL_ADDR; } else return -ENODEV; =20 - tas_priv->irq_info.irq =3D clt->irq; - ret =3D tas2781_read_acpi(tas_priv, device_name); + tas_hda->priv->irq_info.irq =3D clt->irq; + ret =3D tas2781_read_acpi(tas_hda->priv, device_name); if (ret) - return dev_err_probe(tas_priv->dev, ret, + return dev_err_probe(tas_hda->dev, ret, "Platform not supported\n"); =20 - ret =3D tasdevice_init(tas_priv); + ret =3D tasdevice_init(tas_hda->priv); if (ret) goto err; =20 - pm_runtime_set_autosuspend_delay(tas_priv->dev, 3000); - pm_runtime_use_autosuspend(tas_priv->dev); - pm_runtime_mark_last_busy(tas_priv->dev); - pm_runtime_set_active(tas_priv->dev); - pm_runtime_get_noresume(tas_priv->dev); - pm_runtime_enable(tas_priv->dev); + pm_runtime_set_autosuspend_delay(tas_hda->dev, 3000); + pm_runtime_use_autosuspend(tas_hda->dev); + pm_runtime_mark_last_busy(tas_hda->dev); + pm_runtime_set_active(tas_hda->dev); + pm_runtime_get_noresume(tas_hda->dev); + pm_runtime_enable(tas_hda->dev); =20 - pm_runtime_put_autosuspend(tas_priv->dev); + pm_runtime_put_autosuspend(tas_hda->dev); =20 - ret =3D component_add(tas_priv->dev, &tas2781_hda_comp_ops); + ret =3D component_add(tas_hda->dev, &tas2781_hda_comp_ops); if (ret) { - dev_err(tas_priv->dev, "Register component failed: %d\n", ret); - pm_runtime_disable(tas_priv->dev); + dev_err(tas_hda->dev, "Register component failed: %d\n", ret); + pm_runtime_disable(tas_hda->dev); goto err; } =20 - tas2781_reset(tas_priv); + tas2781_reset(tas_hda->priv); err: if (ret) tas2781_hda_remove(&clt->dev); @@ -789,63 +826,64 @@ static void tas2781_hda_i2c_remove(struct i2c_client = *clt) =20 static int tas2781_runtime_suspend(struct device *dev) { - struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); + struct tas2781_hda *tas_hda =3D dev_get_drvdata(dev); int i; =20 - dev_dbg(tas_priv->dev, "Runtime Suspend\n"); + dev_info(tas_hda->dev, "Runtime Suspend\n"); =20 - mutex_lock(&tas_priv->codec_lock); + mutex_lock(&tas_hda->priv->codec_lock); =20 - if (tas_priv->playback_started) { - tasdevice_tuning_switch(tas_priv, 1); - tas_priv->playback_started =3D false; + if (tas_hda->priv->playback_started) { + tasdevice_tuning_switch(tas_hda->priv, 1); + tas_hda->priv->playback_started =3D false; } =20 - for (i =3D 0; i < tas_priv->ndev; i++) { - tas_priv->tasdevice[i].cur_book =3D -1; - tas_priv->tasdevice[i].cur_prog =3D -1; - tas_priv->tasdevice[i].cur_conf =3D -1; + for (i =3D 0; i < tas_hda->priv->ndev; i++) { + tas_hda->priv->tasdevice[i].cur_book =3D -1; + tas_hda->priv->tasdevice[i].cur_prog =3D -1; + tas_hda->priv->tasdevice[i].cur_conf =3D -1; } =20 =20 - mutex_unlock(&tas_priv->codec_lock); + mutex_unlock(&tas_hda->priv->codec_lock); =20 return 0; } =20 static int tas2781_runtime_resume(struct device *dev) { - struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); + struct tas2781_hda *tas_hda =3D dev_get_drvdata(dev); =20 - dev_dbg(tas_priv->dev, "Runtime Resume\n"); + dev_dbg(tas_hda->dev, "Runtime Resume\n"); =20 - mutex_lock(&tas_priv->codec_lock); + mutex_lock(&tas_hda->priv->codec_lock); =20 - tasdevice_prmg_load(tas_priv, tas_priv->cur_prog); + tasdevice_prmg_load(tas_hda->priv, tas_hda->priv->cur_prog); =20 /* If calibrated data occurs error, dsp will still works with default * calibrated data inside algo. */ - tasdevice_apply_calibration(tas_priv); + tasdevice_apply_calibration(tas_hda->priv); =20 - mutex_unlock(&tas_priv->codec_lock); +out: + mutex_unlock(&tas_hda->priv->codec_lock); =20 return 0; } =20 static int tas2781_system_suspend(struct device *dev) { - struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); + struct tas2781_hda *tas_hda =3D dev_get_drvdata(dev); int ret; =20 - dev_dbg(tas_priv->dev, "System Suspend\n"); + dev_dbg(tas_hda->priv->dev, "System Suspend\n"); =20 ret =3D pm_runtime_force_suspend(dev); if (ret) return ret; =20 /* Shutdown chip before system suspend */ - tasdevice_tuning_switch(tas_priv, 1); + tasdevice_tuning_switch(tas_hda->priv, 1); =20 /* * Reset GPIO may be shared, so cannot reset here. @@ -856,30 +894,30 @@ static int tas2781_system_suspend(struct device *dev) =20 static int tas2781_system_resume(struct device *dev) { - struct tasdevice_priv *tas_priv =3D dev_get_drvdata(dev); + struct tas2781_hda *tas_hda =3D dev_get_drvdata(dev); int i, ret; =20 - dev_dbg(tas_priv->dev, "System Resume\n"); + dev_info(tas_hda->priv->dev, "System Resume\n"); =20 ret =3D pm_runtime_force_resume(dev); if (ret) return ret; =20 - mutex_lock(&tas_priv->codec_lock); + mutex_lock(&tas_hda->priv->codec_lock); =20 - for (i =3D 0; i < tas_priv->ndev; i++) { - tas_priv->tasdevice[i].cur_book =3D -1; - tas_priv->tasdevice[i].cur_prog =3D -1; - tas_priv->tasdevice[i].cur_conf =3D -1; + for (i =3D 0; i < tas_hda->priv->ndev; i++) { + tas_hda->priv->tasdevice[i].cur_book =3D -1; + tas_hda->priv->tasdevice[i].cur_prog =3D -1; + tas_hda->priv->tasdevice[i].cur_conf =3D -1; } - tas2781_reset(tas_priv); - tasdevice_prmg_load(tas_priv, tas_priv->cur_prog); + tas2781_reset(tas_hda->priv); + tasdevice_prmg_load(tas_hda->priv, tas_hda->priv->cur_prog); =20 /* If calibrated data occurs error, dsp will still work with default * calibrated data inside algo. */ - tasdevice_apply_calibration(tas_priv); - mutex_unlock(&tas_priv->codec_lock); + tasdevice_apply_calibration(tas_hda->priv); + mutex_unlock(&tas_hda->priv->codec_lock); =20 return 0; } --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1558C10F05 for ; Thu, 7 Dec 2023 00:05:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441846AbjLGAFF (ORCPT ); Wed, 6 Dec 2023 19:05:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232278AbjLGAEn (ORCPT ); Wed, 6 Dec 2023 19:04:43 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B22710C4 for ; Wed, 6 Dec 2023 16:04:39 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 0000000000071702.0000000065710C16.001190F6; Thu, 07 Dec 2023 01:04:38 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 14/16] ALSA: hda/tas2781: call cleaner functions only once Date: Thu, 7 Dec 2023 01:04:30 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Prevent double free if only the DSP firmware is missing Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index 0972345c15e5..cb8872e15bb0 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -660,11 +660,6 @@ static void tasdev_fw_ready(const struct firmware *fmw= , void *context) tasdevice_apply_calibration(tas_priv); =20 out: - if (tas_priv->fw_state =3D=3D TASDEVICE_DSP_FW_FAIL) { - /*If DSP FW fail, kcontrol won't be created */ - tasdevice_config_info_remove(tas_priv); - tasdevice_dsp_remove(tas_priv); - } mutex_unlock(&tas_hda->priv->codec_lock); if (fmw) release_firmware(fmw); --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F293BC4167B for ; Thu, 7 Dec 2023 00:05:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441818AbjLGAFI (ORCPT ); Wed, 6 Dec 2023 19:05:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235135AbjLGAEn (ORCPT ); Wed, 6 Dec 2023 19:04:43 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B65C1A5 for ; Wed, 6 Dec 2023 16:04:40 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 0000000000071705.0000000065710C17.00119103; Thu, 07 Dec 2023 01:04:38 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 15/16] ALSA: hda/tas2781: reset the amp before component_add Date: Thu, 7 Dec 2023 01:04:31 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Prevent race to make the init reliable. Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index cb8872e15bb0..f72e0beab1fb 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -800,14 +800,14 @@ static int tas2781_hda_i2c_probe(struct i2c_client *c= lt) =20 pm_runtime_put_autosuspend(tas_hda->dev); =20 + tas2781_reset(tas_hda->priv); + ret =3D component_add(tas_hda->dev, &tas2781_hda_comp_ops); if (ret) { dev_err(tas_hda->dev, "Register component failed: %d\n", ret); pm_runtime_disable(tas_hda->dev); goto err; } - - tas2781_reset(tas_hda->priv); err: if (ret) tas2781_hda_remove(&clt->dev); --=20 2.43.0 From nobody Sun Dec 28 15:34:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9194DC4167B for ; Thu, 7 Dec 2023 00:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441866AbjLGAFK (ORCPT ); Wed, 6 Dec 2023 19:05:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235150AbjLGAEn (ORCPT ); Wed, 6 Dec 2023 19:04:43 -0500 Received: from irl.hu (irl.hu [95.85.9.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9092DD66 for ; Wed, 6 Dec 2023 16:04:41 -0800 (PST) Received: from fedori.lan (51b690cd.dsl.pool.telekom.hu [::ffff:81.182.144.205]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 0000000000071708.0000000065710C17.0011910F; Thu, 07 Dec 2023 01:04:39 +0100 From: Gergo Koteles To: Shenghao Ding , Kevin Lu , Baojun Xu , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Gergo Koteles Subject: [PATCH 16/16] ALSA: hda/tas2781: configure the amp after firmware load Date: Thu, 7 Dec 2023 01:04:32 +0100 Message-ID: <06f8c1eddd0e91f08e35722ef7df240113c32e1f.1701906455.git.soyer@irl.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make the amp available immediately after a module load to avoid having to wait for a PCM hook action. (eg. unloading & loading the module while listening music) Signed-off-by: Gergo Koteles --- sound/pci/hda/tas2781_hda_i2c.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/pci/hda/tas2781_hda_i2c.c b/sound/pci/hda/tas2781_hda_i2= c.c index f72e0beab1fb..07bdff87c962 100644 --- a/sound/pci/hda/tas2781_hda_i2c.c +++ b/sound/pci/hda/tas2781_hda_i2c.c @@ -659,6 +659,8 @@ static void tasdev_fw_ready(const struct firmware *fmw,= void *context) tasdevice_load_calibration(tas_priv); tasdevice_apply_calibration(tas_priv); =20 + tasdevice_tuning_switch(tas_hda->priv, 0); + out: mutex_unlock(&tas_hda->priv->codec_lock); if (fmw) --=20 2.43.0