mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda/tas2781: do not use regcache
@ 2023-12-21 23:48 Gergo Koteles
  2023-12-22 13:12 ` Mark Brown
  2023-12-29 12:45 ` Takashi Iwai
  0 siblings, 2 replies; 3+ messages in thread
From: Gergo Koteles @ 2023-12-21 23:48 UTC (permalink / raw)
  To: Shenghao Ding, Kevin Lu, Baojun Xu, Jaroslav Kysela,
	Takashi Iwai, Liam Girdwood, Mark Brown
  Cc: linux-sound, linux-kernel, alsa-devel, Gergo Koteles, stable

There are two problems with using regcache in this module.

The amplifier has 3 addressing levels (BOOK, PAGE, REG). The firmware
contains blocks that must be written to BOOK 0x8C. The regcache doesn't
know anything about BOOK, so regcache_sync writes invalid values to the
actual BOOK.

The module handles 2 or more separate amplifiers. The amplifiers have
different register values, and the module uses only one regmap/regcache
for all the amplifiers. The regcache_sync only writes the last amplifier
used.

The module successfully restores all the written register values (RC
profile, program, configuration, calibration) without regcache.

Remove regcache functions and set regmap cache_type to REGCACHE_NONE.

Link: https://lore.kernel.org/r/21a183b5a08cb23b193af78d4b1114cc59419272.1701906455.git.soyer@irl.hu/

Fixes: 5be27f1e3ec9 ("ALSA: hda/tas2781: Add tas2781 HDA driver")
CC: stable@vger.kernel.org
Signed-off-by: Gergo Koteles <soyer@irl.hu>
---
 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_i2c.c
index 2fb1a7037c82..e4c54b2a012c 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 = -1;
 	}
 
-	regcache_cache_only(tas_priv->regmap, true);
-	regcache_mark_dirty(tas_priv->regmap);
 
 	mutex_unlock(&tas_priv->codec_lock);
 
@@ -730,20 +728,11 @@ static int tas2781_runtime_resume(struct device *dev)
 	struct tasdevice_priv *tas_priv = dev_get_drvdata(dev);
 	unsigned long calib_data_sz =
 		tas_priv->ndev * TASDEVICE_SPEAKER_CALIBRATION_SIZE;
-	int ret;
 
 	dev_dbg(tas_priv->dev, "Runtime Resume\n");
 
 	mutex_lock(&tas_priv->codec_lock);
 
-	regcache_cache_only(tas_priv->regmap, false);
-	ret = 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);
 
 	/* 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);
 
-out:
 	mutex_unlock(&tas_priv->codec_lock);
 
-	return ret;
+	return 0;
 }
 
 static int tas2781_system_suspend(struct device *dev)
@@ -770,10 +758,7 @@ static int tas2781_system_suspend(struct device *dev)
 		return ret;
 
 	/* 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);
 
 	/*
 	 * Reset GPIO may be shared, so cannot reset here.
diff --git a/sound/soc/codecs/tas2781-comlib.c b/sound/soc/codecs/tas2781-comlib.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[] = {
 static const struct regmap_config tasdevice_regmap = {
 	.reg_bits = 8,
 	.val_bits = 8,
-	.cache_type = REGCACHE_RBTREE,
+	.cache_type = REGCACHE_NONE,
 	.ranges = tasdevice_ranges,
 	.num_ranges = ARRAY_SIZE(tasdevice_ranges),
 	.max_register = 256 * 128,

base-commit: 916d051730ae48aef8b588fd096fefca4bc0590a
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: hda/tas2781: do not use regcache
  2023-12-21 23:48 [PATCH] ALSA: hda/tas2781: do not use regcache Gergo Koteles
@ 2023-12-22 13:12 ` Mark Brown
  2023-12-29 12:45 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2023-12-22 13:12 UTC (permalink / raw)
  To: Gergo Koteles
  Cc: Shenghao Ding, Kevin Lu, Baojun Xu, Jaroslav Kysela,
	Takashi Iwai, Liam Girdwood, linux-sound, linux-kernel,
	alsa-devel, stable

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

On Fri, Dec 22, 2023 at 12:48:56AM +0100, Gergo Koteles wrote:
> There are two problems with using regcache in this module.
> 
> The amplifier has 3 addressing levels (BOOK, PAGE, REG). The firmware
> contains blocks that must be written to BOOK 0x8C. The regcache doesn't
> know anything about BOOK, so regcache_sync writes invalid values to the
> actual BOOK.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: hda/tas2781: do not use regcache
  2023-12-21 23:48 [PATCH] ALSA: hda/tas2781: do not use regcache Gergo Koteles
  2023-12-22 13:12 ` Mark Brown
@ 2023-12-29 12:45 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2023-12-29 12:45 UTC (permalink / raw)
  To: Gergo Koteles
  Cc: Shenghao Ding, Kevin Lu, Baojun Xu, Jaroslav Kysela,
	Takashi Iwai, Liam Girdwood, Mark Brown, linux-sound,
	linux-kernel, alsa-devel, stable

On Fri, 22 Dec 2023 00:48:56 +0100,
Gergo Koteles wrote:
> 
> There are two problems with using regcache in this module.
> 
> The amplifier has 3 addressing levels (BOOK, PAGE, REG). The firmware
> contains blocks that must be written to BOOK 0x8C. The regcache doesn't
> know anything about BOOK, so regcache_sync writes invalid values to the
> actual BOOK.
> 
> The module handles 2 or more separate amplifiers. The amplifiers have
> different register values, and the module uses only one regmap/regcache
> for all the amplifiers. The regcache_sync only writes the last amplifier
> used.
> 
> The module successfully restores all the written register values (RC
> profile, program, configuration, calibration) without regcache.
> 
> Remove regcache functions and set regmap cache_type to REGCACHE_NONE.
> 
> Link: https://lore.kernel.org/r/21a183b5a08cb23b193af78d4b1114cc59419272.1701906455.git.soyer@irl.hu/
> 
> Fixes: 5be27f1e3ec9 ("ALSA: hda/tas2781: Add tas2781 HDA driver")
> CC: stable@vger.kernel.org
> Signed-off-by: Gergo Koteles <soyer@irl.hu>

Applied to for-linus branch now.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-29 12:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21 23:48 [PATCH] ALSA: hda/tas2781: do not use regcache Gergo Koteles
2023-12-22 13:12 ` Mark Brown
2023-12-29 12:45 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®