All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: rt1308-sdw: get calibration params after power on
@ 2022-03-15  9:37 shumingf
  2022-03-15 15:03 ` Pierre-Louis Bossart
  2022-03-16 20:35 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: shumingf @ 2022-03-15  9:37 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: oder_chiou, jack.yu, alsa-devel, lars, derek.fang, Shuming Fan,
	jfmiranda, flove, pierre-louis.bossart

From: Shuming Fan <shumingf@realtek.com>

It will be safe when getting the calibration params after power-on.
All powers are ready to read the calibration params from EFUSE.

Signed-off-by: Shuming Fan <shumingf@realtek.com>
---
 sound/soc/codecs/rt1308-sdw.c | 73 +++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 33 deletions(-)

diff --git a/sound/soc/codecs/rt1308-sdw.c b/sound/soc/codecs/rt1308-sdw.c
index 149a76075c76..1ef836a68a56 100644
--- a/sound/soc/codecs/rt1308-sdw.c
+++ b/sound/soc/codecs/rt1308-sdw.c
@@ -50,6 +50,8 @@ static bool rt1308_volatile_register(struct device *dev, unsigned int reg)
 	case 0x3008:
 	case 0x300a:
 	case 0xc000:
+	case 0xc860 ... 0xc863:
+	case 0xc870 ... 0xc873:
 		return true;
 	default:
 		return false;
@@ -159,12 +161,45 @@ static int rt1308_read_prop(struct sdw_slave *slave)
 	return 0;
 }
 
+static void rt1308_apply_calib_params(struct rt1308_sdw_priv *rt1308)
+{
+	unsigned int efuse_m_btl_l, efuse_m_btl_r, tmp;
+	unsigned int efuse_c_btl_l, efuse_c_btl_r;
+
+	/* read efuse to apply calibration parameters */
+	regmap_write(rt1308->regmap, 0xc7f0, 0x04);
+	regmap_write(rt1308->regmap, 0xc7f1, 0xfe);
+	msleep(100);
+	regmap_write(rt1308->regmap, 0xc7f0, 0x44);
+	msleep(20);
+	regmap_write(rt1308->regmap, 0xc240, 0x10);
+
+	regmap_read(rt1308->regmap, 0xc861, &tmp);
+	efuse_m_btl_l = tmp;
+	regmap_read(rt1308->regmap, 0xc860, &tmp);
+	efuse_m_btl_l = efuse_m_btl_l | (tmp << 8);
+	regmap_read(rt1308->regmap, 0xc863, &tmp);
+	efuse_c_btl_l = tmp;
+	regmap_read(rt1308->regmap, 0xc862, &tmp);
+	efuse_c_btl_l = efuse_c_btl_l | (tmp << 8);
+	regmap_read(rt1308->regmap, 0xc871, &tmp);
+	efuse_m_btl_r = tmp;
+	regmap_read(rt1308->regmap, 0xc870, &tmp);
+	efuse_m_btl_r = efuse_m_btl_r | (tmp << 8);
+	regmap_read(rt1308->regmap, 0xc873, &tmp);
+	efuse_c_btl_r = tmp;
+	regmap_read(rt1308->regmap, 0xc872, &tmp);
+	efuse_c_btl_r = efuse_c_btl_r | (tmp << 8);
+	dev_dbg(&rt1308->sdw_slave->dev, "%s m_btl_l=0x%x, m_btl_r=0x%x\n", __func__,
+		efuse_m_btl_l, efuse_m_btl_r);
+	dev_dbg(&rt1308->sdw_slave->dev, "%s c_btl_l=0x%x, c_btl_r=0x%x\n", __func__,
+		efuse_c_btl_l, efuse_c_btl_r);
+}
+
 static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
 {
 	struct rt1308_sdw_priv *rt1308 = dev_get_drvdata(dev);
 	int ret = 0;
-	unsigned int efuse_m_btl_l, efuse_m_btl_r, tmp;
-	unsigned int efuse_c_btl_l, efuse_c_btl_r;
 
 	if (rt1308->hw_init)
 		return 0;
@@ -196,37 +231,6 @@ static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
 	/* sw reset */
 	regmap_write(rt1308->regmap, RT1308_SDW_RESET, 0);
 
-	/* read efuse */
-	regmap_write(rt1308->regmap, 0xc360, 0x01);
-	regmap_write(rt1308->regmap, 0xc361, 0x80);
-	regmap_write(rt1308->regmap, 0xc7f0, 0x04);
-	regmap_write(rt1308->regmap, 0xc7f1, 0xfe);
-	msleep(100);
-	regmap_write(rt1308->regmap, 0xc7f0, 0x44);
-	msleep(20);
-	regmap_write(rt1308->regmap, 0xc240, 0x10);
-
-	regmap_read(rt1308->regmap, 0xc861, &tmp);
-	efuse_m_btl_l = tmp;
-	regmap_read(rt1308->regmap, 0xc860, &tmp);
-	efuse_m_btl_l = efuse_m_btl_l | (tmp << 8);
-	regmap_read(rt1308->regmap, 0xc863, &tmp);
-	efuse_c_btl_l = tmp;
-	regmap_read(rt1308->regmap, 0xc862, &tmp);
-	efuse_c_btl_l = efuse_c_btl_l | (tmp << 8);
-	regmap_read(rt1308->regmap, 0xc871, &tmp);
-	efuse_m_btl_r = tmp;
-	regmap_read(rt1308->regmap, 0xc870, &tmp);
-	efuse_m_btl_r = efuse_m_btl_r | (tmp << 8);
-	regmap_read(rt1308->regmap, 0xc873, &tmp);
-	efuse_c_btl_r = tmp;
-	regmap_read(rt1308->regmap, 0xc872, &tmp);
-	efuse_c_btl_r = efuse_c_btl_r | (tmp << 8);
-	dev_dbg(&slave->dev, "%s m_btl_l=0x%x, m_btl_r=0x%x\n", __func__,
-		efuse_m_btl_l, efuse_m_btl_r);
-	dev_dbg(&slave->dev, "%s c_btl_l=0x%x, c_btl_r=0x%x\n", __func__,
-		efuse_c_btl_l, efuse_c_btl_r);
-
 	/* initial settings */
 	regmap_write(rt1308->regmap, 0xc103, 0xc0);
 	regmap_write(rt1308->regmap, 0xc030, 0x17);
@@ -323,6 +327,8 @@ static int rt1308_classd_event(struct snd_soc_dapm_widget *w,
 {
 	struct snd_soc_component *component =
 		snd_soc_dapm_to_component(w->dapm);
+	struct rt1308_sdw_priv *rt1308 =
+		snd_soc_component_get_drvdata(component);
 
 	switch (event) {
 	case SND_SOC_DAPM_POST_PMU:
@@ -331,6 +337,7 @@ static int rt1308_classd_event(struct snd_soc_dapm_widget *w,
 			RT1308_SDW_OFFSET | (RT1308_POWER_STATUS << 4),
 			0x3,	0x3);
 		msleep(40);
+		rt1308_apply_calib_params(rt1308);
 		break;
 	case SND_SOC_DAPM_PRE_PMD:
 		snd_soc_component_update_bits(component,
-- 
2.35.1


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

* Re: [PATCH] ASoC: rt1308-sdw: get calibration params after power on
  2022-03-15  9:37 [PATCH] ASoC: rt1308-sdw: get calibration params after power on shumingf
@ 2022-03-15 15:03 ` Pierre-Louis Bossart
  2022-03-16 20:35 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Pierre-Louis Bossart @ 2022-03-15 15:03 UTC (permalink / raw)
  To: shumingf, broonie, lgirdwood
  Cc: oder_chiou, jack.yu, alsa-devel, lars, derek.fang, jfmiranda,
	flove, pierre-louis.bossart



On 3/15/22 04:37, shumingf@realtek.com wrote:
> From: Shuming Fan <shumingf@realtek.com>
> 
> It will be safe when getting the calibration params after power-on.
> All powers are ready to read the calibration params from EFUSE.
> 
> Signed-off-by: Shuming Fan <shumingf@realtek.com>

For more context, this patch solves 'cracking sound' on speakers and was 
tested by the bug reporter on Dell XPS 17 9710 (SoundWire-based device)

BugLink: https://github.com/thesofproject/sof/issues/5436
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

> ---
>   sound/soc/codecs/rt1308-sdw.c | 73 +++++++++++++++++++----------------
>   1 file changed, 40 insertions(+), 33 deletions(-)
> 
> diff --git a/sound/soc/codecs/rt1308-sdw.c b/sound/soc/codecs/rt1308-sdw.c
> index 149a76075c76..1ef836a68a56 100644
> --- a/sound/soc/codecs/rt1308-sdw.c
> +++ b/sound/soc/codecs/rt1308-sdw.c
> @@ -50,6 +50,8 @@ static bool rt1308_volatile_register(struct device *dev, unsigned int reg)
>   	case 0x3008:
>   	case 0x300a:
>   	case 0xc000:
> +	case 0xc860 ... 0xc863:
> +	case 0xc870 ... 0xc873:
>   		return true;
>   	default:
>   		return false;
> @@ -159,12 +161,45 @@ static int rt1308_read_prop(struct sdw_slave *slave)
>   	return 0;
>   }
>   
> +static void rt1308_apply_calib_params(struct rt1308_sdw_priv *rt1308)
> +{
> +	unsigned int efuse_m_btl_l, efuse_m_btl_r, tmp;
> +	unsigned int efuse_c_btl_l, efuse_c_btl_r;
> +
> +	/* read efuse to apply calibration parameters */
> +	regmap_write(rt1308->regmap, 0xc7f0, 0x04);
> +	regmap_write(rt1308->regmap, 0xc7f1, 0xfe);
> +	msleep(100);
> +	regmap_write(rt1308->regmap, 0xc7f0, 0x44);
> +	msleep(20);
> +	regmap_write(rt1308->regmap, 0xc240, 0x10);
> +
> +	regmap_read(rt1308->regmap, 0xc861, &tmp);
> +	efuse_m_btl_l = tmp;
> +	regmap_read(rt1308->regmap, 0xc860, &tmp);
> +	efuse_m_btl_l = efuse_m_btl_l | (tmp << 8);
> +	regmap_read(rt1308->regmap, 0xc863, &tmp);
> +	efuse_c_btl_l = tmp;
> +	regmap_read(rt1308->regmap, 0xc862, &tmp);
> +	efuse_c_btl_l = efuse_c_btl_l | (tmp << 8);
> +	regmap_read(rt1308->regmap, 0xc871, &tmp);
> +	efuse_m_btl_r = tmp;
> +	regmap_read(rt1308->regmap, 0xc870, &tmp);
> +	efuse_m_btl_r = efuse_m_btl_r | (tmp << 8);
> +	regmap_read(rt1308->regmap, 0xc873, &tmp);
> +	efuse_c_btl_r = tmp;
> +	regmap_read(rt1308->regmap, 0xc872, &tmp);
> +	efuse_c_btl_r = efuse_c_btl_r | (tmp << 8);
> +	dev_dbg(&rt1308->sdw_slave->dev, "%s m_btl_l=0x%x, m_btl_r=0x%x\n", __func__,
> +		efuse_m_btl_l, efuse_m_btl_r);
> +	dev_dbg(&rt1308->sdw_slave->dev, "%s c_btl_l=0x%x, c_btl_r=0x%x\n", __func__,
> +		efuse_c_btl_l, efuse_c_btl_r);
> +}
> +
>   static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
>   {
>   	struct rt1308_sdw_priv *rt1308 = dev_get_drvdata(dev);
>   	int ret = 0;
> -	unsigned int efuse_m_btl_l, efuse_m_btl_r, tmp;
> -	unsigned int efuse_c_btl_l, efuse_c_btl_r;
>   
>   	if (rt1308->hw_init)
>   		return 0;
> @@ -196,37 +231,6 @@ static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
>   	/* sw reset */
>   	regmap_write(rt1308->regmap, RT1308_SDW_RESET, 0);
>   
> -	/* read efuse */
> -	regmap_write(rt1308->regmap, 0xc360, 0x01);
> -	regmap_write(rt1308->regmap, 0xc361, 0x80);
> -	regmap_write(rt1308->regmap, 0xc7f0, 0x04);
> -	regmap_write(rt1308->regmap, 0xc7f1, 0xfe);
> -	msleep(100);
> -	regmap_write(rt1308->regmap, 0xc7f0, 0x44);
> -	msleep(20);
> -	regmap_write(rt1308->regmap, 0xc240, 0x10);
> -
> -	regmap_read(rt1308->regmap, 0xc861, &tmp);
> -	efuse_m_btl_l = tmp;
> -	regmap_read(rt1308->regmap, 0xc860, &tmp);
> -	efuse_m_btl_l = efuse_m_btl_l | (tmp << 8);
> -	regmap_read(rt1308->regmap, 0xc863, &tmp);
> -	efuse_c_btl_l = tmp;
> -	regmap_read(rt1308->regmap, 0xc862, &tmp);
> -	efuse_c_btl_l = efuse_c_btl_l | (tmp << 8);
> -	regmap_read(rt1308->regmap, 0xc871, &tmp);
> -	efuse_m_btl_r = tmp;
> -	regmap_read(rt1308->regmap, 0xc870, &tmp);
> -	efuse_m_btl_r = efuse_m_btl_r | (tmp << 8);
> -	regmap_read(rt1308->regmap, 0xc873, &tmp);
> -	efuse_c_btl_r = tmp;
> -	regmap_read(rt1308->regmap, 0xc872, &tmp);
> -	efuse_c_btl_r = efuse_c_btl_r | (tmp << 8);
> -	dev_dbg(&slave->dev, "%s m_btl_l=0x%x, m_btl_r=0x%x\n", __func__,
> -		efuse_m_btl_l, efuse_m_btl_r);
> -	dev_dbg(&slave->dev, "%s c_btl_l=0x%x, c_btl_r=0x%x\n", __func__,
> -		efuse_c_btl_l, efuse_c_btl_r);
> -
>   	/* initial settings */
>   	regmap_write(rt1308->regmap, 0xc103, 0xc0);
>   	regmap_write(rt1308->regmap, 0xc030, 0x17);
> @@ -323,6 +327,8 @@ static int rt1308_classd_event(struct snd_soc_dapm_widget *w,
>   {
>   	struct snd_soc_component *component =
>   		snd_soc_dapm_to_component(w->dapm);
> +	struct rt1308_sdw_priv *rt1308 =
> +		snd_soc_component_get_drvdata(component);
>   
>   	switch (event) {
>   	case SND_SOC_DAPM_POST_PMU:
> @@ -331,6 +337,7 @@ static int rt1308_classd_event(struct snd_soc_dapm_widget *w,
>   			RT1308_SDW_OFFSET | (RT1308_POWER_STATUS << 4),
>   			0x3,	0x3);
>   		msleep(40);
> +		rt1308_apply_calib_params(rt1308);
>   		break;
>   	case SND_SOC_DAPM_PRE_PMD:
>   		snd_soc_component_update_bits(component,

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

* Re: [PATCH] ASoC: rt1308-sdw: get calibration params after power on
  2022-03-15  9:37 [PATCH] ASoC: rt1308-sdw: get calibration params after power on shumingf
  2022-03-15 15:03 ` Pierre-Louis Bossart
@ 2022-03-16 20:35 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2022-03-16 20:35 UTC (permalink / raw)
  To: shumingf, lgirdwood
  Cc: oder_chiou, jack.yu, alsa-devel, lars, derek.fang, jfmiranda,
	flove, pierre-louis.bossart

On Tue, 15 Mar 2022 17:37:40 +0800, shumingf@realtek.com wrote:
> From: Shuming Fan <shumingf@realtek.com>
> 
> It will be safe when getting the calibration params after power-on.
> All powers are ready to read the calibration params from EFUSE.
> 
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: rt1308-sdw: get calibration params after power on
      commit: abed17fdf92e4b3bfe336f7872270e0924cc4463

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

end of thread, other threads:[~2022-03-16 20:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-15  9:37 [PATCH] ASoC: rt1308-sdw: get calibration params after power on shumingf
2022-03-15 15:03 ` Pierre-Louis Bossart
2022-03-16 20:35 ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.